summaryrefslogtreecommitdiffstats
path: root/src/audio/AudioScriptObject.cpp
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-03-31 15:09:18 +0200
committerSergeanur <s.anureev@yandex.ua>2020-04-01 05:09:25 +0200
commit62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f (patch)
tree8c19e6d05b1a282ded658d58d0df30284bb3ac1e /src/audio/AudioScriptObject.cpp
parentMerge pull request #372 from Nick007J/master (diff)
downloadre3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar.gz
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar.bz2
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar.lz
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar.xz
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.tar.zst
re3-62ae7245ab8c299f5dd9abd44bd4ba1894e17c8f.zip
Diffstat (limited to 'src/audio/AudioScriptObject.cpp')
-rw-r--r--src/audio/AudioScriptObject.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/audio/AudioScriptObject.cpp b/src/audio/AudioScriptObject.cpp
index b5093c52..0ae3834a 100644
--- a/src/audio/AudioScriptObject.cpp
+++ b/src/audio/AudioScriptObject.cpp
@@ -4,12 +4,10 @@
#include "Pools.h"
#include "DMAudio.h"
-WRAPPER void cAudioScriptObject::SaveAllAudioScriptObjects(uint8 *buf, uint32 *size) { EAXJMP(0x57c460); }
-
void
cAudioScriptObject::Reset()
{
- AudioId = 125;
+ AudioId = SCRSOUND_INVALID;
Posn = CVector(0.0f, 0.0f, 0.0f);
AudioEntity = AEHANDLE_NONE;
}
@@ -19,16 +17,19 @@ cAudioScriptObject::operator new(size_t sz)
{
return CPools::GetAudioScriptObjectPool()->New();
}
+
void *
cAudioScriptObject::operator new(size_t sz, int handle)
{
return CPools::GetAudioScriptObjectPool()->New(handle);
}
+
void
cAudioScriptObject::operator delete(void *p, size_t sz)
{
CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p);
}
+
void
cAudioScriptObject::operator delete(void *p, int handle)
{
@@ -36,6 +37,47 @@ cAudioScriptObject::operator delete(void *p, int handle)
}
void
+cAudioScriptObject::LoadAllAudioScriptObjects(uint8 *buf, uint32 size)
+{
+ INITSAVEBUF
+
+ CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE);
+
+ int32 pool_size = ReadSaveBuf<int32>(buf);
+ for (int32 i = 0; i < pool_size; i++) {
+ int handle = ReadSaveBuf<int32>(buf);
+ cAudioScriptObject *p = new(handle) cAudioScriptObject;
+ assert(p != nil);
+ *p = ReadSaveBuf<cAudioScriptObject>(buf);
+ p->AudioEntity = DMAudio.CreateLoopingScriptObject(p);
+ }
+
+ VALIDATESAVEBUF(size);
+}
+
+void
+cAudioScriptObject::SaveAllAudioScriptObjects(uint8 *buf, uint32 *size)
+{
+ INITSAVEBUF
+
+ int32 pool_size = CPools::GetAudioScriptObjectPool()->GetNoOfUsedSpaces();
+ *size = SAVE_HEADER_SIZE + pool_size * (sizeof(cAudioScriptObject) + sizeof(int32));
+ WriteSaveHeader(buf, 'A', 'U', 'D', '\0', *size - SAVE_HEADER_SIZE);
+ WriteSaveBuf(buf, pool_size);
+
+ int32 i = CPools::GetAudioScriptObjectPool()->GetSize();
+ while (i--) {
+ cAudioScriptObject *p = CPools::GetAudioScriptObjectPool()->GetSlot(i);
+ if (p != nil) {
+ WriteSaveBuf(buf, CPools::GetAudioScriptObjectPool()->GetIndex(p));
+ WriteSaveBuf(buf, *p);
+ }
+ }
+
+ VALIDATESAVEBUF(*size);
+}
+
+void
PlayOneShotScriptObject(uint8 id, CVector const &pos)
{
cAudioScriptObject *audioScriptObject = new cAudioScriptObject();
@@ -48,4 +90,6 @@ PlayOneShotScriptObject(uint8 id, CVector const &pos)
STARTPATCHES
InjectHook(0x57C430, &cAudioScriptObject::Reset, PATCH_JUMP);
InjectHook(0x57C5F0, &PlayOneShotScriptObject, PATCH_JUMP);
+InjectHook(0x57C560, &cAudioScriptObject::LoadAllAudioScriptObjects, PATCH_JUMP);
+InjectHook(0x57c460, &cAudioScriptObject::SaveAllAudioScriptObjects, PATCH_JUMP);
ENDPATCHES \ No newline at end of file