diff --git a/sfall/Game/GUI/Text.cpp b/sfall/Game/GUI/Text.cpp index 6d6e1ed9..efd0f45c 100644 --- a/sfall/Game/GUI/Text.cpp +++ b/sfall/Game/GUI/Text.cpp @@ -9,7 +9,6 @@ #include "..\..\Modules\Console.h" -#include "..\..\HRP\Init.h" #include "..\..\HRP\InterfaceBar.h" #include "Text.h" @@ -57,18 +56,18 @@ static long GetPositionWidth(const char* text, long width) { static void __fastcall DisplayPrint(const char* message, bool lineBreak) { if (*message == 0 || !fo::var::getInt(FO_VAR_disp_init)) return; - sfall::Console::PrintFile(message); + sf::Console::PrintFile(message); const long max_lines = 100; // aka FO_VAR_max long max_disp_chars = 256; // HRP value (vanilla 80) - char* display_string_buf_addr = sf::IFaceBar::display_string_buf; // array size: 100x80 (or 100x256 for sfall HRP) + char* display_string_buf_addr = HRP::IFaceBar::display_string_buf; // array size: 100x80 (or 100x256 for sfall HRP) - long width = (sf::hrpIsEnabled) ? sf::GetIntHRPValue(HRP_VAR_disp_width) : sf::IFaceBar::display_width; + long width = (HRP::Setting::ExternalEnabled()) ? sf::GetIntHRPValue(HRP_VAR_disp_width) : HRP::IFaceBar::display_width; if (width == 0) { width = 167; // vanilla size max_disp_chars = 80; - } else if (sfall::hrpIsEnabled) { - display_string_buf_addr = (char*)sf::HRPAddress(HRP_VAR_display_string_buf); // array size 100x256, allocated by Mash's HRP + } else if (HRP::Setting::ExternalEnabled()) { + display_string_buf_addr = (char*)HRP::Setting::GetAddress(HRP_VAR_display_string_buf); // array size 100x256, allocated by Mash's HRP } if (!(fo::var::combat_state & fo::CombatStateFlag::InCombat)) { @@ -189,10 +188,10 @@ static void __declspec(naked) display_print_line_break_extHRP() { void Text::init() { void* printFunc = display_print_line_break; // for vanilla and HRP 4.1.8 - if (sf::HRP::Enabled) { + if (HRP::Setting::IsEnabled()) { sf::MakeJump(fo::funcoffs::display_print_, display_print_hack_replacemet); // 0x43186C } else { - if (sf::hrpIsEnabled && !sf::hrpVersionValid) { + if (HRP::Setting::ExternalEnabled() && !HRP::Setting::VersionIsValid) { printFunc = display_print_line_break_extHRP; } } diff --git a/sfall/HRP/Dialog.cpp b/sfall/HRP/Dialog.cpp index fd6daaa1..168a39fe 100644 --- a/sfall/HRP/Dialog.cpp +++ b/sfall/HRP/Dialog.cpp @@ -14,9 +14,11 @@ #include "Dialog.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + static const long width = 640; // art static long scr_width = 639; @@ -187,7 +189,7 @@ static void UnloadDialogArt() { void Dialog::init() { // replace width size for buffers functons - SafeWriteBatch(&scr_width, { + sf::SafeWriteBatch(&scr_width, { 0x447201, 0x447248, //0x44716F, // gdCreateHeadWindow_ 0x4459F0, 0x445A0C, //0x44597A, // gdReviewInit_ 0x445DA7, 0x445DD1, // gdReviewDisplay_ @@ -217,8 +219,8 @@ void Dialog::init() { 0x4733DF, 0x47343A, // inven_action_cursor_ }); - HookCall(0x44718F, gdCreateHeadWindow_hook_win_add); - HookCalls(GeneralDialogWinAdd, { + sf::HookCall(0x44718F, gdCreateHeadWindow_hook_win_add); + sf::HookCalls(GeneralDialogWinAdd, { 0x445997, // gdReviewInit_ 0x44A6E4, // gdialog_window_create_ 0x448333, // gdialog_barter_create_win_ @@ -228,48 +230,48 @@ void Dialog::init() { // gdCustomSelect_ long yoffset = (DIALOG_SCRN_BACKGROUND) ? 100 : 200; // shifted the window up so that the window with the selected options was visible - SafeWrite32(0x44A03E, HRP::ScreenHeight() - yoffset); - SafeWrite32(0x44A02A, HRP::ScreenWidth()); + sf::SafeWrite32(0x44A03E, Setting::ScreenHeight() - yoffset); + sf::SafeWrite32(0x44A02A, Setting::ScreenWidth()); - HookCall(0x4462A7, gdProcess_hook_win_add); - HookCall(0x446387, gdProcess_hook_win_add); + sf::HookCall(0x4462A7, gdProcess_hook_win_add); + sf::HookCall(0x446387, gdProcess_hook_win_add); - HookCall(0x447900, hook_buf_to_buf); // demo_copy_options_ - HookCall(0x447A46, hook_buf_to_buf); // gDialogRefreshOptionsRect_ + sf::HookCall(0x447900, hook_buf_to_buf); // demo_copy_options_ + sf::HookCall(0x447A46, hook_buf_to_buf); // gDialogRefreshOptionsRect_ - HookCall(0x44AF39, gdDisplayFrame_hook_buf_to_buf); + sf::HookCall(0x44AF39, gdDisplayFrame_hook_buf_to_buf); // Barter interface hacks - HookCall(0x46EDC9, setup_inventory_hook_win_add); - MakeCall(0x46EDD8, setup_inventory_hack); - HookCalls(barter_move_hook_mouse_click_in, { + sf::HookCall(0x46EDC9, setup_inventory_hook_win_add); + sf::MakeCall(0x46EDD8, setup_inventory_hack); + sf::HookCalls(barter_move_hook_mouse_click_in, { 0x474F76, 0x474FF9, // barter_move_inventory_ 0x475241, 0x4752C2, // barter_move_from_table_inventory_ 0x449661 // gdControl_ (custom disposition button) }); - if (DIALOG_SCRN_BACKGROUND) HookCall(0x4472D8, gdDestroyHeadWindow_hook_win_delete); + if (DIALOG_SCRN_BACKGROUND) sf::HookCall(0x4472D8, gdDestroyHeadWindow_hook_win_delete); if (DIALOG_SCRN_ART_FIX) { - HookCall(0x44AB79, talk_to_refresh_background_window_hook_buf_to_buf); + sf::HookCall(0x44AB79, talk_to_refresh_background_window_hook_buf_to_buf); // gdCreateHeadWindow_ - SafeWrite16(0x447255, 0xD269); - SafeWrite32(0x447257, 19); // y - SafeWrite8(0x44725B, 0x90); - SafeWrite16(0x44725C, 0x3EB); + sf::SafeWrite16(0x447255, 0xD269); + sf::SafeWrite32(0x447257, 19); // y + sf::SafeWrite8(0x44725B, 0x90); + sf::SafeWrite16(0x44725C, 0x3EB); // gdDisplayFrame_ - SafeWrite8(0x44AF9D, 20); // 15 to 20 - SafeWrite32(0x44AFEB, 219); // 214 to 219 - SafeWrite32(0x44AF47, 19); // 14 to 19 - SafeWrite32(0x44AF51, 219); // 214 to 219 + sf::SafeWrite8(0x44AF9D, 20); // 15 to 20 + sf::SafeWrite32(0x44AFEB, 219); // 214 to 219 + sf::SafeWrite32(0x44AF47, 19); // 14 to 19 + sf::SafeWrite32(0x44AF51, 219); // 214 to 219 for (size_t i = 0; i < 8; i++) { fo::var::backgrndRects[i].y += 5; fo::var::backgrndRects[i].offy += 5; } - LoadGameHook::OnGameExit() += UnloadDialogArt; + sf::LoadGameHook::OnGameExit() += UnloadDialogArt; } } diff --git a/sfall/HRP/Dialog.h b/sfall/HRP/Dialog.h index ac777dd2..b6d8eff6 100644 --- a/sfall/HRP/Dialog.h +++ b/sfall/HRP/Dialog.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class Dialog { diff --git a/sfall/HRP/Image.cpp b/sfall/HRP/Image.cpp index c167a7ae..aef61062 100644 --- a/sfall/HRP/Image.cpp +++ b/sfall/HRP/Image.cpp @@ -8,7 +8,7 @@ #include "Image.h" -namespace sfall +namespace HRP { long Image::GetAspectSize(long &dW, long &dH, float sW, float sH) { diff --git a/sfall/HRP/Image.h b/sfall/HRP/Image.h index 9dcba81d..c26eea14 100644 --- a/sfall/HRP/Image.h +++ b/sfall/HRP/Image.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class Image { diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index df7ccd52..aba20646 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -20,43 +20,54 @@ #include "Init.h" -namespace sfall +namespace HRP { -static const char* f2ResIni = ".\\f2_res.ini"; +namespace sf = sfall; +static const char* f2ResIni = ".\\f2_res.ini"; +static DWORD baseDLLAddr = 0; // 0x10000000 + +bool Setting::VersionIsValid = false; + +static bool enabled; static long SCR_WIDTH = 640; static long SCR_HEIGHT = 480; -bool HRP::Enabled; - -long HRP::ScreenWidth() { return SCR_WIDTH; } -long HRP::ScreenHeight() { return SCR_HEIGHT; } - -DWORD HRP::hrpDLLBaseAddr = 0x10000000; +bool Setting::IsEnabled() { return enabled; } +long Setting::ScreenWidth() { return SCR_WIDTH; } +long Setting::ScreenHeight() { return SCR_HEIGHT; } static void GetHRPModule() { static const DWORD loadFunc = 0x4FE1D0; HMODULE dll; __asm call loadFunc; // get HRP loading address - __asm mov dll, eax; - if (dll != NULL) HRP::hrpDLLBaseAddr = (DWORD)dll; - dlog_f("Loaded f2_res.dll library at the memory address: 0x%x\n", DL_MAIN, dll); + __asm mov baseDLLAddr, eax; + sf::dlog_f("Loaded f2_res.dll library at the memory address: 0x%x\n", DL_MAIN, dll); } -bool HRP::CheckExternalPatch() { +bool Setting::CheckExternalPatch() { bool isEnabled = (*(DWORD*)0x4E4480 != 0x278805C7); // check if Mash's HRP is enabled if (isEnabled) { GetHRPModule(); MODULEINFO info; - if (GetModuleInformation(GetCurrentProcess(), (HMODULE)HRP::hrpDLLBaseAddr, &info, sizeof(info)) && info.SizeOfImage >= 0x39940 + 7) { - if (GetByteHRPValue(HRP_VAR_VERSION_STR + 7) == 0 && std::strncmp((const char*)HRPAddress(HRP_VAR_VERSION_STR), "4.1.8", 5) == 0) { - hrpVersionValid = true; + if (GetModuleInformation(GetCurrentProcess(), (HMODULE)baseDLLAddr, &info, sizeof(info)) && info.SizeOfImage >= 0x39940 + 7) { + if (sf::GetByteHRPValue(HRP_VAR_VERSION_STR + 7) == 0 && std::strncmp((const char*)GetAddress(HRP_VAR_VERSION_STR), "4.1.8", 5) == 0) { + VersionIsValid = true; } } } - return isEnabled; + return ExternalEnabled(); } + +DWORD Setting::GetAddress(DWORD addr) { + return (baseDLLAddr + (addr & 0xFFFFF)); +} + +bool Setting::ExternalEnabled() { + return (baseDLLAddr != 0); +} + /* static void __declspec(naked) mem_copy() { __asm { @@ -112,24 +123,24 @@ forward: } } */ -void HRP::init() { +void Setting::init() { //HookCall(0x482899, mem_copy); //SafeWrite16(0x4B2EA8, 0x9090); // _show_grid - if (!hrpIsEnabled && IniReader::GetIntDefaultConfig("Main", "HiResMode", 1) == 0) return; // vanilla game mode + if (!Setting::ExternalEnabled() && sf::IniReader::GetIntDefaultConfig("Main", "HiResMode", 1) == 0) return; // vanilla game mode - SCR_WIDTH = IniReader::GetInt("Main", "SCR_WIDTH", 640, f2ResIni); - SCR_HEIGHT = IniReader::GetInt("Main", "SCR_HEIGHT", 480, f2ResIni); + SCR_WIDTH = sf::IniReader::GetInt("Main", "SCR_WIDTH", 640, f2ResIni); + SCR_HEIGHT = sf::IniReader::GetInt("Main", "SCR_HEIGHT", 480, f2ResIni); if (SCR_WIDTH < 640) SCR_WIDTH = 640; if (SCR_HEIGHT < 480) SCR_HEIGHT = 480; - if (hrpIsEnabled) { // external + if (Setting::ExternalEnabled()) { // You have both the built-in and external HRP enabled at the same time. It is recommended to turn off the external HRP by Mash. // To continue using the external HRP, disable the HiResMode option in ddraw.ini return; } - Enabled = true; + enabled = true; // Read config @@ -139,66 +150,66 @@ void HRP::init() { //gDirectDrawMode = IniReader::GetInt("Main", "GRAPHICS_MODE", 2, f2ResIni) == 1; - MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU = (IniReader::GetInt("MAINMENU", "SCALE_BUTTONS_AND_TEXT_MENU", 0, f2ResIni) != 0); - MainMenuScreen::USE_HIRES_IMAGES = (IniReader::GetInt("MAINMENU", "USE_HIRES_IMAGES", 1, f2ResIni) != 0); - MainMenuScreen::MENU_BG_OFFSET_X += IniReader::GetInt("MAINMENU", "MENU_BG_OFFSET_X", -14, f2ResIni); - MainMenuScreen::MENU_BG_OFFSET_Y += IniReader::GetInt("MAINMENU", "MENU_BG_OFFSET_Y", -4, f2ResIni); - MainMenuScreen::MAIN_MENU_SIZE = IniReader::GetInt("MAINMENU", "MAIN_MENU_SIZE", 1, f2ResIni); + MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU = (sf::IniReader::GetInt("MAINMENU", "SCALE_BUTTONS_AND_TEXT_MENU", 0, f2ResIni) != 0); + MainMenuScreen::USE_HIRES_IMAGES = (sf::IniReader::GetInt("MAINMENU", "USE_HIRES_IMAGES", 1, f2ResIni) != 0); + MainMenuScreen::MENU_BG_OFFSET_X += sf::IniReader::GetInt("MAINMENU", "MENU_BG_OFFSET_X", -14, f2ResIni); + MainMenuScreen::MENU_BG_OFFSET_Y += sf::IniReader::GetInt("MAINMENU", "MENU_BG_OFFSET_Y", -4, f2ResIni); + MainMenuScreen::MAIN_MENU_SIZE = sf::IniReader::GetInt("MAINMENU", "MAIN_MENU_SIZE", 1, f2ResIni); - SplashScreen::SPLASH_SCRN_SIZE = IniReader::GetInt("STATIC_SCREENS", "SPLASH_SCRN_SIZE", 1, f2ResIni); + SplashScreen::SPLASH_SCRN_SIZE = sf::IniReader::GetInt("STATIC_SCREENS", "SPLASH_SCRN_SIZE", 1, f2ResIni); //DEATH_SCRN_SIZE //END_SLIDE_SIZE //HELP_SCRN_SIZE - std::string x = trim(IniReader::GetString("MAPS", "SCROLL_DIST_X", "480", 16, f2ResIni)); - std::string y = trim(IniReader::GetString("MAPS", "SCROLL_DIST_Y", "400", 16, f2ResIni)); + std::string x = sf::trim(sf::IniReader::GetString("MAPS", "SCROLL_DIST_X", "480", 16, f2ResIni)); + std::string y = sf::trim(sf::IniReader::GetString("MAPS", "SCROLL_DIST_Y", "400", 16, f2ResIni)); ViewMap::SCROLL_DIST_X = (!x.compare(0, 9, "HALF_SCRN")) ? (SCR_WIDTH / 2) + 32 : std::atol(x.c_str()); ViewMap::SCROLL_DIST_Y = (!y.compare(0, 9, "HALF_SCRN")) ? (SCR_HEIGHT / 2) + 24 : std::atol(y.c_str()); - ViewMap::IGNORE_PLAYER_SCROLL_LIMITS = (IniReader::GetInt("MAPS", "IGNORE_PLAYER_SCROLL_LIMITS", 0, f2ResIni) != 0); - ViewMap::IGNORE_MAP_EDGES = (IniReader::GetInt("MAPS", "IGNORE_MAP_EDGES", 0, f2ResIni) != 0); - ViewMap::EDGE_CLIPPING_ON = (IniReader::GetInt("MAPS", "EDGE_CLIPPING_ON", 1, f2ResIni) != 0); + ViewMap::IGNORE_PLAYER_SCROLL_LIMITS = (sf::IniReader::GetInt("MAPS", "IGNORE_PLAYER_SCROLL_LIMITS", 0, f2ResIni) != 0); + ViewMap::IGNORE_MAP_EDGES = (sf::IniReader::GetInt("MAPS", "IGNORE_MAP_EDGES", 0, f2ResIni) != 0); + ViewMap::EDGE_CLIPPING_ON = (sf::IniReader::GetInt("MAPS", "EDGE_CLIPPING_ON", 1, f2ResIni) != 0); - IFaceBar::IFACE_BAR_MODE = IniReader::GetInt("IFACE", "IFACE_BAR_MODE", 0, f2ResIni); - IFaceBar::IFACE_BAR_SIDE_ART = IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 2, f2ResIni); - IFaceBar::IFACE_BAR_WIDTH = IniReader::GetInt("IFACE", "IFACE_BAR_WIDTH", (SCR_WIDTH >= 800) ? 800 : 640, f2ResIni); - IFaceBar::IFACE_BAR_SIDES_ORI = (IniReader::GetInt("IFACE", "IFACE_BAR_SIDES_ORI", 0, f2ResIni) != 0); + IFaceBar::IFACE_BAR_MODE = sf::IniReader::GetInt("IFACE", "IFACE_BAR_MODE", 0, f2ResIni); + IFaceBar::IFACE_BAR_SIDE_ART = sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDE_ART", 2, f2ResIni); + IFaceBar::IFACE_BAR_WIDTH = sf::IniReader::GetInt("IFACE", "IFACE_BAR_WIDTH", (SCR_WIDTH >= 800) ? 800 : 640, f2ResIni); + IFaceBar::IFACE_BAR_SIDES_ORI = (sf::IniReader::GetInt("IFACE", "IFACE_BAR_SIDES_ORI", 0, f2ResIni) != 0); - Dialog::DIALOG_SCRN_ART_FIX = (IniReader::GetInt("OTHER_SETTINGS", "DIALOG_SCRN_ART_FIX", 1, f2ResIni) != 0); - Dialog::DIALOG_SCRN_BACKGROUND = (IniReader::GetInt("OTHER_SETTINGS", "DIALOG_SCRN_BACKGROUND", 0, f2ResIni) != 0); + Dialog::DIALOG_SCRN_ART_FIX = (sf::IniReader::GetInt("OTHER_SETTINGS", "DIALOG_SCRN_ART_FIX", 1, f2ResIni) != 0); + Dialog::DIALOG_SCRN_BACKGROUND = (sf::IniReader::GetInt("OTHER_SETTINGS", "DIALOG_SCRN_BACKGROUND", 0, f2ResIni) != 0); - if (IniReader::GetInt("OTHER_SETTINGS", "BARTER_PC_INV_DROP_FIX", 1, f2ResIni)) { + if (sf::IniReader::GetInt("OTHER_SETTINGS", "BARTER_PC_INV_DROP_FIX", 1, f2ResIni)) { // barter_move_from_table_inventory_ - if (fo::var::getInt(0x47523D) == 80) SafeWrite32(0x47523D, 100); // x_start - if (fo::var::getInt(0x475231) == 144) SafeWrite32(0x475231, 164); // x_end + if (fo::var::getInt(0x47523D) == 80) sf::SafeWrite32(0x47523D, 100); // x_start + if (fo::var::getInt(0x475231) == 144) sf::SafeWrite32(0x475231, 164); // x_end } // add before sfall.dat and after critter.dat - LoadOrder::AddResourcePatches( - IniReader::GetString("Main", "f2_res_dat", "f2_res.dat", MAX_PATH, f2ResIni), - IniReader::GetString("Main", "f2_res_patches", "", MAX_PATH, f2ResIni) + sf::LoadOrder::AddResourcePatches( + sf::IniReader::GetString("Main", "f2_res_dat", "f2_res.dat", MAX_PATH, f2ResIni), + sf::IniReader::GetString("Main", "f2_res_patches", "", MAX_PATH, f2ResIni) ); /* Inject hacks */ - SafeWrite32(0x482E30, FO_VAR_mapEntranceTileNum); // map_load_file_ (_tile_center_tile to _mapEntranceTileNum) + sf::SafeWrite32(0x482E30, FO_VAR_mapEntranceTileNum); // map_load_file_ (_tile_center_tile to _mapEntranceTileNum) if (SCR_WIDTH != 640 || SCR_HEIGHT != 480) { // Set the resolution for GNW95_init_mode_ex_ - SafeWrite32(0x4CAD6B, SCR_WIDTH); // 640 - SafeWrite32(0x4CAD66, SCR_HEIGHT); // 480 + sf::SafeWrite32(0x4CAD6B, SCR_WIDTH); // 640 + sf::SafeWrite32(0x4CAD66, SCR_HEIGHT); // 480 // Set the resolution for the overlapping temporary black window when loading/starting the game // main_load_new_ - SafeWrite32(0x480D6C, SCR_HEIGHT); - SafeWrite32(0x480D84, SCR_WIDTH); + sf::SafeWrite32(0x480D6C, SCR_HEIGHT); + sf::SafeWrite32(0x480D84, SCR_WIDTH); // gnw_main_ - SafeWrite32(0x480AFA, SCR_HEIGHT); // -100 for ifacebar? - SafeWrite32(0x480B04, SCR_WIDTH); + sf::SafeWrite32(0x480AFA, SCR_HEIGHT); // -100 for ifacebar? + sf::SafeWrite32(0x480B04, SCR_WIDTH); // LoadGame_ - SafeWrite32(0x47C6E0, SCR_HEIGHT); - SafeWrite32(0x47C6E5, SCR_WIDTH); - SafeWrite32(0x47C703, SCR_WIDTH); - SafeWrite32(0x47C70D, SCR_HEIGHT); + sf::SafeWrite32(0x47C6E0, SCR_HEIGHT); + sf::SafeWrite32(0x47C6E5, SCR_WIDTH); + sf::SafeWrite32(0x47C703, SCR_WIDTH); + sf::SafeWrite32(0x47C70D, SCR_HEIGHT); } // Inits diff --git a/sfall/HRP/Init.h b/sfall/HRP/Init.h index 9619da8b..50117e9f 100644 --- a/sfall/HRP/Init.h +++ b/sfall/HRP/Init.h @@ -6,18 +6,20 @@ #pragma once -namespace sfall +namespace HRP { -class HRP { +class Setting { public: static void init(); - static DWORD hrpDLLBaseAddr; + static DWORD GetAddress(DWORD addr); + static bool VersionIsValid; // HRP 4.1.8 version validation static bool CheckExternalPatch(); + static bool ExternalEnabled(); // Built-in high resolution patch - static bool Enabled; + static bool IsEnabled(); static long ScreenWidth(); static long ScreenHeight(); diff --git a/sfall/HRP/InterfaceBar.cpp b/sfall/HRP/InterfaceBar.cpp index e7178039..54a24d4f 100644 --- a/sfall/HRP/InterfaceBar.cpp +++ b/sfall/HRP/InterfaceBar.cpp @@ -13,9 +13,11 @@ #include "InterfaceBar.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + long IFaceBar::IFACE_BAR_MODE; // 1 - the bottom of the map view window extends to the base of the screen and is overlapped by the IFACE Bar long IFaceBar::IFACE_BAR_SIDE_ART; long IFaceBar::IFACE_BAR_WIDTH; @@ -82,17 +84,17 @@ public: static long __fastcall IntfaceWinCreate(long height, long yPos, long xPos, long width, long color, long flags) { if (width != IFaceBar::IFACE_BAR_WIDTH) width = IFaceBar::IFACE_BAR_WIDTH; - yPos += HRP::ScreenHeight() - 479; // yPos:379 = 479-100 - xPos += (HRP::ScreenWidth() - width) / 2; + yPos += Setting::ScreenHeight() - 479; // yPos:379 = 479-100 + xPos += (Setting::ScreenWidth() - width) / 2; xPosition = xPos; yPosition = yPos; flags |= fo::WinFlags::DontMoveTop; - if (IFaceBar::IFACE_BAR_MODE == 0 && IFaceBar::IFACE_BAR_SIDE_ART && HRP::ScreenWidth() > IFaceBar::IFACE_BAR_WIDTH) { + if (IFaceBar::IFACE_BAR_MODE == 0 && IFaceBar::IFACE_BAR_SIDE_ART && Setting::ScreenWidth() > IFaceBar::IFACE_BAR_WIDTH) { long leftID = fo::func::win_add(0, yPos, xPos, height, 0, flags); - long rightID = fo::func::win_add(xPos + width, yPos, HRP::ScreenWidth() - (xPos + width), height, 0, flags); + long rightID = fo::func::win_add(xPos + width, yPos, Setting::ScreenWidth() - (xPos + width), height, 0, flags); panels = new Panels(leftID, rightID); } @@ -184,7 +186,7 @@ static void InterfaceArtScale(BYTE* scr, long w, long h, BYTE* dst, long dh) { } static long __cdecl InterfaceArt(BYTE* scr, long w, long h, long srcWidth, BYTE* dst, long dstWidth) { - if (HRP::ScreenWidth() >= IFaceBar::IFACE_BAR_WIDTH) { + if (Setting::ScreenWidth() >= IFaceBar::IFACE_BAR_WIDTH) { xOffset = IFaceBar::IFACE_BAR_WIDTH - 640; xyOffsetAP = 15 * xOffset; xyOffsetCBtn = 39 * xOffset; @@ -375,70 +377,70 @@ void IFaceBar::init() { display_width = IFaceBar::IFACE_BAR_WIDTH - 473; // message display width (800-473=327) display_string_buf = new char[100 * 256]; - HookCall(0x45D950, intface_init_hook_buf_to_buf_ART); - HookCall(0x45E35C, intface_init_hook_buf_to_buf); + sf::HookCall(0x45D950, intface_init_hook_buf_to_buf_ART); + sf::HookCall(0x45E35C, intface_init_hook_buf_to_buf); - HookCalls(intface_update_move_points_hook_buf_to_buf, {0x45EE43, 0x45EEDF, 0x45EF2D}); + sf::HookCalls(intface_update_move_points_hook_buf_to_buf, {0x45EE43, 0x45EEDF, 0x45EF2D}); - HookCalls(intface_win_register_button, { + sf::HookCalls(intface_win_register_button, { 0x45DA0E, 0x45DAED, 0x45DC0D, 0x45DD44, 0x45DE33, 0x45DF22, 0x45E0B5, 0x45E1EF, // intface_init_ 0x460883, // intface_create_end_turn_button_ 0x4609E3, // intface_create_end_combat_button_ }); - HookCalls(combat_buttons_buf_to_buf, { + sf::HookCalls(combat_buttons_buf_to_buf, { 0x45FA2A, 0x45FA7B, // intface_end_window_open_ 0x45FB87, 0x45FBD1, // intface_end_window_close_ }); // intface_end_buttons_enable_, intface_end_buttons_disable_ - HookCalls(combat_buttons_trans_buf_to_buf, {0x45FC72, 0x45FD06}); + sf::HookCalls(combat_buttons_trans_buf_to_buf, {0x45FC72, 0x45FD06}); // display_init_ hacks - MakeCall(0x43166F, display_init_hack); - HookCall(0x431704, display_init_hook_buf_to_buf); - SafeWrite32(0x43172A, display_width); - SafeWrite32(0x431770, display_width); + sf::MakeCall(0x43166F, display_init_hack); + sf::HookCall(0x431704, display_init_hook_buf_to_buf); + sf::SafeWrite32(0x43172A, display_width); + sf::SafeWrite32(0x431770, display_width); - HookCalls(DisplayReset, { + sf::HookCalls(DisplayReset, { 0x4317EE, // display_init_ 0x431841 // display_reset_ }); // jle > jmp - SafeWrite8(0x4317C1, CodeType::JumpShort); // display_init_ - SafeWrite8(0x431814, CodeType::JumpShort); // display_reset_ + sf::SafeWrite8(0x4317C1, sf::CodeType::JumpShort); // display_init_ + sf::SafeWrite8(0x431814, sf::CodeType::JumpShort); // display_reset_ // display_redraw_ hacks - MakeCall(0x431B19, display_redraw_hack); - SafeWrite32(0x431AB9, display_width); - SafeWrite32(0x431AC0, display_width); - SafeWrite32(0x431B3B, display_width); - SafeWrite32(0x431B36, (DWORD)display_string_buf); + sf::MakeCall(0x431B19, display_redraw_hack); + sf::SafeWrite32(0x431AB9, display_width); + sf::SafeWrite32(0x431AC0, display_width); + sf::SafeWrite32(0x431B3B, display_width); + sf::SafeWrite32(0x431B36, (DWORD)display_string_buf); // rotate numbers hacks - MakeCall(0x460BF3, intface_rotate_numbers_hack, 4); + sf::MakeCall(0x460BF3, intface_rotate_numbers_hack, 4); // remove 'shl eax, 7' - SafeWrite16(0x460C02, 0x9090); - SafeWrite8(0x460C04, 0x90); + sf::SafeWrite16(0x460C02, 0x9090); + sf::SafeWrite8(0x460C04, 0x90); - HookCalls(intface_rotate_numbers_hook_buf_to_buf, { + sf::HookCalls(intface_rotate_numbers_hook_buf_to_buf, { 0x460CC4, 0x460CF8, 0x460D2C, 0x460D75, 0x460EA1, 0x460EF1, 0x460F47, 0x460FA0, 0x460FDD, 0x461010, 0x461060, 0x461085, 0x4610AB, 0x4610EC }); if (ALTERNATE_AMMO_METRE == 0) { // intface_draw_ammo_lights_ hacks - MakeCall(0x460AA6, intface_draw_ammo_lights_hack); - SafeWriteBatch(IFACE_BAR_WIDTH, {0x460AC8, 0x460AD8, 0x460AE3}); - SafeWrite32(0x460AB4, 26 * IFACE_BAR_WIDTH); // y position + sf::MakeCall(0x460AA6, intface_draw_ammo_lights_hack); + sf::SafeWriteBatch(IFACE_BAR_WIDTH, {0x460AC8, 0x460AD8, 0x460AE3}); + sf::SafeWrite32(0x460AB4, 26 * IFACE_BAR_WIDTH); // y position } } - HookCall(0x45D8BC, intface_init_hook_win_add); - HookCall(0x4615FF, refresh_box_bar_win_hook_win_add); - HookCall(0x4AC260, skilldex_start_hook_win_add); + sf::HookCall(0x45D8BC, intface_init_hook_win_add); + sf::HookCall(0x4615FF, refresh_box_bar_win_hook_win_add); + sf::HookCall(0x4AC260, skilldex_start_hook_win_add); - HookCall(0x45EA48, intface_show_hook_win_show); - HookCalls(intface_win_hide, { + sf::HookCall(0x45EA48, intface_show_hook_win_show); + sf::HookCalls(intface_win_hide, { 0x45E3F5, // intface_reset_ 0x45E8FB, // intface_load_ 0x45E9FD // intface_hide_ @@ -450,16 +452,16 @@ void IFaceBar::init() { if (IFACE_BAR_MODE > 0) { // Set view map height to game resolution // replace subtract 99 with add 1 - SafeWrite8(0x481CDF, 1); - SafeWrite8(0x481E2E, 1); + sf::SafeWrite8(0x481CDF, 1); + sf::SafeWrite8(0x481E2E, 1); // replace subtract 99 with add 1 - SafeWrite8(0x481DC3, -1); - SafeWrite8(0x4827A9, -1); + sf::SafeWrite8(0x481DC3, -1); + sf::SafeWrite8(0x4827A9, -1); // remove subtract 100 - SafeWrite8(0x48284F, 0); + sf::SafeWrite8(0x48284F, 0); } - LoadGameHook::OnBeforeGameClose() += []() { + sf::LoadGameHook::OnBeforeGameClose() += []() { if (IFACE_BAR_WIDTH > 640) { delete[] display_string_buf; delete panels; diff --git a/sfall/HRP/InterfaceBar.h b/sfall/HRP/InterfaceBar.h index 1f7871e8..7492f86e 100644 --- a/sfall/HRP/InterfaceBar.h +++ b/sfall/HRP/InterfaceBar.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class IFaceBar { diff --git a/sfall/HRP/Inventory.cpp b/sfall/HRP/Inventory.cpp index 595483b0..6b8e13d5 100644 --- a/sfall/HRP/Inventory.cpp +++ b/sfall/HRP/Inventory.cpp @@ -11,9 +11,11 @@ #include "Inventory.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + static bool setPosition[3]; static long xPosition; static long yPosition; @@ -21,7 +23,7 @@ static long yPosition; static long __fastcall CreateWin(long height, long yPos, long xPos, long width, long mode, long color, long flags) { if (!setPosition[mode]) { setPosition[mode] = true; - long x = (HRP::ScreenWidth() - width) / 2; + long x = (Setting::ScreenWidth() - width) / 2; long y = (fo::var::getInt(FO_VAR_buf_length_2) - height) / 2; fo::var::iscr_data[mode].x = x; fo::var::iscr_data[mode].y = y; @@ -65,18 +67,18 @@ static void __declspec(naked) inventory_hook_mouse_click_in() { void Inventory::init() { // set timer window position to center screen - fo::var::iscr_data[5].x = (HRP::ScreenWidth() - fo::var::iscr_data[5].width) / 2; - fo::var::iscr_data[5].y = (HRP::ScreenHeight() - fo::var::iscr_data[5].height) / 2; + fo::var::iscr_data[5].x = (Setting::ScreenWidth() - fo::var::iscr_data[5].width) / 2; + fo::var::iscr_data[5].y = (Setting::ScreenHeight() - fo::var::iscr_data[5].height) / 2; - HookCall(0x46ED0E, setup_inventory_hook_win_add); - HookCalls(inventory_hook_mouse_click_in, { + sf::HookCall(0x46ED0E, setup_inventory_hook_win_add); + sf::HookCalls(inventory_hook_mouse_click_in, { 0x471145, 0x471270, 0x471301, 0x47138B, // inven_pickup_ 0x474959, 0x474A23 // move_inventory_ }); // setup_inventory_ - SafeMemSet(0x46ED23, CodeType::Nop, 6); - SafeMemSet(0x46ED31, CodeType::Nop, 6); + sf::SafeMemSet(0x46ED23, sf::CodeType::Nop, 6); + sf::SafeMemSet(0x46ED31, sf::CodeType::Nop, 6); } } diff --git a/sfall/HRP/Inventory.h b/sfall/HRP/Inventory.h index eace2542..d095bf3e 100644 --- a/sfall/HRP/Inventory.h +++ b/sfall/HRP/Inventory.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class Inventory { diff --git a/sfall/HRP/MainMenu.cpp b/sfall/HRP/MainMenu.cpp index 3998b2cf..d515ec23 100644 --- a/sfall/HRP/MainMenu.cpp +++ b/sfall/HRP/MainMenu.cpp @@ -16,9 +16,11 @@ #include "MainMenu.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + // 0 - main-menu image will display at its original size // 1 - main-menu image will stretch to fit the screen while maintaining its aspect ratio // 2 - main-menu image will stretch to fill the screen @@ -93,7 +95,7 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, long offset = 0; long sw = w, sh = h; - Graphics::BackgroundClearColor(0); + sf::Graphics::BackgroundClearColor(0); if (MainMenuScreen::USE_HIRES_IMAGES) { if (!mainBackgroundFrm) { @@ -108,13 +110,13 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, if (MainMenuScreen::MAIN_MENU_SIZE != 2) { if (mainBackgroundFrm || MainMenuScreen::MAIN_MENU_SIZE == 1) { - w = HRP::ScreenWidth(); - h = HRP::ScreenHeight(); + w = Setting::ScreenWidth(); + h = Setting::ScreenHeight(); offset = Image::GetAspectSize(w, h, (float)sw, (float)sh); - if (w > HRP::ScreenWidth()) w = HRP::ScreenWidth(); - if (h > HRP::ScreenHeight()) h = HRP::ScreenHeight(); + if (w > Setting::ScreenWidth()) w = Setting::ScreenWidth(); + if (h > Setting::ScreenHeight()) h = Setting::ScreenHeight(); mainmenuWidth = w; } @@ -132,13 +134,13 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, // nothing??? } } else if (MainMenuScreen::MAIN_MENU_SIZE == 2) { - w = HRP::ScreenWidth(); - h = HRP::ScreenHeight(); + w = Setting::ScreenWidth(); + h = Setting::ScreenHeight(); mainmenuWidth = w; } else { // centering - x += (HRP::ScreenWidth() / 2) - (w / 2); - y += (HRP::ScreenHeight() / 2) - (h / 2); + x += (Setting::ScreenWidth() / 2) - (w / 2); + y += (Setting::ScreenHeight() / 2) - (h / 2); } // set scaling factor @@ -147,10 +149,10 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, scaleFactor = h / (float)sh; //scaleFactor = std::round(scaleFactor * 100.0f) / 100.0f; } - scaleXFactor = HRP::ScreenWidth() / (float)640; // TODO: find out how Mash's HRP gets the coefficient for button offsets for different game resolutions + scaleXFactor = Setting::ScreenWidth() / (float)640; // TODO: find out how Mash's HRP gets the coefficient for button offsets for different game resolutions - MainMenu::mTextOffset = MainMenu::mXOffset; - if (MainMenu::mYOffset) MainMenu::mTextOffset += (MainMenu::mYOffset * w); + sf::MainMenu::mTextOffset = sf::MainMenu::mXOffset; + if (sf::MainMenu::mYOffset) sf::MainMenu::mTextOffset += (sf::MainMenu::mYOffset * w); if (x < 0) x = 0; if (y < 0) y = 0; @@ -192,7 +194,7 @@ static void __fastcall TextScale(long xOffset, const char* text, long yPos, long xOffset = (long)(xOffset * scaleFactor); yPos = (long)(yPos * scaleFactor); yPos *= mainmenuWidth; - yPos += MainMenu::mTextOffset; // TODO: check + yPos += sf::MainMenu::mTextOffset; // TODO: check Image::ScaleText( (BYTE*)(fo::var::getInt(FO_VAR_main_window_buf) + yPos + xOffset), @@ -208,7 +210,7 @@ static void __declspec(naked) main_menu_create_hook_text_to_buf() { mov ecx, mainmenuWidth; imul ebp, ecx; // yPos * width add eax, ds:[FO_VAR_main_window_buf]; - add eax, MainMenu::mTextOffset; + add eax, sf::MainMenu::mTextOffset; add eax, ebp; jmp dword ptr ds:[FO_VAR_text_to_buf]; scale: @@ -292,24 +294,24 @@ void MainMenuScreen::init() { if (MENU_BG_OFFSET_X < 0) MENU_BG_OFFSET_X = 0; if (MENU_BG_OFFSET_Y < 0) MENU_BG_OFFSET_Y = 0; - // Main menu window size - //SafeWrite32(0x481674, HRP::ScreenHeight()); - //SafeWrite32(0x48167A, HRP::ScreenWidth()); + // Mainmenu window size + //sf::SafeWrite32(0x481674, HRP::ScreenHeight()); + //sf::SafeWrite32(0x48167A, HRP::ScreenWidth()); - HookCall(0x481680, main_menu_create_hook_add_win); - HookCall(0x481704, main_menu_create_hook_buf_to_buf); - HookCall(0x481767, main_menu_create_hook_win_print); - HookCall(0x481883, main_menu_create_hook_register_button); - MakeCall(0x481933, main_menu_create_hook_text_to_buf, 1); + sf::HookCall(0x481680, main_menu_create_hook_add_win); + sf::HookCall(0x481704, main_menu_create_hook_buf_to_buf); + sf::HookCall(0x481767, main_menu_create_hook_win_print); + sf::HookCall(0x481883, main_menu_create_hook_register_button); + sf::MakeCall(0x481933, main_menu_create_hook_text_to_buf, 1); // imul ebp, edx, 640 -> mov ebp, edx - SafeWrite16(0x481912, 0xD589); - SafeWrite32(0x481914, 0x90909090); + sf::SafeWrite16(0x481912, 0xD589); + sf::SafeWrite32(0x481914, 0x90909090); - SafeWrite16(0x48192D, 0x9090); + sf::SafeWrite16(0x48192D, 0x9090); - LoadGameHook::OnBeforeGameStart() += FreeMainMenuImages; - LoadGameHook::OnBeforeGameClose() += FreeMainMenuImages; + sf::LoadGameHook::OnBeforeGameStart() += FreeMainMenuImages; + sf::LoadGameHook::OnBeforeGameClose() += FreeMainMenuImages; } } diff --git a/sfall/HRP/MainMenu.h b/sfall/HRP/MainMenu.h index d8eeba48..00dfd177 100644 --- a/sfall/HRP/MainMenu.h +++ b/sfall/HRP/MainMenu.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class MainMenuScreen { diff --git a/sfall/HRP/SplashScreen.cpp b/sfall/HRP/SplashScreen.cpp index a0626773..148f4246 100644 --- a/sfall/HRP/SplashScreen.cpp +++ b/sfall/HRP/SplashScreen.cpp @@ -12,9 +12,11 @@ #include "SplashScreen.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + // 0 - image will display at its original size // 1 - image will stretch to fit the screen while maintaining its aspect ratio // 2 - image will stretch to fill the screen @@ -22,8 +24,8 @@ long SplashScreen::SPLASH_SCRN_SIZE; static void __cdecl game_splash_screen_hack_scr_blit(BYTE* srcPixels, long srcWidth, long srcHeight, long srcX, long srcY, long width, long height, long x, long y) { RECT rect; - long w = Graphics::GetGameWidthRes(); - long h = Graphics::GetGameHeightRes(); + long w = sf::Graphics::GetGameWidthRes(); + long h = sf::Graphics::GetGameHeightRes(); // TODO: Load an alternative 32-bit BMP image or DirectX texture // stretch texture for DirectX @@ -43,19 +45,19 @@ static void __cdecl game_splash_screen_hack_scr_blit(BYTE* srcPixels, long srcWi rect.bottom = (y + h) - 1; rect.left = x; rect.right = (rect.left + w) - 1; - Graphics::UpdateDDSurface(resizeBuff, w, h, w, &rect); + sf::Graphics::UpdateDDSurface(resizeBuff, w, h, w, &rect); delete[] resizeBuff; return; } else if (SplashScreen::SPLASH_SCRN_SIZE == 2) { - BYTE* resizeBuff = new BYTE[Graphics::GetGameWidthRes() * Graphics::GetGameHeightRes()]; - Image::Scale(srcPixels, srcWidth, srcHeight, resizeBuff, Graphics::GetGameWidthRes(), Graphics::GetGameHeightRes()); + BYTE* resizeBuff = new BYTE[sf::Graphics::GetGameWidthRes() * sf::Graphics::GetGameHeightRes()]; + Image::Scale(srcPixels, srcWidth, srcHeight, resizeBuff, sf::Graphics::GetGameWidthRes(), sf::Graphics::GetGameHeightRes()); rect.top = 0; rect.left = 0; - rect.right = Graphics::GetGameWidthRes() - 1; - rect.bottom = Graphics::GetGameHeightRes() - 1; - Graphics::UpdateDDSurface(resizeBuff, Graphics::GetGameWidthRes(), Graphics::GetGameHeightRes(), Graphics::GetGameWidthRes(), &rect); + rect.right =sf:: Graphics::GetGameWidthRes() - 1; + rect.bottom = sf::Graphics::GetGameHeightRes() - 1; + sf::Graphics::UpdateDDSurface(resizeBuff, sf::Graphics::GetGameWidthRes(), sf::Graphics::GetGameHeightRes(), sf::Graphics::GetGameWidthRes(), &rect); delete[] resizeBuff; return; @@ -63,13 +65,13 @@ static void __cdecl game_splash_screen_hack_scr_blit(BYTE* srcPixels, long srcWi // original size to center screen - rect.left = (Graphics::GetGameWidthRes() / 2) - (srcWidth / 2) + x; + rect.left = (sf::Graphics::GetGameWidthRes() / 2) - (srcWidth / 2) + x; rect.right = (rect.left + srcWidth) - 1 ; - rect.top = (Graphics::GetGameHeightRes() / 2) - (srcHeight / 2) + y; + rect.top = (sf::Graphics::GetGameHeightRes() / 2) - (srcHeight / 2) + y; rect.bottom = (rect.top + srcHeight) - 1; - Graphics::UpdateDDSurface(srcPixels, srcWidth, srcHeight, srcWidth, &rect); + sf::Graphics::UpdateDDSurface(srcPixels, srcWidth, srcHeight, srcWidth, &rect); } // Fixes colored screen border when the index 0 of the palette contains a color with a non-black (zero) value @@ -88,7 +90,7 @@ static void __fastcall Clear(fo::PALETTE* palette) { index = i; } } - if (index != 0) Graphics::BackgroundClearColor(index); + if (index != 0) sf::Graphics::BackgroundClearColor(index); } static void __declspec(naked) game_splash_screen_hook() { @@ -100,8 +102,8 @@ static void __declspec(naked) game_splash_screen_hook() { } void SplashScreen::init() { - HookCall(0x4444FC, game_splash_screen_hook); - MakeCall(0x44451E, game_splash_screen_hack_scr_blit, 1); + sf::HookCall(0x4444FC, game_splash_screen_hook); + sf::MakeCall(0x44451E, game_splash_screen_hack_scr_blit, 1); } } diff --git a/sfall/HRP/SplashScreen.h b/sfall/HRP/SplashScreen.h index 24dda752..783d9d07 100644 --- a/sfall/HRP/SplashScreen.h +++ b/sfall/HRP/SplashScreen.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class SplashScreen { diff --git a/sfall/HRP/ViewMap/EdgeBorder.cpp b/sfall/HRP/ViewMap/EdgeBorder.cpp index 3e479ae7..8bdb1fbb 100644 --- a/sfall/HRP/ViewMap/EdgeBorder.cpp +++ b/sfall/HRP/ViewMap/EdgeBorder.cpp @@ -12,9 +12,11 @@ #include "EdgeBorder.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + static EdgeBorder::Edge* MapEdgeData; static EdgeBorder::Edge* currentMapEdge; // reference @@ -212,7 +214,7 @@ static fo::DbFile* LoadMapEdgeFileSub(char* mapName) { static void __fastcall LoadMapEdgeFile() { //isLoadingMapEdge = 0; - fo::DbFile* file = LoadMapEdgeFileSub(LoadGameHook::mapLoadingName); + fo::DbFile* file = LoadMapEdgeFileSub(sf::LoadGameHook::mapLoadingName); if (file) { // load error fo::func::db_fclose(file); SetDefaultEdgeData(); @@ -330,7 +332,7 @@ long EdgeBorder::CheckBorder(long tile) { } void EdgeBorder::init() { - LoadGameHook::OnBeforeMapLoad() += LoadMapEdgeFile; + sf::LoadGameHook::OnBeforeMapLoad() += LoadMapEdgeFile; } } diff --git a/sfall/HRP/ViewMap/EdgeBorder.h b/sfall/HRP/ViewMap/EdgeBorder.h index 95931578..9ac4e0e6 100644 --- a/sfall/HRP/ViewMap/EdgeBorder.h +++ b/sfall/HRP/ViewMap/EdgeBorder.h @@ -6,12 +6,13 @@ #pragma once -namespace sfall +namespace HRP { class EdgeBorder { public: - struct Edge { + class Edge { + public: POINT center; // x/y center of current map screen? RECT borderRect; // right is less than left RECT rect_2; @@ -30,6 +31,7 @@ public: }; } + private: ~Edge() { Release(); } diff --git a/sfall/HRP/ViewMap/EdgeClipping.cpp b/sfall/HRP/ViewMap/EdgeClipping.cpp index 77cc4001..47835013 100644 --- a/sfall/HRP/ViewMap/EdgeClipping.cpp +++ b/sfall/HRP/ViewMap/EdgeClipping.cpp @@ -12,9 +12,11 @@ #include "EdgeClipping.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + static RECT mapVisibleArea; // Returns -1 if the scrRect is not in the rectangle of inRect (same as rect_inside_bound_) @@ -217,12 +219,12 @@ static void __declspec(naked) obj_render_post_roof_hook_rect_inside_bound() { } void EdgeClipping::init() { - HookCall(0x4B15F6, refresh_game_hook_rect_inside_bound); - HookCall(0x483EF0, map_scroll_refresh_game_hook_rect_inside_bound); - MakeCall(0x44E481, gmouse_check_scrolling_hack); // from HRP 3.06 (TODO: redo the implementation so that the scrolling of the map works) + sf::HookCall(0x4B15F6, refresh_game_hook_rect_inside_bound); + sf::HookCall(0x483EF0, map_scroll_refresh_game_hook_rect_inside_bound); + sf::MakeCall(0x44E481, gmouse_check_scrolling_hack); // from HRP 3.06 (TODO: redo the implementation so that the scrolling of the map works) // Prevents rendering of "post roof" objects (fixes the red pixels from the hex cursor remaining at the edges of the cropped part of the map) - HookCall(0x489802, obj_render_post_roof_hook_rect_inside_bound); + sf::HookCall(0x489802, obj_render_post_roof_hook_rect_inside_bound); } } diff --git a/sfall/HRP/ViewMap/EdgeClipping.h b/sfall/HRP/ViewMap/EdgeClipping.h index c0418ee6..3ce71752 100644 --- a/sfall/HRP/ViewMap/EdgeClipping.h +++ b/sfall/HRP/ViewMap/EdgeClipping.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class EdgeClipping { diff --git a/sfall/HRP/ViewMap/ViewMap.cpp b/sfall/HRP/ViewMap/ViewMap.cpp index aa81cbc8..608ffdd3 100644 --- a/sfall/HRP/ViewMap/ViewMap.cpp +++ b/sfall/HRP/ViewMap/ViewMap.cpp @@ -14,14 +14,16 @@ #include "ViewMap.h" -namespace sfall +namespace HRP { +namespace sf = sfall; + const long grid_width = 200; // _grid_width const long square_width = 100; const long square_length = 100; -static Rectangle obj_on_screen_rect; +static sf::Rectangle obj_on_screen_rect; long ViewMap::SCROLL_DIST_X; long ViewMap::SCROLL_DIST_Y; @@ -341,26 +343,26 @@ void ViewMap::init() { if (SCROLL_DIST_Y <= 0) SCROLL_DIST_Y = 400; else if (SCROLL_DIST_Y < 240) SCROLL_DIST_Y = 240; - MakeJump(fo::funcoffs::tile_set_center_, tile_set_center_hack_replacement); // 0x4B12F8 - MakeJump(fo::funcoffs::tile_scroll_to_, tile_scroll_to_hack_replacement); // 0x4B3924 + sf::MakeJump(fo::funcoffs::tile_set_center_, tile_set_center_hack_replacement); // 0x4B12F8 + sf::MakeJump(fo::funcoffs::tile_scroll_to_, tile_scroll_to_hack_replacement); // 0x4B3924 - HookCall(0x4B2AC0, square_render_floor_hook_art_id); - HookCall(0x4B2261, square_render_roof_hook_art_id); - HookCall(0x4B2BF7, square_roof_intersect_hook_art_id); // need to test object_under_mouse_ - MakeCall(0x489730, obj_render_pre_roof_hack_0, 1); - MakeCall(0x4897E3, obj_render_pre_roof_hack_1); + sf::HookCall(0x4B2AC0, square_render_floor_hook_art_id); + sf::HookCall(0x4B2261, square_render_roof_hook_art_id); + sf::HookCall(0x4B2BF7, square_roof_intersect_hook_art_id); // need to test object_under_mouse_ + sf::MakeCall(0x489730, obj_render_pre_roof_hack_0, 1); + sf::MakeCall(0x4897E3, obj_render_pre_roof_hack_1); // Fix - MakeCall(0x489665, obj_render_pre_roof_hack); // find the bug + sf::MakeCall(0x489665, obj_render_pre_roof_hack); // find the bug - obj_on_screen_rect.width = HRP::ScreenWidth(); - obj_on_screen_rect.height = HRP::ScreenHeight(); // maybe take into account the interface bar and be: height - 100? - SafeWrite32(0x45C886, (DWORD)&obj_on_screen_rect); // replace rectangle in op_obj_on_screen_ + obj_on_screen_rect.width = Setting::ScreenWidth(); + obj_on_screen_rect.height = Setting::ScreenHeight(); // maybe take into account the interface bar and be: height - 100? + sf::SafeWrite32(0x45C886, (DWORD)&obj_on_screen_rect); // replace rectangle in op_obj_on_screen_ EdgeBorder::init(); EdgeClipping::init(); - LoadGameHook::OnAfterGameInit() += []() { + sf::LoadGameHook::OnAfterGameInit() += []() { if (IGNORE_PLAYER_SCROLL_LIMITS) fo::var::setInt(FO_VAR_scroll_limiting_on) = 0; if (IGNORE_MAP_EDGES) fo::var::setInt(FO_VAR_scroll_blocking_on) = 0; }; diff --git a/sfall/HRP/ViewMap/ViewMap.h b/sfall/HRP/ViewMap/ViewMap.h index 1cedff55..b9d21715 100644 --- a/sfall/HRP/ViewMap/ViewMap.h +++ b/sfall/HRP/ViewMap/ViewMap.h @@ -6,7 +6,7 @@ #pragma once -namespace sfall +namespace HRP { class ViewMap { diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index 7be66bc6..5babf980 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -533,7 +533,7 @@ void Graphics::SetMovieTexture(bool state) { subtitleShow = false; } else if (aviAspect < winAspect) { - if (Graphics::AviMovieWidthFit || (hrpIsEnabled && GetIntHRPValue(HRP_VAR_MOVIE_SIZE) == 2)) { + if (Graphics::AviMovieWidthFit || (HRP::Setting::ExternalEnabled() && GetIntHRPValue(HRP_VAR_MOVIE_SIZE) == 2)) { //desc.Width = gWidth; // scales the movie surface to screen width } else { // scales width proportionally and places the movie surface at the center of the window along the X-axis @@ -1099,8 +1099,8 @@ HRESULT __stdcall InitFakeDirectDrawCreate(void*, IDirectDraw** b, void*) { dlog("Initializing Direct3D...", DL_MAIN); // original resolution or HRP - ResWidth = HRP::ScreenWidth(); //*(DWORD*)0x4CAD6B; // 640 - ResHeight = HRP::ScreenHeight(); //*(DWORD*)0x4CAD66; // 480 + ResWidth = HRP::Setting::ScreenWidth(); //*(DWORD*)0x4CAD6B; // 640 + ResHeight = HRP::Setting::ScreenHeight(); //*(DWORD*)0x4CAD66; // 480 if (!d3d9) d3d9 = Direct3DCreate9(D3D_SDK_VERSION); @@ -1298,12 +1298,12 @@ void Graphics::init() { MakeJump(fo::funcoffs::GNW95_SetPaletteEntries_ + 1, GNW95_SetPaletteEntries_replacement); // 0x4CB311 MakeJump(fo::funcoffs::GNW95_SetPalette_, GNW95_SetPalette_replacement); // 0x4CB568 - if (hrpVersionValid) { + if (HRP::Setting::VersionIsValid) { // Patch HRP to show the mouse cursor over the window title - if (Graphics::mode == 5) SafeWrite8(HRPAddress(0x10027142), CodeType::JumpShort); + if (Graphics::mode == 5) SafeWrite8(HRP::Setting::GetAddress(0x10027142), CodeType::JumpShort); // Patch HRP to fix the issue of displaying a palette color with index 255 for images (splash screens, ending slides) - SafeWrite8(HRPAddress(0x1000F8C7), CodeType::JumpShort); + SafeWrite8(HRP::Setting::GetAddress(0x1000F8C7), CodeType::JumpShort); } textureFilter = IniReader::GetConfigInt("Graphics", "TextureFilter", 1); diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index 15bf793a..4eb18303 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -147,13 +147,13 @@ static void APBarRectPatch() { } static void ActionPointsBarPatch() { - IFaceBar::UseExpandAPBar = true; + HRP::IFaceBar::UseExpandAPBar = true; dlog("Applying expanded action points bar patch.", DL_INIT); - if (hrpIsEnabled) { + if (HRP::Setting::ExternalEnabled()) { // check valid data - if (hrpVersionValid && !_stricmp((const char*)HRPAddress(HRP_VAR_HR_IFACE_FRM_STR), "HR_IFACE_%i.frm")) { - SafeWriteStr(HRPAddress(HRP_VAR_HR_IFACE_FRM_STR + 11), "E.frm"); // patching HRP + if (HRP::Setting::VersionIsValid && !_stricmp((const char*)HRP::Setting::GetAddress(HRP_VAR_HR_IFACE_FRM_STR), "HR_IFACE_%i.frm")) { + SafeWriteStr(HRP::Setting::GetAddress(HRP_VAR_HR_IFACE_FRM_STR + 11), "E.frm"); // patching HRP } else { dlogr(" Incorrect HRP version!", DL_INIT); return; @@ -837,7 +837,7 @@ static void WorldMapInterfacePatch() { dlogr(" Done", DL_INIT); } - if (hrpIsEnabled && hrpVersionValid) { + if (HRP::Setting::ExternalEnabled() && HRP::Setting::VersionIsValid) { if (worldmapInterface = IniReader::GetConfigInt("Interface", "ExpandWorldMap", 0)) { LoadGameHook::OnAfterGameInit() += WorldmapViewportPatch; // Note: must be applied after WorldMapSlots patch } @@ -1056,7 +1056,7 @@ void Interface::init() { // ScriptWindow - prevents the player from moving when clicking on the window if the 'Transparent' flag is not set HookCall(0x44B737, gmouse_bk_process_hook); LoadGameHook::OnBeforeGameInit() += []() { - if (hrpVersionValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); + if (HRP::Setting::VersionIsValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP }; } diff --git a/sfall/Modules/MainMenu.cpp b/sfall/Modules/MainMenu.cpp index 202a84cc..2da04118 100644 --- a/sfall/Modules/MainMenu.cpp +++ b/sfall/Modules/MainMenu.cpp @@ -58,7 +58,7 @@ static void __declspec(naked) MainMenuHookTextYOffset() { static void __fastcall main_menu_create_hook_print_text(long xPos, const char* text, long yPos, long color) { long winId = fo::var::main_window; - if (!hrpIsEnabled && HRP::Enabled) { + if (!HRP::Setting::ExternalEnabled() && HRP::Setting::IsEnabled()) { fo::Window* win = fo::var::window[winId]; yPos = ((yPos - 460) - 20) + win->height; xPos = ((xPos - 615) - 25) + win->width; @@ -90,7 +90,7 @@ void MainMenu::init() { mTextOffset += offset * 640; MakeJump(0x481844, MainMenuHookButtonYOffset); } - if (!HRP::Enabled && mTextOffset) { + if (!HRP::Setting::IsEnabled() && mTextOffset) { MakeCall(0x481933, MainMenuHookTextYOffset, 1); } diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index b6f91a23..d5cac01d 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -686,7 +686,7 @@ static void PartyMemberSkillPatch() { // Note: this will cause the party member to apply his/her skill when you use First Aid/Doctor skill on the player, but only if // the player is standing next to the party member. Because the related engine function is not fully implemented, enabling // this option without a global script that overrides First Aid/Doctor functions has very limited usefulness - if (IniReader::GetConfigInt("Misc", "PartyMemberSkillFix", 0) != 0) { + if (IniReader::GetConfigInt("Misc", "PartyMemberSkillFix", 0)) { dlog("Applying party member using First Aid/Doctor skill patch.", DL_INIT); HookCall(0x412836, action_use_skill_on_hook); dlogr(" Done", DL_INIT); @@ -890,7 +890,7 @@ void MiscPatches::init() { if (IniReader::GetConfigInt("Misc", "OverrideArtCacheSize", 0)) { dlog("Applying override art cache size patch.", DL_INIT); SafeWrite32(0x418867, 0x90909090); - SafeWrite32(0x418872, 256); + SafeWrite32(0x418872, 261); // default for 512 MB system memory by installer dlogr(" Done", DL_INIT); } @@ -955,9 +955,9 @@ void MiscPatches::init() { HookCall(0x483726, map_check_state_hook_redraw); // Corrects the height of the black background for death screen subtitles - if (!hrpIsEnabled) SafeWrite32(0x48134D, 38 - (640 * 3)); // main_death_scene_ (shift y-offset 2px up, w/o HRP) - if (!hrpIsEnabled || hrpVersionValid) SafeWrite8(0x481345, 4); // main_death_scene_ - if (hrpVersionValid) SafeWrite8(HRPAddress(0x10011738), 10); + if (!HRP::Setting::ExternalEnabled()) SafeWrite32(0x48134D, 38 - (640 * 3)); // main_death_scene_ (shift y-offset 2px up, w/o HRP) + if (!HRP::Setting::ExternalEnabled() || HRP::Setting::VersionIsValid) SafeWrite8(0x481345, 4); // main_death_scene_ + if (HRP::Setting::VersionIsValid) SafeWrite8(HRP::Setting::GetAddress(0x10011738), 10); F1EngineBehaviorPatch(); DialogueFix(); diff --git a/sfall/Modules/Tiles.cpp b/sfall/Modules/Tiles.cpp index e50d6474..ff9db207 100644 --- a/sfall/Modules/Tiles.cpp +++ b/sfall/Modules/Tiles.cpp @@ -308,9 +308,9 @@ void Tiles::init() { SafeWriteBatch(0x3F, Tiles_3F); SafeWriteBatch(0x40, Tiles_40); SafeWriteBatch(0xC0, Tiles_C0); - if (hrpVersionValid) { // Check HRP 4.1.8 - SafeWrite8(HRPAddress(0x1000E1C0), 0x40); - SafeWrite8(HRPAddress(0x1000E1DA), 0x3F); + if (HRP::Setting::VersionIsValid) { // Check HRP 4.1.8 + SafeWrite8(HRP::Setting::GetAddress(0x1000E1C0), 0x40); + SafeWrite8(HRP::Setting::GetAddress(0x1000E1DA), 0x3F); } dlogr(" Done", DL_INIT); } diff --git a/sfall/main.cpp b/sfall/main.cpp index 6032d330..a81d03f4 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -93,13 +93,6 @@ namespace sfall bool isDebug = false; -bool hrpIsEnabled = false; -bool hrpVersionValid = false; // HRP 4.1.8 version validation - -DWORD HRPAddress(DWORD addr) { - return (HRP::hrpDLLBaseAddr + (addr & 0xFFFFF)); -} - char falloutConfigName[65]; static void InitModules() { @@ -219,11 +212,11 @@ static void SfallInit() { LoggingInit(); if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n"); - hrpIsEnabled = HRP::CheckExternalPatch(); - if (!hrpIsEnabled) + if (!HRP::Setting::CheckExternalPatch()) { WinProc::init(); - else + } else { ShowCursor(0); + } // enabling debugging features isDebug = (IniReader::GetIntDefaultConfig("Debugging", "Enable", 0) != 0); @@ -295,7 +288,7 @@ defaultIni: } Translate::init(falloutConfigName); - HRP::init(); + HRP::Setting::init(); InitReplacementHacks(); InitModules(); diff --git a/sfall/main.h b/sfall/main.h index 7b0b4887..9217eaa6 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -38,6 +38,8 @@ #include "Logging.h" #include "IniReader.h" +#include "HRP\Init.h" + struct ddrawDll { HMODULE dll; FARPROC DirectDrawEnumerateExA; @@ -82,19 +84,14 @@ namespace sfall #define pushadc __asm push eax __asm push edx __asm push ecx #define popadc __asm pop ecx __asm pop edx __asm pop eax -extern bool hrpIsEnabled; -extern bool hrpVersionValid; - extern char falloutConfigName[65]; -DWORD HRPAddress(DWORD addr); - __inline long GetIntHRPValue(DWORD addr) { - return *reinterpret_cast(HRPAddress(addr)); + return *reinterpret_cast(HRP::Setting::GetAddress(addr)); } __inline BYTE GetByteHRPValue(DWORD addr) { - return *reinterpret_cast(HRPAddress(addr)); + return *reinterpret_cast(HRP::Setting::GetAddress(addr)); } }