diff --git a/sfall/Modules/CRC.cpp b/sfall/Modules/CRC.cpp index 7aa0e66b..a2716fdf 100644 --- a/sfall/Modules/CRC.cpp +++ b/sfall/Modules/CRC.cpp @@ -77,7 +77,7 @@ void CRC(const char* filepath) { DWORD size = GetFileSize(h, 0), crc; bool sizeMatch = (size == ExpectedSize); - if (isDebug && !sizeMatch && GetPrivateProfileIntA("Debugging", "SkipSizeCheck", 0, ".\\ddraw.ini")) { + if (isDebug && !sizeMatch && GetPrivateProfileIntA("Debugging", "SkipSizeCheck", 0, ddrawIni)) { sizeMatch = true; } @@ -91,7 +91,7 @@ void CRC(const char* filepath) { bool matchedCRC = false; - if (isDebug && GetPrivateProfileStringA("Debugging", "ExtraCRC", "", buf, 512, ".\\ddraw.ini") > 0) { + if (isDebug && GetPrivateProfileStringA("Debugging", "ExtraCRC", "", buf, 512, ddrawIni) > 0) { char *TestCRC; TestCRC = strtok(buf, ","); while (TestCRC) { diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index 98223af8..f11a9435 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -33,6 +33,7 @@ #include "LoadGameHook.h" +Delegate<> LoadGameHook::onGameInit; Delegate<> LoadGameHook::onGameReset; Delegate<> LoadGameHook::onBeforeGameStart; Delegate<> LoadGameHook::onAfterGameStarted; @@ -43,6 +44,7 @@ static DWORD saveInCombatFix; static bool disableHorrigan = false; static bool pipBoyAvailableAtGameStart = false; static bool mapLoaded = false; +static bool gameLoaded = false; bool IsMapLoaded() { return mapLoaded; @@ -235,6 +237,11 @@ static void __declspec(naked) main_load_new_hook() { static void __stdcall MainMenuLoop() { mapLoaded = false; + if (!gameLoaded) { + gameLoaded = true; + // called only once + LoadGameHook::onGameInit.invoke(); + } } static void __declspec(naked) main_menu_loop_hook() { diff --git a/sfall/Modules/LoadGameHook.h b/sfall/Modules/LoadGameHook.h index 1be5ce75..d27283ec 100644 --- a/sfall/Modules/LoadGameHook.h +++ b/sfall/Modules/LoadGameHook.h @@ -26,6 +26,9 @@ class LoadGameHook : public Module { public: const char* name() { return "LoadGameHook"; } void init(); + + // Invoked when the game has initialized (game_init_ was called). + static Delegate<> onGameInit; // Invoked when game state is being reset (before loading a save, after quitting, etc.) static Delegate<> onGameReset; diff --git a/sfall/Modules/Message.cpp b/sfall/Modules/Message.cpp index e28c55f2..edb99892 100644 --- a/sfall/Modules/Message.cpp +++ b/sfall/Modules/Message.cpp @@ -21,6 +21,7 @@ #include "..\main.h" #include "..\FalloutEngine\Fallout2.h" +#include "LoadGameHook.h" #include "Message.h" @@ -61,32 +62,10 @@ char* GetMsg(MessageList *msgList, int msgRef, int msgNum) { } void ReadExtraGameMsgFiles() { - int read; - std::string names; - - names.resize(256); - - while ((read = GetPrivateProfileStringA("Misc", "ExtraGameMsgFileList", "", - (LPSTR)names.data(), names.size(), ".\\ddraw.ini")) == names.size() - 1) { - names.resize(names.size() + 256); - } - - if (names.empty()) { - return; - } - - names.resize(names.find_first_of('\0')); - names.append(","); - - int begin = 0; - int end; - int length; - - while ((end = names.find_first_of(',', begin)) != std::string::npos) { - length = end - begin; - - if (length > 0) { - std::string path = "game\\" + names.substr(begin, length) + ".msg"; + auto msgFileList = GetConfigList("Misc", "ExtraGameMsgFileList", "", 512); + if (msgFileList.size() > 0) { + for (auto& msgName : msgFileList) { + std::string path = "game\\" + msgName + ".msg"; MessageList* list = new MessageList(); if (Wrapper::message_load(list, (char*)path.data()) == 1) { gExtraGameMsgLists.insert(std::make_pair(0x2000 + gExtraGameMsgLists.size(), list)); @@ -94,8 +73,6 @@ void ReadExtraGameMsgFiles() { delete list; } } - - begin = end + 1; } } @@ -110,7 +87,7 @@ void ClearReadExtraGameMsgFiles() { } void Message::init() { - ReadExtraGameMsgFiles(); + LoadGameHook::onGameInit += ReadExtraGameMsgFiles; } void Message::exit() { diff --git a/sfall/Modules/Scripting/Opcodes.cpp b/sfall/Modules/Scripting/Opcodes.cpp index a2c97049..bb1dd29f 100644 --- a/sfall/Modules/Scripting/Opcodes.cpp +++ b/sfall/Modules/Scripting/Opcodes.cpp @@ -184,7 +184,7 @@ void __declspec(naked) defaultOpcodeHandler() { void InitNewOpcodes() { bool AllowUnsafeScripting = isDebug - && GetPrivateProfileIntA("Debugging", "AllowUnsafeScripting", 0, ".\\ddraw.ini") != 0; + && GetPrivateProfileIntA("Debugging", "AllowUnsafeScripting", 0, ddrawIni) != 0; dlogr("Adding additional opcodes", DL_SCRIPT); if (AllowUnsafeScripting) { diff --git a/sfall/main.cpp b/sfall/main.cpp index 2ba4abb6..3d134445 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -141,6 +141,7 @@ static void DllMain2() { manager.add(); manager.add(); manager.add(); + manager.add(); manager.add(); manager.add();