[IMaterial] Small fixes

This commit is contained in:
momo5502 2016-12-26 18:44:33 +01:00
parent 8294be1b32
commit f2f7ac9230
4 changed files with 30 additions and 34 deletions

View File

@ -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;
}
}
}

View File

@ -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<int>();
material->hashIndex = reader.read<unsigned __int16>();
char* stateBitsEntry = reader.readArray<char>(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<Game::MaterialTextureDef>(material->textureCount);
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount);
material->stateBitTable = builder->getAllocator()->allocateArray<Game::GfxStateBits>(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<Game::MaterialTextureDef>(material->textureCount & 0xFF);
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount & 0xFF);
material->stateBitTable = builder->getAllocator()->allocateArray<Game::GfxStateBits>(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<float>();
@ -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<float>(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<Game::GfxStateBits>(material->stateBitsCount);
header->material = material;
}
void IMaterial::loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)

View File

@ -267,8 +267,8 @@ namespace Components
Utils::Hook::Set<BYTE>(0x4D3A74, 0);
// Force debug logging
Utils::Hook::Nop(0x4AA89F, 2);
Utils::Hook::Nop(0x4AA8A1, 6);
Utils::Hook::Nop(0x4AA89F, 8);
//Utils::Hook::Set<BYTE>(0x6FF53C, 0);
// remove activeAction execution (exploit in mods)
Utils::Hook::Set<BYTE>(0x5A1D43, 0xEB);

View File

@ -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);
});
}
}