From 0dbd45c84437a0f354a8d6356be6525c27a9e62b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 13 Jan 2016 01:29:22 +0100 Subject: [PATCH] Some patches and structureddata stuff. --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/QuickPatch.cpp | 1 + src/Components/Modules/StructuredData.cpp | 32 ++++++++ src/Components/Modules/StructuredData.hpp | 13 ++++ src/Components/Modules/Theatre.cpp | 13 ++-- src/Game/Structs.hpp | 94 +++++++++++++++++++++++ 7 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 src/Components/Modules/StructuredData.cpp create mode 100644 src/Components/Modules/StructuredData.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 8c8c97c0..a1dba934 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -44,6 +44,7 @@ namespace Components Loader::Register(new AssetHandler()); Loader::Register(new Localization()); Loader::Register(new MusicalTalent()); + Loader::Register(new StructuredData()); Loader::Register(new ConnectProtocol()); } diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index ab898db0..300a8746 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -57,4 +57,5 @@ namespace Components #include "Modules\AssetHandler.hpp" #include "Modules\Localization.hpp" #include "Modules\MusicalTalent.hpp" +#include "Modules\StructuredData.hpp" #include "Modules\ConnectProtocol.hpp" diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 99a9bfbc..129945ae 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -71,6 +71,7 @@ namespace Components // Don't delete config files if corrupted Utils::Hook::Set(0x47DCB3, 0xEB); + Utils::Hook::Set(0x4402B6, 0); // hopefully allow alt-tab during game, used at least in alt-enter handling Utils::Hook::Set(0x45ACE0, 0xC301B0); diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp new file mode 100644 index 00000000..0f5f358f --- /dev/null +++ b/src/Components/Modules/StructuredData.cpp @@ -0,0 +1,32 @@ +#include "STDInclude.hpp" + +namespace Components +{ + void StructuredData::DumpDataDef(Game::structuredDataDef_t* dataDef) + { + if (!dataDef || !dataDef->data) return; + + json11::Json definition = + json11::Json::object + { + { "version", dataDef->data->version }, + //{ "enums", [ 0 ] }, + }; + + Utils::WriteFile(Utils::VA("raw/%s.json", dataDef->name), definition.dump()); + } + + StructuredData::StructuredData() + { + Command::Add("dumpDataDef", [] (Command::Params params) + { + if (params.Length() < 2) return; + StructuredData::DumpDataDef(Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_STRUCTUREDDATADEF, params[1]).structuredData); + }); + } + + StructuredData::~StructuredData() + { + + } +} diff --git a/src/Components/Modules/StructuredData.hpp b/src/Components/Modules/StructuredData.hpp new file mode 100644 index 00000000..5375285c --- /dev/null +++ b/src/Components/Modules/StructuredData.hpp @@ -0,0 +1,13 @@ +namespace Components +{ + class StructuredData : public Component + { + public: + StructuredData(); + ~StructuredData(); + const char* GetName() { return "StructuredData"; }; + + private: + static void DumpDataDef(Game::structuredDataDef_t* dataDef); + }; +} diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 1ad87e9d..0d2ad4da 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -222,13 +222,12 @@ namespace Components FileSystem::DeleteFile("demos", info.Name + ".dm_13.json"); // Reset our ui_demo_* dvars here, because the theater menu needs it. - // Resetting them has no use, as they don't have any default value! - Command::Execute("reset ui_demo_mapname", true); - Command::Execute("reset ui_demo_mapname_localized", true); - Command::Execute("reset ui_demo_gametype", true); - Command::Execute("reset ui_demo_author", true); - Command::Execute("reset ui_demo_length", true); - Command::Execute("reset ui_demo_date", true); + Dvar::Var("ui_demo_mapname").Set(""); + Dvar::Var("ui_demo_mapname_localized").Set(""); + Dvar::Var("ui_demo_gametype").Set(""); + Dvar::Var("ui_demo_length").Set(""); + Dvar::Var("ui_demo_author").Set(""); + Dvar::Var("ui_demo_date").Set(""); // Reload demos Theatre::LoadDemos(); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index cabeb168..e2d99998 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -949,6 +949,99 @@ namespace Game fontEntry_t* characters; } Font; + typedef enum + { + STRUCTURED_DATA_INT = 0, + STRUCTURED_DATA_BYTE = 1, + STRUCTURED_DATA_BOOL = 2, + STRUCTURED_DATA_STRING = 3, + STRUCTURED_DATA_ENUM = 4, + STRUCTURED_DATA_STRUCT = 5, + STRUCTURED_DATA_INDEXEDARR = 6, + STRUCTURED_DATA_ENUMARR = 7, + STRUCTURED_DATA_FLOAT = 8, + STRUCTURED_DATA_SHORT = 9 + } structuredDataType_t; + + typedef struct + { + structuredDataType_t type; + union + { + int index; + }; + int offset; + } structuredDataItem_t; + + typedef struct + { + const char* name; + structuredDataItem_t item; + } structuredDataChild_t; + + typedef struct + { + int numChildren; + structuredDataChild_t* children; + int unknown1; + int unknown2; + } structuredDataStruct_t; + + typedef struct + { + int enumIndex; + structuredDataItem_t item; + } structuredDataEnumArray_t; + + typedef struct + { + const char* key; + int index; + } structuredDataEnumIndex_t; + + typedef struct + { + int numIndices; + int unknown; + structuredDataEnumIndex_t* indices; + } structuredDataEnum_t; + + typedef struct + { + int numItems; + structuredDataItem_t item; + } structuredDataIndexedArray_t; + + typedef struct + { + int version; + unsigned int hash; + int numEnums; + structuredDataEnum_t* enums; + int numStructs; + structuredDataStruct_t* structs; + int numIndexedArrays; + structuredDataIndexedArray_t* indexedArrays; + int numEnumArrays; + structuredDataEnumArray_t* enumArrays; + structuredDataItem_t rootItem; + } structuredData_t; + + typedef struct + { + const char* name; + int unknown; + structuredData_t* data; + } structuredDataDef_t; + + typedef struct + { + structuredData_t* data; + structuredDataItem_t* item; + int offset; + int error; + } structuredDataFindState_t; + union XAssetHeader { void *data; @@ -961,6 +1054,7 @@ namespace Game MapEnts* mapEnts; RawFile* rawfile; Font* font; + structuredDataDef_t* structuredData; }; struct XAsset