[ZoneBuilder] Fix one small thing in weapon writing, change how we search for assets in common_mp as using DB_EnumXAssets was missing some of them, and allow the weapon loading function see zonebuilder assets
This commit is contained in:
parent
5eb9996aea
commit
43456aedbd
@ -3,6 +3,7 @@
|
||||
namespace Components
|
||||
{
|
||||
thread_local int AssetHandler::BypassState = 0;
|
||||
bool AssetHandler::ShouldSearchTempAssets = false;
|
||||
std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces;
|
||||
std::map<Game::XAssetType, Utils::Slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks;
|
||||
Utils::Signal<AssetHandler::RestrictCallback> AssetHandler::RestrictSignal;
|
||||
@ -69,6 +70,21 @@ namespace Components
|
||||
return header;
|
||||
}
|
||||
|
||||
Game::XAssetHeader AssetHandler::FindTemporaryAsset(Game::XAssetType type, const char* filename)
|
||||
{
|
||||
Game::XAssetHeader header = { nullptr };
|
||||
if (type >= Game::XAssetType::ASSET_TYPE_COUNT) return header;
|
||||
|
||||
auto tempPool = &AssetHandler::TemporaryAssets[type];
|
||||
auto entry = tempPool->find(filename);
|
||||
if (entry != tempPool->end())
|
||||
{
|
||||
header = { entry->second };
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
int AssetHandler::HasThreadBypass()
|
||||
{
|
||||
return AssetHandler::BypassState > 0;
|
||||
@ -116,7 +132,7 @@ namespace Components
|
||||
|
||||
|
||||
test al, al
|
||||
jnz finishOriginal
|
||||
jnz checkTempAssets
|
||||
|
||||
mov ecx, [esp + 18h] // Asset type
|
||||
mov ebx, [esp + 1Ch] // Filename
|
||||
@ -137,11 +153,30 @@ namespace Components
|
||||
pop eax
|
||||
|
||||
|
||||
test eax, eax
|
||||
jnz finishFound
|
||||
|
||||
checkTempAssets:
|
||||
mov al, AssetHandler::ShouldSearchTempAssets // check to see if enabled
|
||||
test eax, eax
|
||||
jz finishOriginal
|
||||
|
||||
mov ecx, [esp + 18h] // Asset type
|
||||
mov ebx, [esp + 1Ch] // Filename
|
||||
|
||||
push ebx
|
||||
push ecx
|
||||
|
||||
call AssetHandler::FindTemporaryAsset
|
||||
|
||||
add esp, 8h
|
||||
|
||||
test eax, eax
|
||||
jnz finishFound
|
||||
|
||||
finishOriginal:
|
||||
// Asset not found using custom handlers, redirect to DB_FindXAssetHeader
|
||||
// Asset not found using custom handlers or in temp assets or bypasses were enabled
|
||||
// redirect to DB_FindXAssetHeader
|
||||
mov ebx, ds:6D7190h // InterlockedDecrement
|
||||
mov eax, 40793Bh
|
||||
jmp eax
|
||||
@ -454,6 +489,11 @@ namespace Components
|
||||
Utils::Hook::Set<Game::XAssetEntry*>(0x5BAEA2, entryPool + 1);
|
||||
}
|
||||
|
||||
void AssetHandler::ExposeTemporaryAssets(bool expose)
|
||||
{
|
||||
AssetHandler::ShouldSearchTempAssets = expose;
|
||||
}
|
||||
|
||||
AssetHandler::AssetHandler()
|
||||
{
|
||||
this->reallocateEntryPool();
|
||||
|
@ -39,8 +39,11 @@ namespace Components
|
||||
|
||||
static void ResetBypassState();
|
||||
|
||||
static void ExposeTemporaryAssets(bool expose);
|
||||
|
||||
private:
|
||||
static thread_local int BypassState;
|
||||
static bool ShouldSearchTempAssets;
|
||||
|
||||
static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];
|
||||
|
||||
@ -55,6 +58,7 @@ namespace Components
|
||||
static void RegisterInterface(IAsset* iAsset);
|
||||
|
||||
static Game::XAssetHeader FindAsset(Game::XAssetType type, const char* filename);
|
||||
static Game::XAssetHeader FindTemporaryAsset(Game::XAssetType type, const char* filename);
|
||||
static bool IsAssetEligible(Game::XAssetType type, Game::XAssetHeader* asset);
|
||||
static void FindAssetStub();
|
||||
static void AddAssetStub();
|
||||
|
@ -12,8 +12,12 @@ namespace Assets
|
||||
// let the function see temporary assets when calling DB_FindXAssetHeader during the loading function
|
||||
// otherwise it fails to link things properly
|
||||
Components::AssetHandler::ExposeTemporaryAssets(true);
|
||||
IWeapon::CurrentBuilder = builder;
|
||||
|
||||
header->data = Game::BG_LoadWeaponDef_LoadObj(name.data());
|
||||
|
||||
Components::AssetHandler::ExposeTemporaryAssets(false);
|
||||
IWeapon::CurrentBuilder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,7 +290,7 @@ namespace Assets
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer->saveMax();
|
||||
buffer->saveMax(sizeof(Game::snd_alias_list_t*));
|
||||
buffer->saveString(def->bounceSound[i]->aliasName);
|
||||
}
|
||||
|
||||
|
@ -701,9 +701,9 @@ namespace Components
|
||||
|
||||
if (zoneIndex > 0)
|
||||
{
|
||||
Game::DB_EnumXAssetEntries(type, [&](Game::XAssetEntry* entry)
|
||||
{
|
||||
if (!header.data && entry->zoneIndex == zoneIndex && Game::DB_GetXAssetName(&entry->asset) == name)
|
||||
Game::XAssetEntry* entry = Game::DB_FindXAssetEntry(type, name.data());
|
||||
|
||||
if (entry->zoneIndex == zoneIndex)
|
||||
{
|
||||
// Allocate an empty asset (filled with zeros)
|
||||
header.data = builder->getAllocator()->allocate(Game::DB_GetXAssetSizeHandlers[type]());
|
||||
@ -715,7 +715,6 @@ namespace Components
|
||||
// Set the name to the empty name
|
||||
Game::DB_SetXAssetNameHandlers[type](&header, builder->getAllocator()->duplicateString("," + name));
|
||||
}
|
||||
}, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user