[AssetHandler] Count bypass states

This commit is contained in:
momo5502 2017-02-13 22:24:31 +01:00
parent 4a70fbf4c4
commit 954cd227ce
2 changed files with 12 additions and 9 deletions

View File

@ -2,7 +2,7 @@
namespace Components namespace Components
{ {
thread_local bool AssetHandler::BypassState; thread_local int AssetHandler::BypassState = 0;
std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces; std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces;
std::map<Game::XAssetType, Utils::Slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks; std::map<Game::XAssetType, Utils::Slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks;
Utils::Signal<AssetHandler::RestrictCallback> AssetHandler::RestrictSignal; Utils::Signal<AssetHandler::RestrictCallback> AssetHandler::RestrictSignal;
@ -55,7 +55,7 @@ namespace Components
if (filename) if (filename)
{ {
// Allow call DB_FindXAssetHeader within the hook // Allow call DB_FindXAssetHeader within the hook
AssetHandler::BypassState = true; ++AssetHandler::BypassState;
if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end()) if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end())
{ {
@ -63,7 +63,7 @@ namespace Components
} }
// Disallow calling DB_FindXAssetHeader ;) // Disallow calling DB_FindXAssetHeader ;)
AssetHandler::BypassState = false; --AssetHandler::BypassState;
} }
return header; return header;
@ -71,7 +71,7 @@ namespace Components
int AssetHandler::HasThreadBypass() int AssetHandler::HasThreadBypass()
{ {
return AssetHandler::BypassState & 1; return AssetHandler::BypassState > 0;
} }
__declspec(naked) void AssetHandler::FindAssetStub() __declspec(naked) void AssetHandler::FindAssetStub()
@ -337,11 +337,14 @@ namespace Components
Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename) Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename)
{ {
int originalState = AssetHandler::HasThreadBypass(); ++AssetHandler::BypassState;
AssetHandler::BypassState = true;
Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename); Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename);
if (!originalState) AssetHandler::BypassState = false; --AssetHandler::BypassState;
if(AssetHandler::BypassState < 0)
{
Logger::Error("DB_FindXAssetHeader bypass state reached level below 0, what the fuck????");
}
return header; return header;
} }

View File

@ -42,7 +42,7 @@ namespace Components
static void StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset); static void StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset);
private: private:
static thread_local bool BypassState; static thread_local int BypassState;
static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT]; static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];