From 0e9de1c152b6b7ce1dd86fdab9ea038ea107f1fc Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 30 Sep 2016 22:01:04 +0200 Subject: [PATCH] Experiments --- src/Components/Modules/AssetHandler.cpp | 25 +++++++++++- src/Components/Modules/Zones.cpp | 52 ++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 9a9fce6e..3e3739b6 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -117,6 +117,21 @@ namespace Components { const char* name = Game::DB_GetXAssetNameHandlers[type](asset); + if (name == "props/icicle_tall_des"s) + { + OutputDebugStringA(""); + } + + if (type == 10 && Zones::Version() >= 332 && Utils::String::StartsWith(name, "*")) + { + OutputDebugStringA(Utils::String::VA("LoadDefPtr: %X -> %s\n", reinterpret_cast(asset->image->texture), name)); + } + + if (name == "fx_icicle_broken_small"s || (type != 9 && type != 6 && type != 8 && type != 7 && Zones::Version() >= 332)) + { + OutputDebugStringA(""); + } + // Should we perform the null check before or after this? if (Flags::HasFlag("entries")) { @@ -181,6 +196,10 @@ namespace Components void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset) { +#ifdef DEBUG + Utils::Stream::Offset old = *offset; +#endif + // Same here, reinterpret the value, as we're operating inside the game's environment void* pointer = (*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset(); @@ -191,8 +210,10 @@ namespace Components offset->pointer = *reinterpret_cast(pointer); - //Game::XAssetHeader zob{ offset->pointer }; - } +#ifdef DEBUG + Game::XAssetHeader zob{ offset->pointer }; +#endif + } void AssetHandler::ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder) { diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 42ba92f9..5b070dd8 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -106,6 +106,8 @@ namespace Components int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; *Game::varXString = reinterpret_cast(reinterpret_cast(*Game::varXModel) + (elSize - 4) - (4 * (4 - i))); Game::Load_XString(false); + + Game::XModel* model = *Game::varXModel; } __declspec(naked) void Zones::LoadXModelLodInfoStub() @@ -523,15 +525,15 @@ namespace Components Utils::Memory::Allocator allocator; Game::snd_alias_t* tempSounds = allocator.AllocateArray(count); - for (int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { char* src = &buffer[i * 108]; - std::memcpy(&tempSounds[i], src + 0, 60); + std::memcpy(&tempSounds[i], src + 0, 60); std::memcpy(&tempSounds[i].pad2[36], src + 68, 20); std::memcpy(&tempSounds[i].pad2[56], src + 88, 20); - AssetHandler::Relocate(src + 0, buffer + (i * 100) + 0, 60); + AssetHandler::Relocate(src + 0, buffer + (i * 100) + 0, 60); AssetHandler::Relocate(src + 68, buffer + (i * 100) + 60, 20); AssetHandler::Relocate(src + 88, buffer + (i * 100) + 80, 20); } @@ -554,7 +556,7 @@ namespace Components bool Zones::LoadVehicleDef(bool atStreamStart, char* buffer) { bool result = Game::Load_Stream(atStreamStart, buffer, 788); - + Game::VehicleDef vehicle[2]; std::memcpy(vehicle, &buffer[0], 400); std::memcpy(&vehicle->pad[404], &buffer[400], 388); @@ -670,7 +672,43 @@ namespace Components bool result = Game::Load_Stream(atStreamStart, buffer, size + 4); memcpy(buffer + 28, buffer + 32, 4); - AssetHandler::Relocate(buffer + 32, buffer + 28, 4); + //AssetHandler::Relocate(buffer + 32, buffer + 28, 4); + + // Tell the game to load the image externally! + //Game::GfxImage* image = reinterpret_cast(buffer); + //image->loaded = false; + //image->dataLen1 = 0; + //image->dataLen2 = 0; + + return result; + } + + bool Load_GfxImageLoadStruct(bool atStreamStart, char* buffer, int size) + { +// if (Zones::Version() >= 332) +// { +// size = 0; +// (*reinterpret_cast(0x112ACD0))->dataSize = 0; +// } + + return Game::Load_Stream(atStreamStart, buffer, size); + } + + DWORD Load_Texture(Game::GfxImageLoadDef** loadDef, Game::GfxImage* image) + { +// if (!(*loadDef)->dataSize) +// { +// image->loaded = false; +// } + + if (FastFiles::Current() == "mp_cargoship_sh" || FastFiles::Current() == "mp_cargoship_sh_load") + { + OutputDebugStringA(""); + } + + //OutputDebugStringA(Utils::String::VA("LoadDefPtr: %X -> %s\n", reinterpret_cast(image->texture), image->name)); + DWORD result = Utils::Hook::Call(0x51F4E0)(loadDef, image); + //OutputDebugStringA(Utils::String::VA("LoadDefPtr: %X -> %s\n", reinterpret_cast(image->texture), image->name)); return result; } @@ -754,6 +792,7 @@ namespace Components if (Zones::ZoneVersion >= 332) { Zones::LoadGfxImageHook.Install(); + //Utils::Hook::Nop(0x5BB93E, 2); } else { @@ -830,6 +869,9 @@ namespace Components { ZeroMemory(*Game::varPathData, sizeof(Game::PathData)); }, HOOK_CALL); + + Utils::Hook(0x4D32A9, Load_GfxImageLoadStruct, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x4D32BC, Load_Texture, HOOK_CALL).Install()->Quick(); } Zones::~Zones()