From 43649ce612e0e25f9c5c073b31277eb7148cad04 Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Sat, 15 May 2021 12:33:21 +0200 Subject: [PATCH] Prepare custom texture support #185 --- src/client/component/images.cpp | 37 +++++++++++++++++++++ src/client/game/structs.hpp | 58 +++++++++++++++++++++++++++++++++ src/common/utils/hook.hpp | 2 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/client/component/images.cpp diff --git a/src/client/component/images.cpp b/src/client/component/images.cpp new file mode 100644 index 0000000..0a0c251 --- /dev/null +++ b/src/client/component/images.cpp @@ -0,0 +1,37 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" + +#include + +namespace images +{ + namespace + { + utils::hook::detour load_texture_hook; + + static_assert(sizeof(game::GfxImage) == 104); + static_assert(offsetof(game::GfxImage, name) == (sizeof(game::GfxImage) - sizeof(void*))); + static_assert(offsetof(game::GfxImage, texture) == 56); + + void load_texture_stub(game::GfxImageLoadDef** load_def, game::GfxImage* image) + { + printf("Loading image: %s\n", image->name); + load_texture_hook.invoke(load_def, image); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + if (!game::environment::is_mp()) return; + + load_texture_hook.create(0x1405A21F0, load_texture_stub); + } + }; +} + +REGISTER_COMPONENT(images::component) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 3973367..e24d2ed 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1,4 +1,5 @@ #pragma once +#include #define PROTOCOL 1 @@ -1225,6 +1226,62 @@ namespace game const char* buffer; }; + struct GfxImageLoadDef + { + char levelCount; + char numElements; + char pad[2]; + int flags; + int format; + int resourceSize; + char data[1]; + }; + + union $3FA29451CE6F1FA138A5ABAB84BE9676 + { + ID3D11Texture1D *linemap; + ID3D11Texture2D *map; + ID3D11Texture3D *volmap; + ID3D11Texture2D *cubemap; + GfxImageLoadDef *loadDef; + }; + + struct GfxTexture + { + $3FA29451CE6F1FA138A5ABAB84BE9676 ___u0; + ID3D11ShaderResourceView *shaderView; + ID3D11ShaderResourceView *shaderViewAlternate; + }; + + struct Picmip + { + char platform[2]; + }; + + struct CardMemory + { + int platform[2]; + }; + + struct GfxImage + { + char pad[36]; + char mapType; + char semantic; + char category; + char flags; + Picmip picmip; + char track; + //CardMemory cardMemory; + unsigned short width; + unsigned short height; + unsigned short depth; + unsigned short numElements; + GfxTexture texture; + char pad2[16]; + const char *name; + }; + union XAssetHeader { void* data; @@ -1234,6 +1291,7 @@ namespace game ScriptFile* scriptfile; StringTable* stringTable; LuaFile* luaFile; + GfxImage* image; }; struct XAsset diff --git a/src/common/utils/hook.hpp b/src/common/utils/hook.hpp index 223f18b..251131e 100644 --- a/src/common/utils/hook.hpp +++ b/src/common/utils/hook.hpp @@ -78,7 +78,7 @@ namespace utils::hook return static_cast(this->get_original()); } - template + template T invoke(Args ... args) { return static_cast(this->get_original())(args...);