Asset relocation.

This commit is contained in:
momo5502 2015-12-29 01:45:04 +01:00
parent 57e7ae3333
commit 93d1380139
6 changed files with 70 additions and 7 deletions

View File

@ -6,6 +6,8 @@ namespace Components
std::map<Game::XAssetType, AssetHandler::Callback> AssetHandler::TypeCallbacks;
std::vector<AssetHandler::RestrictCallback> AssetHandler::RestrictCallbacks;
std::map<void*, void*> AssetHandler::Relocations;
Game::XAssetHeader AssetHandler::FindAsset(Game::XAssetType type, const char* filename)
{
Game::XAssetHeader header = { 0 };
@ -98,11 +100,6 @@ namespace Components
test al, al
jz doNotLoad
// push [esp + 8]
// push [esp + 8]
// call DoBeforeLoadAsset
// add esp, 08h
mov eax, [esp + 8]
sub esp, 14h
mov ecx, 5BB657h
@ -124,10 +121,33 @@ namespace Components
AssetHandler::RestrictCallbacks.push_back(callback);
}
void AssetHandler::Relocate(void* start, void* to, DWORD size)
{
for (DWORD i = 0; i < size; i += 4)
{
AssetHandler::Relocations[reinterpret_cast<char*>(start) + i] = reinterpret_cast<char*>(to) + i;
}
}
void AssetHandler::OffsetToAlias(FastFiles::Offset* offset)
{
offset->fullPointer = *reinterpret_cast<void**>((*Game::g_streamBlocks)[offset->GetDecrementedStream()].data + offset->GetDecrementedPointer());
if (AssetHandler::Relocations.find(offset->fullPointer) != AssetHandler::Relocations.end())
{
offset->fullPointer = AssetHandler::Relocations[offset->fullPointer];
}
}
AssetHandler::AssetHandler()
{
// DB_FindXAssetHeader
Utils::Hook(Game::DB_FindXAssetHeader, AssetHandler::FindAssetStub).Install()->Quick();
// DB_ConvertOffsetToAlias
Utils::Hook(0x4FDFA0, AssetHandler::OffsetToAlias, HOOK_JUMP).Install()->Quick();
// DB_AddXAsset
Utils::Hook(0x5BB650, AssetHandler::AddAssetStub, HOOK_JUMP).Install()->Quick();
}

View File

@ -13,8 +13,7 @@ namespace Components
static void OnFind(Game::XAssetType type, Callback callback);
static void OnLoad(RestrictCallback callback);
static const bool Restrict;
static const bool Load;
static void Relocate(void* start, void* to, DWORD size = 4);
private:
static bool BypassState;
@ -24,7 +23,11 @@ namespace Components
static void FindAssetStub();
static void AddAssetStub();
static void OffsetToAlias(FastFiles::Offset* offset);
static std::map<Game::XAssetType, Callback> TypeCallbacks;
static std::vector<RestrictCallback> RestrictCallbacks;
static std::map<void*, void*> Relocations;
};
}

View File

@ -3,6 +3,36 @@ namespace Components
class FastFiles : public Component
{
public:
class Offset
{
public:
union
{
struct
{
uint32_t pointer : 28;
int stream : 4;
};
uint32_t fullValue;
void* fullPointer;
};
uint32_t GetDecrementedPointer()
{
Offset offset = *this;
offset.fullValue--;
return offset.pointer;
};
int GetDecrementedStream()
{
Offset offset = *this;
offset.fullValue--;
return offset.stream;
};
};
FastFiles();
~FastFiles();
const char* GetName() { return "FastFiles"; };

View File

@ -111,6 +111,8 @@ namespace Game
int* gameTypeCount = (int*)0x62E50A0;
gameTypeName_t* gameTypes = (gameTypeName_t*)0x62E50A4;
XBlock** g_streamBlocks = (XBlock**)0x16E554C;
void* ReallocateAssetPool(XAssetType type, unsigned int newSize)
{
int elSize = DB_GetXAssetSizeHandlers[type]();

View File

@ -214,6 +214,8 @@ namespace Game
extern int* gameTypeCount;
extern gameTypeName_t* gameTypes;
extern XBlock** g_streamBlocks;
void* ReallocateAssetPool(XAssetType type, unsigned int newSize);
void Menu_FreeItemMemory(Game::itemDef_t* item);
void OOBPrintT(int type, netadr_t netadr, const char* message);

View File

@ -887,6 +887,12 @@ namespace Game
XAssetHeader header;
};
struct XBlock
{
char *data;
unsigned int size;
};
struct XAssetEntry
{
XAsset asset;