Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/SB/Core/gc/iSnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/SB/Core/x/xEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/SB/Core/x/xJSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/SB/Core/x/xstransvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
187 changes: 149 additions & 38 deletions src/SB/Game/zAssetTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,39 @@

#include "xstransvc.h"
#include "xDebug.h"
#include "xEnv.h"
#include "xJSP.h"

#include <types.h>
#include <rwcore.h>
#include <rpworld.h>
#include <xAnim.h>

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},
Expand Down Expand Up @@ -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 } };
Expand Down Expand Up @@ -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])() = {
Expand Down Expand Up @@ -208,25 +225,56 @@ static xAnimTable* (*tableFuncList[48])() = {
extern xJSPHeader* sTempJSP;
extern xJSPHeader sDummyEmptyJSP;

void zAssetShutdown()
static void* Model_Read(void* param_1, U32 param_2, void* indata, U32 insize, U32* outsize)
{
xSTShutdown();
}
RpAtomic* model = (RpAtomic *)iModelFileNew(indata, insize);

void* Model_Read(void*, unsigned int, void*, unsigned int, unsigned int*) {
*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;

void* Curve_Read(void*, unsigned int, void*, unsigned int, unsigned int*) {
tmpModel->interpolator.flags &= ~2;
}
break;
}

return model;
}

void Model_Unload(void*, U32) {
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);

*(int *)((int)__dest + 0x10) = (int)__dest + 0x14;

return __dest;
}

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;
Expand Down Expand Up @@ -257,11 +305,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;
Expand All @@ -276,42 +326,103 @@ 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;
}
}

void* RWTX_Read(void*, unsigned int, void*, unsigned int, unsigned int*) {
static void* RWTX_Read(void*, unsigned int, void*, unsigned int, unsigned int*) {

}

void TextureRW3_Unload(void*, U32)
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 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 Anim_ATBL_getTable(xAnimTable* (*param)(void))
{
*param();
}

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,
Expand Down