From 15c512ff7bc9414837ed79cbb894c582747b440f Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 20 Feb 2022 08:05:27 +0800 Subject: [PATCH] Fixed some problems with the main menu in sfall HRP Minor edits to other code. --- sfall/FalloutEngine/EngineUtils.cpp | 4 ++++ sfall/FalloutEngine/EngineUtils.h | 2 ++ sfall/FalloutEngine/VariableOffsets.h | 1 + sfall/FalloutEngine/Variables_def.h | 3 ++- sfall/HRP/DeathScreen.cpp | 21 ++++++++++--------- sfall/HRP/HelpScreen.cpp | 14 ++++++------- sfall/HRP/Image.cpp | 14 ++++++------- sfall/HRP/Image.h | 2 ++ sfall/HRP/Init.cpp | 13 ++++++------ sfall/HRP/MainMenu.cpp | 29 ++++++++++++++++----------- sfall/HRP/MoviesScreen.cpp | 14 ++++++------- sfall/HRP/SlidesScreen.cpp | 1 + sfall/Modules/MainMenu.cpp | 2 +- 13 files changed, 69 insertions(+), 51 deletions(-) diff --git a/sfall/FalloutEngine/EngineUtils.cpp b/sfall/FalloutEngine/EngineUtils.cpp index 4d9b17d0..64c151e7 100644 --- a/sfall/FalloutEngine/EngineUtils.cpp +++ b/sfall/FalloutEngine/EngineUtils.cpp @@ -78,6 +78,10 @@ char* GetMsg(fo::MessageList* msgList, int msgNum, int msgType) { return nullptr; } +fo::Window* GetWindow(long winID) { + return fo::var::window[fo::var::window_index[winID]]; +} + fo::Queue* QueueFind(fo::GameObject* object, long type) { if (fo::var::queue) { fo::Queue* queue = fo::var::queue; diff --git a/sfall/FalloutEngine/EngineUtils.h b/sfall/FalloutEngine/EngineUtils.h index 4432d8b9..72e23fb0 100644 --- a/sfall/FalloutEngine/EngineUtils.h +++ b/sfall/FalloutEngine/EngineUtils.h @@ -54,6 +54,8 @@ fo::MessageNode* GetMsgNode(fo::MessageList* msgList, int msgNum); char* GetMsg(fo::MessageList* msgList, int msgNum, int msgType); +fo::Window* GetWindow(long winID); + fo::Queue* QueueFind(fo::GameObject* object, long type); // returns weapon animation code diff --git a/sfall/FalloutEngine/VariableOffsets.h b/sfall/FalloutEngine/VariableOffsets.h index 9d2e547a..3c49b9f3 100644 --- a/sfall/FalloutEngine/VariableOffsets.h +++ b/sfall/FalloutEngine/VariableOffsets.h @@ -61,6 +61,7 @@ #define FO_VAR_curr_font_num 0x51E3B0 #define FO_VAR_curr_pc_stat 0x6681AC #define FO_VAR_curr_stack 0x59E96C +#define FO_VAR_current_palette 0x6639D0 #define FO_VAR_currentProgram 0x59E78C #define FO_VAR_currentWindow 0x51DCB8 #define FO_VAR_cursor_line 0x664514 diff --git a/sfall/FalloutEngine/Variables_def.h b/sfall/FalloutEngine/Variables_def.h index 5efc3c60..4812ea30 100644 --- a/sfall/FalloutEngine/Variables_def.h +++ b/sfall/FalloutEngine/Variables_def.h @@ -21,7 +21,7 @@ VAR_(btncnt, DWORD) VARD(cap, fo::AIcap) // dynamic array VAR_(carCurrentArea, DWORD) VAR_(carGasAmount, long) // from 0 to 80000 -VARA(cmap, fo::PALETTE, 256) +VARA(cmap, fo::PALETTE, 256) // palette without gamma VAR_(colorTable, DWORD) VAR_(combat_end_due_to_load, DWORD) VAR_(combat_free_move, DWORD) @@ -41,6 +41,7 @@ VAR_(curr_anim_counter, DWORD) VAR_(curr_font_num, DWORD) VARA(curr_pc_stat, long, fo::PCSTAT_max_pc_stat) VAR_(curr_stack, DWORD) +VARA(current_palette, fo::PALETTE, 256) // current palette without gamma VAR_(currentProgram, fo::Program*) VAR_(cursor_line, DWORD) VAR_(DarkGreenColor, BYTE) diff --git a/sfall/HRP/DeathScreen.cpp b/sfall/HRP/DeathScreen.cpp index b640fd77..b648538f 100644 --- a/sfall/HRP/DeathScreen.cpp +++ b/sfall/HRP/DeathScreen.cpp @@ -51,18 +51,19 @@ static void __cdecl main_death_scene_hook_buf_to_buf(fo::FrmData* frm, long w, l } } yPosition = h; - Image::Scale(frm->frame.data, width, height, dst, w, h, Setting::ScreenWidth()); - return; - } - yPosition = height; - long y = (h - height) / 2; - long x = (w - width) / 2; - if (x || y) { - yPosition += y; - dst += x + (y * Setting::ScreenWidth()); + Image::Scale(frm->frame.data, width, height, dst, w, h, Setting::ScreenWidth()); + } else { + yPosition = height; + + long y = (h - height) / 2; + long x = (w - width) / 2; + if (x || y) { + yPosition += y; + dst += x + (y * Setting::ScreenWidth()); + } + fo::func::buf_to_buf(frm->frame.data, width, height, width, dst, Setting::ScreenWidth()); } - fo::func::buf_to_buf(frm->frame.data, width, height, width, dst, Setting::ScreenWidth()); } // Darkens a rectangle area for printing text diff --git a/sfall/HRP/HelpScreen.cpp b/sfall/HRP/HelpScreen.cpp index e577ca01..a96324b2 100644 --- a/sfall/HRP/HelpScreen.cpp +++ b/sfall/HRP/HelpScreen.cpp @@ -43,15 +43,15 @@ static void __cdecl game_help_hook_buf_to_buf(fo::FrmData* frm, long w, long h, Image::GetAspectSize(width, height, &x, &y, w, h); if (x || y) dst += x + (y * Setting::ScreenWidth()); } + Image::Scale(frm->frame.data, width, height, dst, w, h, Setting::ScreenWidth()); - return; + } else { + long y = (h - height) / 2; + long x = (w - width) / 2; + if (x || y) dst += x + (y * Setting::ScreenWidth()); + + fo::func::buf_to_buf(frm->frame.data, width, height, width, dst, Setting::ScreenWidth()); } - - long y = (h - height) / 2; - long x = (w - width) / 2; - if (x || y) dst += x + (y * Setting::ScreenWidth()); - - fo::func::buf_to_buf(frm->frame.data, width, height, width, dst, Setting::ScreenWidth()); } void HelpScreen::init() { diff --git a/sfall/HRP/Image.cpp b/sfall/HRP/Image.cpp index ffc2a038..cb24ebb5 100644 --- a/sfall/HRP/Image.cpp +++ b/sfall/HRP/Image.cpp @@ -163,8 +163,8 @@ struct BMPHEADER { }; #pragma pack(pop) -/* BMP 24-bit -bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pitch) { +// BMP 24-bit +bool Image::MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pitch) { long bmpExtraSize = width * 3 % 4; if (bmpExtraSize != 0) bmpExtraSize = 4 - bmpExtraSize; @@ -174,7 +174,7 @@ bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pi BMPHEADER bmpHeader; std::memset(&bmpHeader, 0, sizeof(BMPHEADER)); - bmpHeader.bFile.bfType = 'BM'; + bmpHeader.bFile.bfType = 'MB'; bmpHeader.bFile.bfSize = sizeImage + sizeof(BMPHEADER); bmpHeader.bFile.bfOffBits = sizeof(BMPHEADER); bmpHeader.bInfo.biSize = sizeof(BITMAPINFOHEADER); @@ -189,9 +189,9 @@ bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pi BYTE* dData = bmpImageData; // 32-bit to 24-bit - for (size_t h = 0; h < height; h++) { + for (long h = 0; h < height; h++) { BYTE* sData = dataRGB32; - for (size_t w = 0; w < width; w++) { + for (long w = 0; w < width; w++) { *dData++ = *sData++; *dData++ = *sData++; *dData++ = *sData++; @@ -201,7 +201,7 @@ bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pi dData += bmpExtraSize; } - HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); bool result = (hFile != INVALID_HANDLE_VALUE); if (result) { @@ -213,6 +213,6 @@ bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pi delete[] bmpImageData; return result; -}*/ +} } diff --git a/sfall/HRP/Image.h b/sfall/HRP/Image.h index a08b3e45..3faf717f 100644 --- a/sfall/HRP/Image.h +++ b/sfall/HRP/Image.h @@ -17,6 +17,8 @@ public: static void Scale(BYTE* src, long sWight, long sHeight, BYTE* dst, long dWight, long dHeight, long dPitch = 0, long sPitch = 0); static void ScaleText(BYTE* dst, const char* text, long txtWidth, long dstWidth, long colorFlags, float scaleFactor); + + static bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pitch); }; } diff --git a/sfall/HRP/Init.cpp b/sfall/HRP/Init.cpp index ecb313df..788ec7b5 100644 --- a/sfall/HRP/Init.cpp +++ b/sfall/HRP/Init.cpp @@ -90,11 +90,12 @@ bool Setting::ExternalEnabled() { static std::string GetBackupFileName(const char* runFileName, bool wait) { std::string bakExeName(runFileName); size_t n = bakExeName.rfind('.'); - if (n != std::string::npos) { - bakExeName.replace(n, 4, ".hrp"); - char c = 10; - while (std::remove(bakExeName.c_str()) != 0 && wait && --c) Sleep(1000); // delete .hrp (if it exists) - } + if (n == std::string::npos) return std::string(); // empty + + bakExeName.replace(n, 4, ".hrp"); + char c = 10; + while (std::remove(bakExeName.c_str()) != 0 && wait && --c) Sleep(1000); // delete .hrp (if it exists) + return bakExeName; } @@ -121,7 +122,7 @@ static bool DisableExtHRP(const char* runFileName, std::string &cmdline) { std::fclose(ft); cmdline.append(" -restart"); - MessageBoxA(0, "High Resolution Patch has been successfully deactivated.", "sfall", MB_TASKMODAL | MB_ICONINFORMATION); + //MessageBoxA(0, "High Resolution Patch has been successfully deactivated.", "sfall", MB_TASKMODAL | MB_ICONINFORMATION); ShellExecuteA(0, 0, runFileName, cmdline.c_str(), 0, SW_SHOWDEFAULT); // restart game return true; diff --git a/sfall/HRP/MainMenu.cpp b/sfall/HRP/MainMenu.cpp index 46463543..5b75140c 100644 --- a/sfall/HRP/MainMenu.cpp +++ b/sfall/HRP/MainMenu.cpp @@ -43,7 +43,7 @@ static long offsetX = 0, offsetY = 0; // draw image to main menu window static void __cdecl main_menu_create_hook_buf_to_buf(BYTE* src, long sw, long sh, long srcW, BYTE* dst, long dstW) { - fo::Window* win = fo::var::window[fo::var::main_window]; // the window size is always equal to the scaled image + fo::Window* win = fo::util::GetWindow(fo::var::main_window); // the window size is always equal to the scaled image long h = win->height; long w = win->width; dstW = w; @@ -113,18 +113,17 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, } } - if (MainMenuScreen::MAIN_MENU_SIZE == 1 || sw > Setting::ScreenWidth() || sh > Setting::ScreenHeight()) { + if (MainMenuScreen::MAIN_MENU_SIZE || sw > Setting::ScreenWidth() || sh > Setting::ScreenHeight()) { // out size w = Setting::ScreenWidth(); h = Setting::ScreenHeight(); - Image::GetAspectSize(sw, sh, &x, &y, w, h); + if (MainMenuScreen::MAIN_MENU_SIZE <= 1) { + Image::GetAspectSize(sw, sh, &x, &y, w, h); - if (w > Setting::ScreenWidth()) w = Setting::ScreenWidth(); - if (h > Setting::ScreenHeight()) h = Setting::ScreenHeight(); - } else if (MainMenuScreen::MAIN_MENU_SIZE == 2) { - h = Setting::ScreenHeight(); - w = Setting::ScreenWidth(); + if (w > Setting::ScreenWidth()) w = Setting::ScreenWidth(); + if (h > Setting::ScreenHeight()) h = Setting::ScreenHeight(); + } } else { // centering x = (Setting::ScreenWidth() - w) / 2; @@ -140,8 +139,14 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, if (MainMenuScreen::USE_HIRES_IMAGES == false || (MainMenuScreen::USE_HIRES_IMAGES && MainMenuScreen::SCALE_BUTTONS_AND_TEXT_MENU)) { scaleFactor = scaleHeight; } else { - if (w != 640) offsetX = (long)(6.0f * (Setting::ScreenWidth() * 0.0015625)); - if (h != 480) offsetY = (long)(4.0f * (Setting::ScreenHeight() * 0.0020833334f)); + if (w != 640) { + float diff = (Setting::ScreenWidth() / 640.0f); + offsetX = (long)((8.0f * (diff * diff))); + } + if (h != 480) { + float diff = (Setting::ScreenHeight() / 480.0f); + offsetY = (long)((6.0f * (diff * diff))); + } } sf::MainMenu::mTextOffset = offsetX; @@ -158,7 +163,7 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, } static long __fastcall GetHeightOffset(long &y) { - long h = fo::var::window[fo::var::main_window]->height; + long h = fo::util::GetWindow(fo::var::main_window)->height; y = ((y - 460) - 20) + h; if (y > h) { y = h - 10; @@ -237,7 +242,7 @@ static long __fastcall ButtonPosition(long &width, long xPos, BYTE* &upImageData xPos = (long)(xPos * scaleFactor); } - long h = fo::var::window[fo::var::main_window]->height; + long h = fo::util::GetWindow(fo::var::main_window)->height; /*** Button position ***/ xPos += (long)(sf::MainMenu::mXOffset * scaleWidth) + offsetX; diff --git a/sfall/HRP/MoviesScreen.cpp b/sfall/HRP/MoviesScreen.cpp index 022c0675..57cc65c2 100644 --- a/sfall/HRP/MoviesScreen.cpp +++ b/sfall/HRP/MoviesScreen.cpp @@ -30,7 +30,13 @@ static void __fastcall SetMovieSize() { long subtitleHeight = (fo::var::getInt(FO_VAR_subtitles) && fo::var::getInt(FO_VAR_subtitleList)) ? fo::var::getInt(FO_VAR_subtitleH) + 4 : 0; - if (MoviesScreen::MOVIE_SIZE == 1 || bW > sWidth || bH > sHeight) { + if (MoviesScreen::MOVIE_SIZE == 2) { + movieToSize.top = 0; + movieToSize.bottom = Setting::ScreenHeight() - subtitleHeight; + + movieToSize.left = 0; + movieToSize.right = Setting::ScreenWidth(); + } else if (MoviesScreen::MOVIE_SIZE == 1 || bW > sWidth || bH > sHeight) { long aspectW = sWidth; long aspectH = sHeight; long x = 0; @@ -41,12 +47,6 @@ static void __fastcall SetMovieSize() { movieToSize.top = y; movieToSize.right = x + aspectW; movieToSize.bottom = y + aspectH; - } else if (MoviesScreen::MOVIE_SIZE == 2) { - movieToSize.top = 0; - movieToSize.bottom = Setting::ScreenHeight() - subtitleHeight; - - movieToSize.left = 0; - movieToSize.right = Setting::ScreenWidth(); } else { // set to center movieToSize.top = (Setting::ScreenHeight() - bH) / 2; diff --git a/sfall/HRP/SlidesScreen.cpp b/sfall/HRP/SlidesScreen.cpp index 40782c67..ae6564b9 100644 --- a/sfall/HRP/SlidesScreen.cpp +++ b/sfall/HRP/SlidesScreen.cpp @@ -60,6 +60,7 @@ static void __cdecl endgame_display_image_hook_buf_to_buf(BYTE* src, long w, lon if (x || y) dst += x + (y * Setting::ScreenWidth()); } bottomPos = h; + Image::Scale(src, width, height, dst, w, h, Setting::ScreenWidth()); } else { bottomPos = height; diff --git a/sfall/Modules/MainMenu.cpp b/sfall/Modules/MainMenu.cpp index c9d47673..9d0732a4 100644 --- a/sfall/Modules/MainMenu.cpp +++ b/sfall/Modules/MainMenu.cpp @@ -59,7 +59,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 (!HRP::Setting::ExternalEnabled() && HRP::Setting::IsEnabled()) { - fo::Window* win = fo::var::window[winId]; + fo::Window* win = fo::util::GetWindow(winId); yPos = ((yPos - 460) - 20) + win->height; xPos = ((xPos - 615) - 25) + win->width; }