From fe6c08acc81303be095f3affe5120f1a264069a7 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 3 Sep 2016 16:59:05 +0200 Subject: [PATCH] Better material fix until is done --- src/Components/Modules/Materials.cpp | 24 +++++++++++++++++++++--- src/Components/Modules/Materials.hpp | 7 +++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index dd9ca412..8830f24f 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -22,12 +22,30 @@ namespace Components Game::Material* Materials::VerifyMaterial(Game::Material* material) { - if (!IsBadReadPtr(material, 4) && !IsBadReadPtr(material->name, 1)) +// if (!IsBadReadPtr(material, 4) && !IsBadReadPtr(material->name, 1)) +// { +// return material; +// } + + Materials::VerifyContainer container = { false, material }; + Game::DB_EnumXAssets(Game::XAssetType::ASSET_TYPE_MATERIAL, [] (Game::XAssetHeader header, void* data) + { + Materials::VerifyContainer* container = reinterpret_cast(data); + + if (container && header.material == container->material) + { + container->isValid = true; + } + }, &container, false); + + if (container.isValid) { return material; } - - return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material; + else + { + return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material; + } } __declspec(naked) void Materials::DrawMaterialStub() diff --git a/src/Components/Modules/Materials.hpp b/src/Components/Modules/Materials.hpp index 34bbb505..6b9b5bf8 100644 --- a/src/Components/Modules/Materials.hpp +++ b/src/Components/Modules/Materials.hpp @@ -11,6 +11,13 @@ namespace Components #endif private: + class VerifyContainer + { + public: + bool isValid; + Game::Material* material; + }; + static Utils::Hook ImageVersionCheckHook; static void ImageVersionCheck();