Moved INI reading functions from main.cpp to IniReader.cpp

This commit is contained in:
NovaRain
2021-03-13 13:47:27 +08:00
parent 21ff9238a0
commit e99fe09137
18 changed files with 259 additions and 159 deletions
+2 -2
View File
@@ -83,7 +83,7 @@ void CRC(const char* filepath) {
DWORD size = GetFileSize(h, 0), crc;
bool sizeMatch = (size == ExpectedSize);
if (!sizeMatch && iniGetInt("Debugging", "SkipSizeCheck", 0, ::sfall::ddrawIni)) {
if (!sizeMatch && IniReader::GetIntDefaultConfig("Debugging", "SkipSizeCheck", 0)) {
sizeMatch = true;
}
@@ -99,7 +99,7 @@ void CRC(const char* filepath) {
bool matchedCRC = false;
auto extraCrcList = GetIniList("Debugging", "ExtraCRC", "", 512, ',', ::sfall::ddrawIni);
auto extraCrcList = IniReader::GetListDefaultConfig("Debugging", "ExtraCRC", "", 512, ',');
if (!extraCrcList.empty()) {
matchedCRC = std::any_of(extraCrcList.begin(), extraCrcList.end(), [crc](const std::string& testCrcStr) {
auto testedCrc = strtoul(testCrcStr.c_str(), 0, 16);
+2 -2
View File
@@ -41,7 +41,7 @@ static std::vector<HackPair> hackAddr = {
{0x4C06D1, 5},
// module: AI
{0x4290B6, 5},
//{0x4290B6, 5},
// module: BarBoxes
{0x461342, 5}, {0x461243, 5},
{0x461493, 5}, //{0x461495, 1},
@@ -128,7 +128,7 @@ static std::vector<HackPair> hackAddr = {
// Checking for conflicts requires all options in ddraw.ini to be enabled
void PrintAddrList() {
long level = iniGetInt("Debugging", "Enable", 0, ::sfall::ddrawIni);
long level = IniReader::GetIntDefaultConfig("Debugging", "Enable", 0);
if (level < 10) hackAddr.clear();
std::vector<HackPair> sortAddr(hackAddr);
+123
View File
@@ -0,0 +1,123 @@
/*
* sfall
* Copyright (C) 2008-2021 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 <http://www.gnu.org/licenses/>.
*/
#include "Utils.h"
#include "IniReader.h"
namespace sfall
{
DWORD IniReader::modifiedIni;
static const char* ddrawIni = ".\\ddraw.ini";
static char ini[65] = ".\\";
static char translationIni[65];
const char* IniReader::GetConfigFile() {
return ini;
}
void IniReader::SetDefaultConfigFile() {
std::strcpy(&ini[2], &ddrawIni[2]);
}
void IniReader::SetConfigFile(const char* iniFile) {
strcat_s(ini, iniFile);
}
int IniReader::GetIntDefaultConfig(const char* section, const char* setting, int defaultValue) {
return iniGetInt(section, setting, defaultValue, ddrawIni);
}
std::vector<std::string> IniReader::GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter) {
return GetIniList(section, setting, defaultValue, bufSize, delimiter, ddrawIni);
}
size_t IniReader::Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize) {
return iniGetString(section, setting, defaultValue, buffer, bufSize, translationIni);
}
int IniReader::SetConfigInt(const char* section, const char* setting, int value) {
char buf[33];
_itoa_s(value, buf, 33, 10);
int result = WritePrivateProfileStringA(section, setting, buf, ini);
return result;
}
////////////////////////////////////////////////////////////////////////////////
int iniGetInt(const char* section, const char* setting, int defaultValue, const char* iniFile) {
return GetPrivateProfileIntA(section, setting, defaultValue, iniFile);
}
size_t iniGetString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize, const char* iniFile) {
return GetPrivateProfileStringA(section, setting, defaultValue, buf, bufSize, iniFile);
}
std::string GetIniString(const char* section, const char* setting, const char* defaultValue, size_t bufSize, const char* iniFile) {
char* buf = new char[bufSize];
iniGetString(section, setting, defaultValue, buf, bufSize, iniFile);
std::string str(buf);
delete[] buf;
return str;
}
std::vector<std::string> GetIniList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile) {
auto list = split(GetIniString(section, setting, defaultValue, bufSize, iniFile), delimiter);
std::transform(list.cbegin(), list.cend(), list.begin(), trim);
return list;
}
/*
For ddraw.ini config
*/
unsigned int GetConfigInt(const char* section, const char* setting, int defaultValue) {
return iniGetInt(section, setting, defaultValue, ini);
}
std::string GetConfigString(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return trim(GetIniString(section, setting, defaultValue, bufSize, ini));
}
size_t GetConfigString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize) {
return iniGetString(section, setting, defaultValue, buf, bufSize, ini);
}
std::vector<std::string> GetConfigList(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return GetIniList(section, setting, defaultValue, bufSize, ',', ini);
}
std::vector<std::string> TranslateList(const char* section, const char* setting, const char* defaultValue, char delimiter, size_t bufSize) {
return GetIniList(section, setting, defaultValue, bufSize, delimiter, translationIni);
}
std::string Translate(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return GetIniString(section, setting, defaultValue, bufSize, translationIni);
}
size_t Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize) {
return iniGetString(section, setting, defaultValue, buffer, bufSize, translationIni);
}
void IniReader::init() {
modifiedIni = GetConfigInt("Main", "ModifiedIni", 0);
GetConfigString("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65);
}
}
+78
View File
@@ -0,0 +1,78 @@
/*
* sfall
* Copyright (C) 2008-2021 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace sfall
{
class IniReader {
public:
static void init();
static DWORD IniReader::modifiedIni;
static void IniReader::SetDefaultConfigFile();
static void IniReader::SetConfigFile(const char* iniFile);
static const char* IniReader::GetConfigFile();
// Gets the integer value from the default config (i.e. ddraw.ini)
static int IniReader::GetIntDefaultConfig(const char* section, const char* setting, int defaultValue);
// Gets a list of values separated by the delimiter from the default config (i.e. ddraw.ini)
static std::vector<std::string> IniReader::GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter);
// Translates given string using sfall translation INI file and puts the result into given buffer
static size_t IniReader::Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize);
static int IniReader::SetConfigInt(const char* section, const char* setting, int value);
};
// Gets the integer value from given INI file
int iniGetInt(const char* section, const char* setting, int defaultValue, const char* iniFile);
// Gets the string value from given INI file
size_t iniGetString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize, const char* iniFile);
// Gets the string value from given INI file
std::string GetIniString(const char* section, const char* setting, const char* defaultValue, size_t bufSize, const char* iniFile);
// Parses the comma-separated list setting from given INI file
std::vector<std::string> GetIniList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile);
// Gets the integer value from sfall configuration INI file
unsigned int GetConfigInt(const char* section, const char* setting, int defaultValue);
// Gets the string value from sfall configuration INI file with trim function
std::string GetConfigString(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
// Loads the string value from sfall configuration INI file into the provided buffer
size_t GetConfigString(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize = 128);
// Parses the comma-separated list from the settings from sfall configuration INI file
std::vector<std::string> GetConfigList(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
std::vector<std::string> TranslateList(const char* section, const char* setting, const char* defaultValue, char delimiter, size_t bufSize = 256);
// Translates given string using sfall translation INI file
std::string Translate(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
// Translates given string using sfall translation INI file and puts the result into given buffer
size_t Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize = 128);
}
+4 -4
View File
@@ -74,16 +74,16 @@ void devlog_f(...) {}
void LoggingInit() {
Log.open("sfall-log.txt", std::ios_base::out | std::ios_base::trunc);
if (iniGetInt("Debugging", "Init", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "Init", 0)) {
DebugTypes |= DL_INIT;
}
if (iniGetInt("Debugging", "Hook", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "Hook", 0)) {
DebugTypes |= DL_HOOK;
}
if (iniGetInt("Debugging", "Script", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "Script", 0)) {
DebugTypes |= DL_SCRIPT;
}
if (iniGetInt("Debugging", "Criticals", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "Criticals", 0)) {
DebugTypes |= DL_CRITICALS;
}
}
+1 -1
View File
@@ -544,7 +544,7 @@ void AI::init() {
}
#ifndef NDEBUG
if (iniGetInt("Debugging", "AIBugFixes", 1, ::sfall::ddrawIni) == 0) return;
if (IniReader::GetIntDefaultConfig("Debugging", "AIBugFixes", 1) == 0) return;
#endif
// Fix for NPCs not fully reloading a weapon if it has an ammo capacity more than a box of ammo
+26 -27
View File
@@ -18,7 +18,7 @@ static DWORD critterBody = 0;
static DWORD sizeOnBody = 0;
static DWORD weightOnBody = 0;
static char tempBuffer[355];
static char messageBuffer[355];
/*
Saving a list of PIDs for saved drug effects
@@ -1594,27 +1594,27 @@ static bool showItemDescription = false;
static void __stdcall AppendText(const char* text, const char* desc) {
if (showItemDescription && currDescLen == 0) {
strncpy_s(tempBuffer, desc, 161);
int len = strlen(tempBuffer);
strncpy_s(messageBuffer, desc, 161);
int len = strlen(messageBuffer);
if (len > 160) {
len = 158;
tempBuffer[len++] = '.';
tempBuffer[len++] = '.';
tempBuffer[len++] = '.';
messageBuffer[len++] = '.';
messageBuffer[len++] = '.';
messageBuffer[len++] = '.';
}
tempBuffer[len++] = ' ';
tempBuffer[len] = 0;
messageBuffer[len++] = ' ';
messageBuffer[len] = 0;
currDescLen = len;
} else if (currDescLen == 0) {
tempBuffer[0] = 0;
messageBuffer[0] = 0;
}
strncat(tempBuffer, text, 64);
strncat(messageBuffer, text, 64);
currDescLen += strlen(text);
if (currDescLen < 300) {
tempBuffer[currDescLen++] = '.';
tempBuffer[currDescLen++] = ' ';
tempBuffer[currDescLen] = 0;
messageBuffer[currDescLen++] = '.';
messageBuffer[currDescLen++] = ' ';
messageBuffer[currDescLen] = 0;
}
}
@@ -1639,7 +1639,7 @@ static void __declspec(naked) obj_examine_func_hack_ammo1() {
push eax;
call AppendText;
mov currDescLen, 0;
lea eax, [tempBuffer];
lea eax, [messageBuffer];
jmp fo::funcoffs::gdialogDisplayMsg_;
skip:
jmp dword ptr [esp + 0x1AC - 0x14 + 4];
@@ -1656,9 +1656,9 @@ static void __declspec(naked) obj_examine_func_hack_weapon() {
call AppendText;
mov eax, currDescLen;
sub eax, 2;
mov byte ptr tempBuffer[eax], 0; // cutoff last character
mov byte ptr messageBuffer[eax], 0; // cutoff last character
mov currDescLen, 0;
lea eax, [tempBuffer];
lea eax, [messageBuffer];
skip:
jmp ObjExamineFuncWeapon_Ret;
}
@@ -1762,7 +1762,7 @@ static void __declspec(naked) wmSetupRandomEncounter_hook() {
push eax; // text 2
push edi; // text 1
push 0x500B64; // fmt '%s %s'
lea edi, tempBuffer;
lea edi, messageBuffer;
push edi; // buf
call fo::funcoffs::sprintf_;
add esp, 16;
@@ -2289,13 +2289,11 @@ dude:
}
}
static char pickupMessageBuf[65] = {0};
static char pickupMessage[65] = {0};
static const char* __fastcall GetPickupMessage(const char* name) {
if (pickupMessageBuf[0] == 0) {
Translate("sfall", "NPCPickupFail", "%s cannot pick up the item.", pickupMessageBuf, 64);
}
sprintf(tempBuffer, pickupMessageBuf, name);
return tempBuffer;
std::sprintf(messageBuffer, pickupMessage, name);
return messageBuffer;
}
static void __declspec(naked) obj_pickup_hook_message() {
@@ -2703,11 +2701,11 @@ skip0:
call fo::funcoffs::item_caps_total_;
push eax; // caps
push 0x502B1C; // fmt: $%d
lea eax, tempBuffer;
lea eax, messageBuffer;
push eax;
call fo::funcoffs::sprintf_;
add esp, 3 * 4;
lea eax, tempBuffer;
lea eax, messageBuffer;
call ds:[FO_VAR_text_width];
mov edx, 60; // max width
mov ebx, eax; // ebx - textWidth
@@ -2721,7 +2719,7 @@ skip0:
push 36; // y
sar eax, 1;
sub ecx, eax; // x shift
lea edx, tempBuffer;
lea edx, messageBuffer;
mov eax, ds:[FO_VAR_dialogueWindow];
call fo::funcoffs::win_print_;
test ebp, ebp;
@@ -2887,7 +2885,7 @@ void BugFixes::init()
{
#ifndef NDEBUG
LoadGameHook::OnBeforeGameClose() += PrintAddrList;
if (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0) return;
if (IniReader::GetIntDefaultConfig("Debugging", "BugFixes", 1) == 0) return;
#endif
// Missing game initialization
@@ -3495,6 +3493,7 @@ void BugFixes::init()
// up an item due to not enough space in the inventory
HookCall(0x49B6E7, obj_pickup_hook);
HookCall(0x49B71C, obj_pickup_hook_message);
IniReader::Translate("sfall", "NPCPickupFail", "%s cannot pick up the item.", pickupMessage, 64);
// Fix for anim_move_to_tile_ engine function ignoring the distance argument for the player
HookCall(0x416D44, anim_move_to_tile_hook);
+3 -3
View File
@@ -405,7 +405,7 @@ static const DWORD addrNewLineChar[] = {
};
static void DebugModePatch() {
int dbgMode = iniGetInt("Debugging", "DebugMode", 0, ::sfall::ddrawIni);
int dbgMode = IniReader::GetIntDefaultConfig("Debugging", "DebugMode", 0);
if (dbgMode > 0) {
dlog("Applying debugmode patch.", DL_INIT);
// If the player is using an exe with the debug patch already applied, just skip this block without erroring
@@ -427,7 +427,7 @@ static void DebugModePatch() {
} else {
SafeWrite32(0x4C6D9C, (DWORD)debugGnw);
}
if (iniGetInt("Debugging", "HideObjIsNullMsg", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "HideObjIsNullMsg", 0)) {
MakeJump(0x453FD2, dbg_error_hack);
}
// prints a debug message about a missing critter art file to both debug.log and the message window in sfall debugging mode
@@ -462,7 +462,7 @@ static void DebugModePatch() {
}
static void DontDeleteProtosPatch() {
if (iniGetInt("Debugging", "DontDeleteProtos", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Debugging", "DontDeleteProtos", 0)) {
dlog("Applying permanent protos patch.", DL_INIT);
SafeWrite8(0x48007E, CodeType::JumpShort);
dlogr(" Done", DL_INIT);
+1 -1
View File
@@ -1216,7 +1216,7 @@ void Graphics::exit() {
if (Graphics::mode) {
if (Graphics::mode == 5) {
int data = windowTop | (windowLeft << 16);
if (data >= 0 && data != windowData) SetConfigInt("Graphics", "WindowData", data);
if (data >= 0 && data != windowData) IniReader::SetConfigInt("Graphics", "WindowData", data);
}
CoUninitialize();
}
+1 -1
View File
@@ -255,7 +255,7 @@ void HookScripts::init() {
LoadGameHook::OnGameModeChange() += HookCommon::GameModeChangeHook;
LoadGameHook::OnAfterGameStarted() += SourceUseSkillOnInit;
injectAllHooks = isDebug && (iniGetInt("Debugging", "InjectAllGameHooks", 0, ::sfall::ddrawIni) != 0);
injectAllHooks = isDebug && (IniReader::GetIntDefaultConfig("Debugging", "InjectAllGameHooks", 0) != 0);
if (injectAllHooks) dlogr("Injecting all game hooks.", DL_HOOK|DL_INIT);
}
+1 -1
View File
@@ -943,7 +943,7 @@ void ScriptExtender::init() {
}
}
alwaysFindScripts = isDebug && (iniGetInt("Debugging", "AlwaysFindScripts", 0, ::sfall::ddrawIni) != 0);
alwaysFindScripts = isDebug && (IniReader::GetIntDefaultConfig("Debugging", "AlwaysFindScripts", 0) != 0);
if (alwaysFindScripts) dlogr("Always searching for global/hook scripts behavior enabled.", DL_SCRIPT);
MakeJump(0x4A390C, scr_find_sid_from_program_hack);
+2 -2
View File
@@ -101,7 +101,7 @@ void __declspec(naked) op_eax_available() {
}
static bool IsSpecialIni(const char* str, const char* end) {
const char* pos = strfind(str, &::sfall::ddrawIni[2]);
const char* pos = strfind(str, &IniReader::GetConfigFile()[2]); // TODO test
if (pos && pos < end) return true;
pos = strfind(str, "f2_res.ini");
if (pos && pos < end) return true;
@@ -345,7 +345,7 @@ fail:
void __declspec(naked) op_modified_ini() {
__asm {
mov edx, modifiedIni;
mov edx, IniReader::modifiedIni;
_J_RET_VAL_TYPE(VAR_TYPE_INT);
}
}
+1 -1
View File
@@ -289,7 +289,7 @@ void InitNewOpcodes() {
ForceEncounterRestore(); // restore if the encounter did not happen
};
if (int unsafe = iniGetInt("Debugging", "AllowUnsafeScripting", 0, ::sfall::ddrawIni)) {
if (int unsafe = IniReader::GetIntDefaultConfig("Debugging", "AllowUnsafeScripting", 0)) {
if (unsafe == 2) checkValidMemAddr = false;
dlogr(" Unsafe opcodes enabled.", DL_SCRIPT);
opcodes[0x1cf] = op_write_byte;
+1 -1
View File
@@ -1008,7 +1008,7 @@ void Sound::init() {
HookCall(0x42B849, ai_print_msg_hook);
//Yes, I did leave this in on purpose. Will be of use to anyone trying to add in the sound effects
if (isDebug && iniGetInt("Debugging", "Test_ForceFloats", 0, ::sfall::ddrawIni)) {
if (isDebug && IniReader::GetIntDefaultConfig("Debugging", "Test_ForceFloats", 0)) {
SafeWrite8(0x42B6F5, CodeType::JumpShort); // bypass chance
}
}
+2
View File
@@ -297,6 +297,7 @@
<ClInclude Include="Game\render.h" />
<ClInclude Include="Game\skills.h" />
<ClInclude Include="Game\stats.h" />
<ClInclude Include="IniReader.h" />
<ClInclude Include="Modules\CritterPoison.h" />
<ClInclude Include="Modules\CritterStats.h" />
<ClInclude Include="Modules\Interface.h" />
@@ -405,6 +406,7 @@
<ClCompile Include="Game\render.cpp" />
<ClCompile Include="Game\skills.cpp" />
<ClCompile Include="Game\stats.cpp" />
<ClCompile Include="IniReader.cpp" />
<ClCompile Include="Modules\CritterPoison.cpp" />
<ClCompile Include="Modules\CritterStats.cpp" />
<ClCompile Include="Modules\Interface.cpp" />
+2
View File
@@ -338,6 +338,7 @@
<ClInclude Include="Modules\Scripting\Handlers\Combat.h">
<Filter>Modules\Scripting\Handlers</Filter>
</ClInclude>
<ClInclude Include="IniReader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
@@ -626,6 +627,7 @@
<ClCompile Include="Modules\Scripting\Handlers\Combat.cpp">
<Filter>Modules\Scripting\Handlers</Filter>
</ClCompile>
<ClCompile Include="IniReader.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc" />
+7 -75
View File
@@ -83,7 +83,6 @@
#include "SimplePatch.h"
#include "Logging.h"
#include "ReplacementFuncs.h"
#include "Utils.h"
#include "Version.h"
#include "main.h"
@@ -98,78 +97,12 @@ bool isDebug = false;
bool hrpIsEnabled = false;
bool hrpVersionValid = false; // HRP 4.1.8 version validation
const char ddrawIni[] = ".\\ddraw.ini";
static char ini[65] = ".\\";
static char translationIni[65];
DWORD modifiedIni;
DWORD hrpDLLBaseAddr = 0x10000000;
DWORD HRPAddress(DWORD addr) {
return (hrpDLLBaseAddr + (addr & 0xFFFFF));
}
int iniGetInt(const char* section, const char* setting, int defaultValue, const char* iniFile) {
return GetPrivateProfileIntA(section, setting, defaultValue, iniFile);
}
size_t iniGetString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize, const char* iniFile) {
return GetPrivateProfileStringA(section, setting, defaultValue, buf, bufSize, iniFile);
}
std::string GetIniString(const char* section, const char* setting, const char* defaultValue, size_t bufSize, const char* iniFile) {
char* buf = new char[bufSize];
iniGetString(section, setting, defaultValue, buf, bufSize, iniFile);
std::string str(buf);
delete[] buf;
return str;
}
std::vector<std::string> GetIniList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile) {
auto list = split(GetIniString(section, setting, defaultValue, bufSize, iniFile), delimiter);
std::transform(list.cbegin(), list.cend(), list.begin(), trim);
return list;
}
/*
For ddraw.ini config
*/
unsigned int GetConfigInt(const char* section, const char* setting, int defaultValue) {
return iniGetInt(section, setting, defaultValue, ini);
}
std::string GetConfigString(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return trim(GetIniString(section, setting, defaultValue, bufSize, ini));
}
size_t GetConfigString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize) {
return iniGetString(section, setting, defaultValue, buf, bufSize, ini);
}
std::vector<std::string> GetConfigList(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return GetIniList(section, setting, defaultValue, bufSize, ',', ini);
}
std::vector<std::string> TranslateList(const char* section, const char* setting, const char* defaultValue, char delimiter, size_t bufSize) {
return GetIniList(section, setting, defaultValue, bufSize, delimiter, translationIni);
}
std::string Translate(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return GetIniString(section, setting, defaultValue, bufSize, translationIni);
}
size_t Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize) {
return iniGetString(section, setting, defaultValue, buffer, bufSize, translationIni);
}
int SetConfigInt(const char* section, const char* setting, int value) {
char* buf = new char[33];
_itoa_s(value, buf, 33, 10);
int result = WritePrivateProfileStringA(section, setting, buf, ini);
delete[] buf;
return result;
}
void InitReplacementHacks() {
game::Inventory::init();
game::Items::init();
@@ -280,7 +213,7 @@ static void CompatModeCheck(HKEY root, const char* filepath, int extra) {
inline void SfallInit() {
// enabling debugging features
isDebug = (iniGetInt("Debugging", "Enable", 0, ::sfall::ddrawIni) != 0);
isDebug = (IniReader::GetIntDefaultConfig("Debugging", "Enable", 0) != 0);
if (isDebug) {
LoggingInit();
if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n", DL_MAIN);
@@ -291,7 +224,7 @@ inline void SfallInit() {
CRC(filepath);
if (!isDebug || !iniGetInt("Debugging", "SkipCompatModeCheck", 0, ::sfall::ddrawIni)) {
if (!isDebug || !IniReader::GetIntDefaultConfig("Debugging", "SkipCompatModeCheck", 0)) {
int is64bit;
typedef int (__stdcall *chk64bitproc)(HANDLE, int*);
HMODULE h = LoadLibrary("Kernel32.dll");
@@ -309,7 +242,7 @@ inline void SfallInit() {
// ini file override
bool cmdlineexists = false;
char* cmdline = GetCommandLineA();
if (iniGetInt("Main", "UseCommandLine", 0, ::sfall::ddrawIni)) {
if (IniReader::GetIntDefaultConfig("Main", "UseCommandLine", 0)) {
while (cmdline[0] == ' ') cmdline++;
bool InQuote = false;
int count = -1;
@@ -335,7 +268,7 @@ inline void SfallInit() {
HANDLE h = CreateFileA(cmdline, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if (h != INVALID_HANDLE_VALUE) {
CloseHandle(h);
strcat_s(ini, cmdline);
IniReader::SetConfigFile(cmdline);
} else {
MessageBoxA(0, "You gave a command line argument to Fallout, but it couldn't be matched to a file.\n" \
"Using default ddraw.ini instead.", "Warning", MB_TASKMODAL | MB_ICONWARNING);
@@ -343,12 +276,9 @@ inline void SfallInit() {
}
} else {
defaultIni:
strcpy(&ini[2], &::sfall::ddrawIni[2]);
IniReader::SetDefaultConfigFile();
}
GetConfigString("Main", "TranslationsINI", ".\\Translations.ini", translationIni, 65);
modifiedIni = GetConfigInt("Main", "ModifiedIni", 0);
hrpIsEnabled = (*(DWORD*)0x4E4480 != 0x278805C7); // check if HRP is enabled
if (hrpIsEnabled) {
LoadHRPModule();
@@ -361,6 +291,8 @@ defaultIni:
}
std::srand(GetTickCount());
IniReader::init();
InitReplacementHacks();
InitModules();
}
+2 -38
View File
@@ -35,6 +35,7 @@
#include "SafeWrite.h"
#include "Logging.h"
#include "IniReader.h"
struct ddrawDll {
HMODULE dll;
@@ -74,51 +75,14 @@ namespace sfall
#endif
// Trap for Debugger
#define BREAKPOINT __asm int 3
#define BREAKPOINT __debugbreak
// Macros for quick replacement of assembler opcodes pushad/popad
#define pushadc __asm push eax __asm push edx __asm push ecx
#define popadc __asm pop ecx __asm pop edx __asm pop eax
// Gets the integer value from given INI file.
int iniGetInt(const char* section, const char* setting, int defaultValue, const char* iniFile);
// Gets the string value from given INI file.
size_t iniGetString(const char* section, const char* setting, const char* defaultValue, char* buf, size_t bufSize, const char* iniFile);
// Gets the string value from given INI file.
std::string GetIniString(const char* section, const char* setting, const char* defaultValue, size_t bufSize, const char* iniFile);
// Parses the comma-separated list setting from given INI file.
std::vector<std::string> GetIniList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile);
// Gets the integer value from Sfall configuration INI file.
unsigned int GetConfigInt(const char* section, const char* setting, int defaultValue);
// Gets the string value from Sfall configuration INI file with trim function.
std::string GetConfigString(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
// Loads the string value from Sfall configuration INI file into the provided buffer.
size_t GetConfigString(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize = 128);
// Parses the comma-separated list from the settings from Sfall configuration INI file.
std::vector<std::string> GetConfigList(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
std::vector<std::string> TranslateList(const char* section, const char* setting, const char* defaultValue, char delimiter, size_t bufSize = 256);
// Translates given string using Sfall translation INI file.
std::string Translate(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
// Translates given string using Sfall translation INI file and puts the result into given buffer.
size_t Translate(const char* section, const char* setting, const char* defaultValue, char* buffer, size_t bufSize = 128);
int SetConfigInt(const char* section, const char* setting, int value);
DWORD HRPAddress(DWORD addr);
extern const char ddrawIni[];
extern DWORD modifiedIni;
extern bool hrpIsEnabled;
extern bool hrpVersionValid;