diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index efe61017..175e4600 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -38,6 +38,7 @@ SpeedMultiInitial=100 ;Set to 6 for DX9 fullscreen windowed (the resolution in f2_res.ini should be set to the same aspect ratio as your desktop resolution) ;A DX9 mode is required for any graphics related script extender functions to work (i.e. fullscreen shaders) ;Modes 1, 2 and 3 are no longer supported +;This option will always be read from the main ini file (i.e. ddraw.ini) when using the hi-res patch by Mash Mode=0 ;If using a DX9 mode, this changes the resolution @@ -796,7 +797,7 @@ DisableSpecialAreas=0 ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [Debugging] ;Extra sfall configuration settings that can be used by modders -;This section is not effected by the 'UseCommandLine' option. It will always be read from the main ini +;This section is not affected by the 'UseCommandLine' option. It will always be read from the main ini file (i.e. ddraw.ini) ;Set to 1 to enable sfall debugging mode Enable=0 diff --git a/sfall/Game/items.cpp b/sfall/Game/items.cpp index 513eedd8..f880c3d9 100644 --- a/sfall/Game/items.cpp +++ b/sfall/Game/items.cpp @@ -232,7 +232,7 @@ long __fastcall Items::item_w_mp_cost(fo::GameObject* source, fo::AttackType hit ); } -static void __declspec(naked) item_w_mp_cost_hack() { +static void __declspec(naked) item_w_mp_cost_replacement() { using namespace fo; __asm { push ebx; // isCalled @@ -248,7 +248,7 @@ void Items::init() { sf::HookCall(0x429A08, ai_search_inven_weap_hook); // Replace the item_w_mp_cost_ function with the sfall implementation - sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_hack); // 0x478B25 + sf::MakeJump(fo::funcoffs::item_w_mp_cost_ + 1, item_w_mp_cost_replacement); // 0x478B25 fastShotTweak = sf::IniReader::GetConfigInt("Misc", "FastShotFix", 0); } diff --git a/sfall/Game/tilemap.cpp b/sfall/Game/tilemap.cpp index 76bea8c5..5b45dc55 100644 --- a/sfall/Game/tilemap.cpp +++ b/sfall/Game/tilemap.cpp @@ -123,7 +123,7 @@ long __fastcall Tilemap::tile_num_beyond(long sourceTile, long targetTile, long } static void __declspec(naked) tile_num_beyond_replacement() { - __asm { //push ecx; + __asm { // push ecx; push ebx; mov ecx, eax; call Tilemap::tile_num_beyond; diff --git a/sfall/IniReader.cpp b/sfall/IniReader.cpp index 9e438489..093db20f 100644 --- a/sfall/IniReader.cpp +++ b/sfall/IniReader.cpp @@ -50,6 +50,12 @@ static std::vector getList(const char* section, const char* setting return list; } +static int setInt(const char* section, const char* setting, int value, const char* iniFile) { + char buf[33]; + _itoa_s(value, buf, 33, 10); + return WritePrivateProfileStringA(section, setting, buf, iniFile); +} + const char* IniReader::GetConfigFile() { return ini; } @@ -107,9 +113,11 @@ std::vector IniReader::GetList(const char* section, const char* set } int IniReader::SetConfigInt(const char* section, const char* setting, int value) { - char buf[33]; - _itoa_s(value, buf, 33, 10); - return WritePrivateProfileStringA(section, setting, buf, ini); + return setInt(section, setting, value, ini); +} + +int IniReader::SetDefaultConfigInt(const char* section, const char* setting, int value) { + return setInt(section, setting, value, ddrawIni); } int IniReader::SetDefaultConfigString(const char* section, const char* setting, const char* value) { diff --git a/sfall/IniReader.h b/sfall/IniReader.h index eb3b0f89..56324041 100644 --- a/sfall/IniReader.h +++ b/sfall/IniReader.h @@ -65,6 +65,8 @@ public: static int SetConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigInt(const char* section, const char* setting, int value); + static int SetDefaultConfigString(const char* section, const char* setting, const char* value); }; diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index ea5c26af..42ba0f12 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -1395,13 +1395,16 @@ static __declspec(naked) void dump_screen_hack_replacement() { } void Graphics::init() { - Graphics::mode = IniReader::GetConfigInt("Graphics", "Mode", 0); + Graphics::mode = (hrpIsEnabled) // avoid mode mismatch between ddraw.ini and another ini file + ? IniReader::GetIntDefaultConfig("Graphics", "Mode", 0) + : IniReader::GetConfigInt("Graphics", "Mode", 0); + if (Graphics::mode < 4 || Graphics::mode > 6) { Graphics::mode = 0; } IsWindowedMode = (Graphics::mode >= 5); - if (Graphics::mode != 0) { + if (Graphics::mode >= 4) { dlog("Applying DX9 graphics patch.", DL_INIT); #define _DLL_NAME "d3dx9_42.dll" HMODULE h = LoadLibraryExA(_DLL_NAME, 0, LOAD_LIBRARY_AS_DATAFILE); @@ -1417,7 +1420,7 @@ void Graphics::init() { SafeWrite8(0x50FB6B, '2'); // Set call DirectDrawCreate2 HookCall(0x44260C, game_init_hook); - MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB311 + MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB310 MakeJump(fo::funcoffs::GNW95_SetPalette_, GNW95_SetPalette_replacement); // 0x4CB568 // Replace the screenshot saving implementation for sfall DirectX 9 @@ -1479,7 +1482,7 @@ void Graphics::init() { } void Graphics::exit() { - if (Graphics::mode != 0) { + if (Graphics::mode >= 4) { RECT rect; if (Graphics::mode == 5 && GetWindowRect(window, &rect)) { int data = rect.top | (rect.left << 16); diff --git a/sfall/Modules/Graphics.h b/sfall/Modules/Graphics.h index 82fa2194..33c2cdf6 100644 --- a/sfall/Modules/Graphics.h +++ b/sfall/Modules/Graphics.h @@ -65,7 +65,7 @@ public: static __forceinline void UpdateDDSurface(BYTE* surface, int width, int height, int widthFrom, RECT* rect) { long x = rect->left; long y = rect->top; - if (Graphics::mode == 0) { + if (Graphics::mode < 4) { __asm { xor eax, eax; push y; diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index 5cd32fe2..794421e4 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -271,7 +271,7 @@ static bool __stdcall GameReset(DWORD isGameLoad) { if (gameLoaded) { // prevent resetting when a new game has not been started (loading saved game from main menu) // OnGameReset BugFixes::OnGameLoad(); - if (Graphics::mode) { + if (Graphics::mode >= 4) { Graphics::ForceGraphicsRefresh(0); // disable refresh ScriptShaders::OnGameLoad(); } diff --git a/sfall/Modules/ScriptShaders.cpp b/sfall/Modules/ScriptShaders.cpp index aa8384ed..02253f0f 100644 --- a/sfall/Modules/ScriptShaders.cpp +++ b/sfall/Modules/ScriptShaders.cpp @@ -70,7 +70,7 @@ void __stdcall SetShaderMode(DWORD d, DWORD mode) { } int __stdcall LoadShader(const char* file) { - if (Graphics::mode == 0 || strstr(file, "..") || strstr(file, ":")) return -1; + if (Graphics::mode < 4 || strstr(file, "..") || strstr(file, ":")) return -1; char buf[MAX_PATH]; sprintf_s(buf, "%s\\shaders\\%s", (*fo::ptr::master_db_handle)->path, file); // *fo::ptr::patches for (DWORD d = 0; d < shadersSize; d++) { @@ -225,7 +225,7 @@ void ScriptShaders::OnGameLoad() { } void ScriptShaders::init() { - if (Graphics::mode != 0) { + if (Graphics::mode >= 4) { for each (const std::string& shaderFile in IniReader::GetConfigList("Graphics", "GlobalShaderFile", "", 1024)) { if (shaderFile.length() > 3) gShaderFiles.push_back(GlobalShader(shaderFile)); } diff --git a/sfall/Modules/Sound.cpp b/sfall/Modules/Sound.cpp index daca95a7..1a537cae 100644 --- a/sfall/Modules/Sound.cpp +++ b/sfall/Modules/Sound.cpp @@ -157,7 +157,7 @@ LRESULT CALLBACK SoundWndProc(HWND wnd, UINT msg, WPARAM w, LPARAM l) { static void CreateSndWnd() { dlog("Creating sfall sound callback window.", DL_INIT); - if (Graphics::mode == 0) CoInitialize(0); + if (Graphics::mode < 4) CoInitialize(0); WNDCLASSEX wcx; std::memset(&wcx, 0, sizeof(wcx)); @@ -1072,7 +1072,7 @@ void Sound::init() { } void Sound::exit() { - if (soundwindow && Graphics::mode == 0) CoUninitialize(); + if (soundwindow && Graphics::mode < 4) CoUninitialize(); } } diff --git a/sfall/Modules/TalkingHeads.cpp b/sfall/Modules/TalkingHeads.cpp index 13d18262..697028e4 100644 --- a/sfall/Modules/TalkingHeads.cpp +++ b/sfall/Modules/TalkingHeads.cpp @@ -269,7 +269,7 @@ void TalkingHeads::init() { // Disable centering the screen if NPC has talking head HookCall(0x445224, gdialogInitFromScript_hook); - if (Graphics::mode && IniReader::GetConfigInt("Graphics", "Use32BitHeadGraphics", 0)) { + if (Graphics::mode >= 4 && IniReader::GetConfigInt("Graphics", "Use32BitHeadGraphics", 0)) { TalkingHeads::Use32Bit = true; } }