Update dependencies and add virtual destructor to asset interfaces
This commit is contained in:
parent
bb65f463be
commit
67aade3ef4
2
deps/fmt
vendored
2
deps/fmt
vendored
@ -1 +1 @@
|
||||
Subproject commit ed301089183f51d53f9f076b9676d9c2a1f7c505
|
||||
Subproject commit 9dbb60c4c8019c0d851ce2e61f99cb5c74696369
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit 00d5a7f099065e2c8d119039c2f42c1f88ad8f59
|
||||
Subproject commit 0dca3cc5d642590d4c2bc75ce15e0c2ca31bcc87
|
@ -1,285 +1,291 @@
|
||||
#include "STDInclude.hpp"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
bool AssetHandler::BypassState = false;
|
||||
std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces;
|
||||
std::map<Game::XAssetType, wink::slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks;
|
||||
wink::signal<wink::slot<AssetHandler::RestrictCallback>> AssetHandler::RestrictSignal;
|
||||
|
||||
std::map<void*, void*> AssetHandler::Relocations;
|
||||
|
||||
std::map<std::string, Game::XAssetHeader> AssetHandler::TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];
|
||||
|
||||
void AssetHandler::RegisterInterface(IAsset* iAsset)
|
||||
{
|
||||
if (!iAsset) return;
|
||||
if (iAsset->GetType() == Game::XAssetType::ASSET_TYPE_INVALID)
|
||||
{
|
||||
delete iAsset;
|
||||
return;
|
||||
}
|
||||
|
||||
if (AssetHandler::AssetInterfaces.find(iAsset->GetType()) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
Logger::Print("Duplicate interface handler: %s\n", Game::DB_GetXAssetTypeName(iAsset->GetType()));
|
||||
delete AssetHandler::AssetInterfaces[iAsset->GetType()];
|
||||
}
|
||||
|
||||
AssetHandler::AssetInterfaces[iAsset->GetType()] = iAsset;
|
||||
}
|
||||
|
||||
void AssetHandler::ClearTemporaryAssets()
|
||||
{
|
||||
for (int i = 0; i < Game::XAssetType::ASSET_TYPE_COUNT; ++i)
|
||||
{
|
||||
AssetHandler::TemporaryAssets[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset)
|
||||
{
|
||||
AssetHandler::TemporaryAssets[type][Game::DB_GetXAssetNameHandlers[type](&asset)] = asset;
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindAsset(Game::XAssetType type, const char* filename)
|
||||
{
|
||||
Game::XAssetHeader header = { 0 };
|
||||
|
||||
// Allow call DB_FindXAssetHeader within the hook
|
||||
AssetHandler::BypassState = true;
|
||||
|
||||
if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end())
|
||||
{
|
||||
header = AssetHandler::TypeCallbacks[type](type, filename);
|
||||
}
|
||||
|
||||
// Disallow calling DB_FindXAssetHeader ;)
|
||||
AssetHandler::BypassState = false;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
void __declspec(naked) AssetHandler::FindAssetStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ecx
|
||||
push ebx
|
||||
push ebp
|
||||
push esi
|
||||
push edi
|
||||
|
||||
// Check if custom handler should be bypassed
|
||||
xor eax, eax
|
||||
mov al, AssetHandler::BypassState
|
||||
|
||||
test al, al
|
||||
jnz finishOriginal
|
||||
|
||||
mov ecx, [esp + 18h] // Asset type
|
||||
mov ebx, [esp + 1Ch] // Filename
|
||||
|
||||
push ebx
|
||||
push ecx
|
||||
|
||||
call AssetHandler::FindAsset
|
||||
|
||||
add esp, 8h
|
||||
|
||||
test eax, eax
|
||||
jnz finishFound
|
||||
|
||||
finishOriginal:
|
||||
// Asset not found using custom handlers, redirect to DB_FindXAssetHeader
|
||||
mov ebx, ds:6D7190h // InterlockedDecrement
|
||||
mov eax, 40793Bh
|
||||
jmp eax
|
||||
|
||||
finishFound:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
pop ebx
|
||||
pop ecx
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetHandler::IsAssetEligible(Game::XAssetType type, Game::XAssetHeader *asset)
|
||||
{
|
||||
const char* name = Game::DB_GetXAssetNameHandlers[type](asset);
|
||||
if (!name) return false;
|
||||
|
||||
bool restrict = false;
|
||||
AssetHandler::RestrictSignal(type, *asset, name, &restrict);
|
||||
|
||||
// If no slot restricts the loading, we can load the asset
|
||||
return (!restrict);
|
||||
}
|
||||
|
||||
void __declspec(naked) AssetHandler::AddAssetStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push [esp + 8]
|
||||
push [esp + 8]
|
||||
call AssetHandler::IsAssetEligible
|
||||
add esp, 08h
|
||||
|
||||
test al, al
|
||||
jz doNotLoad
|
||||
|
||||
mov eax, [esp + 8]
|
||||
sub esp, 14h
|
||||
mov ecx, 5BB657h
|
||||
jmp ecx
|
||||
|
||||
doNotLoad:
|
||||
mov eax, [esp + 8]
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::OnFind(Game::XAssetType type, AssetHandler::Callback* callback)
|
||||
{
|
||||
AssetHandler::TypeCallbacks[type] = callback;
|
||||
}
|
||||
|
||||
void AssetHandler::OnLoad(AssetHandler::RestrictCallback* callback)
|
||||
{
|
||||
AssetHandler::RestrictSignal.connect(callback);
|
||||
}
|
||||
|
||||
void AssetHandler::Relocate(void* start, void* to, DWORD size)
|
||||
{
|
||||
for (DWORD i = 0; i < size; i += 4)
|
||||
{
|
||||
// Reinterpret cast is fine here, as we are working with low-level pointers (due to the relocation hook)
|
||||
AssetHandler::Relocations[reinterpret_cast<char*>(start) + i] = reinterpret_cast<char*>(to) + i;
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset)
|
||||
{
|
||||
// Same here, reinterpret the value, as we're operating inside the game's environment
|
||||
offset->pointer = *reinterpret_cast<void**>((*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset());
|
||||
|
||||
if (AssetHandler::Relocations.find(offset->pointer) != AssetHandler::Relocations.end())
|
||||
{
|
||||
offset->pointer = AssetHandler::Relocations[offset->pointer];
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[asset.type]->Save(asset.header, builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type));
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[asset.type]->Mark(asset.header, builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type));
|
||||
}
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Game::XAssetHeader header = { 0 };
|
||||
if (type >= Game::XAssetType::ASSET_TYPE_COUNT) return header;
|
||||
|
||||
auto tempPool = &AssetHandler::TemporaryAssets[type];
|
||||
auto entry = tempPool->find(filename);
|
||||
if (entry != tempPool->end())
|
||||
{
|
||||
return { entry->second };
|
||||
}
|
||||
|
||||
if (AssetHandler::AssetInterfaces.find(type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[type]->Load(&header, filename, builder);
|
||||
|
||||
if (header.data)
|
||||
{
|
||||
Components::AssetHandler::StoreTemporaryAsset(type, header);
|
||||
}
|
||||
}
|
||||
|
||||
if (!header.data)
|
||||
{
|
||||
header = Game::DB_FindXAssetHeader(type, filename.data());
|
||||
if(header.data) Components::AssetHandler::StoreTemporaryAsset(type, header); // Might increase efficiency...
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename)
|
||||
{
|
||||
bool OriginalState = AssetHandler::BypassState;
|
||||
|
||||
AssetHandler::BypassState = true;
|
||||
Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename);
|
||||
if(!OriginalState) AssetHandler::BypassState = false;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
AssetHandler::AssetHandler()
|
||||
{
|
||||
AssetHandler::ClearTemporaryAssets();
|
||||
|
||||
// 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();
|
||||
|
||||
// Register asset interfaces
|
||||
AssetHandler::RegisterInterface(new Assets::IXModel());
|
||||
AssetHandler::RegisterInterface(new Assets::IMapEnts());
|
||||
AssetHandler::RegisterInterface(new Assets::IRawFile());
|
||||
AssetHandler::RegisterInterface(new Assets::IGfxImage());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterial());
|
||||
AssetHandler::RegisterInterface(new Assets::IPhysPreset());
|
||||
AssetHandler::RegisterInterface(new Assets::IXAnimParts());
|
||||
AssetHandler::RegisterInterface(new Assets::IPhysCollmap());
|
||||
//AssetHandler::RegisterInterface(new Assets::IXModelSurfs());
|
||||
AssetHandler::RegisterInterface(new Assets::ILocalizedEntry());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialPixelShader());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialTechniqueSet());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexShader());
|
||||
AssetHandler::RegisterInterface(new Assets::IStructuredDataDefSet());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexDeclaration());
|
||||
|
||||
}
|
||||
|
||||
AssetHandler::~AssetHandler()
|
||||
{
|
||||
ClearTemporaryAssets();
|
||||
|
||||
for (auto i = AssetHandler::AssetInterfaces.begin(); i != AssetHandler::AssetInterfaces.end(); ++i)
|
||||
{
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
AssetHandler::AssetInterfaces.clear();
|
||||
AssetHandler::RestrictSignal.clear();
|
||||
AssetHandler::TypeCallbacks.clear();
|
||||
}
|
||||
}
|
||||
#include "STDInclude.hpp"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
bool AssetHandler::BypassState = false;
|
||||
std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces;
|
||||
std::map<Game::XAssetType, wink::slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks;
|
||||
wink::signal<wink::slot<AssetHandler::RestrictCallback>> AssetHandler::RestrictSignal;
|
||||
|
||||
std::map<void*, void*> AssetHandler::Relocations;
|
||||
|
||||
std::map<std::string, Game::XAssetHeader> AssetHandler::TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];
|
||||
|
||||
void AssetHandler::RegisterInterface(IAsset* iAsset)
|
||||
{
|
||||
if (!iAsset) return;
|
||||
if (iAsset->GetType() == Game::XAssetType::ASSET_TYPE_INVALID)
|
||||
{
|
||||
delete iAsset;
|
||||
return;
|
||||
}
|
||||
|
||||
if (AssetHandler::AssetInterfaces.find(iAsset->GetType()) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
Logger::Print("Duplicate asset interface: %s\n", Game::DB_GetXAssetTypeName(iAsset->GetType()));
|
||||
delete AssetHandler::AssetInterfaces[iAsset->GetType()];
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print("Asset interface registered: %s\n", Game::DB_GetXAssetTypeName(iAsset->GetType()));
|
||||
}
|
||||
|
||||
AssetHandler::AssetInterfaces[iAsset->GetType()] = iAsset;
|
||||
}
|
||||
|
||||
void AssetHandler::ClearTemporaryAssets()
|
||||
{
|
||||
for (int i = 0; i < Game::XAssetType::ASSET_TYPE_COUNT; ++i)
|
||||
{
|
||||
AssetHandler::TemporaryAssets[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset)
|
||||
{
|
||||
AssetHandler::TemporaryAssets[type][Game::DB_GetXAssetNameHandlers[type](&asset)] = asset;
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindAsset(Game::XAssetType type, const char* filename)
|
||||
{
|
||||
Game::XAssetHeader header = { 0 };
|
||||
|
||||
// Allow call DB_FindXAssetHeader within the hook
|
||||
AssetHandler::BypassState = true;
|
||||
|
||||
if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end())
|
||||
{
|
||||
header = AssetHandler::TypeCallbacks[type](type, filename);
|
||||
}
|
||||
|
||||
// Disallow calling DB_FindXAssetHeader ;)
|
||||
AssetHandler::BypassState = false;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
void __declspec(naked) AssetHandler::FindAssetStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ecx
|
||||
push ebx
|
||||
push ebp
|
||||
push esi
|
||||
push edi
|
||||
|
||||
// Check if custom handler should be bypassed
|
||||
xor eax, eax
|
||||
mov al, AssetHandler::BypassState
|
||||
|
||||
test al, al
|
||||
jnz finishOriginal
|
||||
|
||||
mov ecx, [esp + 18h] // Asset type
|
||||
mov ebx, [esp + 1Ch] // Filename
|
||||
|
||||
push ebx
|
||||
push ecx
|
||||
|
||||
call AssetHandler::FindAsset
|
||||
|
||||
add esp, 8h
|
||||
|
||||
test eax, eax
|
||||
jnz finishFound
|
||||
|
||||
finishOriginal:
|
||||
// Asset not found using custom handlers, redirect to DB_FindXAssetHeader
|
||||
mov ebx, ds:6D7190h // InterlockedDecrement
|
||||
mov eax, 40793Bh
|
||||
jmp eax
|
||||
|
||||
finishFound:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
pop ebx
|
||||
pop ecx
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetHandler::IsAssetEligible(Game::XAssetType type, Game::XAssetHeader *asset)
|
||||
{
|
||||
const char* name = Game::DB_GetXAssetNameHandlers[type](asset);
|
||||
if (!name) return false;
|
||||
|
||||
bool restrict = false;
|
||||
AssetHandler::RestrictSignal(type, *asset, name, &restrict);
|
||||
|
||||
// If no slot restricts the loading, we can load the asset
|
||||
return (!restrict);
|
||||
}
|
||||
|
||||
void __declspec(naked) AssetHandler::AddAssetStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push [esp + 8]
|
||||
push [esp + 8]
|
||||
call AssetHandler::IsAssetEligible
|
||||
add esp, 08h
|
||||
|
||||
test al, al
|
||||
jz doNotLoad
|
||||
|
||||
mov eax, [esp + 8]
|
||||
sub esp, 14h
|
||||
mov ecx, 5BB657h
|
||||
jmp ecx
|
||||
|
||||
doNotLoad:
|
||||
mov eax, [esp + 8]
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::OnFind(Game::XAssetType type, AssetHandler::Callback* callback)
|
||||
{
|
||||
AssetHandler::TypeCallbacks[type] = callback;
|
||||
}
|
||||
|
||||
void AssetHandler::OnLoad(AssetHandler::RestrictCallback* callback)
|
||||
{
|
||||
AssetHandler::RestrictSignal.connect(callback);
|
||||
}
|
||||
|
||||
void AssetHandler::Relocate(void* start, void* to, DWORD size)
|
||||
{
|
||||
for (DWORD i = 0; i < size; i += 4)
|
||||
{
|
||||
// Reinterpret cast is fine here, as we are working with low-level pointers (due to the relocation hook)
|
||||
AssetHandler::Relocations[reinterpret_cast<char*>(start) + i] = reinterpret_cast<char*>(to) + i;
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset)
|
||||
{
|
||||
// Same here, reinterpret the value, as we're operating inside the game's environment
|
||||
offset->pointer = *reinterpret_cast<void**>((*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset());
|
||||
|
||||
if (AssetHandler::Relocations.find(offset->pointer) != AssetHandler::Relocations.end())
|
||||
{
|
||||
offset->pointer = AssetHandler::Relocations[offset->pointer];
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[asset.type]->Save(asset.header, builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type));
|
||||
}
|
||||
}
|
||||
|
||||
void AssetHandler::ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
if (AssetHandler::AssetInterfaces.find(asset.type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[asset.type]->Mark(asset.header, builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type));
|
||||
}
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Game::XAssetHeader header = { 0 };
|
||||
if (type >= Game::XAssetType::ASSET_TYPE_COUNT) return header;
|
||||
|
||||
auto tempPool = &AssetHandler::TemporaryAssets[type];
|
||||
auto entry = tempPool->find(filename);
|
||||
if (entry != tempPool->end())
|
||||
{
|
||||
return { entry->second };
|
||||
}
|
||||
|
||||
if (AssetHandler::AssetInterfaces.find(type) != AssetHandler::AssetInterfaces.end())
|
||||
{
|
||||
AssetHandler::AssetInterfaces[type]->Load(&header, filename, builder);
|
||||
|
||||
if (header.data)
|
||||
{
|
||||
Components::AssetHandler::StoreTemporaryAsset(type, header);
|
||||
}
|
||||
}
|
||||
|
||||
if (!header.data)
|
||||
{
|
||||
header = Game::DB_FindXAssetHeader(type, filename.data());
|
||||
if(header.data) Components::AssetHandler::StoreTemporaryAsset(type, header); // Might increase efficiency...
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename)
|
||||
{
|
||||
bool OriginalState = AssetHandler::BypassState;
|
||||
|
||||
AssetHandler::BypassState = true;
|
||||
Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename);
|
||||
if(!OriginalState) AssetHandler::BypassState = false;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
AssetHandler::AssetHandler()
|
||||
{
|
||||
AssetHandler::ClearTemporaryAssets();
|
||||
|
||||
// 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();
|
||||
|
||||
// Register asset interfaces
|
||||
if (ZoneBuilder::IsEnabled())
|
||||
{
|
||||
AssetHandler::RegisterInterface(new Assets::IXModel());
|
||||
AssetHandler::RegisterInterface(new Assets::IMapEnts());
|
||||
AssetHandler::RegisterInterface(new Assets::IRawFile());
|
||||
AssetHandler::RegisterInterface(new Assets::IGfxImage());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterial());
|
||||
AssetHandler::RegisterInterface(new Assets::IPhysPreset());
|
||||
AssetHandler::RegisterInterface(new Assets::IXAnimParts());
|
||||
AssetHandler::RegisterInterface(new Assets::IPhysCollmap());
|
||||
//AssetHandler::RegisterInterface(new Assets::IXModelSurfs());
|
||||
AssetHandler::RegisterInterface(new Assets::ILocalizedEntry());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialPixelShader());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialTechniqueSet());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexShader());
|
||||
AssetHandler::RegisterInterface(new Assets::IStructuredDataDefSet());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexDeclaration());
|
||||
}
|
||||
}
|
||||
|
||||
AssetHandler::~AssetHandler()
|
||||
{
|
||||
ClearTemporaryAssets();
|
||||
|
||||
for (auto i = AssetHandler::AssetInterfaces.begin(); i != AssetHandler::AssetInterfaces.end(); ++i)
|
||||
{
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
AssetHandler::AssetInterfaces.clear();
|
||||
AssetHandler::RestrictSignal.clear();
|
||||
AssetHandler::TypeCallbacks.clear();
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,74 @@
|
||||
namespace Components
|
||||
{
|
||||
class AssetHandler : public Component
|
||||
{
|
||||
public:
|
||||
class IAsset
|
||||
{
|
||||
public:
|
||||
virtual Game::XAssetType GetType() { return Game::XAssetType::ASSET_TYPE_INVALID; };
|
||||
virtual void Mark(Game::XAssetHeader header, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Save(Game::XAssetHeader header, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Dump(Game::XAssetHeader header) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Load(Game::XAssetHeader* header, std::string name, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
};
|
||||
|
||||
typedef Game::XAssetHeader(Callback)(Game::XAssetType type, std::string name);
|
||||
typedef void(RestrictCallback)(Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* restrict);
|
||||
|
||||
AssetHandler();
|
||||
~AssetHandler();
|
||||
const char* GetName() { return "AssetHandler"; };
|
||||
|
||||
static void OnFind(Game::XAssetType type, Callback* callback);
|
||||
static void OnLoad(RestrictCallback* callback);
|
||||
|
||||
static void Relocate(void* start, void* to, DWORD size = 4);
|
||||
|
||||
static void ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder);
|
||||
static void ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder);
|
||||
|
||||
static Game::XAssetHeader FindOriginalAsset(Game::XAssetType type, const char* filename);
|
||||
static Game::XAssetHeader FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder);
|
||||
|
||||
static void ClearTemporaryAssets();
|
||||
static void StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset);
|
||||
|
||||
private:
|
||||
static bool BypassState;
|
||||
|
||||
static void RegisterInterface(IAsset* iAsset);
|
||||
|
||||
static Game::XAssetHeader FindAsset(Game::XAssetType type, const char* filename);
|
||||
static bool IsAssetEligible(Game::XAssetType type, Game::XAssetHeader* asset);
|
||||
static void FindAssetStub();
|
||||
static void AddAssetStub();
|
||||
|
||||
static void OffsetToAlias(Utils::Stream::Offset* offset);
|
||||
|
||||
static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];
|
||||
|
||||
static std::map<Game::XAssetType, IAsset*> AssetInterfaces;
|
||||
static std::map<Game::XAssetType, wink::slot<Callback>> TypeCallbacks;
|
||||
static wink::signal<wink::slot<RestrictCallback>> RestrictSignal;
|
||||
|
||||
static std::map<void*, void*> Relocations;
|
||||
};
|
||||
}
|
||||
|
||||
#include "AssetInterfaces\IXModel.hpp"
|
||||
#include "AssetInterfaces\IMapEnts.hpp"
|
||||
#include "AssetInterfaces\IRawFile.hpp"
|
||||
#include "AssetInterfaces\IGfxImage.hpp"
|
||||
#include "AssetInterfaces\IMaterial.hpp"
|
||||
#include "AssetInterfaces\IPhysPreset.hpp"
|
||||
#include "AssetInterfaces\IXAnimParts.hpp"
|
||||
#include "AssetInterfaces\IPhysCollmap.hpp"
|
||||
#include "AssetInterfaces\IXModelSurfs.hpp"
|
||||
#include "AssetInterfaces\ILocalizedEntry.hpp"
|
||||
#include "AssetInterfaces\IMaterialPixelShader.hpp"
|
||||
#include "AssetInterfaces\IMaterialTechniqueSet.hpp"
|
||||
#include "AssetInterfaces\IMaterialVertexShader.hpp"
|
||||
#include "AssetInterfaces\IStructuredDataDefSet.hpp"
|
||||
#include "AssetInterfaces\IMaterialVertexDeclaration.hpp"
|
||||
namespace Components
|
||||
{
|
||||
class AssetHandler : public Component
|
||||
{
|
||||
public:
|
||||
class IAsset
|
||||
{
|
||||
public:
|
||||
virtual ~IAsset() {};
|
||||
virtual Game::XAssetType GetType() { return Game::XAssetType::ASSET_TYPE_INVALID; };
|
||||
virtual void Mark(Game::XAssetHeader header, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Save(Game::XAssetHeader header, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Dump(Game::XAssetHeader header) { /*ErrorTypeNotSupported(this);*/ };
|
||||
virtual void Load(Game::XAssetHeader* header, std::string name, ZoneBuilder::Zone* builder) { /*ErrorTypeNotSupported(this);*/ };
|
||||
};
|
||||
|
||||
typedef Game::XAssetHeader(Callback)(Game::XAssetType type, std::string name);
|
||||
typedef void(RestrictCallback)(Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* restrict);
|
||||
|
||||
AssetHandler();
|
||||
~AssetHandler();
|
||||
const char* GetName() { return "AssetHandler"; };
|
||||
|
||||
static void OnFind(Game::XAssetType type, Callback* callback);
|
||||
static void OnLoad(RestrictCallback* callback);
|
||||
|
||||
static void Relocate(void* start, void* to, DWORD size = 4);
|
||||
|
||||
static void ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder);
|
||||
static void ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder);
|
||||
|
||||
static Game::XAssetHeader FindOriginalAsset(Game::XAssetType type, const char* filename);
|
||||
static Game::XAssetHeader FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder);
|
||||
|
||||
static void ClearTemporaryAssets();
|
||||
static void StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset);
|
||||
|
||||
private:
|
||||
static bool BypassState;
|
||||
|
||||
static void RegisterInterface(IAsset* iAsset);
|
||||
|
||||
static Game::XAssetHeader FindAsset(Game::XAssetType type, const char* filename);
|
||||
static bool IsAssetEligible(Game::XAssetType type, Game::XAssetHeader* asset);
|
||||
static void FindAssetStub();
|
||||
static void AddAssetStub();
|
||||
|
||||
static void OffsetToAlias(Utils::Stream::Offset* offset);
|
||||
|
||||
static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];
|
||||
|
||||
static std::map<Game::XAssetType, IAsset*> AssetInterfaces;
|
||||
static std::map<Game::XAssetType, wink::slot<Callback>> TypeCallbacks;
|
||||
static wink::signal<wink::slot<RestrictCallback>> RestrictSignal;
|
||||
|
||||
static std::map<void*, void*> Relocations;
|
||||
};
|
||||
}
|
||||
|
||||
#include "AssetInterfaces\IXModel.hpp"
|
||||
#include "AssetInterfaces\IMapEnts.hpp"
|
||||
#include "AssetInterfaces\IRawFile.hpp"
|
||||
#include "AssetInterfaces\IGfxImage.hpp"
|
||||
#include "AssetInterfaces\IMaterial.hpp"
|
||||
#include "AssetInterfaces\IPhysPreset.hpp"
|
||||
#include "AssetInterfaces\IXAnimParts.hpp"
|
||||
#include "AssetInterfaces\IPhysCollmap.hpp"
|
||||
#include "AssetInterfaces\IXModelSurfs.hpp"
|
||||
#include "AssetInterfaces\ILocalizedEntry.hpp"
|
||||
#include "AssetInterfaces\IMaterialPixelShader.hpp"
|
||||
#include "AssetInterfaces\IMaterialTechniqueSet.hpp"
|
||||
#include "AssetInterfaces\IMaterialVertexShader.hpp"
|
||||
#include "AssetInterfaces\IStructuredDataDefSet.hpp"
|
||||
#include "AssetInterfaces\IMaterialVertexDeclaration.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user