@@ -90,13 +90,13 @@ int iLauncherConfigMSXWallType = 0;
9090std::string sLauncherConfigMSXWallAlign = " C" ;
9191
9292// Aspect ratio + HUD stuff
93- float fNativeAspect = ( float ) 16 / 9 ;
93+ constexpr float fNativeAspect = 16 . 0f / 9 . 0f ;
9494float fAspectRatio ;
9595float fAspectMultiplier ;
9696float fHUDWidth ;
9797float fHUDHeight ;
98- float fDefaultHUDWidth = ( float ) 1280 ;
99- float fDefaultHUDHeight = ( float ) 720 ;
98+ constexpr float fDefaultHUDWidth = 1280 ;
99+ constexpr float fDefaultHUDHeight = 720 ;
100100float fHUDWidthOffset ;
101101float fHUDHeightOffset ;
102102float fMGS2_EffectScaleX ;
@@ -173,7 +173,7 @@ HWND WINAPI CreateWindowExA_hooked(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR l
173173 return MainHwnd;
174174}
175175
176- void Init_CalculateScreenSize ()
176+ static void Init_CalculateScreenSize ()
177177{
178178 // Calculate aspect ratio
179179 fAspectRatio = (float )iInternalResX / (float )iInternalResY;
@@ -203,7 +203,7 @@ void Init_CalculateScreenSize()
203203}
204204
205205
206- void Init_ReadConfig ()
206+ static void Init_ReadConfig ()
207207{
208208 // Initialise config
209209 std::ifstream iniFile ((sExePath / sFixPath / sConfigFile ).string ());
@@ -355,7 +355,7 @@ void Init_ReadConfig()
355355
356356}
357357
358- bool DetectGame ()
358+ static bool DetectGame ()
359359{
360360 eGameType = UNKNOWN ;
361361 // Special handling for launcher.exe
@@ -398,7 +398,7 @@ bool DetectGame()
398398 FreeLibraryAndExitThread (baseModule, 1 );
399399}
400400
401- void Init_FixDPIScaling ()
401+ static void Init_FixDPIScaling ()
402402{
403403 if (eGameType & (MG |MGS2 |MGS3 ))
404404 {
@@ -407,14 +407,14 @@ void Init_FixDPIScaling()
407407 }
408408}
409409
410- void Init_CustomResolution ()
410+ static void Init_CustomResolution ()
411411{
412412 if (eGameType & (MG |MGS2 |MGS3 ) && bOutputResolution)
413413 {
414414 // MGS 2 | MGS 3: Custom Resolution
415- uint8_t * MGS2_MGS3_InternalResolutionScanResult = Memory::PatternScan (baseModule, " F2 0F ?? ?? ?? B9 05 00 00 00 E8 ?? ?? ?? ?? 85 ?? 75 ??" , " MGS2_MGS3_InternalResolutionScan" , NULL , NULL );
416- uint8_t * MGS2_MGS3_OutputResolution1ScanResult = Memory::PatternScan (baseModule, " 40 ?? ?? 74 ?? 8B ?? ?? ?? ?? ?? 8B ?? ?? ?? ?? ?? EB ?? B9 06 00 00 00" , " MGS2_MGS3_OutputResolution1Scan" , NULL , NULL );
417- uint8_t * MGS2_MGS3_OutputResolution2ScanResult = Memory::PatternScan (baseModule, " 80 ?? ?? 00 41 ?? ?? ?? ?? ?? 48 ?? ?? ?? BA ?? ?? ?? ?? 8B ??" , " MGS2_MGS3_OutputResolution2Scan" , NULL , NULL );
415+ uint8_t * MGS2_MGS3_InternalResolutionScanResult = Memory::PatternScan (baseModule, " F2 0F ?? ?? ?? B9 05 00 00 00 E8 ?? ?? ?? ?? 85 ?? 75 ??" , " MGS2_MGS3_InternalResolutionScan" );
416+ uint8_t * MGS2_MGS3_OutputResolution1ScanResult = Memory::PatternScan (baseModule, " 40 ?? ?? 74 ?? 8B ?? ?? ?? ?? ?? 8B ?? ?? ?? ?? ?? EB ?? B9 06 00 00 00" , " MGS2_MGS3_OutputResolution1Scan" );
417+ uint8_t * MGS2_MGS3_OutputResolution2ScanResult = Memory::PatternScan (baseModule, " 80 ?? ?? 00 41 ?? ?? ?? ?? ?? 48 ?? ?? ?? BA ?? ?? ?? ?? 8B ??" , " MGS2_MGS3_OutputResolution2Scan" );
418418 if (MGS2_MGS3_InternalResolutionScanResult && MGS2_MGS3_OutputResolution1ScanResult && MGS2_MGS3_OutputResolution2ScanResult)
419419 {
420420 uint8_t * MGS2_MGS3_FSR_Result = Memory::PatternScanSilent (baseModule, " 83 E8 ?? 74 ?? 83 E8 ?? 74 ?? 83 F8 ?? 75 ?? C7 06" );
@@ -541,7 +541,7 @@ void Init_CustomResolution()
541541 }
542542
543543 // MG 1/2 | MGS 2 | MGS 3: WindowedMode
544- if (uint8_t * MGS2_MGS3_WindowedModeScanResult = Memory::PatternScan (baseModule, " 48 ?? ?? E8 ?? ?? ?? ?? 84 ?? 0F 84 ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ?? 41 ?? 03 00 00 00" , " WindowedMode" , NULL , NULL ))
544+ if (uint8_t * MGS2_MGS3_WindowedModeScanResult = Memory::PatternScan (baseModule, " 48 ?? ?? E8 ?? ?? ?? ?? 84 ?? 0F 84 ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ?? 41 ?? 03 00 00 00" , " WindowedMode" ))
545545 {
546546 static SafetyHookMid WindowedModeMidHook{};
547547 WindowedModeMidHook = safetyhook::create_mid (MGS2_MGS3_WindowedModeScanResult,
@@ -565,7 +565,7 @@ void Init_CustomResolution()
565565 spdlog::info (" MG/MG2 | MGS 2 | MGS 3: CreateWindowExA: Hooked function." );
566566
567567 // MG 1/2 | MGS 2 | MGS 3: SetWindowPos
568- if (uint8_t * MGS2_MGS3_SetWindowPosScanResult = Memory::PatternScan (baseModule, " 33 ?? 48 ?? ?? ?? FF ?? ?? ?? ?? ?? 8B ?? ?? BA 02 00 00 00" , " SetWindowPos" , NULL , NULL ))
568+ if (uint8_t * MGS2_MGS3_SetWindowPosScanResult = Memory::PatternScan (baseModule, " 33 ?? 48 ?? ?? ?? FF ?? ?? ?? ?? ?? 8B ?? ?? BA 02 00 00 00" , " SetWindowPos" ))
569569 {
570570 static SafetyHookMid SetWindowPosMidHook{};
571571 SetWindowPosMidHook = safetyhook::create_mid (MGS2_MGS3_SetWindowPosScanResult,
@@ -612,7 +612,7 @@ void Init_CustomResolution()
612612
613613 // Windowed framebuffer
614614
615- if (uint8_t * MGS2_MGS3_WindowedFramebufferFixScanResult = Memory::PatternScan (baseModule, " ?? ?? F3 0F ?? ?? 41 ?? ?? F3 0F ?? ?? F3 0F ?? ?? 66 0F ?? ?? 0F ?? ??" , " Windowed Framebuffer" , NULL , NULL ))
615+ if (uint8_t * MGS2_MGS3_WindowedFramebufferFixScanResult = Memory::PatternScan (baseModule, " ?? ?? F3 0F ?? ?? 41 ?? ?? F3 0F ?? ?? F3 0F ?? ?? 66 0F ?? ?? 0F ?? ??" , " Windowed Framebuffer" ))
616616 {
617617 Memory::PatchBytes ((uintptr_t )MGS2_MGS3_WindowedFramebufferFixScanResult, " \xEB " , 1 );
618618 if (eGameType & MG |MGS3 )
@@ -632,7 +632,7 @@ void Init_CustomResolution()
632632 /*
633633 float WidescreenRes = (float)(iOutputResY * 16) / 9;
634634
635- if (uint8_t* MGS2_MGS3_ViewportScanResult = Memory::PatternScan(baseModule, "48 83 EC ?? 48 8B 05 ?? ?? ?? ?? 4C 8B C2", "MGS 2 | MGS 3: CD3DCachedDevice::SetViewport", NULL, NULL ))
635+ if (uint8_t* MGS2_MGS3_ViewportScanResult = Memory::PatternScan(baseModule, "48 83 EC ?? 48 8B 05 ?? ?? ?? ?? 4C 8B C2", "MGS 2 | MGS 3: CD3DCachedDevice::SetViewport"))
636636 {
637637 static SafetyHookMid Viewport_MidHook {};
638638 Viewport_MidHook = safetyhook::create_mid(MGS2_MGS3_ViewportScanResult,
@@ -673,7 +673,7 @@ void Init_CustomResolution()
673673}
674674
675675
676- void Init_ScaleEffects ()
676+ static void Init_ScaleEffects ()
677677{
678678 if ((eGameType & (MGS2 |MGS3 )) && bOutputResolution)
679679 {
@@ -759,13 +759,13 @@ void Init_ScaleEffects()
759759
760760
761761
762- void Init_AspectFOVFix ()
762+ static void Init_AspectFOVFix ()
763763{
764764 // Fix aspect ratio
765765 if (eGameType & MGS3 && bAspectFix)
766766 {
767767 // MGS 3: Fix gameplay aspect ratio
768- if (uint8_t * MGS3_GameplayAspectScanResult = Memory::PatternScan (baseModule, " F3 0F ?? ?? E8 ?? ?? ?? ?? 48 8D ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ??" , " MGS 3: Aspect Ratio" , NULL , NULL ))
768+ if (uint8_t * MGS3_GameplayAspectScanResult = Memory::PatternScan (baseModule, " F3 0F ?? ?? E8 ?? ?? ?? ?? 48 8D ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ??" , " MGS 3: Aspect Ratio" ))
769769 {
770770 DWORD64 MGS3_GameplayAspectAddress = Memory::GetAbsolute ((uintptr_t )MGS3_GameplayAspectScanResult + 0x5 );
771771 spdlog::info (" MGS 3: Aspect Ratio: Function address is {:s}+{:x}" , sExeName .c_str (), (uintptr_t )MGS3_GameplayAspectAddress - (uintptr_t )baseModule);
@@ -776,14 +776,14 @@ void Init_AspectFOVFix()
776776 {
777777 ctx.xmm1 .f32 [0 ] /= fAspectMultiplier ;
778778 });
779- LOG_HOOK (MGS3_GameplayAspectMidHook, " MGS 3: Aspect Ratio" , NULL , NULL )
779+ LOG_HOOK (MGS3_GameplayAspectMidHook, " MGS 3: Aspect Ratio" )
780780
781781 }
782782 }
783783 else if (eGameType & MGS2 && bAspectFix)
784784 {
785785 // MGS 2: Fix gameplay aspect ratio
786- if (uint8_t * MGS2_GameplayAspectScanResult = Memory::PatternScan (baseModule, " 48 8D ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? F3 44 ?? ?? ?? ?? ?? ?? ??" , " MGS 2: Aspect Ratio" , NULL , NULL ))
786+ if (uint8_t * MGS2_GameplayAspectScanResult = Memory::PatternScan (baseModule, " 48 8D ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? F3 44 ?? ?? ?? ?? ?? ?? ??" , " MGS 2: Aspect Ratio" ))
787787 {
788788 DWORD64 MGS2_GameplayAspectAddress = Memory::GetAbsolute ((uintptr_t )MGS2_GameplayAspectScanResult + 0xB );
789789 spdlog::info (" MGS 2: Aspect Ratio: Function address is {:s}+{:x}" , sExeName .c_str (), (uintptr_t )MGS2_GameplayAspectAddress - (uintptr_t )baseModule);
@@ -794,15 +794,15 @@ void Init_AspectFOVFix()
794794 {
795795 ctx.xmm0 .f32 [0 ] /= fAspectMultiplier ;
796796 });
797- LOG_HOOK (MGS2_GameplayAspectMidHook, " MGS 2: Aspect Ratio" , NULL , NULL )
797+ LOG_HOOK (MGS2_GameplayAspectMidHook, " MGS 2: Aspect Ratio" )
798798 }
799799 }
800800
801801 // Convert FOV to vert- to match 16:9 horizontal field of view
802802 if (eGameType & MGS3 && bFOVFix)
803803 {
804804 // MGS 3: FOV
805- if (uint8_t * MGS3_FOVScanResult = Memory::PatternScan (baseModule, " F3 0F ?? ?? ?? ?? ?? ?? 44 ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? F3 ?? ?? ?? ?? E8 ?? ?? ?? ??" , " MGS 3: FOV" , NULL , NULL ))
805+ if (uint8_t * MGS3_FOVScanResult = Memory::PatternScan (baseModule, " F3 0F ?? ?? ?? ?? ?? ?? 44 ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? F3 ?? ?? ?? ?? E8 ?? ?? ?? ??" , " MGS 3: FOV" ))
806806 {
807807 static SafetyHookMid MGS3_FOVMidHook{};
808808 MGS3_FOVMidHook = safetyhook::create_mid (MGS3_FOVScanResult,
@@ -813,13 +813,13 @@ void Init_AspectFOVFix()
813813 ctx.xmm2 .f32 [0 ] *= fAspectMultiplier ;
814814 }
815815 });
816- LOG_HOOK (MGS3_FOVMidHook, " MG3 2: FOV" , NULL , NULL )
816+ LOG_HOOK (MGS3_FOVMidHook, " MG3 2: FOV" )
817817 }
818818 }
819819 else if (eGameType & MGS2 && bFOVFix)
820820 {
821821 // MGS 2: FOV
822- if (uint8_t * MGS2_FOVScanResult = Memory::PatternScan (baseModule, " 44 ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 44 ?? ?? ?? ?? 48 ?? ?? 48 ?? ?? ?? ?? 00 00" , " MGS 2: FOV" , NULL , NULL ))
822+ if (uint8_t * MGS2_FOVScanResult = Memory::PatternScan (baseModule, " 44 ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 44 ?? ?? ?? ?? 48 ?? ?? 48 ?? ?? ?? ?? 00 00" , " MGS 2: FOV" ))
823823 {
824824 static SafetyHookMid MGS2_FOVMidHook{};
825825 MGS2_FOVMidHook = safetyhook::create_mid (MGS2_FOVScanResult,
@@ -830,14 +830,14 @@ void Init_AspectFOVFix()
830830 ctx.xmm2 .f32 [0 ] *= fAspectMultiplier ;
831831 }
832832 });
833- LOG_HOOK (MGS2_FOVMidHook, " MGS 2: FOV" , NULL , NULL )
833+ LOG_HOOK (MGS2_FOVMidHook, " MGS 2: FOV" )
834834 }
835835
836836 }
837837
838838}
839839
840- void Init_HUDFix ()
840+ static void Init_HUDFix ()
841841{
842842 if (eGameType & MGS2 && bHUDFix)
843843 {
@@ -1010,15 +1010,15 @@ void Init_HUDFix()
10101010
10111011}
10121012
1013- void Init_Miscellaneous ()
1013+ static void Init_Miscellaneous ()
10141014{
10151015 if (eGameType & (MG |MGS2 |MGS3 |LAUNCHER ))
10161016 {
10171017 if (bDisableCursor)
10181018 {
10191019 // Launcher | MG/MG2 | MGS 2 | MGS 3: Disable mouse cursor
10201020 // Thanks again emoose!
1021- if (uint8_t * MGS2_MGS3_MouseCursorScanResult = Memory::PatternScan (eGameType & LAUNCHER ? unityPlayer : baseModule, " BA 00 7F 00 00 33 ?? FF ?? ?? ?? ?? ?? 48 ?? ??" , " Launcher | MG/MG2 | MGS 2 | MGS 3: Mouse Cursor" , NULL , NULL ))
1021+ if (uint8_t * MGS2_MGS3_MouseCursorScanResult = Memory::PatternScan (eGameType & LAUNCHER ? unityPlayer : baseModule, " BA 00 7F 00 00 33 ?? FF ?? ?? ?? ?? ?? 48 ?? ??" , " Launcher | MG/MG2 | MGS 2 | MGS 3: Mouse Cursor" ))
10221022 {
10231023 // The game enters 32512 in the RDX register for the function USER32.LoadCursorA to load IDC_ARROW (normal select arrow in windows)
10241024 // Set this to 0 and no cursor icon is loaded
@@ -1030,7 +1030,7 @@ void Init_Miscellaneous()
10301030
10311031 if ((bDisableTextureFiltering || iAnisotropicFiltering > 0 ) && (eGameType & (MGS2 |MGS3 )))
10321032 {
1033- if (uint8_t * MGS3_SetSamplerStateInsnScanResult = Memory::PatternScan (baseModule, " 48 8B ?? ?? ?? ?? ?? 44 39 ?? ?? 38 ?? ?? ?? 74 ?? 44 89 ?? ?? ?? ?? ?? ?? EB ?? 48 ?? ??" , " MGS 2 | MGS 3: Texture Filtering" , NULL , NULL ))
1033+ if (uint8_t * MGS3_SetSamplerStateInsnScanResult = Memory::PatternScan (baseModule, " 48 8B ?? ?? ?? ?? ?? 44 39 ?? ?? 38 ?? ?? ?? 74 ?? 44 89 ?? ?? ?? ?? ?? ?? EB ?? 48 ?? ??" , " MGS 2 | MGS 3: Texture Filtering" ))
10341034 {
10351035 static SafetyHookMid SetSamplerStateInsnXMidHook{};
10361036 SetSamplerStateInsnXMidHook = safetyhook::create_mid (MGS3_SetSamplerStateInsnScanResult + 0x7 ,
@@ -1044,7 +1044,7 @@ void Init_Miscellaneous()
10441044 // 0x1 = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR (Linear mips is essentially perspective correction.) 0x55 = D3D11_FILTER_ANISOTROPIC
10451045 ctx.r9 = bDisableTextureFiltering ? 0x1 : 0x55 ;
10461046 });
1047- LOG_HOOK (SetSamplerStateInsnXMidHook, " MGS 2 | MGS 3: Texture Filtering" , NULL , NULL )
1047+ LOG_HOOK (SetSamplerStateInsnXMidHook, " MGS 2 | MGS 3: Texture Filtering" )
10481048 }
10491049
10501050 }
@@ -1103,7 +1103,7 @@ void __fastcall MGS2_COsContext_InitializeSKUandLang_Hook(void* thisptr, int lan
11031103 MGS2_COsContext_InitializeSKUandLang (thisptr, iLauncherConfigLanguage);
11041104}
11051105
1106- void Init_LauncherConfigOverride ()
1106+ static void Init_LauncherConfigOverride ()
11071107{
11081108 // If we know games steam appid, try creating steam_appid.txt file, so that game EXE can be launched directly in future runs
11091109 if (game)
@@ -1313,7 +1313,7 @@ void Init_LauncherConfigOverride()
13131313 }
13141314 if (bIsPS2controltype)
13151315 {
1316- if (uint8_t * PS4ControllerScan = Memory::PatternScan (baseModule, " 6F 76 72 5F 73 74 6D 2F 63 74 72 6C 74 79 70 65 5F 70 73 34 2F" , " PS4 Controller Glyphs" , NULL , NULL ))
1316+ if (uint8_t * PS4ControllerScan = Memory::PatternScan (baseModule, " 6F 76 72 5F 73 74 6D 2F 63 74 72 6C 74 79 70 65 5F 70 73 34 2F" , " PS4 Controller Glyphs" ))
13171317 {
13181318 Memory::PatchBytes ((uintptr_t )PS4ControllerScan, " \x6F\x76\x72\x5F\x73\x74\x6D\x2F\x63\x74\x72\x6C\x74\x79\x70\x65\x5F\x70\x73\x32\x2F " , 21 );
13191319 spdlog::info (" MG/MG2 | MGS 2 | MGS 3: Launcher Config: Patched PS4 controller glyphs to PS2 glyphs." );
@@ -1356,7 +1356,7 @@ void afterD3D11CreateDevice()
13561356}
13571357
13581358
1359- void InitializeSubsystems ()
1359+ static void InitializeSubsystems ()
13601360{
13611361 // Initialization order (these systems initialize vars used by following ones.)
13621362 INITIALIZE (g_Logging.LogSysInfo ()); // 0
@@ -1411,29 +1411,17 @@ DWORD __stdcall Main(void*)
14111411}
14121412
14131413
1414- BOOL APIENTRY DllMain (HMODULE hModule,
1415- DWORD ul_reason_for_call,
1416- LPVOID lpReserved
1417- )
1414+ BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
14181415{
1419- switch (ul_reason_for_call)
1416+ if (ul_reason_for_call == DLL_PROCESS_ATTACH )
14201417 {
1421- case DLL_PROCESS_ATTACH :
1422- {
1423- HANDLE mainHandle = CreateThread (NULL , 0 , Main, 0 , CREATE_SUSPENDED , 0 );
1424- if (mainHandle)
1418+ if (const HANDLE mainHandle = CreateThread (NULL , 0 , Main, 0 , CREATE_SUSPENDED , 0 ))
14251419 {
14261420 SetThreadPriority (mainHandle, THREAD_PRIORITY_TIME_CRITICAL ); // set our Main thread priority higher than the games thread
14271421 ResumeThread (mainHandle);
14281422 CloseHandle (mainHandle);
14291423 }
14301424 SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED ); // fixes the monitor going to sleep during cutscenes.
1431- break ;
1432- }
1433- case DLL_THREAD_ATTACH :
1434- case DLL_THREAD_DETACH :
1435- case DLL_PROCESS_DETACH :
1436- break ;
14371425 }
14381426 return TRUE ;
14391427}
0 commit comments