* Initial commit.

:)
This commit is contained in:
iProgramInCpp
2023-07-30 22:22:02 +03:00
commit 9642818a88
613 changed files with 151754 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
#include "SoundData.hpp"
// --------------------------------------------------------------------
// WARNING! If you have an error here it is most likely because you did
// not grab the sound data from a working mcpe01_canada.apk.
//
// Check the readme for a guide on how to extract game sounds from the
// mcpe01_canada.apk file.
// --------------------------------------------------------------------
#include "../../sound_data/sounds.h"

View File

@@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
struct PCMSoundHeader
{
int m_id;
int m_channels;
int m_sample_rate;
int m_length;
};
struct SoundDesc
{
uint16_t* m_pData;
int field_4;
PCMSoundHeader m_header;
PCMSoundHeader* m_pHeader = nullptr;
SoundDesc() {}
SoundDesc(PCMSoundHeader& header, uint16_t* data)
{
m_pHeader = &header;
m_header = header;
m_pData = data;
field_4 = header.m_id * header.m_length * header.m_channels;
}
};

View File

@@ -0,0 +1,33 @@
#pragma once
#include "SoundData.hpp"
// Minecraft Pocket Edition Reverse Engineering Project
// Copyright (C) 2011 Mojang Specifications.
// Data extracted from libminecraftpe.so (mcpe01_canada.apk).
extern SoundDesc SA_cloth1;
extern SoundDesc SA_cloth2;
extern SoundDesc SA_cloth3;
extern SoundDesc SA_cloth4;
extern SoundDesc SA_grass1;
extern SoundDesc SA_grass2;
extern SoundDesc SA_grass3;
extern SoundDesc SA_grass4;
extern SoundDesc SA_gravel1;
extern SoundDesc SA_gravel2;
extern SoundDesc SA_gravel3;
extern SoundDesc SA_gravel4;
extern SoundDesc SA_sand1;
extern SoundDesc SA_sand2;
extern SoundDesc SA_sand3;
extern SoundDesc SA_sand4;
extern SoundDesc SA_stone1;
extern SoundDesc SA_stone2;
extern SoundDesc SA_stone3;
extern SoundDesc SA_stone4;
extern SoundDesc SA_wood1;
extern SoundDesc SA_wood2;
extern SoundDesc SA_wood3;
extern SoundDesc SA_wood4;
extern SoundDesc SA_click;
extern SoundDesc SA_explode;
extern SoundDesc SA_splash;

View File

@@ -0,0 +1,71 @@
#include "SoundEngine.hpp"
#include "SoundDefs.hpp"
SoundEngine::SoundEngine()
{
#ifndef ORIGINAL_CODE
m_pOptions = nullptr;
field_A20 = 0;
#endif
}
void SoundEngine::init(Options* options)
{
m_pOptions = options;
m_repository.add("step.cloth", SA_cloth1);
m_repository.add("step.cloth", SA_cloth2);
m_repository.add("step.cloth", SA_cloth3);
m_repository.add("step.cloth", SA_cloth4);
m_repository.add("step.grass", SA_grass1);
m_repository.add("step.grass", SA_grass2);
m_repository.add("step.grass", SA_grass3);
m_repository.add("step.grass", SA_grass4);
m_repository.add("step.gravel", SA_gravel1);
m_repository.add("step.gravel", SA_gravel2);
m_repository.add("step.gravel", SA_gravel3);
m_repository.add("step.gravel", SA_gravel4);
m_repository.add("step.sand", SA_sand1);
m_repository.add("step.sand", SA_sand2);
m_repository.add("step.sand", SA_sand3);
m_repository.add("step.sand", SA_sand4);
m_repository.add("step.stone", SA_stone1);
m_repository.add("step.stone", SA_stone2);
m_repository.add("step.stone", SA_stone3);
m_repository.add("step.stone", SA_stone4);
m_repository.add("step.wood", SA_wood1);
m_repository.add("step.wood", SA_wood2);
m_repository.add("step.wood", SA_wood3);
m_repository.add("step.wood", SA_wood4);
m_repository.add("random.splash", SA_splash);
m_repository.add("random.explode", SA_explode);
m_repository.add("random.click", SA_click);
}
void SoundEngine::play(const std::string& name)
{
if (m_pOptions->field_4 == 0.0f)
return;
SoundDesc sd;
if (m_repository.get(name, sd))
m_soundSystem.playAt(sd, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f);
}
void SoundEngine::play(const std::string& name, float a, float b, float c, float d, float e)
{
if (m_pOptions->field_4 == 0.0f || d <= 0.0f)
return;
SoundDesc sd;
if (m_repository.get(name, sd))
m_soundSystem.playAt(sd, a, b, c, d, e);
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include "SoundSystem.hpp"
#include "SoundRepository.hpp"
#include "Options.hpp"
#include "Random.hpp"
// Platform specific type for the sound system.
#define SOUND_SYSTEM_TYPE SoundSystem
//#define SOUND_SYSTEM_TYPE SoundSystemSL
//#define SOUND_SYSTEM_TYPE SoundSystemWindows
// @TODO: SoundSystemSL - Use this for the Android port
// @TODO: SoundSystemWindows - Sound system for Windows.
class SoundEngine
{
public:
SoundEngine();
void init(Options*);
void play(const std::string& name);
void play(const std::string& name, float, float, float, float, float);
public:
SOUND_SYSTEM_TYPE m_soundSystem;
Options* m_pOptions;
int field_40 = 0;
Random m_random;
SoundRepository m_repository;
int field_A1C = 0;
int field_A20;
};

View File

@@ -0,0 +1,34 @@
#include "SoundRepository.hpp"
#include "Utils.hpp"
#include "Mth.hpp"
void SoundRepository::add(const std::string& name, SoundDesc& sd)
{
auto iter = m_repo.find(name);
if (iter == m_repo.end())
{
std::vector<SoundDesc> sdv;
sdv.push_back(sd);
m_repo.insert({ name, sdv });
}
else
{
iter->second.push_back(sd);
}
}
bool SoundRepository::get(const std::string& name, SoundDesc& sd)
{
auto iter = m_repo.find(name);
if (iter == m_repo.end())
{
printf("Couldn't find a sound with id: %s\n", name.c_str());
return false;
}
int index = Mth::random(int(iter->second.size()));
sd = iter->second[index];
return true;
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include "SoundData.hpp"
class SoundRepository
{
public:
void add(const std::string& name, SoundDesc& sd);
bool get(const std::string& name, SoundDesc& sd);
public:
std::map<std::string, std::vector<SoundDesc>> m_repo;
};

View File

@@ -0,0 +1,34 @@
#include "SoundSystem.hpp"
bool SoundSystem::isAvailable()
{
return false;
}
void SoundSystem::setListenerPos(float x, float y, float z)
{
}
void SoundSystem::setListenerAngle(float f)
{
}
void SoundSystem::load(const std::string& sound)
{
}
void SoundSystem::play(const std::string& sound)
{
}
void SoundSystem::pause(const std::string& sound)
{
}
void SoundSystem::stop(const std::string& sound)
{
}
void SoundSystem::playAt(const SoundDesc& sound, float x, float y, float z, float a, float b)
{
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <string>
#include "SoundData.hpp"
class SoundSystem
{
public:
virtual bool isAvailable();
virtual void setListenerPos(float x, float y, float z);
virtual void setListenerAngle(float f);
virtual void load(const std::string& sound);
virtual void play(const std::string& sound);
virtual void pause(const std::string& sound);
virtual void stop(const std::string& sound);
virtual void playAt(const SoundDesc& sound, float x, float y, float z, float a, float b);
};