From c3083ea78c308c9613c2b8c51b2f13249f25b532 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 9 May 2018 11:18:31 +0200 Subject: [PATCH] [IMaterial] Fix materials --- .../Modules/AssetInterfaces/IMaterial.cpp | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 961afb30..d13f76da 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -160,9 +160,9 @@ namespace Assets asset->sortKey = header.material->sortKey; // This is temp, as nobody has time to fix materials - asset->stateBitsCount = header.material->stateBitsCount; - asset->stateBitTable = header.material->stateBitTable; - std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48); +// asset->stateBitsCount = header.material->stateBitsCount; +// asset->stateBitTable = header.material->stateBitTable; +// std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48); asset->constantCount = header.material->constantCount; asset->constantTable = header.material->constantTable; @@ -217,6 +217,31 @@ namespace Assets { Components::Logger::Error("Material data left!"); } + + char baseIndex = 0; + for (char i = 0; i < asset->stateBitsCount; ++i) + { + auto stateBits = asset->stateBitTable[i]; + if (stateBits.loadBits[0] == 0x18128812 && + stateBits.loadBits[1] == 0xD) // Seems to be like a default stateBit causing a 'generic' initialization + { + baseIndex = i; + break; + } + } + + for (int i = 0; i < 48; ++i) + { + if (!asset->techniqueSet->techniques[i] && asset->stateBitsEntry[i] != -1) + { + asset->stateBitsEntry[i] = -1; + } + + if (asset->techniqueSet->techniques[i] && asset->stateBitsEntry[i] == -1) + { + asset->stateBitsEntry[i] = baseIndex; + } + } } void IMaterial::loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* /*builder*/)