IW5 material emedding system

This commit is contained in:
momo5502 2016-09-04 17:13:06 +02:00
parent e94d9788d0
commit 5e71960c7e
4 changed files with 84 additions and 33 deletions

View File

@ -24,9 +24,6 @@ namespace Components
Loader::Register(new Maps());
Loader::Register(new News());
Loader::Register(new Node());
#ifndef DISABLE_BITMESSAGE
Loader::Register(new BitMessage());
#endif
Loader::Register(new RCon());
Loader::Register(new Menus());
Loader::Register(new Toast());
@ -53,9 +50,11 @@ namespace Components
Loader::Register(new Dedicated());
Loader::Register(new Discovery());
Loader::Register(new Exception());
Loader::Register(new MinidumpUpload());
Loader::Register(new FastFiles());
Loader::Register(new Materials());
#ifndef DISABLE_BITMESSAGE
Loader::Register(new BitMessage());
#endif
Loader::Register(new FileSystem());
Loader::Register(new QuickPatch());
Loader::Register(new ServerInfo());
@ -65,6 +64,7 @@ namespace Components
Loader::Register(new AssetHandler());
Loader::Register(new Localization());
Loader::Register(new MusicalTalent());
Loader::Register(new MinidumpUpload());
Loader::Register(new StructuredData());
Loader::Register(new ConnectProtocol());

View File

@ -2,6 +2,7 @@
namespace Components
{
int Materials::ImageNameLength;
Utils::Hook Materials::ImageVersionCheckHook;
__declspec(naked) void Materials::ImageVersionCheck()
@ -20,31 +21,32 @@ namespace Components
}
}
Game::Material* Materials::VerifyMaterial(Game::Material* material)
Game::Material* Materials::ResolveMaterial(const char* stringPtr)
{
// if (!IsBadReadPtr(material, 4) && !IsBadReadPtr(material->name, 1))
// {
// return material;
// }
const char* imagePtr = stringPtr + 4;
unsigned int length = static_cast<unsigned int>(stringPtr[3] & 0xFF);
Materials::VerifyContainer container = { false, material };
Game::DB_EnumXAssets(Game::XAssetType::ASSET_TYPE_MATERIAL, [] (Game::XAssetHeader header, void* data)
if (strlen(imagePtr) >= length)
{
Materials::VerifyContainer* container = reinterpret_cast<Materials::VerifyContainer*>(data);
if (container && header.material == container->material)
{
container->isValid = true;
}
}, &container, false);
if (container.isValid)
{
return material;
Materials::ImageNameLength = 4 + length;
std::string image(imagePtr, length);
return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, image.data()).material;
}
else
Materials::ImageNameLength = 4;
return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material;
}
__declspec(naked) void Materials::PostDrawMaterialStub()
{
__asm
{
return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material;
mov eax, Materials::ImageNameLength
add [esp + 30h], eax
mov eax, 5358FFh
jmp eax
}
}
@ -52,8 +54,8 @@ namespace Components
{
__asm
{
push eax
call Materials::VerifyMaterial
push ecx
call Materials::ResolveMaterial
add esp, 4h
mov edx, 5310F0h
@ -61,13 +63,59 @@ namespace Components
}
}
int Materials::WriteDeathMessageIcon(char* string, int offset, Game::Material* material)
{
if (!material)
{
material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "default").material;
}
int length = strlen(material->name);
string[offset++] = static_cast<char>(length);
strncpy_s(string + offset, 1024 - offset, material->name, length);
return offset + length;
}
__declspec(naked) void Materials::DeathMessageStub()
{
__asm
{
push edx // Material
push eax // offset
push ecx // String
call Materials::WriteDeathMessageIcon
add esp, 14h
retn
}
}
Materials::Materials()
{
Materials::ImageNameLength = 7;
// Allow codo images
Materials::ImageVersionCheckHook.Initialize(0x53A456, Materials::ImageVersionCheck, HOOK_CALL)->Install();
// Fix material pointer exploit
Utils::Hook(0x534E0C, Materials::DrawMaterialStub, HOOK_CALL).Install()->Quick();
// Increment string pointer accordingly
Utils::Hook(0x5358FA, Materials::PostDrawMaterialStub, HOOK_JUMP).Install()->Quick();
// Adapt death message to IW5 material format
Utils::Hook(0x5A30D9, Materials::DeathMessageStub, HOOK_JUMP).Install()->Quick();
// Renderer::OnFrame([] ()
// {
// Game::Font* font = Game::R_RegisterFont("fonts/normalFont");
// float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
//
// Game::R_AddCmdDrawText("test^==preview_mp_rustzob", 0x7FFFFFFF, font, 500.0f, 150.0f, 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED);
// });
}
Materials::~Materials()

View File

@ -11,17 +11,16 @@ namespace Components
#endif
private:
class VerifyContainer
{
public:
bool isValid;
Game::Material* material;
};
static int ImageNameLength;
static Utils::Hook ImageVersionCheckHook;
static void ImageVersionCheck();
static Game::Material* VerifyMaterial(Game::Material* material);
static Game::Material* ResolveMaterial(const char* stringPtr);
static void DrawMaterialStub();
static void PostDrawMaterialStub();
static int WriteDeathMessageIcon(char* string, int offset, Game::Material* material);
static void DeathMessageStub();
};
}

View File

@ -21,6 +21,8 @@ namespace Components
Game::StringTable* StringTable::LoadObject(std::string filename)
{
filename = Utils::String::ToLower(filename);
Game::StringTable* table = nullptr;
FileSystem::File rawTable(filename);
@ -73,6 +75,8 @@ namespace Components
{
Game::XAssetHeader header = { 0 };
filename = Utils::String::ToLower(filename);
if (StringTable::StringTableMap.find(filename) != StringTable::StringTableMap.end())
{
header.stringTable = StringTable::StringTableMap[filename];