├── .clangd ├── .gitattributes ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── MGSFPSUnlock.sln ├── MGSFPSUnlock ├── MGS2 │ ├── mgs2.cpp │ └── mgs2.h ├── MGS3 │ ├── mgs3.cpp │ └── mgs3.h ├── MGSFPSUnlock.filters ├── MGSFPSUnlock.vcxproj ├── MGSFPSUnlock.vcxproj.filters ├── Memory.cpp ├── Utils.cpp ├── dllmain.cpp └── includes │ ├── Memory.h │ ├── MinHook.h │ ├── Utils.h │ ├── config.h │ ├── ini.h │ └── stdafx.h ├── README.md └── mingw-toolchain.cmake /.clangd: -------------------------------------------------------------------------------- 1 | CompileFlags: 2 | Add: [ 3 | "-IMGSFPSUnlock/includes", 4 | ] -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | build 7 | .vscode 8 | 9 | # User-specific files 10 | *.rsuser 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # User-specific files (MonoDevelop/Xamarin Studio) 17 | *.userprefs 18 | 19 | # Mono auto generated files 20 | mono_crash.* 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | [Ww][Ii][Nn]32/ 30 | [Aa][Rr][Mm]/ 31 | [Aa][Rr][Mm]64/ 32 | bld/ 33 | [Bb]in/ 34 | [Oo]bj/ 35 | [Ll]og/ 36 | [Ll]ogs/ 37 | 38 | # Visual Studio 2015/2017 cache/options directory 39 | .vs/ 40 | # Uncomment if you have tasks that create the project's static files in wwwroot 41 | #wwwroot/ 42 | 43 | # Visual Studio 2017 auto generated files 44 | Generated\ Files/ 45 | 46 | # MSTest test Results 47 | [Tt]est[Rr]esult*/ 48 | [Bb]uild[Ll]og.* 49 | 50 | # NUnit 51 | *.VisualState.xml 52 | TestResult.xml 53 | nunit-*.xml 54 | 55 | # Build Results of an ATL Project 56 | [Dd]ebugPS/ 57 | [Rr]eleasePS/ 58 | dlldata.c 59 | 60 | # Benchmark Results 61 | BenchmarkDotNet.Artifacts/ 62 | 63 | # .NET Core 64 | project.lock.json 65 | project.fragment.lock.json 66 | artifacts/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.tlog 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 301 | *.vbp 302 | 303 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 304 | *.dsw 305 | *.dsp 306 | 307 | # Visual Studio 6 technical files 308 | *.ncb 309 | *.aps 310 | 311 | # Visual Studio LightSwitch build output 312 | **/*.HTMLClient/GeneratedArtifacts 313 | **/*.DesktopClient/GeneratedArtifacts 314 | **/*.DesktopClient/ModelManifest.xml 315 | **/*.Server/GeneratedArtifacts 316 | **/*.Server/ModelManifest.xml 317 | _Pvt_Extensions 318 | 319 | # Paket dependency manager 320 | .paket/paket.exe 321 | paket-files/ 322 | 323 | # FAKE - F# Make 324 | .fake/ 325 | 326 | # CodeRush personal settings 327 | .cr/personal 328 | 329 | # Python Tools for Visual Studio (PTVS) 330 | __pycache__/ 331 | *.pyc 332 | 333 | # Cake - Uncomment if you are using it 334 | # tools/** 335 | # !tools/packages.config 336 | 337 | # Tabs Studio 338 | *.tss 339 | 340 | # Telerik's JustMock configuration file 341 | *.jmconfig 342 | 343 | # BizTalk build output 344 | *.btp.cs 345 | *.btm.cs 346 | *.odx.cs 347 | *.xsd.cs 348 | 349 | # OpenCover UI analysis results 350 | OpenCover/ 351 | 352 | # Azure Stream Analytics local run output 353 | ASALocalRun/ 354 | 355 | # MSBuild Binary and Structured Log 356 | *.binlog 357 | 358 | # NVidia Nsight GPU debugger configuration file 359 | *.nvuser 360 | 361 | # MFractors (Xamarin productivity tool) working folder 362 | .mfractor/ 363 | 364 | # Local History for Visual Studio 365 | .localhistory/ 366 | 367 | # Visual Studio History (VSHistory) files 368 | .vshistory/ 369 | 370 | # BeatPulse healthcheck temp database 371 | healthchecksdb 372 | 373 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 374 | MigrationBackup/ 375 | 376 | # Ionide (cross platform F# VS Code tools) working folder 377 | .ionide/ 378 | 379 | # Fody - auto-generated XML schema 380 | FodyWeavers.xsd 381 | 382 | # VS Code files for those working on multiple tools 383 | .vscode/* 384 | !.vscode/settings.json 385 | !.vscode/tasks.json 386 | !.vscode/launch.json 387 | !.vscode/extensions.json 388 | *.code-workspace 389 | 390 | # Local History for Visual Studio Code 391 | .history/ 392 | 393 | # Windows Installer files from build outputs 394 | *.cab 395 | *.msi 396 | *.msix 397 | *.msm 398 | *.msp 399 | 400 | # JetBrains Rider 401 | *.sln.iml 402 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/spdlog"] 2 | path = external/spdlog 3 | url = https://github.com/gabime/spdlog 4 | [submodule "external/minhook"] 5 | path = external/minhook 6 | url = https://github.com/TsudaKageyu/minhook.git 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(CMAKE_SYSTEM_NAME Windows) 4 | set(CMAKE_BUILD_TYPE Release) 5 | set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/mingw-toolchain.cmake" CACHE STRING "Toolchain file for MinGW") 6 | 7 | project(MGSFPSUnlock VERSION 1.0 LANGUAGES CXX) 8 | 9 | if(MINGW) 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64") 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") 12 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64 -static") 13 | endif() 14 | 15 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") 16 | 17 | add_library(MGSFPSUnlock SHARED 18 | MGSFPSUnlock/dllmain.cpp 19 | MGSFPSUnlock/Memory.cpp 20 | MGSFPSUnlock/MGS2/mgs2.cpp 21 | MGSFPSUnlock/MGS3/mgs3.cpp 22 | MGSFPSUnlock/Utils.cpp 23 | ) 24 | 25 | set(MINHOOK_BUILD_SHARED OFF CACHE BOOL "Build MinHook as a shared library" FORCE) 26 | set(MINHOOK_BUILD_STATIC ON CACHE BOOL "Build MinHook as a static library" FORCE) 27 | add_subdirectory(external/minhook) 28 | 29 | target_include_directories(MGSFPSUnlock PRIVATE 30 | ${CMAKE_CURRENT_SOURCE_DIR}/MGSFPSUnlock/includes 31 | ${CMAKE_CURRENT_SOURCE_DIR}/MGSFPSUnlock/MGS2 32 | ${CMAKE_CURRENT_SOURCE_DIR}/MGSFPSUnlock/MGS3 33 | ${CMAKE_CURRENT_SOURCE_DIR}/external/spdlog/include 34 | ${CMAKE_CURRENT_SOURCE_DIR}/external/minhook/include 35 | ) 36 | 37 | target_compile_definitions(MGSFPSUnlock PRIVATE 38 | _WINDOWS 39 | _USRDLL 40 | MGS3FPSUNLOCK_EXPORTS 41 | NDEBUG 42 | ) 43 | 44 | target_compile_options(MGSFPSUnlock PRIVATE -fpermissive) 45 | 46 | set_target_properties(MGSFPSUnlock PROPERTIES 47 | CXX_STANDARD 17 48 | CXX_STANDARD_REQUIRED YES 49 | CXX_EXTENSIONS NO 50 | PREFIX "" 51 | OUTPUT_NAME "MGSFPSUnlock" 52 | SUFFIX ".asi" 53 | ) 54 | 55 | target_link_libraries(MGSFPSUnlock PRIVATE 56 | shlwapi 57 | version 58 | minhook 59 | ) -------------------------------------------------------------------------------- /MGSFPSUnlock.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34031.279 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MGSFPSUnlock", "MGSFPSUnlock\MGSFPSUnlock.vcxproj", "{FE4A0B03-4DC5-4685-8D43-05F8C481C981}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libMinHook", "external\minhook\build\VC17\libMinHook.vcxproj", "{F142A341-5EE0-442D-A15F-98AE9B48DBAE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Debug|x64.ActiveCfg = Debug|x64 19 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Debug|x64.Build.0 = Debug|x64 20 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Debug|x86.ActiveCfg = Debug|Win32 21 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Debug|x86.Build.0 = Debug|Win32 22 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Release|x64.ActiveCfg = Release|x64 23 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Release|x64.Build.0 = Release|x64 24 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Release|x86.ActiveCfg = Release|Win32 25 | {FE4A0B03-4DC5-4685-8D43-05F8C481C981}.Release|x86.Build.0 = Release|Win32 26 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.ActiveCfg = Debug|x64 27 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.Build.0 = Debug|x64 28 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x86.ActiveCfg = Debug|Win32 29 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x86.Build.0 = Debug|Win32 30 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.ActiveCfg = Release|x64 31 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.Build.0 = Release|x64 32 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x86.ActiveCfg = Release|Win32 33 | {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x86.Build.0 = Release|Win32 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {B125DC41-92C1-4083-A6F3-40781EC209D8} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /MGSFPSUnlock/MGS2/mgs2.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory.h" 2 | #include "MinHook.h" 3 | #include "Utils.h" 4 | #include "ini.h" 5 | #include "config.h" 6 | #include "spdlog/spdlog.h" 7 | 8 | class MGS2FramerateUnlocker 9 | { 10 | public: 11 | MGS2FramerateUnlocker(); 12 | ~MGS2FramerateUnlocker(); 13 | 14 | bool Initialize(); 15 | void RunUpdateLoop(); 16 | 17 | private: 18 | // Constants 19 | static constexpr int DEFAULT_TIMEBASE = 5; 20 | static constexpr float DEFAULT_FPS = 60.0f; 21 | 22 | // Function delegates 23 | typedef __int64 __fastcall ActDashFireDelegate(__int64 a1); 24 | typedef __int64 __fastcall CreateDebrisTexDelegate(__int64 a1, float* a2, float* a3, unsigned int a4, int a5, int a6, float a7); 25 | typedef __int64 __fastcall GetTimeBaseDelegate(struct _exception* a1); 26 | 27 | // Game data structure 28 | struct GameVariables 29 | { 30 | double* actorWaitValue; 31 | int* cutsceneFlag; 32 | int* demoCutsceneFlag; 33 | }; 34 | 35 | // Original function pointers 36 | GetTimeBaseDelegate* GetTimeBase; 37 | ActDashFireDelegate* ActDashFire; 38 | CreateDebrisTexDelegate* CreateDebrisTex; 39 | 40 | // Game data 41 | GameVariables gameVars; 42 | float frameRateModifier; 43 | int timeBase; 44 | 45 | // Private methods 46 | bool InitializeOffsets(); 47 | bool InstallHooks(); 48 | bool InCutscene() const; 49 | bool InDemoCutscene() const; 50 | 51 | // Private members 52 | double dashLastUpdate = 0; 53 | 54 | // Hook methods 55 | static MGS2FramerateUnlocker* instance; 56 | 57 | static __int64 __fastcall ActDashFireHook(__int64 a1); 58 | static __int64 __fastcall CreateDebrisTexHook(__int64 a1, float* a2, float* a3, unsigned int a4, int a5, int a6, float a7); 59 | static __int64 __fastcall GetTimeBaseHook(struct _exception* a1); 60 | }; 61 | 62 | MGS2FramerateUnlocker* MGS2FramerateUnlocker::instance = nullptr; 63 | 64 | MGS2FramerateUnlocker::MGS2FramerateUnlocker() 65 | : frameRateModifier(1.0f), timeBase(DEFAULT_TIMEBASE) 66 | { 67 | instance = this; 68 | memset(&gameVars, 0, sizeof(GameVariables)); 69 | } 70 | 71 | MGS2FramerateUnlocker::~MGS2FramerateUnlocker() 72 | { 73 | instance = nullptr; 74 | } 75 | 76 | bool MGS2FramerateUnlocker::InCutscene() const 77 | { 78 | return gameVars.cutsceneFlag == NULL ? false : (*gameVars.cutsceneFlag == 1); 79 | } 80 | 81 | bool MGS2FramerateUnlocker::InDemoCutscene() const 82 | { 83 | return gameVars.demoCutsceneFlag == NULL ? false : (*gameVars.demoCutsceneFlag == 1); 84 | } 85 | 86 | __int64 __fastcall MGS2FramerateUnlocker::ActDashFireHook(__int64 a1) 87 | { 88 | if (!instance->InDemoCutscene()) // only slow down during demo cutscenes. boss fight runs at normal gamespeed. 89 | return instance->ActDashFire(a1); 90 | 91 | instance->dashLastUpdate += *instance->gameVars.actorWaitValue; 92 | 93 | if (instance->dashLastUpdate < 1.0 / 30.0) 94 | return 0; 95 | 96 | instance->dashLastUpdate = 0; 97 | 98 | return instance->ActDashFire(a1); 99 | } 100 | 101 | __int64 __fastcall MGS2FramerateUnlocker::CreateDebrisTexHook(__int64 a1, float* a2, float* a3, unsigned int a4, int a5, int a6, float a7) 102 | { 103 | auto result = instance->CreateDebrisTex(a1, a2, a3, a4, a5, a6, a7); 104 | 105 | *(int*)(a1 + 100) = 15 * (instance->GetTimeBase(0) * ((Config.targetFramerate / 60) + 1)); // effect duration 106 | 107 | return result; 108 | } 109 | 110 | __int64 __fastcall MGS2FramerateUnlocker::GetTimeBaseHook(struct _exception* a1) 111 | { 112 | return instance->timeBase; 113 | } 114 | 115 | bool MGS2FramerateUnlocker::InitializeOffsets() 116 | { 117 | spdlog::info("Initializing offsets..."); 118 | 119 | instance->gameVars.actorWaitValue = (double*)(Memory::PatternScan(GameModule, "42 50 5F 4D 45 4D 4A 50 45 47") + 0x18); 120 | 121 | switch (Config.gameVersion) 122 | { 123 | case 0x1000200000000: 124 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAADA64); 125 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16CE4B8); 126 | break; 127 | case 0x1000300000000: 128 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAADA64); 129 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16CE4B8); 130 | break; 131 | case 0x1000400000000: 132 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAB4C74); 133 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16D5638); 134 | break; 135 | case 0x1000400010000: 136 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAB4C74); 137 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16D5638); 138 | break; 139 | case 0x1000500010000: 140 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xA8CD74); 141 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16AD878); 142 | break; 143 | case 0x2000000000000: 144 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAA8F84); 145 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16CA5D8); 146 | break; 147 | case 0x2000000010000: 148 | instance->gameVars.cutsceneFlag = reinterpret_cast(GameBase + 0xAA9F94); 149 | instance->gameVars.demoCutsceneFlag = reinterpret_cast(GameBase + 0x16CB5D8); 150 | break; 151 | default: 152 | spdlog::error("Unsupported game version: {:#x}", Config.gameVersion); 153 | return false; 154 | } 155 | 156 | if (!instance->gameVars.actorWaitValue || 157 | !instance->gameVars.cutsceneFlag || 158 | !instance->gameVars.demoCutsceneFlag) 159 | { 160 | spdlog::error("Failed to initialize one or more critical offsets"); 161 | return false; 162 | } 163 | 164 | spdlog::debug("actorWaitValue = {:#x}", reinterpret_cast(gameVars.actorWaitValue) - GameBase); 165 | spdlog::debug("cutsceneFlag = {:#x}", reinterpret_cast(gameVars.cutsceneFlag) - GameBase); 166 | spdlog::debug("demoCutsceneFlag = {:#x}", reinterpret_cast(gameVars.demoCutsceneFlag) - GameBase); 167 | 168 | DWORD oldProtect; 169 | VirtualProtect(instance->gameVars.actorWaitValue, 8, PAGE_READWRITE, &oldProtect); 170 | spdlog::info("InitializeOffsets() finished."); 171 | return true; 172 | } 173 | 174 | 175 | bool MGS2FramerateUnlocker::InstallHooks() 176 | { 177 | spdlog::info("Installing hooks"); 178 | 179 | MH_STATUS status = MH_Initialize(); 180 | if (status != MH_OK) 181 | { 182 | spdlog::error("Failed to initialize MinHook, status: {}", (int)status); 183 | return false; 184 | } 185 | 186 | uint8_t* getTimeBaseOffset = Memory::PatternScan(GameModule, "48 83 EC 28 E8 ?? ?? ?? ?? 33 C9 83 F8 01 0F 94"); 187 | uint8_t* actDashFireOffset = Memory::PatternScan(GameModule, "?? ?? ?? ?? ?? 49 8D AB 68 FE FF FF 48 81 EC 88"); 188 | uint8_t* createDebrisTexOffset = Memory::PatternScan(GameModule, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 00"); 189 | 190 | if (!actDashFireOffset || !createDebrisTexOffset || !getTimeBaseOffset) 191 | { 192 | spdlog::error("Failed to find one or more function patterns"); 193 | return false; 194 | } 195 | 196 | spdlog::debug("getTimeBaseOffset = {:#x}", reinterpret_cast(getTimeBaseOffset) - reinterpret_cast(GameModule)); 197 | spdlog::debug("actDashFireOffset = {:#x}", reinterpret_cast(actDashFireOffset) - reinterpret_cast(GameModule)); 198 | spdlog::debug("createDebrisTexOffset = {:#x}", reinterpret_cast(createDebrisTexOffset) - reinterpret_cast(GameModule)); 199 | 200 | MH_CreateHook(getTimeBaseOffset, GetTimeBaseHook, reinterpret_cast(&GetTimeBase)); 201 | MH_CreateHook(createDebrisTexOffset, CreateDebrisTexHook, reinterpret_cast(&CreateDebrisTex)); 202 | MH_CreateHook(actDashFireOffset, ActDashFireHook, reinterpret_cast(&ActDashFire)); 203 | 204 | if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) 205 | { 206 | spdlog::error("Failed to create or enable one or more hooks"); 207 | MH_Uninitialize(); 208 | return false; 209 | } 210 | 211 | spdlog::info("All hooks installed successfully"); 212 | return true; 213 | } 214 | 215 | void MGS2FramerateUnlocker::RunUpdateLoop() 216 | { 217 | while (true) 218 | { 219 | if (gameVars.actorWaitValue != nullptr) 220 | { 221 | if (InCutscene()) 222 | { 223 | timeBase = DEFAULT_TIMEBASE; 224 | *gameVars.actorWaitValue = 1.0 / DEFAULT_FPS; 225 | } 226 | else 227 | { 228 | auto mod = (float)Config.targetFramerate / DEFAULT_FPS; 229 | timeBase = std::round(DEFAULT_TIMEBASE / mod - 0.1); 230 | *gameVars.actorWaitValue = 1.0 / (double)Config.targetFramerate; 231 | } 232 | } 233 | Sleep(1); 234 | } 235 | } 236 | 237 | bool MGS2FramerateUnlocker::Initialize() 238 | { 239 | spdlog::info("Initializing framerate unlocker..."); 240 | 241 | if (Config.targetFramerate > DEFAULT_FPS) { //A LOT more work is needed before we support unlocked framerate. 242 | Config.targetFramerate = DEFAULT_FPS; 243 | spdlog::warn("MGS2 currently only supports framerate related bugfixes and not fully unlocked FPS. Setting target to {}.", DEFAULT_FPS); 244 | } 245 | 246 | if (!InitializeOffsets()) 247 | { 248 | spdlog::error("Failed to initialize offsets"); 249 | return false; 250 | } 251 | 252 | if (!InstallHooks()) 253 | { 254 | spdlog::error("Failed to install hooks"); 255 | return false; 256 | } 257 | 258 | frameRateModifier = static_cast(Config.targetFramerate) / DEFAULT_FPS; 259 | timeBase = std::round(DEFAULT_TIMEBASE / frameRateModifier - 0.1); 260 | 261 | // Apply initial values 262 | *gameVars.actorWaitValue = 1.0 / static_cast(Config.targetFramerate); 263 | 264 | spdlog::info("Initialization complete. Target framerate: {}", Config.targetFramerate); 265 | return true; 266 | } 267 | 268 | void MGS2_Initialize() 269 | { 270 | spdlog::info("Starting framerate unlocker"); 271 | 272 | MGS2FramerateUnlocker unlocker; 273 | 274 | if (!unlocker.Initialize()) 275 | { 276 | spdlog::error("Failed to initialize the framerate unlocker"); 277 | return; 278 | } 279 | 280 | unlocker.RunUpdateLoop(); // should maybe hook actorExec instead 281 | } -------------------------------------------------------------------------------- /MGSFPSUnlock/MGS2/mgs2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void MGS2_Initialize(); -------------------------------------------------------------------------------- /MGSFPSUnlock/MGS3/mgs3.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory.h" 2 | #include "MinHook.h" 3 | #include "config.h" 4 | #include "spdlog/spdlog.h" 5 | 6 | class MGS3FramerateUnlocker 7 | { 8 | public: 9 | MGS3FramerateUnlocker(); 10 | ~MGS3FramerateUnlocker(); 11 | 12 | bool Initialize(); 13 | 14 | private: 15 | static MGS3FramerateUnlocker* instance; 16 | 17 | // Constants 18 | static constexpr int DEFAULT_TIMEBASE = 5; 19 | static constexpr float DEFAULT_FPS = 60.0f; 20 | static constexpr float SMOOTHING_FACTOR = 8.0f; 21 | 22 | // Function delegates 23 | typedef uint64_t(__fastcall* GetTimeBaseDelegate)(struct _exception* a1); 24 | typedef void(__fastcall* UpdateMotionTimeBaseADelegate)(uint64_t a1, float a2, int a3); 25 | typedef void(__fastcall* UpdateMotionTimeBaseBDelegate)(uint64_t a1, float a2); 26 | typedef int64_t(__fastcall* GetTargetFpsDelegate)(struct _exception* a1); 27 | typedef int64_t(__fastcall* ThrowItemDelegate)(uint64_t a1, int* a2, float* a3, int a4, uint16_t a5, int a6, int a7, int a8, struct _exception* a9, int a10); 28 | typedef int16_t(__fastcall* UpdateAnimationBlendingDelegate)(struct _exception* a1, int16_t a2); 29 | typedef double(*GetActorExecTimeDelegate)(); 30 | 31 | // Game data structure 32 | struct GameVariables 33 | { 34 | int* timeBase; 35 | double* actorWaitValue; 36 | int* cutsceneFlag; 37 | float* cameraSpeedModifierA; 38 | float* cameraSpeedModifierB; 39 | float* realTimeRate; 40 | }; 41 | 42 | // function pointers 43 | GetTimeBaseDelegate GetTimeBase; 44 | UpdateMotionTimeBaseADelegate UpdateMotionTimeBaseA; 45 | UpdateMotionTimeBaseBDelegate UpdateMotionTimeBaseB; 46 | GetTargetFpsDelegate GetTargetFps; 47 | ThrowItemDelegate ThrowItem; 48 | UpdateAnimationBlendingDelegate UpdateAnimationBlending; 49 | GetActorExecTimeDelegate GetActorExecTime; 50 | 51 | // Game data 52 | GameVariables gameVars; 53 | float frameRateModifier; 54 | int timeBase; 55 | double execTime = 0.00; 56 | 57 | // Private methods 58 | bool InitializeOffsets(); 59 | bool InstallHooks(); 60 | bool InCutscene() const; 61 | float CalculateMotionTimeBase(float value) const; 62 | 63 | // Hook methods 64 | static uint64_t __fastcall GetTimeBaseHook(struct _exception* a1); 65 | static void __fastcall UpdateMotionTimeBaseAHook(uint64_t a1, float a2, int a3); 66 | static void __fastcall UpdateMotionTimeBaseBHook(uint64_t a1, float a2); 67 | static int64_t __fastcall GetTargetFpsHook(struct _exception* a1); 68 | static int64_t __fastcall ThrowItemHook(uint64_t a1, int* a2, float* a3, int a4, uint16_t a5, int a6, int a7, int a8, struct _exception* a9, int a10); 69 | static int16_t __fastcall UpdateAnimationBlendingHook(int16_t currentFrame, int16_t targetFrame); 70 | static double GetActorExecTimeHook(); 71 | }; 72 | 73 | MGS3FramerateUnlocker* MGS3FramerateUnlocker::instance = nullptr; 74 | 75 | MGS3FramerateUnlocker::MGS3FramerateUnlocker() 76 | : frameRateModifier(1.0f), timeBase(DEFAULT_TIMEBASE) 77 | { 78 | instance = this; 79 | memset(&gameVars, 0, sizeof(GameVariables)); 80 | } 81 | 82 | MGS3FramerateUnlocker::~MGS3FramerateUnlocker() 83 | { 84 | instance = nullptr; 85 | } 86 | 87 | uintptr_t GetRelativeOffset(uint8_t* addr) 88 | { 89 | return reinterpret_cast(addr) + 4 + *reinterpret_cast(addr); 90 | } 91 | 92 | bool MGS3FramerateUnlocker::InitializeOffsets() 93 | { 94 | spdlog::info("Initializing offsets..."); 95 | 96 | uint8_t* addr = nullptr; 97 | memset(&gameVars, 0, sizeof(GameVariables)); 98 | 99 | addr = Memory::PatternScan(GameModule, "33 C9 83 F8 01 ?? ?? C1 83 C1 05"); 100 | if (!addr) spdlog::error("Could not find GV_TimeBase"); 101 | else gameVars.timeBase = reinterpret_cast(GetRelativeOffset(addr + 13)); 102 | 103 | addr = Memory::PatternScan(GameModule, "83 3D ?? ?? ?? ?? 00 ?? ?? F2 0F 10 0D"); 104 | if (!addr) spdlog::error("Could not find ActorWaitValue"); 105 | else gameVars.actorWaitValue = reinterpret_cast(GetRelativeOffset(addr + 13)); 106 | 107 | addr = Memory::PatternScan(GameModule, "89 05 ?? ?? ?? ?? B1 65 E8 ?? ?? ?? FF 8B 0D"); 108 | if (!addr) spdlog::error("Could not find CutsceneFlag"); 109 | else gameVars.cutsceneFlag = reinterpret_cast(GetRelativeOffset(addr + 2)); 110 | 111 | addr = Memory::PatternScan(GameModule, "0F 28 F0 E8 ?? ?? ?? ?? F3 0F 10 0D ?? ?? ?? ??"); 112 | if (!addr) spdlog::error("Could not find CameraSpeedModifierA"); 113 | else gameVars.cameraSpeedModifierA = reinterpret_cast(GetRelativeOffset(addr + 12)); 114 | 115 | addr = Memory::PatternScan(GameModule, "0F 28 ?? F3 0F 10 87 90 00 00 00 F3 0F 10 15"); 116 | if (!addr) spdlog::error("Could not find CameraSpeedModifierB"); 117 | else gameVars.cameraSpeedModifierB = reinterpret_cast(GetRelativeOffset(addr + 15)); 118 | 119 | addr = Memory::PatternScan(GameModule, "0F 6E C0 0F 5B C0 F3 0F 59 05 ?? ?? ?? ?? F3 48 0F 2C C0", 1); 120 | if (!addr) spdlog::error("Could not find RealTimeRate"); 121 | else gameVars.realTimeRate = reinterpret_cast(GetRelativeOffset(addr + 10)); 122 | 123 | // set offsets manually here (useful for development) 124 | switch (Config.gameVersion) 125 | { 126 | case 0x2000000010000: 127 | break; 128 | default: 129 | break; 130 | } 131 | 132 | spdlog::debug("timeBase = {:#x}", reinterpret_cast(gameVars.timeBase) - GameBase); 133 | spdlog::debug("actorWaitValue = {:#x}", reinterpret_cast(gameVars.actorWaitValue) - GameBase); 134 | spdlog::debug("cutsceneFlag = {:#x}", reinterpret_cast(gameVars.cutsceneFlag) - GameBase); 135 | spdlog::debug("cameraSpeedModifierA = {:#x}", reinterpret_cast(gameVars.cameraSpeedModifierA) - GameBase); 136 | spdlog::debug("cameraSpeedModifierB = {:#x}", reinterpret_cast(gameVars.cameraSpeedModifierB) - GameBase); 137 | spdlog::debug("realTimeRate = {:#x}", reinterpret_cast(gameVars.realTimeRate) - GameBase); 138 | 139 | if (!gameVars.timeBase || !gameVars.actorWaitValue || !gameVars.cameraSpeedModifierA || 140 | !gameVars.cameraSpeedModifierB || !gameVars.realTimeRate) 141 | { 142 | spdlog::error("Failed to initialize one or more critical offsets"); 143 | return false; 144 | } 145 | 146 | DWORD oldProtect; 147 | VirtualProtect(gameVars.actorWaitValue, 8, PAGE_READWRITE, &oldProtect); 148 | VirtualProtect(gameVars.cameraSpeedModifierA, 4, PAGE_READWRITE, &oldProtect); 149 | VirtualProtect(gameVars.cameraSpeedModifierB, 4, PAGE_READWRITE, &oldProtect); 150 | VirtualProtect(gameVars.realTimeRate, 4, PAGE_READWRITE, &oldProtect); 151 | 152 | return true; 153 | } 154 | 155 | bool MGS3FramerateUnlocker::InstallHooks() 156 | { 157 | spdlog::info("Installing hooks"); 158 | 159 | MH_STATUS status = MH_Initialize(); 160 | if (status != MH_OK) 161 | { 162 | spdlog::error("Failed to initialize MinHook, status: {}", (int)status); 163 | return false; 164 | } 165 | 166 | uint8_t* getTimeBaseAddr = Memory::PatternScan(GameModule, "48 83 EC 28 E8 ?? ?? FD FF 33 C9 83 F8 01 0F 94"); 167 | uint8_t* updateMotionAAddr = Memory::PatternScan(GameModule, "48 85 C9 74 31 0F 57 C0 0F 2F C1 76 0B 66 0F 6E"); 168 | uint8_t* updateMotionBAddr = Memory::PatternScan(GameModule, "48 85 C9 74 3F 0F 57 C0 0F 2F C1 76 0B 66 0F 6E"); 169 | uint8_t* getTargetFpsAddr = Memory::PatternScan(GameModule, "48 83 EC 28 E8 ?? ?? FD FF 83 F8 01 B9 3C 00 00"); 170 | uint8_t* throwItemAddr = Memory::PatternScan(GameModule, "40 55 56 57 41 56 41 57 48 8D 6C 24 E0 48 81 EC"); 171 | uint8_t* animBlendAddr = Memory::PatternScan(GameModule, "48 89 5C 24 08 57 48 83 EC 30 0F 29 74 24 20 0F"); 172 | uint8_t* getActorExecTime = Memory::PatternScan(GameModule, "48 83 EC 28 48 8D 0D ?? ?? ?? 01 FF 15 ?? ?? 78"); 173 | 174 | if (!getTimeBaseAddr || !updateMotionAAddr || !updateMotionBAddr || 175 | !getTargetFpsAddr || !throwItemAddr || !animBlendAddr || !getActorExecTime) 176 | { 177 | spdlog::error("Failed to find one or more function patterns"); 178 | return false; 179 | } 180 | 181 | spdlog::debug("getTimeBase = {:#x}", reinterpret_cast(getTimeBaseAddr) - reinterpret_cast(GameModule)); 182 | spdlog::debug("updateMotionA = {:#x}", reinterpret_cast(updateMotionAAddr) - reinterpret_cast(GameModule)); 183 | spdlog::debug("updateMotionB = {:#x}", reinterpret_cast(updateMotionBAddr) - reinterpret_cast(GameModule)); 184 | spdlog::debug("getTargetFps = {:#x}", reinterpret_cast(getTargetFpsAddr) - reinterpret_cast(GameModule)); 185 | spdlog::debug("throwItem = {:#x}", reinterpret_cast(throwItemAddr) - reinterpret_cast(GameModule)); 186 | spdlog::debug("animBlend = {:#x}", reinterpret_cast(animBlendAddr) - reinterpret_cast(GameModule)); 187 | spdlog::debug("getActorExecTime = {:#x}", reinterpret_cast(getActorExecTime) - reinterpret_cast(GameModule)); 188 | 189 | MH_CreateHook(getTimeBaseAddr, GetTimeBaseHook, reinterpret_cast(&GetTimeBase)); 190 | MH_CreateHook(updateMotionAAddr, UpdateMotionTimeBaseAHook, reinterpret_cast(&UpdateMotionTimeBaseA)); 191 | MH_CreateHook(updateMotionBAddr, UpdateMotionTimeBaseBHook, reinterpret_cast(&UpdateMotionTimeBaseB)); 192 | MH_CreateHook(getTargetFpsAddr, GetTargetFpsHook, reinterpret_cast(&GetTargetFps)); 193 | MH_CreateHook(throwItemAddr, ThrowItemHook, reinterpret_cast(&ThrowItem)); 194 | MH_CreateHook(animBlendAddr, UpdateAnimationBlendingHook, reinterpret_cast(&UpdateAnimationBlending)); 195 | MH_CreateHook(getActorExecTime, GetActorExecTimeHook, reinterpret_cast(&GetActorExecTime)); 196 | 197 | if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) 198 | { 199 | spdlog::error("Failed to create or enable one or more hooks"); 200 | MH_Uninitialize(); 201 | return false; 202 | } 203 | 204 | spdlog::info("All hooks installed successfully"); 205 | return true; 206 | } 207 | 208 | bool MGS3FramerateUnlocker::InCutscene() const 209 | { 210 | return gameVars.cutsceneFlag != nullptr && (*gameVars.cutsceneFlag == 0); 211 | } 212 | 213 | float MGS3FramerateUnlocker::CalculateMotionTimeBase(float value) const 214 | { 215 | if (value <= 0.00f) 216 | { 217 | value = static_cast(*gameVars.timeBase); 218 | } 219 | 220 | value = value * (DEFAULT_TIMEBASE / static_cast(*gameVars.timeBase)); 221 | return value / frameRateModifier; 222 | } 223 | 224 | uint64_t __fastcall MGS3FramerateUnlocker::GetTimeBaseHook(struct _exception* a1) 225 | { 226 | if (instance->InCutscene()) 227 | { 228 | return DEFAULT_TIMEBASE; 229 | } 230 | 231 | return instance->timeBase; 232 | } 233 | 234 | void __fastcall MGS3FramerateUnlocker::UpdateMotionTimeBaseAHook(uint64_t a1, float a2, int a3) 235 | { 236 | instance->UpdateMotionTimeBaseA(a1, instance->CalculateMotionTimeBase(a2), a3); 237 | } 238 | 239 | void __fastcall MGS3FramerateUnlocker::UpdateMotionTimeBaseBHook(uint64_t a1, float a2) 240 | { 241 | instance->UpdateMotionTimeBaseB(a1, instance->CalculateMotionTimeBase(a2)); 242 | } 243 | 244 | int64_t __fastcall MGS3FramerateUnlocker::GetTargetFpsHook(struct _exception* a1) 245 | { 246 | return Config.targetFramerate; 247 | } 248 | 249 | int64_t __fastcall MGS3FramerateUnlocker::ThrowItemHook(uint64_t a1, int* a2, float* a3, int a4, uint16_t a5, int a6, int a7, int a8, struct _exception* a9, int a10) 250 | { 251 | *(float*)&a6 = *(float*)&a6 / instance->frameRateModifier; 252 | return instance->ThrowItem(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 253 | } 254 | 255 | int16_t __fastcall MGS3FramerateUnlocker::UpdateAnimationBlendingHook(int16_t currentFrame, int16_t targetFrame) 256 | { 257 | const float smoothingFactor = SMOOTHING_FACTOR * instance->frameRateModifier; 258 | 259 | int16_t diff = targetFrame - currentFrame; 260 | int16_t value = static_cast(static_cast(diff) / smoothingFactor); 261 | 262 | if (*instance->gameVars.timeBase != instance->GetTimeBase(nullptr)) 263 | { 264 | currentFrame = (value != 0) ? (currentFrame + value) : targetFrame; 265 | } 266 | 267 | return (value != 0) ? (currentFrame + value) : targetFrame; 268 | } 269 | 270 | double MGS3FramerateUnlocker::GetActorExecTimeHook() 271 | { 272 | instance->execTime = instance->GetActorExecTime(); 273 | 274 | if (instance->InCutscene()) 275 | { 276 | *instance->gameVars.timeBase = DEFAULT_TIMEBASE; 277 | *instance->gameVars.actorWaitValue = 1.0 / DEFAULT_FPS; 278 | } 279 | else 280 | { 281 | *instance->gameVars.timeBase = instance->timeBase; 282 | *instance->gameVars.actorWaitValue = 1.0 / static_cast(Config.targetFramerate); 283 | } 284 | 285 | return instance->execTime; 286 | } 287 | 288 | bool MGS3FramerateUnlocker::Initialize() 289 | { 290 | spdlog::info("Initializing framerate unlocker..."); 291 | 292 | if (Config.gameVersion < 0x1000200000000) 293 | { 294 | spdlog::error("Unsupported game version: {:#x}. Version 1.2 or higher is required.", Config.gameVersion); 295 | return false; 296 | } 297 | 298 | if (!InitializeOffsets()) 299 | { 300 | spdlog::error("Failed to initialize offsets"); 301 | return false; 302 | } 303 | 304 | if (!InstallHooks()) 305 | { 306 | spdlog::error("Failed to install hooks"); 307 | return false; 308 | } 309 | 310 | frameRateModifier = static_cast(Config.targetFramerate) / DEFAULT_FPS; 311 | timeBase = std::round(DEFAULT_TIMEBASE / frameRateModifier - 0.1); 312 | 313 | // Apply initial values 314 | *gameVars.timeBase = timeBase; 315 | *gameVars.actorWaitValue = 1.0 / static_cast(Config.targetFramerate); 316 | *gameVars.cameraSpeedModifierA = *gameVars.cameraSpeedModifierA / frameRateModifier; 317 | *gameVars.cameraSpeedModifierB = *gameVars.cameraSpeedModifierB / frameRateModifier; 318 | *gameVars.realTimeRate = *gameVars.realTimeRate / frameRateModifier; 319 | 320 | spdlog::info("Initialization complete"); 321 | return true; 322 | } 323 | 324 | void MGS3_Initialize() 325 | { 326 | spdlog::info("Starting framerate unlocker"); 327 | 328 | MGS3FramerateUnlocker unlocker; 329 | 330 | if (!unlocker.Initialize()) 331 | { 332 | spdlog::error("Failed to initialize the framerate unlocker"); 333 | return; 334 | } 335 | 336 | Sleep(INFINITE); 337 | } -------------------------------------------------------------------------------- /MGSFPSUnlock/MGS3/mgs3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void MGS3_Initialize(); -------------------------------------------------------------------------------- /MGSFPSUnlock/MGSFPSUnlock.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /MGSFPSUnlock/MGSFPSUnlock.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | Win32Proj 24 | {fe4a0b03-4dc5-4685-8d43-05f8c481c981} 25 | MGSFPSUnlock 26 | 10.0 27 | MGSFPSUnlock 28 | 29 | 30 | 31 | DynamicLibrary 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | DynamicLibrary 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | DynamicLibrary 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | DynamicLibrary 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | .asi 76 | $(ProjectDir)\includes; 77 | ..\external\spdlog\include;$(ExternalIncludePath) 78 | 79 | 80 | .asi 81 | $(ProjectDir)\includes; 82 | $(SolutionDir)$(Platform)\$(Configuration)\ 83 | ..\external\spdlog\include;$(ExternalIncludePath) 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;MGS3FPSUNLOCK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 90 | true 91 | Use 92 | pch.h 93 | 94 | 95 | Windows 96 | true 97 | false 98 | 99 | 100 | 101 | 102 | Level3 103 | true 104 | true 105 | true 106 | WIN32;NDEBUG;MGS3FPSUNLOCK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 107 | true 108 | Use 109 | pch.h 110 | 111 | 112 | Windows 113 | true 114 | true 115 | true 116 | false 117 | 118 | 119 | 120 | 121 | Level3 122 | true 123 | _DEBUG;MGS3FPSUNLOCK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 124 | true 125 | NotUsing 126 | pch.h 127 | stdcpplatest 128 | 129 | 130 | Windows 131 | true 132 | false 133 | $(CoreLibraryDependencies);%(AdditionalDependencies);Shlwapi.lib;version.lib;$(SolutionDir)lib\$(Configuration)\libMinHook.x64.lib 134 | 135 | 136 | 137 | 138 | Level3 139 | true 140 | true 141 | true 142 | NDEBUG;MGS3FPSUNLOCK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 143 | true 144 | NotUsing 145 | pch.h 146 | MaxSpeed 147 | false 148 | stdcpplatest 149 | /utf-8 %(AdditionalOptions) 150 | 151 | 152 | Windows 153 | true 154 | true 155 | true 156 | false 157 | $(CoreLibraryDependencies);%(AdditionalDependencies);Shlwapi.lib;version.lib;$(SolutionDir)lib\$(Configuration)\libMinHook.x64.lib 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /MGSFPSUnlock/MGSFPSUnlock.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | MGS2 9 | 10 | 11 | MGS3 12 | 13 | 14 | 15 | 16 | MGS2 17 | 18 | 19 | MGS3 20 | 21 | 22 | includes 23 | 24 | 25 | includes 26 | 27 | 28 | includes 29 | 30 | 31 | includes 32 | 33 | 34 | includes 35 | 36 | 37 | includes 38 | 39 | 40 | includes 41 | 42 | 43 | 44 | 45 | {41837e79-f57f-43c6-8364-62de24213c0e} 46 | 47 | 48 | {fbda13db-9b45-4ecd-bc1f-f5ab9da2dddf} 49 | 50 | 51 | {6bf4a300-050b-439a-b288-f1a439f6681d} 52 | 53 | 54 | -------------------------------------------------------------------------------- /MGSFPSUnlock/Memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Memory.h" 7 | #include "MinHook.h" 8 | 9 | void Memory::DetourFunction(uint64_t target, LPVOID detour, LPVOID* ppOriginal) 10 | { 11 | int error = 0; 12 | if (error = MH_CreateHook((LPVOID)target, detour, ppOriginal) != 0) 13 | { 14 | return; 15 | } 16 | MH_EnableHook((LPVOID)target); 17 | } 18 | 19 | uintptr_t Memory::PatternScanBasic(uintptr_t beg, uintptr_t end, uint8_t* str, uintptr_t len) 20 | { 21 | for (uintptr_t ptr = beg; ptr < end - len; ++ptr) 22 | { 23 | if (0 == memcmp((const void*)ptr, str, len)) 24 | return ptr; 25 | ptr++; 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | // CSGOSimple's pattern scan 32 | // https://github.com/OneshotGH/CSGOSimple-master/blob/master/CSGOSimple/helpers/utils.cpp 33 | uint8_t* Memory::PatternScan(void* module, const char* signature, int skip, bool end) 34 | { 35 | static auto pattern_to_byte = [](const char* pattern) { 36 | auto bytes = std::vector{}; 37 | auto start = const_cast(pattern); 38 | auto end = const_cast(pattern) + strlen(pattern); 39 | 40 | for (auto current = start; current < end; ++current) { 41 | if (*current == '?') { 42 | ++current; 43 | if (*current == '?') 44 | ++current; 45 | bytes.push_back(-1); 46 | } 47 | else { 48 | bytes.push_back(strtoul(current, ¤t, 16)); 49 | } 50 | } 51 | return bytes; 52 | }; 53 | 54 | auto dosHeader = (PIMAGE_DOS_HEADER)module; 55 | auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew); 56 | 57 | auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage; 58 | auto patternBytes = pattern_to_byte(signature); 59 | auto scanBytes = reinterpret_cast(module); 60 | 61 | auto s = patternBytes.size(); 62 | auto d = patternBytes.data(); 63 | int foundCount = 0; 64 | 65 | for (auto i = 0ul; i < sizeOfImage - s; ++i) { 66 | bool found = true; 67 | for (auto j = 0ul; j < s; ++j) { 68 | if (scanBytes[i + j] != d[j] && d[j] != -1) { 69 | found = false; 70 | break; 71 | } 72 | } 73 | if (found) { 74 | foundCount++; 75 | if (foundCount > skip) { 76 | return end ? &scanBytes[i] + s : &scanBytes[i]; 77 | } 78 | } 79 | } 80 | return nullptr; 81 | } -------------------------------------------------------------------------------- /MGSFPSUnlock/Utils.cpp: -------------------------------------------------------------------------------- 1 | #include "Utils.h" 2 | #include 3 | #include 4 | #include 5 | 6 | void GetGameType(HMODULE gameModule, GameType& result) 7 | { 8 | char exePath[_MAX_PATH] = { 0 }; 9 | GetModuleFileNameA(gameModule, exePath, _MAX_PATH); 10 | char* filename = PathFindFileNameA(exePath); 11 | printf("%s\n", filename); 12 | 13 | if (strcmp(filename, "METAL GEAR SOLID2.exe") == 0) 14 | result = GameType::MGS2; 15 | else if (strcmp(filename, "METAL GEAR SOLID3.exe") == 0) 16 | result = GameType::MGS3; 17 | else 18 | result = GameType::Unknown; 19 | } 20 | 21 | uint64_t GetGameVersion(HMODULE gameModule) 22 | { 23 | char exePath[_MAX_PATH] = { 0 }; 24 | GetModuleFileNameA(gameModule, exePath, _MAX_PATH); 25 | char* filename = PathFindFileNameA(exePath); 26 | 27 | if (strncmp(filename, "launcher.exe", 13) == 0) 28 | { 29 | return 0; 30 | } 31 | 32 | DWORD verHandle = 0; 33 | UINT size = 0; 34 | LPBYTE lpBuffer = NULL; 35 | 36 | DWORD verSize = GetFileVersionInfoSizeA(exePath, &verHandle); 37 | 38 | if (verSize != 0) 39 | { 40 | BYTE* verData = new BYTE[verSize]; 41 | 42 | if (GetFileVersionInfoA(exePath, verHandle, verSize, verData)) 43 | { 44 | if (VerQueryValueA(verData, "\\", (VOID FAR* FAR*)&lpBuffer, &size)) 45 | { 46 | if (size) 47 | { 48 | VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer; 49 | if (verInfo->dwSignature == 0xfeef04bd) 50 | { 51 | ULARGE_INTEGER version; 52 | version.LowPart = verInfo->dwFileVersionLS; 53 | version.HighPart = verInfo->dwFileVersionMS; 54 | delete[] verData; 55 | return version.QuadPart; 56 | } 57 | } 58 | } 59 | } 60 | delete[] verData; 61 | } 62 | return 0; 63 | } -------------------------------------------------------------------------------- /MGSFPSUnlock/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Memory.h" 3 | #include "MinHook.h" 4 | #include "Utils.h" 5 | #include "ini.h" 6 | #include "config.h" 7 | #include "spdlog/spdlog.h" 8 | #include "spdlog/sinks/basic_file_sink.h" 9 | #include "MGS2/mgs2.h" 10 | #include "MGS3/mgs3.h" 11 | 12 | #define LOG_FORMAT_PREFIX "[%Y-%m-%d %H:%M:%S.%e] [MGSFPSUnlock] [%l]" 13 | 14 | std::shared_ptr logger; 15 | std::string sLogFile = "MGSFPSUnlock.log"; 16 | std::string sFixVer = "0.0.6"; 17 | std::filesystem::path sExePath; 18 | std::string sFixPath; 19 | 20 | GameConfig Config; 21 | HMODULE GameModule = GetModuleHandleA(NULL); 22 | uintptr_t GameBase = (uintptr_t)GameModule; 23 | mINI::INIStructure ConfigValues; 24 | 25 | void ReadConfig() 26 | { 27 | std::string configPath = sExePath.string() + sFixPath + "MGSFPSUnlock.ini"; 28 | mINI::INIFile ini(configPath); 29 | if (!ini.read(ConfigValues)) 30 | { 31 | ConfigValues["Settings"]["TargetFrameRate"] = "60"; 32 | ini.generate(ConfigValues); 33 | spdlog::info("Config file not detected! Generating a new one at: {}", configPath); 34 | } 35 | else 36 | { 37 | spdlog::info("Config file loaded: {}", configPath); 38 | } 39 | Config.targetFramerate = std::stoi(ConfigValues["Settings"]["TargetFrameRate"]); 40 | spdlog::info("Config Parse: Target Framerate: {}", Config.targetFramerate); 41 | } 42 | 43 | void InitializeLogger() 44 | { 45 | // Get game name and exe path 46 | WCHAR exePath[_MAX_PATH] = { 0 }; 47 | GetModuleFileNameW(GameModule, exePath, MAX_PATH); 48 | sExePath = exePath; 49 | sExePath = sExePath.remove_filename(); 50 | 51 | std::string paths[4] = { "", "plugins\\", "scripts\\", "update\\" }; 52 | for (int i = 0; i < (sizeof(paths) / sizeof(paths[0])); i++) 53 | { 54 | if (std::filesystem::exists(sExePath.string() + paths[i] + "MGSFPSUnlock.asi")) 55 | { 56 | sFixPath = paths[i]; 57 | break; 58 | } 59 | } 60 | 61 | { 62 | try 63 | { 64 | if (!std::filesystem::is_directory(sExePath.string() + "logs")) 65 | { 66 | std::filesystem::create_directory(sExePath.string() + "logs"); //create a "logs" subdirectory in the game folder to keep the main directory tidy. 67 | } 68 | logger = spdlog::basic_logger_mt("MGSFPSUnlock", sExePath.string() + "logs\\" + sLogFile, true); 69 | logger->set_level(spdlog::level::debug); 70 | logger->flush_on(spdlog::level::debug); 71 | spdlog::set_default_logger(logger); 72 | spdlog::set_pattern(LOG_FORMAT_PREFIX ": %v"); 73 | spdlog::info("MGSFPSUnlock v{} loaded.", sFixVer.c_str()); 74 | spdlog::info("ASI plugin location: {}", sExePath.string() + sFixPath + "MGSFPSUnlock.asi"); 75 | spdlog::info("Log file: {}", sExePath.string() + "logs\\" + sLogFile); 76 | } 77 | catch (const spdlog::spdlog_ex& ex) { 78 | AllocConsole(); 79 | FILE* dummy; 80 | freopen_s(&dummy, "CONOUT$", "w", stdout); 81 | std::cout << "Log initialisation failed: " << ex.what() << std::endl; 82 | FreeLibraryAndExitThread(GameModule, 1); 83 | } 84 | } 85 | } 86 | 87 | DWORD WINAPI MainThread(LPVOID lpParam) 88 | { 89 | InitializeLogger(); 90 | 91 | GetGameType(GameModule, Config.gameType); 92 | Config.gameVersion = GetGameVersion(GameModule); 93 | if (Config.gameVersion == 0) 94 | { 95 | spdlog::error("Unable to get game version, closing!"); 96 | return false; 97 | } 98 | 99 | ReadConfig(); //Read the config after checking gameVersion, otherwise any regeneration logs will be cleared when the launcher closes. 100 | 101 | 102 | //convert gameVersion to a string 103 | std::stringstream stream; 104 | stream << std::hex << Config.gameVersion; 105 | std::string versionstring(stream.str()); 106 | 107 | switch (Config.gameType) 108 | { 109 | case GameType::MGS2: 110 | spdlog::info("Found Game: MGS2 - Version: {}", versionstring); 111 | spdlog::set_pattern(LOG_FORMAT_PREFIX " MGS2: %v"); 112 | MGS2_Initialize(); 113 | break; 114 | case GameType::MGS3: 115 | spdlog::info("Found Game: MGS3 - Version: {}", versionstring); 116 | spdlog::set_pattern(LOG_FORMAT_PREFIX " MGS3: %v"); 117 | MGS3_Initialize(); 118 | break; 119 | default: 120 | spdlog::error("Unknown game!"); 121 | break; 122 | } 123 | 124 | return true; 125 | } 126 | 127 | BOOL APIENTRY DllMain( HMODULE hModule, 128 | DWORD ul_reason_for_call, 129 | LPVOID lpReserved 130 | ) 131 | { 132 | switch (ul_reason_for_call) 133 | { 134 | case DLL_PROCESS_ATTACH: 135 | DisableThreadLibraryCalls(hModule); 136 | CreateThread(NULL, NULL, MainThread, NULL, NULL, NULL); 137 | break; 138 | case DLL_THREAD_ATTACH: 139 | case DLL_THREAD_DETACH: 140 | case DLL_PROCESS_DETACH: 141 | break; 142 | } 143 | return TRUE; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/Memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Memory 7 | { 8 | void DetourFunction(uint64_t target, LPVOID detour, LPVOID* ppOriginal); 9 | uintptr_t PatternScanBasic(uintptr_t beg, uintptr_t end, uint8_t* str, uintptr_t len); 10 | uint8_t* PatternScan(void* module, const char* signature, int skip = 0, bool end = false); 11 | }; -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/MinHook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) 32 | #error MinHook supports only x86 and x64 systems. 33 | #endif 34 | 35 | #include 36 | 37 | // MinHook Error Codes. 38 | typedef enum MH_STATUS 39 | { 40 | // Unknown error. Should not be returned. 41 | MH_UNKNOWN = -1, 42 | 43 | // Successful. 44 | MH_OK = 0, 45 | 46 | // MinHook is already initialized. 47 | MH_ERROR_ALREADY_INITIALIZED, 48 | 49 | // MinHook is not initialized yet, or already uninitialized. 50 | MH_ERROR_NOT_INITIALIZED, 51 | 52 | // The hook for the specified target function is already created. 53 | MH_ERROR_ALREADY_CREATED, 54 | 55 | // The hook for the specified target function is not created yet. 56 | MH_ERROR_NOT_CREATED, 57 | 58 | // The hook for the specified target function is already enabled. 59 | MH_ERROR_ENABLED, 60 | 61 | // The hook for the specified target function is not enabled yet, or already 62 | // disabled. 63 | MH_ERROR_DISABLED, 64 | 65 | // The specified pointer is invalid. It points the address of non-allocated 66 | // and/or non-executable region. 67 | MH_ERROR_NOT_EXECUTABLE, 68 | 69 | // The specified target function cannot be hooked. 70 | MH_ERROR_UNSUPPORTED_FUNCTION, 71 | 72 | // Failed to allocate memory. 73 | MH_ERROR_MEMORY_ALLOC, 74 | 75 | // Failed to change the memory protection. 76 | MH_ERROR_MEMORY_PROTECT, 77 | 78 | // The specified module is not loaded. 79 | MH_ERROR_MODULE_NOT_FOUND, 80 | 81 | // The specified function is not found. 82 | MH_ERROR_FUNCTION_NOT_FOUND 83 | } 84 | MH_STATUS; 85 | 86 | // Can be passed as a parameter to MH_EnableHook, MH_DisableHook, 87 | // MH_QueueEnableHook or MH_QueueDisableHook. 88 | #define MH_ALL_HOOKS NULL 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | // Initialize the MinHook library. You must call this function EXACTLY ONCE 95 | // at the beginning of your program. 96 | MH_STATUS WINAPI MH_Initialize(VOID); 97 | 98 | // Uninitialize the MinHook library. You must call this function EXACTLY 99 | // ONCE at the end of your program. 100 | MH_STATUS WINAPI MH_Uninitialize(VOID); 101 | 102 | // Creates a Hook for the specified target function, in disabled state. 103 | // Parameters: 104 | // pTarget [in] A pointer to the target function, which will be 105 | // overridden by the detour function. 106 | // pDetour [in] A pointer to the detour function, which will override 107 | // the target function. 108 | // ppOriginal [out] A pointer to the trampoline function, which will be 109 | // used to call the original target function. 110 | // This parameter can be NULL. 111 | MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID* ppOriginal); 112 | 113 | // Creates a Hook for the specified API function, in disabled state. 114 | // Parameters: 115 | // pszModule [in] A pointer to the loaded module name which contains the 116 | // target function. 117 | // pszTarget [in] A pointer to the target function name, which will be 118 | // overridden by the detour function. 119 | // pDetour [in] A pointer to the detour function, which will override 120 | // the target function. 121 | // ppOriginal [out] A pointer to the trampoline function, which will be 122 | // used to call the original target function. 123 | // This parameter can be NULL. 124 | MH_STATUS WINAPI MH_CreateHookApi( 125 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID* ppOriginal); 126 | 127 | // Creates a Hook for the specified API function, in disabled state. 128 | // Parameters: 129 | // pszModule [in] A pointer to the loaded module name which contains the 130 | // target function. 131 | // pszTarget [in] A pointer to the target function name, which will be 132 | // overridden by the detour function. 133 | // pDetour [in] A pointer to the detour function, which will override 134 | // the target function. 135 | // ppOriginal [out] A pointer to the trampoline function, which will be 136 | // used to call the original target function. 137 | // This parameter can be NULL. 138 | // ppTarget [out] A pointer to the target function, which will be used 139 | // with other functions. 140 | // This parameter can be NULL. 141 | MH_STATUS WINAPI MH_CreateHookApiEx( 142 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID* ppOriginal, LPVOID* ppTarget); 143 | 144 | // Removes an already created hook. 145 | // Parameters: 146 | // pTarget [in] A pointer to the target function. 147 | MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); 148 | 149 | // Enables an already created hook. 150 | // Parameters: 151 | // pTarget [in] A pointer to the target function. 152 | // If this parameter is MH_ALL_HOOKS, all created hooks are 153 | // enabled in one go. 154 | MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); 155 | 156 | // Disables an already created hook. 157 | // Parameters: 158 | // pTarget [in] A pointer to the target function. 159 | // If this parameter is MH_ALL_HOOKS, all created hooks are 160 | // disabled in one go. 161 | MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); 162 | 163 | // Queues to enable an already created hook. 164 | // Parameters: 165 | // pTarget [in] A pointer to the target function. 166 | // If this parameter is MH_ALL_HOOKS, all created hooks are 167 | // queued to be enabled. 168 | MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); 169 | 170 | // Queues to disable an already created hook. 171 | // Parameters: 172 | // pTarget [in] A pointer to the target function. 173 | // If this parameter is MH_ALL_HOOKS, all created hooks are 174 | // queued to be disabled. 175 | MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); 176 | 177 | // Applies all queued changes in one go. 178 | MH_STATUS WINAPI MH_ApplyQueued(VOID); 179 | 180 | // Translates the MH_STATUS to its name as a string. 181 | const char* WINAPI MH_StatusToString(MH_STATUS status); 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | 187 | -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/Utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "config.h" 5 | 6 | void GetGameType(HMODULE gameModule, GameType& result); 7 | uint64_t GetGameVersion(HMODULE gameModule); -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ini.h" 4 | 5 | enum class GameType 6 | { 7 | Unknown, 8 | MGS2, 9 | MGS3 10 | }; 11 | 12 | struct GameConfig 13 | { 14 | GameType gameType; 15 | uint64_t gameVersion; 16 | int targetFramerate; 17 | }; 18 | 19 | extern GameConfig Config; 20 | extern HMODULE GameModule; 21 | extern uintptr_t GameBase; 22 | extern mINI::INIStructure ConfigValues; -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/ini.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * Copyright (c) 2018 Danijel Durakovic 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is furnished to do 10 | * so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // 26 | // /mINI/ v0.9.14 27 | // An INI file reader and writer for the modern age. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // 31 | // A tiny utility library for manipulating INI files with a straightforward 32 | // API and a minimal footprint. It conforms to the (somewhat) standard INI 33 | // format - sections and keys are case insensitive and all leading and 34 | // trailing whitespace is ignored. Comments are lines that begin with a 35 | // semicolon. Trailing comments are allowed on section lines. 36 | // 37 | // Files are read on demand, upon which data is kept in memory and the file 38 | // is closed. This utility supports lazy writing, which only writes changes 39 | // and updates to a file and preserves custom formatting and comments. A lazy 40 | // write invoked by a write() call will read the output file, find what 41 | // changes have been made and update the file accordingly. If you only need to 42 | // generate files, use generate() instead. Section and key order is preserved 43 | // on read, write and insert. 44 | // 45 | /////////////////////////////////////////////////////////////////////////////// 46 | // 47 | // /* BASIC USAGE EXAMPLE: */ 48 | // 49 | // /* read from file */ 50 | // mINI::INIFile file("myfile.ini"); 51 | // mINI::INIStructure ini; 52 | // file.read(ini); 53 | // 54 | // /* read value; gets a reference to actual value in the structure. 55 | // if key or section don't exist, a new empty value will be created */ 56 | // std::string& value = ini["section"]["key"]; 57 | // 58 | // /* read value safely; gets a copy of value in the structure. 59 | // does not alter the structure */ 60 | // std::string value = ini.get("section").get("key"); 61 | // 62 | // /* set or update values */ 63 | // ini["section"]["key"] = "value"; 64 | // 65 | // /* set multiple values */ 66 | // ini["section2"].set({ 67 | // {"key1", "value1"}, 68 | // {"key2", "value2"} 69 | // }); 70 | // 71 | // /* write updates back to file, preserving comments and formatting */ 72 | // file.write(ini); 73 | // 74 | // /* or generate a file (overwrites the original) */ 75 | // file.generate(ini); 76 | // 77 | /////////////////////////////////////////////////////////////////////////////// 78 | // 79 | // Long live the INI file!!! 80 | // 81 | /////////////////////////////////////////////////////////////////////////////// 82 | 83 | #ifndef MINI_INI_H_ 84 | #define MINI_INI_H_ 85 | 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | #include 94 | #include 95 | #include 96 | 97 | namespace mINI 98 | { 99 | namespace INIStringUtil 100 | { 101 | const char* const whitespaceDelimiters = " \t\n\r\f\v"; 102 | inline void trim(std::string& str) 103 | { 104 | str.erase(str.find_last_not_of(whitespaceDelimiters) + 1); 105 | str.erase(0, str.find_first_not_of(whitespaceDelimiters)); 106 | } 107 | #ifndef MINI_CASE_SENSITIVE 108 | inline void toLower(std::string& str) 109 | { 110 | std::transform(str.begin(), str.end(), str.begin(), [](const char c) { 111 | return static_cast(std::tolower(c)); 112 | }); 113 | } 114 | #endif 115 | inline void replace(std::string& str, std::string const& a, std::string const& b) 116 | { 117 | if (!a.empty()) 118 | { 119 | std::size_t pos = 0; 120 | while ((pos = str.find(a, pos)) != std::string::npos) 121 | { 122 | str.replace(pos, a.size(), b); 123 | pos += b.size(); 124 | } 125 | } 126 | } 127 | #ifdef _WIN32 128 | const char* const endl = "\r\n"; 129 | #else 130 | const char* const endl = "\n"; 131 | #endif 132 | } 133 | 134 | template 135 | class INIMap 136 | { 137 | private: 138 | using T_DataIndexMap = std::unordered_map; 139 | using T_DataItem = std::pair; 140 | using T_DataContainer = std::vector; 141 | using T_MultiArgs = typename std::vector>; 142 | 143 | T_DataIndexMap dataIndexMap; 144 | T_DataContainer data; 145 | 146 | inline std::size_t setEmpty(std::string& key) 147 | { 148 | std::size_t index = data.size(); 149 | dataIndexMap[key] = index; 150 | data.emplace_back(key, T()); 151 | return index; 152 | } 153 | 154 | public: 155 | using const_iterator = typename T_DataContainer::const_iterator; 156 | 157 | INIMap() { } 158 | 159 | INIMap(INIMap const& other) 160 | { 161 | std::size_t data_size = other.data.size(); 162 | for (std::size_t i = 0; i < data_size; ++i) 163 | { 164 | auto const& key = other.data[i].first; 165 | auto const& obj = other.data[i].second; 166 | data.emplace_back(key, obj); 167 | } 168 | dataIndexMap = T_DataIndexMap(other.dataIndexMap); 169 | } 170 | 171 | T& operator[](std::string key) 172 | { 173 | INIStringUtil::trim(key); 174 | #ifndef MINI_CASE_SENSITIVE 175 | INIStringUtil::toLower(key); 176 | #endif 177 | auto it = dataIndexMap.find(key); 178 | bool hasIt = (it != dataIndexMap.end()); 179 | std::size_t index = (hasIt) ? it->second : setEmpty(key); 180 | return data[index].second; 181 | } 182 | T get(std::string key) const 183 | { 184 | INIStringUtil::trim(key); 185 | #ifndef MINI_CASE_SENSITIVE 186 | INIStringUtil::toLower(key); 187 | #endif 188 | auto it = dataIndexMap.find(key); 189 | if (it == dataIndexMap.end()) 190 | { 191 | return T(); 192 | } 193 | return T(data[it->second].second); 194 | } 195 | bool has(std::string key) const 196 | { 197 | INIStringUtil::trim(key); 198 | #ifndef MINI_CASE_SENSITIVE 199 | INIStringUtil::toLower(key); 200 | #endif 201 | return (dataIndexMap.count(key) == 1); 202 | } 203 | void set(std::string key, T obj) 204 | { 205 | INIStringUtil::trim(key); 206 | #ifndef MINI_CASE_SENSITIVE 207 | INIStringUtil::toLower(key); 208 | #endif 209 | auto it = dataIndexMap.find(key); 210 | if (it != dataIndexMap.end()) 211 | { 212 | data[it->second].second = obj; 213 | } 214 | else 215 | { 216 | dataIndexMap[key] = data.size(); 217 | data.emplace_back(key, obj); 218 | } 219 | } 220 | void set(T_MultiArgs const& multiArgs) 221 | { 222 | for (auto const& it : multiArgs) 223 | { 224 | auto const& key = it.first; 225 | auto const& obj = it.second; 226 | set(key, obj); 227 | } 228 | } 229 | bool remove(std::string key) 230 | { 231 | INIStringUtil::trim(key); 232 | #ifndef MINI_CASE_SENSITIVE 233 | INIStringUtil::toLower(key); 234 | #endif 235 | auto it = dataIndexMap.find(key); 236 | if (it != dataIndexMap.end()) 237 | { 238 | std::size_t index = it->second; 239 | data.erase(data.begin() + index); 240 | dataIndexMap.erase(it); 241 | for (auto& it2 : dataIndexMap) 242 | { 243 | auto& vi = it2.second; 244 | if (vi > index) 245 | { 246 | vi--; 247 | } 248 | } 249 | return true; 250 | } 251 | return false; 252 | } 253 | void clear() 254 | { 255 | data.clear(); 256 | dataIndexMap.clear(); 257 | } 258 | std::size_t size() const 259 | { 260 | return data.size(); 261 | } 262 | const_iterator begin() const { return data.begin(); } 263 | const_iterator end() const { return data.end(); } 264 | }; 265 | 266 | using INIStructure = INIMap>; 267 | 268 | namespace INIParser 269 | { 270 | using T_ParseValues = std::pair; 271 | 272 | enum class PDataType : char 273 | { 274 | PDATA_NONE, 275 | PDATA_COMMENT, 276 | PDATA_SECTION, 277 | PDATA_KEYVALUE, 278 | PDATA_UNKNOWN 279 | }; 280 | 281 | inline PDataType parseLine(std::string line, T_ParseValues& parseData) 282 | { 283 | parseData.first.clear(); 284 | parseData.second.clear(); 285 | INIStringUtil::trim(line); 286 | if (line.empty()) 287 | { 288 | return PDataType::PDATA_NONE; 289 | } 290 | char firstCharacter = line[0]; 291 | if (firstCharacter == ';') 292 | { 293 | return PDataType::PDATA_COMMENT; 294 | } 295 | if (firstCharacter == '[') 296 | { 297 | auto commentAt = line.find_first_of(';'); 298 | if (commentAt != std::string::npos) 299 | { 300 | line = line.substr(0, commentAt); 301 | } 302 | auto closingBracketAt = line.find_last_of(']'); 303 | if (closingBracketAt != std::string::npos) 304 | { 305 | auto section = line.substr(1, closingBracketAt - 1); 306 | INIStringUtil::trim(section); 307 | parseData.first = section; 308 | return PDataType::PDATA_SECTION; 309 | } 310 | } 311 | auto lineNorm = line; 312 | INIStringUtil::replace(lineNorm, "\\=", " "); 313 | auto equalsAt = lineNorm.find_first_of('='); 314 | if (equalsAt != std::string::npos) 315 | { 316 | auto key = line.substr(0, equalsAt); 317 | INIStringUtil::trim(key); 318 | INIStringUtil::replace(key, "\\=", "="); 319 | auto value = line.substr(equalsAt + 1); 320 | INIStringUtil::trim(value); 321 | parseData.first = key; 322 | parseData.second = value; 323 | return PDataType::PDATA_KEYVALUE; 324 | } 325 | return PDataType::PDATA_UNKNOWN; 326 | } 327 | } 328 | 329 | class INIReader 330 | { 331 | public: 332 | using T_LineData = std::vector; 333 | using T_LineDataPtr = std::shared_ptr; 334 | 335 | bool isBOM = false; 336 | 337 | private: 338 | std::ifstream fileReadStream; 339 | T_LineDataPtr lineData; 340 | 341 | T_LineData readFile() 342 | { 343 | fileReadStream.seekg(0, std::ios::end); 344 | const std::size_t fileSize = static_cast(fileReadStream.tellg()); 345 | fileReadStream.seekg(0, std::ios::beg); 346 | if (fileSize >= 3) { 347 | const char header[3] = { 348 | static_cast(fileReadStream.get()), 349 | static_cast(fileReadStream.get()), 350 | static_cast(fileReadStream.get()) 351 | }; 352 | isBOM = ( 353 | header[0] == static_cast(0xEF) && 354 | header[1] == static_cast(0xBB) && 355 | header[2] == static_cast(0xBF) 356 | ); 357 | } 358 | else { 359 | isBOM = false; 360 | } 361 | std::string fileContents; 362 | fileContents.resize(fileSize); 363 | fileReadStream.seekg(isBOM ? 3 : 0, std::ios::beg); 364 | fileReadStream.read(&fileContents[0], fileSize); 365 | fileReadStream.close(); 366 | T_LineData output; 367 | if (fileSize == 0) 368 | { 369 | return output; 370 | } 371 | std::string buffer; 372 | buffer.reserve(50); 373 | for (std::size_t i = 0; i < fileSize; ++i) 374 | { 375 | char& c = fileContents[i]; 376 | if (c == '\n') 377 | { 378 | output.emplace_back(buffer); 379 | buffer.clear(); 380 | continue; 381 | } 382 | if (c != '\0' && c != '\r') 383 | { 384 | buffer += c; 385 | } 386 | } 387 | output.emplace_back(buffer); 388 | return output; 389 | } 390 | 391 | public: 392 | INIReader(std::string const& filename, bool keepLineData = false) 393 | { 394 | fileReadStream.open(filename, std::ios::in | std::ios::binary); 395 | if (keepLineData) 396 | { 397 | lineData = std::make_shared(); 398 | } 399 | } 400 | ~INIReader() { } 401 | 402 | bool operator>>(INIStructure& data) 403 | { 404 | if (!fileReadStream.is_open()) 405 | { 406 | return false; 407 | } 408 | T_LineData fileLines = readFile(); 409 | std::string section; 410 | bool inSection = false; 411 | INIParser::T_ParseValues parseData; 412 | for (auto const& line : fileLines) 413 | { 414 | auto parseResult = INIParser::parseLine(line, parseData); 415 | if (parseResult == INIParser::PDataType::PDATA_SECTION) 416 | { 417 | inSection = true; 418 | data[section = parseData.first]; 419 | } 420 | else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE) 421 | { 422 | auto const& key = parseData.first; 423 | auto const& value = parseData.second; 424 | data[section][key] = value; 425 | } 426 | if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN) 427 | { 428 | if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection) 429 | { 430 | continue; 431 | } 432 | lineData->emplace_back(line); 433 | } 434 | } 435 | return true; 436 | } 437 | T_LineDataPtr getLines() 438 | { 439 | return lineData; 440 | } 441 | }; 442 | 443 | class INIGenerator 444 | { 445 | private: 446 | std::ofstream fileWriteStream; 447 | 448 | public: 449 | bool prettyPrint = false; 450 | 451 | INIGenerator(std::string const& filename) 452 | { 453 | fileWriteStream.open(filename, std::ios::out | std::ios::binary); 454 | } 455 | ~INIGenerator() { } 456 | 457 | bool operator<<(INIStructure const& data) 458 | { 459 | if (!fileWriteStream.is_open()) 460 | { 461 | return false; 462 | } 463 | if (!data.size()) 464 | { 465 | return true; 466 | } 467 | auto it = data.begin(); 468 | for (;;) 469 | { 470 | auto const& section = it->first; 471 | auto const& collection = it->second; 472 | fileWriteStream 473 | << "[" 474 | << section 475 | << "]"; 476 | if (collection.size()) 477 | { 478 | fileWriteStream << INIStringUtil::endl; 479 | auto it2 = collection.begin(); 480 | for (;;) 481 | { 482 | auto key = it2->first; 483 | INIStringUtil::replace(key, "=", "\\="); 484 | auto value = it2->second; 485 | INIStringUtil::trim(value); 486 | fileWriteStream 487 | << key 488 | << ((prettyPrint) ? " = " : "=") 489 | << value; 490 | if (++it2 == collection.end()) 491 | { 492 | break; 493 | } 494 | fileWriteStream << INIStringUtil::endl; 495 | } 496 | } 497 | if (++it == data.end()) 498 | { 499 | break; 500 | } 501 | fileWriteStream << INIStringUtil::endl; 502 | if (prettyPrint) 503 | { 504 | fileWriteStream << INIStringUtil::endl; 505 | } 506 | } 507 | return true; 508 | } 509 | }; 510 | 511 | class INIWriter 512 | { 513 | private: 514 | using T_LineData = std::vector; 515 | using T_LineDataPtr = std::shared_ptr; 516 | 517 | std::string filename; 518 | 519 | T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original) 520 | { 521 | T_LineData output; 522 | INIParser::T_ParseValues parseData; 523 | std::string sectionCurrent; 524 | bool parsingSection = false; 525 | bool continueToNextSection = false; 526 | bool discardNextEmpty = false; 527 | bool writeNewKeys = false; 528 | std::size_t lastKeyLine = 0; 529 | for (auto line = lineData->begin(); line != lineData->end(); ++line) 530 | { 531 | if (!writeNewKeys) 532 | { 533 | auto parseResult = INIParser::parseLine(*line, parseData); 534 | if (parseResult == INIParser::PDataType::PDATA_SECTION) 535 | { 536 | if (parsingSection) 537 | { 538 | writeNewKeys = true; 539 | parsingSection = false; 540 | --line; 541 | continue; 542 | } 543 | sectionCurrent = parseData.first; 544 | if (data.has(sectionCurrent)) 545 | { 546 | parsingSection = true; 547 | continueToNextSection = false; 548 | discardNextEmpty = false; 549 | output.emplace_back(*line); 550 | lastKeyLine = output.size(); 551 | } 552 | else 553 | { 554 | continueToNextSection = true; 555 | discardNextEmpty = true; 556 | continue; 557 | } 558 | } 559 | else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE) 560 | { 561 | if (continueToNextSection) 562 | { 563 | continue; 564 | } 565 | if (data.has(sectionCurrent)) 566 | { 567 | auto& collection = data[sectionCurrent]; 568 | auto const& key = parseData.first; 569 | auto const& value = parseData.second; 570 | if (collection.has(key)) 571 | { 572 | auto outputValue = collection[key]; 573 | if (value == outputValue) 574 | { 575 | output.emplace_back(*line); 576 | } 577 | else 578 | { 579 | INIStringUtil::trim(outputValue); 580 | auto lineNorm = *line; 581 | INIStringUtil::replace(lineNorm, "\\=", " "); 582 | auto equalsAt = lineNorm.find_first_of('='); 583 | auto valueAt = lineNorm.find_first_not_of( 584 | INIStringUtil::whitespaceDelimiters, 585 | equalsAt + 1 586 | ); 587 | std::string outputLine = line->substr(0, valueAt); 588 | if (prettyPrint && equalsAt + 1 == valueAt) 589 | { 590 | outputLine += " "; 591 | } 592 | outputLine += outputValue; 593 | output.emplace_back(outputLine); 594 | } 595 | lastKeyLine = output.size(); 596 | } 597 | } 598 | } 599 | else 600 | { 601 | if (discardNextEmpty && line->empty()) 602 | { 603 | discardNextEmpty = false; 604 | } 605 | else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN) 606 | { 607 | output.emplace_back(*line); 608 | } 609 | } 610 | } 611 | if (writeNewKeys || std::next(line) == lineData->end()) 612 | { 613 | T_LineData linesToAdd; 614 | if (data.has(sectionCurrent) && original.has(sectionCurrent)) 615 | { 616 | auto const& collection = data[sectionCurrent]; 617 | auto const& collectionOriginal = original[sectionCurrent]; 618 | for (auto const& it : collection) 619 | { 620 | auto key = it.first; 621 | if (collectionOriginal.has(key)) 622 | { 623 | continue; 624 | } 625 | auto value = it.second; 626 | INIStringUtil::replace(key, "=", "\\="); 627 | INIStringUtil::trim(value); 628 | linesToAdd.emplace_back( 629 | key + ((prettyPrint) ? " = " : "=") + value 630 | ); 631 | } 632 | } 633 | if (!linesToAdd.empty()) 634 | { 635 | output.insert( 636 | output.begin() + lastKeyLine, 637 | linesToAdd.begin(), 638 | linesToAdd.end() 639 | ); 640 | } 641 | if (writeNewKeys) 642 | { 643 | writeNewKeys = false; 644 | --line; 645 | } 646 | } 647 | } 648 | for (auto const& it : data) 649 | { 650 | auto const& section = it.first; 651 | if (original.has(section)) 652 | { 653 | continue; 654 | } 655 | if (prettyPrint && output.size() > 0 && !output.back().empty()) 656 | { 657 | output.emplace_back(); 658 | } 659 | output.emplace_back("[" + section + "]"); 660 | auto const& collection = it.second; 661 | for (auto const& it2 : collection) 662 | { 663 | auto key = it2.first; 664 | auto value = it2.second; 665 | INIStringUtil::replace(key, "=", "\\="); 666 | INIStringUtil::trim(value); 667 | output.emplace_back( 668 | key + ((prettyPrint) ? " = " : "=") + value 669 | ); 670 | } 671 | } 672 | return output; 673 | } 674 | 675 | public: 676 | bool prettyPrint = false; 677 | 678 | INIWriter(std::string const& filename) 679 | : filename(filename) 680 | { 681 | } 682 | ~INIWriter() { } 683 | 684 | bool operator<<(INIStructure& data) 685 | { 686 | struct stat buf; 687 | bool fileExists = (stat(filename.c_str(), &buf) == 0); 688 | if (!fileExists) 689 | { 690 | INIGenerator generator(filename); 691 | generator.prettyPrint = prettyPrint; 692 | return generator << data; 693 | } 694 | INIStructure originalData; 695 | T_LineDataPtr lineData; 696 | bool readSuccess = false; 697 | bool fileIsBOM = false; 698 | { 699 | INIReader reader(filename, true); 700 | if ((readSuccess = reader >> originalData)) 701 | { 702 | lineData = reader.getLines(); 703 | fileIsBOM = reader.isBOM; 704 | } 705 | } 706 | if (!readSuccess) 707 | { 708 | return false; 709 | } 710 | T_LineData output = getLazyOutput(lineData, data, originalData); 711 | std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary); 712 | if (fileWriteStream.is_open()) 713 | { 714 | if (fileIsBOM) { 715 | const char utf8_BOM[3] = { 716 | static_cast(0xEF), 717 | static_cast(0xBB), 718 | static_cast(0xBF) 719 | }; 720 | fileWriteStream.write(utf8_BOM, 3); 721 | } 722 | if (output.size()) 723 | { 724 | auto line = output.begin(); 725 | for (;;) 726 | { 727 | fileWriteStream << *line; 728 | if (++line == output.end()) 729 | { 730 | break; 731 | } 732 | fileWriteStream << INIStringUtil::endl; 733 | } 734 | } 735 | return true; 736 | } 737 | return false; 738 | } 739 | }; 740 | 741 | class INIFile 742 | { 743 | private: 744 | std::string filename; 745 | 746 | public: 747 | INIFile(std::string const& filename) 748 | : filename(filename) 749 | { } 750 | 751 | ~INIFile() { } 752 | 753 | bool read(INIStructure& data) const 754 | { 755 | if (data.size()) 756 | { 757 | data.clear(); 758 | } 759 | if (filename.empty()) 760 | { 761 | return false; 762 | } 763 | INIReader reader(filename); 764 | return reader >> data; 765 | } 766 | bool generate(INIStructure const& data, bool pretty = false) const 767 | { 768 | if (filename.empty()) 769 | { 770 | return false; 771 | } 772 | INIGenerator generator(filename); 773 | generator.prettyPrint = pretty; 774 | return generator << data; 775 | } 776 | bool write(INIStructure& data, bool pretty = false) const 777 | { 778 | if (filename.empty()) 779 | { 780 | return false; 781 | } 782 | INIWriter writer(filename); 783 | writer.prettyPrint = pretty; 784 | return writer << data; 785 | } 786 | }; 787 | } 788 | 789 | #endif // MINI_INI_H_ 790 | -------------------------------------------------------------------------------- /MGSFPSUnlock/includes/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | 5 | //#include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MGSFPSUnlock 2 | This is an experimental mod that allows you to play Metal Gear Solid 3 at framerates above (and below) 60. This mod is a work in progress so you should expect there to be issues. 3 | 4 | ## How to use 5 | 6 | 1. Download `MGSFPSUnlock.zip` from the [releases](https://github.com/cipherxof/MGSFPSUnlock/releases) page 7 | 2. Extract to your MGS3 install location (i.e `C:\Program Files (x86)\Steam\steamapps\common\MGS3`) 8 | 3. Edit `MGSFPSUnlock.ini` and choose your target framerate. 9 | 4. Install [MGSHDFix](https://github.com/Lyall/MGSHDFix) and enable Borderless Windowed mode (this shouldn't be required in the future) 10 | 11 | ## Todo 12 | - [x] MGS3 Support 13 | - [ ] MGS2 Support 14 | - [ ] Variable Framerate 15 | 16 | ## Building 17 | 18 | ```bash 19 | git clone https://github.com/cipherxof/MGSFPSUnlock.git 20 | cd MGSFPSUnlock 21 | git submodule update --init 22 | ``` 23 | 24 | ### Windows 25 | 26 | Open MGSFPSUnlock.sln in Visual Studio (2022) and build 27 | 28 | ### Linux 29 | 30 | Install `mingw-w64-gcc` 31 | 32 | ```bash 33 | mkdir build && cd build 34 | cmake .. 35 | make 36 | ``` -------------------------------------------------------------------------------- /mingw-toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Windows) 2 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 3 | 4 | set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) 5 | set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) 6 | 7 | set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 /usr/x86_64-w64-mingw32/sys-root/mingw) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 10 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) --------------------------------------------------------------------------------