diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index b3f82e9d..b0f6777d 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -130,8 +130,7 @@ namespace Assets if (map->dpvs.surfaces[i].material) { - std::string matname = reader.readString(); // Name - map->dpvs.surfaces[i].material = basemat; + map->dpvs.surfaces[i].material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString(), builder).material; } } } diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 7a7058ea..ec85cb5c 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -33,7 +33,7 @@ namespace Assets material->sortKey = reader.readByte(); material->textureAtlasRowCount = reader.readByte(); material->textureAtlasColumnCount = reader.readByte(); - material->drawSurf.packed = reader.read<__int16>(); + material->drawSurf.packed = reader.read<__int64>(); material->surfaceTypeBits = reader.read(); material->hashIndex = reader.read(); char* stateBitsEntry = reader.readArray(48); @@ -43,27 +43,29 @@ namespace Assets material->stateBitsCount = reader.readByte(); material->stateFlags = reader.readByte(); material->cameraRegion = reader.readByte(); - material->techniqueSet = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_TECHSET, reader.readCString()).techniqueSet; - material->textureTable = builder->getAllocator()->allocateArray(material->textureCount); - material->constantTable = builder->getAllocator()->allocateArray(material->constantCount); - material->stateBitTable = builder->getAllocator()->allocateArray(material->stateBitsCount); + std::string techset = reader.readString(); + material->techniqueSet = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_TECHSET, techset.data()).techniqueSet; + + material->textureTable = builder->getAllocator()->allocateArray(material->textureCount & 0xFF); + material->constantTable = builder->getAllocator()->allocateArray(material->constantCount & 0xFF); + material->stateBitTable = builder->getAllocator()->allocateArray(material->stateBitsCount & 0xFF); if(!material->textureTable || !material->constantTable || !material->stateBitTable) { Components::Logger::Print("Error allocating memory for material structure!\n"); - builder->getAllocator()->free(material); // cleanup return; } - for (int i = 0; i < material->textureCount; ++i) + for (char i = 0; i < material->textureCount; ++i) { - const char* mapName = reader.readCString(); - material->textureTable[i].nameStart = mapName[0]; - material->textureTable[i].nameEnd = mapName[strlen(mapName) - 1]; - material->textureTable[i].nameHash = Game::R_HashString(mapName); + std::string mapName = reader.readString(); + material->textureTable[i].nameStart = mapName.front(); + material->textureTable[i].nameEnd = mapName.back(); + material->textureTable[i].nameHash = Game::R_HashString(mapName.data()); material->textureTable[i].sampleState = reader.readByte(); material->textureTable[i].semantic = reader.readByte(); + if (material->textureTable[i].semantic == SEMANTIC_WATER_MAP) { material->textureTable[i].info.water->floatTime = reader.read(); @@ -90,36 +92,23 @@ namespace Assets { material->textureTable[i].info.image = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readCString()).image; } - - builder->getAllocator()->free(mapName); } - for (int i = 0; i < material->constantCount; ++i) + for (char i = 0; i < material->constantCount; ++i) { - const char* constName = reader.readCString(); - const char* ptr = constName; - int j = 0; - // its late and msbuild wont stop bitching about strncpy being unsafe and i really dont care enough to fix it any other way - // this will do for now - // strncpy(materialConstantTable[i].name, constName, 12); - while(j < 12 && *ptr) - { - material->constantTable[i].name[j] = *ptr; - ++ptr; - ++j; - } - material->constantTable[i].nameHash = Game::R_HashString(constName); + std::string constName = reader.readString(); + strncpy_s(material->constantTable[i].name, 12, constName.data(), 12); + + material->constantTable[i].nameHash = Game::R_HashString(constName.data()); float* literal = reader.readArray(4); material->constantTable[i].literal[0] = literal[0]; material->constantTable[i].literal[1] = literal[1]; material->constantTable[i].literal[2] = literal[2]; material->constantTable[i].literal[3] = literal[3]; - - builder->getAllocator()->free(constName); - builder->getAllocator()->free(literal); } material->stateBitTable = reader.readArray(material->stateBitsCount); + header->material = material; } void IMaterial::loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index cb9c3e8d..048cf17e 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -267,8 +267,8 @@ namespace Components Utils::Hook::Set(0x4D3A74, 0); // Force debug logging - Utils::Hook::Nop(0x4AA89F, 2); - Utils::Hook::Nop(0x4AA8A1, 6); + Utils::Hook::Nop(0x4AA89F, 8); + //Utils::Hook::Set(0x6FF53C, 0); // remove activeAction execution (exploit in mods) Utils::Hook::Set(0x5A1D43, 0xEB); diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 7a735e45..a9761ad7 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -792,6 +792,14 @@ namespace Components }, &type, false); } }); + + Command::Add("sortkeysdump", [](Command::Params*) + { + Game::DB_EnumXAssets(Game::ASSET_TYPE_MATERIAL, [](Game::XAssetHeader header, void*) + { + Logger::Print("%s: %X\n", header.material->name, header.material->sortKey & 0xFF); + }, nullptr, false); + }); } }