From dcd46633ca0a562bfcb2b87f3e290e3269679bf1 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 3 Feb 2016 22:01:10 +0100 Subject: [PATCH] Check if zone is loaded. --- src/Components/Modules/ZoneBuilder.cpp | 15 ++++++--------- src/Game/Functions.cpp | 19 +++++++++++++++++++ src/Game/Functions.hpp | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 23c30ea5..f59d2dba 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -60,15 +60,14 @@ namespace Components void ZoneBuilder::Zone::LoadFastFiles() { Logger::Print("Loading required FastFiles...\n"); + for (int i = 0; i < DataMap.GetRows(); ++i) { if (DataMap.GetElementAt(i, 0) == "require") { std::string fastfile = DataMap.GetElementAt(i, 1); - //Logger::Print("Loading '%s'...\n", fastfile.c_str()); - - //if (!DB_IsZoneLoaded(fastfile.c_str())) + if (!Game::DB_IsZoneLoaded(fastfile.c_str())) { Game::XZoneInfo info; info.name = fastfile.data(); @@ -76,13 +75,11 @@ namespace Components info.freeFlags = 0; Game::DB_LoadXAssets(&info, 1, true); - - //LoadFastFile(fastfile.c_str(), true); } -// else -// { -// Logger::Print("Zone '%s' already loaded\n", fastfile.c_str()); -// } + else + { + Logger::Print("Zone '%s' already loaded\n", fastfile.c_str()); + } } } } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index d83c491d..babadbbc 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -264,6 +264,25 @@ namespace Game return ASSET_TYPE_INVALID; } + bool DB_IsZoneLoaded(const char* zone) + { + int zoneCount = Utils::Hook::Get(0x1261BCC); + char* zoneIndices = reinterpret_cast(0x16B8A34); + char* zoneData = reinterpret_cast(0x14C0F80); + + for (int i = 0; i < zoneCount; i++) + { + std::string name = zoneData + 4 + 0xA4 * (zoneIndices[i] & 0xFF); + + if (name == zone) + { + return true; + } + } + + return false; + } + void MessageBox(std::string message, std::string title) { SetConsole("com_errorMessage", message.data()); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index f64b97f2..4cf0667a 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -362,6 +362,7 @@ namespace Game const char *DB_GetXAssetName(XAsset *asset); XAssetType DB_GetXAssetNameType(const char* name); + bool DB_IsZoneLoaded(const char* zone); void MessageBox(std::string message, std::string title);