From 4f6b68ca93615d5035819aa78e7680cb003a208f Mon Sep 17 00:00:00 2001 From: Vennor Date: Sat, 2 Apr 2016 18:41:59 +0200 Subject: [PATCH 1/9] - Moved existing msg file reading functions and structs from HeroAppearance.cpp to a dedicated Message.h/.cpp file pair. - Added extern map to hold read extra msg files. --- sfall/HeroAppearance.cpp | 117 +-------------------------------------- sfall/Message.cpp | 95 +++++++++++++++++++++++++++++++ sfall/Message.h | 56 +++++++++++++++++++ 3 files changed, 152 insertions(+), 116 deletions(-) create mode 100644 sfall/Message.cpp create mode 100644 sfall/Message.h diff --git a/sfall/HeroAppearance.cpp b/sfall/HeroAppearance.cpp index 4fd8aa0d..bc33d69b 100644 --- a/sfall/HeroAppearance.cpp +++ b/sfall/HeroAppearance.cpp @@ -23,6 +23,7 @@ #include "FalloutEngine.h" #include "HeroAppearance.h" #include "ScriptExtender.h" +#include "Message.h" bool AppModEnabled=false; //check if Appearance mod enabled for script fuctions @@ -65,35 +66,6 @@ typedef struct LINENode { } LINENode; -//for holding a message -typedef struct MSGNode { - DWORD ref; - DWORD a; - char *msg1; //unused - char *msg2; - - MSGNode() { - ref=0; - a=0; - msg1=NULL; - msg2=NULL; - } -} MSGNode; - - -//for holding msg array -typedef struct MSGList { - long numMsgs; - void *MsgNodes; - - MSGList() { - MsgNodes=NULL; - numMsgs=0; - } -} MSGList; - - - //structures for holding frms loaded with fallout2 functions #pragma pack(2) typedef class FRMframe { @@ -333,93 +305,6 @@ int FWriteDword(void *FileStream, DWORD bVal) { } -/////////////////////////////////////////////////////////////////MESSAGE FUNCTIONS//////////////////////////////////////////////////////////////////////// - -//-------------------------------------------------- -int LoadMsgList(MSGList *MsgList, char *MsgFilePath) { - int retVal; - __asm { - mov edx, MsgFilePath - mov eax, MsgList - call message_load_ - mov retVal, eax - } - return retVal; -} - - -//----------------------------------------- -int DestroyMsgList(MSGList *MsgList) { - int retVal; - __asm { - mov eax, MsgList - call message_exit_ - mov retVal, eax - } - return retVal; -} - -/* -//----------------------------------------------------------- -bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef) { - bool retVal=FALSE; - MsgNode->ref=msgRef; - - __asm { - mov edx, MsgNode - mov eax, MsgList - call message_search_ - cmp eax, 1 - jne EndFunc - mov retVal, 1 -EndFunc: - } - return retVal; -} -*/ - - -//---------------------------------------------------- -MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef) { - - if (MsgList == NULL) return NULL; - if (MsgList->numMsgs <= 0) return NULL; - - MSGNode *MsgNode = (MSGNode*)MsgList->MsgNodes; - - long last = MsgList->numMsgs - 1; - long first = 0; - long mid; - - //Use Binary Search to find msg - while (first <= last) { - mid = (first + last) / 2; - if (msgRef > MsgNode[mid].ref) - first = mid + 1; - else if (msgRef < MsgNode[mid].ref) - last = mid - 1; - else - return &MsgNode[mid]; - } - - return NULL; -} - - -//-------------------------------------------------------- -char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum) { - MSGNode *MsgNode = GetMsgNode(MsgList, msgRef); - if (MsgNode) { - if (msgNum == 2) - return MsgNode->msg2; - else if (msgNum == 1) - return MsgNode->msg1; - } - return NULL; -} - - - /////////////////////////////////////////////////////////////////MOUSE FUNCTIONS//////////////////////////////////////////////////////////////////////// //----------------------------------------------------- //get current mouse pic ref diff --git a/sfall/Message.cpp b/sfall/Message.cpp new file mode 100644 index 00000000..844e02fd --- /dev/null +++ b/sfall/Message.cpp @@ -0,0 +1,95 @@ +/* + * sfall + * Copyright (C) 2009, 2010 Mash (Matt Wells, mashw at bigpond dot net dot au) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "Message.h" +#include "FalloutEngine.h" + +std::unordered_map gExtraGameMsgLists; + +int LoadMsgList(MSGList *MsgList, char *MsgFilePath) { + int retVal; + __asm { + mov edx, MsgFilePath + mov eax, MsgList + call message_load_ + mov retVal, eax + } + return retVal; +} + +int DestroyMsgList(MSGList *MsgList) { + int retVal; + __asm { + mov eax, MsgList + call message_exit_ + mov retVal, eax + } + return retVal; +} + +//bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef) { +// bool retVal=FALSE; +// MsgNode->ref=msgRef; +// +// __asm { +// mov edx, MsgNode +// mov eax, MsgList +// call message_search_ +// cmp eax, 1 +// jne EndFunc +// mov retVal, 1 +// EndFunc: +// } +// return retVal; +//} + +MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef) { + + if (MsgList == NULL) return NULL; + if (MsgList->numMsgs <= 0) return NULL; + + MSGNode *MsgNode = (MSGNode*)MsgList->MsgNodes; + + long last = MsgList->numMsgs - 1; + long first = 0; + long mid; + + //Use Binary Search to find msg + while (first <= last) { + mid = (first + last) / 2; + if (msgRef > MsgNode[mid].ref) + first = mid + 1; + else if (msgRef < MsgNode[mid].ref) + last = mid - 1; + else + return &MsgNode[mid]; + } + + return NULL; +} + +char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum) { + MSGNode *MsgNode = GetMsgNode(MsgList, msgRef); + if (MsgNode) { + if (msgNum == 2) + return MsgNode->msg2; + else if (msgNum == 1) + return MsgNode->msg1; + } + return NULL; +} diff --git a/sfall/Message.h b/sfall/Message.h new file mode 100644 index 00000000..076177b5 --- /dev/null +++ b/sfall/Message.h @@ -0,0 +1,56 @@ +/* +* sfall +* Copyright (C) 2008, 2009 The sfall team +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#pragma once + +#include +#include "main.h" + +//for holding a message +typedef struct MSGNode { + DWORD ref; + DWORD a; + char *msg1; //unused + char *msg2; + + MSGNode() { + ref = 0; + a = 0; + msg1 = NULL; + msg2 = NULL; + } +} MSGNode; + +//for holding msg array +typedef struct MSGList { + long numMsgs; + void *MsgNodes; + + MSGList() { + MsgNodes = NULL; + numMsgs = 0; + } +} MSGList; + +extern std::unordered_map gExtraGameMsgLists; + +int LoadMsgList(MSGList *MsgList, char *MsgFilePath); +int DestroyMsgList(MSGList *MsgList); +//bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef); +MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef); +char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum); From b8968c5334044feed6d874cf003fe64bbdf9ba21 Mon Sep 17 00:00:00 2001 From: Vennor Date: Sat, 2 Apr 2016 18:43:52 +0200 Subject: [PATCH 2/9] - Added extra msg file reading based on names given in ddraw.ini. - Added fetching strings from extra msg files. --- sfall/LoadGameHook.cpp | 42 +++++++++++++++++++++++++++++++++ sfall/ScriptOps/ScriptUtils.hpp | 16 +++++++++++++ sfall/main.cpp | 13 ++++++++++ 3 files changed, 71 insertions(+) diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index d0b079a5..de5df4d3 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -39,6 +39,7 @@ #include "sound.h" #include "SuperSave.h" #include "version.h" +#include "Message.h" #define MAX_GLOBAL_SIZE (MaxGlobalVars*12 + 4) @@ -276,6 +277,45 @@ end: retn; } } + +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"; + MSGList* list = new MSGList; + + if (LoadMsgList(list, (char*)path.data()) == 1) + gExtraGameMsgLists.insert(std::make_pair(0x2000 + gExtraGameMsgLists.size(), list)); + } + + begin = end + 1; + } +} + static void NewGame2() { ResetState(0); @@ -298,6 +338,8 @@ static void NewGame2() { *(DWORD*)0x00672E04=1; } + ReadExtraGameMsgFiles(); + LoadGlobalScripts(); CritLoad(); } diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index 2d626c36..7a4421d1 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -26,6 +26,7 @@ #include "ScriptArrays.hpp" #include "FileSystem.h" #include "Arrays.h" +#include "Message.h" static void __declspec(naked) funcSqrt() { __asm { @@ -870,6 +871,21 @@ static void _stdcall op_message_str_game2() { else if (fileId >= 0x1000 && fileId <= 0x1005) { // proto msg files msg = GetMessageStr((DWORD)&proto_msg_files[2*(fileId - 0x1000)], msgId); } + else if (fileId >= 0x2000) // Extra game message files. + { + std::unordered_map::iterator it + = gExtraGameMsgLists.find(fileId); + + if (it != gExtraGameMsgLists.end()) + { + msg = GetMsg(it->second, msgId, 2); + } + else + { + msg = 0; + SetOpReturn(0, DATATYPE_INT); + } + } if (msg != 0) SetOpReturn(msg); else diff --git a/sfall/main.cpp b/sfall/main.cpp index 395d5a1d..5d99beb2 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -59,6 +59,7 @@ #include "Tiles.h" #include "timer.h" #include "version.h" +#include "Message.h" bool IsDebug = false; @@ -1542,7 +1543,19 @@ static void DllMain2() { dlogr("Leave DllMain2", DL_MAIN); } +void ClearExtraGameMsgFiles() +{ + std::unordered_map::iterator it; + + for (it = gExtraGameMsgLists.begin(); it != gExtraGameMsgLists.end(); ++it) + { + DestroyMsgList(it->second); + delete it->second; + } +} + static void _stdcall OnExit() { + ClearExtraGameMsgFiles(); ConsoleExit(); AnimationsAtOnceExit(); HeroAppearanceModExit(); From f9dbbcdca2f80ba4d3e321e0c13adaab98fc0c2b Mon Sep 17 00:00:00 2001 From: Vennor Date: Sun, 8 May 2016 15:53:05 +0200 Subject: [PATCH 3/9] - Tidied up extra game message getter a bit. - Removed unnecessary function call. --- sfall/ScriptOps/ScriptUtils.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index 7a4421d1..4e99ac27 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -871,20 +871,13 @@ static void _stdcall op_message_str_game2() { else if (fileId >= 0x1000 && fileId <= 0x1005) { // proto msg files msg = GetMessageStr((DWORD)&proto_msg_files[2*(fileId - 0x1000)], msgId); } - else if (fileId >= 0x2000) // Extra game message files. - { - std::unordered_map::iterator it - = gExtraGameMsgLists.find(fileId); + else if (fileId >= 0x2000) { // Extra game message files. + std::unordered_map::iterator it = gExtraGameMsgLists.find(fileId); if (it != gExtraGameMsgLists.end()) - { msg = GetMsg(it->second, msgId, 2); - } else - { msg = 0; - SetOpReturn(0, DATATYPE_INT); - } } if (msg != 0) SetOpReturn(msg); From 07b7e270b83e2341f82ad676795ecef20d737e35 Mon Sep 17 00:00:00 2001 From: Vennor Date: Sun, 8 May 2016 16:11:51 +0200 Subject: [PATCH 4/9] - Encapsulated and moved ReadExtraGameMsgFiles function call from NewGame2 to MainMenu. --- sfall/LoadGameHook.cpp | 47 +++++++----------------------------------- sfall/Message.cpp | 40 +++++++++++++++++++++++++++++++++++ sfall/Message.h | 1 + 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index de5df4d3..60ce5202 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -278,44 +278,6 @@ end: } } -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"; - MSGList* list = new MSGList; - - if (LoadMsgList(list, (char*)path.data()) == 1) - gExtraGameMsgLists.insert(std::make_pair(0x2000 + gExtraGameMsgLists.size(), list)); - } - - begin = end + 1; - } -} - static void NewGame2() { ResetState(0); @@ -338,8 +300,6 @@ static void NewGame2() { *(DWORD*)0x00672E04=1; } - ReadExtraGameMsgFiles(); - LoadGlobalScripts(); CritLoad(); } @@ -353,11 +313,18 @@ static void __declspec(naked) NewGame() { } } +static void ReadExtraGameMsgFilesIfNeeded() +{ + if (gExtraGameMsgLists.empty()) + ReadExtraGameMsgFiles(); +} + static void __declspec(naked) MainMenu() { __asm { pushad; push 0; call ResetState; + call ReadExtraGameMsgFilesIfNeeded; call LoadHeroAppearance; popad; call main_menu_loop_; diff --git a/sfall/Message.cpp b/sfall/Message.cpp index 844e02fd..bc675187 100644 --- a/sfall/Message.cpp +++ b/sfall/Message.cpp @@ -93,3 +93,43 @@ char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum) { } return NULL; } + +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"; + MSGList* list = new MSGList; + + if (LoadMsgList(list, (char*)path.data()) == 1) + gExtraGameMsgLists.insert(std::make_pair(0x2000 + gExtraGameMsgLists.size(), list)); + else + delete list; + } + + begin = end + 1; + } +} diff --git a/sfall/Message.h b/sfall/Message.h index 076177b5..cf86f4e8 100644 --- a/sfall/Message.h +++ b/sfall/Message.h @@ -54,3 +54,4 @@ int DestroyMsgList(MSGList *MsgList); //bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef); MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef); char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum); +void ReadExtraGameMsgFiles(); \ No newline at end of file From 9bd03bfb76da54402f10ebf9842bf3adabf9a95b Mon Sep 17 00:00:00 2001 From: Vennor Date: Sun, 8 May 2016 20:09:56 +0200 Subject: [PATCH 5/9] Changed std::unordered_map to std::tr1::unordered_map for compatibility with older compilers. --- sfall/Message.cpp | 2 +- sfall/Message.h | 2 +- sfall/ScriptOps/ScriptUtils.hpp | 2 +- sfall/main.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sfall/Message.cpp b/sfall/Message.cpp index bc675187..3f50cd45 100644 --- a/sfall/Message.cpp +++ b/sfall/Message.cpp @@ -19,7 +19,7 @@ #include "Message.h" #include "FalloutEngine.h" -std::unordered_map gExtraGameMsgLists; +std::tr1::unordered_map gExtraGameMsgLists; int LoadMsgList(MSGList *MsgList, char *MsgFilePath) { int retVal; diff --git a/sfall/Message.h b/sfall/Message.h index cf86f4e8..d2964cc8 100644 --- a/sfall/Message.h +++ b/sfall/Message.h @@ -47,7 +47,7 @@ typedef struct MSGList { } } MSGList; -extern std::unordered_map gExtraGameMsgLists; +extern std::tr1::unordered_map gExtraGameMsgLists; int LoadMsgList(MSGList *MsgList, char *MsgFilePath); int DestroyMsgList(MSGList *MsgList); diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index 4e99ac27..a230a2cb 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -872,7 +872,7 @@ static void _stdcall op_message_str_game2() { msg = GetMessageStr((DWORD)&proto_msg_files[2*(fileId - 0x1000)], msgId); } else if (fileId >= 0x2000) { // Extra game message files. - std::unordered_map::iterator it = gExtraGameMsgLists.find(fileId); + std::tr1::unordered_map::iterator it = gExtraGameMsgLists.find(fileId); if (it != gExtraGameMsgLists.end()) msg = GetMsg(it->second, msgId, 2); diff --git a/sfall/main.cpp b/sfall/main.cpp index 5d99beb2..52bb5101 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -1545,7 +1545,7 @@ static void DllMain2() { void ClearExtraGameMsgFiles() { - std::unordered_map::iterator it; + std::tr1::unordered_map::iterator it; for (it = gExtraGameMsgLists.begin(); it != gExtraGameMsgLists.end(); ++it) { From 5ca7ed0dc52c61f6ee493260515c72532967d2a8 Mon Sep 17 00:00:00 2001 From: Vennor Date: Sun, 8 May 2016 20:13:13 +0200 Subject: [PATCH 6/9] - Renamed ClearExtraGameMsgFiles function to ClearReadExtraGameMsgFiles. - Moved ClearReadExtraGameMsgFiles function to Message.cpp. - Added map clearing to ClearReadExtraGameMsgFiles. - Changed formatting. --- sfall/Message.cpp | 20 ++++++++++++++------ sfall/Message.h | 3 ++- sfall/main.cpp | 13 +------------ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/sfall/Message.cpp b/sfall/Message.cpp index 3f50cd45..42a65b5b 100644 --- a/sfall/Message.cpp +++ b/sfall/Message.cpp @@ -94,8 +94,7 @@ char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum) { return NULL; } -void ReadExtraGameMsgFiles() -{ +void ReadExtraGameMsgFiles() { int read; std::string names; @@ -115,12 +114,10 @@ void ReadExtraGameMsgFiles() int end; int length; - while ((end = names.find_first_of(',', begin)) != std::string::npos) - { + while ((end = names.find_first_of(',', begin)) != std::string::npos) { length = end - begin; - if (length > 0) - { + if (length > 0) { std::string path = "game\\" + names.substr(begin, length) + ".msg"; MSGList* list = new MSGList; @@ -133,3 +130,14 @@ void ReadExtraGameMsgFiles() begin = end + 1; } } + +void ClearReadExtraGameMsgFiles() { + std::tr1::unordered_map::iterator it; + + for (it = gExtraGameMsgLists.begin(); it != gExtraGameMsgLists.end(); ++it) { + DestroyMsgList(it->second); + delete it->second; + } + + gExtraGameMsgLists.clear(); +} \ No newline at end of file diff --git a/sfall/Message.h b/sfall/Message.h index d2964cc8..2e70cb09 100644 --- a/sfall/Message.h +++ b/sfall/Message.h @@ -54,4 +54,5 @@ int DestroyMsgList(MSGList *MsgList); //bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef); MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef); char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum); -void ReadExtraGameMsgFiles(); \ No newline at end of file +void ReadExtraGameMsgFiles(); +void ClearReadExtraGameMsgFiles(); \ No newline at end of file diff --git a/sfall/main.cpp b/sfall/main.cpp index 52bb5101..65a78df0 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -1543,19 +1543,8 @@ static void DllMain2() { dlogr("Leave DllMain2", DL_MAIN); } -void ClearExtraGameMsgFiles() -{ - std::tr1::unordered_map::iterator it; - - for (it = gExtraGameMsgLists.begin(); it != gExtraGameMsgLists.end(); ++it) - { - DestroyMsgList(it->second); - delete it->second; - } -} - static void _stdcall OnExit() { - ClearExtraGameMsgFiles(); + ClearReadExtraGameMsgFiles(); ConsoleExit(); AnimationsAtOnceExit(); HeroAppearanceModExit(); From 90b718122dc37f1c420becbe13ea524a5c569496 Mon Sep 17 00:00:00 2001 From: Vennor Date: Sun, 8 May 2016 20:15:37 +0200 Subject: [PATCH 7/9] Added string header inclusion to Message.cpp. --- sfall/Message.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sfall/Message.cpp b/sfall/Message.cpp index 42a65b5b..81be6e2e 100644 --- a/sfall/Message.cpp +++ b/sfall/Message.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #include "Message.h" #include "FalloutEngine.h" From 2330dd97bb8c5561dc547fce3f8cc55a162e552f Mon Sep 17 00:00:00 2001 From: Vennor Date: Mon, 9 May 2016 19:10:25 +0200 Subject: [PATCH 8/9] Refactored op_message_str_game2 function to always return a valid string value. Now an "Error" string will be returned on error instead of an uninitialized char pointer or an integer value. --- sfall/ScriptOps/ScriptUtils.hpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sfall/ScriptOps/ScriptUtils.hpp b/sfall/ScriptOps/ScriptUtils.hpp index a230a2cb..023a4b45 100644 --- a/sfall/ScriptOps/ScriptUtils.hpp +++ b/sfall/ScriptOps/ScriptUtils.hpp @@ -862,9 +862,10 @@ static const DWORD* proto_msg_files = (DWORD*)0x006647AC; static void _stdcall op_message_str_game2() { DWORD fileId = opArgs[0]; + const char* msg = 0; + if (IsOpArgInt(0) && IsOpArgInt(1)) { int msgId = GetOpArgInt(1); - const char* msg; if (fileId < 20) { // main msg files msg = GetMessageStr(game_msg_files[fileId], msgId); } @@ -876,16 +877,13 @@ static void _stdcall op_message_str_game2() { if (it != gExtraGameMsgLists.end()) msg = GetMsg(it->second, msgId, 2); - else - msg = 0; } - if (msg != 0) - SetOpReturn(msg); - else - SetOpReturn(0, DATATYPE_INT); - } else { - SetOpReturn(0, DATATYPE_INT); } + + if (msg == 0) + msg = "Error"; + + SetOpReturn(msg); } static void __declspec(naked) op_message_str_game() { From c3e489424351eadbc1d5f36772da89b586872eb9 Mon Sep 17 00:00:00 2001 From: Vennor Date: Mon, 9 May 2016 19:34:07 +0200 Subject: [PATCH 9/9] Moved opening brace to the same line as the function prototype. --- sfall/LoadGameHook.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index 60ce5202..a20e1858 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -313,8 +313,7 @@ static void __declspec(naked) NewGame() { } } -static void ReadExtraGameMsgFilesIfNeeded() -{ +static void ReadExtraGameMsgFilesIfNeeded() { if (gExtraGameMsgLists.empty()) ReadExtraGameMsgFiles(); }