Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/HandleManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,23 @@ namespace SokuLib

template<class T>
class HandleManagerEx {
static_assert(std::has_virtual_destructor<T>::value);
public:
Vector<T*> vector;
Vector<unsigned int> usedIndexes;
List<unsigned int> unusedIndexes;
unsigned int nextBase = 0;
CriticalSection mutex;

virtual ~HandleManagerEx() { for(auto t : vector) delete t; }
virtual ~HandleManagerEx() {
// when the destructor is virtual
// the memory allocation is always removed
// from the heap the class was defined
// for others we can choose the heap
for(auto t : vector) {
if constexpr (std::has_virtual_destructor<T>::value) delete t;
else SokuLib::Delete<T>(t);
}
}

template<typename... Args>
inline T* Allocate(unsigned int& retId, Args... args) {
Expand All @@ -109,7 +117,9 @@ namespace SokuLib
index = vector.size();
if(++nextBase > 0xffff) nextBase = 1;
retId = (index & 0xffff) | (nextBase << 16);
vector.push_back(ret = new T(args...));
if constexpr(std::has_virtual_destructor<T>::value) ret = new T(args...);
else ret = SokuLib::New<T>(sizeof(T), args...);
vector.push_back(ret);
usedIndexes.push_back(retId >> 16);
}
mutex.unlock();
Expand Down
2 changes: 2 additions & 0 deletions src/SokuAddresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ namespace SokuLib
ADDR_RCHARID = 0x00899D30,
ADDR_INPUT_MANAGER_CLUSTER = 0x0089A248,
ADDR_MENU_LIST = 0x0089A884,
ADDR_SFX_MANAGER = 0x0089F9F8,
ADDR_BGM_MANAGER = 0x0089FE50,
ADDR_TEXTURE_MANAGER = 0x0089FF08,
ADDR_WINDOW_HWND = 0x0089FF90,
ADDR_LOAD_GRAPHICS_THREAD = 0x0089FFF4,
Expand Down
8 changes: 8 additions & 0 deletions src/SoundData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ namespace SokuLib
int bufferSize;
};

class DS3DBuffer {
public:
void** vtable;
void* dsHandle; // IDirectSoundBuffer*
int bufferSize;
void* ds3dHandle; // IDirectSound3DBuffer*
};

class BgmBuffer {
public:
String filename;
Expand Down
9 changes: 9 additions & 0 deletions src/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@

#include "SokuAddresses.hpp"
#include "SoundManager.hpp"
#include "UnionCast.hpp"

namespace SokuLib
{
void (* const playSEWaveBuffer)(int id) = reinterpret_cast<void (*)(int id)>(ADDR_PLAY_SE_WAVE_BUFFER);
void (* const playNetBell)(int id) = reinterpret_cast<void (*)(int id)>(ADDR_PLAY_NET_BELL);

SFXManager& SFXManager::instance = *reinterpret_cast<SFXManager *>(ADDR_SFX_MANAGER);
BGMManager& BGMManager::instance = *reinterpret_cast<BGMManager *>(ADDR_BGM_MANAGER);

unsigned int SFXManager::load(unsigned int& id, const char* soundPath) { return (this->*union_cast<unsigned int(SFXManager::*)(unsigned int&, const char*)>(0x401AF0))(id, soundPath); }
bool SFXManager::unload(unsigned int id) { return (this->*union_cast<bool(SFXManager::*)(unsigned int)>(0x401BD0))(id); }
void SFXManager::play(unsigned int id) { return (this->*union_cast<void(SFXManager::*)(unsigned int)>(0x401D50))(id); }

}
56 changes: 56 additions & 0 deletions src/SoundManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef SOKULIB_SOUNDMANAGER_HPP
#define SOKULIB_SOUNDMANAGER_HPP

#include "HandleManager.hpp"
#include "SoundData.hpp"

namespace SokuLib
{
Expand Down Expand Up @@ -78,6 +80,60 @@ namespace SokuLib
{
((void (*)(const char *))0x43ff10)(path);
}

// size = 0x458
struct SFXManager {
HandleManager<WaveData*> handlesA;
HandleManager<DSBuffer*> handleB;
DSBuffer buffers[32];
DS3DBuffer buffers3D[32];
char unknown448[8];
float volume, volumeCoef;

static SFXManager& instance; // 0x89F9F8

// void initialize(); // 0x401990
// void unloadBuffers(); // 0x401A80
unsigned int load(unsigned int& id, const char* soundPath); // 0x401AF0
bool unload(unsigned int id); // 0x401BD0
// void setVolume(float value); // 0x401C20
// void setItemVolume(unsigned int id, float value); // 0x401CE0
void play(unsigned int id); // 0x401D50
};

// size = 0xB8
struct BGMManager {
HANDLE threadAHandle;
LPDWORD threadAID;
HANDLE threadBHandle;
LPDWORD threadBID;
HANDLE eventHandle10;
HANDLE eventHandle14;
bool isActive;
// offset 3

CriticalSection criticalSection;
HandleManagerEx<BgmBuffer> handles;
List<void*> unknownList88; // playing? data type is probably the handleID
List<void*> unknownList94; // queued?
List<void*> unknownListA0; // stopped?
float volume, volumeCoef;
char unknownB4[0x04];

static BGMManager& instance; // 0x89FE50

// 0x899d5c == current_bgm_id

// void initialize(); // 0x403740
// void unloadBuffers(); // 0x4037d0
// unsigned int* create(unsigned int& id); // 0x4039A0
// bool load(unsigned int id, const char* soundPath, bool useListB, float unknown); // 0x4039C0
// void somethingA(unsigned int id, int time); // 0x403B20
// void somethingB(unsigned int id); // 0x403BB0
// void somethingC(unsigned int id, int time, int startTime, bool alwaysTrue); // 0x403C20 (playFadeIn?)
// void somethingD(unsigned int id, int time, int startTime, float unknown); // 0x403C70 (stopFadeOut?)
// void setItemVolume(unsigned int id, float); // 0x403D10
};
}


Expand Down