From f6fd11d662ef44e095ca0406a87be78fe8633ee1 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Thu, 17 Mar 2022 23:56:15 +0100 Subject: [PATCH] Fix custom materials --- src/client/component/materials.cpp | 22 ++++++++-------------- src/client/game/structs.hpp | 7 ++++++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/client/component/materials.cpp b/src/client/component/materials.cpp index 287238c0..1b0b17c5 100644 --- a/src/client/component/materials.cpp +++ b/src/client/component/materials.cpp @@ -27,6 +27,8 @@ namespace materials std::unordered_map images; }; + char constant_table[0x20] = {}; + utils::concurrency::container material_data; game::GfxImage* setup_image(game::GfxImage* image, const utils::image& raw_image) @@ -57,6 +59,7 @@ namespace materials std::memcpy(texture_table, white->textureTable, sizeof(game::MaterialTextureDef)); std::memcpy(image, white->textureTable->u.image, sizeof(game::GfxImage)); + material->constantTable = &constant_table; material->name = utils::memory::get_allocator()->duplicate_string(name); image->name = material->name; @@ -85,6 +88,7 @@ namespace materials && !utils::io::read_file(utils::string::va("h1-mod/materials/%s.png", name.data()), &data) && !utils::io::read_file(utils::string::va("data/materials/%s.png", name.data()), &data)) { + data_.materials[name] = nullptr; return nullptr; } @@ -124,24 +128,14 @@ namespace materials return result; } - bool db_material_streaming_fail_stub(game::Material* material) + int db_material_streaming_fail_stub(game::Material* material) { - const auto found = material_data.access([material](material_data_t& data_) + if (material->constantTable == &constant_table) { - if (data_.materials.find(material->name) != data_.materials.end()) - { - return true; - } - - return false; - }); - - if (found) - { - return false; + return 0; } - return db_material_streaming_fail_hook.invoke(material); + return db_material_streaming_fail_hook.invoke(material); } } diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index bb7c3aec..40515051 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1175,7 +1175,12 @@ namespace game const char* name; char __pad0[0x118]; char textureCount; - char __pad1[7]; + char constantCount; + char stateBitsCount; + char stateFlags; + char cameraRegion; + char materialType; + char assetFlags; MaterialTechniqueSet* techniqueSet; MaterialTextureDef* textureTable; void* constantTable;