diff --git a/src/SB/Core/x/xSGT.cpp b/src/SB/Core/x/xSGT.cpp new file mode 100644 index 0000000..13e03b2 --- /dev/null +++ b/src/SB/Core/x/xSGT.cpp @@ -0,0 +1,75 @@ +S32 xSGT_LoadPrefsCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_READCONTEXT* rctxt, U32 ui, + S32 i) +{ + U32 stereo; + + xSGReadData(xsgdata, rctxt, &stereo, 1); + xSGReadData(xsgdata, rctxt, &gSnd.categoryVolFader[2], 1); + xSGReadData(xsgdata, rctxt, &gSnd.categoryVolFader[0], 1); + xSGReadData(xsgdata, rctxt, &globals.option_vibration, 1); + if (globals.option_vibration != 0) + { + xPadRumbleEnable(globals.currentActivePad, 1); + } + else + { + xPadRumbleEnable(globals.currentActivePad, 0); + } + return 1; +} + +S32 xSGT_LoadLoadCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_READCONTEXT* rctxt, U32 ui, + S32 i) +{ + char bigbuf[32] = {}; + S32 compdiff = 0; + + xSGReadData(xsgdata, rctxt, bigbuf, 1, strlen(currSceneStr)); + if (strlen(currSceneStr) != strlen(bigbuf)) + { + compdiff = 1; + } + if (compdiff == 0) + { + strcpy(sceneRead, bigbuf); + } + + return compdiff == 0; +} + +S32 xSGT_SaveProcPrefsCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_WRITECONTEXT* wctxt) +{ + int sum = 0; + sum += xSGWriteData(xsgdata, wctxt, &gSnd.stereo, 1); + sum += xSGWriteData(xsgdata, wctxt, &gSnd.categoryVolFader[2], 1); + sum += xSGWriteData(xsgdata, wctxt, &gSnd.categoryVolFader[0], 1); + sum += xSGWriteData(xsgdata, wctxt, &globals.option_vibration, 1); + return sum + 1; +} + +S32 xSGT_SaveInfoPrefsCB(void* p1, st_XSAVEGAME_DATA* data, S32* i, S32* j) +{ + *i = 16; + *j = *i * 2; + return 1; +} + +S32 xSGT_SaveProcCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_WRITECONTEXT* wctxt) +{ + if (globals.sceneCur->sceneID == 'PG12') + { + strcpy(currSceneStr, xUtil_idtag2string('HB01', 0)); + } + else + { + strcpy(currSceneStr, xUtil_idtag2string(globals.sceneCur->sceneID, 0)); + } + return xSGWriteData(xsgdata, wctxt, currSceneStr, 1, strlen(currSceneStr)) + 1; +} + +S32 xSGT_SaveInfoCB(void* vp, st_XSAVEGAME_DATA* xsgdata, S32* need, S32* most) +{ + *need = xSGWriteStrLen(currSceneStr); + *most = *need << 1; + return 1; +} diff --git a/src/SB/Game/zActionLine.cpp b/src/SB/Game/zActionLine.cpp new file mode 100644 index 0000000..269f708 --- /dev/null +++ b/src/SB/Game/zActionLine.cpp @@ -0,0 +1 @@ +#include "zActionLine.h" diff --git a/src/SB/Game/zAnimList.cpp b/src/SB/Game/zAnimList.cpp new file mode 100644 index 0000000..d2751f5 --- /dev/null +++ b/src/SB/Game/zAnimList.cpp @@ -0,0 +1 @@ +#include "zAnimList.h" diff --git a/src/SB/Game/zAssetTypes.cpp b/src/SB/Game/zAssetTypes.cpp new file mode 100644 index 0000000..6cd1c05 --- /dev/null +++ b/src/SB/Game/zAssetTypes.cpp @@ -0,0 +1,2 @@ +// TODO: Set up all the headers that this one includes +//#include "zAssetTypes.h" diff --git a/src/SB/Game/zAsync.cpp b/src/SB/Game/zAsync.cpp new file mode 100644 index 0000000..f6aeaef --- /dev/null +++ b/src/SB/Game/zAsync.cpp @@ -0,0 +1 @@ +#include "zAsync.h" diff --git a/src/SB/Game/zAsync.h b/src/SB/Game/zAsync.h new file mode 100644 index 0000000..7f1809e --- /dev/null +++ b/src/SB/Game/zAsync.h @@ -0,0 +1,4 @@ +#ifndef ZASYNC_H +#define ZASYNC_H + +#endif diff --git a/src/SB/Game/zBusStop.cpp b/src/SB/Game/zBusStop.cpp new file mode 100644 index 0000000..252e624 --- /dev/null +++ b/src/SB/Game/zBusStop.cpp @@ -0,0 +1 @@ +#include "zBusStop.h" diff --git a/src/SB/Game/zBusStop.h b/src/SB/Game/zBusStop.h new file mode 100644 index 0000000..99507e3 --- /dev/null +++ b/src/SB/Game/zBusStop.h @@ -0,0 +1,4 @@ +#ifndef ZBUSSTOP_H +#define ZBUSSTOP_H + +#endif diff --git a/src/SB/Game/zCam.cpp b/src/SB/Game/zCam.cpp new file mode 100644 index 0000000..de3c88c --- /dev/null +++ b/src/SB/Game/zCam.cpp @@ -0,0 +1 @@ +#include "zCam.h" diff --git a/src/SB/Game/zCam.h b/src/SB/Game/zCam.h new file mode 100644 index 0000000..307c080 --- /dev/null +++ b/src/SB/Game/zCam.h @@ -0,0 +1,4 @@ +#ifndef ZCAM_H +#define ZCAM_H + +#endif diff --git a/src/SB/Game/zCamCar.cpp b/src/SB/Game/zCamCar.cpp new file mode 100644 index 0000000..cf69548 --- /dev/null +++ b/src/SB/Game/zCamCar.cpp @@ -0,0 +1 @@ +#include "zCamCar.h" diff --git a/src/SB/Game/zCamCar.h b/src/SB/Game/zCamCar.h new file mode 100644 index 0000000..bb4ad04 --- /dev/null +++ b/src/SB/Game/zCamCar.h @@ -0,0 +1,4 @@ +#ifndef ZCAMCAR_H +#define ZCAMCAR_H + +#endif diff --git a/src/SB/Game/zCamDrive.cpp b/src/SB/Game/zCamDrive.cpp new file mode 100644 index 0000000..c6d6c0b --- /dev/null +++ b/src/SB/Game/zCamDrive.cpp @@ -0,0 +1 @@ +#include "zCamDrive.h" diff --git a/src/SB/Game/zCamDrive.h b/src/SB/Game/zCamDrive.h new file mode 100644 index 0000000..81585cc --- /dev/null +++ b/src/SB/Game/zCamDrive.h @@ -0,0 +1,4 @@ +#ifndef ZCAMDRIVE_H +#define ZCAMDRIVE_H + +#endif diff --git a/src/SB/Game/zCamMarker.cpp b/src/SB/Game/zCamMarker.cpp new file mode 100644 index 0000000..b41aae8 --- /dev/null +++ b/src/SB/Game/zCamMarker.cpp @@ -0,0 +1 @@ +#include "zCamMarker.h" diff --git a/src/SB/Game/zCamSB.cpp b/src/SB/Game/zCamSB.cpp new file mode 100644 index 0000000..24a6419 --- /dev/null +++ b/src/SB/Game/zCamSB.cpp @@ -0,0 +1 @@ +#include "zCamSB.h" diff --git a/src/SB/Game/zCamSB.h b/src/SB/Game/zCamSB.h new file mode 100644 index 0000000..38e2311 --- /dev/null +++ b/src/SB/Game/zCamSB.h @@ -0,0 +1,14 @@ +#ifndef ZCAMSB_H +#define ZCAMSB_H + +#include "xCamera.h" + +struct zCamSB : xCam +{ + void update(F32 dt); + void start(); + void destroy(); + void create(); +}; + +#endif diff --git a/src/SB/Game/zCamera.cpp b/src/SB/Game/zCamera.cpp new file mode 100644 index 0000000..e22df66 --- /dev/null +++ b/src/SB/Game/zCamera.cpp @@ -0,0 +1,81 @@ +#include "zCamera.h" + +namespace +{ + WallJumpViewState wall_jump_enabled; + bool lassocam_enabled; + U32 stop_track; + bool input_enabled = true; + F32 dMultiplier; + F32 dOffset; + F32 hMultiplier; + F32 hOffset; + zCamSB* follow_cam; +} // namespace + +void zCameraReset(xCamera* cam) +{ + zcam_mode = 0; + zcam_bbounce = 0; + zcam_lbbounce = 0; + zcam_lconvers = 0; + zcam_longbounce = 0; + zcam_highbounce = 0; + zcam_convers = 0; + zcam_fly = 0; + zcam_flypaused = 0; + zcam_cutscene = 0; + zcam_reward = 0; + + zcam_fovcurr = 75.0f; + zcam_overrot_tmr = 0.0f; + wall_jump_enabled = WJVS_DISABLED; + lassocam_enabled = '\0'; + stop_track = 0; + zcam_mintgtheight = -1e+38f; + zcam_centering = '\0'; + zcam_lastcentering = '\0'; + sNearToggleEnabled = '\0'; + + cam->fov = 75.0f; + + sCamTweakLerp -= 0.0f / sCamTweakTime; + if (sCamTweakLerp < 0.0f) + { + sCamTweakLerp = 0.0f; + } + + sCamTweakPitchCur = + sCamTweakPitch[1] * sCamTweakLerp + sCamTweakPitch[0] * (1.0f - sCamTweakLerp); + + sCamTweakDistMultCur = + sCamTweakDistMult[1] * sCamTweakLerp + sCamTweakDistMult[0] * (1.0f - sCamTweakLerp); + + zCamTweakLook* tweak = (zcam_near != 0) ? &zcam_neartweak : &zcam_fartweak; + + sCamD = sCamTweakDistMultCur * tweak->dist * icos(tweak->pitch + sCamTweakPitchCur); + sCamH = sCamTweakDistMultCur * tweak->dist * isin(tweak->pitch + sCamTweakPitchCur) + tweak->h; + sCamPitch = tweak->pitch + sCamTweakPitchCur; + + F32 dist = (zcam_highbounce != 0) ? zcam_highbounce_d : + (wall_jump_enabled == WJVS_ENABLED ? zcam_wall_d : sCamD); + F32 camDist = dMultiplier * dist + dOffset; + F32 height = (zcam_highbounce != 0) ? zcam_highbounce_h : + (wall_jump_enabled == WJVS_ENABLED ? zcam_wall_h : sCamH); + F32 camHeight = dMultiplier * height + dOffset; + + F32 pitch = (zcam_highbounce != 0) ? zcam_highbounce_pitch : sCamPitch; + + xCameraReset(cam, camDist, camHeight, pitch); + + input_enabled = true; + dMultiplier = 1.0f; + dOffset = 0.0f; + hMultiplier = 1.0f; + hOffset = 0.0f; + + if (follow_cam != NULL) + { + follow_cam->cfg_common.priority = '\0'; + } +} diff --git a/src/SB/Game/zCamera.h b/src/SB/Game/zCamera.h index 1d33f20..de3144e 100644 --- a/src/SB/Game/zCamera.h +++ b/src/SB/Game/zCamera.h @@ -1,7 +1,7 @@ #ifndef ZCAMERA_H #define ZCAMERA_H -#include "xCamera.h" +#include "zCamSB.h" enum WallJumpViewState { @@ -31,6 +31,13 @@ struct zFlyKey F32 focal; }; +struct zCamTweakLook +{ + F32 h; + F32 dist; + F32 pitch; +}; + extern F32 zcam_overrot_tmr; extern S32 zcam_near; extern S32 zcam_mode; @@ -90,6 +97,22 @@ extern F32 zcam_overrot_velmax; extern F32 zcam_overrot_tmanual; extern F32 zcam_mintgtheight; + +U8 zcam_centering; +U8 zcam_lastcentering; +bool sNearToggleEnabled; +F32 sCamTweakLerp; +F32 sCamTweakTime; +F32 sCamTweakPitchCur; +F32 sCamTweakPitch[2]; +F32 sCamTweakDistMultCur; +F32 sCamTweakDistMult[2]; +static zCamTweakLook zcam_neartweak; +static zCamTweakLook zcam_fartweak; +F32 sCamD; +F32 sCamH; +F32 sCamPitch; + void zCameraReset(xCamera* cam); void zCameraSetBbounce(S32 bbouncing); void zCameraSetHighbounce(S32 hbounce); diff --git a/src/SB/Game/zCameraFly.cpp b/src/SB/Game/zCameraFly.cpp new file mode 100644 index 0000000..24ff4a1 --- /dev/null +++ b/src/SB/Game/zCameraFly.cpp @@ -0,0 +1 @@ +#include "zCameraFly.h" diff --git a/src/SB/Game/zCameraTweak.cpp b/src/SB/Game/zCameraTweak.cpp new file mode 100644 index 0000000..aa6c6d5 --- /dev/null +++ b/src/SB/Game/zCameraTweak.cpp @@ -0,0 +1 @@ +#include "zCameraTweak.h" diff --git a/src/SB/Game/zCar.cpp b/src/SB/Game/zCar.cpp new file mode 100644 index 0000000..0b186bd --- /dev/null +++ b/src/SB/Game/zCar.cpp @@ -0,0 +1,63 @@ +#include "zCar.h" + +// Refrain from doing these functions until the zCar struct is fixed. + +#define Car 1 +#define Idle01 2 +#define Drive 3 +#define DriveSlippy 4 +#define Boosting 5 +#define Reversing 6 +#define Crash 7 +#define SpinLeft 8 +#define SpinRight 9 +#define Success 10 +#define Failed 11 +#define Death 12 +#define Jump 13 +#define JumpLandSquash 14 + +#define ANIM_COUNT 78 +extern U32 g_hash_caranim[ANIM_COUNT]; +const char* g_strz_caranim[ANIM_COUNT]; + +// Needs the functions calls updated +// NewState and DefaultBeforeEnter do not have correct amount of params yet + +xAnimTable* CreateAnimTable() +{ + S32 ourAnims[32] = { + // clang-format off + Car, + Idle01, + Drive, + DriveSlippy, + Boosting, + Reversing, + Crash, + SpinLeft, + SpinRight, + Success, + Failed, + Death, + Jump, + JumpLandSquash, + + // clang-format on + }; + + xAnimTable* table = xAnimTableNew("stop0", 0); + + xAnimTableNewState(table, "Car", 0x10, 0, 1.0f, NULL, NULL, 0.0f, NULL, NULL, + xAnimDefaultBeforeEnter, NULL, NULL); +} + +U32 zCar::JumpEndedCB(xAnimTransition* unk0, xAnimSingle* anim, void* unk3) +{ + zCar* pCar = zEntPlayerCarGetCar(); +} + +U32 zCar::AnimDefaultCB(xAnimTransition* unk0, xAnimSingle* anim, void*) +{ + zCar* pCar = zEntPlayerCarGetCar(); +} diff --git a/src/SB/Game/zCollGeom.cpp b/src/SB/Game/zCollGeom.cpp new file mode 100644 index 0000000..bdd211d --- /dev/null +++ b/src/SB/Game/zCollGeom.cpp @@ -0,0 +1,143 @@ +#include "zCollGeom.h" + +static volatile U32 sNumTables; +static U32 sTableCount[3]; +static zCollGeomTable* sTableList[3]; + +void zCollGeom_CamDisable(xEnt* ent) +{ + ent->camcollModel = NULL; +} + +void zCollGeom_CamEnable(xEnt* ent) +{ + if (!ent->camcollModel) + { + ent->camcollModel = ent->model; + } +} + +void zCollGeom_Init() +{ + sNumTables = xSTAssetCountByType('COLL'); + + if (sNumTables) + { + U32 tmpsize, i, k; + void* data; + + for (k = 0; k < sNumTables; k++) + { + data = xSTFindAssetByType('COLL', k, &tmpsize); + + if (!data) + { + break; + } + + sTableCount[k] = *(U32*)data; + + if (!sTableCount[k]) + { + sTableList[k] = NULL; + break; + } + + sTableList[k] = (zCollGeomTable*)((U32*)data + 1); + + for (i = 0; i < sTableCount[k]; i++) + { + if ((U32)sTableList[k][i].baseModel) + { + sTableList[k][i].baseModel = + (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].baseModel, NULL); + } + + if ((U32)sTableList[k][i].colModel[0]) + { + sTableList[k][i].colModel[0] = + (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].colModel[0], NULL); + } + + if (!sTableList[k][i].colModel[0]) + { + if (sTableList[k][i].camcolModel) + { + sTableList[k][i].camcolModel = + (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].camcolModel, NULL); + } + } + } + } + } +} + +// PORTED FROM BATTLE, GOOD REFERENCE +U32 zCollGeom_EntSetup(xEnt* ent) +{ + U32 i, j; + S32 auto_cam_coll; + + auto_cam_coll = (ent->baseType == eBaseTypeStatic); + + ent->collModel = NULL; + ent->camcollModel = NULL; + + if (ent->model) + { + for (j = 0; j < sNumTables; j++) + { + for (i = 0; i < sTableCount[j]; i++) + { + if (sTableList[j][i].baseModel == ent->model->Data) + { + RpAtomic* imodel; + + if (imodel = sTableList[j][i].colModel[0]) + { + xModelInstance* model = xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL); + + ent->collModel = model; + ent->collModel->Mat = ent->model->Mat; + + while (imodel = iModelFile_RWMultiAtomic(imodel)) + { + xModelInstanceAttach(xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL), + model); + } + } + else if (imodel = sTableList[j][i].camcolModel) + { + xModelInstance* model = xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL); + + ent->camcollModel = model; + ent->camcollModel->Mat = ent->model->Mat; + + while (imodel = iModelFile_RWMultiAtomic(imodel)) + { + xModelInstanceAttach(xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL), + model); + } + } + else + { + auto_cam_coll = 0; + } + } + } + } + } + + if (auto_cam_coll && !ent->camcollModel) + { + ent->camcollModel = ent->model; + } + + if (ent->collModel) + { + return 1; + } + + ent->collModel = ent->model; + return 0; +} diff --git a/src/SB/Game/zCombo.cpp b/src/SB/Game/zCombo.cpp new file mode 100644 index 0000000..449350d --- /dev/null +++ b/src/SB/Game/zCombo.cpp @@ -0,0 +1 @@ +#include "zCombo.h" diff --git a/src/SB/Game/zConditional.cpp b/src/SB/Game/zConditional.cpp new file mode 100644 index 0000000..f9d1216 --- /dev/null +++ b/src/SB/Game/zConditional.cpp @@ -0,0 +1,32 @@ +#include "zConditional.h" + +S32 zConditionalEventCB(xBase*, xBase*, U32, const F32*, xBase*); + +void zConditionalLoad(_zConditional* ent, xSerial* s) +{ + xBaseLoad(ent, s); +} + +void zConditionalSave(_zConditional* ent, xSerial* s) +{ + xBaseSave(ent, s); +} + +void zConditionalInit(void* b, void* asset) +{ + _zConditional* cond = (_zConditional*)b; + + xBaseInit((xBase*)cond, (xBaseAsset*)asset); + //cond->eventFunc = (xBaseEventCB)zConditionalEventCB; + //cond->asset = asset; + + if (cond->linkCount != 0) + { + cond->link = (xLinkAsset*)(cond->asset + 1); + } + else + { + cond->link = NULL; + } + zVarInit(zVarEntryTable); +} diff --git a/src/SB/Game/zConfig.cpp b/src/SB/Game/zConfig.cpp new file mode 100644 index 0000000..a6b4e1e --- /dev/null +++ b/src/SB/Game/zConfig.cpp @@ -0,0 +1,23 @@ +#include "zConfig.h" + +#include + +U8 zConfig_isPlayerPatrick(ePlayerEnum playerEnum) +{ + U8 isPatrick = 0; + if ((playerEnum >= 10) && (playerEnum <= 0x15)) + { + isPatrick = 1; + } + return isPatrick; +} + +U8 zConfig_isPlayerSpongebob(ePlayerEnum playerEnum) +{ + U8 isSpongebob = 0; + if ((playerEnum >= 0) && (playerEnum <= 10)) + { + isSpongebob = 1; + } + return isSpongebob; +} diff --git a/src/SB/Game/zCutsceneMgr.cpp b/src/SB/Game/zCutsceneMgr.cpp new file mode 100644 index 0000000..40ca7a3 --- /dev/null +++ b/src/SB/Game/zCutsceneMgr.cpp @@ -0,0 +1,160 @@ +#include "zCutsceneMgr.h" + +static S32 gCutsceneSkipOK; +static S32 donpcfx; +static U8 ents_hidden; +static S32 s_atomicNumber; + +void zCutsceneMgrUpdate(xBase* to, xScene* sc, F32 dt) +{ + zCutsceneMgr* t = (zCutsceneMgr*)to; + if (t->csn->ShutDownWait) + { + if (donpcfx) + { + zNPCFXCutsceneDone(sc, dt, t); + } + donpcfx = 0; + if (xCutscene_Destroy(t->csn)) + { + zCutsceneMgrKillFX(t); + t->csn = NULL; + globals.cmgr = NULL; + xCameraSetFOV(&globals.oldSkoolCamera, t->oldfov); + } + } + else + { + if (t->csn->Ready) + { + if (!donpcfx) + { + donpcfx = zNPCFXCutscenePrep(sc, dt, t); + } + if (donpcfx) + { + zNPCFXCutscene(sc, dt, t); + } + + zCutsceneMgrUpdateFX(t); + if (t->stop || !xCutscene_Update(t->csn, dt)) + { + if (!t->stop) + { + zEntEvent(to, to, 0x13); + } + + t->csn->PlaybackSpeed = 0.0f; + //zEntEvent(&globals.player.ent, 9); + //zEntEvent(&globals.player.ent, 3); + zEntEvent(to, to, 0xbf); + iCameraSetNearFarClip(0.0f, 0.0f); + + if ((globals.sceneCur->pendingPortal)) + { + //zEntEvent(&globals.player.ent, 8); + //zEntEvent(&globals.player.ent, 4); + xSndStopAll(0xffff); + return; + } + + if (donpcfx) + { + zNPCFXCutsceneDone(sc, dt, t); + } + donpcfx = 0; + + if (xCutscene_Destroy(t->csn)) + { + zCutsceneMgrKillFX(t); + t->csn = NULL; + globals.cmgr = NULL; + xCameraSetFOV(&globals.oldSkoolCamera, t->oldfov); + } + + zMusicUnpause(0); + } + else + { + if (gCutsceneSkipOK && t->csn->Time > gSkipTimeCutscene && + globals.pad0->pressed & 0x50000) + { + zEntEvent(to, to, 0x13); + } + } + } + else + { + iCSLoadStep(t->csn); + if (t->csn->Ready) + { + zCutsceneMgrPlayStart(t); + zEntEvent(to, to, 0x18); + //zEntEvent(&globals.player.ent, 8); + //zEntEvent(&globals.player.ent, 4); + donpcfx = zNPCFXCutscenePrep(sc, dt, t); + } + } + } + check_hide_entities(); +} + +void zCutsceneMgrFinishExit(xBase* to) +{ + zCutsceneMgr* t = (zCutsceneMgr*)to; + + while (1) + { + iFileAsyncService(); + xSndUpdate(); + if (t->csn->Waiting == 0) + break; + iVSync(); + } + if (donpcfx != 0) + { + zNPCFXCutsceneDone(globals.sceneCur, 0.0f, t); + } + donpcfx = 0; + if (xCutscene_Destroy(t->csn) == 0) + { + return; + } + + //zEntEvent(&globals.player.ent, 9); + //zEntEvent(&globals.player.ent, 3); + zCutsceneMgrKillFX(t); + t->csn = NULL; + globals.cmgr = NULL; +} + +void zCutsceneMgrFinishLoad(xBase* to) +{ + zCutsceneMgr* t = (zCutsceneMgr*)to; + + while (true) + { + iFileAsyncService(); + xSndUpdate(); + iCSLoadStep(t->csn); + iTRCDisk::CheckDVDAndResetState(); + if (t->csn->Ready) + { + break; + } + iVSync(); + } + zCutsceneMgrPlayStart(t); + zEntEvent(to, to, 0x18); + //zEntEvent(&globals.player.ent, 8); + //zEntEvent(&globals.player.ent, 4); + return; +} + +void zCutsceneMgrLoad(zCutsceneMgr*, xSerial* s) +{ +} + +void zCutsceneMgrSave(zCutsceneMgr*, xSerial* s) +{ +} diff --git a/src/SB/Game/zDestructible.cpp b/src/SB/Game/zDestructible.cpp new file mode 100644 index 0000000..fd6a8a1 --- /dev/null +++ b/src/SB/Game/zDestructible.cpp @@ -0,0 +1 @@ +#include "zDestructible.h" diff --git a/src/SB/Game/zDestructible.h b/src/SB/Game/zDestructible.h new file mode 100644 index 0000000..ee67bb1 --- /dev/null +++ b/src/SB/Game/zDestructible.h @@ -0,0 +1,4 @@ +#ifndef ZDESTRUCTIBLE_H +#define ZDESTRUCTIBLE_H + +#endif diff --git a/src/SB/Game/zDiscoFloor.cpp b/src/SB/Game/zDiscoFloor.cpp new file mode 100644 index 0000000..3d1419c --- /dev/null +++ b/src/SB/Game/zDiscoFloor.cpp @@ -0,0 +1 @@ +#include "zDiscoFloor.h" diff --git a/src/SB/Game/zDispatcher.cpp b/src/SB/Game/zDispatcher.cpp new file mode 100644 index 0000000..256b7e0 --- /dev/null +++ b/src/SB/Game/zDispatcher.cpp @@ -0,0 +1,489 @@ +#include "zDispatcher.h" + +#include "iTRC.h" +#include "iSystem.h" +#include "iCutscene.h" +#include "zNPCFXCinematic.h" +#include "xCM.h" +#include "zMusic.h" +#include "xScrFx.h" +#include "zSaveLoad.h" +#include "zHud.h" +#include "zRumble.h" +#include "zVar.h" +#include "zGameState.h" +#include "xIni.h" + +extern st_ZDISPATCH_CONTEXT lbl_80254E00; +extern char lbl_80254E10[512]; + +extern S32 g_zdsp_init; +extern S32 warned_zDispatcher; +extern signed char init_zDispatcher; +extern S32 oldVibrationOption; +extern U32 oldSoundMode; +extern U32 oldMusicVolume; +extern U32 oldSFXVolume; + +extern st_ZDISPATCH_DEPOT g_zdsp_depot; + +extern iColor_tag _1143; + +extern iColor_tag _1142; +extern F32 _1179; +extern F32 _1180; +extern F32 _1181; +extern F32 _1197; +extern F64 _1199; + +extern U8 menu_fmv_played; +extern char zEventLogBuf[256][20]; + +S16 zDispatcher_GetCurrentWorld() +{ +} + +U32 zDispatcher_FindNextValidWorld(U32 sceneID) +{ + char sceneName[4]; + S32 worldIndex; + S32 i; + S32 j; + S32 newIndex; +} + +U32 zDispatcher_FindTaskPointer(U32 sceneID, S32 task) +{ + char sceneName[4]; + S32 i; + S32 j; +} + +void zDispatcher_FindWorldTask(U32 sceneID, S32& world, S32& task) +{ + char sceneName[4]; + S32 i; + S32 j; +} + +// WIP +// FIXME: This switch is a mess, good luck. + +// PORTED DIRECTLY FROM BFBB +// NEEDS A LOT OF WORK +S32 ZDSP_elcb_event(xBase*, xBase* xb, U32 toEvent, const F32* toParam, xBase* toParamWidget) +{ + st_ZDISPATCH_DATA* dspdata = (st_ZDISPATCH_DATA*)xb; + switch (toEvent) + { + case 10: + ZDSP_instReset(dspdata, globals.sceneCur); + break; + case 0x129: + zMusicNotifyEvent(toParam, toParamWidget); + break; + case 0x60: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 0); + break; + case 0x61: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 1); + break; + case 0x62: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 2); + break; + case 0x63: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 3); + break; + case 0x64: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_VIBESET, 1); + break; + case 0x65: + ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_VIBESET, 0); + break; + case 0x66: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDMOD_SET, 0); + break; + case 0x67: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDMOD_SET, 1); + break; + + case 0x68: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDVOL_INCR); + break; + case 0x69: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDVOL_DECR); + break; + case 0x6a: + ZDSP_injectCmd(dspdata, ZDSP_CMD_MUSVOL_INCR); + break; + case 0x6b: + ZDSP_injectCmd(dspdata, ZDSP_CMD_MUSVOL_DECR); + break; + + case 0x6c: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SFXVOL_INCR); + break; + case 0x6d: + ZDSP_injectCmd(dspdata, ZDSP_CMD_SFXVOL_DECR); + break; + case 0xa9: + zGameStateSwitchEvent(toEvent); + break; + case 0x9e: + globals.currentActivePad = 0; + zGameStateSwitchEvent(0x9e); + break; + case 0xa7: + break; + case 0xa8: + zSaveLoad_DispatchCB(toEvent, toParam); + break; + + case 0xc2: + zEntPlayer_SNDPlay(ePlayerSnd_CheckPoint, _1179); + F32 fVar2; + if (*toParam != _1179) + { + fVar2 = _1180 * *toParam; + } + else + { + //fVar2 = globals.player.ent.frame->rot.angle; + } + zEntPlayer_StoreCheckPoint((xVec3*)toParamWidget, fVar2, globals.oldSkoolCamera.id); + break; + case 0x11e: + zhud::show(); + break; + case 0x11f: + zhud::hide(); + break; + case 0x120: + iColor_tag black = _1142; + iColor_tag clear = _1143; + xScrFxFade(&clear, &black, *toParam, 0, 1); + break; + case 0x126: + menu_fmv_played = 1; + //zFMVPlay(zFMVFileGetName((eFMVFile)(U32)*toParam), 0x10001, _1181, 1, 0); + break; + case 0x130: + zSceneEnableScreenAdj(1); + zSceneSetOldScreenAdj(); + break; + case 0x131: + zSceneEnableScreenAdj(0); + break; + case 0x101: + globals.player.g.PowerUp[(int)*toParam] = 1; + break; + + case 0x1fd: + xCameraFXShake(*toParam, toParam[1], toParam[2], toParam[3], _1179, NULL, NULL); + break; + case 0x210: + xCMstart((xCreditsData*)toParamWidget, *toParam, xb); + break; + + case 0x211: + xCMstop(); + break; + + case 0x217: + char events[512]; + U32 c; + U32 len; + U32 i; + char log[512]; + + for (i = 0; i < 512; i++) + { + events[i] = lbl_80254E10[i]; + } + + c = 0; + for (i = 0; i < 8; i += len) + { + c += 1; + len = strlen((char*)&ringlist[i]); + } + + strcpy(lbl_80254E10, zEventLogBuf[c + 1]); + for (i = c + 2; i < 0x13; i++) + { + strcat(log, zEventLogBuf[i]); + } + strncpy(events, log, 0x200); + break; + case 0x21b: + zDispatcherStoreOptions(); + break; + + case 0x21c: + zDispatcherRestoreOptions(); + break; + } + return 1; +} + +S32 ZDSP_doCommand(st_ZDISPATCH_DATA* dspdata, st_ZDISPATCH_CONTEXT* cmdCtxt) +{ + S32 iv; + en_DISPATCH_COMMAND cmd = cmdCtxt->cmd; + void* indata = cmdCtxt->indata; + void* result = cmdCtxt->result; + + if (init_zDispatcher == 0) + { + warned_zDispatcher = 0; + init_zDispatcher = 1; + } + if (warned_zDispatcher == 0) + { + warned_zDispatcher = 1; + } + + switch (cmd) + { + case ZDSP_CMD_CTRL_CFGGET: + *(S32*)result = 0; + break; + case ZDSP_CMD_CTRL_CFGSET: + if (result != NULL) + { + *(S32*)result = 0; + } + break; + case ZDSP_CMD_CTRL_VIBEGET: + *(S32*)result = zVarEntryCB_VibrationOn(NULL); + break; + case ZDSP_CMD_CTRL_VIBESET: + if (globals.option_vibration != *(S32*)indata) + { + globals.option_vibration = *(S32*)indata; + xPadRumbleEnable(globals.currentActivePad, globals.option_vibration); + zRumbleStart(globals.currentActivePad, SDR_Test); + } + break; + case ZDSP_CMD_SNDMOD_GET: + *(S32*)result = zVarEntryCB_SndMode(NULL); + break; + case ZDSP_CMD_SNDMOD_SET: + if (*(S32*)indata == 0) + { + iSndStereo(0); + } + else if (*(S32*)indata == 1) + { + iSndStereo(1); + } + + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndMode(NULL); + } + break; + case ZDSP_CMD_MUSVOL_GET: + *(S32*)result = zVarEntryCB_SndMusicVol(NULL); + break; + case ZDSP_CMD_MUSVOL_SET: + WRAP_xsnd_setMusicVolume(*(S32*)indata); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndMusicVol(NULL); + } + break; + case ZDSP_CMD_MUSVOL_INCR: + iv = zVarEntryCB_SndMusicVol(NULL); + if (indata != NULL) + { + iv += *(S32*)indata; + } + else + { + iv += 1; + } + WRAP_xsnd_setMusicVolume(iv); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndMusicVol(NULL); + } + break; + case ZDSP_CMD_MUSVOL_DECR: + iv = zVarEntryCB_SndMusicVol(NULL); + if (indata != NULL) + { + iv -= *(S32*)indata; + } + else + { + iv -= 1; + } + WRAP_xsnd_setMusicVolume(iv); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndMusicVol(NULL); + } + break; + case ZDSP_CMD_SFXVOL_GET: + *(S32*)result = zVarEntryCB_SndFXVol(NULL); + break; + case ZDSP_CMD_SFXVOL_SET: + WRAP_xsnd_setSFXVolume(*(S32*)indata); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndFXVol(NULL); + } + break; + case ZDSP_CMD_SFXVOL_INCR: + iv = zVarEntryCB_SndFXVol(NULL); + if (indata != NULL) + { + iv += *(S32*)indata; + } + else + { + iv += 1; + } + WRAP_xsnd_setSFXVolume(iv); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndFXVol(NULL); + } + break; + case ZDSP_CMD_SFXVOL_DECR: + iv = zVarEntryCB_SndFXVol(NULL); + if (indata != NULL) + { + iv -= *(S32*)indata; + } + else + { + iv -= 1; + } + WRAP_xsnd_setSFXVolume(iv); + if (result != NULL) + { + *(S32*)result = zVarEntryCB_SndFXVol(NULL); + } + break; + case ZDSP_CMD_GSTATE_GET: + *(S32*)result = zGameStateGet(); + break; + case ZDSP_CMD_GSTATE_SET: + zGameStateSwitch(*(S32*)indata); + if (result != NULL) + { + *(S32*)result = zGameStateGet(); + } + break; + case ZDSP_CMD_GMODE_GET: + *(S32*)result = zGameModeGet(); + break; + case ZDSP_CMD_GMODE_SET: + zGameModeSwitch(*(eGameMode*)indata); + if (result != NULL) + { + *(S32*)result = zGameModeGet(); + } + break; + case ZDSP_CMD_SNDVOL_GET: + case ZDSP_CMD_SNDVOL_SET: + case ZDSP_CMD_SNDVOL_INCR: + case ZDSP_CMD_SNDVOL_DECR: + case ZDSP_CHECKPNT_SET: + break; + } + return 1; +} + +void zDispatcher_Load(st_ZDISPATCH_DATA* dspdata, xSerial* s) +{ + xBaseLoad(dspdata, s); +} + +void zDispatcher_Save(st_ZDISPATCH_DATA* dspdata, xSerial* s) +{ + xBaseSave(dspdata, s); +} + +void zDispatcher_InitDep(st_ZDISPATCH_DATA* dspdata, zScene* zscn) +{ +} + +void zDispatcher_Init(st_ZDISPATCH_DATA* dspdata, xBaseAsset* bass) +{ + xBaseInit(dspdata, bass); + dspdata->rawass = bass; + //dspdata->eventFunc = ZDSP_elcb_event; + if (dspdata->linkCount != 0) + { + dspdata->link = (xLinkAsset*)(dspdata->rawass + 1); + } + else + { + dspdata->link = NULL; + } +} + +st_ZDISPATCH_DATA* zDispatcher_getInst(st_ZDISPATCH_DATA* pool, S32 idx) +{ + return &pool[idx]; +} + +st_ZDISPATCH_DATA* zDispatcher_memPool(S32 cnt) +{ + st_ZDISPATCH_DATA* pool; + st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; + if (cnt < 1) + { + return NULL; + } + else + { + pool = (st_ZDISPATCH_DATA*)xMemAlloc(gActiveHeap, cnt * sizeof(st_ZDISPATCH_DATA), 0); + memset(pool, 0, cnt * sizeof(st_ZDISPATCH_DATA)); + depot->raw_pool = pool; + depot->raw_cnt = cnt; + return pool; + } +} + +void zDispatcher_sceneFinish() +{ + st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; + + g_zdsp_init--; + if (g_zdsp_init == 0) + { + memset(depot, 0, sizeof(st_ZDISPATCH_DEPOT)); + } +} + +void zDispatcher_scenePrepare() +{ + st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; + if (g_zdsp_init++ == 0) + { + memset(depot, 0, sizeof(st_ZDISPATCH_DEPOT)); + } +} + +void zDispatcher_Shutdown() +{ +} + +void zDispatcher_Startup() +{ +} + +void zDispatcherParseINI(xIniFile* ini) +{ + S32 i; + char itemName[16]; + char value[256]; + char* value_; + S32 j; + char* ltok; + char* tok; +} diff --git a/src/SB/Game/zDust.cpp b/src/SB/Game/zDust.cpp index e69de29..96b9454 100644 --- a/src/SB/Game/zDust.cpp +++ b/src/SB/Game/zDust.cpp @@ -0,0 +1 @@ +#include "zDust.h" diff --git a/src/SB/Game/zDust.h b/src/SB/Game/zDust.h new file mode 100644 index 0000000..b7e6af8 --- /dev/null +++ b/src/SB/Game/zDust.h @@ -0,0 +1,4 @@ +#ifndef ZDUST_H +#define ZDUST_H + +#endif diff --git a/src/SB/Game/zEGenerator.cpp b/src/SB/Game/zEGenerator.cpp new file mode 100644 index 0000000..a46e49f --- /dev/null +++ b/src/SB/Game/zEGenerator.cpp @@ -0,0 +1,93 @@ +#include "zEGenerator.h" + +void zEGenerator_TurnOn(zEGenerator* egen) +{ + zEGenAsset* zasset; + xAnimPlay* aplay; + xAnimSingle* asing; + U16 itgt; + U16 imp; + S32 i; + xLinkAsset* link; + U32 dstAssetID; + xBase* b; + xVec3 destOffset; + xEnt* ent; + //S32 i; + _tagLightningAdd add; +} + +void zEGenerator_Render(zEGenerator* egen) +{ + xEntRender(egen); +} + +void zEGenerator_Update(zEGenerator* egen, xScene* sc, F32 dt) +{ + xBase* b; + zEnt* ent; +} + +void zEGenerator_Move(zEGenerator* egen, xScene* xscn, F32 tmpFloat) +{ +} + +void zEGenerator_Reset(zEGenerator* egen, xScene* xscn) +{ + zEntReset((zEnt*)egen); + zEGenAsset* zasset = (zEGenAsset*)egen->asset; + egen->flags = (U16)zasset->flags; + if (egen->flags & 1) + { + zEGenerator_TurnOn(egen); + } + else + { + zEGenerator_TurnOff(egen); + } + if (zasset->moreFlags & 0b100) + { + egen->chkby = XENT_COLLTYPE_NONE; + } + else + { + egen->chkby = XENT_COLLTYPE_PLYR | XENT_COLLTYPE_NPC; + } + egen->bupdate((xEnt*)egen, (xVec3*)&egen->model->Mat->pos); +} + +void zEGenerator_Load(zEGenerator* ent, xSerial* s) +{ + zEntLoad(ent, s); +} + +void zEGenerator_Save(zEGenerator* ent, xSerial* s) +{ + zEntSave(ent, s); +} + +void zEGenerator_Setup(zEGenerator* egen, xScene* xscn) +{ + zEntSetup(egen); + egen->num_dsts = 0; + for (S32 i = 0; i < egen->linkCount; i++) + { + xLinkAsset* la = (xLinkAsset*)&egen->link[i]; + xBase* b = (xBase*)zSceneFindObject(la->dstAssetID); + if (b != NULL && la->dstEvent == 0xc0) + { + if (b->baseType == eBaseTypeMovePoint) + { + egen->num_dsts++; + } + else if (b->baseFlags & 0x20) + { + egen->num_dsts++; + } + } + } +} + +void zEGenerator_Init(void* egen, void* asset) +{ +} diff --git a/src/SB/Game/zEnv.cpp b/src/SB/Game/zEnv.cpp new file mode 100644 index 0000000..b90c469 --- /dev/null +++ b/src/SB/Game/zEnv.cpp @@ -0,0 +1,146 @@ +#include "zEnv.h" + +#include "zGlobals.h" +#include "zLight.h" +#include "xstransvc.h" +#include "xGroup.h" +#include "zSurface.h" + +// DWARF says void zEnvEventCB(xBase* to, U32 toEvent, F32* toParam, xBase* toParamWidget) +void zEnvEventCB(xBase* a0, xBase* a1, U32 a2, const F32* a3, xBase* a4, U32 a5) +{ +} + +void zEnvLoad(_zEnv* ent, xSerial* s) +{ + xBaseLoad(ent, s); +} + +void zEnvSave(_zEnv* ent, xSerial* s) +{ + xBaseSave(ent, s); +} + +void zEnvRender(xEnv* env) +{ + RpWorld* world = env->geom->world; + S32 num = RpWorldGetNumMaterials(world); + + for (S32 i = 0; i < num; i++) + { + xSurface* sp = zSurfaceGetSurface(i); + zSurfaceProps* pp = (zSurfaceProps*)sp->moprops; + + if (pp && pp->asset && pp->texanim_flags & 0x1) + { + RpMaterial* mp = RpWorldGetMaterial(world, i); + + if (mp) + { + xGroup* g = (xGroup*)pp->texanim[0].group_ptr; + + if (g) + { + U32 texid = xGroupGetItem(g, pp->texanim[0].group_idx); + RwTexture* texptr = (RwTexture*)xSTFindAsset(texid, NULL); + + if (texptr) + { + RpMaterialSetTexture(mp, texptr); + } + } + } + } + } + + xEnvRender(env, FALSE); +} + +void zEnvStartingCamera(_zEnv*) +{ + return; +} + +void zEnvSetup(_zEnv* env) +{ + // TODO + // I don't think the struct is correct + + // This function seems to be correct in BFBB, our globals struct is fucked though. + // Keep this the way it is, and fix the struct + + xBaseSetup(env); + iEnvLightingBasics((iEnv*)globals.sceneCur->env->geom, (xEnvAsset*)env->easset); +} + +// Again, Copied from Battle, Needs a good amount of work +void zEnvInit(_zEnv* env, xEnvAsset* easset) +{ + U32 bufsize; + void* buf; + + xBaseInit(env, easset); + + env->easset = easset; + //env->eventFunc = zEnvEventCB; + + if (env->linkCount) + { + env->link = (xLinkAsset*)(env->easset + 1); + } + + globals.sceneCur->zen = env; + globals.sceneCur->zen = env; + + xSTAssetCountByType('BSP '); + + buf = xSTFindAsset(easset->bspAssetID, &bufsize); + + if (buf) + { + xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 0); + } + + zSurfaceRegisterMapper(easset->bspMapperID); + + if (easset->bspCollisionAssetID) + { + buf = xSTFindAsset(easset->bspCollisionAssetID, &bufsize); + + if (buf) + { + xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 1); + } + } + + if (easset->bspFXAssetID) + { + buf = xSTFindAsset(easset->bspFXAssetID, &bufsize); + + if (buf) + { + xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 2); + } + } + + if (easset->bspCameraAssetID) + { + buf = xSTFindAsset(easset->bspCameraAssetID, &bufsize); + + if (buf) + { + xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 3); + } + } + + if (globals.sceneCur->env && globals.sceneCur->env->geom) + { + zLightResetAll(globals.sceneCur->env); + iLightInit(globals.sceneCur->env->geom->world); + } +} + +void zEnvInit(void* env, void* easset) +{ + zEnvInit((_zEnv*)env, (xEnvAsset*)easset); +} diff --git a/src/SB/Game/zEnv.h b/src/SB/Game/zEnv.h index b31d2c1..e8e25fb 100644 --- a/src/SB/Game/zEnv.h +++ b/src/SB/Game/zEnv.h @@ -5,7 +5,7 @@ #include "xEnv.h" #include "iEnv.h" -void zEnvEventCB(xBase* to, U32 toEvent, F32* toParam, xBase* toParamWidget); +void zEnvEventCB(xBase* a0, xBase* a1, U32 a2, const F32* a3, xBase* a4, U32 a5); void zEnvLoad(_zEnv* ent, xSerial* s); void zEnvSave(_zEnv* ent, xSerial* s); void zEnvRender(xEnv* env); diff --git a/src/SB/Game/zGame.cpp b/src/SB/Game/zGame.cpp new file mode 100644 index 0000000..d6b44b3 --- /dev/null +++ b/src/SB/Game/zGame.cpp @@ -0,0 +1,56 @@ +#include "zGame.h" + +void DoTheResetinator() +{ +} + +void zGameStall() +{ + bool tempGameBool; + if (gGameMode == 8) + { + tempGameBool = TRUE; + } + else if (gGameMode == 7) + { + tempGameBool = TRUE; + } + else if (gGameMode == 6) + { + tempGameBool = TRUE; + } + else if (gGameMode == 2) + { + tempGameBool = TRUE; + } + else if (gGameMode == 4) + { + tempGameBool = TRUE; + } + else if (gGameMode == 6) + { + tempGameBool = TRUE; + } + else if (gGameMode == 1) + { + tempGameBool = TRUE; + } + else if (gGameMode == 0) + { + tempGameBool = TRUE; + } + else + { + tempGameBool = FALSE; + } + + if (!tempGameBool) // chain of if elses + { + zGameModeSwitch(eGameMode_Stall); + xSndMgrPauseSounds(0, TRUE, TRUE); + xSndMgrPauseSounds(1, TRUE, TRUE); + xSndMgrPauseSounds(2, TRUE, FALSE); + iPadStopRumble(globals.pad[1]); + zEntEvent("techbutton6_click", 24); + } +} diff --git a/src/SB/Game/zGameExtras.cpp b/src/SB/Game/zGameExtras.cpp new file mode 100644 index 0000000..e78d824 --- /dev/null +++ b/src/SB/Game/zGameExtras.cpp @@ -0,0 +1,131 @@ +#include "zGameExtras.h" + +void zGameExtras_Load(xSerial* xser) +{ + S32 keepers[2]; + keepers[0] = 0; + xser->Read(keepers); + g_flg_chEnabled |= keepers[0]; +} + +void zGameExtras_Save(xSerial* xser) +{ + xser->Write(g_flg_chEnabled & 0xFFFF); +} + +S32 zGameExtras_CheatFlags() +{ + return g_flg_chEnabled; +} + +S32 EGG_check_ExtrasFlags(EGGItem*) +{ + switch (g_currMonth) + { + case JANUARY: + if (g_currDay == 1) // New Year's Day + g_gameExtraFlags |= 0b000000001; + break; + + case FEBRUARY: + if (g_currDay == 2) + g_gameExtraFlags |= 0b100000000; + break; + + case MARCH: + if (g_currDay == 15) + g_gameExtraFlags |= 0b000001000; + if (g_currDay == 17) // St. Patrick's Day + g_gameExtraFlags |= 0b000000100; + if (g_currDay == 18) + g_gameExtraFlags |= 0b100000000; + if (g_currDay == 21) + g_gameExtraFlags |= 0b100000000; + if (g_currDay == 22) + g_gameExtraFlags |= 0b100000000; + break; + + case APRIL: + if (g_currDay == 1) // April Fools' Day + g_gameExtraFlags |= 0b010000000; + break; + + case MAY: + break; + + case JUNE: + if (g_currDay == 6) + g_gameExtraFlags |= 0b001000000; + break; + + case JULY: + if (g_currDay == 4) // Independence Day + g_gameExtraFlags |= 0b000000010; + break; + + case AUGUST: + if (g_currDay == 8) + g_gameExtraFlags |= 0b100000000; + break; + + case SEPTEMBER: + if (g_currDay == 8) + g_gameExtraFlags |= 0b000000010; + break; + + case OCTOBER: + if (g_currDay == 5) + g_gameExtraFlags |= 0b100000000; + if (g_currDay == 14) + g_gameExtraFlags |= 0b100000000; + if (g_currDay == 22) + g_gameExtraFlags |= 0b100000000; + if (g_currDay == 31) // Halloween + g_gameExtraFlags |= 0b000100000; + break; + + case NOVEMBER: + if (g_currDay == 5) + g_gameExtraFlags |= 0b100000000; + break; + + case DECEMBER: + break; + } + + return 0; +} + +void zGameExtras_SceneReset() +{ + if (!g_enableGameExtras) + { + return; + } + + EGGItem* egg_next = g_eggBasket; + + while (egg_next->fun_check) + { + EGGItem* egg = egg_next++; + + if (egg->enabled) + { + if (egg->funcs->fun_reset) + { + egg->funcs->fun_reset(egg); + } + } + } +} + +void zGameExtras_MoDay(S32* month, S32* day) +{ + *month = g_currMonth; + *day = g_currDay; +} + +S32 zGameExtras_ExtrasFlags() +{ + return g_gameExtraFlags; +} diff --git a/src/SB/Game/zGameState.cpp b/src/SB/Game/zGameState.cpp new file mode 100644 index 0000000..e784e3b --- /dev/null +++ b/src/SB/Game/zGameState.cpp @@ -0,0 +1,83 @@ +#include "zGameState.h" + +void zGameStatePauseUnpauseSnd(bool pause) +{ + xSndMgrPauseSounds(0, pause, TRUE); + xSndMgrPauseSounds(1, pause, TRUE); + xSndMgrPauseSounds(2, pause, FALSE); +} + +void SB04FMVPauseSoundCB(bool doPause) +{ + bool tempBool; + + if (gGameMode == 8) + { + tempBool = TRUE; + } + else if (gGameMode == 7) + { + tempBool = TRUE; + } + else if (gGameMode == 6) + { + tempBool = TRUE; + } + else if (gGameMode == 2) + { + tempBool = TRUE; + } + else if (gGameMode == 4) + { + tempBool = TRUE; + } + else if (gGameMode == 6) + { + tempBool = TRUE; + } + else if (gGameMode == 1) + { + tempBool = TRUE; + } + else if (gGameMode == 0) + { + tempBool = TRUE; + } + else + { + tempBool = FALSE; + } + + if (tempBool) + { + xSndMgrPauseSounds(3, doPause, TRUE); + } + else if (doPause != 0) + { + xSndMgrPauseSounds(-3, TRUE, TRUE); + } + else + { + xSndMgrPauseSounds(-3, FALSE, TRUE); + } +} + +void zGameSetOstrich(_GameOstrich o) +{ + gGameOstrich = o; +} + +_GameOstrich zGameGetOstrich() +{ + return gGameOstrich; +} + +eGameMode zGameModeGet() +{ + return gGameMode; +} + +S32 zGameStateGet() +{ + return gGameState; +} diff --git a/src/SB/Game/zGoo.cpp b/src/SB/Game/zGoo.cpp new file mode 100644 index 0000000..3787877 --- /dev/null +++ b/src/SB/Game/zGoo.cpp @@ -0,0 +1,14 @@ +#include "zGoo.h" + +void zGooExit() +{ + zgoo_gps = 0; + zgoo_ngps = 0; + zgoo_nused = 0; +} + +void zGooInit(S32 nobj) +{ + zgoo_gps = (zGooParams*)xMemAlloc(gActiveHeap, nobj * 0xc, 0); + zgoo_ngps = nobj; +} diff --git a/src/SB/Game/zGrid.cpp b/src/SB/Game/zGrid.cpp new file mode 100644 index 0000000..1b98f1b --- /dev/null +++ b/src/SB/Game/zGrid.cpp @@ -0,0 +1,10 @@ +#include "zGrid.h" + +void zGridExit(zScene* s) +{ + xGridKill(&colls_grid); + xGridKill(&colls_oso_grid); + xGridKill(&npcs_grid); + xGridKill(&grabbable_grid); + zGridInitted = 0; +} diff --git a/src/SB/Game/zLOD.cpp b/src/SB/Game/zLOD.cpp new file mode 100644 index 0000000..407a6df --- /dev/null +++ b/src/SB/Game/zLOD.cpp @@ -0,0 +1,21 @@ +#include "zLOD.h" + +zLODTable* zLOD_Get(xEnt* ent) +{ + if (!ent->model) + { + return 0; + } + + for (int i = 0; i < sLODTableCount; i++) + { + if (sLODTableList[i].baseBucket != NULL) + { + if ((*sLODTableList[i].baseBucket)->OriginalData == ent->model->Data) + { + return &sLODTableList[i]; + } + } + } + return 0; +} diff --git a/src/SB/Game/zLight.cpp b/src/SB/Game/zLight.cpp new file mode 100644 index 0000000..fc1791f --- /dev/null +++ b/src/SB/Game/zLight.cpp @@ -0,0 +1,80 @@ +#include "zLight.h" + +void zLightSetVolume(zVolume* vol) +{ + if (!vol) + { + sPartitionVolume = 0; + } + else + { + U32 lp_id = xStrHash("LIGHT_PARTITION" + 9); + if (vol->id == lp_id) + { + sPartitionVolume = vol; + } + } +} + +void zLightRemoveLocalEnv() +{ + int i; + const RwLLLink* link; + + for (i = 0; i < gNumTemporaryLights; i++) + { + link = gLightWorld->directionalLightList.link.prev; + link->prev->next = link->next; + link->next->prev = link->prev; + } + gNumTemporaryLights = 0; +} + +void zLightAddLocal(xEnt* ent) +{ +} + +void zLightLoad(_zLight* ent, xSerial* s) +{ + xBaseLoad(ent, s); +} + +void zLightSave(_zLight* ent, xSerial* s) +{ + xBaseSave(ent, s); +} + +void zLightDestroyAll() +{ + S32 total = sLightTotal; + + for (int i = 0; i < total; i++, sLightTotal--) + { + zLightDestroy(sLight[i]); + } + sLightTotal = 0; +} + +void zLightResolveLinks() +{ + S32 i; + _zLight* zl; + + for (i = 0; i < sLightTotal; i++) + { + zl = sLight[i]; + if (zl->tasset->attachID) + { + zl->attached_to = zSceneFindObject(zl->tasset->attachID); + } + else + { + zl->attached_to = 0; + } + } +} + +void zLightInit(void* b, void* tasset) +{ + zLightInit((xBase*)b, (zLightAsset*)tasset); +} diff --git a/src/SB/Game/zLightEffect.cpp b/src/SB/Game/zLightEffect.cpp new file mode 100644 index 0000000..e327c38 --- /dev/null +++ b/src/SB/Game/zLightEffect.cpp @@ -0,0 +1,77 @@ +#include "zLightEffect.h" + +void zLightEffectInitCauldron(_zLight* zlight) +{ + *zlight->reg = 0.0f; + zlight->flags = zlight->flags | 1; +} + +void zLightEffectRandomColFast(_zLight* zlight, F32) +{ +} + +void zLightEffectRandomCol(_zLight* zlight, F32) +{ +} + +void zLightEffectRandomColSlow(_zLight* zlight, F32) +{ +} + +void zLightEffectHalfDimFast(_zLight* zlight, F32) +{ +} + +void zLightEffectHalfDim(_zLight* zlight, F32) +{ +} + +void zLightEffectHalfDimSlow(_zLight* zlight, F32) +{ +} + +void zLightEffectDimFast(_zLight* zlight, F32) +{ +} + +void zLightEffectDim(_zLight* zlight, F32) +{ +} + +void zLightEffectDimSlow(_zLight* zlight, F32) +{ +} + +void zLightEffectStrobeFast(_zLight* zlight, F32) +{ +} + +void zLightEffectStrobe(_zLight* zlight, F32) +{ +} + +void zLightEffectStrobeSlow(_zLight* zlight, F32) +{ +} + +void zLightEffectInitFlicker(_zLight* zlight) +{ + *zlight->reg = 0.0f; + zlight->flags = zlight->flags | 1; +} + +void zLightEffectInitRandomCol(_zLight*) +{ +} + +void zLightEffectInitHalfDim(_zLight*) +{ +} + +void zLightEffectInitDim(_zLight*) +{ +} + +void zLightEffectInitStrobe(_zLight*) +{ +} diff --git a/src/SB/Game/zLightWeight.cpp b/src/SB/Game/zLightWeight.cpp new file mode 100644 index 0000000..119c379 --- /dev/null +++ b/src/SB/Game/zLightWeight.cpp @@ -0,0 +1,7 @@ +#include "zLightWeight.h" + +// These are in the dwarf, but you have to find them with just "lightweight_manager" + +// void z::lightweight_manager::setup() +// { +// } diff --git a/src/SB/Game/zLightWeight.h b/src/SB/Game/zLightWeight.h new file mode 100644 index 0000000..73cf25b --- /dev/null +++ b/src/SB/Game/zLightWeight.h @@ -0,0 +1,4 @@ +#ifndef ZLIGHTWEIGHT_H +#define ZLIGHTWEIGHT_H + +#endif diff --git a/src/SB/Game/zLightning.cpp b/src/SB/Game/zLightning.cpp new file mode 100644 index 0000000..0153d72 --- /dev/null +++ b/src/SB/Game/zLightning.cpp @@ -0,0 +1,9 @@ +#include "zLightning.h" + +void _zLightningKill(zLightning* l) +{ +} + +void zLightningKill(zLightning* l) +{ +} diff --git a/src/SB/Game/zMenu.cpp b/src/SB/Game/zMenu.cpp new file mode 100644 index 0000000..38ba915 --- /dev/null +++ b/src/SB/Game/zMenu.cpp @@ -0,0 +1,42 @@ +// For some reason including this breaks the bitshift in zMenuPause +//#include "zMenu.h" + +void zMenuAllowAtract(bool allowAttract) +{ + sAllowAttract = allowAttract; +} + +void zMenuPause(bool bPause) +{ + S64 time; + U32 Utime; + + if (bPause == FALSE) + { + Utime = iTimeGet(); + time = iTimeDiffSec((U64)Utime >> 0x20); + time_last = time - SECS_PER_VBLANK; + Utime = iTimeGet(); + } + + sTimeLast = Utime >> 0x20; +} + +S32 zMenuIsFirstBoot() +{ + return sFirstBoot; +} + +U32 zMenuGetBadCard() +{ + return card + 1; +} + +void zMenuExit() +{ +} + +S32 zMenuRunning() +{ + return sInMenu; +} diff --git a/src/SB/Game/zNMECommon.cpp b/src/SB/Game/zNMECommon.cpp new file mode 100644 index 0000000..70fbb08 --- /dev/null +++ b/src/SB/Game/zNMECommon.cpp @@ -0,0 +1,5 @@ +#include "zNMECommon.h" + +void zNMECommon::DieTheGoodDeath() +{ +} diff --git a/src/SB/Game/zNMETypeBossDennis.cpp b/src/SB/Game/zNMETypeBossDennis.cpp new file mode 100644 index 0000000..874e405 --- /dev/null +++ b/src/SB/Game/zNMETypeBossDennis.cpp @@ -0,0 +1,31 @@ +#include "zNMETypeBossDennis.h" + +S32 zNMEGoalDenDead::Exit(F32 dt, void* ctxt) +{ +} + +S32 zNMEGoalDenDamage::Exit(F32 dt, void* ctxt) +{ + zNMEDennis& npc = *(zNMEDennis*)this->psyche->clt_owner; + npc.tmr_nextLeap = -1.0f; + return 0; +} + +zNMEGoalDenEvade::PathDirect(zNMEDennis*, F32 dt) +{ +} + +// Return type not in dwarf, Could be wrong +void zNMEDennis::MeterRender() +{ +} + +void zNMEDennis::RenderHud() +{ + zNMEDennis::MeterRender(); +} + +S32 zNMEDennis::DfltVulnFlags() +{ + return 0xc07b0007; // HACKED TOGETHER FOR TESTING PURPOSES +} diff --git a/src/SB/Game/zNMETypeBossDennis.h b/src/SB/Game/zNMETypeBossDennis.h new file mode 100644 index 0000000..58c4ed8 --- /dev/null +++ b/src/SB/Game/zNMETypeBossDennis.h @@ -0,0 +1,4 @@ +#ifndef ZNMETYPEBOSSDENNIS_H +#define ZNMETYPEBOSSDENNIS_H + +#endif diff --git a/src/SB/Game/zNMETypeCritBasic.cpp b/src/SB/Game/zNMETypeCritBasic.cpp new file mode 100644 index 0000000..e52e773 --- /dev/null +++ b/src/SB/Game/zNMETypeCritBasic.cpp @@ -0,0 +1,18 @@ +#include "zNMETypeCritBasic.h" + +void zNMECritBasic::SelfSetup() +{ + xBehaveMgr* bmgr; + xPsyche* psy; + bmgr = xBehaveMgr_GetSelf(); + bmgr->Subscribe(this, 0); + psy = psy_self; + psy->BrainBegin(); + psy->AddGoal('NGC\0', NULL); + psy->AddGoal('NGC\1', NULL); + psy->AddGoal('NGC\4', NULL); + psy->AddGoal('NGC\2', NULL); + psy->AddGoal('NGC\3', NULL); + psy->BrainEnd(); + //*(undefined4 *)(this_01 + 0x44) = 0x4e474300; +} diff --git a/src/SB/Game/zNMETypeCritBasic.h b/src/SB/Game/zNMETypeCritBasic.h new file mode 100644 index 0000000..e6f046e --- /dev/null +++ b/src/SB/Game/zNMETypeCritBasic.h @@ -0,0 +1,4 @@ +#ifndef ZNMETYPECRITBASIC_H +#define ZNMETYPECRITBASIC_H + +#endif diff --git a/src/SB/Game/zNPCMgr.cpp b/src/SB/Game/zNPCMgr.cpp new file mode 100644 index 0000000..bc18f85 --- /dev/null +++ b/src/SB/Game/zNPCMgr.cpp @@ -0,0 +1,116 @@ +#include "zNPCMgr.h" + +struct NPCMTypeTable // ported from bfbb +{ + en_npctyp useNPCType; + char* modelName; + unsigned int hashOfName; +} g_tbltype[250]; + +S32 zNPCMgr_OrdComp_npcid(void* vkey, void* vitem) +{ + S32 rc; + U32 item; + U32 key; + + key = *(U32*)vkey; + item = *(U32*)vitem; + if (key < item) + { + rc = -1; + } + else if (key > item) + { + rc = 1; + } + else + { + rc = 0; + } + + return rc; +} + +// S32 zNPCMgr_OrdTest_npcid(void* vkey, void* vitem) +// { +// S32 rc; +// void* key = *(void**)(vitem); + +// if (vkey < key) +// { +// rc = -1; +// } +// else if (vkey > key) +// { +// rc = 1; +// } +// else +// { +// rc = 0; +// } + +// return rc; +// } + +void zNPCMgr::Shutdown() +{ + if (this->npcFactory != NULL) + { + delete this->npcFactory; + } + this->npcFactory = NULL; +} + +void zNPCMgr_scenePostInit() +{ +} + +void zNPCMgr_sceneReset() +{ +} + +void zNPCMgr_sceneFinish() +{ +} + +void zNPCMgr_scenePrepare(S32 npccnt) // npccnt may not be right. code was ported +{ +} + +void zNPCMgr_Shutdown() +{ + g_modinit--; + if (g_modinit == 0) + { + zNPCMgr* mgr = zNPCMgrSelf(); + if (mgr != NULL) + { + mgr->Shutdown(); + delete mgr; + g_npcmgr = NULL; + } + zNPCMgr_Shutdown(); + xBehaveMgr_Shutdown(); + } +} + +void zNPCMgr_Startup() +{ + if (g_modinit++ == 0) + { + xBehaveMgr_Startup(); + zNPCMgr* npc = new ('NPCM', NULL) zNPCMgr(); + g_npcmgr = npc; + npc->Startup(); + } +} + +zNPCMgr* zNPCMgr_GetNPCList() +{ + return g_npcmgr; +} + +zNPCMgr* zNPCMgrSelf() +{ + return g_npcmgr; +} diff --git a/src/SB/Game/zPlayer.cpp b/src/SB/Game/zPlayer.cpp new file mode 100644 index 0000000..6cd7ed5 --- /dev/null +++ b/src/SB/Game/zPlayer.cpp @@ -0,0 +1,9 @@ +#include "zPlayer.h" + +void zPlayerReset(zEnt* ent) +{ +} + +void zPlayerRender(zEnt* ent) +{ +} diff --git a/src/SB/Game/zPlayer.h b/src/SB/Game/zPlayer.h new file mode 100644 index 0000000..2ab479b --- /dev/null +++ b/src/SB/Game/zPlayer.h @@ -0,0 +1,4 @@ +#ifndef ZPLAYER_H +#define ZPLAYER_H + +#endif diff --git a/src/SB/Game/zPlayerSB.cpp b/src/SB/Game/zPlayerSB.cpp new file mode 100644 index 0000000..d58121c --- /dev/null +++ b/src/SB/Game/zPlayerSB.cpp @@ -0,0 +1,14 @@ +#include "zPlayerSB.h" + +TreasureChest* zPlayerSB::GetTreasureChestHud() +{ + return &treasureChest; +} + +void zPlayerSB::LoadCheckPoint() +{ +} + +void zPlayerSB::StoreCheckPoint() +{ +} diff --git a/src/SB/Game/zPlayerSB.h b/src/SB/Game/zPlayerSB.h new file mode 100644 index 0000000..0634927 --- /dev/null +++ b/src/SB/Game/zPlayerSB.h @@ -0,0 +1,35 @@ +#ifndef ZPLAYERSB_H +#define ZPLAYERSB_H + +#include "zPlayer.h" + +// not everything is here? +struct zPlayerSB : zPlayer +{ + // padded to get GetTreasureChestHud to match. + // All structs that are used here are updated to be correct. + // Assumably the dwarf is simply wrong + U64 padding; + U32 padding2; + U8 inited; + ManlinessMeter manlinessMeter; + KrabbyPattyMeter krabbyPattyMeter; + TreasureChest treasureChest; + GoofyGooberMeter goofyGooberMeter; + NitroMeter nitroMeter; + + TreasureChest* GetTreasureChestHud(); + void SetCamera(); + void LoadCheckPoint(); + void StoreCheckPoint(); + void HandleEvent(xBase* from, U32 thisEvent, F32* toParam, xBase* toParamWidget, + U32 toParamWidgetID); + void RenderEffects(); + void Render(); + void Update(F32 dt); + void Reset(); + void Init(xEntAsset* asset); + void Init(xEntAsset* asset, S32 playerIdx); +}; + +#endif diff --git a/src/SB/Game/zRenderState.cpp b/src/SB/Game/zRenderState.cpp new file mode 100644 index 0000000..2dd866d --- /dev/null +++ b/src/SB/Game/zRenderState.cpp @@ -0,0 +1,8 @@ +#include "zRenderState.h" + +_SDRenderState sRS; + +_SDRenderState zRenderStateCurrent() +{ + return sRS; +} diff --git a/src/SB/Game/zRewardsMgr.cpp b/src/SB/Game/zRewardsMgr.cpp new file mode 100644 index 0000000..5548087 --- /dev/null +++ b/src/SB/Game/zRewardsMgr.cpp @@ -0,0 +1,34 @@ +#include "zRewardsMgr.h" + +#include "xHudMeter.h" + +U32 upgradeSlotsPoints[14]; + +void zRewardsMgr::SetPlayerDead() +{ + playerDead = TRUE; +} + +U32 zRewardsMgr::GetUpgradeRangeUpper() const +{ +} + +void zRewardsMgr::ResetLastComboIndex() +{ + lastComboIndex = 0; +} + +U32 zRewardsMgr::GetLastComboIndex() const +{ + return lastComboIndex; +} + +void zRewardsMgr::ResetLastComboManlinessPoints() +{ + lastComboManlinessPoints = 0; +} + +U32 zRewardsMgr::GetLastComboManlinessPoints() const +{ + return lastComboManlinessPoints; +} diff --git a/src/SB/Game/zRewardsMgr.h b/src/SB/Game/zRewardsMgr.h new file mode 100644 index 0000000..3dddbaa --- /dev/null +++ b/src/SB/Game/zRewardsMgr.h @@ -0,0 +1,4 @@ +#ifndef ZREWARDSMGR_H +#define ZREWARDSMGR_H + +#endif diff --git a/src/SB/Game/zSaveLoad.cpp b/src/SB/Game/zSaveLoad.cpp new file mode 100644 index 0000000..e8adf84 --- /dev/null +++ b/src/SB/Game/zSaveLoad.cpp @@ -0,0 +1,1474 @@ +#include "zSaveLoad.h" + +#include "iTRC.h" + +void zSaveLoad_DispatchCB(U32 dispatchEvent, const F32* toParam) +{ + switch (dispatchEvent) + { + case 0xa8: + promptSel = 4; + break; + case 0xaa: + promptSel = 3; + break; + case 0xab: + currentCard = (int)*toParam; + en_SAVEGAME_MODE mode = XSG_MODE_LOAD; + if (gGameMode == eGameMode_Save) + { + mode = XSG_MODE_SAVE; + } + st_XSAVEGAME_DATA* data = xSGInit(mode); + zSaveLoad_CardCheckSpaceSingle_doCheck(data, currentCard); + xSGDone(data); + break; + case 0xac: + currentGame = (int)*toParam; + break; + case 0xad: + promptSel = 3; + break; + } +} + +// Scheduling meme on the return +U32 zSaveLoad_SaveLoop() +{ + zSaveLoadInit(); + S32 state = 0; + saveSuccess = 0; + + while (state != 6) + { + switch (state) + { + case 0: + while (zSaveLoad_CardCount() == 0) + { + zSaveLoad_CardPrompt(0); + } + state = 1; + break; + case 1: + switch (zSaveLoad_CardPick(0)) + { + case 1: + state = 2; + break; + case 4: + if (gGameState != 0) + { + gGameMode = eGameMode_Pause; + state = 6; + + xBase* sendTo = zSceneFindObject(xStrHash("PAUSE OPTIONS BKG GROUP")); + zEntEvent(sendTo, eEventUIFocusOn_Select); + + sendTo = zSceneFindObject(xStrHash("PAUSE OPTIONS GROUP")); + zEntEvent(sendTo, eEventUIFocusOn); + + sendTo = zSceneFindObject(xStrHash("PAUSE OPTION MGR UIF")); + zEntEvent(sendTo, eEventUIFocusOn_Select); + + sendTo = zSceneFindObject(xStrHash("PAUSE OPTION SAVE UIF")); + zEntEvent(sendTo, eEventUIFocusOn_Select); + } + else + { + gGameMode = eGameMode_Title; + state = 6; + + xBase* sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME NO")); + zEntEvent(sendTo, eEventUIFocusOn); + + sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME NO")); + zEntEvent(sendTo, eEventUIUnselect); + + sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME YES")); + zEntEvent(sendTo, eEventUIFocusOn_Select); + + sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME")); + zEntEvent(sendTo, eEventUIFocusOn); + + sendTo = zSceneFindObject(xStrHash("BLUE ALPHA 1 UI")); + zEntEvent(sendTo, eEventInvisible); + } + break; + case 11: + state = 10; + currentGame = 0; + break; + default: + state = 0; + } + break; + case 2: + sAccessType = 2; + switch (zSaveLoad_GameSelect(0)) + { + case 2: + case 4: + case 5: + case 6: + case 7: + case 9: + state = 1; + break; + case 1: + state = 10; + break; + case -1: + zSaveLoad_ErrorPrompt(0); + state = 1; + break; + } + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + break; + case 11: + zGameModeSwitch(eGameMode_Game); + zGameStateSwitch(1); + state = 6; + break; + case 10: + S32 tmp = zSaveLoad_SaveGame(); + if (tmp == 1) + { + zGameModeSwitch(eGameMode_Game); + zGameStateSwitch(1); + saveSuccess = 1; + state = 6; + + xBase* sendTo = zSceneFindObject(xStrHash("MNU4 SAVE COMPLETED")); + zEntEvent(sendTo, eEventVisible); + } + else + { + switch (tmp) + { + case 7: + zSaveLoad_SaveDamagedErrorPrompt(0); + break; + case 8: + zSaveLoad_CardYankedErrorPrompt(0); + break; + case 10: + zSaveLoad_CardPromptSpace(0); + break; + default: + zSaveLoad_ErrorPrompt(0); + break; + } + state = 1; + } + break; + } + } + + sAccessType = 0; + return saveSuccess; +} + +U32 zSaveLoad_LoadLoop() +{ + zSaveLoadInit(); + sAccessType = 1; + S32 state = 0; + while (state != 6) + { + switch (state) + { + case 0: + while (zSaveLoad_CardCount() == 0) + { + zSaveLoad_CardPrompt(1); + } + zSaveLoad_UIEvent(0x14, eEventUIFocusOff_Unselect); + state = 1; + break; + case 1: + switch (zSaveLoad_CardPick(1)) + { + case 1: + state = 2; + break; + case 4: + state = 8; + break; + case -1: + state = 0; + break; + case 2: + break; + } + break; + case 2: + switch (zSaveLoad_GameSelect(1)) + { + case 2: + case 4: + case 5: + case 6: + case 7: + case 9: + state = 1; + break; + case 1: + state = 9; + break; + case -1: + zSaveLoad_ErrorPrompt(1); + state = 1; + break; + } + break; + case 3: + break; + case 8: + zGameModeSwitch(eGameMode_Title); + zGameStateSwitch(0); + state = 6; + break; + case 9: + switch (zSaveLoad_LoadGame()) + { + case 1: + zGameModeSwitch(eGameMode_Game); + zGameStateSwitch(0); + state = 6; + globals.autoSaveFeature = 1; + break; + case 7: + zSaveLoad_DamagedSaveGameErrorPrompt(1); + state = 1; + break; + default: + zSaveLoad_ErrorPrompt(1); + state = 1; + } + } + } + + zSendEventToThumbIcon(eEventInvisible); + return (U32)sceneRead[0] << 0x18 | (U32)sceneRead[1] << 0x10 | (U32)sceneRead[2] << 0x8 | + (U32)sceneRead[3]; +} + +// Reordering, causing different register use at the end +S32 zSaveLoad_LoadGame() +{ + S32 success = false; + S32 teststat = true; + S32 rc; + en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; + S32 use_tgt = CardtoTgt(currentCard); + autoSaveCard = currentCard; + + st_XSAVEGAME_DATA* xsgdata = zSaveLoadSGInit(XSG_MODE_LOAD); + xSGTgtSelect(xsgdata, use_tgt); + xSGGameSet(xsgdata, currentGame); + + if (xsgdata == NULL) + { + teststat = false; + } + + xSGAddLoadClient(xsgdata, 'ROOM', NULL, xSGT_LoadLoadCB); + xSGAddLoadClient(xsgdata, 'PREF', NULL, xSGT_LoadPrefsCB); + xSerial_svgame_register(xsgdata, XSG_MODE_LOAD); + + if (!xSGSetup(xsgdata)) + { + teststat = false; + } + + en_XSG_WHYFAIL whyFail = XSG_WHYERR_NONE; + if (teststat) + { + rc = xSGProcess(xsgdata); + if (rc) + { + asstat = xSGAsyncStatus(xsgdata, 1, &whyFail, NULL); + } + if (!rc) + { + teststat = false; + } + else + { + switch (asstat) + { + case XSG_ASTAT_SUCCESS: + success = true; + break; + case XSG_ASTAT_FAILED: + success = false; + break; + case XSG_ASTAT_NOOP: + case XSG_ASTAT_INPROG: + break; + } + } + } + + if (teststat) + { + rc = xSGWrapup(xsgdata); + if (rc < 0) + { + teststat = false; + whyFail = XSG_WHYERR_OTHER; + } + else if (rc == 0) + { + teststat = false; + } + } + + if (!zSaveLoadSGDone(xsgdata)) + { + teststat = false; + } + + XSGAutoData* asg = xSGAutoSave_GetCache(); + S32 use_game = currentCard; + if (success && teststat) + { + S32 idx = xSGTgtPhysSlotIdx(xsgdata, use_tgt); + asg->SetCache(use_tgt, use_game, idx); + globals.autoSaveFeature = 1; + return 1; + } + asg->Discard(); + + switch (whyFail) + { + case XSG_WHYERR_OTHER: + return 7; + default: + return -1; + } +} + +// Reordering at beginning +S32 zSaveLoad_SaveGame() +{ + S32 success = false; + S32 teststat = true; + en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; + S32 use_tgt = CardtoTgt(currentCard); + S32 use_game = currentGame; + autoSaveCard = currentCard; + + st_XSAVEGAME_DATA* xsgdata = zSaveLoadSGInit(XSG_MODE_SAVE); + if (xSGCheckMemoryCard(xsgdata, currentCard) == 0) + { + zSaveLoadSGDone(xsgdata); + return 8; + } + + xSGTgtSelect(xsgdata, use_tgt); + xSGGameSet(xsgdata, use_game); + if (xsgdata == NULL) + { + teststat = false; + } + + zSceneSave(globals.sceneCur, NULL); + + xSGAddSaveClient(xsgdata, 'ROOM', NULL, xSGT_SaveInfoCB, xSGT_SaveProcCB); + xSGAddSaveClient(xsgdata, 'PREF', NULL, xSGT_SaveInfoPrefsCB, xSGT_SaveProcPrefsCB); + + xSerial_svgame_register(xsgdata, XSG_MODE_SAVE); + + U32 progress = zSceneCalcProgress(); + char label[64]; + const char* area; + + if (globals.sceneCur->sceneID == 'PG12') + { + area = zSceneGetLevelName('HB01'); + } + else + { + area = zSceneGetLevelName(globals.sceneCur->sceneID); + } + + strncpy(label, area, sizeof(label)); + + if (!xSGSetup(xsgdata, use_game, label, progress, 0, zSceneGetLevelIndex())) + { + teststat = false; + } + + en_XSG_WHYFAIL whyFail = XSG_WHYERR_NONE; + if (teststat) + { + S32 rc = xSGProcess(xsgdata); + if (rc) + { + asstat = xSGAsyncStatus(xsgdata, 1, &whyFail, NULL); + } + + xSGGameIsEmpty(xsgdata, use_game); + xSGTgtHasGameDir(xsgdata, use_tgt); + if (!rc) + { + teststat = false; + } + else + { + switch (asstat) + { + case XSG_ASTAT_SUCCESS: + success = true; + break; + case XSG_ASTAT_FAILED: + success = false; + break; + case XSG_ASTAT_NOOP: + case XSG_ASTAT_INPROG: + break; + } + } + } + + if (teststat && !xSGWrapup(xsgdata)) + { + teststat = false; + } + + if (!xSGCheckMemoryCard(xsgdata, currentCard)) + { + zSaveLoadSGDone(xsgdata); + return 8; + } + + if (!zSaveLoadSGDone(xsgdata)) + { + teststat = false; + } + + XSGAutoData* asg = xSGAutoSave_GetCache(); + if (success && teststat) + { + S32 idx = xSGTgtPhysSlotIdx(xsgdata, use_tgt); + asg->SetCache(use_tgt, use_game, idx); + globals.autoSaveFeature = 1; + return 1; + } + asg->Discard(); + + switch (whyFail) + { + case XSG_WHYERR_DAMAGE: + case XSG_WHYERR_OTHER: + return 7; + case XSG_WHYERR_NOCARD: + case XSG_WHYERR_CARDYANKED: + return 8; + default: + return -1; + } +} + +S32 zSaveLoad_DoAutoSave() +{ + S32 success = 0; + S32 teststat = 1; + en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; + st_XSAVEGAME_DATA* svinst; + + XSGAutoData* autodata = xSGAutoSave_GetCache(); + if (autodata == NULL) + { + return -1; + } + if (!autodata->IsValid()) + { + return -1; + } + + S32 use_tgt = CardtoTgt(autodata->LastTarget()); + S32 lastGame = autodata->LastGame(); + autodata->Discard(); + svinst = xSGInit(XSG_MODE_SAVE); + xSGTgtSelect(svinst, use_tgt); + xSGGameSet(svinst, lastGame); + + if (svinst == NULL) + { + teststat = 0; + } + + zSceneSave(globals.sceneCur, 0); + + xSGAddSaveClient(svinst, 'ROOM', 0, xSGT_SaveInfoCB, xSGT_SaveProcCB); + xSGAddSaveClient(svinst, 'PREF', 0, xSGT_SaveInfoPrefsCB, xSGT_SaveProcPrefsCB); + + xSerial_svgame_register(svinst, XSG_MODE_SAVE); + U32 progress = zSceneCalcProgress(); + + const char* area; + if (globals.sceneCur->sceneID == 'PG12') + { + area = zSceneGetLevelName('HB01'); + } + else + { + area = zSceneGetLevelName(globals.sceneCur->sceneID); + } + + char label[64]; + strncpy(label, area, sizeof(label)); + if (!xSGSetup(svinst, lastGame, label, progress, 0, zSceneGetLevelIndex())) + { + teststat = 0; + } + + if (teststat != 0) + { + S32 iprocess = xSGProcess(svinst); + if (iprocess != 0) + { + asstat = xSGAsyncStatus(svinst, 1, 0, 0); + } + xSGGameIsEmpty(svinst, lastGame); + xSGTgtHasGameDir(svinst, use_tgt); + if (iprocess == 0) + { + teststat = false; + } + else + { + switch (asstat) + { + case XSG_ASTAT_INPROG: + break; + case XSG_ASTAT_SUCCESS: + success = true; + break; + case XSG_ASTAT_FAILED: + success = false; + break; + } + } + } + + if (teststat && xSGWrapup(svinst) == 0) + { + teststat = false; + } + + if (xSGDone(svinst) == 0) + { + teststat = false; + } + + if ((success) && (teststat)) + { + if (autodata != NULL) + { + S32 idx = xSGTgtPhysSlotIdx(svinst, use_tgt); + autodata->SetCache(use_tgt, lastGame, idx); + globals.autoSaveFeature = 1; + } + return 1; + } + else + { + if (autodata != NULL) + { + autodata->Discard(); + } + globals.autoSaveFeature = 0; + return -1; + } +} + +void zSaveLoadAutoSaveUpdate() +{ + xBase* obj; + s32 out1, out2; + + if (globals.autoSaveFeature == 0 || gGameMode == eGameMode_Pause) + { + return; + } + if (preAutoSaving == 0) + { + return; + } + + S32 physicalSlot = xSGAutoSave_GetCache()->LastPhysicalSlot(); + if (physicalSlot >= 0) + { + autoSaveCard = physicalSlot; + switch (CARDProbeEx(physicalSlot, &out1, &out2)) + { + case 0: + case -1: + obj = zSceneFindObject(xStrHash("SAVING GAME ICON UI")); //"SAVING GAME ICON UI" + if (obj != NULL) + { + zEntEvent(obj, eEventVisible); + } + break; + default: + obj = zSceneFindObject(xStrHash("SAVING GAME ICON UI")); //"SAVING GAME ICON UI" + if (obj != NULL) + { + zEntEvent(obj, eEventInvisible); + } + + obj = zSceneFindObject(xStrHash("MNU4 AUTO SAVE FAILED")); //"MNU4 AUTO SAVE FAILED" + if (obj != NULL) + { + zEntEvent(obj, eEventVisible); + } + globals.autoSaveFeature = 0; + zSaveLoadPreAutoSave(0); + break; + } + } +} + +void zSaveLoadPreAutoSave(bool onOff) +{ + preAutoSaving = onOff; + if (onOff) + { + ResetButton::DisableReset(); + } + else + { + ResetButton::EnableReset(); + } +} + +S32 zSaveLoad_CardCheckFormatted(int, int); + +S32 zSaveLoad_GameSelect(S32 mode) +{ + S32 done = 0; + S32 i; + st_XSAVEGAME_DATA* svinst; + S32 use_tgt; + + badCard = 1; + while (badCard != 0) + { + currentGame = -1; + promptSel = -1; + use_tgt = CardtoTgt(currentCard); + + if (mode == 1) + { + zSaveLoad_UIEvent(0, eEventEnable); + zSaveLoad_UIEvent(0, eEventUIFocusOn); + zSaveLoad_UIEvent(0x33, eEventUIFocusOn); + } + else + { + zSaveLoad_UIEvent(0x34, eEventUIFocusOn); + } + + for (i = 0; i < 3; i++) + { + svinst = xSGInit(XSG_MODE_LOAD); + xSGTgtSelect(svinst, use_tgt); + if (xSGGameIsEmpty(svinst, i)) + { + if (mode == 1) + { + zSaveLoad_UIEvent(i + 6, eEventDisable); + } + strcpy(zSaveLoadGameTable[i].label, "Empty"); + strcpy(zSaveLoadGameTable[i].date, "Empty"); + zSaveLoadGameTable[i].progress = 0; + zSaveLoadGameTable[i].size = 0; + zSaveLoadGameTable[i].thumbIconIndex = -1; + } + else + { + strcpy(zSaveLoadGameTable[i].label, xSGGameLabel(svinst, i)); + if (strcmpi(zSaveLoadGameTable[i].label, zSceneGetLevelName('MNU3')) == 0) + { + strcpy(zSaveLoadGameTable[i].label, zSceneGetLevelName('HB01')); + } + strcpy(zSaveLoadGameTable[i].date, xSGGameModDate(svinst, i)); + zSaveLoadGameTable[i].progress = xSGGameProgress(svinst, i); + zSaveLoadGameTable[i].size = xSGGameSize(svinst, i); + zSaveLoadGameTable[i].size = zSaveLoadGameTable[i].size + 0x1fff & 0xffffe000; + zSaveLoadGameTable[i].size >>= 0xd; + zSaveLoadGameTable[i].size += 3; + + zSendEventToThumbIcon(3); + zSaveLoadGameTable[i].thumbIconIndex = xSGGameThumbIndex(svinst, i); + if (strcmpi(zSaveLoadGameTable[i].label, "") == 0) + { + zSaveLoadGameTable[i].thumbIconIndex = -1; + } + } + xSGDone(svinst); + } + + if (mode == 1) + { + for (S32 emptyCount = 6; emptyCount <= 8; emptyCount++) + { + if (zSaveLoad_slotIsEmpty(emptyCount - 6) == 0) + { + zSaveLoad_UIEvent(emptyCount, eEventUISelect); + break; + } + } + } + else + { + zSaveLoad_UIEvent(0x15, eEventUIFocusOn); + zSaveLoad_UIEvent(0x19, eEventUISelect); + } + badCard = 0; + + while (!done && promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(3); + if (promptSel == 4) + { + done = promptSel; + } + + if (currentGame == -1) + { + continue; + } + + done = zSaveLoad_CardCheck(currentCard, mode); + if (done != 1) + { + currentGame = -1; + badCard = 0; + + if (done == 9) + { + zSaveLoad_CardWrongDeviceErrorPrompt(mode); + done = 9; + } + break; + } + + done = zSaveLoad_CardCheckFormatted(currentCard, mode); + if (done != 1) + { + switch (done) + { + case 5: + done = 0; + promptSel = -1; + continue; + case 7: + zSaveLoad_CardDamagedErrorPrompt(mode); + promptSel = -1; + done = 7; + badCard = 0; + continue; + case 2: + currentGame = -1; + badCard = 0; + continue; + default: + continue; + } + } + + done = zSaveLoad_CardCheckValid(currentCard, mode); + if (done != 1) + { + switch (done) + { + case 5: + case 6: + done = 0; + promptSel = -1; + continue; + case 2: + promptSel = -1; + currentGame = -1; + badCard = 0; + continue; + default: + break; + } + } + + if (badCard == 0) + { + done = zSaveLoad_CardCheckGameSlot(currentCard, currentGame, mode); + if (done != 1) + { + switch (done) + { + case -1: + case 5: + done = 0; + promptSel = -1; + break; + case 2: + currentGame = -1; + break; + } + } + } + else + { + done = 0; + currentGame = -1; + } + } + } + + if (mode == 1) + { + zSaveLoad_UIEvent(0, eEventEnable); + } + + S32 index = 0x15; + if (mode == 1) + { + index = 0; + } + zSaveLoad_UIEvent(index, eEventUIFocusOff_Unselect); + return done; +} + +void zSaveLoad_BuildName(char* name_txt, S32 idx) +{ + char desired[128]; + char current_name[128]; + + BuildIt(desired, idx); + + S32 counter = 0; + for (S32 i = 0; i < idx; i++) + { + BuildIt(current_name, i); + if (strcmp(zSaveLoadGameTable[i].label, zSaveLoadGameTable[idx].label) == 0 && + strcmp(current_name, "Corrupt Save File\n\n") != 0) + { + counter++; + } + } + + if (counter > 0) + { + sprintf(name_txt, "%s (%d)", desired, counter); + name_txt[0x3f] = NULL; + } + else + { + strcpy(name_txt, desired); + } +} + +S32 zSaveLoad_CardPick(S32 mode) +{ + S32 done = 0; + S32 formatDone = 0x16; + + currentCard = -1; + promptSel = -1; + + if (mode == 1) + { + formatDone = 1; + } + + zSaveLoad_UIEvent(formatDone, eEventUIFocusOn); + formatDone = 0x17; + if (mode == 1) + { + formatDone = 4; + } + + zSaveLoad_UIEvent(formatDone, eEventUISelect); + + while (!done && promptSel == -1) + { + if (currentCard != -1) + { + done = zSaveLoad_CardCheck(currentCard, mode); + switch (done) + { + case 2: + currentCard = -1; + promptSel = -1; + continue; + case -1: + done = 0; + promptSel = -1; + continue; + case 9: + zSaveLoad_CardWrongDeviceErrorPrompt(mode); + done = -1; + promptSel = -1; + continue; + } + + done = zSaveLoad_CardCheckFormatted(currentCard, mode); + switch (done) + { + case 5: + done = 0; + if (promptSel == 3) + { + promptSel = -1; + continue; + } + if (promptSel == 4) + { + currentCard = -1; + return -1; + } + break; + case 6: + done = 0; + promptSel = -1; + continue; + case 7: + zSaveLoad_CardDamagedErrorPrompt(mode); + done = -1; + promptSel = -1; + continue; + case 2: + case 4: + currentCard = -1; + promptSel = -1; + continue; + case -1: + done = 0; + promptSel = -1; + continue; + case 8: + case 9: + case 10: + case 11: + + default: + break; + } + + done = zSaveLoad_CardCheckValid(currentCard, mode); + switch (done) + { + case 5: + case 6: + done = 0; + promptSel = -1; + continue; + case 2: + case 4: + promptSel = -1; + currentGame = -1; + break; + case 0: + case 1: + break; + case -1: + done = 0; + promptSel = -1; + continue; + case 3: + break; + } + } + + zSaveLoad_Tick(); + } + + formatDone = 0x16; + if (mode == 1) + { + formatDone = 1; + } + + zSaveLoad_UIEvent(formatDone, eEventUIFocusOff_Unselect); + + if (done == 1) + { + return done; + } + if (promptSel != -1) + { + return promptSel; + } + return done; +} + +S32 zSaveLoad_CardCheckSlotOverwrite(S32 cardNumber, S32 gameNumber) +{ + // TODO: Figure out what this number means. + S32 iVar1 = zSaveLoad_CardCheckSlotOverwrite_Free(cardNumber, gameNumber); + // NOTE (Square): I'm not sure that this is supposed to be a loop. It doesn't make + // sense to just break at the end and the condition feels like it should be an early return + // but this matches and I don't know how else to generate the `b` instruction at 0x18 + while (iVar1 != 1 || iVar1 == 10) + { + if (iVar1 == -1 || iVar1 == 10) + { + return iVar1; + } + + if (IsValidName(zSaveLoadGameTable[gameNumber].label)) + { + iVar1 = zSaveLoad_CardPromptOverwrite(); + } + else + { + iVar1 = zSaveLoad_CardPromptOverwriteDamaged(); + } + + if (iVar1 == 5) + { + return iVar1; + } + + if (iVar1 == 2 || iVar1 == 4) + { + return 2; + } + break; + } + + return 1; +} + +S32 zSaveLoad_CardCheckSlotEmpty(S32 cardNumber, S32 gameNumber) +{ + S32 i = zSaveLoad_CardCheckSlotEmpty_hasGame(cardNumber, gameNumber); + while (i != 1) + { + i = zSaveLoad_CardCheckSlotEmpty_hasGame(cardNumber, gameNumber); + if (i == -1 || i == 6) + { + return i; + } + + i = zSaveLoad_CardPromptGameSlotEmpty(); + if (i == 2 || i == 4) + { + return 2; + } + } + return 1; +} + +S32 zSaveLoad_CardCheckGameSlot(S32 cardNumber, S32 gameNumber, S32 mode) +{ + if (mode == 1) + { + return zSaveLoad_CardCheckSlotEmpty(cardNumber, gameNumber); + } + else + { + return zSaveLoad_CardCheckSlotOverwrite(cardNumber, gameNumber); + } +} + +S32 zSaveLoad_CardCheckGames(S32 cardNumber, S32 mode) +{ + S32 result = zSaveLoad_CardCheckGamesSingle(cardNumber); + while (result != 1) + { + badCard = 1; + + result = zSaveLoad_CardCheckGamesSingle(cardNumber); + if (result == -1 || result == 6 || result == 5) + { + return result; + } + + result = zSaveLoad_CardPromptGames(mode); + if (result == 2 || result == 4) + { + return 2; + } + } + return 1; +} + +S32 zSaveLoad_CardCheckSpace(S32 cardNumber, S32 mode) +{ + S32 result = zSaveLoad_CardCheckSpaceSingle(cardNumber); + while (result != 1) + { + badCard = 1; + + result = zSaveLoad_CardCheckSpaceSingle(cardNumber); + if (result == -1 || result == 6 || result == 5) + { + return result; + } + + result = zSaveLoad_CardPromptSpace(mode); + if (result == 2 || result == 4) + { + return 2; + } + } + return 1; +} + +S32 zSaveLoad_CardCheckValid(S32 cardNumber, S32 mode) +{ + if (mode == 1) + { + return zSaveLoad_CardCheckGames(cardNumber, mode); + } + else + { + return zSaveLoad_CardCheckSpace(cardNumber, mode); + } +} + +S32 zSaveLoad_CardCheckFormatted(S32 cardNumber, S32 mode) +{ + S32 result; + while (result = zSaveLoad_CardCheckFormattedSingle(cardNumber), result != 1) + { + badCard = 1; + + result = zSaveLoad_CardCheckFormattedSingle(cardNumber); + if (result == -1) + { + return -1; + } + + if (result == 7) + { + return 7; + } + + result = zSaveLoad_CardPromptFormat(mode); + if (result == 2 || result == 4) + { + return 2; + } + + sAccessType = 3; + S32 tmp = format(cardNumber, mode); + sAccessType = 2; + return tmp != 1 ? tmp : 11; + } + return 1; +} + +S32 zSaveLoad_CardCheck(S32 cardNumber, S32 mode) +{ + S32 cardResult = zSaveLoad_CardCheckSingle(cardNumber); + while (cardResult == 0) + { + badCard = 1; + + cardResult = zSaveLoad_CardPrompt(mode); + if (cardResult == 2 || cardResult == 4) + { + return 2; + } + cardResult = zSaveLoad_CardCheckSingle(cardNumber); + } + return cardResult == 9 ? 9 : 1; +} + +S32 zSaveLoad_CardCheckFormattedSingle(S32 cardNumber) +{ + S32 rc; + st_XSAVEGAME_DATA* ldinst = xSGInit(XSG_MODE_LOAD); + S32 tgtmax; + + rc = 0; + switch (xSGTgtCount(ldinst, &tgtmax)) + { + case 2: + switch (xSGTgtIsFormat(ldinst, cardNumber, NULL)) + { + case -1: + rc = 7; + break; + case 1: + rc = 1; + break; + case 0: + default: + rc = 0; + break; + } + break; + case 1: + S32 idx = xSGTgtPhysSlotIdx(ldinst, 0); + if (idx != cardNumber) + { + rc = -1; + } + else if (!(idx ^ cardNumber)) + { + switch (xSGTgtIsFormat(ldinst, 0, NULL)) + { + case -1: + rc = 7; + break; + case 1: + rc = 1; + break; + case 0: + default: + rc = 0; + break; + } + } + break; + case 0: + rc = -1; + break; + } + + xSGDone(ldinst); + return rc; +} + +S32 zSaveLoad_CardPromptOverwriteDamaged() +{ + zSaveLoad_UIEvent(0x15, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x23, eEventUIFocusOn_Select); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(5); + } + zSaveLoad_UIEvent(0x23, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPromptOverwrite() +{ + zSaveLoad_UIEvent(0x15, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x22, eEventUIFocusOn_Select); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(5); + } + zSaveLoad_UIEvent(0x22, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPromptGameSlotEmpty() +{ + zSaveLoad_UIEvent(0, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x13, eEventUIFocusOn_Select); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + } + zSaveLoad_UIEvent(0x13, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPromptGames(S32 mode) +{ + S32 i = 0x15; + if (mode == 1) + { + i = 0; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(1, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x12, eEventUIFocusOn_Select); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(3); + } + zSaveLoad_UIEvent(0x12, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPromptSpace(S32 mode) +{ + S32 i = 0x15; + if (mode == 1) + { + i = 0; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x16, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x25, eEventUIFocusOn_Select); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(3); + } + zSaveLoad_UIEvent(0x25, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPromptFormat(S32 mode) +{ + S32 i = 0x15; + if (mode == 1) + { + i = 0; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + + i = 0x16; + if (mode == 1) + { + i = 1; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + zSaveLoad_UIEvent(0x32, eEventUIFocusOn); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + zSaveLoad_poll(3); + } + zSaveLoad_UIEvent(0x32, eEventUIFocusOff_Unselect); + return promptSel; +} + +S32 zSaveLoad_CardPrompt(S32 cardNumber) +{ + S32 i = 0x15; + if (cardNumber == 1) + { + i = 0; + } + zSaveLoad_UIEvent(i, eEventEnable); + + i = 0x15; + if (cardNumber == 1) + { + i = 0; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + + i = 0x24; + if (cardNumber == 1) + { + i = 0x11; + } + zSaveLoad_UIEvent(i, eEventUIFocusOn_Select); + + i = 0x16; + if (cardNumber == 1) + { + i = 1; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + + promptSel = -1; + while (promptSel == -1) + { + zSaveLoad_Tick(); + } + + i = 0x24; + if (cardNumber == 1) + { + i = 0x11; + } + zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); + + if (cardNumber == 1) + { + zSaveLoad_UIEvent(0, eEventDisable); + } + return promptSel; +} + +S32 format(S32 num, S32 mode) +{ + st_XSAVEGAME_DATA* data = zSaveLoadSGInit(XSG_MODE_LOAD); + S32 tgtmax; + + S32 rc = 0; + switch (xSGTgtCount(data, &tgtmax)) + { + case 2: + xSGTgtSelect(data, num); + rc = xSGTgtFormatTgt(data, num, 0); + zSaveLoadSGDone(data); + if (rc == -1) + { + zSaveLoad_ErrorFormatCardYankedPrompt(mode); + rc = 5; + } + else + { + if (rc == 0) + { + zSaveLoad_ErrorFormatPrompt(mode); + } + if (rc != 0) + { + rc = 1; + } + } + break; + case 1: + S32 idx = xSGTgtPhysSlotIdx(data, 0); + if (idx != num) + { + zSaveLoadSGDone(data); + rc = 5; + } + else + { + if (idx ^ num) + { + zSaveLoadSGDone(data); + } + else + { + xSGTgtSelect(data, 0); + rc = xSGTgtFormatTgt(data, num, 0); + zSaveLoadSGDone(data); + if (rc == 0) + { + zSaveLoad_ErrorFormatPrompt(mode); + } + } + } + break; + case 0: + rc = 5; + zSaveLoadSGDone(data); + break; + } + return rc; +} + +void zSaveLoad_Tick(bool) +{ + // REFERENCE BFBB +} diff --git a/src/SB/Game/zScene.cpp b/src/SB/Game/zScene.cpp new file mode 100644 index 0000000..e9951b4 --- /dev/null +++ b/src/SB/Game/zScene.cpp @@ -0,0 +1,1098 @@ +#include "zScene.h" + +#include "zRewards.h" +#include "zRenderState.h" +#include "zEntDestructObj.h" +#include "zParCmd.h" +#include "zAnimList.h" +#include "zDispatcher.h" +#include "zCameraTweak.h" +#include "zCamMarker.h" +#include "zMusic.h" +#include "zGrid.h" +#include "xDecal.h" +#include "xFog.h" +#include "zTalkBox.h" +#include "zUIFont.h" +#include "zEntButton.h" +#include "xSkyDome.h" +#include "zLOD.h" +#include "zGame.h" +#include "zGoo.h" +#include "iModel.h" +#include "xShadow.h" +#include "zLightning.h" +#include "zLight.h" +#include "zActionLine.h" +#include "xPtankPool.h" +#include "zParPTank.h" +#include "zNPCMgr.h" +#include "xScrFx.h" + +U8 HACK_BASETYPE; +static S32 bytesNeeded; +static S32 availOnDisk; +static S32 neededFiles; +static F32 offsetx; +static F32 offsety; +static U32 enableScreenAdj; +volatile static F32 oldOffsetx; +volatile static F32 oldOffsety; +static S32 sMemDepthSceneStart = -1; +static S32 sMemDepthJustHIPStart = -1; +_zEnv* gCurEnv; +U32 gTransitionSceneID; +F32 gSceneUpdateTime; +static xVec3 sOldPosPlayer; +static xVec3 sOldPosCamera; +static U32 sSuddenMove; + +struct zSceneLevel +{ + const char* desc; + const char* prefix; +}; + +struct IDBasePair +{ + U32 id; + xBase* base; +}; + +static IDBasePair* scobj_idbps; +static S32 scobj_size = -1; +static S32 nidbps = -1; + +extern U32 _1251; +extern char byte_803D0884; +extern U32 _2014; + +extern U32 _1250; +extern F32 _1373; +extern F32 _1374; +extern F32 _1375; +extern F32 _1493; +extern F32 _1494; +extern F32 _1495; +extern F32 _1496_0; +extern U32 _2013; +extern F32 _2094; +extern F32 _2095_0; +extern F32 _2096_0; +extern F32 _2097_0; +extern F32 _2242; + +static void zSceneObjHashtableInit(S32 count); +static void zSceneObjHashtableExit(); +static S32 zSceneObjHashtableUsage(); +static void zSceneObjHashtableAdd(U32 id, xBase* base); +static xBase* zSceneObjHashtableGet(U32 id); +static xBase* zSceneExitSoundIteratorCB(xBase* b, zScene*, void*); +static void zSceneAutoSave(); + +U32 zScene_ScreenAdjustMode() +{ + return enableScreenAdj; +} + +void zSceneSetOldScreenAdj() +{ + oldOffsetx = offsetx; + oldOffsety = offsety; +} + +void zSceneEnableScreenAdj(U32 enable) +{ + enableScreenAdj = enable; +} +void zSceneCardCheckStartup_set(S32 needed, S32 available, S32 files) +{ + bytesNeeded = needed; + availOnDisk = available; + neededFiles = files; +} + +void zScene_UpdateFlyToInterface(F32 dt) +{ +} + +U32 zSceneGetLevelIndex() +{ + return zSceneGetLevelIndex(globals.sceneCur->sceneID); +} + +const char* zSceneGetLevelName(U32 sceneID) +{ + char c1 = (sceneID >> 24) & 0xFF; + char c2 = (sceneID >> 16) & 0xFF; + + // Add in the updated LevelTable to this file + + // for (S32 i = 0; i < sizeof(sLevelTable) / sizeof(sLevelTable[0]); i++) + // { + // if (c1 == sLevelTable[i].prefix[0] && c2 == sLevelTable[i].prefix[1]) + // { + // return sLevelTable[i].desc; + // } + // } + + return "Level Not Found"; +} + +void zSceneMemLvlChkCB() +{ +} + +const char* zSceneGetName(xBase* b) +{ + if (b) + { + const char* n = xSTAssetName(b->id); + + if (n) + { + return n; + } + } + + return ""; +} + +const char* zSceneGetName(U32 gameID) +{ + xBase* b = zSceneFindObject(gameID); + + if (b) + { + return zSceneGetName(b); + } + + return ""; +} + +xBase* zSceneFindObject(U32 gameID) +{ + return 0; +} + +static void zSceneObjHashtableAdd(U32 id, xBase* base) +{ + S32 k, chkd; + + chkd = id & (scobj_size - 1); + + for (k = 0; k < scobj_size; k++) + { + IDBasePair* idbp = &scobj_idbps[chkd]; + + if (idbp->id == 0) + { + idbp->id = id; + idbp->base = base; + nidbps++; + break; + } + + chkd++; + + if (chkd == scobj_size) + { + chkd = 0; + } + } +} + +void zSceneRenderPreFX() +{ + // PORT CODE FROM BATTLE +} + +void zSceneRenderPostFX() +{ + // PORT CODE FROM BATTLE +} + +void zSceneRender() +{ + zSceneRenderPreFX(); + xScrFxRender(globals.oldSkoolCamera.lo_cam); + zSceneRenderPostFX(); +} + +void zSceneUpdate(F32 dt) +{ + // REFERENCE BFBB +} + +S32 zSceneSetup_serialTraverseCB(U32 clientID, xSerial* xser) +{ + char uiName[16]; + S32 val = 0; + xBase* b; + + xser->Read_b1(&val); + + if (val == 0) + { + return 1; + } + + sprintf(uiName, "%s", xUtil_idtag2string(clientID, 0)); + + uiName[1] = ' '; + + strcat(uiName, " VISITED"); + + b = zSceneFindObject(xStrHash(uiName)); + + if (b) + { + b->baseFlags |= 0x1; + } + + return 1; +} + +static void ActivateCB(xBase* base) +{ + base->baseFlags &= (U8)~0x40; +} + +static void DeactivateCB(xBase* base) +{ + base->baseFlags |= 0x40; +} + +void zSceneSetup() +{ + // REFERENCE BFBB +} + +void zSceneReset() +{ + zScene* s = globals.sceneCur; + + zEntPlayerPreReset(); + + gOccludeCount = 0; + + xScrFxLetterboxReset(); + zEntPickup_FlushGrabbed(); + zEntPickup_SceneReset(); + zMusicReset(); + //zThrown_Reset(); + zShrapnel_Reset(); + zFX_SceneReset(); + xFXSceneReset(); + xShadowManager_Reset(); + //ztalkbox::reset_all(); + //zCameraTweakGlobal_Reset(); + xPadDestroyRumbleChain(0); + + globals.cmgr = NULL; + + zEntEventAll(NULL, 0, eEventRoomEnd, NULL); + zEntEventAll(NULL, 0, eEventSceneEnd, NULL); + + zSceneSave(s, NULL); + zSceneAutoSave(); + + xSndStopAll(~SND_CAT_UI); + xSndUpdate(); + iSndWaitForDeadSounds(); + + for (U32 i = 0; i < s->num_base; i++) + { + if (s->base[i]) + { + switch (s->base[i]->baseType) + { + case eBaseTypePickup: + case eBaseTypeCamera: + case eBaseTypeDoor: + case eBaseTypeSavePoint: + case eBaseTypeItem: + case eBaseTypeStatic: + case eBaseTypeDynamic: + case eBaseTypeMovePoint: + case eBaseTypeTimer: + case eBaseTypeBubble: + case eBaseTypePortal: + case eBaseTypeGroup: + case eBaseTypeSFX: + case eBaseTypeFFX: + case eBaseTypeVFX: + case eBaseTypeButton: + case eBaseTypeProjectile: + case eBaseTypeSurface: + case eBaseTypeDestructObj: + case eBaseTypeGust: + case eBaseTypeVolume: + case eBaseTypeDispatcher: + case eBaseTypeCond: + case eBaseTypeUI: + case eBaseTypeUIFont: + case eBaseTypeProjectileType: + case eBaseTypeFog: + case eBaseTypeLight: + case eBaseTypeParticleEmitter: + case eBaseTypeParticleSystem: + case eBaseTypeCutsceneMgr: + default: + { + zEntEvent(NULL, 0, s->base[i], eEventReset, NULL, NULL, 1); + break; + } + case eBaseTypeCounter: + { + //xCounterReset(s->base[i]); + break; + } + case eBaseTypePlayer: + { + zEntPlayerReset((xEnt*)s->base[i]); + break; + } + case eBaseTypePlatform: + { + //zPlatform_Reset((zPlatform*)s->base[i], globals.sceneCur); + break; + } + case eBaseTypePendulum: + { + //zPendulum_Reset((_zPendulum*)s->base[i], globals.sceneCur); + break; + } + case eBaseTypeHangable: + { + //zEntHangable_Reset((zEntHangable*)s->base[i]); + break; + } + case eBaseTypeLobMaster: + { + zEntEvent(s->base[i], eEventReset); + break; + } + case eBaseTypeEGenerator: + { + //zEGenerator_Reset((zEGenerator*)s->base[i], globals.sceneCur); + break; + } + case eBaseTypeEnv: + { + _zEnv* env = (_zEnv*)s->base[i]; + + if (env) + { + if (zSceneFindObject(env->easset->startCameraAssetID)) + { + //zCameraReset(&globals.camera); + } + + xClimateInitAsset(&gClimate, env->easset); + } + } + } + } + } + + zNPCMgr_sceneReset(); + zEntPlayer_LoadCheckPoint(); + zSceneLoad(globals.sceneCur, NULL); + zSceneEnableVisited(s); + xSerialTraverse(zSceneSetup_serialTraverseCB); + xSkyDome_Setup(); + xUpdateCull_Reset(globals.updateMgr); + xUpdateCull_Update(globals.updateMgr, 100); + zGridReset(s); + + zEntEventAll(NULL, 0, eEventSceneBegin, NULL); + zEntEventAll(NULL, 0, eEventRoomBegin, NULL); + zEntEventAll(NULL, 0, eEventSceneReset, NULL); + + //zNPCTiki_InitStacking(globals.sceneCur); + //zNPCTiki_InitFX(globals.sceneCur); + + xUpdateCull_Update(globals.updateMgr, 100); + zLOD_Update(100); + + //zGameExtras_SceneReset(); +} + +void zSceneLoad(zScene* ent) +{ + // REFERENCE BFBB +} + +void zSceneSave(zScene* ent) +{ + // REFERENCE BFBB +} + +void zSceneSwitch(_zPortal* p, S32 forceSameScene) +{ + // REFERENCE BFBB +} + +void zSceneUpdateSFXWidgets() +{ + zScene* s = globals.sceneCur; + xSFXUpdateEnvironmentalStreamSounds((xSFX*)s->baseList[eBaseTypeSFX], + s->baseCount[eBaseTypeSFX]); +} + +void zSceneExit(S32 beginReload) +{ + // REFERENCE BFBB +} + +void zSceneInit(U32 theSceneID, S32 reloadInProgress) +{ + F32 pdone; + zScene* s; + U32 i; + + U8 rgba_bkgrd[4]; + *(U32*)rgba_bkgrd = _1250; + + gTransitionSceneID = theSceneID; + gOccludeCount = 0; + + char b[5]; + *(U32*)b = _1251; + b[4] = byte_803D0884; + + sprintf(b, xUtil_idtag2string(theSceneID, 0)); + xStrupr(b); + + theSceneID = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; + + xUtil_idtag2string(theSceneID, 0); + + xFogClearFog(); + xSndSceneInit(); + + if (!reloadInProgress) + { + sMemDepthSceneStart = xMemPushBase(); + } + + zGameScreenTransitionBegin(); + zParPTankInit(); + + pdone = _1373; + + if (globals.useHIPHOP && !reloadInProgress) + { + zGameScreenTransitionUpdate(pdone, "... scene preload ...\n"); + + S32 ver_hop = xSTPreLoadScene(theSceneID, NULL, 0x2); + + if (ver_hop >= 0x000A000F) + { + xSTQueueSceneAssets(theSceneID, 0x2); + + do + { + rgba_bkgrd[0] = 0; + rgba_bkgrd[1] = 0; + rgba_bkgrd[2] = 0; + rgba_bkgrd[3] = 0; + + pdone += _1373; + + zGameScreenTransitionUpdate(pdone, "... scene loading ...\n", rgba_bkgrd); + } while (xSTLoadStep(theSceneID) < _1374); + + xSTDisconnect(theSceneID, 0x2); + } + } + + sMemDepthJustHIPStart = xMemPushBase(); + s = (zScene*)xMemAllocSize(sizeof(zScene)); + + globals.sceneCur = s; + + xSceneInit(s, 200, 2048, 2068, 250); + + s->env = (xEnv*)xMemAllocSize(sizeof(xEnv)); + s->sceneID = theSceneID; + + iTime time; + + time = iTimeGet(); + xUtil_idtag2string(theSceneID, 0); + iTimeDiffSec(time); + + xSTPreLoadScene(theSceneID, NULL, 0x1); + + time = iTimeGet(); + xUtil_idtag2string(theSceneID, 0); + iTimeDiffSec(time); + + xSTQueueSceneAssets(theSceneID, 0x1); + + time = iTimeGet(); + xUtil_idtag2string(theSceneID, 0); + iTimeDiffSec(time); + + pdone += _1373; + + zGameScreenTransitionUpdate(pdone, "... scene asset queue ...\n"); + + time = iTimeGet(); + xUtil_idtag2string(theSceneID, 0); + iTimeDiffSec(time); + + do + { + rgba_bkgrd[0] = 0; + rgba_bkgrd[1] = 0; + rgba_bkgrd[2] = 0; + rgba_bkgrd[3] = 0; + + pdone += _1373; + + zGameScreenTransitionUpdate(pdone, "... scene loading ...\n", rgba_bkgrd); + } while (xSTLoadStep(theSceneID) < _1374); + + xSTDisconnect(theSceneID, 0x1); + + time = iTimeGet(); + xUtil_idtag2string(theSceneID, 0); + iTimeDiffSec(time); + + pdone += _1373; + + zGameScreenTransitionUpdate(pdone, "...initializing scene - sound\n"); + + zEntPlayer_LoadSounds(); + iSndInitSceneLoaded(); + xPadRumbleEnable(globals.currentActivePad, globals.option_vibration); + + xSTSwitchScene(theSceneID, NULL, NULL); + + globals.sceneCur->resolvID = zSceneFindObject; + globals.sceneCur->id2Name = zSceneGetName; + globals.sceneCur->base2Name = zSceneGetName; + + g_xSceneCur = globals.sceneCur; + + xModelPipeNumTables = xSTAssetCountByType('PIPT'); + + for (S32 i = 0; i < xModelPipeNumTables; i++) + { + void* data = xSTFindAssetByType('PIPT', i, NULL); + + xModelPipeCount[i] = *(S32*)data; + xModelPipeData[i] = (xModelPipeInfo*)((S32*)data + 1); + } + + xModelLookupCount = 0; + + //PipeForAllSceneModels(PipeCountStuffCB); + + if (xModelLookupCount) + { + xModelLookupList = + (xModelPipeLookup*)xMemAllocSize(xModelLookupCount * sizeof(xModelPipeLookup)); + + xModelLookupCount = 0; + + //PipeForAllSceneModels(PipeAddStuffCB); + } + + xModelBucket_PreCountReset(); + //PipeForAllSceneModels(xModelBucket_PreCountBucket); + + xModelBucket_PreCountAlloc(256); + //PipeForAllSceneModels(xModelBucket_InsertBucket); + + xModelBucket_Init(); + //add_scene_tweaks(); + xPTankPoolSceneEnter(); + zParPTankSceneEnter(); + xDecalInit(); + xFXScenePrepare(); + zLasso_scenePrepare(); + zDispatcher_scenePrepare(); + + S32 total_npcs = xSTAssetCountByType('VIL '); + zNPCMgr_scenePrepare(total_npcs); + + zAnimListInit(); + zGooInit(24); + + zGameScreenTransitionUpdate(_1375, "...initializing scene - base types\n"); + + for (i = 0; i < eBaseTypeCount; i++) + { + s->baseCount[i] = 0; + s->baseList[i] = NULL; + } + + zCollGeom_Init(); + zUI_Init(); + zUIFontInit(); + ztextbox::init(); + //ztalkbox::init(); + ztaskbox::init(); + + xModelInstStaticAlloc = 1; + s->num_base = 0; + + // for (i = 0; sInitTable[i].name; i++) + // { + // U32 typeCount = xSTAssetCountByType(sInitTable[i].assetType); + + // s->baseCount[sInitTable[i].baseType] = typeCount; + // s->num_base += typeCount; + + // if (sInitTable[i].querySubObjects) + // { + // for (U32 j = 0; j < typeCount; j++) + // { + // s->num_base += sInitTable[i].querySubObjects( + // xSTFindAssetByType(sInitTable[i].assetType, j, NULL)); + // } + // } + // } + + //add_dynamic_types(*s); + + if (s->num_base) + { + s->base = (xBase**)xMemAllocSize(s->num_base * sizeof(xBase*)); + } + else + { + s->base = NULL; + } + + zSceneObjHashtableInit(4096); + xFFXPoolInit(12); + xFFXShakePoolInit(3); + xFFXRotMatchPoolInit(1); + xEntSceneInit(); + xEntMotionDebugInit(s->baseCount[eBaseTypePlatform] + s->baseCount[eBaseTypePendulum] + + s->baseCount[eBaseTypeButton]); + zLightSetVolume(NULL); + //xPartitionReset(); + xFXRibbonSceneEnter(); + + U32 base_idx = 0; + + // for (i = 0; sInitTable[i].name; i++) + // { + // HACK_BASETYPE = sInitTable[i].baseType; + + // if (sInitTable[i].func) + // { + // base_idx = sInitTable[i].func(s, &sInitTable[i], base_idx); + // } + // } + + //init_dynamic_types(*s, base_idx); + + s->num_update_base = 0; + + for (i = 0; i < s->num_base; i++) + { + // if (BaseTypeNeedsUpdate(s->base[i]->baseType)) + // { + // s->num_update_base++; + // } + } + + s->update_base = (xBase**)xMemAllocSize(s->num_update_base * sizeof(xBase*)); + + base_idx = 0; + + for (i = 0; i < s->num_base; i++) + { + // if (BaseTypeNeedsUpdate(s->base[i]->baseType)) + // { + // s->update_base[base_idx] = s->base[i]; + // } + } + + xModelInstStaticAlloc = 0; + + zGameScreenTransitionEnd(); + zSceneObjHashtableUsage(); + zUI_ScenePortalInit(s); + zLightResolveLinks(); + zRenderStateInit(); + xFXStreakInit(); + xFXShineInit(); + xFXFireworksInit("PAREMIT_FIREWORKS_TRAIL", "PAREMIT_FIREWORKS1", "PAREMIT_FIREWORKS2", + "Fireworks_explode", "Fireworks_trail"); + //zFeetGetIDs(); + zLightningInit(); + zParCmdFindClipVolumes(); + zEntDestructObj_FindFX(); + zShrapnel_SceneInit(globals.sceneCur); + zCameraTweakGlobal_Reset(); + zActionLineInit(); + xScrFxLetterboxReset(); + xShadowManager_Init(eBaseTypeNPC + 10); + + S32 lkitCount = xSTAssetCountByType('LKIT'); + void* lkitData; + + for (S32 i = 0; i < lkitCount; i++) + { + lkitData = xSTFindAssetByType('LKIT', i, NULL); + + xLightKit_Prepare(lkitData); + } + + xClimateInit(&gClimate); + zSceneInitEnvironmentalSoundEffect(); + + sHackSmoothedUpdate = 1; + + //FootstepHackSceneEnter(); + zEntPickup_SceneEnter(); + xFXSceneInit(); + //zGame_HackGalleryInit(); + iSndSuspendCD(0); +} + +static U32 BaseTypeNeedsUpdate(U8 baseType) +{ + if (baseType == eBaseTypeUnknown || baseType == eBaseTypePlayer || baseType == eBaseTypeEnv || + baseType == eBaseTypeCamera || baseType == eBaseTypeStatic || + baseType == eBaseTypeMovePoint || baseType == eBaseTypeBubble || + baseType == eBaseTypePortal || baseType == eBaseTypeGroup || baseType == eBaseTypeSFX || + baseType == eBaseTypeFFX || baseType == eBaseTypeVFX || baseType == eBaseTypeCounter || + baseType == eBaseTypeProjectile || baseType == eBaseTypeGust || + baseType == eBaseTypeVolume || baseType == eBaseTypeDispatcher || + baseType == eBaseTypeCond || baseType == eBaseTypeUI || + baseType == eBaseTypeProjectileType || baseType == eBaseTypeLobMaster || + baseType == eBaseTypeCutsceneMgr || baseType == eBaseTypeHud || + baseType == eBaseTypeNPCProps || baseType == eBaseTypeParticleEmitterProps || + baseType == eBaseTypeCruiseBubble || baseType == eBaseTypeTextBox || + baseType == eBaseTypeTalkBox || baseType == eBaseTypeTaskBox || + baseType == eBaseTypeBoulderGenerator || baseType == eBaseTypeNPCSettings || + baseType == eBaseTypeTurret) + { + return 0; + } + + return 1; +} + +static void PipeForAllSceneModels(void (*pipeCB)(RpAtomic* data, U32 pipeFlags, U32 subObjects)) +{ + // non-matching: wrong registers + + S32 i, j, k; + S32 numModels = xSTAssetCountByType('MODL'); + + for (i = 0; i < numModels; i++) + { + RpAtomic* model = (RpAtomic*)xSTFindAssetByType('MODL', i, NULL); + + if (model) + { + PKRAssetTOCInfo ainfo; + U32 numSubObjects, remainSubObjBits, currSubObjBits; + RpAtomic* tempmodel; + + xSTGetAssetInfoByType('MODL', i, &ainfo); + + numSubObjects = 0; + tempmodel = model; + + do + { + numSubObjects++; + tempmodel = iModelFile_RWMultiAtomic(tempmodel); + } while (tempmodel); + + remainSubObjBits = (1 << numSubObjects) - 1; + + for (j = 0; j < xModelPipeNumTables; j++) + { + for (k = 0; k < xModelPipeCount[j]; k++) + { + if (ainfo.aid == xModelPipeData[j][k].ModelHashID) + { + currSubObjBits = remainSubObjBits & xModelPipeData[j][k].SubObjectBits; + + if (currSubObjBits) + { + pipeCB(model, xModelPipeData[j][k].PipeFlags, currSubObjBits); + } + + remainSubObjBits &= ~currSubObjBits; + + if (!remainSubObjBits) + { + goto loc_800B1698; + } + } + } + } + + if (remainSubObjBits) + { + pipeCB(model, 0, remainSubObjBits); + } + } + + loc_800B1698: + continue; + } +} + +static void PipeAddStuffCB(RpAtomic* data, U32 pipeFlags, U32) +{ + if (pipeFlags) + { + xModelLookupList[xModelLookupCount].model = data; + xModelLookupList[xModelLookupCount].PipeFlags = pipeFlags; + xModelLookupCount++; + } +} + +static void PipeCountStuffCB(RpAtomic*, U32 pipeFlags, U32) +{ + if (pipeFlags) + { + xModelLookupCount++; + } +} + +void zSceneSet(xBase* b, S32 index) +{ + globals.sceneCur->base[index] = b; +} + +static U32 zSceneInitFunc_Dispatcher(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + S32 count; + + count = s->baseCount[desc->baseType]; + + if (count) + { + st_ZDISPATCH_DATA* dpat_pool = zDispatcher_memPool(count); + s->baseList[desc->baseType] = dpat_pool; + + for (S32 idx = 0; idx < count; idx++) + { + xBase* b = zDispatcher_getInst(dpat_pool, idx); + xEntAsset* asset = (xEntAsset*)xSTFindAssetByType('DPAT', idx, NULL); + + zSceneSet(b, base_idx); + zDispatcher_Init((st_ZDISPATCH_DATA*)b, asset); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + } + + return base_idx; +} + +static U32 zSceneInitFunc_LobMaster(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + return base_idx; +} + +static U32 zSceneInitFunc_Volume(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + S32 count; + + count = s->baseCount[desc->baseType]; + + zVolumeInit(); + + if (count) + { + s->baseList[desc->baseType] = zVolumeGetVolume(0); + + for (S32 idx = 0; idx < count; idx++) + { + xBase* b = zVolumeGetVolume(idx); + + zLightSetVolume((zVolume*)b); + + zSceneSet(b, base_idx); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + } + + return base_idx; +} + +static U32 zSceneInitFunc_Surface(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + S32 count; + + count = s->baseCount[desc->baseType]; + + if (count) + { + s->baseList[desc->baseType] = xSurfaceGetByIdx(0); + + for (S32 idx = 0; idx < count; idx++) + { + xBase* b = xSurfaceGetByIdx(idx); + + zSceneSet(b, base_idx); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + } + + return base_idx; +} + +static U32 zSceneInitFunc_Camera(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + S32 count; + zCamMarker* camBlock; + + count = s->baseCount[desc->baseType]; + + if (count) + { + camBlock = (zCamMarker*)xMemAllocSize(count * sizeof(zCamMarker)); + s->baseList[desc->baseType] = camBlock; + + for (S32 idx = 0; idx < count; idx++) + { + xBase* b = &camBlock[idx]; + xCamAsset* assetCam = (xCamAsset*)xSTFindAssetByType('CAM ', idx, NULL); + + zSceneSet(b, base_idx); + zCamMarkerInit(b, assetCam); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + } + + return base_idx; +} + +static U32 zSceneInitFunc_Player(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + // REFERENCE BFBB + return 0; +} + +static U32 zSceneInitFunc_MovePoint(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + S32 count; + U32 assetSize; + zMovePoint* movpBlock; + + assetSize = 0; + count = s->baseCount[desc->baseType]; + movpBlock = zMovePoint_GetMemPool(count); + + if (movpBlock) + { + s->baseList[desc->baseType] = movpBlock; + + for (S32 idx = 0; idx < count; idx++) + { + xBase* b = zMovePoint_GetInst(idx); + xBaseAsset* basset = (xBaseAsset*)xSTFindAssetByType('MVPT', idx, &assetSize); + + zSceneSet(b, base_idx); + zMovePointInit(zMovePoint_GetInst(idx), (xMovePointAsset*)basset); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + } + + return base_idx; +} + +static U32 zSceneInitFunc_Default(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + U8* block; + S32 count; + U32 assetSize, offset; + xBase* b; + + block = NULL; + assetSize = 0; + offset = desc->sizeRuntime; + count = s->baseCount[desc->baseType]; + + if (count) + { + block = (U8*)xMemAllocSize(count * offset); + + s->baseList[desc->baseType] = (xBase*)block; + } + + for (S32 i = 0; i < count; i++) + { + void* asset = xSTFindAssetByType(desc->assetType, i, &assetSize); + b = (xBase*)(block + i * offset); + + zSceneSet(b, base_idx); + + if (desc->objectInitFunc) + { + desc->objectInitFunc(b, asset); + } + + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + + return base_idx; +} + +static U32 zSceneInitFunc_DefaultEnt(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) +{ + U8* block; + S32 count; + U32 assetSize, offset; + xBase* b; + + block = NULL; + assetSize = 0; + offset = desc->sizeRuntime; + count = s->baseCount[desc->baseType]; + + if (count) + { + block = (U8*)xMemAllocSize(count * offset); + + s->baseList[desc->baseType] = (xBase*)block; + } + + for (S32 i = 0; i < count; i++) + { + void* asset = xSTFindAssetByType(desc->assetType, i, &assetSize); + b = (xBase*)(block + i * offset); + + zSceneSet(b, base_idx); + + if (desc->objectInitFunc) + { + desc->objectInitFunc(b, asset); + } + + //xSceneAddEnt(s, s->ents[base_idx]); + zSceneObjHashtableAdd(b->id, b); + + base_idx++; + } + + return base_idx; +} diff --git a/src/SB/Game/zSurface.cpp b/src/SB/Game/zSurface.cpp new file mode 100644 index 0000000..ebb00ac --- /dev/null +++ b/src/SB/Game/zSurface.cpp @@ -0,0 +1,254 @@ +#include "zSurface.h" + +#include "xstransvc.h" + +extern volatile S32 sMapperCount; +extern zMaterialMapAsset* sMapper[1]; + +extern xSurface sDef_surf; + +extern F32 lbl_803CDEE8; // 0.34906587 // @798 +extern F32 lbl_803CDEE0; // 3.1415927 // pi // @796 +extern F32 lbl_803CDEF0; // 176.0 // @801 +extern F32 lbl_803CDEE4; // 180.0 // @797 + +extern F32 lbl_803CDEDC; // -1.0 // @702 + +extern F32 lbl_803CDED8; // 1.0 // @701 + +extern const char* zSurface_strings[]; + +xSurface& zSurfaceGetDefault() +{ + return sDef_surf; +} + +void zSurfaceGetName(S32 type, char* buffer) +{ + *buffer = NULL; + switch (type) + { + case 0: + strcpy(buffer, "DEFAULT"); + break; + case 1: + strcpy(buffer, "TILE"); + break; + case 2: + strcpy(buffer, "CARPET"); + break; + case 3: + strcpy(buffer, "SHORTGRASS"); + break; + case 4: + strcpy(buffer, "LONGGRASS"); + break; + case 5: + strcpy(buffer, "GRAVEL"); + break; + case 6: + strcpy(buffer, "DIRT"); + break; + case 7: + strcpy(buffer, "MUD"); + break; + case 8: + strcpy(buffer, "THORNS"); + break; + case 9: + strcpy(buffer, "METAL"); + break; + case 10: + strcpy(buffer, "SHEETMETAL"); + break; + case 11: + strcpy(buffer, "CONCRETE"); + break; + case 12: + strcpy(buffer, "MARBLE"); + break; + case 13: + strcpy(buffer, "STONE"); + break; + case 14: + strcpy(buffer, "WOOD"); + break; + case 15: + strcpy(buffer, "SNOW"); + break; + case 16: + strcpy(buffer, "ICE"); + break; + case 17: + strcpy(buffer, "SHALLOWWATER"); + break; + case 18: + strcpy(buffer, "DEEPWATER"); + break; + case 19: + strcpy(buffer, "TAR"); + break; + case 20: + strcpy(buffer, "SPECIAL1"); + break; + case 21: + strcpy(buffer, "DeepAcid"); + break; + case 22: + strcpy(buffer, "NONE"); + } +} + +F32 zSurfaceGetDamping(const xSurface* surf, F32 min_vel) +{ + return xpow(min_vel, surf->friction); +} + +S32 zSurfaceGetSlickness(const xSurface* surf) +{ + return (int)(lbl_803CDED8 / surf->friction); +} + +F32 zSurfaceGetOutOfBoundsDelay(const xSurface& s) +{ + if (s.moprops) + { + return ((zSurfaceProps*)s.moprops)->asset->oob_delay; + } + return lbl_803CDEDC; +} + +F32 zSurfaceGetFriction(const xSurface* surf) +{ + return surf->friction; +} + +U32 zSurfaceGetStandOn(const xSurface* surf) +{ + if (surf->moprops) + { + return !(((zSurfaceProps*)surf->moprops)->asset->phys_flags & 8); + } + return 1; +} + +U32 zSurfaceGetSticky(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->game_sticky; + } + return 0; +} + +U32 zSurfaceGetDamagePassthrough(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->game_damage_flags & 1; + } + return 0; +} + +S32 zSurfaceGetDamageType(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->game_damage_type; + } + return 0; +} + +U32 zSurfaceGetMatchOrient(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 2; + } + return 0; +} + +F32 zSurfaceGetSlideStopAngle(const xSurface* surf) +{ + if (surf->moprops) + { + return ((((zSurfaceProps*)surf->moprops)->asset->sld_start) * PI) / 176.0f; + } + return PI / 9; +} + +F32 zSurfaceGetSlideStartAngle(const xSurface* surf) +{ + if (surf->moprops) + { + return ((((zSurfaceProps*)surf->moprops)->asset->sld_start) * PI) / 176.0f; + } + return PI / 9; +} + +U8 zSurfaceOutOfBounds(const xSurface& s) +{ + if (s.moprops) + { + return ((zSurfaceProps*)s.moprops)->asset->phys_flags >> 4 & 1; + } + return 0; +} + +U32 zSurfaceGetStep(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 4; + } + return 0; +} + +U32 zSurfaceGetSlide(const xSurface* surf) +{ + if (surf->moprops) + { + return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 1; + } + return 0; +} + +xSurface* zSurfaceGetSurface(const xCollis* coll) +{ + xSurface* surf = NULL; + + if (coll->flags & 1) + { + if (coll->optr) + { + surf = coll->mptr->Surf; + } + else + { + surf = zSurfaceGetSurface(coll->oid); + } + } + if (surf != NULL) + { + return surf; + } + surf = &sDef_surf; + return surf; +} + +// TODO: Hacked to OK (with volatile sMapperCount and assignment in if), fix later +void zSurfaceRegisterMapper(U32 assetId) +{ + if (sMapperCount >= 1) + { + return; + } + if (!assetId) + { + return; + } + if (sMapper[sMapperCount] = (zMaterialMapAsset*)xSTFindAsset(assetId, 0)) + { + sMapperCount++; + } +} diff --git a/src/SB/Game/zTextBox.cpp b/src/SB/Game/zTextBox.cpp index 00ce1e4..d548cda 100644 --- a/src/SB/Game/zTextBox.cpp +++ b/src/SB/Game/zTextBox.cpp @@ -176,7 +176,7 @@ namespace e.set_text(*(U32*)&argf[0]); } - e.activate(); + //e.activate(); break; } case eEventInvisible: @@ -282,7 +282,7 @@ void ztextbox::render_backdrop() } } -void ztextbox::activate() +void ztextbox::activate(bool skipFirstFrame) { if (flag.active) { @@ -290,7 +290,7 @@ void ztextbox::activate() } flag.active = true; - flag.visible = true; + flag.skipFrame = skipFirstFrame; prev = NULL; next = head_active; @@ -311,7 +311,6 @@ void ztextbox::deactivate() } flag.active = false; - flag.visible = false; if (prev) { diff --git a/src/SB/Game/zTextBox.h b/src/SB/Game/zTextBox.h index 203cd6e..d0f2217 100644 --- a/src/SB/Game/zTextBox.h +++ b/src/SB/Game/zTextBox.h @@ -9,6 +9,26 @@ struct ztextbox : xBase { + /* + struct asset_type : xDynAsset + { + uint32 text; + basic_rect_0 bounds; + uint32 font; + _class_25 size; + _class_29 space; + color_type color; + _class_1 inset; + _enum_1 xjustify; + _enum_2 yjustify; + _enum_3 expand; + float32 max_height; + _class_14 backdrop; + color_type shadowColor; + float32 shadowOffsetX; + float32 shadowOffsetY; + }; + */ struct asset_type : xDynAsset { struct color_type @@ -60,15 +80,17 @@ struct ztextbox : xBase color_type color; U32 texture; } backdrop; + color_type shadowColor; + F32 shadowOffsetX; + F32 shadowOffsetY; }; struct { - bool active : 1; // bit 24 - bool dirty : 1; // bit 25 - bool show_backdrop : 1; // bit 26 - bool visible : 1; // bit 27 - bool hack_invisible : 1; // bit 28 + bool active : 1; + bool dirty : 1; + bool show_backdrop : 1; + bool skipFrame : 1; } flag; asset_type* asset; xtextbox tb; @@ -88,7 +110,7 @@ struct ztextbox : xBase void reset(); void render(); void render_backdrop(); - void activate(); + void activate(bool skipFirstFrame); void deactivate(); void set_text(const char* s); void set_text(U32 id); diff --git a/src/SB/Game/zUIController.cpp b/src/SB/Game/zUIController.cpp new file mode 100644 index 0000000..065728d --- /dev/null +++ b/src/SB/Game/zUIController.cpp @@ -0,0 +1,16 @@ +#include "zUIController.h" + +void zUIController_Init(zUIController*, zUIControllerAsset*) +{ +} + +void zUIController_Init(xBase&, xDynAsset&, unsigned long) +{ + zUIController* UIControl = 0; + zUIControllerAsset* UIControlAsset = 0; + zUIController_Init(UIControl, UIControlAsset); +} + +void zUIController::DoRender() const +{ +} diff --git a/src/SB/Game/zUIController.h b/src/SB/Game/zUIController.h new file mode 100644 index 0000000..1881af8 --- /dev/null +++ b/src/SB/Game/zUIController.h @@ -0,0 +1,4 @@ +#ifndef ZUICONTROLLER_H +#define ZUICONTROLLER_H + +#endif diff --git a/src/SB/Game/zUICustom.cpp b/src/SB/Game/zUICustom.cpp new file mode 100644 index 0000000..9ebaf50 --- /dev/null +++ b/src/SB/Game/zUICustom.cpp @@ -0,0 +1,79 @@ +#include "zUICustom.h" + +unsigned char zUICustomConditionallyDisabled::PreRender() +{ + return m_bCondition; // struct sees to be missing some data +} + +unsigned char zUICustomConditionallyDisabled::PreAutoMenu() +{ + return m_bCondition; // struct sees to be missing some data +} + +void zUICustomImageSlideshow::SetTextureList(xGroup* m_TextureGroup) +{ + xGroupGetCount(m_TextureGroup); +} + +void zUICustom::PostApplyMotionFrame(zUIMotionFrame*) +{ +} + +void zUICustom::PreApplyMotionFrame(zUIMotionFrame*) +{ +} + +void zUICustom::PostInitMotion() +{ +} + +void zUICustom::PreInitMotion() +{ +} + +void zUICustom::Exit() +{ +} + +void zUICustom::PostRender() +{ +} + +U8 zUICustom::PreAutoMenu() +{ + return 1; +} + +U8 zUICustom::PreRender() +{ + return 1; +} + +void zUICustom::PostUpdate(float) +{ +} + +void zUICustom::PreUpdate(float) +{ +} + +U8 zUICustom::HandleEvent(xBase*, unsigned int, const float*, xBase*, unsigned int) +{ + return 1; +} + +void zUICustom::ResetMotion() +{ +} + +void zUICustom::Reset() +{ +} + +void zUICustom::Setup() +{ +} + +void zUICustom::Init() +{ +} diff --git a/src/SB/Game/zUICustom.h b/src/SB/Game/zUICustom.h new file mode 100644 index 0000000..848e20a --- /dev/null +++ b/src/SB/Game/zUICustom.h @@ -0,0 +1,4 @@ +#ifndef ZUICUSTOM_H +#define ZUICUSTOM_H + +#endif diff --git a/src/SB/Game/zUIUserString.cpp b/src/SB/Game/zUIUserString.cpp new file mode 100644 index 0000000..452a565 --- /dev/null +++ b/src/SB/Game/zUIUserString.cpp @@ -0,0 +1,15 @@ +void zUIUserString_Init(zUIUserString*, zUIUserStringAsset*) +{ +} + +void zUIUserString_Init(xBase&, xDynAsset&, unsigned long) +{ + zUIUserString* zUIString = 0; + zUIUserStringAsset* zUIStringAsset = 0; + zUIUserString_Init(zUIString, zUIStringAsset); +} + +U32 zUIUserString::GetSortKey() const +{ + return 0; +} diff --git a/src/SB/Game/zUIUserString.h b/src/SB/Game/zUIUserString.h new file mode 100644 index 0000000..320985e --- /dev/null +++ b/src/SB/Game/zUIUserString.h @@ -0,0 +1,4 @@ +#ifndef ZUIUSERSTRING_H +#define ZUIUSERSTRING_H + +#endif diff --git a/src/SB/Game/zVar.cpp b/src/SB/Game/zVar.cpp new file mode 100644 index 0000000..f423f56 --- /dev/null +++ b/src/SB/Game/zVar.cpp @@ -0,0 +1,164 @@ +#include "zVar.h" + +#include + +#include "zGlobals.h" +#include "xutil.h" + +char* var_text(const substr& str); +U32 zVarEntryCB_SndFXVol(void*); +U32 zVarEntryCB_SndMusicVol(void*); + +extern const char zVar_strings[]; + +S32 zVarEntryCB_IsVisible(void* context) +{ + return 0; +} + +S32 zVarEntryCB_IsEnabled(void* arg) +{ + return 0; +} + +S32 zVarEntryCB_CounterValue(void* arg) +{ + // Given the void argument type, no idea what type this actually is. + // What we do know that at an offset 5 words in there's a signed S16. + struct something + { + U32 stuff[5]; + S16 theValue; + }; + return ((something*)arg)->theValue; +} + +S32 zVarEntryCB_Minute(void*) +{ + return iGetMinute(); +} + +S32 zVarEntryCB_Hour(void*) +{ + return iGetHour(); +} + +S32 zVarEntryCB_Date(void*) +{ + return iGetDay() + iGetMonth() * 0x64; +} + +S32 zVarEntryCB_CurrentRoom(void*) +{ + char buffer[16]; + sprintf(buffer, &zVar_strings[0xbaa] /*"%s"*/, + xUtil_idtag2string(globals.sceneCur->sceneID, 0)); + + S32 room = (buffer[2] - '0') * 10 + (buffer[3] - '0'); + + // Convert the most significant char to uppercase + // The lowercase variable doesn't exist in the ps4 symbols but I can't + // figure out how to get a match otherwise. + U32 mostSignificantChar = buffer[0]; + bool lowercase = false; + if (mostSignificantChar >= 'a' && mostSignificantChar <= 'z') + { + lowercase = true; + } + if (lowercase) + { + mostSignificantChar -= 0x20; + } + + return room + ((mostSignificantChar - 'A') + 1) * 100; +} + +S32 zVarEntryCB_CurrentSceneLetter(void*) +{ + char buffer[16]; + sprintf(buffer, &zVar_strings[0x10] /*"%s"*/, xUtil_idtag2string(globals.sceneCur->sceneID, 0)); + + // Convert the most significant char to uppercase + // The lowercase variable doesn't exist in the ps4 symbols but I can't + // figure out how to get a match otherwise. + U32 mostSignificantChar = buffer[0]; + bool lowercase = false; + if (mostSignificantChar >= 'a' && mostSignificantChar <= 'z') + { + lowercase = true; + } + if (lowercase) + { + mostSignificantChar -= 0x20; + } + + return (mostSignificantChar - 'A') + 1; +} + +U32 zVarEntryCB_VibrationOn(void* arg) +{ + // I'm pretty sure they actually and'd with a bit mask here, I couldn't find + // another way (such as casting to bool) to get the right instructions. + return globals.option_vibration & 0x1; +} + +U32 zVarEntryCB_MCAvailable(void* arg) +{ + if (xSGGameIsEmpty(NULL, 0) == 1) + { + if (xSGGameIsEmpty(NULL, 1) == 1) + { + return 0; + } + if (xSGGameIsEmpty(NULL, 1) == 0) + { + return 2; + } + } + else if (xSGGameIsEmpty(NULL, 0) == 0) + { + if (xSGGameIsEmpty(NULL, 1) == 1) + { + return 1; + } + if (xSGGameIsEmpty(NULL, 1) == 0) + { + return 3; + } + } + + return 0; +} + +U32 zVarEntryCB_SndFXVol(void* arg) +{ + F64 f0 = 10.0; + F64 f1 = 0.5; + F64 f2 = gSnd.categoryVolFader[0]; + + f2 *= f1; + f2 = f0 + f2; + + return f2; +} + +U32 zVarEntryCB_SndMusicVol(void* arg) +{ + F64 f0 = 10.0; + F64 f1 = 0.5; + F64 f2 = gSnd.categoryVolFader[2]; + + f2 *= f1; + f2 = f0 + f2; + + return f2; +} + +U32 zVarEntryCB_SndMode(void* arg) +{ + return gSnd.stereo; +} + +void zVarNewGame() +{ +} diff --git a/src/SB/Game/zVent.cpp b/src/SB/Game/zVent.cpp new file mode 100644 index 0000000..b63b61e --- /dev/null +++ b/src/SB/Game/zVent.cpp @@ -0,0 +1 @@ +#include "zVent.h" diff --git a/src/SB/Game/zVent.h b/src/SB/Game/zVent.h new file mode 100644 index 0000000..b042514 --- /dev/null +++ b/src/SB/Game/zVent.h @@ -0,0 +1,4 @@ +#ifndef ZVENT_H +#define ZVENT_H + +#endif diff --git a/src/SB/Game/zVolume.cpp b/src/SB/Game/zVolume.cpp new file mode 100644 index 0000000..859b5be --- /dev/null +++ b/src/SB/Game/zVolume.cpp @@ -0,0 +1,189 @@ +#include "zVolume.h" + +#include "xEvent.h" + +struct PreCalcOcclude +{ + xVec4 DepthVec; + xVec4 FrustVec[4]; +}; + +extern zVolume* vols; +extern U16 nvols; + +extern S32 gOccludeCount; +extern zVolume* gOccludeList[10]; +extern S32 gOccludeCalcCount; +extern PreCalcOcclude gOccludeCalc[10]; + +extern float lbl_803CDFB8; + +S32 zVolumeEventCB(xBase*, xBase* to, U32 toEvent, const F32*, xBase*, U32) +{ + zVolume* vol = (zVolume*)to; + S32 i; + + switch (toEvent) + { + case eEventReset: + { + vol->Reset(); + break; + } + case eEventOccludeOn: + { + if (gOccludeCount == 10) + { + return 1; + } + + for (i = 0; i < gOccludeCount; i++) + { + if (gOccludeList[i] == vol) + { + return 1; + } + } + + gOccludeList[gOccludeCount] = vol; + gOccludeCount++; + + break; + } + case eEventOccludeOff: + { + for (i = 0; i < gOccludeCount; i++) + { + if (gOccludeList[i] == vol) + { + gOccludeList[gOccludeCount] = gOccludeList[gOccludeCount - 1]; + gOccludeCount--; + + return 1; + } + } + + break; + } + } + + return 1; +} + +void zVolume_OccludePrecalc(xVec3* camPos) +{ + S32 i; + S32 j; + xVec3 corner[5]; + zVolume* vol; + xVolumeAsset* a; + F32 c; + F32 s; + PreCalcOcclude* calc; + xVec3 d1; + xVec3 d2; + xVec4 locFrustVec[4]; + F32 depthdot; + F32 camdot; + F32 testdot1; + F32 testdot2; + + gOccludeCalcCount = 0; + + for (i = 0; i < gOccludeCount; i++) + { + vol = gOccludeList[i]; + a = vol->asset; + + c = icos(a->rot); + s = isin(a->rot); + + calc = &gOccludeCalc[gOccludeCalcCount]; + + corner[0].x = c * (a->bound.box.box.lower.x - a->xpivot) + a->xpivot; + corner[0].y = a->bound.box.box.lower.y; + corner[0].z = s * (a->bound.box.box.lower.x - a->xpivot) + a->bound.box.box.lower.z; + + corner[1].y = a->bound.box.box.lower.y; + corner[1].x = c * (a->bound.box.box.upper.x - a->xpivot) + a->xpivot; + corner[1].z = s * (a->bound.box.box.upper.x - a->xpivot) + a->bound.box.box.lower.z; + + corner[2].x = c * (a->bound.box.box.upper.x - a->xpivot) + a->xpivot; + corner[2].y = a->bound.box.box.upper.y; + corner[2].z = s * (a->bound.box.box.upper.x - a->xpivot) + a->bound.box.box.lower.z; + + corner[3].x = c * (a->bound.box.box.lower.x - a->xpivot) + a->xpivot; + corner[3].y = a->bound.box.box.upper.y; + corner[3].z = s * (a->bound.box.box.lower.x - a->xpivot) + a->bound.box.box.lower.z; + + corner[4] = corner[0]; + + xVec3Sub(&d1, &corner[1], &corner[0]); + xVec3Sub(&d2, &corner[2], &corner[0]); + + xVec3Cross((xVec3*)calc, &d1, &d2); + xVec3Normalize((xVec3*)calc, (xVec3*)calc); + + depthdot = xVec3Dot((xVec3*)calc, &corner[0]); + camdot = xVec3Dot((xVec3*)calc, camPos); + + if (camdot > depthdot) + { + xVec3Inv((xVec3*)calc, (xVec3*)calc); + + camdot = -camdot; + depthdot = -depthdot; + } + + if (iabs(camdot - depthdot) >= lbl_803CDFB8) + { + calc->DepthVec.w = depthdot; + + for (j = 0; j < 4; j++) + { + xVec3Sub(&d1, &corner[j], camPos); + xVec3Sub(&d2, &corner[j + 1], camPos); + xVec3Cross((xVec3*)&locFrustVec[j], &d1, &d2); + xVec3Normalize((xVec3*)&locFrustVec[j], (xVec3*)&locFrustVec[j]); + } + + testdot1 = xVec3Dot((xVec3*)&locFrustVec[0], &corner[0]); + testdot2 = xVec3Dot((xVec3*)&locFrustVec[0], &corner[2]); + + if (testdot1 > testdot2) + { + for (j = 0; j < 4; j++) + { + xVec3Inv((xVec3*)&locFrustVec[j], (xVec3*)&locFrustVec[j]); + } + } + + for (j = 0; j < 4; j++) + { + locFrustVec[j].w = xVec3Dot((xVec3*)&locFrustVec[j], &corner[j]); + } + + calc->FrustVec[0].x = locFrustVec[0].w; + calc->FrustVec[0].y = locFrustVec[1].w; + calc->FrustVec[0].z = locFrustVec[2].w; + calc->FrustVec[0].w = locFrustVec[3].w; + + calc->FrustVec[1].x = locFrustVec[0].x; + calc->FrustVec[1].y = locFrustVec[1].x; + calc->FrustVec[1].z = locFrustVec[2].x; + calc->FrustVec[1].w = locFrustVec[3].x; + + calc->FrustVec[2].x = locFrustVec[0].y; + calc->FrustVec[2].y = locFrustVec[1].y; + calc->FrustVec[2].z = locFrustVec[2].y; + calc->FrustVec[2].w = locFrustVec[3].y; + + calc->FrustVec[3].x = locFrustVec[0].z; + calc->FrustVec[3].y = locFrustVec[1].z; + calc->FrustVec[3].z = locFrustVec[2].z; + calc->FrustVec[3].w = locFrustVec[3].z; + + gOccludeCalcCount++; + } + } +} diff --git a/src/SB/Game/zWad1.cpp b/src/SB/Game/zWad1.cpp index 5134a38..0e61c3d 100644 --- a/src/SB/Game/zWad1.cpp +++ b/src/SB/Game/zWad1.cpp @@ -1,1144 +1,25 @@ #include "zWad1.h" -#include "xGlobals.h" -#include "zGlobals.h" -// zEnv - -void zEnvEventCB(xBase* to, U32 toEvent, F32* toParam, xBase* toParamWidget) -{ -} - -void zEnvLoad(_zEnv* ent, xSerial* s) -{ - xBaseLoad(ent, s); -} - -void zEnvSave(_zEnv* ent, xSerial* s) -{ - xBaseSave(ent, s); -} - -void zEnvRender(xEnv* env) -{ - RpWorld* world = env->geom->world; - S32 num = RpWorldGetNumMaterials(world); - - for (S32 i = 0; i < num; i++) - { - xSurface* sp = zSurfaceGetSurface(i); - zSurfaceProps* pp = (zSurfaceProps*)sp->moprops; - - if (pp && pp->asset && pp->texanim_flags & 0x1) - { - RpMaterial* mp = RpWorldGetMaterial(world, i); - - if (mp) - { - xGroup* g = (xGroup*)pp->texanim[0].group_ptr; - - if (g) - { - U32 texid = xGroupGetItem(g, pp->texanim[0].group_idx); - RwTexture* texptr = (RwTexture*)xSTFindAsset(texid, NULL); - - if (texptr) - { - RpMaterialSetTexture(mp, texptr); - } - } - } - } - } - - xEnvRender(env, FALSE); -} - -void zEnvStartingCamera(_zEnv*) -{ - return; -} - -void zEnvSetup(_zEnv* env) -{ - // TODO - // I don't think the struct is correct - - // This function seems to be correct in BFBB, our globals struct is fucked though. - // Keep this the way it is, and fix the struct - - xBaseSetup(env); - iEnvLightingBasics((iEnv*)globals.sceneCur->env->geom, (xEnvAsset*)env->easset); -} - -// Again, Copied from Battle, Needs a good amount of work -void zEnvInit(_zEnv* env, xEnvAsset* easset) -{ - U32 bufsize; - void* buf; - - xBaseInit(env, easset); - - env->easset = easset; - //env->eventFunc = zEnvEventCB; - - if (env->linkCount) - { - env->link = (xLinkAsset*)(env->easset + 1); - } - - globals.sceneCur->zen = env; - globals.sceneCur->zen = env; - - xSTAssetCountByType('BSP '); - - buf = xSTFindAsset(easset->bspAssetID, &bufsize); - - if (buf) - { - xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 0); - } - - zSurfaceRegisterMapper(easset->bspMapperID); - - if (easset->bspCollisionAssetID) - { - buf = xSTFindAsset(easset->bspCollisionAssetID, &bufsize); - - if (buf) - { - xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 1); - } - } - - if (easset->bspFXAssetID) - { - buf = xSTFindAsset(easset->bspFXAssetID, &bufsize); - - if (buf) - { - xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 2); - } - } - - if (easset->bspCameraAssetID) - { - buf = xSTFindAsset(easset->bspCameraAssetID, &bufsize); - - if (buf) - { - xEnvLoadBsp(globals.sceneCur->env, buf, bufsize, 3); - } - } - - if (globals.sceneCur->env && globals.sceneCur->env->geom) - { - zLightResetAll(globals.sceneCur->env); - iLightInit(globals.sceneCur->env->geom->world); - } -} - -void zEnvInit(void* env, void* easset) -{ - zEnvInit((_zEnv*)env, (xEnvAsset*)easset); -} - -// zEGenerator - -void zEGenerator_TurnOn(zEGenerator* egen) -{ - zEGenAsset* zasset; - xAnimPlay* aplay; - xAnimSingle* asing; - U16 itgt; - U16 imp; - S32 i; - xLinkAsset* link; - U32 dstAssetID; - xBase* b; - xVec3 destOffset; - xEnt* ent; - //S32 i; - _tagLightningAdd add; -} - -void zEGenerator_Render(zEGenerator* egen) -{ - xEntRender(egen); -} - -void zEGenerator_Update(zEGenerator* egen, xScene* sc, F32 dt) -{ - xBase* b; - zEnt* ent; -} - -void zEGenerator_Move(zEGenerator* egen, xScene* xscn, F32 tmpFloat) -{ -} - -void zEGenerator_Reset(zEGenerator* egen, xScene* xscn) -{ - zEntReset((zEnt*)egen); - zEGenAsset* zasset = (zEGenAsset*)egen->asset; - egen->flags = (U16)zasset->flags; - if (egen->flags & 1) - { - zEGenerator_TurnOn(egen); - } - else - { - zEGenerator_TurnOff(egen); - } - if (zasset->moreFlags & 0b100) - { - egen->chkby = XENT_COLLTYPE_NONE; - } - else - { - egen->chkby = XENT_COLLTYPE_PLYR | XENT_COLLTYPE_NPC; - } - egen->bupdate((xEnt*)egen, (xVec3*)&egen->model->Mat->pos); -} - -void zEGenerator_Load(zEGenerator* ent, xSerial* s) -{ - zEntLoad(ent, s); -} - -void zEGenerator_Save(zEGenerator* ent, xSerial* s) -{ - zEntSave(ent, s); -} - -void zEGenerator_Setup(zEGenerator* egen, xScene* xscn) -{ - zEntSetup(egen); - egen->num_dsts = 0; - for (S32 i = 0; i < egen->linkCount; i++) - { - xLinkAsset* la = (xLinkAsset*)&egen->link[i]; - xBase* b = (xBase*)zSceneFindObject(la->dstAssetID); - if (b != NULL && la->dstEvent == 0xc0) - { - if (b->baseType == eBaseTypeMovePoint) - { - egen->num_dsts++; - } - else if (b->baseFlags & 0x20) - { - egen->num_dsts++; - } - } - } -} - -void zEGenerator_Init(void* egen, void* asset) -{ -} - -// zDispatcher - -extern st_ZDISPATCH_CONTEXT lbl_80254E00; -extern char lbl_80254E10[512]; - -extern S32 g_zdsp_init; -extern S32 warned_zDispatcher; -extern signed char init_zDispatcher; -extern S32 oldVibrationOption; -extern U32 oldSoundMode; -extern U32 oldMusicVolume; -extern U32 oldSFXVolume; - -extern st_ZDISPATCH_DEPOT g_zdsp_depot; - -extern iColor_tag _1143; - -extern iColor_tag _1142; -extern F32 _1179; -extern F32 _1180; -extern F32 _1181; -extern F32 _1197; -extern F64 _1199; - -extern U8 menu_fmv_played; -extern char zEventLogBuf[256][20]; - -S16 zDispatcher_GetCurrentWorld() -{ -} - -U32 zDispatcher_FindNextValidWorld(U32 sceneID) -{ - char sceneName[4]; - S32 worldIndex; - S32 i; - S32 j; - S32 newIndex; -} - -U32 zDispatcher_FindTaskPointer(U32 sceneID, S32 task) -{ - char sceneName[4]; - S32 i; - S32 j; -} - -void zDispatcher_FindWorldTask(U32 sceneID, S32& world, S32& task) -{ - char sceneName[4]; - S32 i; - S32 j; -} - -// WIP -// FIXME: This switch is a mess, good luck. - -// PORTED DIRECTLY FROM BFBB -// NEEDS A LOT OF WORK -S32 ZDSP_elcb_event(xBase*, xBase* xb, U32 toEvent, const F32* toParam, xBase* toParamWidget) -{ - st_ZDISPATCH_DATA* dspdata = (st_ZDISPATCH_DATA*)xb; - switch (toEvent) - { - case 10: - ZDSP_instReset(dspdata, globals.sceneCur); - break; - case 0x129: - zMusicNotifyEvent(toParam, toParamWidget); - break; - case 0x60: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 0); - break; - case 0x61: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 1); - break; - case 0x62: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 2); - break; - case 0x63: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_CFGSET, 3); - break; - case 0x64: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_VIBESET, 1); - break; - case 0x65: - ZDSP_injectCmd(dspdata, ZDSP_CMD_CTRL_VIBESET, 0); - break; - case 0x66: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDMOD_SET, 0); - break; - case 0x67: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDMOD_SET, 1); - break; - - case 0x68: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDVOL_INCR); - break; - case 0x69: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SNDVOL_DECR); - break; - case 0x6a: - ZDSP_injectCmd(dspdata, ZDSP_CMD_MUSVOL_INCR); - break; - case 0x6b: - ZDSP_injectCmd(dspdata, ZDSP_CMD_MUSVOL_DECR); - break; - - case 0x6c: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SFXVOL_INCR); - break; - case 0x6d: - ZDSP_injectCmd(dspdata, ZDSP_CMD_SFXVOL_DECR); - break; - case 0xa9: - zGameStateSwitchEvent(toEvent); - break; - case 0x9e: - globals.currentActivePad = 0; - zGameStateSwitchEvent(0x9e); - break; - case 0xa7: - break; - case 0xa8: - zSaveLoad_DispatchCB(toEvent, toParam); - break; - - case 0xc2: - zEntPlayer_SNDPlay(ePlayerSnd_CheckPoint, _1179); - F32 fVar2; - if (*toParam != _1179) - { - fVar2 = _1180 * *toParam; - } - else - { - //fVar2 = globals.player.ent.frame->rot.angle; - } - zEntPlayer_StoreCheckPoint((xVec3*)toParamWidget, fVar2, globals.oldSkoolCamera.id); - break; - case 0x11e: - zhud::show(); - break; - case 0x11f: - zhud::hide(); - break; - case 0x120: - iColor_tag black = _1142; - iColor_tag clear = _1143; - xScrFxFade(&clear, &black, *toParam, 0, 1); - break; - case 0x126: - menu_fmv_played = 1; - //zFMVPlay(zFMVFileGetName((eFMVFile)(U32)*toParam), 0x10001, _1181, 1, 0); - break; - case 0x130: - zSceneEnableScreenAdj(1); - zSceneSetOldScreenAdj(); - break; - case 0x131: - zSceneEnableScreenAdj(0); - break; - case 0x101: - globals.player.g.PowerUp[(int)*toParam] = 1; - break; - - case 0x1fd: - xCameraFXShake(*toParam, toParam[1], toParam[2], toParam[3], _1179, NULL, NULL); - break; - case 0x210: - xCMstart((xCreditsData*)toParamWidget, *toParam, xb); - break; - - case 0x211: - xCMstop(); - break; - - case 0x217: - char events[512]; - U32 c; - U32 len; - U32 i; - char log[512]; - - for (i = 0; i < 512; i++) - { - events[i] = lbl_80254E10[i]; - } - - c = 0; - for (i = 0; i < 8; i += len) - { - c += 1; - len = strlen((char*)&ringlist[i]); - } - - strcpy(lbl_80254E10, zEventLogBuf[c + 1]); - for (i = c + 2; i < 0x13; i++) - { - strcat(log, zEventLogBuf[i]); - } - strncpy(events, log, 0x200); - break; - case 0x21b: - zDispatcherStoreOptions(); - break; - - case 0x21c: - zDispatcherRestoreOptions(); - break; - } - return 1; -} - -S32 ZDSP_doCommand(st_ZDISPATCH_DATA* dspdata, st_ZDISPATCH_CONTEXT* cmdCtxt) -{ - S32 iv; - en_DISPATCH_COMMAND cmd = cmdCtxt->cmd; - void* indata = cmdCtxt->indata; - void* result = cmdCtxt->result; - - if (init_zDispatcher == 0) - { - warned_zDispatcher = 0; - init_zDispatcher = 1; - } - if (warned_zDispatcher == 0) - { - warned_zDispatcher = 1; - } - - switch (cmd) - { - case ZDSP_CMD_CTRL_CFGGET: - *(S32*)result = 0; - break; - case ZDSP_CMD_CTRL_CFGSET: - if (result != NULL) - { - *(S32*)result = 0; - } - break; - case ZDSP_CMD_CTRL_VIBEGET: - *(S32*)result = zVarEntryCB_VibrationOn(NULL); - break; - case ZDSP_CMD_CTRL_VIBESET: - if (globals.option_vibration != *(S32*)indata) - { - globals.option_vibration = *(S32*)indata; - xPadRumbleEnable(globals.currentActivePad, globals.option_vibration); - zRumbleStart(globals.currentActivePad, SDR_Test); - } - break; - case ZDSP_CMD_SNDMOD_GET: - *(S32*)result = zVarEntryCB_SndMode(NULL); - break; - case ZDSP_CMD_SNDMOD_SET: - if (*(S32*)indata == 0) - { - iSndStereo(0); - } - else if (*(S32*)indata == 1) - { - iSndStereo(1); - } - - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndMode(NULL); - } - break; - case ZDSP_CMD_MUSVOL_GET: - *(S32*)result = zVarEntryCB_SndMusicVol(NULL); - break; - case ZDSP_CMD_MUSVOL_SET: - WRAP_xsnd_setMusicVolume(*(S32*)indata); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndMusicVol(NULL); - } - break; - case ZDSP_CMD_MUSVOL_INCR: - iv = zVarEntryCB_SndMusicVol(NULL); - if (indata != NULL) - { - iv += *(S32*)indata; - } - else - { - iv += 1; - } - WRAP_xsnd_setMusicVolume(iv); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndMusicVol(NULL); - } - break; - case ZDSP_CMD_MUSVOL_DECR: - iv = zVarEntryCB_SndMusicVol(NULL); - if (indata != NULL) - { - iv -= *(S32*)indata; - } - else - { - iv -= 1; - } - WRAP_xsnd_setMusicVolume(iv); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndMusicVol(NULL); - } - break; - case ZDSP_CMD_SFXVOL_GET: - *(S32*)result = zVarEntryCB_SndFXVol(NULL); - break; - case ZDSP_CMD_SFXVOL_SET: - WRAP_xsnd_setSFXVolume(*(S32*)indata); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndFXVol(NULL); - } - break; - case ZDSP_CMD_SFXVOL_INCR: - iv = zVarEntryCB_SndFXVol(NULL); - if (indata != NULL) - { - iv += *(S32*)indata; - } - else - { - iv += 1; - } - WRAP_xsnd_setSFXVolume(iv); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndFXVol(NULL); - } - break; - case ZDSP_CMD_SFXVOL_DECR: - iv = zVarEntryCB_SndFXVol(NULL); - if (indata != NULL) - { - iv -= *(S32*)indata; - } - else - { - iv -= 1; - } - WRAP_xsnd_setSFXVolume(iv); - if (result != NULL) - { - *(S32*)result = zVarEntryCB_SndFXVol(NULL); - } - break; - case ZDSP_CMD_GSTATE_GET: - *(S32*)result = zGameStateGet(); - break; - case ZDSP_CMD_GSTATE_SET: - zGameStateSwitch(*(S32*)indata); - if (result != NULL) - { - *(S32*)result = zGameStateGet(); - } - break; - case ZDSP_CMD_GMODE_GET: - *(S32*)result = zGameModeGet(); - break; - case ZDSP_CMD_GMODE_SET: - zGameModeSwitch(*(eGameMode*)indata); - if (result != NULL) - { - *(S32*)result = zGameModeGet(); - } - break; - case ZDSP_CMD_SNDVOL_GET: - case ZDSP_CMD_SNDVOL_SET: - case ZDSP_CMD_SNDVOL_INCR: - case ZDSP_CMD_SNDVOL_DECR: - case ZDSP_CHECKPNT_SET: - break; - } - return 1; -} - -void zDispatcher_Load(st_ZDISPATCH_DATA* dspdata, xSerial* s) -{ - xBaseLoad(dspdata, s); -} - -void zDispatcher_Save(st_ZDISPATCH_DATA* dspdata, xSerial* s) -{ - xBaseSave(dspdata, s); -} - -void zDispatcher_InitDep(st_ZDISPATCH_DATA* dspdata, zScene* zscn) -{ -} - -void zDispatcher_Init(st_ZDISPATCH_DATA* dspdata, xBaseAsset* bass) -{ - xBaseInit(dspdata, bass); - dspdata->rawass = bass; - //dspdata->eventFunc = ZDSP_elcb_event; - if (dspdata->linkCount != 0) - { - dspdata->link = (xLinkAsset*)(dspdata->rawass + 1); - } - else - { - dspdata->link = NULL; - } -} - -st_ZDISPATCH_DATA* zDispatcher_getInst(st_ZDISPATCH_DATA* pool, S32 idx) -{ - return &pool[idx]; -} - -st_ZDISPATCH_DATA* zDispatcher_memPool(S32 cnt) -{ - st_ZDISPATCH_DATA* pool; - st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; - if (cnt < 1) - { - return NULL; - } - else - { - pool = (st_ZDISPATCH_DATA*)xMemAlloc(gActiveHeap, cnt * sizeof(st_ZDISPATCH_DATA), 0); - memset(pool, 0, cnt * sizeof(st_ZDISPATCH_DATA)); - depot->raw_pool = pool; - depot->raw_cnt = cnt; - return pool; - } -} - -void zDispatcher_sceneFinish() -{ - st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; - - g_zdsp_init--; - if (g_zdsp_init == 0) - { - memset(depot, 0, sizeof(st_ZDISPATCH_DEPOT)); - } -} - -void zDispatcher_scenePrepare() -{ - st_ZDISPATCH_DEPOT* depot = &g_zdsp_depot; - if (g_zdsp_init++ == 0) - { - memset(depot, 0, sizeof(st_ZDISPATCH_DEPOT)); - } -} - -void zDispatcher_Shutdown() -{ -} - -void zDispatcher_Startup() -{ -} - -void zDispatcherParseINI(xIniFile* ini) -{ - S32 i; - char itemName[16]; - char value[256]; - char* value_; - S32 j; - char* ltok; - char* tok; -} - -// z_disco_floor - -// REQUIRES A LOT OF STUFF TO BE PORTED -// TOO LAZY TO DO IT RN - -// zDestructible - -// zCutsceneMgr - -static S32 gCutsceneSkipOK; -static S32 donpcfx; -static U8 ents_hidden; -static S32 s_atomicNumber; - -void zCutsceneMgrUpdate(xBase* to, xScene* sc, F32 dt) -{ - zCutsceneMgr* t = (zCutsceneMgr*)to; - if (t->csn->ShutDownWait) - { - if (donpcfx) - { - zNPCFXCutsceneDone(sc, dt, t); - } - donpcfx = 0; - if (xCutscene_Destroy(t->csn)) - { - zCutsceneMgrKillFX(t); - t->csn = NULL; - globals.cmgr = NULL; - xCameraSetFOV(&globals.oldSkoolCamera, t->oldfov); - } - } - else - { - if (t->csn->Ready) - { - if (!donpcfx) - { - donpcfx = zNPCFXCutscenePrep(sc, dt, t); - } - if (donpcfx) - { - zNPCFXCutscene(sc, dt, t); - } - - zCutsceneMgrUpdateFX(t); - if (t->stop || !xCutscene_Update(t->csn, dt)) - { - if (!t->stop) - { - zEntEvent(to, to, 0x13); - } - - t->csn->PlaybackSpeed = 0.0f; - //zEntEvent(&globals.player.ent, 9); - //zEntEvent(&globals.player.ent, 3); - zEntEvent(to, to, 0xbf); - iCameraSetNearFarClip(0.0f, 0.0f); - - if ((globals.sceneCur->pendingPortal)) - { - //zEntEvent(&globals.player.ent, 8); - //zEntEvent(&globals.player.ent, 4); - xSndStopAll(0xffff); - return; - } - - if (donpcfx) - { - zNPCFXCutsceneDone(sc, dt, t); - } - donpcfx = 0; - - if (xCutscene_Destroy(t->csn)) - { - zCutsceneMgrKillFX(t); - t->csn = NULL; - globals.cmgr = NULL; - xCameraSetFOV(&globals.oldSkoolCamera, t->oldfov); - } - - zMusicUnpause(0); - } - else - { - if (gCutsceneSkipOK && t->csn->Time > gSkipTimeCutscene && - globals.pad0->pressed & 0x50000) - { - zEntEvent(to, to, 0x13); - } - } - } - else - { - iCSLoadStep(t->csn); - if (t->csn->Ready) - { - zCutsceneMgrPlayStart(t); - zEntEvent(to, to, 0x18); - //zEntEvent(&globals.player.ent, 8); - //zEntEvent(&globals.player.ent, 4); - donpcfx = zNPCFXCutscenePrep(sc, dt, t); - } - } - } - check_hide_entities(); -} - -void zCutsceneMgrFinishExit(xBase* to) -{ - zCutsceneMgr* t = (zCutsceneMgr*)to; - - while (1) - { - iFileAsyncService(); - xSndUpdate(); - if (t->csn->Waiting == 0) - break; - iVSync(); - } - if (donpcfx != 0) - { - zNPCFXCutsceneDone(globals.sceneCur, 0.0f, t); - } - donpcfx = 0; - if (xCutscene_Destroy(t->csn) == 0) - { - return; - } - - //zEntEvent(&globals.player.ent, 9); - //zEntEvent(&globals.player.ent, 3); - zCutsceneMgrKillFX(t); - t->csn = NULL; - globals.cmgr = NULL; -} - -void zCutsceneMgrFinishLoad(xBase* to) -{ - zCutsceneMgr* t = (zCutsceneMgr*)to; - - while (true) - { - iFileAsyncService(); - xSndUpdate(); - iCSLoadStep(t->csn); - iTRCDisk::CheckDVDAndResetState(); - if (t->csn->Ready) - { - break; - } - iVSync(); - } - zCutsceneMgrPlayStart(t); - zEntEvent(to, to, 0x18); - //zEntEvent(&globals.player.ent, 8); - //zEntEvent(&globals.player.ent, 4); - return; -} - -void zCutsceneMgrLoad(zCutsceneMgr*, xSerial* s) -{ -} - -void zCutsceneMgrSave(zCutsceneMgr*, xSerial* s) -{ -} - -// zConfig - -U8 zConfig_isPlayerPatrick(ePlayerEnum playerEnum) -{ - U8 isPatrick = 0; - if ((playerEnum >= 10) && (playerEnum <= 0x15)) - { - isPatrick = 1; - } - return isPatrick; -} - -U8 zConfig_isPlayerSpongebob(ePlayerEnum playerEnum) -{ - U8 isSpongebob = 0; - if ((playerEnum >= 0) && (playerEnum <= 10)) - { - isSpongebob = 1; - } - return isSpongebob; -} - -// zConditional - -S32 zConditionalEventCB(xBase*, xBase*, U32, const F32*, xBase*); - -void zConditionalLoad(_zConditional* ent, xSerial* s) -{ - xBaseLoad(ent, s); -} - -void zConditionalSave(_zConditional* ent, xSerial* s) -{ - xBaseSave(ent, s); -} - -void zConditionalInit(void* b, void* asset) -{ - _zConditional* cond = (_zConditional*)b; - - xBaseInit((xBase*)cond, (xBaseAsset*)asset); - //cond->eventFunc = (xBaseEventCB)zConditionalEventCB; - //cond->asset = asset; - - if (cond->linkCount != 0) - { - cond->link = (xLinkAsset*)(cond->asset + 1); - } - else - { - cond->link = NULL; - } - zVarInit(zVarEntryTable); -} - -// zCollGeom - -static volatile U32 sNumTables; -static U32 sTableCount[3]; -static zCollGeomTable* sTableList[3]; - -void zCollGeom_CamDisable(xEnt* ent) -{ - ent->camcollModel = NULL; -} - -void zCollGeom_CamEnable(xEnt* ent) -{ - if (!ent->camcollModel) - { - ent->camcollModel = ent->model; - } -} - -void zCollGeom_Init() -{ - sNumTables = xSTAssetCountByType('COLL'); - - if (sNumTables) - { - U32 tmpsize, i, k; - void* data; - - for (k = 0; k < sNumTables; k++) - { - data = xSTFindAssetByType('COLL', k, &tmpsize); - - if (!data) - { - break; - } - - sTableCount[k] = *(U32*)data; - - if (!sTableCount[k]) - { - sTableList[k] = NULL; - break; - } - - sTableList[k] = (zCollGeomTable*)((U32*)data + 1); - - for (i = 0; i < sTableCount[k]; i++) - { - if ((U32)sTableList[k][i].baseModel) - { - sTableList[k][i].baseModel = - (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].baseModel, NULL); - } - - if ((U32)sTableList[k][i].colModel[0]) - { - sTableList[k][i].colModel[0] = - (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].colModel[0], NULL); - } - - if (!sTableList[k][i].colModel[0]) - { - if (sTableList[k][i].camcolModel) - { - sTableList[k][i].camcolModel = - (RpAtomic*)xSTFindAsset((U32)sTableList[k][i].camcolModel, NULL); - } - } - } - } - } -} - -// PORTED FROM BATTLE, GOOD REFERENCE -U32 zCollGeom_EntSetup(xEnt* ent) -{ - U32 i, j; - S32 auto_cam_coll; - - auto_cam_coll = (ent->baseType == eBaseTypeStatic); - - ent->collModel = NULL; - ent->camcollModel = NULL; - - if (ent->model) - { - for (j = 0; j < sNumTables; j++) - { - for (i = 0; i < sTableCount[j]; i++) - { - if (sTableList[j][i].baseModel == ent->model->Data) - { - RpAtomic* imodel; - - if (imodel = sTableList[j][i].colModel[0]) - { - xModelInstance* model = xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL); - - ent->collModel = model; - ent->collModel->Mat = ent->model->Mat; - - while (imodel = iModelFile_RWMultiAtomic(imodel)) - { - xModelInstanceAttach(xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL), - model); - } - } - else if (imodel = sTableList[j][i].camcolModel) - { - xModelInstance* model = xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL); - - ent->camcollModel = model; - ent->camcollModel->Mat = ent->model->Mat; - - while (imodel = iModelFile_RWMultiAtomic(imodel)) - { - xModelInstanceAttach(xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL), - model); - } - } - else - { - auto_cam_coll = 0; - } - } - } - } - } - - if (auto_cam_coll && !ent->camcollModel) - { - ent->camcollModel = ent->model; - } - - if (ent->collModel) - { - return 1; - } - - ent->collModel = ent->model; - return 0; -} - -// zCar - -// Refrain from doing these functions until the zCar struct is fixed. - -#define Car 1 -#define Idle01 2 -#define Drive 3 -#define DriveSlippy 4 -#define Boosting 5 -#define Reversing 6 -#define Crash 7 -#define SpinLeft 8 -#define SpinRight 9 -#define Success 10 -#define Failed 11 -#define Death 12 -#define Jump 13 -#define JumpLandSquash 14 - -#define ANIM_COUNT 78 -extern U32 g_hash_caranim[ANIM_COUNT]; -const char* g_strz_caranim[ANIM_COUNT]; - -// Needs the functions calls updated -// NewState and DefaultBeforeEnter do not have correct amount of params yet - -xAnimTable* CreateAnimTable() -{ - S32 ourAnims[32] = { - // clang-format off - Car, - Idle01, - Drive, - DriveSlippy, - Boosting, - Reversing, - Crash, - SpinLeft, - SpinRight, - Success, - Failed, - Death, - Jump, - JumpLandSquash, - - // clang-format on - }; - - xAnimTable* table = xAnimTableNew("stop0", 0); - - xAnimTableNewState(table, "Car", 0x10, 0, 1.0f, NULL, NULL, 0.0f, NULL, NULL, - xAnimDefaultBeforeEnter, NULL, NULL); -} - -U32 zCar::JumpEndedCB(xAnimTransition* unk0, xAnimSingle* anim, void* unk3) -{ - zCar* pCar = zEntPlayerCarGetCar(); -} - -U32 zCar::AnimDefaultCB(xAnimTransition* unk0, xAnimSingle* anim, void*) -{ - zCar* pCar = zEntPlayerCarGetCar(); -} +#include "zEnv.cpp" +#include "zEGenerator.cpp" +#include "zDispatcher.cpp" +#include "zDiscoFloor.cpp" +#include "zDestructible.cpp" +#include "zCutsceneMgr.cpp" +#include "zConfig.cpp" +#include "zConditional.cpp" +#include "zCollGeom.cpp" +#include "zCar.cpp" +#include "zCamSB.cpp" +#include "zCamMarker.cpp" +#include "zCameraTweak.cpp" +#include "zCameraFly.cpp" +#include "zCamera.cpp" +#include "zCamDrive.cpp" +#include "zCamCar.cpp" +#include "zCam.cpp" +#include "zBusStop.cpp" +#include "zAsync.cpp" +#include "zAssetTypes.cpp" +#include "zAnimList.cpp" +#include "zActionLine.cpp" diff --git a/src/SB/Game/zWad1.h b/src/SB/Game/zWad1.h index 0bd719c..28e5bde 100644 --- a/src/SB/Game/zWad1.h +++ b/src/SB/Game/zWad1.h @@ -5,35 +5,4 @@ #include #include -#include "zEnv.h" -#include "zSurface.h" -#include "xGroup.h" -#include "xstransvc.h" -#include "iLight.h" -#include "zLight.h" -#include "zEGenerator.h" -#include "zDispatcher.h" -#include "xIni.h" -#include "zGameState.h" -#include "zVar.h" -#include "zRumble.h" -#include "zHud.h" -#include "zSaveLoad.h" -#include "xScrFx.h" -#include "zFMV.h" -#include "zMusic.h" -#include "xCM.h" -#include "zDiscoFloor.h" -#include "zCutsceneMgr.h" -#include "xCutsceneMgr.h" -#include "zNPCFXCinematic.h" -#include "iCutscene.h" -#include "iSystem.h" -#include "iTRC.h" -#include "zConfig.h" -#include "xserializer.h" -#include "zConditional.h" -#include "zCar.h" -#include "xString.h" - #endif diff --git a/src/SB/Game/zWad2.cpp b/src/SB/Game/zWad2.cpp index 5cceea2..4397a4f 100644 --- a/src/SB/Game/zWad2.cpp +++ b/src/SB/Game/zWad2.cpp @@ -410,663 +410,16 @@ void (*cb_dispatch)(xBase*, xBase*, U32, F32*, xBase*, U32); // -// zNPCMgr - -struct NPCMTypeTable // ported from bfbb -{ - en_npctyp useNPCType; - char* modelName; - unsigned int hashOfName; -} g_tbltype[250]; - -S32 zNPCMgr_OrdComp_npcid(void* vkey, void* vitem) -{ - S32 rc; - U32 item; - U32 key; - - key = *(U32*)vkey; - item = *(U32*)vitem; - if (key < item) - { - rc = -1; - } - else if (key > item) - { - rc = 1; - } - else - { - rc = 0; - } - - return rc; -} - -// S32 zNPCMgr_OrdTest_npcid(void* vkey, void* vitem) -// { -// S32 rc; -// void* key = *(void**)(vitem); - -// if (vkey < key) -// { -// rc = -1; -// } -// else if (vkey > key) -// { -// rc = 1; -// } -// else -// { -// rc = 0; -// } - -// return rc; -// } - -void zNPCMgr::Shutdown() -{ - if (this->npcFactory != NULL) - { - delete this->npcFactory; - } - this->npcFactory = NULL; -} - -void zNPCMgr_scenePostInit() -{ -} - -void zNPCMgr_sceneReset() -{ -} - -void zNPCMgr_sceneFinish() -{ -} - -void zNPCMgr_scenePrepare(S32 npccnt) // npccnt may not be right. code was ported -{ -} - -void zNPCMgr_Shutdown() -{ - g_modinit--; - if (g_modinit == 0) - { - zNPCMgr* mgr = zNPCMgrSelf(); - if (mgr != NULL) - { - mgr->Shutdown(); - delete mgr; - g_npcmgr = NULL; - } - zNPCMgr_Shutdown(); - xBehaveMgr_Shutdown(); - } -} - -void zNPCMgr_Startup() -{ - if (g_modinit++ == 0) - { - xBehaveMgr_Startup(); - zNPCMgr* npc = new ('NPCM', NULL) zNPCMgr(); - g_npcmgr = npc; - npc->Startup(); - } -} - -zNPCMgr* zNPCMgr_GetNPCList() -{ - return g_npcmgr; -} - -zNPCMgr* zNPCMgrSelf() -{ - return g_npcmgr; -} - -// zMenu - -void zMenuAllowAtract(bool allowAttract) -{ - sAllowAttract = allowAttract; -} - -void zMenuPause(bool bPause) -{ - S64 time; - U32 Utime; - - if (bPause == FALSE) - { - Utime = iTimeGet(); - time = iTimeDiffSec((U64)Utime >> 0x20); - time_last = time - SECS_PER_VBLANK; - Utime = iTimeGet(); - } - - sTimeLast = Utime >> 0x20; -} - -S32 zMenuIsFirstBoot() -{ - return sFirstBoot; -} - -U32 zMenuGetBadCard() -{ - return card + 1; -} - -void zMenuExit() -{ -} - -S32 zMenuRunning() -{ - return sInMenu; -} - -// zLOD - -zLODTable* zLOD_Get(xEnt* ent) -{ - if (!ent->model) - { - return 0; - } - - for (int i = 0; i < sLODTableCount; i++) - { - if (sLODTableList[i].baseBucket != NULL) - { - if ((*sLODTableList[i].baseBucket)->OriginalData == ent->model->Data) - { - return &sLODTableList[i]; - } - } - } - return 0; -} - -// z::lightweight_manager - -// These are in the dwarf, but you have to find them with just "lightweight_manager" - -// void z::lightweight_manager::setup() -// { -// } - -// zLightning - -void _zLightningKill(zLightning* l) -{ -} - -void zLightningKill(zLightning* l) -{ -} - -// zLightEffect - -void zLightEffectInitCauldron(_zLight* zlight) -{ - *zlight->reg = 0.0f; - zlight->flags = zlight->flags | 1; -} - -void zLightEffectRandomColFast(_zLight* zlight, F32) -{ -} - -void zLightEffectRandomCol(_zLight* zlight, F32) -{ -} - -void zLightEffectRandomColSlow(_zLight* zlight, F32) -{ -} - -void zLightEffectHalfDimFast(_zLight* zlight, F32) -{ -} - -void zLightEffectHalfDim(_zLight* zlight, F32) -{ -} - -void zLightEffectHalfDimSlow(_zLight* zlight, F32) -{ -} - -void zLightEffectDimFast(_zLight* zlight, F32) -{ -} - -void zLightEffectDim(_zLight* zlight, F32) -{ -} - -void zLightEffectDimSlow(_zLight* zlight, F32) -{ -} - -void zLightEffectStrobeFast(_zLight* zlight, F32) -{ -} - -void zLightEffectStrobe(_zLight* zlight, F32) -{ -} - -void zLightEffectStrobeSlow(_zLight* zlight, F32) -{ -} - -void zLightEffectInitFlicker(_zLight* zlight) -{ - *zlight->reg = 0.0f; - zlight->flags = zlight->flags | 1; -} - -void zLightEffectInitRandomCol(_zLight*) -{ -} - -void zLightEffectInitHalfDim(_zLight*) -{ -} - -void zLightEffectInitDim(_zLight*) -{ -} - -void zLightEffectInitStrobe(_zLight*) -{ -} - -// zLight - -void zLightSetVolume(zVolume* vol) -{ - if (!vol) - { - sPartitionVolume = 0; - } - else - { - U32 lp_id = xStrHash("LIGHT_PARTITION" + 9); - if (vol->id == lp_id) - { - sPartitionVolume = vol; - } - } -} - -void zLightRemoveLocalEnv() -{ - int i; - const RwLLLink* link; - - for (i = 0; i < gNumTemporaryLights; i++) - { - link = gLightWorld->directionalLightList.link.prev; - link->prev->next = link->next; - link->next->prev = link->prev; - } - gNumTemporaryLights = 0; -} - -void zLightAddLocal(xEnt* ent) -{ -} - -void zLightLoad(_zLight* ent, xSerial* s) -{ - xBaseLoad(ent, s); -} - -void zLightSave(_zLight* ent, xSerial* s) -{ - xBaseSave(ent, s); -} - -void zLightDestroyAll() -{ - S32 total = sLightTotal; - - for (int i = 0; i < total; i++, sLightTotal--) - { - zLightDestroy(sLight[i]); - } - sLightTotal = 0; -} - -void zLightResolveLinks() -{ - S32 i; - _zLight* zl; - - for (i = 0; i < sLightTotal; i++) - { - zl = sLight[i]; - if (zl->tasset->attachID) - { - zl->attached_to = zSceneFindObject(zl->tasset->attachID); - } - else - { - zl->attached_to = 0; - } - } -} - -void zLightInit(void* b, void* tasset) -{ - zLightInit((xBase*)b, (zLightAsset*)tasset); -} - +#include "zNPCMgr.cpp" +#include "zMenu.cpp" +#include "zLOD.cpp" +#include "zLightWeight.cpp" +#include "zLightning.cpp" +#include "zLightEffect.cpp" +#include "zLight.cpp" // zPat / zLasso - -// zGrid - -void zGridExit(zScene* s) -{ - xGridKill(&colls_grid); - xGridKill(&colls_oso_grid); - xGridKill(&npcs_grid); - xGridKill(&grabbable_grid); - zGridInitted = 0; -} - -// zGoo - -void zGooExit() -{ - zgoo_gps = 0; - zgoo_ngps = 0; - zgoo_nused = 0; -} - -void zGooInit(S32 nobj) -{ - zgoo_gps = (zGooParams*)xMemAlloc(gActiveHeap, nobj * 0xc, 0); - zgoo_ngps = nobj; -} - -// zGameState - -//xSndMgrPauseSounds - -void zGameStatePauseUnpauseSnd(bool pause) -{ - xSndMgrPauseSounds(0, pause, TRUE); - xSndMgrPauseSounds(1, pause, TRUE); - xSndMgrPauseSounds(2, pause, FALSE); -} - -void SB04FMVPauseSoundCB(bool doPause) -{ - bool tempBool; - - if (gGameMode == 8) - { - tempBool = TRUE; - } - else if (gGameMode == 7) - { - tempBool = TRUE; - } - else if (gGameMode == 6) - { - tempBool = TRUE; - } - else if (gGameMode == 2) - { - tempBool = TRUE; - } - else if (gGameMode == 4) - { - tempBool = TRUE; - } - else if (gGameMode == 6) - { - tempBool = TRUE; - } - else if (gGameMode == 1) - { - tempBool = TRUE; - } - else if (gGameMode == 0) - { - tempBool = TRUE; - } - else - { - tempBool = FALSE; - } - - if (tempBool) - { - xSndMgrPauseSounds(3, doPause, TRUE); - } - else if (doPause != 0) - { - xSndMgrPauseSounds(-3, TRUE, TRUE); - } - else - { - xSndMgrPauseSounds(-3, FALSE, TRUE); - } -} - -void zGameSetOstrich(_GameOstrich o) -{ - gGameOstrich = o; -} - -_GameOstrich zGameGetOstrich() -{ - return gGameOstrich; -} - -eGameMode zGameModeGet() -{ - return gGameMode; -} - -S32 zGameStateGet() -{ - return gGameState; -} - -// zGameExtras / EGG - -void zGameExtras_Load(xSerial* xser) -{ - S32 keepers[2]; - keepers[0] = 0; - xser->Read(keepers); - g_flg_chEnabled |= keepers[0]; -} - -void zGameExtras_Save(xSerial* xser) -{ - xser->Write(g_flg_chEnabled & 0xFFFF); -} - -S32 zGameExtras_CheatFlags() -{ - return g_flg_chEnabled; -} - -S32 EGG_check_ExtrasFlags(EGGItem*) -{ - switch (g_currMonth) - { - case JANUARY: - if (g_currDay == 1) // New Year's Day - g_gameExtraFlags |= 0b000000001; - break; - - case FEBRUARY: - if (g_currDay == 2) - g_gameExtraFlags |= 0b100000000; - break; - - case MARCH: - if (g_currDay == 15) - g_gameExtraFlags |= 0b000001000; - if (g_currDay == 17) // St. Patrick's Day - g_gameExtraFlags |= 0b000000100; - if (g_currDay == 18) - g_gameExtraFlags |= 0b100000000; - if (g_currDay == 21) - g_gameExtraFlags |= 0b100000000; - if (g_currDay == 22) - g_gameExtraFlags |= 0b100000000; - break; - - case APRIL: - if (g_currDay == 1) // April Fools' Day - g_gameExtraFlags |= 0b010000000; - break; - - case MAY: - break; - - case JUNE: - if (g_currDay == 6) - g_gameExtraFlags |= 0b001000000; - break; - - case JULY: - if (g_currDay == 4) // Independence Day - g_gameExtraFlags |= 0b000000010; - break; - - case AUGUST: - if (g_currDay == 8) - g_gameExtraFlags |= 0b100000000; - break; - - case SEPTEMBER: - if (g_currDay == 8) - g_gameExtraFlags |= 0b000000010; - break; - - case OCTOBER: - if (g_currDay == 5) - g_gameExtraFlags |= 0b100000000; - if (g_currDay == 14) - g_gameExtraFlags |= 0b100000000; - if (g_currDay == 22) - g_gameExtraFlags |= 0b100000000; - if (g_currDay == 31) // Halloween - g_gameExtraFlags |= 0b000100000; - break; - - case NOVEMBER: - if (g_currDay == 5) - g_gameExtraFlags |= 0b100000000; - break; - - case DECEMBER: - break; - } - - return 0; -} - -void zGameExtras_SceneReset() -{ - if (!g_enableGameExtras) - { - return; - } - - EGGItem* egg_next = g_eggBasket; - - while (egg_next->fun_check) - { - EGGItem* egg = egg_next++; - - if (egg->enabled) - { - if (egg->funcs->fun_reset) - { - egg->funcs->fun_reset(egg); - } - } - } -} - -void zGameExtras_MoDay(S32* month, S32* day) -{ - *month = g_currMonth; - *day = g_currDay; -} - -S32 zGameExtras_ExtrasFlags() -{ - return g_gameExtraFlags; -} - -// zGame - -void DoTheResetinator() -{ -} - -void zGameStall() -{ - bool tempGameBool; - if (gGameMode == 8) - { - tempGameBool = TRUE; - } - else if (gGameMode == 7) - { - tempGameBool = TRUE; - } - else if (gGameMode == 6) - { - tempGameBool = TRUE; - } - else if (gGameMode == 2) - { - tempGameBool = TRUE; - } - else if (gGameMode == 4) - { - tempGameBool = TRUE; - } - else if (gGameMode == 6) - { - tempGameBool = TRUE; - } - else if (gGameMode == 1) - { - tempGameBool = TRUE; - } - else if (gGameMode == 0) - { - tempGameBool = TRUE; - } - else - { - tempGameBool = FALSE; - } - - if (!tempGameBool) // chain of if elses - { - zGameModeSwitch(eGameMode_Stall); - xSndMgrPauseSounds(0, TRUE, TRUE); - xSndMgrPauseSounds(1, TRUE, TRUE); - xSndMgrPauseSounds(2, TRUE, FALSE); - iPadStopRumble(globals.pad[1]); - zEntEvent("techbutton6_click", 24); - } -} +#include "zGrid.cpp" +#include "zGoo.cpp" +#include "zGameState.cpp" +#include "zGameExtras.cpp" +#include "zGame.cpp" diff --git a/src/SB/Game/zWad2.h b/src/SB/Game/zWad2.h index fabedf6..dd2f7fc 100644 --- a/src/SB/Game/zWad2.h +++ b/src/SB/Game/zWad2.h @@ -4,21 +4,10 @@ #include #include "xPartition.h" - #include "zNPCMgr.h" #include "zNMECommon.h" -#include "xordarray.h" -#include "zNPCSpawner.h" -#include "zNPCMessenger.h" -#include "iTime.h" -#include "xFX.h" -#include "zFX.h" -#include "zTextBox.h" -#include "iSnd.h" #include "zGame.h" -#include "zGameState.h" #include "zGameExtras.h" -#include "zGoo.h" #include "zLight.h" #include "zLightning.h" #include "xDebug.h" @@ -26,15 +15,7 @@ #include "xCounter.h" #include "zFMV.h" #include "zUI.h" -#include "zUIFont.h" -#include "xSnd.h" #include "zMusic.h" -#include "zGlobals.h" -#include "xMath3.h" -#include "xTRC.h" -#include "zGrid.h" -#include "xGrid.h" -#include "xShadow.h" #include "xWad5.h" diff --git a/src/SB/Game/zWad3.cpp b/src/SB/Game/zWad3.cpp index ddd0985..b7514f7 100644 --- a/src/SB/Game/zWad3.cpp +++ b/src/SB/Game/zWad3.cpp @@ -1,1677 +1,10 @@ #include "zWad3.h" -// zVolume - -struct PreCalcOcclude -{ - xVec4 DepthVec; - xVec4 FrustVec[4]; -}; - -extern zVolume* vols; -extern U16 nvols; - -extern S32 gOccludeCount; -extern zVolume* gOccludeList[10]; -extern S32 gOccludeCalcCount; -extern PreCalcOcclude gOccludeCalc[10]; - -extern float lbl_803CDFB8; - -S32 zVolumeEventCB(xBase*, xBase* to, U32 toEvent, const F32*, xBase*, U32) -{ - zVolume* vol = (zVolume*)to; - S32 i; - - switch (toEvent) - { - case eEventReset: - { - vol->Reset(); - break; - } - case eEventOccludeOn: - { - if (gOccludeCount == 10) - { - return 1; - } - - for (i = 0; i < gOccludeCount; i++) - { - if (gOccludeList[i] == vol) - { - return 1; - } - } - - gOccludeList[gOccludeCount] = vol; - gOccludeCount++; - - break; - } - case eEventOccludeOff: - { - for (i = 0; i < gOccludeCount; i++) - { - if (gOccludeList[i] == vol) - { - gOccludeList[gOccludeCount] = gOccludeList[gOccludeCount - 1]; - gOccludeCount--; - - return 1; - } - } - - break; - } - } - - return 1; -} - -void zVolume_OccludePrecalc(xVec3* camPos) -{ - S32 i; - S32 j; - xVec3 corner[5]; - zVolume* vol; - xVolumeAsset* a; - F32 c; - F32 s; - PreCalcOcclude* calc; - xVec3 d1; - xVec3 d2; - xVec4 locFrustVec[4]; - F32 depthdot; - F32 camdot; - F32 testdot1; - F32 testdot2; - - gOccludeCalcCount = 0; - - for (i = 0; i < gOccludeCount; i++) - { - vol = gOccludeList[i]; - a = vol->asset; - - c = icos(a->rot); - s = isin(a->rot); - - calc = &gOccludeCalc[gOccludeCalcCount]; - - corner[0].x = c * (a->bound.box.box.lower.x - a->xpivot) + a->xpivot; - corner[0].y = a->bound.box.box.lower.y; - corner[0].z = s * (a->bound.box.box.lower.x - a->xpivot) + a->bound.box.box.lower.z; - - corner[1].y = a->bound.box.box.lower.y; - corner[1].x = c * (a->bound.box.box.upper.x - a->xpivot) + a->xpivot; - corner[1].z = s * (a->bound.box.box.upper.x - a->xpivot) + a->bound.box.box.lower.z; - - corner[2].x = c * (a->bound.box.box.upper.x - a->xpivot) + a->xpivot; - corner[2].y = a->bound.box.box.upper.y; - corner[2].z = s * (a->bound.box.box.upper.x - a->xpivot) + a->bound.box.box.lower.z; - - corner[3].x = c * (a->bound.box.box.lower.x - a->xpivot) + a->xpivot; - corner[3].y = a->bound.box.box.upper.y; - corner[3].z = s * (a->bound.box.box.lower.x - a->xpivot) + a->bound.box.box.lower.z; - - corner[4] = corner[0]; - - xVec3Sub(&d1, &corner[1], &corner[0]); - xVec3Sub(&d2, &corner[2], &corner[0]); - - xVec3Cross((xVec3*)calc, &d1, &d2); - xVec3Normalize((xVec3*)calc, (xVec3*)calc); - - depthdot = xVec3Dot((xVec3*)calc, &corner[0]); - camdot = xVec3Dot((xVec3*)calc, camPos); - - if (camdot > depthdot) - { - xVec3Inv((xVec3*)calc, (xVec3*)calc); - - camdot = -camdot; - depthdot = -depthdot; - } - - if (iabs(camdot - depthdot) >= lbl_803CDFB8) - { - calc->DepthVec.w = depthdot; - - for (j = 0; j < 4; j++) - { - xVec3Sub(&d1, &corner[j], camPos); - xVec3Sub(&d2, &corner[j + 1], camPos); - xVec3Cross((xVec3*)&locFrustVec[j], &d1, &d2); - xVec3Normalize((xVec3*)&locFrustVec[j], (xVec3*)&locFrustVec[j]); - } - - testdot1 = xVec3Dot((xVec3*)&locFrustVec[0], &corner[0]); - testdot2 = xVec3Dot((xVec3*)&locFrustVec[0], &corner[2]); - - if (testdot1 > testdot2) - { - for (j = 0; j < 4; j++) - { - xVec3Inv((xVec3*)&locFrustVec[j], (xVec3*)&locFrustVec[j]); - } - } - - for (j = 0; j < 4; j++) - { - locFrustVec[j].w = xVec3Dot((xVec3*)&locFrustVec[j], &corner[j]); - } - - calc->FrustVec[0].x = locFrustVec[0].w; - calc->FrustVec[0].y = locFrustVec[1].w; - calc->FrustVec[0].z = locFrustVec[2].w; - calc->FrustVec[0].w = locFrustVec[3].w; - - calc->FrustVec[1].x = locFrustVec[0].x; - calc->FrustVec[1].y = locFrustVec[1].x; - calc->FrustVec[1].z = locFrustVec[2].x; - calc->FrustVec[1].w = locFrustVec[3].x; - - calc->FrustVec[2].x = locFrustVec[0].y; - calc->FrustVec[2].y = locFrustVec[1].y; - calc->FrustVec[2].z = locFrustVec[2].y; - calc->FrustVec[2].w = locFrustVec[3].y; - - calc->FrustVec[3].x = locFrustVec[0].z; - calc->FrustVec[3].y = locFrustVec[1].z; - calc->FrustVec[3].z = locFrustVec[2].z; - calc->FrustVec[3].w = locFrustVec[3].z; - - gOccludeCalcCount++; - } - } -} - -// zVent - -// zVar - -char* var_text(const substr& str); -U32 zVarEntryCB_SndFXVol(void*); -U32 zVarEntryCB_SndMusicVol(void*); - -extern const char zVar_strings[]; - -S32 zVarEntryCB_IsVisible(void* arg) -{ - return 0; -} - -S32 zVarEntryCB_IsEnabled(void* arg) -{ - return 0; -} - -S32 zVarEntryCB_CounterValue(void* arg) -{ - // Given the void argument type, no idea what type this actually is. - // What we do know that at an offset 5 words in there's a signed S16. - struct something - { - U32 stuff[5]; - S16 theValue; - }; - return ((something*)arg)->theValue; -} - -S32 zVarEntryCB_Minute(void*) -{ - return iGetMinute(); -} - -S32 zVarEntryCB_Hour(void*) -{ - return iGetHour(); -} - -S32 zVarEntryCB_Date(void*) -{ - return iGetDay() + iGetMonth() * 0x64; -} - -S32 zVarEntryCB_CurrentRoom(void*) -{ - char buffer[16]; - sprintf(buffer, &zVar_strings[0xbaa] /*"%s"*/, - xUtil_idtag2string(globals.sceneCur->sceneID, 0)); - - S32 room = (buffer[2] - '0') * 10 + (buffer[3] - '0'); - - // Convert the most significant char to uppercase - // The lowercase variable doesn't exist in the ps4 symbols but I can't - // figure out how to get a match otherwise. - U32 mostSignificantChar = buffer[0]; - bool lowercase = false; - if (mostSignificantChar >= 'a' && mostSignificantChar <= 'z') - { - lowercase = true; - } - if (lowercase) - { - mostSignificantChar -= 0x20; - } - - return room + ((mostSignificantChar - 'A') + 1) * 100; -} - -S32 zVarEntryCB_CurrentSceneLetter(void*) -{ - char buffer[16]; - sprintf(buffer, &zVar_strings[0x10] /*"%s"*/, xUtil_idtag2string(globals.sceneCur->sceneID, 0)); - - // Convert the most significant char to uppercase - // The lowercase variable doesn't exist in the ps4 symbols but I can't - // figure out how to get a match otherwise. - U32 mostSignificantChar = buffer[0]; - bool lowercase = false; - if (mostSignificantChar >= 'a' && mostSignificantChar <= 'z') - { - lowercase = true; - } - if (lowercase) - { - mostSignificantChar -= 0x20; - } - - return (mostSignificantChar - 'A') + 1; -} - -U32 zVarEntryCB_VibrationOn(void* arg) -{ - // I'm pretty sure they actually and'd with a bit mask here, I couldn't find - // another way (such as casting to bool) to get the right instructions. - return globals.option_vibration & 0x1; -} - -U32 zVarEntryCB_MCAvailable(void* arg) -{ - if (xSGGameIsEmpty(NULL, 0) == 1) - { - if (xSGGameIsEmpty(NULL, 1) == 1) - { - return 0; - } - if (xSGGameIsEmpty(NULL, 1) == 0) - { - return 2; - } - } - else if (xSGGameIsEmpty(NULL, 0) == 0) - { - if (xSGGameIsEmpty(NULL, 1) == 1) - { - return 1; - } - if (xSGGameIsEmpty(NULL, 1) == 0) - { - return 3; - } - } - - return 0; -} - -U32 zVarEntryCB_SndFXVol(void* arg) -{ - F64 f0 = 10.0; - F64 f1 = 0.5; - F64 f2 = gSnd.categoryVolFader[0]; - - f2 *= f1; - f2 = f0 + f2; - - return f2; -} - -U32 zVarEntryCB_SndMusicVol(void* arg) -{ - F64 f0 = 10.0; - F64 f1 = 0.5; - F64 f2 = gSnd.categoryVolFader[2]; - - f2 *= f1; - f2 = f0 + f2; - - return f2; -} - -U32 zVarEntryCB_SndMode(void* arg) -{ - return gSnd.stereo; -} - -void zVarNewGame() -{ -} - -// zSurface - -extern volatile S32 sMapperCount; -extern zMaterialMapAsset* sMapper[1]; - -extern xSurface sDef_surf; - -extern F32 lbl_803CDEE8; // 0.34906587 // @798 -extern F32 lbl_803CDEE0; // 3.1415927 // pi // @796 -extern F32 lbl_803CDEF0; // 176.0 // @801 -extern F32 lbl_803CDEE4; // 180.0 // @797 - -extern F32 lbl_803CDEDC; // -1.0 // @702 - -extern F32 lbl_803CDED8; // 1.0 // @701 - -extern const char* zSurface_strings[]; - -xSurface& zSurfaceGetDefault() -{ - return sDef_surf; -} - -void zSurfaceGetName(S32 type, char* buffer) -{ - *buffer = NULL; - switch (type) - { - case 0: - strcpy(buffer, "DEFAULT"); - break; - case 1: - strcpy(buffer, "TILE"); - break; - case 2: - strcpy(buffer, "CARPET"); - break; - case 3: - strcpy(buffer, "SHORTGRASS"); - break; - case 4: - strcpy(buffer, "LONGGRASS"); - break; - case 5: - strcpy(buffer, "GRAVEL"); - break; - case 6: - strcpy(buffer, "DIRT"); - break; - case 7: - strcpy(buffer, "MUD"); - break; - case 8: - strcpy(buffer, "THORNS"); - break; - case 9: - strcpy(buffer, "METAL"); - break; - case 10: - strcpy(buffer, "SHEETMETAL"); - break; - case 11: - strcpy(buffer, "CONCRETE"); - break; - case 12: - strcpy(buffer, "MARBLE"); - break; - case 13: - strcpy(buffer, "STONE"); - break; - case 14: - strcpy(buffer, "WOOD"); - break; - case 15: - strcpy(buffer, "SNOW"); - break; - case 16: - strcpy(buffer, "ICE"); - break; - case 17: - strcpy(buffer, "SHALLOWWATER"); - break; - case 18: - strcpy(buffer, "DEEPWATER"); - break; - case 19: - strcpy(buffer, "TAR"); - break; - case 20: - strcpy(buffer, "SPECIAL1"); - break; - case 21: - strcpy(buffer, "DeepAcid"); - break; - case 22: - strcpy(buffer, "NONE"); - } -} - -F32 zSurfaceGetDamping(const xSurface* surf, F32 min_vel) -{ - return xpow(min_vel, surf->friction); -} - -S32 zSurfaceGetSlickness(const xSurface* surf) -{ - return (int)(lbl_803CDED8 / surf->friction); -} - -F32 zSurfaceGetOutOfBoundsDelay(const xSurface& s) -{ - if (s.moprops) - { - return ((zSurfaceProps*)s.moprops)->asset->oob_delay; - } - return lbl_803CDEDC; -} - -F32 zSurfaceGetFriction(const xSurface* surf) -{ - return surf->friction; -} - -U32 zSurfaceGetStandOn(const xSurface* surf) -{ - if (surf->moprops) - { - return !(((zSurfaceProps*)surf->moprops)->asset->phys_flags & 8); - } - return 1; -} - -U32 zSurfaceGetSticky(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->game_sticky; - } - return 0; -} - -U32 zSurfaceGetDamagePassthrough(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->game_damage_flags & 1; - } - return 0; -} - -S32 zSurfaceGetDamageType(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->game_damage_type; - } - return 0; -} - -U32 zSurfaceGetMatchOrient(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 2; - } - return 0; -} - -F32 zSurfaceGetSlideStopAngle(const xSurface* surf) -{ - if (surf->moprops) - { - return ((((zSurfaceProps*)surf->moprops)->asset->sld_start) * PI) / 176.0f; - } - return PI / 9; -} - -F32 zSurfaceGetSlideStartAngle(const xSurface* surf) -{ - if (surf->moprops) - { - return ((((zSurfaceProps*)surf->moprops)->asset->sld_start) * PI) / 176.0f; - } - return PI / 9; -} - -U8 zSurfaceOutOfBounds(const xSurface& s) -{ - if (s.moprops) - { - return ((zSurfaceProps*)s.moprops)->asset->phys_flags >> 4 & 1; - } - return 0; -} - -U32 zSurfaceGetStep(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 4; - } - return 0; -} - -U32 zSurfaceGetSlide(const xSurface* surf) -{ - if (surf->moprops) - { - return ((zSurfaceProps*)surf->moprops)->asset->phys_flags & 1; - } - return 0; -} - -xSurface* zSurfaceGetSurface(const xCollis* coll) -{ - xSurface* surf = NULL; - - if (coll->flags & 1) - { - if (coll->optr) - { - surf = coll->mptr->Surf; - } - else - { - surf = zSurfaceGetSurface(coll->oid); - } - } - if (surf != NULL) - { - return surf; - } - surf = &sDef_surf; - return surf; -} - -// TODO: Hacked to OK (with volatile sMapperCount and assignment in if), fix later -void zSurfaceRegisterMapper(U32 assetId) -{ - if (sMapperCount >= 1) - { - return; - } - if (!assetId) - { - return; - } - if (sMapper[sMapperCount] = (zMaterialMapAsset*)xSTFindAsset(assetId, 0)) - { - sMapperCount++; - } -} - -// zScene - -U8 HACK_BASETYPE; -static S32 bytesNeeded; -static S32 availOnDisk; -static S32 neededFiles; -static F32 offsetx; -static F32 offsety; -static U32 enableScreenAdj; -volatile static F32 oldOffsetx; -volatile static F32 oldOffsety; -static S32 sMemDepthSceneStart = -1; -static S32 sMemDepthJustHIPStart = -1; -_zEnv* gCurEnv; -U32 gTransitionSceneID; -F32 gSceneUpdateTime; -static xVec3 sOldPosPlayer; -static xVec3 sOldPosCamera; -static U32 sSuddenMove; - -struct zSceneLevel -{ - const char* desc; - const char* prefix; -}; - -struct IDBasePair -{ - U32 id; - xBase* base; -}; - -static IDBasePair* scobj_idbps; -static S32 scobj_size = -1; -static S32 nidbps = -1; - -extern U32 _1251; -extern char byte_803D0884; -extern U32 _2014; - -extern U32 _1250; -extern F32 _1373; -extern F32 _1374; -extern F32 _1375; -extern F32 _1493; -extern F32 _1494; -extern F32 _1495; -extern F32 _1496_0; -extern U32 _2013; -extern F32 _2094; -extern F32 _2095_0; -extern F32 _2096_0; -extern F32 _2097_0; -extern F32 _2242; - -static void zSceneObjHashtableInit(S32 count); -static void zSceneObjHashtableExit(); -static S32 zSceneObjHashtableUsage(); -static void zSceneObjHashtableAdd(U32 id, xBase* base); -static xBase* zSceneObjHashtableGet(U32 id); -static xBase* zSceneExitSoundIteratorCB(xBase* b, zScene*, void*); -static void zSceneAutoSave(); - -U32 zScene_ScreenAdjustMode() -{ - return enableScreenAdj; -} - -void zSceneSetOldScreenAdj() -{ - oldOffsetx = offsetx; - oldOffsety = offsety; -} - -void zSceneEnableScreenAdj(U32 enable) -{ - enableScreenAdj = enable; -} -void zSceneCardCheckStartup_set(S32 needed, S32 available, S32 files) -{ - bytesNeeded = needed; - availOnDisk = available; - neededFiles = files; -} - -void zScene_UpdateFlyToInterface(F32 dt) -{ -} - -U32 zSceneGetLevelIndex() -{ - return zSceneGetLevelIndex(globals.sceneCur->sceneID); -} - -const char* zSceneGetLevelName(U32 sceneID) -{ - char c1 = (sceneID >> 24) & 0xFF; - char c2 = (sceneID >> 16) & 0xFF; - - // Add in the updated LevelTable to this file - - // for (S32 i = 0; i < sizeof(sLevelTable) / sizeof(sLevelTable[0]); i++) - // { - // if (c1 == sLevelTable[i].prefix[0] && c2 == sLevelTable[i].prefix[1]) - // { - // return sLevelTable[i].desc; - // } - // } - - return "Level Not Found"; -} - -void zSceneMemLvlChkCB() -{ -} - -const char* zSceneGetName(xBase* b) -{ - if (b) - { - const char* n = xSTAssetName(b->id); - - if (n) - { - return n; - } - } - - return ""; -} - -const char* zSceneGetName(U32 gameID) -{ - xBase* b = zSceneFindObject(gameID); - - if (b) - { - return zSceneGetName(b); - } - - return ""; -} - -xBase* zSceneFindObject(U32 gameID) -{ - return 0; -} - -static void zSceneObjHashtableAdd(U32 id, xBase* base) -{ - S32 k, chkd; - - chkd = id & (scobj_size - 1); - - for (k = 0; k < scobj_size; k++) - { - IDBasePair* idbp = &scobj_idbps[chkd]; - - if (idbp->id == 0) - { - idbp->id = id; - idbp->base = base; - nidbps++; - break; - } - - chkd++; - - if (chkd == scobj_size) - { - chkd = 0; - } - } -} - -void zSceneRenderPreFX() -{ - // PORT CODE FROM BATTLE -} - -void zSceneRenderPostFX() -{ - // PORT CODE FROM BATTLE -} - -void zSceneRender() -{ - zSceneRenderPreFX(); - xScrFxRender(globals.oldSkoolCamera.lo_cam); - zSceneRenderPostFX(); -} - -void zSceneUpdate(F32 dt) -{ - // REFERENCE BFBB -} - -S32 zSceneSetup_serialTraverseCB(U32 clientID, xSerial* xser) -{ - char uiName[16]; - S32 val = 0; - xBase* b; - - xser->Read_b1(&val); - - if (val == 0) - { - return 1; - } - - sprintf(uiName, "%s", xUtil_idtag2string(clientID, 0)); - - uiName[1] = ' '; - - strcat(uiName, " VISITED"); - - b = zSceneFindObject(xStrHash(uiName)); - - if (b) - { - b->baseFlags |= 0x1; - } - - return 1; -} - -static void ActivateCB(xBase* base) -{ - base->baseFlags &= (U8)~0x40; -} - -static void DeactivateCB(xBase* base) -{ - base->baseFlags |= 0x40; -} - -void zSceneSetup() -{ - // REFERENCE BFBB -} - -void zSceneReset() -{ - zScene* s = globals.sceneCur; - - zEntPlayerPreReset(); - - gOccludeCount = 0; - - xScrFxLetterboxReset(); - zEntPickup_FlushGrabbed(); - zEntPickup_SceneReset(); - zMusicReset(); - //zThrown_Reset(); - zShrapnel_Reset(); - zFX_SceneReset(); - xFXSceneReset(); - xShadowManager_Reset(); - //ztalkbox::reset_all(); - //zCameraTweakGlobal_Reset(); - xPadDestroyRumbleChain(0); - - globals.cmgr = NULL; - - zEntEventAll(NULL, 0, eEventRoomEnd, NULL); - zEntEventAll(NULL, 0, eEventSceneEnd, NULL); - - zSceneSave(s, NULL); - zSceneAutoSave(); - - xSndStopAll(~SND_CAT_UI); - xSndUpdate(); - iSndWaitForDeadSounds(); - - for (U32 i = 0; i < s->num_base; i++) - { - if (s->base[i]) - { - switch (s->base[i]->baseType) - { - case eBaseTypePickup: - case eBaseTypeCamera: - case eBaseTypeDoor: - case eBaseTypeSavePoint: - case eBaseTypeItem: - case eBaseTypeStatic: - case eBaseTypeDynamic: - case eBaseTypeMovePoint: - case eBaseTypeTimer: - case eBaseTypeBubble: - case eBaseTypePortal: - case eBaseTypeGroup: - case eBaseTypeSFX: - case eBaseTypeFFX: - case eBaseTypeVFX: - case eBaseTypeButton: - case eBaseTypeProjectile: - case eBaseTypeSurface: - case eBaseTypeDestructObj: - case eBaseTypeGust: - case eBaseTypeVolume: - case eBaseTypeDispatcher: - case eBaseTypeCond: - case eBaseTypeUI: - case eBaseTypeUIFont: - case eBaseTypeProjectileType: - case eBaseTypeFog: - case eBaseTypeLight: - case eBaseTypeParticleEmitter: - case eBaseTypeParticleSystem: - case eBaseTypeCutsceneMgr: - default: - { - zEntEvent(NULL, 0, s->base[i], eEventReset, NULL, NULL, 1); - break; - } - case eBaseTypeCounter: - { - //xCounterReset(s->base[i]); - break; - } - case eBaseTypePlayer: - { - zEntPlayerReset((xEnt*)s->base[i]); - break; - } - case eBaseTypePlatform: - { - //zPlatform_Reset((zPlatform*)s->base[i], globals.sceneCur); - break; - } - case eBaseTypePendulum: - { - //zPendulum_Reset((_zPendulum*)s->base[i], globals.sceneCur); - break; - } - case eBaseTypeHangable: - { - //zEntHangable_Reset((zEntHangable*)s->base[i]); - break; - } - case eBaseTypeLobMaster: - { - zEntEvent(s->base[i], eEventReset); - break; - } - case eBaseTypeEGenerator: - { - //zEGenerator_Reset((zEGenerator*)s->base[i], globals.sceneCur); - break; - } - case eBaseTypeEnv: - { - _zEnv* env = (_zEnv*)s->base[i]; - - if (env) - { - if (zSceneFindObject(env->easset->startCameraAssetID)) - { - //zCameraReset(&globals.camera); - } - - xClimateInitAsset(&gClimate, env->easset); - } - } - } - } - } - - zNPCMgr_sceneReset(); - zEntPlayer_LoadCheckPoint(); - zSceneLoad(globals.sceneCur, NULL); - zSceneEnableVisited(s); - xSerialTraverse(zSceneSetup_serialTraverseCB); - xSkyDome_Setup(); - xUpdateCull_Reset(globals.updateMgr); - xUpdateCull_Update(globals.updateMgr, 100); - zGridReset(s); - - zEntEventAll(NULL, 0, eEventSceneBegin, NULL); - zEntEventAll(NULL, 0, eEventRoomBegin, NULL); - zEntEventAll(NULL, 0, eEventSceneReset, NULL); - - //zNPCTiki_InitStacking(globals.sceneCur); - //zNPCTiki_InitFX(globals.sceneCur); - - xUpdateCull_Update(globals.updateMgr, 100); - zLOD_Update(100); - - //zGameExtras_SceneReset(); -} - -void zSceneLoad(zScene* ent) -{ - // REFERENCE BFBB -} - -void zSceneSave(zScene* ent) -{ - // REFERENCE BFBB -} - -void zSceneSwitch(_zPortal* p, S32 forceSameScene) -{ - // REFERENCE BFBB -} - -void zSceneUpdateSFXWidgets() -{ - zScene* s = globals.sceneCur; - xSFXUpdateEnvironmentalStreamSounds((xSFX*)s->baseList[eBaseTypeSFX], - s->baseCount[eBaseTypeSFX]); -} - -void zSceneExit(S32 beginReload) -{ - // REFERENCE BFBB -} - -void zSceneInit(U32 theSceneID, S32 reloadInProgress) -{ - F32 pdone; - zScene* s; - U32 i; - - U8 rgba_bkgrd[4]; - *(U32*)rgba_bkgrd = _1250; - - gTransitionSceneID = theSceneID; - gOccludeCount = 0; - - char b[5]; - *(U32*)b = _1251; - b[4] = byte_803D0884; - - sprintf(b, xUtil_idtag2string(theSceneID, 0)); - xStrupr(b); - - theSceneID = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; - - xUtil_idtag2string(theSceneID, 0); - - xFogClearFog(); - xSndSceneInit(); - - if (!reloadInProgress) - { - sMemDepthSceneStart = xMemPushBase(); - } - - zGameScreenTransitionBegin(); - zParPTankInit(); - - pdone = _1373; - - if (globals.useHIPHOP && !reloadInProgress) - { - zGameScreenTransitionUpdate(pdone, "... scene preload ...\n"); - - S32 ver_hop = xSTPreLoadScene(theSceneID, NULL, 0x2); - - if (ver_hop >= 0x000A000F) - { - xSTQueueSceneAssets(theSceneID, 0x2); - - do - { - rgba_bkgrd[0] = 0; - rgba_bkgrd[1] = 0; - rgba_bkgrd[2] = 0; - rgba_bkgrd[3] = 0; - - pdone += _1373; - - zGameScreenTransitionUpdate(pdone, "... scene loading ...\n", rgba_bkgrd); - } while (xSTLoadStep(theSceneID) < _1374); - - xSTDisconnect(theSceneID, 0x2); - } - } - - sMemDepthJustHIPStart = xMemPushBase(); - s = (zScene*)xMemAllocSize(sizeof(zScene)); - - globals.sceneCur = s; - - xSceneInit(s, 200, 2048, 2068, 250); - - s->env = (xEnv*)xMemAllocSize(sizeof(xEnv)); - s->sceneID = theSceneID; - - iTime time; - - time = iTimeGet(); - xUtil_idtag2string(theSceneID, 0); - iTimeDiffSec(time); - - xSTPreLoadScene(theSceneID, NULL, 0x1); - - time = iTimeGet(); - xUtil_idtag2string(theSceneID, 0); - iTimeDiffSec(time); - - xSTQueueSceneAssets(theSceneID, 0x1); - - time = iTimeGet(); - xUtil_idtag2string(theSceneID, 0); - iTimeDiffSec(time); - - pdone += _1373; - - zGameScreenTransitionUpdate(pdone, "... scene asset queue ...\n"); - - time = iTimeGet(); - xUtil_idtag2string(theSceneID, 0); - iTimeDiffSec(time); - - do - { - rgba_bkgrd[0] = 0; - rgba_bkgrd[1] = 0; - rgba_bkgrd[2] = 0; - rgba_bkgrd[3] = 0; - - pdone += _1373; - - zGameScreenTransitionUpdate(pdone, "... scene loading ...\n", rgba_bkgrd); - } while (xSTLoadStep(theSceneID) < _1374); - - xSTDisconnect(theSceneID, 0x1); - - time = iTimeGet(); - xUtil_idtag2string(theSceneID, 0); - iTimeDiffSec(time); - - pdone += _1373; - - zGameScreenTransitionUpdate(pdone, "...initializing scene - sound\n"); - - zEntPlayer_LoadSounds(); - iSndInitSceneLoaded(); - xPadRumbleEnable(globals.currentActivePad, globals.option_vibration); - - xSTSwitchScene(theSceneID, NULL, NULL); - - globals.sceneCur->resolvID = zSceneFindObject; - globals.sceneCur->id2Name = zSceneGetName; - globals.sceneCur->base2Name = zSceneGetName; - - g_xSceneCur = globals.sceneCur; - - xModelPipeNumTables = xSTAssetCountByType('PIPT'); - - for (S32 i = 0; i < xModelPipeNumTables; i++) - { - void* data = xSTFindAssetByType('PIPT', i, NULL); - - xModelPipeCount[i] = *(S32*)data; - xModelPipeData[i] = (xModelPipeInfo*)((S32*)data + 1); - } - - xModelLookupCount = 0; - - //PipeForAllSceneModels(PipeCountStuffCB); - - if (xModelLookupCount) - { - xModelLookupList = - (xModelPipeLookup*)xMemAllocSize(xModelLookupCount * sizeof(xModelPipeLookup)); - - xModelLookupCount = 0; - - //PipeForAllSceneModels(PipeAddStuffCB); - } - - xModelBucket_PreCountReset(); - //PipeForAllSceneModels(xModelBucket_PreCountBucket); - - xModelBucket_PreCountAlloc(256); - //PipeForAllSceneModels(xModelBucket_InsertBucket); - - xModelBucket_Init(); - //add_scene_tweaks(); - xPTankPoolSceneEnter(); - zParPTankSceneEnter(); - xDecalInit(); - xFXScenePrepare(); - zLasso_scenePrepare(); - zDispatcher_scenePrepare(); - - S32 total_npcs = xSTAssetCountByType('VIL '); - zNPCMgr_scenePrepare(total_npcs); - - zAnimListInit(); - zGooInit(24); - - zGameScreenTransitionUpdate(_1375, "...initializing scene - base types\n"); - - for (i = 0; i < eBaseTypeCount; i++) - { - s->baseCount[i] = 0; - s->baseList[i] = NULL; - } - - zCollGeom_Init(); - zUI_Init(); - zUIFontInit(); - ztextbox::init(); - //ztalkbox::init(); - ztaskbox::init(); - - xModelInstStaticAlloc = 1; - s->num_base = 0; - - // for (i = 0; sInitTable[i].name; i++) - // { - // U32 typeCount = xSTAssetCountByType(sInitTable[i].assetType); - - // s->baseCount[sInitTable[i].baseType] = typeCount; - // s->num_base += typeCount; - - // if (sInitTable[i].querySubObjects) - // { - // for (U32 j = 0; j < typeCount; j++) - // { - // s->num_base += sInitTable[i].querySubObjects( - // xSTFindAssetByType(sInitTable[i].assetType, j, NULL)); - // } - // } - // } - - //add_dynamic_types(*s); - - if (s->num_base) - { - s->base = (xBase**)xMemAllocSize(s->num_base * sizeof(xBase*)); - } - else - { - s->base = NULL; - } - - zSceneObjHashtableInit(4096); - xFFXPoolInit(12); - xFFXShakePoolInit(3); - xFFXRotMatchPoolInit(1); - xEntSceneInit(); - xEntMotionDebugInit(s->baseCount[eBaseTypePlatform] + s->baseCount[eBaseTypePendulum] + - s->baseCount[eBaseTypeButton]); - zLightSetVolume(NULL); - //xPartitionReset(); - xFXRibbonSceneEnter(); - - U32 base_idx = 0; - - // for (i = 0; sInitTable[i].name; i++) - // { - // HACK_BASETYPE = sInitTable[i].baseType; - - // if (sInitTable[i].func) - // { - // base_idx = sInitTable[i].func(s, &sInitTable[i], base_idx); - // } - // } - - //init_dynamic_types(*s, base_idx); - - s->num_update_base = 0; - - for (i = 0; i < s->num_base; i++) - { - // if (BaseTypeNeedsUpdate(s->base[i]->baseType)) - // { - // s->num_update_base++; - // } - } - - s->update_base = (xBase**)xMemAllocSize(s->num_update_base * sizeof(xBase*)); - - base_idx = 0; - - for (i = 0; i < s->num_base; i++) - { - // if (BaseTypeNeedsUpdate(s->base[i]->baseType)) - // { - // s->update_base[base_idx] = s->base[i]; - // } - } - - xModelInstStaticAlloc = 0; - - zGameScreenTransitionEnd(); - zSceneObjHashtableUsage(); - zUI_ScenePortalInit(s); - zLightResolveLinks(); - zRenderStateInit(); - xFXStreakInit(); - xFXShineInit(); - xFXFireworksInit("PAREMIT_FIREWORKS_TRAIL", "PAREMIT_FIREWORKS1", "PAREMIT_FIREWORKS2", - "Fireworks_explode", "Fireworks_trail"); - //zFeetGetIDs(); - zLightningInit(); - zParCmdFindClipVolumes(); - zEntDestructObj_FindFX(); - zShrapnel_SceneInit(globals.sceneCur); - zCameraTweakGlobal_Reset(); - zActionLineInit(); - xScrFxLetterboxReset(); - xShadowManager_Init(eBaseTypeNPC + 10); - - S32 lkitCount = xSTAssetCountByType('LKIT'); - void* lkitData; - - for (S32 i = 0; i < lkitCount; i++) - { - lkitData = xSTFindAssetByType('LKIT', i, NULL); - - xLightKit_Prepare(lkitData); - } - - xClimateInit(&gClimate); - zSceneInitEnvironmentalSoundEffect(); - - sHackSmoothedUpdate = 1; - - //FootstepHackSceneEnter(); - zEntPickup_SceneEnter(); - xFXSceneInit(); - //zGame_HackGalleryInit(); - iSndSuspendCD(0); -} - -static U32 BaseTypeNeedsUpdate(U8 baseType) -{ - if (baseType == eBaseTypeUnknown || baseType == eBaseTypePlayer || baseType == eBaseTypeEnv || - baseType == eBaseTypeCamera || baseType == eBaseTypeStatic || - baseType == eBaseTypeMovePoint || baseType == eBaseTypeBubble || - baseType == eBaseTypePortal || baseType == eBaseTypeGroup || baseType == eBaseTypeSFX || - baseType == eBaseTypeFFX || baseType == eBaseTypeVFX || baseType == eBaseTypeCounter || - baseType == eBaseTypeProjectile || baseType == eBaseTypeGust || - baseType == eBaseTypeVolume || baseType == eBaseTypeDispatcher || - baseType == eBaseTypeCond || baseType == eBaseTypeUI || - baseType == eBaseTypeProjectileType || baseType == eBaseTypeLobMaster || - baseType == eBaseTypeCutsceneMgr || baseType == eBaseTypeHud || - baseType == eBaseTypeNPCProps || baseType == eBaseTypeParticleEmitterProps || - baseType == eBaseTypeCruiseBubble || baseType == eBaseTypeTextBox || - baseType == eBaseTypeTalkBox || baseType == eBaseTypeTaskBox || - baseType == eBaseTypeBoulderGenerator || baseType == eBaseTypeNPCSettings || - baseType == eBaseTypeTurret) - { - return 0; - } - - return 1; -} - -static void PipeForAllSceneModels(void (*pipeCB)(RpAtomic* data, U32 pipeFlags, U32 subObjects)) -{ - // non-matching: wrong registers - - S32 i, j, k; - S32 numModels = xSTAssetCountByType('MODL'); - - for (i = 0; i < numModels; i++) - { - RpAtomic* model = (RpAtomic*)xSTFindAssetByType('MODL', i, NULL); - - if (model) - { - PKRAssetTOCInfo ainfo; - U32 numSubObjects, remainSubObjBits, currSubObjBits; - RpAtomic* tempmodel; - - xSTGetAssetInfoByType('MODL', i, &ainfo); - - numSubObjects = 0; - tempmodel = model; - - do - { - numSubObjects++; - tempmodel = iModelFile_RWMultiAtomic(tempmodel); - } while (tempmodel); - - remainSubObjBits = (1 << numSubObjects) - 1; - - for (j = 0; j < xModelPipeNumTables; j++) - { - for (k = 0; k < xModelPipeCount[j]; k++) - { - if (ainfo.aid == xModelPipeData[j][k].ModelHashID) - { - currSubObjBits = remainSubObjBits & xModelPipeData[j][k].SubObjectBits; - - if (currSubObjBits) - { - pipeCB(model, xModelPipeData[j][k].PipeFlags, currSubObjBits); - } - - remainSubObjBits &= ~currSubObjBits; - - if (!remainSubObjBits) - { - goto loc_800B1698; - } - } - } - } - - if (remainSubObjBits) - { - pipeCB(model, 0, remainSubObjBits); - } - } - - loc_800B1698: - continue; - } -} - -static void PipeAddStuffCB(RpAtomic* data, U32 pipeFlags, U32) -{ - if (pipeFlags) - { - xModelLookupList[xModelLookupCount].model = data; - xModelLookupList[xModelLookupCount].PipeFlags = pipeFlags; - xModelLookupCount++; - } -} - -static void PipeCountStuffCB(RpAtomic*, U32 pipeFlags, U32) -{ - if (pipeFlags) - { - xModelLookupCount++; - } -} - -void zSceneSet(xBase* b, S32 index) -{ - globals.sceneCur->base[index] = b; -} - -static U32 zSceneInitFunc_Dispatcher(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - S32 count; - - count = s->baseCount[desc->baseType]; - - if (count) - { - st_ZDISPATCH_DATA* dpat_pool = zDispatcher_memPool(count); - s->baseList[desc->baseType] = dpat_pool; - - for (S32 idx = 0; idx < count; idx++) - { - xBase* b = zDispatcher_getInst(dpat_pool, idx); - xEntAsset* asset = (xEntAsset*)xSTFindAssetByType('DPAT', idx, NULL); - - zSceneSet(b, base_idx); - zDispatcher_Init((st_ZDISPATCH_DATA*)b, asset); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - } - - return base_idx; -} - -static U32 zSceneInitFunc_LobMaster(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - return base_idx; -} - -static U32 zSceneInitFunc_Volume(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - S32 count; - - count = s->baseCount[desc->baseType]; - - zVolumeInit(); - - if (count) - { - s->baseList[desc->baseType] = zVolumeGetVolume(0); - - for (S32 idx = 0; idx < count; idx++) - { - xBase* b = zVolumeGetVolume(idx); - - zLightSetVolume((zVolume*)b); - - zSceneSet(b, base_idx); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - } - - return base_idx; -} - -static U32 zSceneInitFunc_Surface(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - S32 count; - - count = s->baseCount[desc->baseType]; - - if (count) - { - s->baseList[desc->baseType] = xSurfaceGetByIdx(0); - - for (S32 idx = 0; idx < count; idx++) - { - xBase* b = xSurfaceGetByIdx(idx); - - zSceneSet(b, base_idx); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - } - - return base_idx; -} - -static U32 zSceneInitFunc_Camera(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - S32 count; - zCamMarker* camBlock; - - count = s->baseCount[desc->baseType]; - - if (count) - { - camBlock = (zCamMarker*)xMemAllocSize(count * sizeof(zCamMarker)); - s->baseList[desc->baseType] = camBlock; - - for (S32 idx = 0; idx < count; idx++) - { - xBase* b = &camBlock[idx]; - xCamAsset* assetCam = (xCamAsset*)xSTFindAssetByType('CAM ', idx, NULL); - - zSceneSet(b, base_idx); - zCamMarkerInit(b, assetCam); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - } - - return base_idx; -} - -static U32 zSceneInitFunc_Player(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - // REFERENCE BFBB - return 0; -} - -static U32 zSceneInitFunc_MovePoint(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - S32 count; - U32 assetSize; - zMovePoint* movpBlock; - - assetSize = 0; - count = s->baseCount[desc->baseType]; - movpBlock = zMovePoint_GetMemPool(count); - - if (movpBlock) - { - s->baseList[desc->baseType] = movpBlock; - - for (S32 idx = 0; idx < count; idx++) - { - xBase* b = zMovePoint_GetInst(idx); - xBaseAsset* basset = (xBaseAsset*)xSTFindAssetByType('MVPT', idx, &assetSize); - - zSceneSet(b, base_idx); - zMovePointInit(zMovePoint_GetInst(idx), (xMovePointAsset*)basset); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - } - - return base_idx; -} - -static U32 zSceneInitFunc_Default(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - U8* block; - S32 count; - U32 assetSize, offset; - xBase* b; - - block = NULL; - assetSize = 0; - offset = desc->sizeRuntime; - count = s->baseCount[desc->baseType]; - - if (count) - { - block = (U8*)xMemAllocSize(count * offset); - - s->baseList[desc->baseType] = (xBase*)block; - } - - for (S32 i = 0; i < count; i++) - { - void* asset = xSTFindAssetByType(desc->assetType, i, &assetSize); - b = (xBase*)(block + i * offset); - - zSceneSet(b, base_idx); - - if (desc->objectInitFunc) - { - desc->objectInitFunc(b, asset); - } - - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - - return base_idx; -} - -static U32 zSceneInitFunc_DefaultEnt(zScene* s, zSceneObjectInstanceDesc* desc, U32 base_idx) -{ - U8* block; - S32 count; - U32 assetSize, offset; - xBase* b; - - block = NULL; - assetSize = 0; - offset = desc->sizeRuntime; - count = s->baseCount[desc->baseType]; - - if (count) - { - block = (U8*)xMemAllocSize(count * offset); - - s->baseList[desc->baseType] = (xBase*)block; - } - - for (S32 i = 0; i < count; i++) - { - void* asset = xSTFindAssetByType(desc->assetType, i, &assetSize); - b = (xBase*)(block + i * offset); - - zSceneSet(b, base_idx); - - if (desc->objectInitFunc) - { - desc->objectInitFunc(b, asset); - } - - //xSceneAddEnt(s, s->ents[base_idx]); - zSceneObjHashtableAdd(b->id, b); - - base_idx++; - } - - return base_idx; -} +#include "zVolume.cpp" +#include "zVent.cpp" +#include "zVar.cpp" +#include "zSurface.cpp" +#include "zScene.cpp" // xSGT / zSaveLoad @@ -1763,1616 +96,10 @@ char* thumbIconMap[15] = { "ThumbIconHB", "ThumbIconJF", "ThumbIconBB", "ThumbIc "ThumbIconB2", "ThumbIconKF", "ThumbIconGY", "ThumbIconDB", "ThumbIconB3", "ThumbIconHB", "ThumbIconHB" }; -S32 xSGT_LoadPrefsCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_READCONTEXT* rctxt, U32 ui, - S32 i) -{ - U32 stereo; - - xSGReadData(xsgdata, rctxt, &stereo, 1); - xSGReadData(xsgdata, rctxt, &gSnd.categoryVolFader[2], 1); - xSGReadData(xsgdata, rctxt, &gSnd.categoryVolFader[0], 1); - xSGReadData(xsgdata, rctxt, &globals.option_vibration, 1); - if (globals.option_vibration != 0) - { - xPadRumbleEnable(globals.currentActivePad, 1); - } - else - { - xPadRumbleEnable(globals.currentActivePad, 0); - } - return 1; -} - -S32 xSGT_LoadLoadCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_READCONTEXT* rctxt, U32 ui, - S32 i) -{ - char bigbuf[32] = {}; - S32 compdiff = 0; - - xSGReadData(xsgdata, rctxt, bigbuf, 1, strlen(currSceneStr)); - if (strlen(currSceneStr) != strlen(bigbuf)) - { - compdiff = 1; - } - if (compdiff == 0) - { - strcpy(sceneRead, bigbuf); - } - - return compdiff == 0; -} - -S32 xSGT_SaveProcPrefsCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_WRITECONTEXT* wctxt) -{ - int sum = 0; - sum += xSGWriteData(xsgdata, wctxt, &gSnd.stereo, 1); - sum += xSGWriteData(xsgdata, wctxt, &gSnd.categoryVolFader[2], 1); - sum += xSGWriteData(xsgdata, wctxt, &gSnd.categoryVolFader[0], 1); - sum += xSGWriteData(xsgdata, wctxt, &globals.option_vibration, 1); - return sum + 1; -} - -S32 xSGT_SaveInfoPrefsCB(void* p1, st_XSAVEGAME_DATA* data, S32* i, S32* j) -{ - *i = 16; - *j = *i * 2; - return 1; -} - -S32 xSGT_SaveProcCB(void* vp, st_XSAVEGAME_DATA* xsgdata, st_XSAVEGAME_WRITECONTEXT* wctxt) -{ - if (globals.sceneCur->sceneID == 'PG12') - { - strcpy(currSceneStr, xUtil_idtag2string('HB01', 0)); - } - else - { - strcpy(currSceneStr, xUtil_idtag2string(globals.sceneCur->sceneID, 0)); - } - return xSGWriteData(xsgdata, wctxt, currSceneStr, 1, strlen(currSceneStr)) + 1; -} - -S32 xSGT_SaveInfoCB(void* vp, st_XSAVEGAME_DATA* xsgdata, S32* need, S32* most) -{ - *need = xSGWriteStrLen(currSceneStr); - *most = *need << 1; - return 1; -} - -void zSaveLoad_DispatchCB(U32 dispatchEvent, const F32* toParam) -{ - switch (dispatchEvent) - { - case 0xa8: - promptSel = 4; - break; - case 0xaa: - promptSel = 3; - break; - case 0xab: - currentCard = (int)*toParam; - en_SAVEGAME_MODE mode = XSG_MODE_LOAD; - if (gGameMode == eGameMode_Save) - { - mode = XSG_MODE_SAVE; - } - st_XSAVEGAME_DATA* data = xSGInit(mode); - zSaveLoad_CardCheckSpaceSingle_doCheck(data, currentCard); - xSGDone(data); - break; - case 0xac: - currentGame = (int)*toParam; - break; - case 0xad: - promptSel = 3; - break; - } -} - -// Scheduling meme on the return -U32 zSaveLoad_SaveLoop() -{ - zSaveLoadInit(); - S32 state = 0; - saveSuccess = 0; - - while (state != 6) - { - switch (state) - { - case 0: - while (zSaveLoad_CardCount() == 0) - { - zSaveLoad_CardPrompt(0); - } - state = 1; - break; - case 1: - switch (zSaveLoad_CardPick(0)) - { - case 1: - state = 2; - break; - case 4: - if (gGameState != 0) - { - gGameMode = eGameMode_Pause; - state = 6; - - xBase* sendTo = zSceneFindObject(xStrHash("PAUSE OPTIONS BKG GROUP")); - zEntEvent(sendTo, eEventUIFocusOn_Select); - - sendTo = zSceneFindObject(xStrHash("PAUSE OPTIONS GROUP")); - zEntEvent(sendTo, eEventUIFocusOn); - - sendTo = zSceneFindObject(xStrHash("PAUSE OPTION MGR UIF")); - zEntEvent(sendTo, eEventUIFocusOn_Select); - - sendTo = zSceneFindObject(xStrHash("PAUSE OPTION SAVE UIF")); - zEntEvent(sendTo, eEventUIFocusOn_Select); - } - else - { - gGameMode = eGameMode_Title; - state = 6; - - xBase* sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME NO")); - zEntEvent(sendTo, eEventUIFocusOn); - - sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME NO")); - zEntEvent(sendTo, eEventUIUnselect); - - sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME YES")); - zEntEvent(sendTo, eEventUIFocusOn_Select); - - sendTo = zSceneFindObject(xStrHash("MNU3 START CREATE NEW GAME")); - zEntEvent(sendTo, eEventUIFocusOn); - - sendTo = zSceneFindObject(xStrHash("BLUE ALPHA 1 UI")); - zEntEvent(sendTo, eEventInvisible); - } - break; - case 11: - state = 10; - currentGame = 0; - break; - default: - state = 0; - } - break; - case 2: - sAccessType = 2; - switch (zSaveLoad_GameSelect(0)) - { - case 2: - case 4: - case 5: - case 6: - case 7: - case 9: - state = 1; - break; - case 1: - state = 10; - break; - case -1: - zSaveLoad_ErrorPrompt(0); - state = 1; - break; - } - break; - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - break; - case 11: - zGameModeSwitch(eGameMode_Game); - zGameStateSwitch(1); - state = 6; - break; - case 10: - S32 tmp = zSaveLoad_SaveGame(); - if (tmp == 1) - { - zGameModeSwitch(eGameMode_Game); - zGameStateSwitch(1); - saveSuccess = 1; - state = 6; - - xBase* sendTo = zSceneFindObject(xStrHash("MNU4 SAVE COMPLETED")); - zEntEvent(sendTo, eEventVisible); - } - else - { - switch (tmp) - { - case 7: - zSaveLoad_SaveDamagedErrorPrompt(0); - break; - case 8: - zSaveLoad_CardYankedErrorPrompt(0); - break; - case 10: - zSaveLoad_CardPromptSpace(0); - break; - default: - zSaveLoad_ErrorPrompt(0); - break; - } - state = 1; - } - break; - } - } - - sAccessType = 0; - return saveSuccess; -} - -U32 zSaveLoad_LoadLoop() -{ - zSaveLoadInit(); - sAccessType = 1; - S32 state = 0; - while (state != 6) - { - switch (state) - { - case 0: - while (zSaveLoad_CardCount() == 0) - { - zSaveLoad_CardPrompt(1); - } - zSaveLoad_UIEvent(0x14, eEventUIFocusOff_Unselect); - state = 1; - break; - case 1: - switch (zSaveLoad_CardPick(1)) - { - case 1: - state = 2; - break; - case 4: - state = 8; - break; - case -1: - state = 0; - break; - case 2: - break; - } - break; - case 2: - switch (zSaveLoad_GameSelect(1)) - { - case 2: - case 4: - case 5: - case 6: - case 7: - case 9: - state = 1; - break; - case 1: - state = 9; - break; - case -1: - zSaveLoad_ErrorPrompt(1); - state = 1; - break; - } - break; - case 3: - break; - case 8: - zGameModeSwitch(eGameMode_Title); - zGameStateSwitch(0); - state = 6; - break; - case 9: - switch (zSaveLoad_LoadGame()) - { - case 1: - zGameModeSwitch(eGameMode_Game); - zGameStateSwitch(0); - state = 6; - globals.autoSaveFeature = 1; - break; - case 7: - zSaveLoad_DamagedSaveGameErrorPrompt(1); - state = 1; - break; - default: - zSaveLoad_ErrorPrompt(1); - state = 1; - } - } - } - - zSendEventToThumbIcon(eEventInvisible); - return (U32)sceneRead[0] << 0x18 | (U32)sceneRead[1] << 0x10 | (U32)sceneRead[2] << 0x8 | - (U32)sceneRead[3]; -} - -// Reordering, causing different register use at the end -S32 zSaveLoad_LoadGame() -{ - S32 success = false; - S32 teststat = true; - S32 rc; - en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; - S32 use_tgt = CardtoTgt(currentCard); - autoSaveCard = currentCard; - - st_XSAVEGAME_DATA* xsgdata = zSaveLoadSGInit(XSG_MODE_LOAD); - xSGTgtSelect(xsgdata, use_tgt); - xSGGameSet(xsgdata, currentGame); - - if (xsgdata == NULL) - { - teststat = false; - } - - xSGAddLoadClient(xsgdata, 'ROOM', NULL, xSGT_LoadLoadCB); - xSGAddLoadClient(xsgdata, 'PREF', NULL, xSGT_LoadPrefsCB); - xSerial_svgame_register(xsgdata, XSG_MODE_LOAD); - - if (!xSGSetup(xsgdata)) - { - teststat = false; - } - - en_XSG_WHYFAIL whyFail = XSG_WHYERR_NONE; - if (teststat) - { - rc = xSGProcess(xsgdata); - if (rc) - { - asstat = xSGAsyncStatus(xsgdata, 1, &whyFail, NULL); - } - if (!rc) - { - teststat = false; - } - else - { - switch (asstat) - { - case XSG_ASTAT_SUCCESS: - success = true; - break; - case XSG_ASTAT_FAILED: - success = false; - break; - case XSG_ASTAT_NOOP: - case XSG_ASTAT_INPROG: - break; - } - } - } - - if (teststat) - { - rc = xSGWrapup(xsgdata); - if (rc < 0) - { - teststat = false; - whyFail = XSG_WHYERR_OTHER; - } - else if (rc == 0) - { - teststat = false; - } - } - - if (!zSaveLoadSGDone(xsgdata)) - { - teststat = false; - } - - XSGAutoData* asg = xSGAutoSave_GetCache(); - S32 use_game = currentCard; - if (success && teststat) - { - S32 idx = xSGTgtPhysSlotIdx(xsgdata, use_tgt); - asg->SetCache(use_tgt, use_game, idx); - globals.autoSaveFeature = 1; - return 1; - } - asg->Discard(); - - switch (whyFail) - { - case XSG_WHYERR_OTHER: - return 7; - default: - return -1; - } -} - -// Reordering at beginning -S32 zSaveLoad_SaveGame() -{ - S32 success = false; - S32 teststat = true; - en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; - S32 use_tgt = CardtoTgt(currentCard); - S32 use_game = currentGame; - autoSaveCard = currentCard; - - st_XSAVEGAME_DATA* xsgdata = zSaveLoadSGInit(XSG_MODE_SAVE); - if (xSGCheckMemoryCard(xsgdata, currentCard) == 0) - { - zSaveLoadSGDone(xsgdata); - return 8; - } - - xSGTgtSelect(xsgdata, use_tgt); - xSGGameSet(xsgdata, use_game); - if (xsgdata == NULL) - { - teststat = false; - } - - zSceneSave(globals.sceneCur, NULL); - - xSGAddSaveClient(xsgdata, 'ROOM', NULL, xSGT_SaveInfoCB, xSGT_SaveProcCB); - xSGAddSaveClient(xsgdata, 'PREF', NULL, xSGT_SaveInfoPrefsCB, xSGT_SaveProcPrefsCB); - - xSerial_svgame_register(xsgdata, XSG_MODE_SAVE); - - U32 progress = zSceneCalcProgress(); - char label[64]; - const char* area; - - if (globals.sceneCur->sceneID == 'PG12') - { - area = zSceneGetLevelName('HB01'); - } - else - { - area = zSceneGetLevelName(globals.sceneCur->sceneID); - } - - strncpy(label, area, sizeof(label)); - - if (!xSGSetup(xsgdata, use_game, label, progress, 0, zSceneGetLevelIndex())) - { - teststat = false; - } - - en_XSG_WHYFAIL whyFail = XSG_WHYERR_NONE; - if (teststat) - { - S32 rc = xSGProcess(xsgdata); - if (rc) - { - asstat = xSGAsyncStatus(xsgdata, 1, &whyFail, NULL); - } - - xSGGameIsEmpty(xsgdata, use_game); - xSGTgtHasGameDir(xsgdata, use_tgt); - if (!rc) - { - teststat = false; - } - else - { - switch (asstat) - { - case XSG_ASTAT_SUCCESS: - success = true; - break; - case XSG_ASTAT_FAILED: - success = false; - break; - case XSG_ASTAT_NOOP: - case XSG_ASTAT_INPROG: - break; - } - } - } - - if (teststat && !xSGWrapup(xsgdata)) - { - teststat = false; - } - - if (!xSGCheckMemoryCard(xsgdata, currentCard)) - { - zSaveLoadSGDone(xsgdata); - return 8; - } - - if (!zSaveLoadSGDone(xsgdata)) - { - teststat = false; - } - - XSGAutoData* asg = xSGAutoSave_GetCache(); - if (success && teststat) - { - S32 idx = xSGTgtPhysSlotIdx(xsgdata, use_tgt); - asg->SetCache(use_tgt, use_game, idx); - globals.autoSaveFeature = 1; - return 1; - } - asg->Discard(); - - switch (whyFail) - { - case XSG_WHYERR_DAMAGE: - case XSG_WHYERR_OTHER: - return 7; - case XSG_WHYERR_NOCARD: - case XSG_WHYERR_CARDYANKED: - return 8; - default: - return -1; - } -} - -S32 zSaveLoad_DoAutoSave() -{ - S32 success = 0; - S32 teststat = 1; - en_XSGASYNC_STATUS asstat = XSG_ASTAT_NOOP; - st_XSAVEGAME_DATA* svinst; - - XSGAutoData* autodata = xSGAutoSave_GetCache(); - if (autodata == NULL) - { - return -1; - } - if (!autodata->IsValid()) - { - return -1; - } - - S32 use_tgt = CardtoTgt(autodata->LastTarget()); - S32 lastGame = autodata->LastGame(); - autodata->Discard(); - svinst = xSGInit(XSG_MODE_SAVE); - xSGTgtSelect(svinst, use_tgt); - xSGGameSet(svinst, lastGame); - - if (svinst == NULL) - { - teststat = 0; - } - - zSceneSave(globals.sceneCur, 0); - - xSGAddSaveClient(svinst, 'ROOM', 0, xSGT_SaveInfoCB, xSGT_SaveProcCB); - xSGAddSaveClient(svinst, 'PREF', 0, xSGT_SaveInfoPrefsCB, xSGT_SaveProcPrefsCB); - - xSerial_svgame_register(svinst, XSG_MODE_SAVE); - U32 progress = zSceneCalcProgress(); - - const char* area; - if (globals.sceneCur->sceneID == 'PG12') - { - area = zSceneGetLevelName('HB01'); - } - else - { - area = zSceneGetLevelName(globals.sceneCur->sceneID); - } - - char label[64]; - strncpy(label, area, sizeof(label)); - if (!xSGSetup(svinst, lastGame, label, progress, 0, zSceneGetLevelIndex())) - { - teststat = 0; - } - - if (teststat != 0) - { - S32 iprocess = xSGProcess(svinst); - if (iprocess != 0) - { - asstat = xSGAsyncStatus(svinst, 1, 0, 0); - } - xSGGameIsEmpty(svinst, lastGame); - xSGTgtHasGameDir(svinst, use_tgt); - if (iprocess == 0) - { - teststat = false; - } - else - { - switch (asstat) - { - case XSG_ASTAT_INPROG: - break; - case XSG_ASTAT_SUCCESS: - success = true; - break; - case XSG_ASTAT_FAILED: - success = false; - break; - } - } - } - - if (teststat && xSGWrapup(svinst) == 0) - { - teststat = false; - } - - if (xSGDone(svinst) == 0) - { - teststat = false; - } - - if ((success) && (teststat)) - { - if (autodata != NULL) - { - S32 idx = xSGTgtPhysSlotIdx(svinst, use_tgt); - autodata->SetCache(use_tgt, lastGame, idx); - globals.autoSaveFeature = 1; - } - return 1; - } - else - { - if (autodata != NULL) - { - autodata->Discard(); - } - globals.autoSaveFeature = 0; - return -1; - } -} - -void zSaveLoadAutoSaveUpdate() -{ - xBase* obj; - s32 out1, out2; - - if (globals.autoSaveFeature == 0 || gGameMode == eGameMode_Pause) - { - return; - } - if (preAutoSaving == 0) - { - return; - } - - S32 physicalSlot = xSGAutoSave_GetCache()->LastPhysicalSlot(); - if (physicalSlot >= 0) - { - autoSaveCard = physicalSlot; - switch (CARDProbeEx(physicalSlot, &out1, &out2)) - { - case 0: - case -1: - obj = zSceneFindObject(xStrHash("SAVING GAME ICON UI")); //"SAVING GAME ICON UI" - if (obj != NULL) - { - zEntEvent(obj, eEventVisible); - } - break; - default: - obj = zSceneFindObject(xStrHash("SAVING GAME ICON UI")); //"SAVING GAME ICON UI" - if (obj != NULL) - { - zEntEvent(obj, eEventInvisible); - } - - obj = zSceneFindObject(xStrHash("MNU4 AUTO SAVE FAILED")); //"MNU4 AUTO SAVE FAILED" - if (obj != NULL) - { - zEntEvent(obj, eEventVisible); - } - globals.autoSaveFeature = 0; - zSaveLoadPreAutoSave(0); - break; - } - } -} - -void zSaveLoadPreAutoSave(bool onOff) -{ - preAutoSaving = onOff; - if (onOff) - { - ResetButton::DisableReset(); - } - else - { - ResetButton::EnableReset(); - } -} - -S32 zSaveLoad_CardCheckFormatted(int, int); - -S32 zSaveLoad_GameSelect(S32 mode) -{ - S32 done = 0; - S32 i; - st_XSAVEGAME_DATA* svinst; - S32 use_tgt; - - badCard = 1; - while (badCard != 0) - { - currentGame = -1; - promptSel = -1; - use_tgt = CardtoTgt(currentCard); - - if (mode == 1) - { - zSaveLoad_UIEvent(0, eEventEnable); - zSaveLoad_UIEvent(0, eEventUIFocusOn); - zSaveLoad_UIEvent(0x33, eEventUIFocusOn); - } - else - { - zSaveLoad_UIEvent(0x34, eEventUIFocusOn); - } - - for (i = 0; i < 3; i++) - { - svinst = xSGInit(XSG_MODE_LOAD); - xSGTgtSelect(svinst, use_tgt); - if (xSGGameIsEmpty(svinst, i)) - { - if (mode == 1) - { - zSaveLoad_UIEvent(i + 6, eEventDisable); - } - strcpy(zSaveLoadGameTable[i].label, "Empty"); - strcpy(zSaveLoadGameTable[i].date, "Empty"); - zSaveLoadGameTable[i].progress = 0; - zSaveLoadGameTable[i].size = 0; - zSaveLoadGameTable[i].thumbIconIndex = -1; - } - else - { - strcpy(zSaveLoadGameTable[i].label, xSGGameLabel(svinst, i)); - if (strcmpi(zSaveLoadGameTable[i].label, zSceneGetLevelName('MNU3')) == 0) - { - strcpy(zSaveLoadGameTable[i].label, zSceneGetLevelName('HB01')); - } - strcpy(zSaveLoadGameTable[i].date, xSGGameModDate(svinst, i)); - zSaveLoadGameTable[i].progress = xSGGameProgress(svinst, i); - zSaveLoadGameTable[i].size = xSGGameSize(svinst, i); - zSaveLoadGameTable[i].size = zSaveLoadGameTable[i].size + 0x1fff & 0xffffe000; - zSaveLoadGameTable[i].size >>= 0xd; - zSaveLoadGameTable[i].size += 3; - - zSendEventToThumbIcon(3); - zSaveLoadGameTable[i].thumbIconIndex = xSGGameThumbIndex(svinst, i); - if (strcmpi(zSaveLoadGameTable[i].label, "") == 0) - { - zSaveLoadGameTable[i].thumbIconIndex = -1; - } - } - xSGDone(svinst); - } - - if (mode == 1) - { - for (S32 emptyCount = 6; emptyCount <= 8; emptyCount++) - { - if (zSaveLoad_slotIsEmpty(emptyCount - 6) == 0) - { - zSaveLoad_UIEvent(emptyCount, eEventUISelect); - break; - } - } - } - else - { - zSaveLoad_UIEvent(0x15, eEventUIFocusOn); - zSaveLoad_UIEvent(0x19, eEventUISelect); - } - badCard = 0; - - while (!done && promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(3); - if (promptSel == 4) - { - done = promptSel; - } - - if (currentGame == -1) - { - continue; - } - - done = zSaveLoad_CardCheck(currentCard, mode); - if (done != 1) - { - currentGame = -1; - badCard = 0; - - if (done == 9) - { - zSaveLoad_CardWrongDeviceErrorPrompt(mode); - done = 9; - } - break; - } - - done = zSaveLoad_CardCheckFormatted(currentCard, mode); - if (done != 1) - { - switch (done) - { - case 5: - done = 0; - promptSel = -1; - continue; - case 7: - zSaveLoad_CardDamagedErrorPrompt(mode); - promptSel = -1; - done = 7; - badCard = 0; - continue; - case 2: - currentGame = -1; - badCard = 0; - continue; - default: - continue; - } - } - - done = zSaveLoad_CardCheckValid(currentCard, mode); - if (done != 1) - { - switch (done) - { - case 5: - case 6: - done = 0; - promptSel = -1; - continue; - case 2: - promptSel = -1; - currentGame = -1; - badCard = 0; - continue; - default: - break; - } - } - - if (badCard == 0) - { - done = zSaveLoad_CardCheckGameSlot(currentCard, currentGame, mode); - if (done != 1) - { - switch (done) - { - case -1: - case 5: - done = 0; - promptSel = -1; - break; - case 2: - currentGame = -1; - break; - } - } - } - else - { - done = 0; - currentGame = -1; - } - } - } - - if (mode == 1) - { - zSaveLoad_UIEvent(0, eEventEnable); - } - - S32 index = 0x15; - if (mode == 1) - { - index = 0; - } - zSaveLoad_UIEvent(index, eEventUIFocusOff_Unselect); - return done; -} - -void zSaveLoad_BuildName(char* name_txt, S32 idx) -{ - char desired[128]; - char current_name[128]; - - BuildIt(desired, idx); - - S32 counter = 0; - for (S32 i = 0; i < idx; i++) - { - BuildIt(current_name, i); - if (strcmp(zSaveLoadGameTable[i].label, zSaveLoadGameTable[idx].label) == 0 && - strcmp(current_name, "Corrupt Save File\n\n") != 0) - { - counter++; - } - } - - if (counter > 0) - { - sprintf(name_txt, "%s (%d)", desired, counter); - name_txt[0x3f] = NULL; - } - else - { - strcpy(name_txt, desired); - } -} - -S32 zSaveLoad_CardPick(S32 mode) -{ - S32 done = 0; - S32 formatDone = 0x16; - - currentCard = -1; - promptSel = -1; - - if (mode == 1) - { - formatDone = 1; - } - - zSaveLoad_UIEvent(formatDone, eEventUIFocusOn); - formatDone = 0x17; - if (mode == 1) - { - formatDone = 4; - } - - zSaveLoad_UIEvent(formatDone, eEventUISelect); - - while (!done && promptSel == -1) - { - if (currentCard != -1) - { - done = zSaveLoad_CardCheck(currentCard, mode); - switch (done) - { - case 2: - currentCard = -1; - promptSel = -1; - continue; - case -1: - done = 0; - promptSel = -1; - continue; - case 9: - zSaveLoad_CardWrongDeviceErrorPrompt(mode); - done = -1; - promptSel = -1; - continue; - } - - done = zSaveLoad_CardCheckFormatted(currentCard, mode); - switch (done) - { - case 5: - done = 0; - if (promptSel == 3) - { - promptSel = -1; - continue; - } - if (promptSel == 4) - { - currentCard = -1; - return -1; - } - break; - case 6: - done = 0; - promptSel = -1; - continue; - case 7: - zSaveLoad_CardDamagedErrorPrompt(mode); - done = -1; - promptSel = -1; - continue; - case 2: - case 4: - currentCard = -1; - promptSel = -1; - continue; - case -1: - done = 0; - promptSel = -1; - continue; - case 8: - case 9: - case 10: - case 11: - - default: - break; - } - - done = zSaveLoad_CardCheckValid(currentCard, mode); - switch (done) - { - case 5: - case 6: - done = 0; - promptSel = -1; - continue; - case 2: - case 4: - promptSel = -1; - currentGame = -1; - break; - case 0: - case 1: - break; - case -1: - done = 0; - promptSel = -1; - continue; - case 3: - break; - } - } - - zSaveLoad_Tick(); - } - - formatDone = 0x16; - if (mode == 1) - { - formatDone = 1; - } - - zSaveLoad_UIEvent(formatDone, eEventUIFocusOff_Unselect); - - if (done == 1) - { - return done; - } - if (promptSel != -1) - { - return promptSel; - } - return done; -} - -S32 zSaveLoad_CardCheckSlotOverwrite(S32 cardNumber, S32 gameNumber) -{ - // TODO: Figure out what this number means. - S32 iVar1 = zSaveLoad_CardCheckSlotOverwrite_Free(cardNumber, gameNumber); - // NOTE (Square): I'm not sure that this is supposed to be a loop. It doesn't make - // sense to just break at the end and the condition feels like it should be an early return - // but this matches and I don't know how else to generate the `b` instruction at 0x18 - while (iVar1 != 1 || iVar1 == 10) - { - if (iVar1 == -1 || iVar1 == 10) - { - return iVar1; - } - - if (IsValidName(zSaveLoadGameTable[gameNumber].label)) - { - iVar1 = zSaveLoad_CardPromptOverwrite(); - } - else - { - iVar1 = zSaveLoad_CardPromptOverwriteDamaged(); - } - - if (iVar1 == 5) - { - return iVar1; - } - - if (iVar1 == 2 || iVar1 == 4) - { - return 2; - } - break; - } - - return 1; -} - -S32 zSaveLoad_CardCheckSlotEmpty(S32 cardNumber, S32 gameNumber) -{ - S32 i = zSaveLoad_CardCheckSlotEmpty_hasGame(cardNumber, gameNumber); - while (i != 1) - { - i = zSaveLoad_CardCheckSlotEmpty_hasGame(cardNumber, gameNumber); - if (i == -1 || i == 6) - { - return i; - } - - i = zSaveLoad_CardPromptGameSlotEmpty(); - if (i == 2 || i == 4) - { - return 2; - } - } - return 1; -} - -S32 zSaveLoad_CardCheckGameSlot(S32 cardNumber, S32 gameNumber, S32 mode) -{ - if (mode == 1) - { - return zSaveLoad_CardCheckSlotEmpty(cardNumber, gameNumber); - } - else - { - return zSaveLoad_CardCheckSlotOverwrite(cardNumber, gameNumber); - } -} - -S32 zSaveLoad_CardCheckGames(S32 cardNumber, S32 mode) -{ - S32 result = zSaveLoad_CardCheckGamesSingle(cardNumber); - while (result != 1) - { - badCard = 1; - - result = zSaveLoad_CardCheckGamesSingle(cardNumber); - if (result == -1 || result == 6 || result == 5) - { - return result; - } - - result = zSaveLoad_CardPromptGames(mode); - if (result == 2 || result == 4) - { - return 2; - } - } - return 1; -} - -S32 zSaveLoad_CardCheckSpace(S32 cardNumber, S32 mode) -{ - S32 result = zSaveLoad_CardCheckSpaceSingle(cardNumber); - while (result != 1) - { - badCard = 1; - - result = zSaveLoad_CardCheckSpaceSingle(cardNumber); - if (result == -1 || result == 6 || result == 5) - { - return result; - } - - result = zSaveLoad_CardPromptSpace(mode); - if (result == 2 || result == 4) - { - return 2; - } - } - return 1; -} - -S32 zSaveLoad_CardCheckValid(S32 cardNumber, S32 mode) -{ - if (mode == 1) - { - return zSaveLoad_CardCheckGames(cardNumber, mode); - } - else - { - return zSaveLoad_CardCheckSpace(cardNumber, mode); - } -} - -S32 zSaveLoad_CardCheckFormatted(S32 cardNumber, S32 mode) -{ - S32 result; - while (result = zSaveLoad_CardCheckFormattedSingle(cardNumber), result != 1) - { - badCard = 1; - - result = zSaveLoad_CardCheckFormattedSingle(cardNumber); - if (result == -1) - { - return -1; - } - - if (result == 7) - { - return 7; - } - - result = zSaveLoad_CardPromptFormat(mode); - if (result == 2 || result == 4) - { - return 2; - } - - sAccessType = 3; - S32 tmp = format(cardNumber, mode); - sAccessType = 2; - return tmp != 1 ? tmp : 11; - } - return 1; -} - -S32 zSaveLoad_CardCheck(S32 cardNumber, S32 mode) -{ - S32 cardResult = zSaveLoad_CardCheckSingle(cardNumber); - while (cardResult == 0) - { - badCard = 1; - - cardResult = zSaveLoad_CardPrompt(mode); - if (cardResult == 2 || cardResult == 4) - { - return 2; - } - cardResult = zSaveLoad_CardCheckSingle(cardNumber); - } - return cardResult == 9 ? 9 : 1; -} - -S32 zSaveLoad_CardCheckFormattedSingle(S32 cardNumber) -{ - S32 rc; - st_XSAVEGAME_DATA* ldinst = xSGInit(XSG_MODE_LOAD); - S32 tgtmax; - - rc = 0; - switch (xSGTgtCount(ldinst, &tgtmax)) - { - case 2: - switch (xSGTgtIsFormat(ldinst, cardNumber, NULL)) - { - case -1: - rc = 7; - break; - case 1: - rc = 1; - break; - case 0: - default: - rc = 0; - break; - } - break; - case 1: - S32 idx = xSGTgtPhysSlotIdx(ldinst, 0); - if (idx != cardNumber) - { - rc = -1; - } - else if (!(idx ^ cardNumber)) - { - switch (xSGTgtIsFormat(ldinst, 0, NULL)) - { - case -1: - rc = 7; - break; - case 1: - rc = 1; - break; - case 0: - default: - rc = 0; - break; - } - } - break; - case 0: - rc = -1; - break; - } - - xSGDone(ldinst); - return rc; -} - -S32 zSaveLoad_CardPromptOverwriteDamaged() -{ - zSaveLoad_UIEvent(0x15, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x23, eEventUIFocusOn_Select); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(5); - } - zSaveLoad_UIEvent(0x23, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPromptOverwrite() -{ - zSaveLoad_UIEvent(0x15, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x22, eEventUIFocusOn_Select); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(5); - } - zSaveLoad_UIEvent(0x22, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPromptGameSlotEmpty() -{ - zSaveLoad_UIEvent(0, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x13, eEventUIFocusOn_Select); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - } - zSaveLoad_UIEvent(0x13, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPromptGames(S32 mode) -{ - S32 i = 0x15; - if (mode == 1) - { - i = 0; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(1, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x12, eEventUIFocusOn_Select); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(3); - } - zSaveLoad_UIEvent(0x12, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPromptSpace(S32 mode) -{ - S32 i = 0x15; - if (mode == 1) - { - i = 0; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x16, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x25, eEventUIFocusOn_Select); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(3); - } - zSaveLoad_UIEvent(0x25, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPromptFormat(S32 mode) -{ - S32 i = 0x15; - if (mode == 1) - { - i = 0; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - - i = 0x16; - if (mode == 1) - { - i = 1; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - zSaveLoad_UIEvent(0x32, eEventUIFocusOn); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - zSaveLoad_poll(3); - } - zSaveLoad_UIEvent(0x32, eEventUIFocusOff_Unselect); - return promptSel; -} - -S32 zSaveLoad_CardPrompt(S32 cardNumber) -{ - S32 i = 0x15; - if (cardNumber == 1) - { - i = 0; - } - zSaveLoad_UIEvent(i, eEventEnable); - - i = 0x15; - if (cardNumber == 1) - { - i = 0; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - - i = 0x24; - if (cardNumber == 1) - { - i = 0x11; - } - zSaveLoad_UIEvent(i, eEventUIFocusOn_Select); - - i = 0x16; - if (cardNumber == 1) - { - i = 1; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - - promptSel = -1; - while (promptSel == -1) - { - zSaveLoad_Tick(); - } - - i = 0x24; - if (cardNumber == 1) - { - i = 0x11; - } - zSaveLoad_UIEvent(i, eEventUIFocusOff_Unselect); - - if (cardNumber == 1) - { - zSaveLoad_UIEvent(0, eEventDisable); - } - return promptSel; -} - -S32 format(S32 num, S32 mode) -{ - st_XSAVEGAME_DATA* data = zSaveLoadSGInit(XSG_MODE_LOAD); - S32 tgtmax; - - S32 rc = 0; - switch (xSGTgtCount(data, &tgtmax)) - { - case 2: - xSGTgtSelect(data, num); - rc = xSGTgtFormatTgt(data, num, 0); - zSaveLoadSGDone(data); - if (rc == -1) - { - zSaveLoad_ErrorFormatCardYankedPrompt(mode); - rc = 5; - } - else - { - if (rc == 0) - { - zSaveLoad_ErrorFormatPrompt(mode); - } - if (rc != 0) - { - rc = 1; - } - } - break; - case 1: - S32 idx = xSGTgtPhysSlotIdx(data, 0); - if (idx != num) - { - zSaveLoadSGDone(data); - rc = 5; - } - else - { - if (idx ^ num) - { - zSaveLoadSGDone(data); - } - else - { - xSGTgtSelect(data, 0); - rc = xSGTgtFormatTgt(data, num, 0); - zSaveLoadSGDone(data); - if (rc == 0) - { - zSaveLoad_ErrorFormatPrompt(mode); - } - } - } - break; - case 0: - rc = 5; - zSaveLoadSGDone(data); - break; - } - return rc; -} - -void zSaveLoad_Tick(bool) -{ - // REFERENCE BFBB -} - -// zRewardsMgr - -U32 upgradeSlotsPoints[14]; - -void zRewardsMgr::SetPlayerDead() -{ - playerDead = TRUE; -} - -U32 zRewardsMgr::GetUpgradeRangeUpper() const -{ -} - -void zRewardsMgr::ResetLastComboIndex() -{ - lastComboIndex = 0; -} - -U32 zRewardsMgr::GetLastComboIndex() const -{ - return lastComboIndex; -} - -void zRewardsMgr::ResetLastComboManlinessPoints() -{ - lastComboManlinessPoints = 0; -} - -U32 zRewardsMgr::GetLastComboManlinessPoints() const -{ - return lastComboManlinessPoints; -} - -// zRenderState - -_SDRenderState sRS; - -_SDRenderState zRenderStateCurrent() -{ - return sRS; -} - -// zPlayerSB - -TreasureChest* zPlayerSB::GetTreasureChestHud() -{ - return &treasureChest; -} - -void zPlayerSB::LoadCheckPoint() -{ -} - -void zPlayerSB::StoreCheckPoint() -{ -} - -// zPlayer - -void zPlayerReset(zEnt* ent) -{ -} +#include "xSGT.cpp" +#include "zSaveLoad.cpp" -void zPlayerRender(zEnt* ent) -{ -} +#include "zRewardsMgr.cpp" +#include "zRenderState.cpp" +#include "zPlayerSB.cpp" +#include "zPlayer.cpp" diff --git a/src/SB/Game/zWad3.h b/src/SB/Game/zWad3.h index 39c08fc..f76d4f1 100644 --- a/src/SB/Game/zWad3.h +++ b/src/SB/Game/zWad3.h @@ -1,97 +1,6 @@ #ifndef ZWAD3_H #define ZWAD3_H -#include - -#include "zGlobals.h" -#include "xString.h" -#include "string.h" -#include "xstransvc.h" -#include "zVolume.h" -#include "xEvent.h" -#include "zVar.h" -#include "xutil.h" -#include "zSurface.h" -#include "zEnt.h" -#include "zEntPickup.h" -#include "xScrFx.h" -#include "zNPCMgr.h" -#include "xPar.h" -#include "xParMgr.h" -#include "zParPTank.h" -#include "xPtankPool.h" -#include "xFX.h" -#include "zParSys.h" -#include "zActionLine.h" -#include "zLight.h" -#include "zLightning.h" -#include "xShadow.h" -#include "zDiscoFloor.h" -#include "xCutscene.h" -#include "zNPCGlyph.h" -#include "zNPCHazard.h" -#include "zEntButton.h" -#include "zCutsceneMgr.h" -#include "zUIFont.h" -#include "zUI.h" -#include "zTalkBox.h" -#include "xFog.h" -#include "xTimer.h" -#include "xDecal.h" -#include "xEntBoulder.h" -#include "zGrid.h" -#include "zMusic.h" -#include "xMarkerAsset.h" -#include "zCamera.h" -#include "zCamMarker.h" -#include "zCameraFly.h" -#include "zCameraTweak.h" -#include "zEntTeleportBox.h" -#include "xSystem.h" -#include "zDispatcher.h" -#include "zConditional.h" -#include "zAnimList.h" -#include "zParCmd.h" -#include "zEntDestructObj.h" -#include "zRenderState.h" -#include "xModel.h" -#include "zScene.h" -#include "xScene.h" #include "zSaveLoad.h" -#include "iTRC.h" -#include "iSystem.h" -#include "zHud.h" -#include "zRewards.h" -#include "xHudMeter.h" - -// Needs moved to another file because zWad2 and zWad3 use this struct -// not everything is here? -struct zPlayerSB : zPlayer -{ - // padded to get GetTreasureChestHud to match. - // All structs that are used here are updated to be correct. - // Assumably the dwarf is simply wrong - U64 padding; - U32 padding2; - U8 inited; - ManlinessMeter manlinessMeter; - KrabbyPattyMeter krabbyPattyMeter; - TreasureChest treasureChest; - GoofyGooberMeter goofyGooberMeter; - NitroMeter nitroMeter; - - TreasureChest* GetTreasureChestHud(); - void SetCamera(); - void LoadCheckPoint(); - void StoreCheckPoint(); - void HandleEvent(xBase* from, U32 thisEvent, F32* toParam, xBase* toParamWidget, - U32 toParamWidgetID); - void RenderEffects(); - void Render(); - void Update(F32 dt); - void Reset(); - void Init(xEntAsset* asset); - void Init(xEntAsset* asset, S32 playerIdx); -}; #endif diff --git a/src/SB/Game/zWadNME.cpp b/src/SB/Game/zWadNME.cpp index 2e07aff..2004234 100644 --- a/src/SB/Game/zWadNME.cpp +++ b/src/SB/Game/zWadNME.cpp @@ -1,52 +1,5 @@ #include "zWadNME.h" -void zNMECritBasic::SelfSetup() -{ - xBehaveMgr* bmgr; - xPsyche* psy; - bmgr = xBehaveMgr_GetSelf(); - bmgr->Subscribe(this, 0); - psy = psy_self; - psy->BrainBegin(); - psy->AddGoal('NGC\0', NULL); - psy->AddGoal('NGC\1', NULL); - psy->AddGoal('NGC\4', NULL); - psy->AddGoal('NGC\2', NULL); - psy->AddGoal('NGC\3', NULL); - psy->BrainEnd(); - //*(undefined4 *)(this_01 + 0x44) = 0x4e474300; -} - -void zNMECommon::DieTheGoodDeath() -{ -} - -S32 zNMEGoalDenDead::Exit(F32 dt, void* ctxt) -{ -} - -S32 zNMEGoalDenDamage::Exit(F32 dt, void* ctxt) -{ - zNMEDennis& npc = *(zNMEDennis*)this->psyche->clt_owner; - npc.tmr_nextLeap = -1.0f; - return 0; -} - -zNMEGoalDenEvade::PathDirect(zNMEDennis*, F32 dt) -{ -} - -// Return type not in dwarf, Could be wrong -void zNMEDennis::MeterRender() -{ -} - -void zNMEDennis::RenderHud() -{ - zNMEDennis::MeterRender(); -} - -S32 zNMEDennis::DfltVulnFlags() -{ - return 0xc07b0007; // HACKED TOGETHER FOR TESTING PURPOSES -} +#include "zNMETypeCritBasic.cpp" +#include "zNMECommon.cpp" +#include "zNMETypeBossDennis.cpp" diff --git a/src/SB/Game/zWadNME.h b/src/SB/Game/zWadNME.h index 36a1a38..3f6c68e 100644 --- a/src/SB/Game/zWadNME.h +++ b/src/SB/Game/zWadNME.h @@ -2,14 +2,9 @@ #define ZWADNME_H #include "zNMECommon.h" -#include "iSnd.h" #include "xModelBlur.h" #include "zStreamedSound.h" #include "zBossCam.h" -#include "xGroup.h" -#include "xGlobals.h" -#include "zGlobals.h" -#include "zWadNME.h" enum en_denstage { diff --git a/src/SB/Game/zWadUI.cpp b/src/SB/Game/zWadUI.cpp index c184297..333ecd5 100644 --- a/src/SB/Game/zWadUI.cpp +++ b/src/SB/Game/zWadUI.cpp @@ -9,111 +9,6 @@ zUIControllerAsset* UIControlAsset = 0; zUIUserString* zUIString = 0; zUIUserStringAsset* zUIStringAsset = 0; -unsigned char zUICustomConditionallyDisabled::PreRender() -{ - return m_bCondition; // struct sees to be missing some data -} - -unsigned char zUICustomConditionallyDisabled::PreAutoMenu() -{ - return m_bCondition; // struct sees to be missing some data -} - -void zUICustomImageSlideshow::SetTextureList(xGroup* m_TextureGroup) -{ - xGroupGetCount(m_TextureGroup); -} - -void zUICustom::PostApplyMotionFrame(zUIMotionFrame*) -{ -} - -void zUICustom::PreApplyMotionFrame(zUIMotionFrame*) -{ -} - -void zUICustom::PostInitMotion() -{ -} - -void zUICustom::PreInitMotion() -{ -} - -void zUICustom::Exit() -{ -} - -void zUICustom::PostRender() -{ -} - -U8 zUICustom::PreAutoMenu() -{ - return 1; -} - -U8 zUICustom::PreRender() -{ - return 1; -} - -void zUICustom::PostUpdate(float) -{ -} - -void zUICustom::PreUpdate(float) -{ -} - -U8 zUICustom::HandleEvent(xBase*, unsigned int, const float*, xBase*, unsigned int) -{ - return 1; -} - -void zUICustom::ResetMotion() -{ -} - -void zUICustom::Reset() -{ -} - -void zUICustom::Setup() -{ -} - -void zUICustom::Init() -{ -} - -void zUIController_Init(zUIController*, zUIControllerAsset*) -{ -} - -void zUIController_Init(xBase&, xDynAsset&, unsigned long) -{ - zUIController* UIControl = 0; - zUIControllerAsset* UIControlAsset = 0; - zUIController_Init(UIControl, UIControlAsset); -} - -void zUIController::DoRender() const -{ -} - -void zUIUserString_Init(zUIUserString*, zUIUserStringAsset*) -{ -} - -void zUIUserString_Init(xBase&, xDynAsset&, unsigned long) -{ - zUIUserString* zUIString = 0; - zUIUserStringAsset* zUIStringAsset = 0; - zUIUserString_Init(zUIString, zUIStringAsset); -} - -U32 zUIUserString::GetSortKey() const -{ - return 0; -} +#include "zUICustom.cpp" +#include "zUIController.cpp" +#include "zUIUserString.cpp"