From 32f066a9cd5faf062ae09e9eabb7ac7e6ff3d38c Mon Sep 17 00:00:00 2001 From: escape209 Date: Thu, 13 Mar 2025 17:14:18 +0000 Subject: [PATCH 1/2] zAssetTypes adjacent matches --- src/SB/Core/gc/iSnd.h | 1 + src/SB/Core/x/xEnv.h | 1 + src/SB/Core/x/xJSP.h | 1 + src/SB/Core/x/xstransvc.h | 1 + src/SB/Game/zAssetTypes.cpp | 161 +++++++++++++++++++++++++++--------- 5 files changed, 126 insertions(+), 39 deletions(-) diff --git a/src/SB/Core/gc/iSnd.h b/src/SB/Core/gc/iSnd.h index db980e134..0455a3e54 100644 --- a/src/SB/Core/gc/iSnd.h +++ b/src/SB/Core/gc/iSnd.h @@ -65,6 +65,7 @@ S32 iSndIsPlaying(U32 assetID, U32 parid); void iSndWaitForDeadSounds(); void iSndSceneExit(); void sndloadcb(tag_xFile* tag); +S32 iSndLoadSounds(void*); void iSndSetExternalCallback(void (*func_ptr)(U32)); void iSndAXFree(_AXVPB** param1); void iSndStartStereo(U32 id1, U32 id2, F32 pitch); diff --git a/src/SB/Core/x/xEnv.h b/src/SB/Core/x/xEnv.h index 3d994cb71..a64c5b119 100644 --- a/src/SB/Core/x/xEnv.h +++ b/src/SB/Core/x/xEnv.h @@ -32,6 +32,7 @@ struct xEnvAsset : xBaseAsset }; void xEnvLoadBsp(xEnv* env, const void* data, U32 datasize, S32 dataType); +void xEnvFree(xEnv* env); void xEnvSetup(xEnv* env); void xEnvRender(xEnv* env); diff --git a/src/SB/Core/x/xJSP.h b/src/SB/Core/x/xJSP.h index 06ce6a174..fad7731dd 100644 --- a/src/SB/Core/x/xJSP.h +++ b/src/SB/Core/x/xJSP.h @@ -24,5 +24,6 @@ struct xJSPHeader RpMesh* AddMeshCB(RpMesh* mesh, RpMeshHeader* header, RwV3d** param_3); void xJSP_MultiStreamRead(void* data, U32 size, xJSPHeader** jsp); +void xJSP_Destroy(xJSPHeader* jsp); #endif diff --git a/src/SB/Core/x/xstransvc.h b/src/SB/Core/x/xstransvc.h index 2c0f0d63a..d9930930e 100644 --- a/src/SB/Core/x/xstransvc.h +++ b/src/SB/Core/x/xstransvc.h @@ -20,6 +20,7 @@ struct st_STRAN_DATA U32 loadlock; }; +S32 xSTStartup(st_PACKER_ASSETTYPE* handlers); S32 xSTPreLoadScene(U32 sid, void* userdata, S32 flg_hiphop); S32 xSTQueueSceneAssets(U32 sid, S32 flg_hiphop); void xSTUnLoadScene(U32 sid, S32 flg_hiphop); diff --git a/src/SB/Game/zAssetTypes.cpp b/src/SB/Game/zAssetTypes.cpp index ffae46263..3609746d4 100644 --- a/src/SB/Game/zAssetTypes.cpp +++ b/src/SB/Game/zAssetTypes.cpp @@ -2,29 +2,39 @@ #include "xstransvc.h" #include "xDebug.h" +#include "xEnv.h" +#include "xJSP.h" #include #include #include #include -void* Curve_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* ATBL_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* RWTX_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* Model_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* BSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* JSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); -void* SndInfoRead(void*, unsigned int, void*, unsigned int, unsigned int*); -void Model_Unload(void*, U32); -void BSP_Unload(void*, U32); -void JSP_Unload(void*, U32); -void Anim_Unload(void*, U32); -void TextureRW3_Unload(void*, U32); -void LightKit_Unload(void*, U32); -void MovePoint_Unload(void*, U32); +static void* Curve_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void* ATBL_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void ATBL_Init(); +static void* RWTX_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void* Model_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void* BSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void* JSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize); +static void* SndInfoRead(void*, unsigned int, void*, unsigned int, unsigned int*); +static void Model_Unload(void*, U32); +static void BSP_Unload(void*, U32); +static void JSP_Unload(void*, U32); +static void Anim_Unload(void*, U32); +static void TextureRW3_Unload(void*, U32); +static void LightKit_Unload(void*, U32); +static void MovePoint_Unload(void*, U32); static xJSPHeader sDummyEmptyJSP; +static u32 s_sbFootSoundA; +static u32 s_sbFootSoundB; +static u32 s_scFootSoundA; +static u32 s_scFootSoundB; +static u32 s_patFootSoundA; +static u32 s_patFootSoundB; + static st_PACKER_ASSETTYPE assetTypeHandlers[78] = { {'BSP ', 0, 0, BSP_Read, NULL, NULL, NULL, NULL, BSP_Unload, NULL}, {'JSP ', 0, 0, JSP_Read, NULL, NULL, NULL, NULL, JSP_Unload, NULL}, @@ -105,6 +115,17 @@ static st_PACKER_ASSETTYPE assetTypeHandlers[78] = { {'CRDT'}, }; +void zAssetStartup() +{ + xSTStartup(assetTypeHandlers); + ATBL_Init(); +} + +void zAssetShutdown() +{ + xSTShutdown(); +} + static HackModelRadius hackRadiusTable[3] = { { 0xFA77E6FAU, 20.0f }, { 0x5BD0EDACU, 1000.0f }, { 0xED21A1C6U, 50.0f } }; @@ -147,11 +168,7 @@ struct AnimTableList animTable[33] = { { "ZNPC_AnimTable_Chuck", ZNPC_AnimTable_Chuck, 0 }, { "ZNPC_AnimTable_Jelly", ZNPC_AnimTable_Jelly, 0 }, { "ZNPC_AnimTable_SuperFriend", ZNPC_AnimTable_SuperFriend, 0 }, - { - "ZNPC_AnimTable_BossPatrick\0SB_run1L\0SB_run1R\0SC_run_kelpL\0Pat_run_rock_dryL\0Pat_run_rock_dryR\0\0Debug%02d", - ZNPC_AnimTable_BossPatrick, - 0, - }, + { "ZNPC_AnimTable_BossPatrick", ZNPC_AnimTable_BossPatrick, 0, } }; static xAnimTable* (*tableFuncList[48])() = { @@ -208,25 +225,33 @@ static xAnimTable* (*tableFuncList[48])() = { extern xJSPHeader* sTempJSP; extern xJSPHeader sDummyEmptyJSP; -void zAssetShutdown() +static void* Model_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { - xSTShutdown(); + } -void* Model_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { +static void* Curve_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) +{ + *outsize = insize; -} + void* __dest = RWSRCGLOBAL(memoryFuncs.rwmalloc(insize)); + memcpy(__dest, indata, insize); -void* Curve_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { + *(int *)((int)__dest + 0x10) = (int)__dest + 0x14; + return __dest; } -void Model_Unload(void*, U32) { - +static void Model_Unload(void* userdata, U32) +{ + if (userdata != NULL) + { + iModelUnload((RpAtomic*)userdata); + } } // Ghidra's output here is not helpful -void* BSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) +static void* BSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) { RwMemory rwmem; RwChunkHeaderInfo chunkHeaderInfo; @@ -257,11 +282,13 @@ void* BSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsiz return bsp; } -void BSP_Unload(void*, U32) { +static void BSP_Unload(void*, U32) +{ + xEnvFree(globals.sceneCur->env); } -void* JSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) +static void* JSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) { xJSPHeader* retjsp = &sDummyEmptyJSP; *outsize = 32; @@ -276,42 +303,98 @@ void* JSP_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsiz return retjsp; } -void JSP_Unload(void*, U32) { +static void JSP_Unload(void* userdata, U32 b) +{ + if ((xJSPHeader*)userdata != &sDummyEmptyJSP) + { + xJSP_Destroy((xJSPHeader*)userdata); + } +} + +static RwTexture* TexCB(RwTexture* texture, void* data) +{ + if (*(RwTexture**)data == NULL) + { + *(RwTexture**)(data) = texture; + } +} + +static void* RWTX_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { } -void* RWTX_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { +static void TextureRW3_Unload(void* a, U32 b) +{ + if (a != NULL) + { + ((RwTexture*)(a))->refCount = 1; + RwTextureDestroy((RwTexture*)a); + } +} +static void ATBL_Init() +{ + for (int i = 0; i < 0x21; i++) + { + animTable[i].id = xStrHash(animTable[i].name); + } } -void TextureRW3_Unload(void*, U32) +void FootstepHackSceneEnter() { + s_sbFootSoundA = xStrHash("SB_run1L"); + s_sbFootSoundB = xStrHash("SB_run1R"); + s_scFootSoundA = xStrHash("SC_run_kelpL"); + s_scFootSoundB = xStrHash("SC_run_kelpL"); + s_patFootSoundA = xStrHash("Pat_run_rock_dryL"); + s_patFootSoundB = xStrHash("Pat_run_rock_dryR"); } -U8 dummyEffectCB(U32, xAnimActiveEffect*, xAnimSingle*, void*) +static U8 dummyEffectCB(U32, xAnimActiveEffect*, xAnimSingle*, void*) { return 0; } -void* ATBL_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { +static void* ATBL_Read(void*, unsigned int, void*, unsigned int, unsigned int*) { } -void Anim_Unload(void*, U32) +static void Anim_Unload(void*, U32) { } -void LightKit_Unload(void*, U32) +static void LightKit_Unload(void* userdata, U32 b) { + xLightKit_Destroy((xLightKit*)userdata); } -void MovePoint_Unload(void*, U32) +static void MovePoint_Unload(void* userdata, U32 b) { - + xMovePointSplineDestroy((xMovePoint*)userdata); } -void* SndInfoRead(void*, unsigned int, void*, unsigned int, unsigned int*) { +static void* SndInfoRead(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) +{ + void* __dest = RWSRCGLOBAL(memoryFuncs.rwmalloc(insize)); + + if (__dest == NULL) + { + return __dest; + } + + memcpy(__dest, indata, insize); + + if (iSndLoadSounds(__dest) == 0) + { + RWSRCGLOBAL(memoryFuncs.rwfree(__dest)); + return NULL; + } + else + { + *outsize = insize; + } + return __dest; } U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, xEnt* ent, F32 radius, From b015f37afcdd71c37e765401cf88d8e76cd27a59 Mon Sep 17 00:00:00 2001 From: escape209 Date: Thu, 13 Mar 2025 19:24:45 +0000 Subject: [PATCH 2/2] zAssetTypes: Model_Read --- src/SB/Game/zAssetTypes.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SB/Game/zAssetTypes.cpp b/src/SB/Game/zAssetTypes.cpp index 3609746d4..dae6892a7 100644 --- a/src/SB/Game/zAssetTypes.cpp +++ b/src/SB/Game/zAssetTypes.cpp @@ -225,9 +225,32 @@ static xAnimTable* (*tableFuncList[48])() = { extern xJSPHeader* sTempJSP; extern xJSPHeader sDummyEmptyJSP; -static void* Model_Read(void*, unsigned int, void*, unsigned int, unsigned int*) +static void* Model_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) { + RpAtomic* model = (RpAtomic *)iModelFileNew(indata, insize); + *outsize = 0x70; + + for (int i = 0; i < 3; i++) + { + if (param_2 != hackRadiusTable[i].assetid) + { + continue; + } + for (RpAtomic* tmpModel = model; tmpModel != NULL; tmpModel = (RpAtomic *)iModelFile_RWMultiAtomic(tmpModel)) + { + tmpModel->boundingSphere.radius = hackRadiusTable[i].radius; + + tmpModel->boundingSphere.center.x = 0.0f; + tmpModel->boundingSphere.center.y = 0.0f; + tmpModel->boundingSphere.center.z = 0.0f; + + tmpModel->interpolator.flags &= ~2; + } + break; + } + + return model; } static void* Curve_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize) @@ -368,6 +391,11 @@ static void LightKit_Unload(void* userdata, U32 b) xLightKit_Destroy((xLightKit*)userdata); } +static void Anim_ATBL_getTable(xAnimTable* (*param)(void)) +{ + *param(); +} + static void MovePoint_Unload(void* userdata, U32 b) { xMovePointSplineDestroy((xMovePoint*)userdata);