From c0b0debf0bc6af551570b5057ec7fa3f96da9260 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 3 Apr 2022 23:42:25 -0700 Subject: [PATCH] Added rooms parsing to DynOS level gen --- data/dynos.cpp.h | 6 ++++ data/dynos_bin_gfx.cpp | 2 ++ data/dynos_bin_lvl.cpp | 16 ++++++++++ data/dynos_bin_pointer.cpp | 14 +++++++++ data/dynos_bin_read.cpp | 6 +++- data/dynos_bin_rooms.cpp | 64 ++++++++++++++++++++++++++++++++++++++ data/dynos_bin_utils.cpp | 4 +++ data/dynos_level.cpp | 2 +- 8 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 data/dynos_bin_rooms.cpp diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 9b3152c1..2b20ec0d 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -33,6 +33,7 @@ enum { DATA_TYPE_TRAJECTORY, DATA_TYPE_MOVTEX, DATA_TYPE_MOVTEXQC, + DATA_TYPE_ROOMS, DATA_TYPE_UNUSED, }; @@ -434,6 +435,7 @@ struct GfxData : NoCopy { DataNodes mTrajectories; DataNodes mMovtexs; DataNodes mMovtexQCs; + DataNodes mRooms; // Animation data Array *> mAnimValues; @@ -773,6 +775,10 @@ DataNode* DynOS_MovtexQC_Parse(GfxData* aGfxData, DataNode* void DynOS_MovtexQC_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); DataNode* DynOS_MovtexQC_Load(FILE *aFile, GfxData *aGfxData); +DataNode* DynOS_Rooms_Parse(GfxData* aGfxData, DataNode* aNode); +void DynOS_Rooms_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); +DataNode* DynOS_Rooms_Load(FILE *aFile, GfxData *aGfxData); + DataNode* DynOS_Tex_Parse(GfxData* aGfxData, DataNode* aNode); void DynOS_Tex_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); void DynOS_Tex_Load(FILE *aFile, GfxData *aGfxData); diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index 23da1e23..c5da0bc1 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -658,7 +658,9 @@ static void ParseGfxSymbol(GfxData* aGfxData, DataNode* aNode, Gfx*& aHead, gfx_symbol_4(gsDPSetFogColor); gfx_symbol_2(gsSPFogPosition, false); gfx_symbol_1(gsDPSetAlphaCompare, false); + gfx_symbol_2(gsSPCopyLightEXT, false); + gfx_symbol_2(gsSPFogFactor, false); // Special symbols if (_Symbol == "gsSPTexture") { diff --git a/data/dynos_bin_lvl.cpp b/data/dynos_bin_lvl.cpp index ed183076..1ce42330 100644 --- a/data/dynos_bin_lvl.cpp +++ b/data/dynos_bin_lvl.cpp @@ -1456,6 +1456,13 @@ static LevelScript ParseLevelScriptSymbolArg(GfxData* aGfxData, DataNodemRooms) { + if (_Arg == _Node->mName) { + return (LevelScript) DynOS_Rooms_Parse(aGfxData, _Node)->mData; + } + } + // Integers s32 x; if ((_Arg[1] == 'x' && sscanf(_Arg.begin(), "%x", &x) == 1) || (sscanf(_Arg.begin(), "%d", &x) == 1)) { @@ -1825,6 +1832,11 @@ static bool DynOS_Lvl_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxD DynOS_MovtexQC_Write(_File, aGfxData, _Node); } } + for (auto &_Node : aGfxData->mRooms) { + if (_Node->mLoadIndex == i) { + DynOS_Rooms_Write(_File, aGfxData, _Node); + } + } } fclose(_File); return true; @@ -1884,6 +1896,10 @@ GfxData *DynOS_Lvl_LoadFromBinary(const SysPath &aPackFolder, const char *aLevel case DATA_TYPE_COLLISION: DynOS_Col_Load (_File, _GfxData); break; case DATA_TYPE_LEVEL_SCRIPT: DynOS_Lvl_Load (_File, _GfxData); break; case DATA_TYPE_MACRO_OBJECT: DynOS_MacroObject_Load(_File, _GfxData); break; + case DATA_TYPE_TRAJECTORY: DynOS_Trajectory_Load (_File, _GfxData); break; + case DATA_TYPE_MOVTEX: DynOS_Movtex_Load (_File, _GfxData); break; + case DATA_TYPE_MOVTEXQC: DynOS_MovtexQC_Load (_File, _GfxData); break; + case DATA_TYPE_ROOMS: DynOS_Rooms_Load (_File, _GfxData); break; default: _Done = true; break; } } diff --git a/data/dynos_bin_pointer.cpp b/data/dynos_bin_pointer.cpp index 8c7d2b75..eebbf884 100644 --- a/data/dynos_bin_pointer.cpp +++ b/data/dynos_bin_pointer.cpp @@ -106,6 +106,13 @@ static PointerData GetDataFromPointer(const void* aPtr, GfxData* aGfxData) { } } + // Rooms + for (auto& _Node : aGfxData->mRooms) { + if (_Node->mData == aPtr) { + return { _Node->mName, 0 }; + } + } + // Behaviors enum BehaviorId id = get_id_from_vanilla_behavior((const BehaviorScript*) aPtr); if (id >= 0 && id < id_bhv_max_count) { @@ -270,6 +277,13 @@ static void *GetPointerFromData(GfxData *aGfxData, const String &aPtrName, u32 a } } + // Rooms + for (auto &_Node : aGfxData->mRooms) { + if (_Node->mName == aPtrName) { + return (void *) _Node->mData; + } + } + // Behaviors enum BehaviorId id = get_id_from_behavior_name(aPtrName.begin()); if (id >= 0 && id < id_bhv_max_count) { diff --git a/data/dynos_bin_read.cpp b/data/dynos_bin_read.cpp index e760cf45..5fad16f3 100644 --- a/data/dynos_bin_read.cpp +++ b/data/dynos_bin_read.cpp @@ -15,6 +15,7 @@ static IfDefPtr GetNearestIfDefPointer(char *pFileBuffer) { { "#ifndef VERSION_JP", 18, false }, { "#ifdef VERSION_EU", 17, true }, { "#ifdef TEXTURE_FIX", 18, false }, + { "#if defined(VERSION_JP) || defined(VERSION_SH)", 47, false }, }; IfDefPtr _Nearest = { NULL, 0, false }; for (const auto &_IfDef : sIfDefs) { @@ -178,7 +179,9 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) { } else if (_Buffer == "Lights1") { _DataType = DATA_TYPE_LIGHT; } else if (_Buffer == "u8") { - _DataType = DATA_TYPE_TEXTURE; + _DataType = strstr(aFilename.c_str(), "room") + ? DATA_TYPE_ROOMS + : DATA_TYPE_TEXTURE; } else if (_Buffer == "Texture") { _DataType = DATA_TYPE_TEXTURE; } else if (_Buffer == "Vtx") { @@ -228,6 +231,7 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) { case DATA_TYPE_TRAJECTORY: AppendNewNode(aGfxData, aGfxData->mTrajectories, _Buffer, pDataName, pDataTokens); break; case DATA_TYPE_MOVTEX: AppendNewNode(aGfxData, aGfxData->mMovtexs, _Buffer, pDataName, pDataTokens); break; case DATA_TYPE_MOVTEXQC: AppendNewNode(aGfxData, aGfxData->mMovtexQCs, _Buffer, pDataName, pDataTokens); break; + case DATA_TYPE_ROOMS: AppendNewNode(aGfxData, aGfxData->mRooms, _Buffer, pDataName, pDataTokens); break; case DATA_TYPE_UNUSED: pDataTokens = (Array *) 1; break; } _Buffer.Clear(); diff --git a/data/dynos_bin_rooms.cpp b/data/dynos_bin_rooms.cpp new file mode 100644 index 00000000..e5bad55f --- /dev/null +++ b/data/dynos_bin_rooms.cpp @@ -0,0 +1,64 @@ +#include "dynos.cpp.h" + +extern "C" { +} + + ///////////// + // Parsing // +///////////// + +DataNode* DynOS_Rooms_Parse(GfxData* aGfxData, DataNode* aNode) { + if (aNode->mData) return aNode; + + // U8 data + aNode->mSize = (u32) (aNode->mTokens.Count()); + aNode->mData = New(aNode->mSize); + for (u32 i = 0; i != aNode->mSize; ++i) { + aNode->mData[i] = (u8) aNode->mTokens[i].ParseInt(); + } + aNode->mLoadIndex = aGfxData->mLoadIndex++; + return aNode; +} + + ///////////// + // Writing // +///////////// + +void DynOS_Rooms_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode) { + if (!aNode->mData) return; + + // Name + WriteBytes(aFile, DATA_TYPE_ROOMS); + aNode->mName.Write(aFile); + + // Data + WriteBytes(aFile, aNode->mSize); + for (u32 i = 0; i != aNode->mSize; ++i) { + WriteBytes(aFile, aNode->mData[i]); + } +} + + ///////////// + // Reading // +///////////// + +DataNode* DynOS_Rooms_Load(FILE *aFile, GfxData *aGfxData) { + DataNode *_Node = New>(); + + // Name + _Node->mName.Read(aFile); + + // Data + _Node->mSize = ReadBytes(aFile); + _Node->mData = New(_Node->mSize); + for (u32 i = 0; i != _Node->mSize; ++i) { + _Node->mData[i] = ReadBytes(aFile); + } + + // Add it + if (aGfxData != NULL) { + aGfxData->mRooms.Add(_Node); + } + + return _Node; +} diff --git a/data/dynos_bin_utils.cpp b/data/dynos_bin_utils.cpp index 4b68b70f..5017a251 100644 --- a/data/dynos_bin_utils.cpp +++ b/data/dynos_bin_utils.cpp @@ -54,6 +54,10 @@ void DynOS_Gfx_Free(GfxData* aGfxData) { Delete(_Node->mData); Delete(_Node); } + for (auto& _Node : aGfxData->mRooms) { + Delete(_Node->mData); + Delete(_Node); + } Delete(aGfxData); } } diff --git a/data/dynos_level.cpp b/data/dynos_level.cpp index bd88e511..e3fd7d06 100644 --- a/data/dynos_level.cpp +++ b/data/dynos_level.cpp @@ -226,7 +226,7 @@ s32 DynOS_Level_GetCourse(s32 aLevel) { const void *DynOS_Level_GetScript(s32 aLevel) { DynOS_Level_Init(); - return DynOS_Lvl_Get("level_bob_entry"); // DO NOT COMMIT + return DynOS_Lvl_Get("level_jrb_entry"); // DO NOT COMMIT return sDynosLevelScripts[aLevel]; }