Fix custom materials

This commit is contained in:
Federico Cecchetto 2022-03-17 23:56:15 +01:00
parent cea4d720be
commit f6fd11d662
2 changed files with 14 additions and 15 deletions

View File

@ -27,6 +27,8 @@ namespace materials
std::unordered_map<std::string, std::string> images;
};
char constant_table[0x20] = {};
utils::concurrency::container<material_data_t> 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<bool>([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<bool>(material);
return db_material_streaming_fail_hook.invoke<int>(material);
}
}

View File

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