├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── AudioScripts ├── BGM │ ├── BGM-Map.csv │ ├── Build-BGM-Files.bat │ ├── README.md │ ├── adx2aix.exe │ ├── adxencd.exe │ ├── aix.txt │ ├── aix2adx.c │ ├── aix2adx.exe │ └── aixhist.txt ├── Dialog │ ├── AFSPacker-readme.txt │ ├── AFSPacker.exe │ ├── Build-Dialog-Files.bat │ ├── Dialog-Map.csv │ ├── README.md │ └── adxencd.exe ├── License.txt ├── README.md └── SFX │ ├── License.txt │ ├── README.md │ ├── SFX-Map.csv │ ├── mergebin.cpp │ ├── mergebin.exe │ ├── mergebin.vcxproj │ ├── splitbin.cpp │ ├── splitbin.exe │ └── splitbin.vcxproj ├── Common ├── AutoUpdate.cpp ├── AutoUpdate.h ├── FileSystemHooks.cpp ├── FileSystemHooks.h ├── GfxUtils.cpp ├── GfxUtils.h ├── IUnknownPtr.h ├── License.txt ├── LoadModules.cpp ├── LoadModules.h ├── ModelGLTF.cpp ├── ModelGLTF.h ├── Settings.cpp ├── Settings.h ├── Settings.ini ├── Unicode.h ├── Utils.cpp ├── Utils.h ├── md5.cpp └── md5.h ├── Include ├── GTA │ ├── CFileMgr.h │ └── WSF.h ├── VersionHelpers.h ├── criware │ ├── criware.h │ ├── criware_adx.cpp │ ├── criware_adx.h │ ├── criware_adxfic.cpp │ ├── criware_adxfic.h │ ├── criware_afs.cpp │ ├── criware_afs.h │ ├── criware_aix.cpp │ ├── criware_aix.h │ ├── criware_debug.cpp │ ├── criware_debug.h │ ├── criware_decode.cpp │ ├── criware_dsound.cpp │ ├── criware_dsound.h │ ├── criware_file.cpp │ ├── criware_file.h │ ├── criware_lock.cpp │ ├── criware_lock.h │ ├── criware_main.cpp │ ├── criware_sound.cpp │ ├── criware_sound.h │ ├── criware_xaudio2.cpp │ └── criware_xaudio2.h ├── stdafx.h ├── tinygltf │ ├── json.hpp │ └── tiny_gltf.h ├── winmm.cpp └── winmm.h ├── Launcher ├── BuildNo.rc ├── CConfig.cpp ├── CConfig.h ├── CWnd.cpp ├── CWnd.h ├── LICENSE ├── Launcher.cpp ├── Launcher.ico ├── Launcher.rc ├── Launcher.vcxproj ├── Launcher.vcxproj.filters ├── Resource.h ├── UALx86.rc ├── config.xml ├── config_br.xml ├── config_es.xml ├── config_it.xml └── manifest.xml ├── License.txt ├── Logging ├── License.txt ├── Logging.cpp └── Logging.h ├── Patches ├── 2TBHardDriveFix.cpp ├── AdvancedOptionsFix.cpp ├── AtticShadowFixes.cpp ├── BloodSize.cpp ├── CatacombsMeatRoom.cpp ├── ChangeClosetSpawn.cpp ├── ClosetCutscene.cpp ├── CockroachesReplacement.cpp ├── CommandWindowMouseFix.cpp ├── Common.cpp ├── ControllerTweaks.cpp ├── CreatureVehicleSpawn.cpp ├── CustomAdvancedOptions.cpp ├── DelayedFadeIn.cpp ├── DelayedStart.cpp ├── DisableRedCrossDuringCutscenes.cpp ├── DisableShadowCutscene.cpp ├── DoubleFootstepFix.cpp ├── DrawDistance.cpp ├── ElevatorCursorColorFix.cpp ├── EnhancedFlashlight.cpp ├── FMVPatches.cpp ├── FinalBossRoomFix.cpp ├── FireEscapeKey.cpp ├── FlashlightClockPush.cpp ├── FlashlightFlicker.cpp ├── FlashlightReflection.cpp ├── FlashlightReflection.h ├── FmvSubtitles.cpp ├── FogAdjustments.cpp ├── FogFix.cpp ├── Fonts.cpp ├── FullscreenImages.cpp ├── FullscreenImages.h ├── FullscreenVideos.cpp ├── GameLoad.cpp ├── HangOnEsc.cpp ├── HoldDamage.cpp ├── HoldToStomp.cpp ├── HospitalChase.cpp ├── HotelWater.cpp ├── InputTweaks.cpp ├── InputTweaks.h ├── Langs.cpp ├── LaunchAsAdmin.cpp ├── LeaveEndingDrawDistance.cpp ├── License.txt ├── LightingPatch.cpp ├── LightingTransition.cpp ├── LowHealthIndicator.cpp ├── MainMenu.cpp ├── MapTranscription.cpp ├── MemoFix.cpp ├── MenuSounds.cpp ├── ModelID.h ├── MothDrawOrder.cpp ├── NoCDPatch.cpp ├── ObservationDeckFogFix.cpp ├── OldManCoinFix.cpp ├── OptionsMenuTweaks.cpp ├── OptionsMenuTweaks.h ├── PS2NoiseFilter.cpp ├── PatchBinary.cpp ├── PatchCriware.cpp ├── PatchInventoryBGM.cpp ├── Patches.h ├── PauseScreen.cpp ├── PistonRoom.cpp ├── PlayWavSound.cpp ├── PreventChainsawSpawn.cpp ├── PrisonerTimer.cpp ├── PuzzleAlignmentFixes.cpp ├── PuzzleAlignmentFixes.h ├── QuickSaveCancelFix.cpp ├── QuickSaveTweaks.cpp ├── ReplaceWindowTitle.cpp ├── Resolution.cpp ├── Room312FlashlightFix.cpp ├── Room312Shadow.cpp ├── RotatingMannequinGlitch.cpp ├── RowboatAnimation.cpp ├── RowboatFix.cpp ├── SaveBGImage.cpp ├── SfxPatch.cpp ├── SfxPatch.h ├── ShowerRoomFlashlightFix.cpp ├── SixtyFPSPatch.cpp ├── SixtyFPSPatch.h ├── SpecialFX.cpp ├── SpecificSoundLoopFix.cpp ├── Specular.cpp ├── SprayEffect.cpp ├── SwapLightHeavyAttack.cpp ├── TeddyBearLookFix.cpp ├── TexPatch.cpp ├── TreeLighting.cpp ├── VHSAudio.cpp ├── ValidateBinary.cpp ├── WaterDrawOrderFix.cpp ├── WaterEnhancement.cpp ├── WaterEnhancement_caustics.h └── WaterEnhancement_dudv.h ├── README.md ├── ReShade ├── LICENSE.md ├── ReShadeFX │ ├── LICENSE.md │ ├── ReShadeFX.vcxproj │ ├── ReShadeFX.vcxproj.filters │ └── spirv.props ├── Runtime │ ├── LICENSE.md │ ├── runtime.cpp │ ├── runtime.hpp │ ├── runtime_config.cpp │ ├── runtime_config.hpp │ └── runtime_objects.hpp └── stb │ ├── LICENSE.md │ ├── stb.props │ ├── stb.vcxproj │ └── stb_impl.c ├── Resolution.h ├── Resources ├── AreaTex.dds ├── BuildNo.rc ├── Frutbunn.fx ├── Lottes.fx ├── PirateBloom.fx ├── ReShade.ini ├── Refresh.fx ├── Resource.h ├── SH2EEsetup.exe ├── SMAA.fx ├── SearchTex.dds ├── UALx86.rc ├── Xidi.ini ├── alsoft.ini ├── dinput8.dll ├── exe_str_e.txt ├── exe_str_f.txt ├── exe_str_g.txt ├── exe_str_i.txt ├── exe_str_j.txt ├── exe_str_s.txt ├── sh2-enhce.rc ├── sh2.ico ├── sh2pc.ips ├── sh2pc.txt └── webcsv.url ├── WidescreenFixesPack ├── License.txt ├── WidescreenFixesPack.cpp └── WidescreenFixesPack.h ├── Wrappers ├── BuildNo.rc ├── License.txt ├── d3d8.h ├── d3d8 │ ├── AddressLookupTable.h │ ├── DirectX81SDK │ │ └── include │ │ │ ├── .gitignore │ │ │ ├── d3d8.h │ │ │ ├── d3d8.lib │ │ │ ├── d3d8caps.h │ │ │ ├── d3d8types.h │ │ │ ├── d3dx8.h │ │ │ ├── d3dx8.lib │ │ │ ├── d3dx8core.h │ │ │ ├── d3dx8effect.h │ │ │ ├── d3dx8math.h │ │ │ ├── d3dx8math.inl │ │ │ ├── d3dx8mesh.h │ │ │ ├── d3dx8shape.h │ │ │ ├── d3dx8tex.h │ │ │ ├── dxfile.h │ │ │ └── libci.lib │ ├── IDirect3D8.cpp │ ├── IDirect3D8.h │ ├── IDirect3DCubeTexture8.cpp │ ├── IDirect3DCubeTexture8.h │ ├── IDirect3DDevice8.cpp │ ├── IDirect3DDevice8.h │ ├── IDirect3DIndexBuffer8.cpp │ ├── IDirect3DIndexBuffer8.h │ ├── IDirect3DSurface8.cpp │ ├── IDirect3DSurface8.h │ ├── IDirect3DSwapChain8.cpp │ ├── IDirect3DSwapChain8.h │ ├── IDirect3DTexture8.cpp │ ├── IDirect3DTexture8.h │ ├── IDirect3DVertexBuffer8.cpp │ ├── IDirect3DVertexBuffer8.h │ ├── IDirect3DVolume8.cpp │ ├── IDirect3DVolume8.h │ ├── IDirect3DVolumeTexture8.cpp │ ├── IDirect3DVolumeTexture8.h │ ├── InterfaceQuery.cpp │ ├── License.txt │ ├── Overlay.cpp │ ├── Overlay.h │ ├── d3d8wrapper.cpp │ └── d3d8wrapper.h ├── d3d8to9.cpp ├── d3d8to9.h ├── d3d9 │ ├── IDirect3D9.cpp │ ├── IDirect3D9.h │ ├── IDirect3DDevice9.cpp │ ├── IDirect3DDevice9.h │ ├── IDirect3DSwapChain9.cpp │ ├── IDirect3DSwapChain9.h │ ├── LICENSE.md │ ├── buffer_detection.cpp │ ├── buffer_detection.hpp │ ├── com_ptr.hpp │ ├── d3d9wrapper.cpp │ ├── d3d9wrapper.h │ ├── d3dx9.cpp │ ├── d3dx9.h │ ├── d3dx9_data.h │ ├── runtime_d3d9.cpp │ ├── runtime_d3d9.hpp │ ├── state_block.cpp │ └── state_block.hpp ├── dinput8.h ├── dinput8 │ ├── AddressLookupTable.h │ ├── IDirectInput8A.cpp │ ├── IDirectInput8A.h │ ├── IDirectInputDevice8A.cpp │ ├── IDirectInputDevice8A.h │ ├── IDirectInputEffect.cpp │ ├── IDirectInputEffect.h │ ├── InterfaceQuery.cpp │ ├── License.txt │ ├── dinput8wrapper.cpp │ └── dinput8wrapper.h ├── dsound.h ├── dsound │ ├── AddressLookupTable.h │ ├── IDirectSound8.cpp │ ├── IDirectSound8.h │ ├── IDirectSoundBuffer8.cpp │ ├── IDirectSoundBuffer8.h │ ├── InterfaceQuery.cpp │ ├── License.txt │ ├── dsoundwrapper.cpp │ └── dsoundwrapper.h ├── wrapper.cpp ├── wrapper.def └── wrapper.h ├── d3dx ├── License.txt ├── d3dx.vcxproj └── dllmain.cpp ├── dllmain.cpp ├── sh2-enhce.sln ├── sh2-enhce.vcxproj └── sh2-enhce.vcxproj.filters /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | branches: [ "master" ] 7 | workflow_dispatch: 8 | 9 | permissions: 10 | contents: read 11 | 12 | env: 13 | UseMultiToolTask: true 14 | 15 | jobs: 16 | build: 17 | runs-on: windows-latest 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | config: [Workflow] 22 | platform: [Win32] 23 | 24 | steps: 25 | - uses: actions/checkout@v3 26 | with: 27 | submodules: recursive 28 | - uses: microsoft/setup-msbuild@v1 29 | - uses: Trass3r/setup-cpp@master 30 | - name: Build 31 | run: msbuild /m /p:Configuration=${{ matrix.config }} /p:Platform=${{ matrix.platform }} sh2-enhce.sln 32 | - uses: actions/upload-artifact@v4 33 | with: 34 | name: ${{ matrix.config }} binaries 35 | path: | 36 | bin/${{ matrix.config }}/* 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build results 2 | [Bb]in/* 3 | [Oo]bj/* 4 | [Bb]uild/* 5 | [Dd]ebug/* 6 | [Rr]elease/* 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | *.drv 32 | 33 | # Other Visual Studio files 34 | .vs/* 35 | RC* 36 | ipch/* 37 | *.ipch 38 | *.user 39 | *.suo 40 | *.aps 41 | *.log 42 | *.tlog 43 | *.exp 44 | *.ncb 45 | *.res 46 | *.sdf 47 | *.opensdf 48 | *.lastbuildstate 49 | *.ipsh 50 | *.idb 51 | *.pdb 52 | *.db 53 | .opendb 54 | *.opendb 55 | *.TMP 56 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "External/d3d8to9"] 2 | path = External/d3d8to9 3 | url = https://github.com/crosire/d3d8to9 4 | branch = main 5 | [submodule "External/Logging"] 6 | path = External/Logging 7 | url = https://github.com/elishacloud/Logging 8 | [submodule "External/Hooking"] 9 | path = External/Hooking 10 | url = https://github.com/elishacloud/Hooking 11 | [submodule "External/injector"] 12 | path = External/injector 13 | url = https://github.com/thelink2012/injector 14 | [submodule "External/Hooking.Patterns"] 15 | path = External/Hooking.Patterns 16 | url = https://github.com/ThirteenAG/Hooking.Patterns 17 | [submodule "External/reshade"] 18 | path = External/reshade 19 | url = https://github.com/elishacloud/reshade 20 | [submodule "External/WidescreenFixesPack"] 21 | path = External/WidescreenFixesPack 22 | url = https://github.com/ThirteenAG/WidescreenFixesPack 23 | [submodule "external/csvparser"] 24 | path = External/csvparser 25 | url = https://github.com/d99kris/rapidcsv 26 | [submodule "External/xxHash"] 27 | path = External/xxHash 28 | url = https://github.com/Cyan4973/xxHash 29 | [submodule "External/tinyxml2"] 30 | path = External/tinyxml2 31 | url = https://github.com/leethomason/tinyxml2 32 | [submodule "Installer"] 33 | path = Installer 34 | url = https://github.com/nipkownix/SH2EE-web-installer 35 | [submodule "External/MemoryModule"] 36 | path = External/MemoryModule 37 | url = https://github.com/fancycode/MemoryModule 38 | [submodule "External/dsoal"] 39 | path = External/dsoal 40 | url = https://github.com/elishacloud/dsoal 41 | -------------------------------------------------------------------------------- /AudioScripts/BGM/BGM-Map.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/BGM/BGM-Map.csv -------------------------------------------------------------------------------- /AudioScripts/BGM/adx2aix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/BGM/adx2aix.exe -------------------------------------------------------------------------------- /AudioScripts/BGM/adxencd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/BGM/adxencd.exe -------------------------------------------------------------------------------- /AudioScripts/BGM/aix.txt: -------------------------------------------------------------------------------- 1 | AIX header: 2 | 0x00-0x02: "AIX" 3 | 0x03: "F","P", or "E" 4 | 0x04-0x07: offset of next AIX header, from 0x08 5 | 0x08... data 6 | 7 | AIXF data: (starts file) 8 | 0x00 9 | 10 | AIXP header: 11 | 0x00-0x03: "AIXP" 12 | 0x04-0x07: offset to start of next AIXP header (from 0x10) 13 | 0x08: channel number 14 | 0x09: 0x03 (maybe number of channels?) 15 | 0x0a-0x0b: size of data 16 | 0x0c-0x0f: frame number (-1 = first frame, -2 = last frame) 17 | 0x10... data 18 | 19 | AIXE header: 20 | 0x00-0x03: "AIXE" 21 | 0x04-0x07: offset to end of file (or to more AIXPs) -------------------------------------------------------------------------------- /AudioScripts/BGM/aix2adx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // AIX2ADX 0.1 5 | // by hcs 6 | 7 | // get 16-bit big endian value 8 | int get16bit(unsigned char* p) 9 | { 10 | return (p[0] << 8) | p[1]; 11 | } 12 | 13 | // get 32-bit big endian value 14 | int get32bit(unsigned char* p) 15 | { 16 | return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; 17 | } 18 | 19 | int main(int argc, char ** argv) { 20 | FILE * infile, *outfile = NULL; 21 | int channel, chancount, frame, samplerate, size; 22 | int goround, searchstart, eos = 0; 23 | int channeltocopy, curaix, nextaix, done, i; 24 | char buf[0x24], namebase[256], filename[256 + 4]; 25 | char *t; 26 | 27 | // Default print statement 28 | printf("AIX2ADX 0.1 by hcs\n"); 29 | 30 | // CLI help message 31 | if (argc != 2) { printf("usage: %s AIXFILE.AIX\n", argv[0]); return 1; } 32 | 33 | // Open file 34 | infile = fopen(argv[1], "rb"); 35 | if (!infile) { printf("error opening %s\n", argv[1]); return 1; } 36 | 37 | // Generate namebase 38 | t = strrchr(argv[1], '\\'); 39 | if (!t) t = argv[1]; 40 | else t++; 41 | for (i = 0; t < strrchr(argv[1], '.'); t++, i++) namebase[i] = *t; 42 | namebase[i] = '\0'; 43 | 44 | for (goround = 0; goround >= 0; goround++) 45 | { 46 | chancount = -1; 47 | 48 | searchstart = eos; 49 | 50 | for (channeltocopy = 0; chancount < 0 || channeltocopy < chancount; channeltocopy++) 51 | { 52 | fseek(infile, searchstart, SEEK_SET); 53 | curaix = searchstart; 54 | done = 0; 55 | 56 | while (!done) 57 | { 58 | if (fread(buf, 8, 1, infile) != 1) { channeltocopy = chancount = 0; goround = -2; break; } 59 | 60 | if (memcmp(buf, "AIX", 3)) { printf("malformed AIX header at %08x (bad signature)\n", curaix); return 1; } 61 | 62 | nextaix = curaix + 8 + get32bit(buf + 0x4); 63 | 64 | switch (buf[3]) { 65 | case 'F': 66 | printf("file header\n"); 67 | break; 68 | case 'E': 69 | printf("end of section\n"); 70 | done = 1; 71 | eos = nextaix; 72 | break; 73 | case 'P': 74 | fread(buf, 8, 1, infile); 75 | channel = buf[0]; 76 | chancount = buf[1]; 77 | frame = get32bit(buf + 4); 78 | size = get16bit(buf + 2); 79 | 80 | if (channel == channeltocopy) 81 | { 82 | if (!outfile) 83 | { 84 | sprintf(filename, "%s%02d%03d.adx", namebase, goround, channel); 85 | outfile = fopen(filename, "wb"); 86 | if (!outfile) { printf("error opening %s\n", filename); return 1; } 87 | } 88 | printf("goround #%d\tchannel #%d/%d\tframe #%d\tsize: %#08x\n", goround, channel + 1, chancount, frame, size); 89 | for (i = 0; i < size; i++) 90 | { 91 | fread(buf, 1, 1, infile); 92 | fwrite(buf, 1, 1, outfile); 93 | } 94 | } 95 | break; 96 | default: 97 | printf("malformed AIX header at %08x (bad type)\n", curaix); 98 | } 99 | 100 | fseek(infile, nextaix, SEEK_SET); 101 | curaix = nextaix; 102 | } // while (!done) 103 | 104 | if (outfile) { fclose(outfile); outfile = NULL; } 105 | 106 | } // for (channeltocopy) 107 | 108 | } // for (goround) 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /AudioScripts/BGM/aix2adx.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/BGM/aix2adx.exe -------------------------------------------------------------------------------- /AudioScripts/BGM/aixhist.txt: -------------------------------------------------------------------------------- 1 | aix2adx history 2 | 3 | 0.1 - 01/23/06 - will continue to output streams past AIXE marker 4 | 0.0 - 01/22/06 - first version 5 | -------------------------------------------------------------------------------- /AudioScripts/Dialog/AFSPacker-readme.txt: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------# 2 | # AFS Packer - Version 1.1 # 3 | # By PacoChan - http://pacochan.tales-tra.com # 4 | #----------------------------------------------------------------# 5 | 6 | AFS Packer can extract the files of an AFS archive to a folder, or 7 | generate a new AFS archive with the files inside a folder. The AFS format 8 | is used in many games. Many of them from Sega. 9 | 10 | The program requires .NET Framework 3.5. 11 | 12 | Usage: 13 | 14 | AFSPacker -e input_file ouput_dir [list_file] : Extract AFS file 15 | 16 | AFSPacker -c input_dir output_file [list_file] : Create AFS file 17 | 18 | list_file: will create or read a text file containing a list of all 19 | the files that will be extracted/imported from/to the AFS file. 20 | This is useful if you need the files to be in the same 21 | order as in the original AFS (for example: Shenmue 1 & 2). 22 | 23 | 24 | Changelog: 25 | 26 | V1.1: Fixed a crash reading AFS files in games like Arc Rise Fantasia. 27 | V1.0: Initial release. -------------------------------------------------------------------------------- /AudioScripts/Dialog/AFSPacker.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/Dialog/AFSPacker.exe -------------------------------------------------------------------------------- /AudioScripts/Dialog/Dialog-Map.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/Dialog/Dialog-Map.csv -------------------------------------------------------------------------------- /AudioScripts/Dialog/adxencd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/Dialog/adxencd.exe -------------------------------------------------------------------------------- /AudioScripts/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /AudioScripts/SFX/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /AudioScripts/SFX/mergebin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/SFX/mergebin.exe -------------------------------------------------------------------------------- /AudioScripts/SFX/splitbin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | char t_xFileName[MAX_PATH] = { '\0' }; 7 | 8 | static char* GetFileName(DWORD FileNum) 9 | { 10 | char FileName[10] = { '\0' }; 11 | sprintf_s(FileName, "%d", FileNum); 12 | if (strlen(FileName) == 1) 13 | { 14 | FileName[3] = '\0'; 15 | FileName[2] = FileName[0]; 16 | FileName[1] = '0'; 17 | FileName[0] = '0'; 18 | } 19 | else if (strlen(FileName) == 2) 20 | { 21 | FileName[3] = '\0'; 22 | FileName[2] = FileName[1]; 23 | FileName[1] = FileName[0]; 24 | FileName[0] = '0'; 25 | } 26 | 27 | sprintf_s(t_xFileName, "sddata%s.wav", FileName); 28 | return t_xFileName; 29 | } 30 | 31 | int main(int argc, char** argv) 32 | { 33 | printf("MERGEBIN 1.0 by Elisha Riedlinger\n\n"); 34 | 35 | // Vars 36 | ofstream outfile; 37 | ifstream myfile; 38 | DWORD aIndex = 0; 39 | char myPath[MAX_PATH] = { '\0' }; 40 | char folder[MAX_PATH] = { '\0' }; 41 | 42 | // Arguments 43 | if (argc == 1) 44 | { 45 | printf("usage: %s \n", argv[0]); 46 | printf("No folder path found using current folder!\n"); 47 | strcpy_s(folder, ".\\"); 48 | } 49 | else if (argc != 2) 50 | { 51 | printf("usage: %s \n", argv[0]); 52 | return 1; 53 | } 54 | else 55 | { 56 | strcpy_s(folder, argv[1]); 57 | strcat_s(folder, "\\"); 58 | } 59 | 60 | // Open file 61 | sprintf_s(myPath, "%ssddata.bin", folder); 62 | myfile.open(myPath, ios::binary | ios::in | ios::ate); 63 | if (!myfile.is_open()) 64 | { 65 | printf("error opening %s\n", myPath); 66 | return 1; 67 | } 68 | 69 | // Get file bytes 70 | DWORD size = (DWORD)myfile.tellg(); 71 | myfile.seekg(0, ios::beg); 72 | char * memblock; 73 | memblock = new char[size]; 74 | myfile.read(memblock, size); 75 | myfile.close(); 76 | 77 | // Open file 78 | DWORD FileCounter = 0; 79 | sprintf_s(myPath, "%s%s", folder, GetFileName(FileCounter)); 80 | outfile.open(myPath, ios::binary | ios::out); 81 | if (!outfile.is_open()) 82 | { 83 | printf("error creating %s\n", myPath); 84 | return 1; 85 | } 86 | 87 | // Start loop 88 | for (DWORD x = 0; x < size; x++) 89 | { 90 | // Check if new file should be created 91 | if (x + 5 < size && x > 5) 92 | { 93 | if (memblock[x] == 'R' && 94 | memblock[x + 1] == 'I' && 95 | memblock[x + 2] == 'F' && 96 | memblock[x + 3] == 'F') 97 | { 98 | // Close old file 99 | outfile.flush(); 100 | outfile.close(); 101 | 102 | // Start new file 103 | FileCounter++; 104 | sprintf_s(myPath, "%s%s", folder, GetFileName(FileCounter)); 105 | outfile.open(myPath, ios::binary | ios::out); 106 | if (!outfile.is_open()) 107 | { 108 | printf("error creating %s\n", myPath); 109 | return 1; 110 | } 111 | printf("%d - ", FileCounter); 112 | } 113 | } 114 | 115 | // Write byte to file 116 | outfile.write(&memblock[x], 1); 117 | } 118 | 119 | // Delete array 120 | delete[] memblock; 121 | 122 | printf("\n\nCompleted!\n"); 123 | 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /AudioScripts/SFX/splitbin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/AudioScripts/SFX/splitbin.exe -------------------------------------------------------------------------------- /Common/AutoUpdate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | std::string ReadFileContents(std::wstring &path); 4 | DWORD MatchCount(std::string& path1, std::string& path2); 5 | std::string MergeiniFile(std::stringstream &s_currentini, std::stringstream &s_ini, bool OverWriteCurrent = false); 6 | DWORD WINAPI CheckForUpdate(LPVOID lpName); 7 | -------------------------------------------------------------------------------- /Common/FileSystemHooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Settings.h" 4 | 5 | #define VISIT_BGM_FILES(visit) \ 6 | visit(bgm_001, adx, L"\\sound\\adx\\apart") \ 7 | visit(bgm_003, adx, L"\\sound\\adx\\apart") \ 8 | visit(bgm_014, adx, L"\\sound\\adx\\apart") \ 9 | visit(bgm_101, aix, L"\\sound\\adx\\apart") \ 10 | visit(bgm_102, aix, L"\\sound\\adx\\apart") \ 11 | visit(bgm_103, aix, L"\\sound\\adx\\apart") \ 12 | visit(bgm_118, aix, L"\\sound\\adx\\apart") \ 13 | visit(bgm_125, aix, L"\\sound\\adx\\apart") \ 14 | visit(bgm_002, adx, L"\\sound\\adx\\end") \ 15 | visit(bgm_012, adx, L"\\sound\\adx\\end") \ 16 | visit(bgm_022, adx, L"\\sound\\adx\\forest") \ 17 | visit(bgm_114_a, adx, L"\\sound\\adx\\forest") \ 18 | visit(bgm_114_b, aix, L"\\sound\\adx\\forest") \ 19 | visit(bgm_115, aix, L"\\sound\\adx\\forest") \ 20 | visit(bgm_016, adx, L"\\sound\\adx\\hospital") \ 21 | visit(bgm_021, adx, L"\\sound\\adx\\hospital") \ 22 | visit(bgm_100, aix, L"\\sound\\adx\\hospital") \ 23 | visit(bgm_105, aix, L"\\sound\\adx\\hospital") \ 24 | visit(bgm_106, aix, L"\\sound\\adx\\hospital") \ 25 | visit(bgm_111, aix, L"\\sound\\adx\\hospital") \ 26 | visit(bgm_119, aix, L"\\sound\\adx\\hospital") \ 27 | visit(bgm_123, aix, L"\\sound\\adx\\hospital") \ 28 | visit(bgm_007, adx, L"\\sound\\adx\\hotel") \ 29 | visit(bgm_009, adx, L"\\sound\\adx\\hotel") \ 30 | visit(bgm_017, adx, L"\\sound\\adx\\hotel") \ 31 | visit(bgm_108, aix, L"\\sound\\adx\\hotel") \ 32 | visit(bgm_112, aix, L"\\sound\\adx\\hotel") \ 33 | visit(bgm_112_ng, aix, L"\\sound\\adx\\hotel") \ 34 | visit(bgm_113, aix, L"\\sound\\adx\\hotel") \ 35 | visit(bgm_121, aix, L"\\sound\\adx\\hotel") \ 36 | visit(bgm_122, aix, L"\\sound\\adx\\hotel") \ 37 | visit(bgm_124, aix, L"\\sound\\adx\\hotel") \ 38 | visit(bgm_126, adx, L"\\sound\\adx\\hotel") \ 39 | visit(bgm_104, aix, L"\\sound\\adx\\mansion") \ 40 | visit(bgm_015, adx, L"\\sound\\adx\\prison") \ 41 | visit(bgm_020, adx, L"\\sound\\adx\\prison") \ 42 | visit(bgm_107, aix, L"\\sound\\adx\\prison") \ 43 | visit(bgm_109, aix, L"\\sound\\adx\\prison") \ 44 | visit(bgm_110, aix, L"\\sound\\adx\\prison") \ 45 | visit(bgm_116, aix, L"\\sound\\adx\\prison") \ 46 | visit(bgm_120, aix, L"\\sound\\adx\\prison") \ 47 | visit(bgm_128, aix, L"\\sound\\adx\\prison") \ 48 | visit(bgm_004, adx, L"\\sound\\adx\\town") \ 49 | visit(bgm_005, adx, L"\\sound\\adx\\town") \ 50 | visit(bgm_018, adx, L"\\sound\\adx\\town") \ 51 | visit(bgm_117, aix, L"\\sound\\adx\\town") \ 52 | visit(voice, afs, L"\\sound\\adx\\voice") 53 | 54 | template 55 | bool isInString(T strCheck, T str, size_t size); 56 | 57 | char* GetFileModPath(const char* sh2, const char* str); 58 | wchar_t* GetFileModPath(const wchar_t* sh2, const wchar_t* str); 59 | 60 | LPCSTR GetModPath(LPCSTR); 61 | LPCWSTR GetModPath(LPCWSTR); 62 | LPCSTR GetLangPath(LPCSTR); 63 | LPCWSTR GetLangPath(LPCWSTR); 64 | 65 | void InstallCreateProcessHooks(); 66 | void InstallFileSystemHooks(); 67 | -------------------------------------------------------------------------------- /Common/GfxUtils.h: -------------------------------------------------------------------------------- 1 | // added by iOrange in 2024 2 | 3 | #pragma once 4 | 5 | #include "Wrappers\d3d8\d3d8wrapper.h" 6 | 7 | // flags for the GfxCreateTextureFromFile 8 | #define GCTFF_BUILD_MIPS 0x00000001 // will generate mips if not present in the file 9 | 10 | // a replacement for the old and ugly D3DXCreateTextureFromFile 11 | HRESULT GfxCreateTextureFromFileA(LPDIRECT3DDEVICE8 device, LPCSTR srcFile, LPDIRECT3DTEXTURE8* dstTexture, DWORD flags); 12 | HRESULT GfxCreateTextureFromFileW(LPDIRECT3DDEVICE8 device, LPCWSTR srcFile, LPDIRECT3DTEXTURE8* dstTexture, DWORD flags); 13 | 14 | HRESULT GfxCreateTextureFromFileInMem(LPDIRECT3DDEVICE8 device, void* fileMem, DWORD fileSize, LPDIRECT3DTEXTURE8* dstTexture); 15 | 16 | #ifdef UNICODE 17 | #define GfxCreateTextureFromFile GfxCreateTextureFromFileW 18 | #else 19 | #define GfxCreateTextureFromFile GfxCreateTextureFromFileA 20 | #endif 21 | -------------------------------------------------------------------------------- /Common/IUnknownPtr.h: -------------------------------------------------------------------------------- 1 | // added by iOrange in 2024 2 | 3 | #pragma once 4 | 5 | // simplified version of Microsoft::WRL::ComPtr 6 | 7 | template 8 | class IUnknownPtr { 9 | public: 10 | IUnknownPtr() : mPtr(nullptr) {} 11 | 12 | ~IUnknownPtr() { 13 | InternalRelease(); 14 | } 15 | 16 | IUnknownPtr& operator=(decltype(__nullptr)) { 17 | InternalRelease(); 18 | return *this; 19 | } 20 | 21 | IUnknownPtr& operator=(T* other) { 22 | if (mPtr != other) { 23 | InternalRelease(); 24 | mPtr = other; 25 | } 26 | return *this; 27 | } 28 | 29 | operator bool() const { 30 | return mPtr != nullptr; 31 | } 32 | 33 | T* GetPtr() const { 34 | return mPtr; 35 | } 36 | 37 | T* operator->() const { 38 | return mPtr; 39 | } 40 | 41 | T* const* GetAddressOf() const { 42 | return &mPtr; 43 | } 44 | 45 | T** GetAddressOf() { 46 | return &mPtr; 47 | } 48 | 49 | T** ReleaseAndGetAddressOf() { 50 | InternalRelease(); 51 | return &mPtr; 52 | } 53 | 54 | private: 55 | void InternalAddRef() const { 56 | if (mPtr) { 57 | mPtr->AddRef(); 58 | } 59 | } 60 | 61 | unsigned long InternalRelease() { 62 | unsigned long refs = 0ul; 63 | T* temp = mPtr; 64 | 65 | if (temp) { 66 | mPtr = nullptr; 67 | refs = temp->Release(); 68 | } 69 | 70 | return refs; 71 | } 72 | 73 | private: 74 | T* mPtr; 75 | }; 76 | -------------------------------------------------------------------------------- /Common/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Common/LoadModules.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void LoadASIPlugins(bool LoadFromScriptsOnly); 4 | void InitializeASI(HMODULE hModule); 5 | HRESULT DeleteAllfiles(LPCWSTR lpFolder); 6 | -------------------------------------------------------------------------------- /Include/GTA/CFileMgr.h: -------------------------------------------------------------------------------- 1 | #pragma warning(push) 2 | #pragma warning(disable: 4178 4201 4305 4309 4458 4510 4996) 3 | #include "WSF.h" 4 | #pragma warning(pop) 5 | 6 | class CFileMgr 7 | { 8 | public: 9 | static inline FILE* OpenFile(const char* path, const char* mode) 10 | { 11 | #pragma warning(suppress: 4996) 12 | return fopen(path, mode); 13 | }; 14 | static inline int CloseFile(FILE* stream) 15 | { 16 | return fclose(stream); 17 | }; 18 | static inline bool ReadLine(FILE* stream, char* str, int num) 19 | { 20 | return fgets(str, num, stream) != nullptr; 21 | }; 22 | static inline size_t Read(FILE* stream, void* buf, size_t len) 23 | { 24 | return fread(buf, 1, len, stream); 25 | }; 26 | static inline size_t Write(FILE* stream, const char* ptr, size_t len) 27 | { 28 | return fwrite(ptr, 1, len, stream); 29 | }; 30 | static inline bool Seek(FILE* stream, long pos, int from) 31 | { 32 | return fseek(stream, pos, from) != 0; 33 | }; 34 | static inline const char* LoadLine(FILE* hFile) 35 | { 36 | static char cLineBuffer[512]; 37 | 38 | if (!CFileMgr::ReadLine(hFile, cLineBuffer, sizeof(cLineBuffer))) 39 | return nullptr; 40 | 41 | for (int i = 0; cLineBuffer[i]; ++i) 42 | { 43 | if (cLineBuffer[i] == '\n') 44 | cLineBuffer[i] = '\0'; 45 | else if (cLineBuffer[i] < ' ' || cLineBuffer[i] == ',') 46 | cLineBuffer[i] = ' '; 47 | } 48 | 49 | const char* p = cLineBuffer; 50 | while (*p <= ' ') 51 | { 52 | if (!*p++) 53 | break; 54 | } 55 | return p; 56 | }; 57 | }; 58 | -------------------------------------------------------------------------------- /Include/VersionHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // _WIN32_WINNT version constants 3 | // 4 | #define _WIN32_WINNT_VISTA 0x0600 5 | #define _WIN32_WINNT_WIN7 0x0601 6 | #define _WIN32_WINNT_WIN8 0x0602 7 | #define _WIN32_WINNT_WINBLUE 0x0603 8 | 9 | inline bool IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor); 10 | -------------------------------------------------------------------------------- /Include/criware/criware_adx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //------------------------------------------- 4 | typedef struct ADX_headerV3 5 | { 6 | BE16 magic; // 0 7 | BE16 copyright_offset; // 2 8 | BYTE encoding, // 4 9 | block_size, // 5 10 | sample_bitdepth, // 6 11 | channel_count; // 7 12 | BE32 sample_rate, // 8 13 | total_samples; // C 14 | BE16 highpass_frequency; // 10 15 | BYTE version, // 12 16 | flags; // 13 17 | BE16 loop_align_samples, // 14 18 | loop_enabled; // 16 19 | BE32 loop_enabled2, // 18 20 | loop_sample_begin, // 1C 21 | loop_byte_begin, // 20 22 | loop_sample_end, // 24 23 | loop_byte_end, // 28 24 | dummy0, // 2C 25 | dummy1, // 30 26 | dummy2, // 34 27 | dummy3, // 38 28 | dummy4; // 3C 29 | } ADX_headerV3; 30 | 31 | typedef struct ADX_headerAIX 32 | { 33 | BE16 magic; // 0 34 | BE16 copyright_offset; // 2 35 | BYTE encoding, // 4 36 | block_size, // 5 37 | sample_bitdepth, // 6 38 | channel_count; // 7 39 | BE32 sample_rate, // 8 40 | total_samples; // C 41 | BE16 highpass_frequency; // 10 42 | BYTE version, // 12 43 | flags; // 13 44 | } ADX_header_AIX; 45 | 46 | typedef struct ADX_headerV4 47 | { 48 | BE16 magic; // 0 49 | BE16 copyright_offset; // 2 50 | BYTE encoding, // 4 51 | block_size, // 5 52 | sample_bitdepth, // 6 53 | channel_count; // 7 54 | BE32 sample_rate, // 8 55 | total_samples; // C 56 | BE16 highpass_frequency; // 10 57 | BYTE version, // 12 58 | flags; // 13 59 | BE16 loop_align_samples, // 14 60 | dummy0; // 16 61 | BE32 dummy1, // 18 62 | dummy2, // 1C 63 | dummy3, // 20 64 | loop_enabled, // 24 65 | loop_sample_begin, // 28 66 | loop_byte_begin, // 2C 67 | loop_sample_end, // 30 68 | loop_byte_end, // 34 69 | dummy4, // 38 70 | dummy5; // 3C 71 | } ADX_headerV4; 72 | 73 | class SndObjBase; // forward declaration 74 | 75 | class ADXT_Object 76 | { 77 | public: 78 | ADXT_Object(); 79 | ~ADXT_Object(); 80 | 81 | void Reset(); 82 | 83 | void ThSuspend(); // suspend thread 84 | void ThResume(); // resume thread 85 | void ThKill(); // murders thread in a safe way 86 | 87 | CriFileStream* stream; 88 | SndObjBase* obj; 89 | int volume, 90 | state; 91 | // 92 | u_long work_size; 93 | void* work; 94 | u_short maxch; 95 | // state flags 96 | u_short is_aix : 1, 97 | set_volume : 1, 98 | // threading 99 | th_suspended : 1, 100 | th_exit : 1; 101 | volatile int th_wait; 102 | HANDLE th; 103 | 104 | private: 105 | void Thread(); 106 | static DWORD WINAPI thread(LPVOID param); 107 | }; 108 | 109 | void ADXDEC_SetCoeff(CriFileStream* adx); 110 | unsigned ADXDEC_Decode(CriFileStream* adx, short* buffer, unsigned samples_needed, bool looping_enabled); 111 | 112 | int OpenADX(const char* filename, ADXStream** obj); 113 | int OpenADX(ADXStream* adx); 114 | 115 | void adx_StartFname(ADXT_Object* obj, const char* fname); 116 | -------------------------------------------------------------------------------- /Include/criware/criware_adxfic.h: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | #pragma once 4 | 5 | typedef struct ADX_Entry 6 | { 7 | uint32_t hash; 8 | std::string filename; 9 | DWORD size; 10 | } ADX_Entry; 11 | 12 | typedef struct ADXFIC_Object 13 | { 14 | std::vector files; 15 | } ADXFIC_Object; 16 | 17 | ADXFIC_Object* adx_ficCreate(const char* dname); 18 | -------------------------------------------------------------------------------- /Include/criware/criware_afs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int afs_LoadPartitionNw(int ptid, const char* filename, void* ptinfo, void* nfile); 4 | int afs_StartAfs(ADXT_Object* obj, int patid, int fid); 5 | -------------------------------------------------------------------------------- /Include/criware/criware_aix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //------------------------------------------- 3 | // generic header 4 | typedef struct AIX_ENRTY 5 | { 6 | BE32 frequency; 7 | BE32 channels; 8 | } AIX_ENTRY; 9 | 10 | typedef struct AIX_CHUNK 11 | { 12 | BYTE magic[3], // 00 'AIX' 13 | type; // 03 F, P, E 14 | BE32 next; // 04 offset to next header 15 | } AIX_CHUNK; 16 | 17 | typedef struct AIX_HEADER 18 | { 19 | DWORD magic; // 00 'AIXF' 20 | BE32 next; // 04 offset to next header 21 | BE32 unk8, // 08 22 | unkC, // 0C sector alignment? 23 | unk10, // 10 24 | unk14, // 14 25 | unk18, // 18 26 | unk1C, // 1C 27 | unk20, // 20 28 | data_size, // 24 amount of interleaved ADX data 29 | total_samples; // 28 30 | BE32 frequency, // 2C frequency for all streams 31 | unk30, // 30 32 | unk34, // 34 33 | unk38, // 38 34 | unk3C; // 3C 35 | BYTE stream_count, // 40 number of interleaved streams 36 | unk41[3]; // 41 37 | BE32 unk44; // 44 no idea, always zero 38 | AIX_ENTRY entries[759]; // 48 supplementary stream data 39 | } AIX_HEADER; 40 | 41 | // file header 42 | typedef struct AIXF_HEADER 43 | { 44 | BYTE magic[4]; // AIXF 45 | } AIXF_HEADER; 46 | 47 | // properties header 48 | typedef struct AIXP_HEADER 49 | { 50 | BYTE stream_id, 51 | out_channels; 52 | BE16 size; 53 | BE32 frames; 54 | } AIXP_HEADER; 55 | 56 | // end header 57 | typedef struct AIXE_HEADER 58 | { 59 | BYTE magic[4]; // AIXE 60 | } AIXE_HEADER; 61 | 62 | class AIXP_Object 63 | { 64 | public: 65 | AIXP_Object() : stream_no(0), 66 | demuxer(nullptr), 67 | state(AIXP_STAT_STOP), 68 | fname(nullptr), 69 | th(0) 70 | { 71 | } 72 | ~AIXP_Object() 73 | { 74 | Release(); 75 | } 76 | 77 | void Release(); 78 | 79 | int stream_no, 80 | state; 81 | AIX_Demuxer* demuxer; 82 | ADXT_Object adxt[8]; 83 | HANDLE th; // initial caching thread 84 | const char* fname; 85 | }; 86 | 87 | typedef struct AIXP_WORK 88 | { 89 | u_long magic; 90 | AIXP_Object* obj; 91 | } AIXP_WORK; 92 | 93 | int OpenAIX(const char* filename, AIX_Demuxer** obj); 94 | 95 | void aix_start(AIXP_Object* obj, const char* fname); 96 | -------------------------------------------------------------------------------- /Include/criware/criware_debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Gemini 3 | * =============================================================== 4 | * Debugging module 5 | * --------------------------------------------------------------- 6 | * Generic interface for handling error messages. 7 | * =============================================================== 8 | */ 9 | 10 | #include "criware.h" 11 | #include "Wrappers\d3d8\d3d8wrapper.h" 12 | 13 | static int dlevel = 0; 14 | 15 | void ADXD_Error(const char* caption, const char* fmt, ...) 16 | { 17 | if (dlevel) 18 | { 19 | va_list ap; 20 | char buf[256]; 21 | 22 | va_start(ap, fmt); 23 | vsprintf_s(buf, sizeof(buf), fmt, ap); 24 | va_end(ap); 25 | 26 | MessageBoxA(DeviceWindow, buf, caption, MB_ICONERROR | MB_SYSTEMMODAL | MB_TOPMOST); 27 | exit(0); 28 | } 29 | } 30 | 31 | void ADXD_Warning(const char* caption, const char* fmt, ...) 32 | { 33 | if (dlevel) 34 | { 35 | va_list ap; 36 | char buf[256]; 37 | 38 | va_start(ap, fmt); 39 | vsprintf_s(buf, sizeof(buf), fmt, ap); 40 | va_end(ap); 41 | 42 | MessageBoxA(DeviceWindow, buf, caption, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_TOPMOST); 43 | } 44 | } 45 | 46 | void ADXD_Log(const char* fmt, ...) 47 | { 48 | if (dlevel) 49 | { 50 | va_list ap; 51 | char buf[256]; 52 | 53 | va_start(ap, fmt); 54 | vsprintf_s(buf, fmt, ap); 55 | va_end(ap); 56 | 57 | OutputDebugStringA(buf); 58 | } 59 | } 60 | 61 | void ADXD_SetLevel(int level) 62 | { 63 | dlevel = level < 2 ? 0 : 1; 64 | } 65 | -------------------------------------------------------------------------------- /Include/criware/criware_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | #pragma once 4 | 5 | void ADXD_Error(const char* caption, const char* fmt, ...); 6 | void ADXD_Warning(const char* caption, const char* fmt, ...); 7 | void ADXD_Log(const char* fmt, ...); 8 | 9 | void ADXD_SetLevel(int level); 10 | -------------------------------------------------------------------------------- /Include/criware/criware_dsound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !XAUDIO2 4 | 5 | class SndObjDSound : public SndObjBase 6 | { 7 | public: 8 | SndObjDSound() : pBuf(nullptr) 9 | { 10 | Release(); 11 | } 12 | virtual ~SndObjDSound() 13 | { 14 | Release(); 15 | } 16 | 17 | virtual void CreateBuffer(CriFileStream* stream); 18 | 19 | virtual void Play(); 20 | virtual void Stop(); 21 | virtual void Update(); 22 | 23 | virtual void SendData(); 24 | virtual void SetVolume(int vol); 25 | virtual void Release(); 26 | 27 | private: 28 | u_long GetPosition(); 29 | u_long GetPlayedSamples(); 30 | int GetStatus(); 31 | 32 | void Fill(u_long size); 33 | 34 | LPDIRECTSOUNDBUFFER pBuf; 35 | }; 36 | 37 | extern SndObjBase* sound_obj_tbl[SOUND_MAX_OBJ]; 38 | 39 | void adxs_SetupDSound(LPDIRECTSOUND8 pDS); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Include/criware/criware_lock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Gemini 3 | * =========================================================== 4 | * Thread module 5 | * ----------------------------------------------------------- 6 | * Critical section manager for ADX. 7 | * =========================================================== 8 | */ 9 | #include "criware.h" 10 | #include 11 | 12 | #if 0 13 | static double GetTime() 14 | { 15 | return std::chrono::duration(std::chrono::high_resolution_clock::now().time_since_epoch()).count() * 1000.; 16 | } 17 | #endif 18 | 19 | static CRITICAL_SECTION ADX_crit; 20 | 21 | void ADX_lock_init() 22 | { 23 | InitializeCriticalSection(&ADX_crit); 24 | } 25 | 26 | void ADX_lock_close() 27 | { 28 | DeleteCriticalSection(&ADX_crit); 29 | } 30 | 31 | void ADX_lock() 32 | { 33 | #if 0 34 | double start = GetTime(); 35 | 36 | while (!TryEnterCriticalSection(&ADX_crit)) 37 | { 38 | // deadlock prevention 39 | double cur = GetTime() - start; 40 | if (cur > 3000.) // 3 second threshold to acquire the critical section 41 | { 42 | ADXD_Log("Preventing deadlock %3f ms\n", cur); 43 | break; 44 | } 45 | } 46 | #else 47 | EnterCriticalSection(&ADX_crit); 48 | #endif 49 | } 50 | 51 | void ADX_unlock() 52 | { 53 | LeaveCriticalSection(&ADX_crit); 54 | } 55 | -------------------------------------------------------------------------------- /Include/criware/criware_lock.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------- 2 | // thread module 3 | #pragma once 4 | 5 | void ADX_lock_init(); 6 | void ADX_lock_close(); 7 | void ADX_lock(); 8 | void ADX_unlock(); 9 | -------------------------------------------------------------------------------- /Include/criware/criware_sound.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Gemini 3 | * =============================================================== 4 | * Generic sound interface 5 | * --------------------------------------------------------------- 6 | * A generic sound interface that can be expanded to support any 7 | * API. 8 | * =============================================================== 9 | */ 10 | #include "criware.h" 11 | 12 | SndObjBase* sound_obj_tbl[SOUND_MAX_OBJ]; 13 | 14 | SndObjBase* adxs_FindObj() 15 | { 16 | for (int i = 0; i < SOUND_MAX_OBJ; i++) 17 | if (sound_obj_tbl[i]->used == 0) 18 | return sound_obj_tbl[i]; 19 | 20 | ADXD_Log(__FUNCTION__ ": couldn't find any unused sound objects.\n"); 21 | 22 | return nullptr; 23 | } 24 | 25 | void adxs_Clear(SndObjBase* obj) 26 | { 27 | obj->Release(); 28 | } 29 | 30 | void adxs_Release() 31 | { 32 | for (int i = 0; i < SOUND_MAX_OBJ; i++) 33 | { 34 | if (sound_obj_tbl[i]) 35 | { 36 | delete sound_obj_tbl[i]; 37 | sound_obj_tbl[i] = nullptr; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Include/criware/criware_sound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "criware_adx.h" 3 | 4 | enum DSOBJ_STATE 5 | { 6 | DSOS_UNUSED, 7 | DSOS_PLAYING, 8 | DSOS_LOOPING, 9 | DSOS_ENDED 10 | }; 11 | 12 | #define SOUND_MAX_OBJ 32 13 | 14 | typedef void (*SndCbPlayEnd)(LPVOID); 15 | 16 | class SndObjBase 17 | { 18 | public: 19 | SndObjBase() 20 | { 21 | Release(); 22 | } 23 | virtual ~SndObjBase() 24 | { 25 | Release(); 26 | } 27 | 28 | virtual void CreateBuffer(CriFileStream* stream) 29 | { 30 | UNREFERENCED_PARAMETER(stream); 31 | } 32 | 33 | virtual void Release() 34 | { 35 | offset = 0; 36 | offset_played = 0; 37 | used = 0; 38 | loops = 0; 39 | stopped = 0; 40 | volume = 0; 41 | memset(&fmt, 0, sizeof(fmt)); 42 | str = nullptr; 43 | adx = nullptr; 44 | } 45 | 46 | virtual void Play() {} 47 | virtual void Stop() {} 48 | virtual void Update() {} 49 | 50 | virtual void SendData() {} 51 | virtual void SetVolume(int vol) 52 | { 53 | UNREFERENCED_PARAMETER(vol); 54 | } 55 | 56 | u_long offset, 57 | offset_played; 58 | u_long used : 1, 59 | loops : 1, 60 | stopped : 1; 61 | int volume; 62 | WAVEFORMATEX fmt; 63 | CriFileStream* str; 64 | ADXT_Object* adx; 65 | }; 66 | 67 | SndObjBase* adxs_FindObj(); 68 | void adxs_Clear(SndObjBase* obj); 69 | void adxs_Release(); 70 | -------------------------------------------------------------------------------- /Include/criware/criware_xaudio2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if XAUDIO2 3 | 4 | #define XAUDIO2_BUFFER_SIZE 32768 5 | #define XAUDIO2_BUFFER_HALF (XAUDIO2_BUFFER_SIZE / 2) 6 | 7 | class SndObjXAudio : public SndObjBase 8 | { 9 | public: 10 | SndObjXAudio() 11 | { 12 | pVoice = nullptr; 13 | flip = 0; 14 | memset(&info, 0, sizeof(info)); 15 | 16 | Release(); 17 | } 18 | virtual ~SndObjXAudio() 19 | { 20 | Release(); 21 | } 22 | 23 | virtual void CreateBuffer(CriFileStream* stream); 24 | 25 | virtual void Release(); 26 | 27 | virtual void Play(); 28 | virtual void Stop(); 29 | virtual void Update(); 30 | 31 | virtual void SendData(); 32 | virtual void SetVolume(int vol); 33 | 34 | private: 35 | IXAudio2SourceVoice *pVoice; 36 | BYTE buffer[XAUDIO2_BUFFER_SIZE]; 37 | XAUDIO2_BUFFER info; 38 | int flip; 39 | 40 | // simple callback override for signaling 41 | class XAudio2Callback : public IXAudio2VoiceCallback 42 | { 43 | public: 44 | XAudio2Callback() : 45 | hEndEvent(CreateEventA(nullptr, FALSE, FALSE, nullptr)) 46 | {} 47 | ~XAudio2Callback() { CloseHandle(hEndEvent); } 48 | 49 | virtual void _stdcall OnStreamEnd() {} 50 | virtual void _stdcall OnVoiceProcessingPassEnd() {} 51 | virtual void _stdcall OnVoiceProcessingPassStart(UINT32 SamplesRequired) {} 52 | virtual void _stdcall OnBufferEnd(void* pBufferContext) { SetEvent(hEndEvent); } // signal that we need more data 53 | virtual void _stdcall OnBufferStart(void* pBufferContext) {} 54 | virtual void _stdcall OnLoopEnd(void* pBufferContext) {} 55 | virtual void _stdcall OnVoiceError(void* pBufferContext, HRESULT Error) {} 56 | 57 | HANDLE hEndEvent; 58 | }; 59 | 60 | XAudio2Callback cb; 61 | }; 62 | 63 | void adxs_SetupXAudio(void* pXA); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /Include/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /Include/winmm.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "winmm.h" 18 | #include "Logging\Logging.h" 19 | 20 | typedef MMRESULT(WINAPI *PFN_timeBeginPeriod)(UINT uPeriod); 21 | typedef MMRESULT(WINAPI *PFN_timeEndPeriod)(UINT uPeriod); 22 | PFN_timeBeginPeriod timeBeginPeriodPtr = nullptr; 23 | PFN_timeEndPeriod timeEndPeriodPtr = nullptr; 24 | HMODULE winmmModule = nullptr; 25 | 26 | void Loadwinmm() 27 | { 28 | static bool IsLoaded = false; 29 | if (IsLoaded) 30 | { 31 | return; // Only load the dll once 32 | } 33 | IsLoaded = true; 34 | winmmModule = LoadLibraryA("winmm.dll"); 35 | if (winmmModule) 36 | { 37 | timeBeginPeriodPtr = reinterpret_cast(GetProcAddress(winmmModule, "timeBeginPeriod")); 38 | timeEndPeriodPtr = reinterpret_cast(GetProcAddress(winmmModule, "timeEndPeriod")); 39 | if (!timeBeginPeriodPtr) Logging::Log() << "Failed to get 'timeBeginPeriod' ProcAddress of winmm.dll!"; 40 | if (!timeEndPeriodPtr) Logging::Log() << "Failed to get 'timeEndPeriod' ProcAddress of winmm.dll!"; 41 | } 42 | else 43 | { 44 | Logging::Log() << "Failed to load winmm.dll!"; 45 | } 46 | } 47 | 48 | MMRESULT timeBeginPeriod(UINT uPeriod) 49 | { 50 | // Load module 51 | Loadwinmm(); 52 | 53 | // Call function 54 | if (timeBeginPeriodPtr) 55 | { 56 | return timeBeginPeriodPtr(uPeriod); 57 | } 58 | return S_FALSE; 59 | } 60 | 61 | MMRESULT timeEndPeriod(UINT uPeriod) 62 | { 63 | // Load module 64 | Loadwinmm(); 65 | 66 | // Call function 67 | if (timeEndPeriodPtr) 68 | { 69 | return timeEndPeriodPtr(uPeriod); 70 | } 71 | return S_FALSE; 72 | } 73 | -------------------------------------------------------------------------------- /Include/winmm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | 6 | #ifndef _TIMERAPI_H_ 7 | #define _TIMERAPI_H_ 8 | #endif 9 | 10 | typedef _Return_type_success_(return == 0) UINT MMRESULT; /* error return code, 0 means no error */ 11 | 12 | MMRESULT timeBeginPeriod(UINT); 13 | MMRESULT timeEndPeriod(UINT); 14 | -------------------------------------------------------------------------------- /Launcher/BuildNo.rc: -------------------------------------------------------------------------------- 1 | #define BUILD_NUMBER 2110 2 | -------------------------------------------------------------------------------- /Launcher/LICENSE: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2022 Gemini 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | * 16 | * Code taken from: https://github.com/Gemini-Loboto3/SH2config 17 | */ -------------------------------------------------------------------------------- /Launcher/Launcher.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Launcher/Launcher.ico -------------------------------------------------------------------------------- /Launcher/Launcher.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Launcher/Launcher.rc -------------------------------------------------------------------------------- /Launcher/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BuildNo.rc" 4 | 5 | #define IDC_MYICON 2 6 | #define IDD_CONFIG_DIALOG 102 7 | #define IDM_ABOUT 104 8 | #define IDI_CONFIG 107 9 | #define IDI_SMALL 108 10 | #define IDR_MAINFRAME 128 11 | #define IDC_COMBO1 1000 12 | #define IDC_STATIC -1 13 | 14 | // Included resource files (do NOT change these number associations, used in reg keys) 15 | #define IDR_CONFIG_XML_EN 901 16 | #define IDR_CONFIG_XML_ES 902 17 | #define IDR_CONFIG_XML_IT 903 18 | #define IDR_CONFIG_XML_BR 904 19 | 20 | // Main resource file details 21 | #define APP_NAME "SH2EE Configuration Tool" 22 | #define APP_MAJOR 3 23 | #define APP_MINOR 0 24 | #define APP_BUILDNUMBER BUILD_NUMBER 25 | #define APP_REVISION 0 26 | #define APP_COMPANYNAME "Sadrate Presents" 27 | #define APP_DESCRPTION "SH2EE Configuration Tool" 28 | #define APP_COPYRIGHT "Gemini (C) 2022" 29 | #define APP_ORIGINALVERSION "SH2EEconfig.exe" 30 | #define APP_INTERNALNAME "Launcher" 31 | 32 | // Get APP_VERSION 33 | #define _TO_STRING_(x) #x 34 | #define _TO_STRING(x) _TO_STRING_(x) 35 | #define APP_VERSION _TO_STRING(APP_MAJOR) "." _TO_STRING(APP_MINOR) "." _TO_STRING(APP_BUILDNUMBER) "." _TO_STRING(APP_REVISION) 36 | #define VERSION_NUMBER APP_MAJOR, APP_MINOR, APP_BUILDNUMBER, APP_REVISION 37 | -------------------------------------------------------------------------------- /Launcher/UALx86.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Launcher/UALx86.rc -------------------------------------------------------------------------------- /Launcher/manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | SH2EE Configuration Tool 10 | 11 | 12 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Logging/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Logging/Logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include "External\Logging\Logging.h" 6 | 7 | typedef enum _D3DERR { } D3DERR; 8 | typedef enum _DIERR { } DIERR; 9 | typedef enum _DSERR { } DSERR; 10 | 11 | std::ostream& operator<<(std::ostream& os, const D3DERR& ErrCode); 12 | std::ostream& operator<<(std::ostream& os, const DIERR& ErrCode); 13 | std::ostream& operator<<(std::ostream& os, const DSERR& ErrCode); 14 | #ifdef GUID_DEFINED 15 | std::ostream& operator<<(std::ostream& os, REFIID riid); 16 | #endif 17 | std::ostream& operator<<(std::ostream& os, const POINT& p); 18 | std::ostream& operator<<(std::ostream& os, const RECT& rect); 19 | -------------------------------------------------------------------------------- /Patches/ChangeClosetSpawn.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | void PatchClosetSpawn() 24 | { 25 | // Get James load position Apt307 address 26 | constexpr BYTE SearchBytes[]{ 0x6A, 0x01, 0x6A, 0x07, 0x68, 0x01, 0x02, 0x00, 0x00, 0xE8 }; 27 | float *Apt307JamesLoadPosZ = (float*)SearchAndGetAddresses(0x00599226, 0x00599AD6, 0x005993F6, SearchBytes, sizeof(SearchBytes), 0x24, __FUNCTION__); 28 | float *Apt307JamesLoadRotX = (float*)((DWORD)Apt307JamesLoadPosZ + 0x11); 29 | 30 | // Checking address pointer 31 | if (!Apt307JamesLoadPosZ) 32 | { 33 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 34 | return; 35 | } 36 | 37 | // Update SH2 code 38 | Logging::Log() << "Updating James' spawn point position..."; 39 | float Value = -101525.0f; 40 | UpdateMemoryAddress((BYTE*)Apt307JamesLoadPosZ, &Value, sizeof(float)); 41 | Value = 0.3f; 42 | UpdateMemoryAddress((BYTE*)Apt307JamesLoadRotX, &Value, sizeof(float)); 43 | } 44 | 45 | void RunClosetSpawn() 46 | { 47 | // Load Camera FOV address 48 | GetCameraFOV(); 49 | 50 | // Checking address pointer 51 | if (!CameraFOVAddr) 52 | { 53 | RUNONCE(); 54 | 55 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 56 | return; 57 | } 58 | 59 | static DWORD LastCutscene = 0; 60 | DWORD CutsceneID = GetCutsceneID(); 61 | if (LastCutscene == CS_APT_RPT_CLOSET && CutsceneID != CS_APT_RPT_CLOSET) 62 | { 63 | *CameraFOVAddr = 448.0f; 64 | } 65 | LastCutscene = CutsceneID; 66 | } 67 | -------------------------------------------------------------------------------- /Patches/CreatureVehicleSpawn.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | void PatchCreatureVehicleSpawn() 23 | { 24 | // Get Lying Figures address 25 | constexpr BYTE SearchBytes[]{ 0x89, 0x4E, 0x10, 0xC6, 0x46, 0x06, 0x00, 0x88, 0x46, 0x03, 0xD9, 0x86, 0x90, 0x00, 0x00, 0x00, 0xD8, 0x1D }; 26 | DWORD CreatureAddr = SearchAndGetAddresses(0x004C5C42, 0x004C5EF2, 0x004C57B2, SearchBytes, sizeof(SearchBytes), 0x00, __FUNCTION__); 27 | if (!CreatureAddr) 28 | { 29 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 30 | return; 31 | } 32 | 33 | // Update SH2 code 34 | Logging::Log() << "Fixing behavior of Lying Figures that are hiding under vehicles..."; 35 | UpdateMemoryAddress((void*)CreatureAddr, "\x90\x90\x90", 3); 36 | } 37 | -------------------------------------------------------------------------------- /Patches/DelayedStart.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | void DelayedStart(); 23 | 24 | // Variables for ASM 25 | void* EntryPointExceptionFunction = nullptr; 26 | 27 | // ASM function to start functions delayed 28 | __declspec(naked) void __stdcall DelayedStartASM() 29 | { 30 | __asm 31 | { 32 | call DelayedStart 33 | jmp EntryPointExceptionFunction 34 | } 35 | } 36 | 37 | // Set hook at beginning of Silent Hill 2 code to do startup functions delayed 38 | bool SetDelayedStart() 39 | { 40 | // Get memory pointer 41 | constexpr BYTE SearchBytes[]{ 0xFF, 0xD7, 0x66, 0x81, 0x38, 0x4D, 0x5A, 0x75, 0x1F, 0x8B, 0x48, 0x3C, 0x03, 0xC8, 0x81, 0x39 }; 42 | DWORD Address = SearchAndGetAddresses(0x0056FDEB, 0x0056EBBB, 0x0056E4DB, SearchBytes, sizeof(SearchBytes), -0xE, __FUNCTION__); 43 | 44 | // Checking address pointer 45 | if (!Address || *(BYTE*)Address != 0xE8) 46 | { 47 | Logging::Log() << "Error: failed to set delayed startup..."; 48 | return false; 49 | } 50 | EntryPointExceptionFunction = (void*)(Address + 5 + *(DWORD*)(Address + 1)); 51 | 52 | // Update SH2 code 53 | Logging::Log() << "Setting delayed startup..."; 54 | WriteCalltoMemory((BYTE*)Address, *DelayedStartASM, 5); 55 | 56 | // Return 57 | return true; 58 | } 59 | -------------------------------------------------------------------------------- /Patches/DisableShadowCutscene.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | void RunShadowCutscene() 24 | { 25 | // Get shadow address 26 | static BYTE *Address = nullptr; 27 | if (!Address) 28 | { 29 | RUNONCE(); 30 | 31 | // Get address for shadows 32 | constexpr BYTE SearchBytes[]{ 0x00, 0x33, 0xC9, 0x3B, 0xD3, 0x0F, 0x94, 0xC1, 0xA3 }; 33 | Address = (BYTE*)ReadSearchedAddresses(0x00462DD5, 0x00463045, 0x00463045, SearchBytes, sizeof(SearchBytes), -0xA0, __FUNCTION__); 34 | if (!Address) 35 | { 36 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 37 | return; 38 | } 39 | } 40 | 41 | // Set shadow 42 | static bool ValueSet = false; 43 | static BYTE LastValue = 0x01; 44 | if (GetCutsceneID() == CS_ANGELA_CEMETERY || GetCutsceneID() == CS_HSP_ALT_RADIO_QUIZ || GetCutsceneID() == CS_BOWL_MARIA || GetCutsceneID() == CS_HSP_ALT_LAURA_LEAVES || GetCutsceneID() == CS_END_MARIA_EPILOGUE || GetCutsceneID() == CS_END_REBIRTH_EPILOGUE || 45 | (GetCutsceneID() == CS_APT_RPT_CLOSET && GetCutscenePos() == -20133.99805f)) 46 | { 47 | if (!ValueSet) 48 | { 49 | // Store current shadow value 50 | UpdateMemoryAddress(&LastValue, Address, sizeof(BYTE)); 51 | 52 | // Disable shadows 53 | UpdateMemoryAddress(Address, "\x00", sizeof(BYTE)); 54 | ValueSet = true; 55 | } 56 | } 57 | else if (ValueSet) 58 | { 59 | // Restore shadow value 60 | UpdateMemoryAddress(Address, &LastValue, sizeof(BYTE)); 61 | ValueSet = false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Patches/ElevatorCursorColorFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Hotel Employee Elevator Cursor Color 24 | // 00 = Gray 25 | // 01 = Blue 26 | // 02 = Red 27 | // 04 = Green 28 | 29 | void* CursorColorPointerAddr = nullptr; 30 | void* jmpReturnCursorColorBugFix = nullptr; 31 | 32 | // ASM function to update cursor color 33 | __declspec(naked) void __stdcall CursorColorBugFixASM() 34 | { 35 | __asm 36 | { 37 | push ecx 38 | mov ecx, dword ptr ds : [CursorColorPointerAddr] 39 | mov eax, dword ptr ds : [ecx] 40 | and eax, 0xFF808080 41 | or eax, 0x00808080 42 | mov dword ptr ds : [ecx], eax 43 | pop ecx 44 | jmp jmpReturnCursorColorBugFix 45 | } 46 | } 47 | 48 | // Patch SH2 code to Fix Elevator Cursor Color 49 | void PatchElevatorCursorColor() 50 | { 51 | BYTE* ElevadorPushAddr = (BYTE*)( 52 | GameVersion == SH2V_10 ? 0x0057A671 : 53 | GameVersion == SH2V_11 ? 0x0057AF21 : 54 | GameVersion == SH2V_DC ? 0x0057A841 : NULL); 55 | 56 | BYTE* CursorColorASMAddr = (BYTE*)( 57 | GameVersion == SH2V_10 ? 0x004A2E29 : 58 | GameVersion == SH2V_11 ? 0x004A30D9 : 59 | GameVersion == SH2V_DC ? 0x004A2999 : NULL); 60 | 61 | // Check variable addresses 62 | if (!ElevadorPushAddr || !CursorColorASMAddr || 63 | *(DWORD*)ElevadorPushAddr != 0xE856F633 || *(DWORD*)CursorColorASMAddr != 0x00A7850F) 64 | { 65 | Logging::Log() << __FUNCTION__ << " Error: memory addresses don't match!"; 66 | return; 67 | } 68 | jmpReturnCursorColorBugFix = CursorColorASMAddr + 0xAD; 69 | CursorColorPointerAddr = (BYTE*)*(DWORD*)(CursorColorASMAddr + 0x08); 70 | 71 | UpdateMemoryAddress(ElevadorPushAddr, "\x6A\x04\x90", 3); // Push 4 NOP 72 | WriteJMPtoMemory(CursorColorASMAddr + 1, CursorColorBugFixASM); 73 | UpdateMemoryAddress(CursorColorASMAddr, "\x0F\x85", 2); // JNE (jump not equal) 74 | } 75 | -------------------------------------------------------------------------------- /Patches/FMVPatches.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 mercury501 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Logging\Logging.h" 21 | #include "Common\Utils.h" 22 | 23 | void PatchFMVFramerate() 24 | { 25 | Logging::Log() << "Patching FMV speed..."; 26 | 27 | uint8_t* FMVFixAddr = GetSixtyFPSFMVFixPointer(); 28 | 29 | UpdateMemoryAddress(FMVFixAddr, "\x90\x90\x90\x90\x90", 5); 30 | } 31 | -------------------------------------------------------------------------------- /Patches/FinalBossRoomFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 mercury501, Polymega 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "Logging\Logging.h" 18 | #include "Patches.h" 19 | #include "Common\Utils.h" 20 | 21 | float* FinalBossDrawDistanceAddr = nullptr; 22 | 23 | const float FinalBossFixValue = -30000.f; 24 | const float FinalBossOriginalWalkway = -8000.f; 25 | const float FinalBossOriginalFloor = -4000.f; 26 | const float FinalBossOriginalBoxSpawn = -12000.f; 27 | 28 | void RunFinalBossRoomFix() 29 | { 30 | if (GetJamesPosY() < -14600.f && GetRoomID() == R_FINAL_BOSS_RM) 31 | { 32 | UpdateMemoryAddress(GetFinalBossBottomWalkwaySpawnPointer(), &FinalBossFixValue, sizeof(float)); 33 | UpdateMemoryAddress(GetFinalBossBottomFloorSpawnPointer(), &FinalBossFixValue, sizeof(float)); 34 | UpdateMemoryAddress(GetFinalBossBlackBoxSpawnPointer(), &FinalBossFixValue, sizeof(float)); 35 | } 36 | else 37 | { 38 | UpdateMemoryAddress(GetFinalBossBottomWalkwaySpawnPointer(), &FinalBossOriginalWalkway, sizeof(float)); 39 | UpdateMemoryAddress(GetFinalBossBottomFloorSpawnPointer(), &FinalBossOriginalFloor, sizeof(float)); 40 | UpdateMemoryAddress(GetFinalBossBlackBoxSpawnPointer(), &FinalBossOriginalBoxSpawn, sizeof(float)); 41 | } 42 | } 43 | 44 | float* GetFinalBossDrawDistancePointer() 45 | { 46 | if (FinalBossDrawDistanceAddr) 47 | { 48 | return FinalBossDrawDistanceAddr; 49 | } 50 | 51 | // Address is retrieved like so because it's only reference is a float** not byte aligned 52 | float* DrawDistancePtr = GameVersion == SH2V_10 ? (float*) 0x00800614 : 53 | GameVersion == SH2V_11 ? (float*)0x008041FC : 54 | GameVersion == SH2V_DC ? (float*)0x008031FC : nullptr; 55 | 56 | // Checking address pointer 57 | if (!DrawDistancePtr) 58 | { 59 | Logging::Log() << __FUNCTION__ << " Error: failed to find FinalBossDrawDistance address!"; 60 | return nullptr; 61 | } 62 | 63 | FinalBossDrawDistanceAddr = DrawDistancePtr; 64 | 65 | return FinalBossDrawDistanceAddr; 66 | } 67 | 68 | void PatchFinalBossRoom() 69 | { 70 | Logging::Log() << "Patching final boss black box..."; 71 | 72 | *GetFinalBossDrawDistancePointer() = 30000.f; 73 | } -------------------------------------------------------------------------------- /Patches/FireEscapeKey.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | void PatchFireEscapeKey() 24 | { 25 | // Get Fire Escape Key pointer 26 | constexpr BYTE SearchBytes[]{ 0xC3, 0xB8 }; 27 | DWORD* FireEscapeKeyPtr = (DWORD*)ReadSearchedAddresses(0x00494F00, 0x004951A0, 0x004953B0, SearchBytes, sizeof(SearchBytes), 0x2, __FUNCTION__); 28 | if (!FireEscapeKeyPtr) 29 | { 30 | Logging::Log() << __FUNCTION__ << " Error: failed to find pointer address!"; 31 | return; 32 | } 33 | 34 | // Get Fire Escape Key address 35 | DWORD FireEscapeKeyAddr = 0; 36 | if (!ReadMemoryAddress(FireEscapeKeyPtr, &FireEscapeKeyAddr, sizeof(DWORD)) || !FireEscapeKeyAddr) 37 | { 38 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 39 | return; 40 | } 41 | 42 | // Get Pickup Fire Escape Key address 43 | DWORD PickupKeyAddr = FireEscapeKeyAddr + 0x64; 44 | 45 | // Get Examine Fire Escape Key (Behind Bars) address 46 | DWORD ExamineKeyAddr = PickupKeyAddr + 0x7D8; 47 | 48 | // Update SH2 code 49 | Logging::Log() << "Enabling Fire Escape Key Fix..."; 50 | UpdateMemoryAddress((void*)PickupKeyAddr, "\x00", sizeof(BYTE)); 51 | UpdateMemoryAddress((void*)ExamineKeyAddr, "\x00", sizeof(BYTE)); 52 | } 53 | -------------------------------------------------------------------------------- /Patches/FlashlightClockPush.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Variables for ASM 24 | DWORD FlashlightClockValue; 25 | void *jmpFlashlightClock; 26 | 27 | // ASM functions to fix an issue with lighting in a certain room 28 | __declspec(naked) void __stdcall FlashlightClockASM() 29 | { 30 | __asm 31 | { 32 | and edx, FlashlightClockValue 33 | jmp jmpFlashlightClock 34 | } 35 | } 36 | 37 | void PatchFlashlightClockPush() 38 | { 39 | // Get address 40 | constexpr BYTE SearchBytes[]{ 0xD8, 0xD9, 0xDF, 0xE0, 0xF6, 0xC4, 0x41, 0x75, 0x0A, 0xDD, 0xD8, 0x89, 0x3D }; 41 | void *Address = (void*)SearchAndGetAddresses(0x0048E81B, 0x0048EABB, 0x0048ECCB, SearchBytes, sizeof(SearchBytes), 0x3D, __FUNCTION__); 42 | 43 | if (!Address) 44 | { 45 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 46 | return; 47 | } 48 | jmpFlashlightClock = (void*)((DWORD)Address + 0x06); 49 | FlashlightClockValue = 0xFFFFFF3F; 50 | 51 | // Update SH2 code 52 | Logging::Log() << "Fixing Flashlight Clock Push..."; 53 | WriteJMPtoMemory((BYTE*)Address, *FlashlightClockASM, 6); 54 | } 55 | 56 | void RunFlashlightClockPush() 57 | { 58 | if (GetRoomID() == R_APT_E_RM_208 && GetInGameCameraPosY() == -112.6049728f) 59 | { 60 | constexpr DWORD NewValue = 0xFFFFFFEF; 61 | if (FlashlightClockValue != NewValue) 62 | { 63 | FlashlightClockValue = NewValue; 64 | } 65 | } 66 | else 67 | { 68 | constexpr DWORD NewValue = 0xFFFFFF3F; 69 | if (FlashlightClockValue != NewValue) 70 | { 71 | FlashlightClockValue = NewValue; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Patches/FlashlightFlicker.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | void PatchFlashlightFlicker() 24 | { 25 | // Get address 26 | constexpr BYTE SearchBytes[]{ 0x00, 0x00, 0x00, 0x00, 0x74, 0x0F, 0xE8 }; 27 | void *Address = (void*)SearchAndGetAddresses(0x0040170D, 0x0040170D, 0x0040170D, SearchBytes, sizeof(SearchBytes), 0x15, __FUNCTION__); 28 | 29 | // Checking address pointer 30 | if (!Address) 31 | { 32 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 33 | return; 34 | } 35 | 36 | // Update SH2 code 37 | Logging::Log() << "Fixing Flashlight Flicker..."; 38 | UpdateMemoryAddress(Address, "\x90\x90\x90\x90\x90", 5); 39 | } 40 | -------------------------------------------------------------------------------- /Patches/HoldDamage.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2022 Murugo 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | namespace 24 | { 25 | // Variables for ASM 26 | DWORD* DeltaTimeFuncAddr = 0; 27 | float DamageScale = 30.0f; 28 | } 29 | 30 | // ASM which scales enemy damage by delta time while the player is in a hold attack. 31 | __declspec(naked) void __stdcall ScaleHoldDamageASM() 32 | { 33 | __asm 34 | { 35 | push eax 36 | mov eax, dword ptr ds : [DeltaTimeFuncAddr] 37 | call eax // Pushes delta time to st(0) 38 | fmul dword ptr ds : [DamageScale] 39 | fmul dword ptr ds : [esi + 0x11C] // Multiply by enemy damage 40 | fsubp st(1), st(0) 41 | pop eax 42 | ret 43 | } 44 | } 45 | 46 | // Patch how much damage an enemy hold attack will inflict every frame by scaling damage with the current frame rate. 47 | // Affects hold damage rate for Flesh Lips, Abstract Daddy, and the final boss (tentacle choke and moth attack). 48 | void PatchHoldDamage() 49 | { 50 | constexpr BYTE SearchBytesApplyHoldDamage[]{ 0xD9, 0x86, 0x3C, 0x01, 0x00, 0x00, 0x8B, 0x96, 0x1C, 0x01, 0x00, 0x00 }; 51 | DWORD ApplyHoldDamageAddr = SearchAndGetAddresses(0x005359D5, 0x00535D05, 0x00535625, SearchBytesApplyHoldDamage, sizeof(SearchBytesApplyHoldDamage), 0x0C, __FUNCTION__); 52 | if (!ApplyHoldDamageAddr) 53 | { 54 | Logging::Log() << __FUNCTION__ << "Error: failed to find memory address!"; 55 | return; 56 | } 57 | 58 | DeltaTimeFuncAddr = GetDeltaTimeFunctionPointer(); 59 | if (!DeltaTimeFuncAddr) 60 | { 61 | return; 62 | } 63 | 64 | Logging::Log() << "Enabling Enemy Hold Damage Fix..."; 65 | WriteCalltoMemory((BYTE*)ApplyHoldDamageAddr, *ScaleHoldDamageASM, 0x06); 66 | } 67 | -------------------------------------------------------------------------------- /Patches/HospitalChase.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Run SH2 code to Fix RPT Hospital Elevator Stabbing Animation 24 | void RunHospitalChase() 25 | { 26 | static DWORD Address = NULL; 27 | if (!Address) 28 | { 29 | RUNONCE(); 30 | 31 | // Get address 32 | constexpr BYTE SearchBytes[]{ 0x8B, 0xC2, 0x83, 0xC4, 0x18, 0xC3, 0x90, 0x90, 0x8B, 0x44, 0x24, 0x04, 0x83, 0xF8, 0x04, 0x0F, 0x87, 0x0D, 0x01, 0x00, 0x00, 0x53, 0xFF, 0x24, 0x85 }; 33 | Address = ReadSearchedAddresses(0x004A8BD8, 0x004A8E88, 0x004A8748, SearchBytes, sizeof(SearchBytes), 0x1E, __FUNCTION__); 34 | if (!Address) 35 | { 36 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 37 | return; 38 | } 39 | } 40 | 41 | RUNCODEONCE(Logging::Log() << "Setting RPT Hospital Elevator Animation Fix..."); 42 | 43 | // Fix Animation 44 | static bool ValueSet = false; 45 | if (GetRoomID() == R_HSP_ALT_RPT_HALLWAY) 46 | { 47 | 48 | if (!ValueSet && GetJamesPosX() > 33185.0f) 49 | { 50 | BYTE Value = 5; 51 | UpdateMemoryAddress((void*)Address, &Value, sizeof(BYTE)); 52 | 53 | ValueSet = true; 54 | } 55 | } 56 | else if (ValueSet) 57 | { 58 | ValueSet = false; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Patches/LeaveEndingDrawDistance.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 mercury501 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "Common\Utils.h" 18 | #include "Patches\Patches.h" 19 | #include "Logging\Logging.h" 20 | 21 | void PatchLeaveEndingCemeteryDrawDistance() 22 | { 23 | DWORD CemeteryDrawDistance = GameVersion == SH2V_10 ? 0x008E7878 : 24 | GameVersion == SH2V_11 ? 0x008EB548 : 25 | GameVersion == SH2V_DC ? 0x008EA548 : 26 | NULL; 27 | 28 | if (CemeteryDrawDistance == NULL) 29 | { 30 | Logging::Log() << __FUNCTION__ << " Couldn't parse game version."; 31 | return; 32 | } 33 | 34 | float DrawDistanceValue = 40000.0f; 35 | 36 | UpdateMemoryAddress((BYTE*)CemeteryDrawDistance, &DrawDistanceValue, sizeof(float)); 37 | 38 | Logging::Log() << __FUNCTION__ << " Patched L. ending draw distance!"; 39 | } -------------------------------------------------------------------------------- /Patches/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Patches/LowHealthIndicator.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include 20 | #include "Patches.h" 21 | #include "Common\Utils.h" 22 | #include "Common\FileSystemHooks.h" 23 | #include "Common\Settings.h" 24 | #include "Logging\Logging.h" 25 | #include "Common\Unicode.h" 26 | 27 | // Default values 28 | float LowHealthXPos = 0.85f; 29 | float LowHealthYPos = 0.95f; 30 | float LowHealthHeight = 0.1f; 31 | 32 | void PatchLowHealthIndicator() 33 | { 34 | // Check if LowHealthFade.png exists 35 | std::vector Paths = { GetLangPath(""), GetModPath(""), "data" }; 36 | if (!std::any_of(Paths.begin(), Paths.end(), [](auto& entry) { return PathFileExists((std::string(entry) + "\\pic\\etc\\LowHealthFade.png").c_str()); })) 37 | { 38 | Logging::Log() << "Warning: 'LowHealthFade.png' not found!"; 39 | LowHealthIndicatorStyle = 1; 40 | return; 41 | } 42 | 43 | // Set variables for new fullscreen style 44 | LowHealthXPos = 0.0f; 45 | LowHealthYPos = 1.001f; 46 | LowHealthHeight = 0.25f; 47 | 48 | DWORD BaseMemoryAddress = 49 | GameVersion == SH2V_10 ? 0x004F684C : 50 | GameVersion == SH2V_11 ? 0x004F6AFC : 51 | GameVersion == SH2V_DC ? 0x004F63BC : NULL; 52 | 53 | // Checking address pointer 54 | if (!BaseMemoryAddress || *(BYTE*)BaseMemoryAddress != 0xD8 || *(BYTE*)((DWORD)BaseMemoryAddress + 1) != 0x0D) 55 | { 56 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 57 | return; 58 | } 59 | 60 | // Update SH2 code 61 | Logging::Log() << "Updating Low Health Indicator..."; 62 | float* Value = &LowHealthXPos; 63 | UpdateMemoryAddress((BYTE*)(BaseMemoryAddress + 2), &Value, sizeof(float)); 64 | Value = &LowHealthYPos; 65 | UpdateMemoryAddress((BYTE*)(BaseMemoryAddress + 12), &Value, sizeof(float)); 66 | UpdateMemoryAddress((BYTE*)(BaseMemoryAddress + 24), &Value, sizeof(float)); 67 | Value = &LowHealthHeight; 68 | UpdateMemoryAddress((BYTE*)(BaseMemoryAddress + 44), &Value, sizeof(float)); 69 | } 70 | -------------------------------------------------------------------------------- /Patches/MemoFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | // Variables for ASM 23 | void *MemoBottomBrightnessAddr = nullptr; 24 | void *MemoTopBrightnessAddr = nullptr; 25 | 26 | // ASM functions to fix memo brightness 27 | __declspec(naked) void __stdcall MemoBrightnessASM() 28 | { 29 | __asm 30 | { 31 | push ecx 32 | mov ecx, dword ptr ds : [MemoBottomBrightnessAddr] 33 | mov dword ptr ds : [ecx], eax // Writes RGB for Bottom Layer 34 | mov ecx, dword ptr ds : [MemoTopBrightnessAddr] 35 | mov dword ptr ds : [ecx], eax // Writes RGB for Top Layer 36 | pop ecx 37 | retn 38 | } 39 | } 40 | 41 | // Patch SH2 code to fix memo brightness 42 | void PatchMemoBrightnes() 43 | { 44 | // Get memo brightness address 45 | constexpr BYTE MemoBrightnessSearchBytes[]{ 0x8B, 0xC6, 0xC1, 0xE0, 0x08, 0x0B, 0xC6, 0xC1, 0xE0, 0x08, 0x81, 0xE1, 0x00, 0x00, 0x00, 0xFF, 0x0B, 0xC1, 0x0B, 0xC6, 0x68 }; 46 | DWORD MemoBrightnessAddr = SearchAndGetAddresses(0x0049914D, 0x004993FD, 0x00498CBD, MemoBrightnessSearchBytes, sizeof(MemoBrightnessSearchBytes), 0x22, __FUNCTION__); 47 | 48 | // Checking address pointer 49 | if (!MemoBrightnessAddr) 50 | { 51 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 52 | return; 53 | } 54 | 55 | MemoBottomBrightnessAddr = (void*)*(DWORD*)(MemoBrightnessAddr + 1); 56 | MemoTopBrightnessAddr = (void*)((DWORD)MemoBottomBrightnessAddr + 0x80); 57 | 58 | Logging::Log() << "Fixing memo brightness..."; 59 | WriteCalltoMemory((BYTE*)MemoBrightnessAddr, *MemoBrightnessASM); 60 | } 61 | -------------------------------------------------------------------------------- /Patches/MothDrawOrder.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Murugo 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | // Variables for ASM 23 | DWORD DrawDistanceFactorAddr = 0; // (Size of depth sort list - 1) / (DrawDistance + 1000.0) 24 | 25 | __declspec(naked) void __stdcall FixMothSortIndexASM() 26 | { 27 | __asm 28 | { 29 | push eax 30 | mov eax, dword ptr ds : [DrawDistanceFactorAddr] 31 | // ST[0] = distance of the moth object from the camera. 32 | // Get the correct insertion index for depth sorting. 33 | fmul dword ptr ds : [eax] 34 | pop eax 35 | mov dword ptr ds : [esp + 0x68], 0x3F800000 36 | ret 37 | } 38 | } 39 | 40 | // Patch draw order of moths to render correctly with other transparent geometry in the scene. 41 | void PatchMothDrawOrder() 42 | { 43 | constexpr BYTE DrawDistanceFactorSearchBytes[]{ 0x85, 0xC0, 0xB9, 0x2C, 0x00, 0x00, 0x00, 0x74, 0x1B }; 44 | DrawDistanceFactorAddr = ReadSearchedAddresses(0x00476AC5, 0x00476D65, 0x00476F75, DrawDistanceFactorSearchBytes, sizeof(DrawDistanceFactorSearchBytes), 0x0A, __FUNCTION__); 45 | if (!DrawDistanceFactorAddr) 46 | { 47 | Logging::Log() << __FUNCTION__ << " Error: failed to find pointer address!"; 48 | return; 49 | } 50 | DrawDistanceFactorAddr += 0x08; 51 | 52 | constexpr BYTE FixMothSortIndexSearchBytes[]{ 0xF3, 0xA5, 0xC6, 0x85, 0xA4, 0x00, 0x00, 0x00, 0x02 }; 53 | const DWORD FixMothSortIndexAddrA = SearchAndGetAddresses(0x004A4D9F, 0x004A504F, 0x004A490F, FixMothSortIndexSearchBytes, sizeof(FixMothSortIndexSearchBytes), 0x43, __FUNCTION__); 54 | if (!FixMothSortIndexAddrA) 55 | { 56 | Logging::Log() << __FUNCTION__ << " Error: failed to find pointer address!"; 57 | return; 58 | } 59 | const DWORD FixMothSortIndexAddrB = FixMothSortIndexAddrA + 0x262; 60 | 61 | Logging::Log() << "Patching moth object draw order..."; 62 | WriteCalltoMemory((BYTE*)FixMothSortIndexAddrA, *FixMothSortIndexASM, 0x08); 63 | WriteCalltoMemory((BYTE*)FixMothSortIndexAddrB, *FixMothSortIndexASM, 0x08); 64 | } 65 | -------------------------------------------------------------------------------- /Patches/NoCDPatch.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | void PatchCDCheck() 23 | { 24 | // Check for CD patch 25 | constexpr BYTE CDCheckAddredBlock[] = { 0xEC, 0x08, 0x04, 0x00, 0x00, 0xA1 }; 26 | void *CDCheckAddr = CheckMultiMemoryAddress((void*)0x00408761, (void*)0x004088C1, (void*)0x004088D1, (void*)CDCheckAddredBlock, sizeof(CDCheckAddredBlock), __FUNCTION__); 27 | if (CDCheckAddr && !CheckMemoryAddress((void*)((DWORD)CDCheckAddr - 1), "\x81", 0x01, __FUNCTION__, false)) 28 | { 29 | Logging::Log() << "CD patch already set!"; 30 | return; 31 | } 32 | 33 | // Address found 34 | constexpr BYTE CDBlockTest[] = { 0x33, 0x84, 0x24, 0x08, 0x04, 0x00, 0x00, 0x53 }; 35 | if (!CDCheckAddr || !CheckMemoryAddress((void*)((DWORD)CDCheckAddr + 10), (void*)CDBlockTest, sizeof(CDCheckAddr), __FUNCTION__)) 36 | { 37 | Logging::Log() << __FUNCTION__ << " Error: Could not find CD check function address in memory!"; 38 | return; 39 | } 40 | CDCheckAddr = (void*)((DWORD)CDCheckAddr - 1); 41 | 42 | // Update SH2 code 43 | Logging::Log() << "Bypassing CD check..."; 44 | UpdateMemoryAddress(CDCheckAddr, "\x33\xC0\x40\xC3", 4); 45 | } 46 | -------------------------------------------------------------------------------- /Patches/OldManCoinFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Murugo 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Game flag set after James throws the canned juice down the garbage chute. 24 | constexpr WORD kCannedJuiceGameFlag = 0x5F; 25 | 26 | // Prevents the Old Man Coin from appearing in the garbage chute outside Wood Side Apartments until 27 | // after James uses the canned juice in the second floor laundry room. 28 | void PatchOldManCoinFix() 29 | { 30 | constexpr BYTE SearchBytes[]{ 0x1F, 0x07, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00 }; 31 | DWORD OldManCoinPreFlagAddr = SearchAndGetAddresses(0x008DE900, 0x008E25D0, 0x008E15D0, SearchBytes, sizeof(SearchBytes), 0x06, __FUNCTION__); 32 | if (!OldManCoinPreFlagAddr) 33 | { 34 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 35 | return; 36 | } 37 | 38 | Logging::Log() << "Patching Old Man Coin Fix..."; 39 | UpdateMemoryAddress((void*)OldManCoinPreFlagAddr, &kCannedJuiceGameFlag, sizeof(WORD)); 40 | } 41 | -------------------------------------------------------------------------------- /Patches/PatchInventoryBGM.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 The Machine Ambassador, mercury501 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | void* jmp_return; 24 | void* jmp_to_loop; 25 | 26 | DWORD* muteSound; 27 | DWORD LastRoomID; 28 | bool SoundFixFlag; 29 | DWORD EventIndex; 30 | BYTE MenuEventIndex; 31 | 32 | // BGM Fading out instructions 33 | #pragma warning(suppress: 4740) 34 | __declspec(naked) void __stdcall FixInventoryBGMBugASM() 35 | { 36 | EventIndex = GetEventIndex(); 37 | MenuEventIndex = GetMenuEvent(); 38 | 39 | if (MenuEventIndex == MENU_IN_GAME || 40 | (MenuEventIndex == MENU_LOAD_SCR && EventIndex == EVENT_LOAD_SCR)) 41 | { 42 | if (EventIndex == EVENT_GAME_RESULT_11) 43 | { 44 | *muteSound = 0x0F; 45 | __asm 46 | { 47 | jmp jmp_return 48 | } 49 | } 50 | 51 | if (EventIndex == EVENT_IN_GAME || EventIndex == EVENT_MAP || EventIndex == EVENT_INVENTORY || EventIndex == EVENT_OPTIONS_FMV || 52 | EventIndex == EVENT_MEMO_LIST || EventIndex == EVENT_SAVE_SCREEN || EventIndex == EVENT_PAUSE_MENU || MenuEventIndex == MENU_LOAD_SCR) 53 | { 54 | SoundFixFlag = (LastRoomID != GetRoomID()); 55 | LastRoomID = GetRoomID(); 56 | 57 | if (SoundFixFlag || EventIndex == EVENT_IN_GAME) 58 | { 59 | __asm 60 | { 61 | jmp jmp_return 62 | } 63 | } 64 | } 65 | } 66 | __asm 67 | { 68 | jmp jmp_to_loop 69 | } 70 | } 71 | 72 | void PatchInventoryBGMBug() 73 | { 74 | constexpr BYTE BuggyBGMBytes[] = { 0x83, 0xF8, 0x04, 0x75, 0x0D, 0x68 }; 75 | const DWORD BuggyBGMAddr = SearchAndGetAddresses(0x005166E8, 0x00516A18, 0x00516338, BuggyBGMBytes, sizeof(BuggyBGMBytes), -0x1F, __FUNCTION__); 76 | 77 | // Check errors 78 | if (!BuggyBGMAddr) 79 | { 80 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 81 | return; 82 | } 83 | 84 | muteSound = (DWORD*)*(DWORD*)(BuggyBGMAddr - 0x04); 85 | jmp_return = reinterpret_cast(BuggyBGMAddr + 0x24); 86 | jmp_to_loop = reinterpret_cast(BuggyBGMAddr + 0x31); 87 | 88 | // Update SH2 code 89 | Logging::Log() << "Fixing Inventory BGM..."; 90 | WriteJMPtoMemory(reinterpret_cast(BuggyBGMAddr), *FixInventoryBGMBugASM, 0x24); 91 | } -------------------------------------------------------------------------------- /Patches/PauseScreen.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\FileSystemHooks.h" 21 | #include "Common\Utils.h" 22 | #include "Logging\Logging.h" 23 | #include "Common\Settings.h" 24 | 25 | void *jmpOptionsExitAddr = nullptr; 26 | void *PauseScreenCall1 = nullptr; 27 | void *PauseScreenCall2 = nullptr; 28 | void *PauseScreenCall3 = nullptr; 29 | 30 | // ASM functions to return to gameplay after entering options menu from the pause screen 31 | __declspec(naked) void __stdcall PauseScreenASM() 32 | { 33 | __asm 34 | { 35 | call PauseScreenCall1 // fixes doubled text 36 | call PauseScreenCall2 // normal call used when returning to game play 37 | call PauseScreenCall3 // fixes incorrect text & enables sh2e shaders 38 | mov eax, 0x02 39 | retn 40 | } 41 | } 42 | 43 | void PatchPauseScreen() 44 | { 45 | // Get Options exit address 46 | constexpr BYTE SearchBytesOptionsExit[]{ 0x08, 0x00, 0x00, 0x00, 0xEB, 0x0F, 0xB8, 0x10, 0x00, 0x00, 0x00, 0xA3 }; 47 | BYTE *OptionsExitAddress = (BYTE*)SearchAndGetAddresses(0x004697AF, 0x00469A4F, 0x00469C5F, SearchBytesOptionsExit, sizeof(SearchBytesOptionsExit), 0x06, __FUNCTION__); 48 | 49 | // Get call address 50 | constexpr BYTE SearchBytesGameCall[]{ 0x83, 0xC4, 0x0C, 0xB8, 0x01, 0x00, 0x00, 0x00, 0x5B, 0xC3, 0x90 }; 51 | DWORD GameCallAddr = SearchAndGetAddresses(0x00475839, 0x00475AD9, 0x00475CE9, SearchBytesGameCall, sizeof(SearchBytesGameCall), -0x5F, __FUNCTION__); 52 | 53 | // Checking address pointer 54 | if (!OptionsExitAddress || !GameCallAddr) 55 | { 56 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 57 | return; 58 | } 59 | 60 | // Set call addresses 61 | PauseScreenCall1 = (void*)(GameCallAddr + *(DWORD*)(GameCallAddr + 1) + 5); 62 | PauseScreenCall2 = (void*)(GameCallAddr + *(DWORD*)(GameCallAddr + 6) + 10); 63 | PauseScreenCall3 = (void*)(GameCallAddr + *(DWORD*)(GameCallAddr - 0xC0) - 0x9E); 64 | 65 | // Update SH2 code 66 | Logging::Log() << "Setting Pause Menu Fix..."; 67 | WriteCalltoMemory(OptionsExitAddress, PauseScreenASM); 68 | } 69 | -------------------------------------------------------------------------------- /Patches/PreventChainsawSpawn.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | void PatchPreventChainsawSpawn() 23 | { 24 | // Get chiansaw spawn address 25 | constexpr BYTE SearchBytes[]{ 0x85, 0xF6, 0x7E, 0x0F, 0xF6, 0xC1, 0x40, 0x74, 0x0A, 0x81, 0x0D }; 26 | DWORD ChainsawAddr = SearchAndGetAddresses(0x0048AB80, 0x0048AE20, 0x0048B030, SearchBytes, sizeof(SearchBytes), -0x12, __FUNCTION__); 27 | if (!ChainsawAddr) 28 | { 29 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 30 | return; 31 | } 32 | 33 | Logging::Log() << "Add fix to prevent chainsaw from spawning on first playthrough..."; 34 | UpdateMemoryAddress((void*)ChainsawAddr, "\x00", 1); 35 | } 36 | -------------------------------------------------------------------------------- /Patches/PrisonerTimer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2022 Murugo 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // ASM function to modify the prisoner timer after reset 24 | __declspec(naked) void __stdcall PrisonerTimerResetASM() 25 | { 26 | __asm 27 | { 28 | sal dword ptr[esi + 0xA0], 1 // Multiply prisoner timer by 2 29 | ret 30 | } 31 | } 32 | 33 | // Modify the value of the "Ritual" prisoner timer to fix the footstep rate at 60 FPS 34 | void PatchPrisonerTimer() 35 | { 36 | // Get Prisoner Timer Reset address 37 | constexpr BYTE SearchBytesPrisonerTimerReset[]{ 0x89, 0x86, 0xA0, 0x00, 0x00, 0x00, 0xD9, 0x1C, 0x24, 0xE8 }; 38 | DWORD PrisonerTimerResetAddr = SearchAndGetAddresses(0x004AE5F8, 0x004AE8A8, 0x004AE168, SearchBytesPrisonerTimerReset, sizeof(SearchBytesPrisonerTimerReset), 0x1D, __FUNCTION__); 39 | if (!PrisonerTimerResetAddr) 40 | { 41 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 42 | return; 43 | } 44 | 45 | Logging::Log() << "Enabling Prisoner Timer Fix..."; 46 | WriteJMPtoMemory((BYTE*)PrisonerTimerResetAddr, *PrisonerTimerResetASM, 0x05); 47 | } 48 | -------------------------------------------------------------------------------- /Patches/PuzzleAlignmentFixes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #include "Wrappers\d3d8\DirectX81SDK\include\d3d8.h" 5 | 6 | struct StyleBits 7 | { 8 | unsigned short textured : 1; // 0 = flat shaded, 1 = textured 9 | unsigned short unk02 : 1; // affects the vertices, draws larger 10 | unsigned short useTexCoords : 1; // 0 = draw entire texture, 1 = draw portion given by texCoords 11 | unsigned short unk08 : 1; 12 | unsigned short unk10 : 1; 13 | unsigned short useTransparency : 1; 14 | unsigned short unk40 : 1; 15 | unsigned short fourCorners : 1; // 0 = quad is specified by top left and bottom right vertices. 1 = vertices are positioned independently. 16 | unsigned short unk100 : 1; 17 | }; 18 | 19 | struct UIElement 20 | { 21 | IDirect3DBaseTexture8* texture; 22 | DWORD dword4; // probably another texture 23 | DWORD id; // avoid trusting this value, the game never uses it and it differs between region/versions 24 | 25 | struct { 26 | short x; 27 | short y; 28 | } verts[4]; // If style.fourCorners == 0, only verts[0] and verts[1] are used 29 | 30 | struct { 31 | float u1; 32 | float v1; 33 | float u2; 34 | float v2; 35 | } texCoords; 36 | 37 | WORD word2C; 38 | StyleBits style; 39 | WORD word30; 40 | WORD word32; 41 | 42 | WORD width; 43 | WORD height; 44 | 45 | struct { 46 | unsigned char b; 47 | unsigned char g; 48 | unsigned char r; 49 | unsigned char a; 50 | } color; 51 | 52 | DWORD reserved3C; 53 | DWORD reserved40; 54 | }; 55 | static_assert(sizeof(UIElement) == 0x44); 56 | 57 | void PatchPuzzleAlignmentFixes(); 58 | -------------------------------------------------------------------------------- /Patches/Room312FlashlightFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 mercury501 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "Common\Utils.h" 18 | #include "Patches\Patches.h" 19 | #include "Logging\Logging.h" 20 | 21 | BYTE* InhibitFlashlightAddr = nullptr; 22 | 23 | bool InhibitedFlashlightFlag = false; 24 | 25 | void CheckRoom312Flashlight() 26 | { 27 | if (!InhibitFlashlightAddr) 28 | { 29 | InhibitFlashlightAddr = GameVersion == SH2V_10 ? (BYTE*)0x0048EBC8 : 30 | GameVersion == SH2V_11 ? (BYTE*)0x0048EE68 : 31 | GameVersion == SH2V_DC ? (BYTE*)0x0048F078 : 32 | nullptr; 33 | 34 | if (!InhibitFlashlightAddr) 35 | { 36 | Logging::Log() << __FUNCTION__ << " Couldn't identify game version."; 37 | return; 38 | } 39 | 40 | Logging::Log() << __FUNCTION__ << " Initialized room 312 flashlight fix!"; 41 | } 42 | 43 | bool InhibitFlashlight = GetRoomID() == R_HTL_RM_312 && (GetInventoryItem() & 0x80); 44 | 45 | if (InhibitFlashlight && !InhibitedFlashlightFlag) 46 | { 47 | UpdateMemoryAddress(InhibitFlashlightAddr, "\x90\xE9", 0x02); 48 | InhibitedFlashlightFlag = true; 49 | } 50 | else if (!InhibitFlashlight && InhibitedFlashlightFlag) 51 | { 52 | UpdateMemoryAddress(InhibitFlashlightAddr, "\x0F\x84", 0x02); 53 | InhibitedFlashlightFlag = false; 54 | } 55 | } -------------------------------------------------------------------------------- /Patches/RotatingMannequinGlitch.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Run SH2 code to fix the rotating Mannequin glitch 24 | void RunRotatingMannequin() 25 | { 26 | // Get flashlight acquired Address 27 | static DWORD *FlashlightAcquiredAddr = nullptr; 28 | if (!FlashlightAcquiredAddr) 29 | { 30 | RUNONCE(); 31 | 32 | // Get address 33 | constexpr BYTE SearchBytes[]{ 0x8D, 0x50, 0x1C, 0x8B, 0x0A, 0x89, 0x0D }; 34 | FlashlightAcquiredAddr = (DWORD*)ReadSearchedAddresses(0x0045507D, 0x004552DD, 0x004552DD, SearchBytes, sizeof(SearchBytes), 0x56, __FUNCTION__); 35 | 36 | // Checking address pointer 37 | if (!FlashlightAcquiredAddr) 38 | { 39 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 40 | return; 41 | } 42 | } 43 | 44 | // Get Mannequin state Address 45 | static DWORD *MannequinStateAddr = nullptr; 46 | if (!MannequinStateAddr) 47 | { 48 | RUNONCE(); 49 | 50 | // Get address 51 | constexpr BYTE SearchBytes[]{ 0x68, 0x00, 0x02, 0x00, 0x00, 0x33, 0xF6, 0x33, 0xDB, 0x50, 0x89, 0x94, 0x24, 0x50, 0x04, 0x00, 0x00 }; 52 | MannequinStateAddr = (DWORD*)ReadSearchedAddresses(0x0048CBC5, 0x0048CE65, 0x0048D075, SearchBytes, sizeof(SearchBytes), 0x34, __FUNCTION__); 53 | 54 | // Checking address pointer 55 | if (!MannequinStateAddr) 56 | { 57 | Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; 58 | return; 59 | } 60 | MannequinStateAddr = (DWORD*)((DWORD)MannequinStateAddr + 0x60); 61 | } 62 | 63 | LOG_ONCE("Fixing the rotating Mannequin glitch..."); 64 | 65 | // Static updates 66 | static bool ValueSet = false; 67 | if (GetRoomID() == R_APT_E_HALLWAY_2F && *MannequinStateAddr != 0x00 && (*FlashlightAcquiredAddr & 0x40000)) 68 | { 69 | if (!ValueSet && *MannequinStateAddr == 0x206) 70 | { 71 | DWORD Value = 0x207; 72 | UpdateMemoryAddress(MannequinStateAddr, &Value, sizeof(DWORD)); 73 | } 74 | ValueSet = true; 75 | } 76 | else if (ValueSet) 77 | { 78 | ValueSet = false; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Patches/RowboatAnimation.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\Utils.h" 20 | #include "Logging\Logging.h" 21 | 22 | // Variables for ASM 23 | DWORD *RowboatPointer; 24 | 25 | // ASM functions to update Rowboat Animation 26 | __declspec(naked) void __stdcall RowboatAnimationASM() 27 | { 28 | __asm 29 | { 30 | cmp eax, 0x4C 31 | jne near RowboatExit 32 | push ecx 33 | push eax 34 | xor ecx, ecx 35 | dec ecx 36 | mov eax, dword ptr ds : [RowboatPointer] 37 | mov dword ptr ds : [eax], ecx 38 | pop eax 39 | pop ecx 40 | 41 | RowboatExit: 42 | retn 43 | } 44 | } 45 | 46 | // Patch SH2 code to Fix Rowboat Animation 47 | void PatchRowboatAnimation() 48 | { 49 | // Get Rowboat Animation address 50 | constexpr BYTE RowboatSearchBytes[]{ 0x8B, 0x56, 0x08, 0x89, 0x10, 0x5F, 0x5E, 0x5D, 0x83, 0xC4, 0x50, 0xC3 }; 51 | DWORD RowboatAddr = SearchAndGetAddresses(0x004A0293, 0x004A0543, 0x0049FE03, RowboatSearchBytes, sizeof(RowboatSearchBytes), 0x22, __FUNCTION__); 52 | 53 | // Get memory pointer for Rowboat Animation 54 | constexpr BYTE RowboatSearchPtrBytes[] = { 0x56, 0x6A, 0x0A, 0x6A, 0x00, 0x50, 0xE8 }; 55 | DWORD RowboatMemoryPtr = SearchAndGetAddresses(0x0053F9C3, 0x0053FCF3, 0x0053F613, RowboatSearchPtrBytes, sizeof(RowboatSearchPtrBytes), -0x3D, __FUNCTION__); 56 | 57 | // Checking address pointer 58 | if (!RowboatMemoryPtr || !RowboatAddr) 59 | { 60 | Logging::Log() << __FUNCTION__ << " Error: failed to find pointer address!"; 61 | return; 62 | } 63 | memcpy(&RowboatPointer, (void*)(RowboatMemoryPtr + 2), sizeof(DWORD)); 64 | 65 | // Check for valid code before updating 66 | if (!CheckMemoryAddress((void*)RowboatAddr, "\xC3", 1, __FUNCTION__) || 67 | !CheckMemoryAddress((void*)RowboatMemoryPtr, "\x3B\x05", 2, __FUNCTION__)) 68 | { 69 | Logging::Log() << __FUNCTION__ << " Error: memory addresses don't match!"; 70 | return; 71 | } 72 | 73 | // Update SH2 code 74 | Logging::Log() << "Setting Rowboat Animation Fix..."; 75 | WriteJMPtoMemory((BYTE*)RowboatAddr, *RowboatAnimationASM); 76 | } 77 | -------------------------------------------------------------------------------- /Patches/RowboatFix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 BigManJapan, mercury501 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "External\injector\include\injector\injector.hpp" 18 | #include "External\injector\include\injector\utility.hpp" 19 | #include "Patches\Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | injector::hook_back orgHandleMovement; 24 | BYTE* GreatKnifeAddr = nullptr; 25 | 26 | void __cdecl HandleMovement_Hook() 27 | { 28 | if ((GetBoatFlag() == 0x01 && GetRoomID() == R_TOWN_LAKE)) 29 | { 30 | UpdateMemoryAddress(GreatKnifeAddr, "\xFF", 0x01); 31 | } 32 | else 33 | { 34 | UpdateMemoryAddress(GreatKnifeAddr, "\x08", 0x01); 35 | } 36 | 37 | orgHandleMovement.fun(); 38 | } 39 | 40 | void PatchGreatKnifeBoatSpeed() 41 | { 42 | Logging::Log() << "Patching boat speed with great knife..."; 43 | 44 | constexpr BYTE HandleMovementSearchBytes[]{ 0xA8, 0x04, 0x74, 0x38, 0xf6, 0xC4, 0x20, 0x0F }; 45 | BYTE* HandleMovementAddr = (BYTE*)SearchAndGetAddresses(0x0053639F, 0x005366CF, 0x00535FEF, HandleMovementSearchBytes, sizeof(HandleMovementSearchBytes), 0x0D, __FUNCTION__); 46 | 47 | // Checking address pointer 48 | if (!HandleMovementAddr) 49 | { 50 | Logging::Log() << __FUNCTION__ << " Error: failed to find handle movement memory address!"; 51 | return; 52 | } 53 | 54 | constexpr BYTE GreatKnifeSearchBytes[]{ 0xEB, 0x02, 0x32, 0xD2 }; 55 | GreatKnifeAddr = (BYTE*)SearchAndGetAddresses(0x0052EA5A, 0x0052ED8A, 0x0052E6AA, GreatKnifeSearchBytes, sizeof(GreatKnifeSearchBytes), 0x0A, __FUNCTION__); 56 | 57 | // Checking address pointer 58 | if (!HandleMovementAddr) 59 | { 60 | Logging::Log() << __FUNCTION__ << " Error: failed to find great knife index memory address!"; 61 | return; 62 | } 63 | 64 | orgHandleMovement.fun = injector::MakeCALL(HandleMovementAddr, HandleMovement_Hook, true).get(); 65 | } -------------------------------------------------------------------------------- /Patches/SaveBGImage.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Patches.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | // Patch the save/load BG images for each campaign 24 | void PatchSaveBGImage() 25 | { 26 | // Get fog addresses 27 | constexpr BYTE BGLoadSearchBytes[]{ 0x83, 0xC4, 0x0C, 0x3C, 0x02, 0x7D, 0x1D, 0x80, 0x3D }; 28 | BYTE *BGLoadAddr = (BYTE*)SearchAndGetAddresses(0x0044B414, 0x0044B5B4, 0x0044B5B4, BGLoadSearchBytes, sizeof(BGLoadSearchBytes), 0x5, __FUNCTION__); 29 | 30 | if (!BGLoadAddr) 31 | { 32 | Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; 33 | return; 34 | } 35 | 36 | // Update SH2 code 37 | Logging::Log() << "Enabling Save Background Images Fix..."; 38 | UpdateMemoryAddress(BGLoadAddr, "\x90\x90", 2); 39 | } 40 | 41 | void RunSaveBGImage() 42 | { 43 | static BYTE *ChapterIDPointer = GetChapterIDPointer(); 44 | if (!ChapterIDPointer) 45 | { 46 | LOG_ONCE(__FUNCTION__ " Error: failed to find memory address!"); 47 | return; 48 | } 49 | 50 | static BYTE LastMenuEvent = 0; 51 | BYTE MenuEvent = GetMenuEvent(); 52 | 53 | if (LastMenuEvent != MENU_MAIN_MENU && MenuEvent == MENU_MAIN_MENU) 54 | { 55 | *ChapterIDPointer = CHAPTER_MAIN_SCENARIO; 56 | } 57 | 58 | LastMenuEvent = MenuEvent; 59 | } 60 | -------------------------------------------------------------------------------- /Patches/SixtyFPSPatch.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 mercury501, Murugo, Aero_, Polymega 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "Logging\Logging.h" 18 | #include "Patches.h" 19 | #include "Common\Utils.h" 20 | #include "Common\Settings.h" 21 | 22 | extern float MotionBlurValue; 23 | extern BYTE EddieBossTimeLimit; 24 | -------------------------------------------------------------------------------- /Patches/ValidateBinary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #include "Common\md5.h" 20 | #include "Common\Utils.h" 21 | #include "Logging\Logging.h" 22 | 23 | constexpr char *GoodHashes[] = { 24 | { "c65baee155f3f47b4538e67ff9073d25" }, 25 | { "1be408eca5e437e9d7f63461e2cb9e69" }, 26 | { "1e797657100d0b6e6de23cffec94a331" }, 27 | { "957b9349b0dd8a48e64e6d7218b7522c" }, 28 | { "b2d4a1f0cff2542f9f856150cd770a16" }, 29 | { "f3f5360298b6d0f6f2e09cf24a0925d1" }, 30 | { "c16ed8436fdcfc53a07ab21723994770" }, 31 | { "0afa171ea93ee1441682f49969e6f02c" }, 32 | { "f9ccf14b5e5a31d9fe50e5b5efe50ed7" }, 33 | { "37caa31bdb473d9019be2491bd8dc914" } 34 | }; 35 | 36 | // Get number of textures in array 37 | constexpr DWORD HashNum = (sizeof(GoodHashes) / sizeof(*GoodHashes)); 38 | 39 | void ValidateBinary() 40 | { 41 | wchar_t pathname[MAX_PATH]; 42 | GetSH2FolderPath(pathname, MAX_PATH); 43 | std::ifstream file(pathname, std::ios::in | std::ios::binary | std::ios::ate); 44 | std::string buffer; 45 | 46 | if (file.is_open()) 47 | { 48 | // Get binary size 49 | DWORD size = (DWORD)file.tellg(); 50 | buffer.resize(size); 51 | 52 | // Read binary file 53 | file.seekg(0, std::ios::beg); 54 | file.read((char*)&buffer[0], size); 55 | 56 | // Close binary 57 | file.close(); 58 | } 59 | else 60 | { 61 | Logging::Log() << __FUNCTION__ << " Error: Could not open binary!"; 62 | return; 63 | } 64 | 65 | // Compute hash 66 | std::string hash(md5(buffer)); 67 | 68 | // Check for good binary 69 | for (int x = 0; x < HashNum; x++) 70 | { 71 | if (hash.compare(GoodHashes[x]) == 0) 72 | { 73 | // Found good binary 74 | return; 75 | } 76 | } 77 | 78 | Logging::Log() << "Warning: Unknown game binary hash: " << md5(buffer).c_str(); 79 | } 80 | -------------------------------------------------------------------------------- /ReShade/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Patrick Mours. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /ReShade/ReShadeFX/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Patrick Mours. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /ReShade/ReShadeFX/ReShadeFX.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ReShade/ReShadeFX/spirv.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | $(ProjectDir)..\..\External\reshade\deps\spirv\include\spirv\unified1;%(AdditionalIncludeDirectories)\include\spirv\unified1;%(AdditionalIncludeDirectories) 7 | 8 | 9 | -------------------------------------------------------------------------------- /ReShade/Runtime/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Patrick Mours. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /ReShade/stb/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Patrick Mours. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /ReShade/stb/stb.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | $(ProjectDir)External\reshade\deps\stb;$(ProjectDir)External\reshade\deps\stb_image_dds;$(ProjectDir)..\..\External\reshade\deps\stb;$(ProjectDir)..\..\External\reshade\deps\stb_image_dds;%(AdditionalIncludeDirectories) 7 | STBI_NO_STDIO;STBI_NO_LINEAR;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 8 | 9 | 10 | -------------------------------------------------------------------------------- /ReShade/stb/stb_impl.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #define STB_IMAGE_DDS_IMPLEMENTATION 3 | #define STB_IMAGE_WRITE_IMPLEMENTATION 4 | #define STB_IMAGE_RESIZE_IMPLEMENTATION 5 | 6 | #include "stb_image.h" 7 | #include "stb_image_dds.h" 8 | #include "stb_image_write.h" 9 | #include "stb_image_resize.h" 10 | -------------------------------------------------------------------------------- /Resolution.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct RESOLUTONTEXT 6 | { 7 | char resStrBuf[27]; 8 | }; 9 | 10 | const std::vector& GetResolutionText(); 11 | 12 | // Updates WSF and updates the text resolution index. 13 | void WSFDynamicChangeWithIndex(BYTE NewIndex); 14 | 15 | // Returns whether the resolution option is locked. 16 | bool IsResolutionLocked(); 17 | -------------------------------------------------------------------------------- /Resources/AreaTex.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/AreaTex.dds -------------------------------------------------------------------------------- /Resources/BuildNo.rc: -------------------------------------------------------------------------------- 1 | #define BUILD_NUMBER 2227 2 | -------------------------------------------------------------------------------- /Resources/ReShade.ini: -------------------------------------------------------------------------------- 1 | Techniques=SMAA,Pirate_Bloom,CRTFrutbunn,CRT_Lottes,CRTRefresh 2 | TechniqueSorting=SMAA,Pirate_Bloom,CRTFrutbunn,CRT_Lottes,CRTRefresh 3 | PreprocessorDefinitions=ENABLE_HISTOGRAM=0 4 | 5 | [D3D9] 6 | DepthCopyAtClearIndex=0 7 | DepthCopyBeforeClears=0 8 | DisableINTZ=0 9 | UseAspectRatioHeuristics=1 10 | 11 | [DX9_BUFFER_DETECTION] 12 | DisableINTZ=0 13 | PreserveDepthBuffer=0 14 | PreserveDepthBufferIndex=4294967295 15 | UseAspectRatioHeuristics=1 16 | 17 | [GENERAL] 18 | PerformanceMode=1 19 | PreprocessorDefinitions=RESHADE_DEPTH_LINEARIZATION_FAR_PLANE=1000.0,RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN=0,RESHADE_DEPTH_INPUT_IS_REVERSED=0,RESHADE_DEPTH_INPUT_IS_LOGARITHMIC=0 20 | PresetTransitionDelay=1000 21 | 22 | [Lottes.fx] 23 | hardScan=-8.000000 24 | hardPix=-3.000000 25 | warp=0.000000,0.000000 26 | maskDark=0.500000 27 | maskLight=1.500000 28 | scaleInLinearGamma=0 29 | simpleLinearGamma=0 30 | shadowMask=1.000000 31 | brightboost=1.150000 32 | hardBloomPix=-1.500000 33 | hardBloomScan=-2.000000 34 | bloomAmount=0.150000 35 | shape=2.000000 36 | DO_BLOOM=0 37 | 38 | [FrutbunnNonCurve.fx] 39 | blur=0.850000 40 | CURVATURE=0 41 | CURVED_SCANLINES=0 42 | LIGHT=1 43 | light=2 44 | SCANLINES=1 45 | screenCurveX=0.350000 46 | screenCurveY=0.350000 47 | screenZoom=0.975000 48 | 49 | [FrutbunnCurve.fx] 50 | blur=0.850000 51 | CURVATURE=1 52 | CURVED_SCANLINES=0 53 | LIGHT=1 54 | light=2 55 | SCANLINES=1 56 | screenCurveX=0.350000 57 | screenCurveY=0.350000 58 | screenZoom=0.975000 59 | 60 | [Refresh.fx] 61 | fRollingFlicker_Factor=0.010000 62 | fRollingFlicker_VSyncTime=0.100000 63 | 64 | [PirateBloom.fx] 65 | BLOOM_BLEND=1 66 | BLOOM_DEBUG=0 67 | BLOOM_RADIUS=0.350000 68 | BLOOM_SATURATION=0.500000 69 | BLOOM_STRENGTH=0.650000 70 | BLOOM_THRESHOLD=0.650000 71 | 72 | [SMAA.fx] 73 | CornerRounding=25 74 | DebugOutput=0 75 | DepthEdgeDetectionThreshold=0.010000 76 | EdgeDetectionThreshold=0.100000 77 | EdgeDetectionType=1 78 | MaxSearchSteps=32 79 | MaxSearchStepsDiagonal=16 80 | PredicationEnabled=0 81 | PredicationScale=2.000000 82 | PredicationStrength=0.400000 83 | PredicationThreshold=0.010000 84 | -------------------------------------------------------------------------------- /Resources/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BuildNo.rc" 4 | 5 | // Included resource files 6 | #define OIC_SH2_ICON 151 7 | 8 | #define IDR_SETTINGS_INI 101 9 | #define IDR_RESHADE_INI 102 10 | #define IDR_ALSOFT_INI 103 11 | 12 | #define IDR_SMAA_FX 201 13 | #define IDR_PIRATEBLOOM_FX 204 14 | #define IDR_FRUTBUNN_FX 205 15 | #define IDR_LOTTES_FX 206 16 | #define IDR_REFRESH_FX 207 17 | 18 | #define IDR_SEARCHTEX_DDS 301 19 | #define IDR_AREATEX_DDS 302 20 | 21 | #define IDR_LANG_RES_JA 501 22 | #define IDR_LANG_RES_EN 502 23 | #define IDR_LANG_RES_FR 503 24 | #define IDR_LANG_RES_DE 504 25 | #define IDR_LANG_RES_IT 505 26 | #define IDR_LANG_RES_ES 506 27 | 28 | // Main resource file details 29 | #define APP_NAME "Silent Hill 2: Enhanced Edition" 30 | #define APP_MAJOR 3 31 | #define APP_MINOR 0 32 | #define APP_BUILDNUMBER BUILD_NUMBER 33 | #define APP_REVISION 0 34 | #define APP_COMPANYNAME "Sadrate Presents" 35 | #define APP_DESCRPTION "A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC." 36 | #define APP_COPYRIGHT "Copyright (C) 2024 Elisha Riedlinger" 37 | #define APP_ORIGINALVERSION "d3d8.dll" 38 | #define APP_INTERNALNAME "sh2-enhce" 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // 42 | // ReShade 43 | // 44 | #define RESHADE_DATE "2020-10-03" 45 | #define RESHADE_TIME "01:58:54" 46 | #define RESHADE_FULL 4.5.3.797 47 | #define RESHADE_MAJOR 4 48 | #define RESHADE_MINOR 5 49 | #define RESHADE_REVISION 3 50 | #define RESHADE_BUILD 797 51 | #define RESHADE_STRING_FILE "4.5.3.797" 52 | #define RESHADE_STRING_PRODUCT "4.5.3 UNOFFICIAL" 53 | ///////////////////////////////////////////////////////////////////////////// 54 | 55 | // Get APP_VERSION 56 | #define _TO_STRING_(x) #x 57 | #define _TO_STRING(x) _TO_STRING_(x) 58 | #define APP_VERSION _TO_STRING(APP_MAJOR) "." _TO_STRING(APP_MINOR) "." _TO_STRING(APP_BUILDNUMBER) "." _TO_STRING(APP_REVISION) 59 | #define VERSION_NUMBER APP_MAJOR, APP_MINOR, APP_BUILDNUMBER, APP_REVISION 60 | 61 | #ifdef RESHADE_FILE_LIST 62 | 63 | #include "Common\Settings.h" 64 | 65 | namespace 66 | { 67 | struct FILELIST { 68 | bool* enabled; 69 | DWORD value; 70 | std::string name; 71 | }; 72 | 73 | std::string GammaEffectName = "LiftGammaGain"; 74 | 75 | std::vector shaderList{ 76 | { &EnableSMAA, IDR_SMAA_FX, "SMAA.fx" }, 77 | { &EnableCRTShader, IDR_PIRATEBLOOM_FX, "PirateBloom.fx" }, 78 | { &CRTNonCurveShader, IDR_FRUTBUNN_FX, "FrutbunnNonCurve.fx" }, 79 | { &CRTCurveShader, IDR_FRUTBUNN_FX, "FrutbunnCurve.fx" }, 80 | { &EnableCRTShader, IDR_LOTTES_FX, "Lottes.fx" }, 81 | { &EnableCRTShader, IDR_REFRESH_FX, "Refresh.fx" }, 82 | }; 83 | 84 | std::vector textureList{ 85 | { nullptr, IDR_SEARCHTEX_DDS, "SearchTex.dds" }, 86 | { nullptr, IDR_AREATEX_DDS, "AreaTex.dds" }, 87 | }; 88 | } 89 | 90 | #endif 91 | 92 | void LockConfigs(); 93 | bool ResolutionAvailableCheck(int width, int height); -------------------------------------------------------------------------------- /Resources/SH2EEsetup.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/SH2EEsetup.exe -------------------------------------------------------------------------------- /Resources/SearchTex.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/SearchTex.dds -------------------------------------------------------------------------------- /Resources/UALx86.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/UALx86.rc -------------------------------------------------------------------------------- /Resources/Xidi.ini: -------------------------------------------------------------------------------- 1 | [Mapper] 2 | Type = ModifiedStandardGamepad 3 | 4 | [CustomMapper:ModifiedStandardGamepad] 5 | 6 | ; Imports all of the element mappers from StandardGamepad. 7 | ; This line is allowed to appear anywhere in the section, including between or after the element mappers below. 8 | Template = StandardGamepad 9 | 10 | ; These changes are applied on top of the template. 11 | ButtonA = Button(2) 12 | ButtonB = Button(3) 13 | ButtonX = Button(1) -------------------------------------------------------------------------------- /Resources/alsoft.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | channels= 3 | frequency=44100 4 | stereo-mode=auto 5 | cf_level=0 6 | sources=512 7 | slots=64 8 | sends=16 9 | sample-type=float32 10 | resampler=cubic 11 | default-hrtf=Built-In 44100hz 12 | hrtf=auto 13 | period_size=128 14 | periods=3 15 | hrtf-mode=full 16 | hrtf-size=0 -------------------------------------------------------------------------------- /Resources/dinput8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/dinput8.dll -------------------------------------------------------------------------------- /Resources/exe_str_e.txt: -------------------------------------------------------------------------------- 1 | \hPAUSED 2 | \hResume 3 | \hSave Game 4 | \hLoad Game 5 | \hOptions 6 | \hQuit 7 | \hExit to Main Menu? 8 | \hYes 9 | \hNo 10 | \c\hPlease insert Silent Hill 2 disc 11 | \c\hPaused 12 | \c\hWrong disc 13 | \c\hController not connected 14 | \c\hDisc not inserted 15 | \c\hDisc tray open 16 | \c\hNow loading 17 | \c\hPlease wait 18 | \c\hChecking disc 19 | \c\hExit to main menu? 20 | \c\hYes 21 | \c\hNo 22 | Button %d 23 | \hGAME SAVED 24 | \hCAN'T SAVE 25 | \hNO QUICK SAVE 26 | \hConfigure in d3d8.ini file 27 | \hConfigure in Windows Sound Settings 28 | \hMaster Volume 29 | \hAdjust master volume 30 | \hHealth Indicator 31 | \hEnable the low health indicator 32 | \hRender Resolution 33 | \hAdjust rendering resolution 34 | \h3D Sound 35 | \hEnable 3D sound effects -------------------------------------------------------------------------------- /Resources/exe_str_f.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/exe_str_f.txt -------------------------------------------------------------------------------- /Resources/exe_str_g.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/exe_str_g.txt -------------------------------------------------------------------------------- /Resources/exe_str_i.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/exe_str_i.txt -------------------------------------------------------------------------------- /Resources/exe_str_j.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/exe_str_j.txt -------------------------------------------------------------------------------- /Resources/exe_str_s.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/exe_str_s.txt -------------------------------------------------------------------------------- /Resources/sh2-enhce.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include 4 | #include "Resource.h" 5 | 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Version 9 | // 10 | 11 | VS_VERSION_INFO VERSIONINFO 12 | FILEVERSION VERSION_NUMBER 13 | PRODUCTVERSION VERSION_NUMBER 14 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 15 | FILEFLAGS 0 16 | FILEOS VOS_NT_WINDOWS32 17 | FILETYPE VFT_DLL 18 | FILESUBTYPE VFT2_UNKNOWN 19 | { 20 | BLOCK "StringFileInfo" 21 | { 22 | BLOCK "04090000" 23 | { 24 | VALUE "CompanyName", APP_COMPANYNAME 25 | VALUE "FileDescription", APP_DESCRPTION 26 | VALUE "FileVersion", APP_VERSION 27 | VALUE "InternalName", APP_INTERNALNAME 28 | VALUE "LegalCopyright", APP_COPYRIGHT 29 | VALUE "OriginalFilename", APP_ORIGINALVERSION 30 | VALUE "ProductName", APP_NAME 31 | VALUE "ProductVersion", APP_VERSION 32 | } 33 | } 34 | 35 | BLOCK "VarFileInfo" 36 | { 37 | VALUE "Translation", 0x409, 0 38 | } 39 | } 40 | 41 | ///////////////////////////////////////////////////////////////////////////// 42 | -------------------------------------------------------------------------------- /Resources/sh2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/sh2.ico -------------------------------------------------------------------------------- /Resources/sh2pc.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Resources/sh2pc.ips -------------------------------------------------------------------------------- /Resources/sh2pc.txt: -------------------------------------------------------------------------------- 1 | About sh2pc.ips: 2 | 3 | - Removes CD protection 4 | - Adds code to load d3dx.dll 5 | - Adds an icon into the file 6 | 7 | last updated 6/3/2024 8 | 9 | Original file: 10 | MD5: c16ed8436fdcfc53a07ab21723994770 11 | SHA-1: 41f100f3f93b448bee739342acb9539c428dc1c8 12 | SHA-256: ff8aac516350b4e0db182bb18f98e760742bc482fc4dc4ad52f04ef276e7207e 13 | 14 | Patched file: 15 | MD5: f9ccf14b5e5a31d9fe50e5b5efe50ed7 16 | SHA-1: d636f95ba008c3ff8dd7a15ebfde25e063036261 17 | SHA-256: ee0e886acfa5a2193e3880e2afaf6b721bf0a8d54cbdcea2d01141e3a98702b1 18 | -------------------------------------------------------------------------------- /Resources/webcsv.url: -------------------------------------------------------------------------------- 1 | https://files.townofsilenthill.com/SH2EE/_sh2ee.csv 2 | -------------------------------------------------------------------------------- /WidescreenFixesPack/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | * 16 | * Includes source code from WidescreenFixes Pack 17 | * https://github.com/ThirteenAG/WidescreenFixesPack 18 | */ -------------------------------------------------------------------------------- /WidescreenFixesPack/WidescreenFixesPack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "Common\Settings.h" 7 | 8 | void WSFInit(); 9 | void SetCutsceneBorder(); 10 | int GetValue(std::string_view, std::string_view szKey, int); 11 | -------------------------------------------------------------------------------- /Wrappers/BuildNo.rc: -------------------------------------------------------------------------------- 1 | #define FILEVERSION 1.12.0.0 2 | -------------------------------------------------------------------------------- /Wrappers/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Wrappers/d3d8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define VISIT_PROCS_D3D8(visit) \ 4 | visit(ValidatePixelShader, jmpaddr) \ 5 | visit(ValidateVertexShader, jmpaddr) \ 6 | visit(Direct3DCreate8, jmpaddr) 7 | 8 | #ifdef PROC_CLASS 9 | PROC_CLASS(d3d8, dll, VISIT_PROCS_D3D8) 10 | #endif 11 | -------------------------------------------------------------------------------- /Wrappers/d3d8/DirectX81SDK/include/.gitignore: -------------------------------------------------------------------------------- 1 | !*.lib -------------------------------------------------------------------------------- /Wrappers/d3d8/DirectX81SDK/include/d3d8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Wrappers/d3d8/DirectX81SDK/include/d3d8.lib -------------------------------------------------------------------------------- /Wrappers/d3d8/DirectX81SDK/include/d3dx8.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx8.h 6 | // Content: D3DX utility library 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef __D3DX8_H__ 11 | #define __D3DX8_H__ 12 | 13 | #include "d3d8.h" 14 | #include 15 | 16 | #ifndef D3DXINLINE 17 | #ifdef __cplusplus 18 | #define D3DXINLINE inline 19 | #else 20 | #define D3DXINLINE _inline 21 | #endif 22 | #endif 23 | 24 | #define D3DX_DEFAULT ULONG_MAX 25 | #define D3DX_DEFAULT_FLOAT FLT_MAX 26 | 27 | #include "d3dx8math.h" 28 | #include "d3dx8core.h" 29 | #include "d3dx8tex.h" 30 | #include "d3dx8mesh.h" 31 | #include "d3dx8shape.h" 32 | #include "d3dx8effect.h" 33 | 34 | 35 | #endif //__D3DX8_H__ 36 | -------------------------------------------------------------------------------- /Wrappers/d3d8/DirectX81SDK/include/d3dx8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Wrappers/d3d8/DirectX81SDK/include/d3dx8.lib -------------------------------------------------------------------------------- /Wrappers/d3d8/DirectX81SDK/include/libci.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elishacloud/Silent-Hill-2-Enhancements/02b36d39a06876dcb8d8b6e26e29934f266fca60/Wrappers/d3d8/DirectX81SDK/include/libci.lib -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3D8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3D8 : public IDirect3D8 4 | { 5 | private: 6 | LPDIRECT3D8 ProxyInterface; 7 | 8 | public: 9 | m_IDirect3D8(LPDIRECT3D8 pD3D) : ProxyInterface(pD3D) 10 | { 11 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 12 | } 13 | ~m_IDirect3D8() 14 | { 15 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 16 | } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3D8 methods ***/ 24 | STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction); 25 | STDMETHOD_(UINT, GetAdapterCount)(THIS); 26 | STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier); 27 | STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter); 28 | STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode); 29 | STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter, D3DDISPLAYMODE* pMode); 30 | STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter, D3DDEVTYPE DevType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed); 31 | STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); 32 | STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType); 33 | STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat); 34 | STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps); 35 | STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter); 36 | STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice8** ppReturnedDeviceInterface); 37 | }; 38 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DCubeTexture8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DCubeTexture8 : public IDirect3DCubeTexture8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DCUBETEXTURE8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DCubeTexture8(LPDIRECT3DCUBETEXTURE8 pTexture8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pTexture8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DCubeTexture8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DCUBETEXTURE8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DBaseTexture8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 34 | STDMETHOD_(DWORD, GetPriority)(THIS); 35 | STDMETHOD_(void, PreLoad)(THIS); 36 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 37 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 38 | STDMETHOD_(DWORD, GetLOD)(THIS); 39 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 40 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DSURFACE_DESC *pDesc); 41 | STDMETHOD(GetCubeMapSurface)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8** ppCubeMapSurface); 42 | STDMETHOD(LockRect)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 43 | STDMETHOD(UnlockRect)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level); 44 | STDMETHOD(AddDirtyRect)(THIS_ D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect); 45 | }; 46 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DIndexBuffer8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DIndexBuffer8 : public IDirect3DIndexBuffer8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DINDEXBUFFER8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DIndexBuffer8(LPDIRECT3DINDEXBUFFER8 pBuffer8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pBuffer8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DIndexBuffer8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DINDEXBUFFER8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DResource8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 34 | STDMETHOD_(DWORD, GetPriority)(THIS); 35 | STDMETHOD_(void, PreLoad)(THIS); 36 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 37 | STDMETHOD(Lock)(THIS_ UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags); 38 | STDMETHOD(Unlock)(THIS); 39 | STDMETHOD(GetDesc)(THIS_ D3DINDEXBUFFER_DESC *pDesc); 40 | }; 41 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DSurface8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DSurface8 : public IDirect3DSurface8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DSURFACE8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | IDirect3DSurface8* RenderInterface = nullptr; 9 | IDirect3DSurface8* ReplacedInterface = nullptr; 10 | 11 | bool IsTextureRenderTarget = false; 12 | bool IsTextureOfSurface = false; 13 | 14 | // For fake emulated locking 15 | bool IsLocked = false; 16 | bool EmuReadOnly = false; 17 | RECT EmuRect = { NULL }; 18 | IDirect3DSurface8* pEmuSurface = nullptr; 19 | 20 | public: 21 | m_IDirect3DSurface8(LPDIRECT3DSURFACE8 pSurface8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pSurface8), m_pDevice(pDevice) 22 | { 23 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 24 | 25 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 26 | } 27 | ~m_IDirect3DSurface8() 28 | { 29 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 30 | } 31 | 32 | LPDIRECT3DSURFACE8 GetProxyInterface() { return ProxyInterface; } 33 | 34 | /*** IUnknown methods ***/ 35 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 36 | STDMETHOD_(ULONG, AddRef)(THIS); 37 | STDMETHOD_(ULONG, Release)(THIS); 38 | 39 | /*** IDirect3DSurface8 methods ***/ 40 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 41 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 42 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 43 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 44 | STDMETHOD(GetContainer)(THIS_ REFIID riid, void** ppContainer); 45 | STDMETHOD(GetDesc)(THIS_ D3DSURFACE_DESC *pDesc); 46 | STDMETHOD(LockRect)(THIS_ D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 47 | STDMETHOD(UnlockRect)(THIS); 48 | }; 49 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DSwapChain8.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d8wrapper.h" 18 | 19 | HRESULT m_IDirect3DSwapChain8::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | Logging::LogDebug() << __FUNCTION__; 22 | 23 | if ((riid == IID_IDirect3DSwapChain8 || riid == IID_IUnknown) && ppvObj) 24 | { 25 | AddRef(); 26 | 27 | *ppvObj = this; 28 | 29 | return S_OK; 30 | } 31 | 32 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 33 | 34 | if (SUCCEEDED(hr)) 35 | { 36 | genericQueryInterface(riid, ppvObj, m_pDevice); 37 | } 38 | 39 | return hr; 40 | } 41 | 42 | ULONG m_IDirect3DSwapChain8::AddRef(THIS) 43 | { 44 | Logging::LogDebug() << __FUNCTION__; 45 | 46 | return ProxyInterface->AddRef(); 47 | } 48 | 49 | ULONG m_IDirect3DSwapChain8::Release(THIS) 50 | { 51 | Logging::LogDebug() << __FUNCTION__; 52 | 53 | return ProxyInterface->Release(); 54 | } 55 | 56 | HRESULT m_IDirect3DSwapChain8::Present(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion) 57 | { 58 | Logging::LogDebug() << __FUNCTION__; 59 | 60 | return ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); 61 | } 62 | 63 | HRESULT m_IDirect3DSwapChain8::GetBackBuffer(THIS_ UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) 64 | { 65 | Logging::LogDebug() << __FUNCTION__; 66 | 67 | HRESULT hr = ProxyInterface->GetBackBuffer(BackBuffer, Type, ppBackBuffer); 68 | 69 | if (SUCCEEDED(hr) && ppBackBuffer) 70 | { 71 | *ppBackBuffer = m_pDevice->ProxyAddressLookupTableD3d8->FindAddress(*ppBackBuffer); 72 | } 73 | 74 | return hr; 75 | } 76 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DSwapChain8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DSwapChain8 : public IDirect3DSwapChain8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DSWAPCHAIN8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DSwapChain8(LPDIRECT3DSWAPCHAIN8 pSwapChain8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pSwapChain8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DSwapChain8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DSWAPCHAIN8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DSwapChain8 methods ***/ 29 | STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion); 30 | STDMETHOD(GetBackBuffer)(THIS_ UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer); 31 | }; 32 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DTexture8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DTexture8 : public IDirect3DTexture8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DTEXTURE8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DTexture8(LPDIRECT3DTEXTURE8 pTexture8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pTexture8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DTexture8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DTEXTURE8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DBaseTexture8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 34 | STDMETHOD_(DWORD, GetPriority)(THIS); 35 | STDMETHOD_(void, PreLoad)(THIS); 36 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 37 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 38 | STDMETHOD_(DWORD, GetLOD)(THIS); 39 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 40 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DSURFACE_DESC *pDesc); 41 | STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level, IDirect3DSurface8** ppSurfaceLevel); 42 | STDMETHOD(LockRect)(THIS_ UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 43 | STDMETHOD(UnlockRect)(THIS_ UINT Level); 44 | STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect); 45 | }; 46 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DVertexBuffer8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVertexBuffer8 : public IDirect3DVertexBuffer8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DVERTEXBUFFER8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DVertexBuffer8(LPDIRECT3DVERTEXBUFFER8 pBuffer8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pBuffer8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DVertexBuffer8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DVERTEXBUFFER8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DResource8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 34 | STDMETHOD_(DWORD, GetPriority)(THIS); 35 | STDMETHOD_(void, PreLoad)(THIS); 36 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 37 | STDMETHOD(Lock)(THIS_ UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags); 38 | STDMETHOD(Unlock)(THIS); 39 | STDMETHOD(GetDesc)(THIS_ D3DVERTEXBUFFER_DESC *pDesc); 40 | }; 41 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DVolume8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVolume8 : public IDirect3DVolume8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DVOLUME8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DVolume8(LPDIRECT3DVOLUME8 pVolume8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pVolume8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DVolume8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DVOLUME8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DVolume8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD(GetContainer)(THIS_ REFIID riid, void** ppContainer); 34 | STDMETHOD(GetDesc)(THIS_ D3DVOLUME_DESC *pDesc); 35 | STDMETHOD(LockBox)(THIS_ D3DLOCKED_BOX * pLockedVolume, CONST D3DBOX* pBox, DWORD Flags); 36 | STDMETHOD(UnlockBox)(THIS); 37 | }; 38 | -------------------------------------------------------------------------------- /Wrappers/d3d8/IDirect3DVolumeTexture8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVolumeTexture8 : public IDirect3DVolumeTexture8, public AddressLookupTableD3d8Object 4 | { 5 | private: 6 | LPDIRECT3DVOLUMETEXTURE8 ProxyInterface; 7 | m_IDirect3DDevice8* m_pDevice; 8 | 9 | public: 10 | m_IDirect3DVolumeTexture8(LPDIRECT3DVOLUMETEXTURE8 pTexture8, m_IDirect3DDevice8* pDevice) : ProxyInterface(pTexture8), m_pDevice(pDevice) 11 | { 12 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 13 | 14 | m_pDevice->ProxyAddressLookupTableD3d8->SaveAddress(this, ProxyInterface); 15 | } 16 | ~m_IDirect3DVolumeTexture8() 17 | { 18 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 19 | } 20 | 21 | LPDIRECT3DVOLUMETEXTURE8 GetProxyInterface() { return ProxyInterface; } 22 | 23 | /*** IUnknown methods ***/ 24 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 25 | STDMETHOD_(ULONG, AddRef)(THIS); 26 | STDMETHOD_(ULONG, Release)(THIS); 27 | 28 | /*** IDirect3DBaseTexture8 methods ***/ 29 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice8** ppDevice); 30 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 31 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 32 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 33 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 34 | STDMETHOD_(DWORD, GetPriority)(THIS); 35 | STDMETHOD_(void, PreLoad)(THIS); 36 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 37 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 38 | STDMETHOD_(DWORD, GetLOD)(THIS); 39 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 40 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DVOLUME_DESC *pDesc); 41 | STDMETHOD(GetVolumeLevel)(THIS_ UINT Level, IDirect3DVolume8** ppVolumeLevel); 42 | STDMETHOD(LockBox)(THIS_ UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags); 43 | STDMETHOD(UnlockBox)(THIS_ UINT Level); 44 | STDMETHOD(AddDirtyBox)(THIS_ CONST D3DBOX* pDirtyBox); 45 | }; 46 | -------------------------------------------------------------------------------- /Wrappers/d3d8/InterfaceQuery.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d8wrapper.h" 18 | 19 | void genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_IDirect3DDevice8* m_pDevice) 20 | { 21 | if (!ppvObj || !*ppvObj || !m_pDevice) 22 | { 23 | return; 24 | } 25 | 26 | if (riid == IID_IDirect3D8) 27 | { 28 | IDirect3D8 *pD3D8 = nullptr; 29 | if (SUCCEEDED(m_pDevice->GetDirect3D(&pD3D8)) && pD3D8) 30 | { 31 | *ppvObj = pD3D8; 32 | pD3D8->Release(); 33 | return; 34 | } 35 | } 36 | 37 | if (riid == IID_IDirect3DDevice8) 38 | { 39 | *ppvObj = m_pDevice; 40 | return; 41 | } 42 | 43 | #define QUERYINTERFACE(x) \ 44 | if (riid == IID_ ## x) \ 45 | { \ 46 | *ppvObj = m_pDevice->ProxyAddressLookupTableD3d8->FindAddress(*ppvObj); \ 47 | return; \ 48 | } 49 | 50 | QUERYINTERFACE(IDirect3DTexture8); 51 | QUERYINTERFACE(IDirect3DCubeTexture8); 52 | QUERYINTERFACE(IDirect3DVolumeTexture8); 53 | QUERYINTERFACE(IDirect3DVertexBuffer8); 54 | QUERYINTERFACE(IDirect3DIndexBuffer8); 55 | QUERYINTERFACE(IDirect3DSurface8); 56 | QUERYINTERFACE(IDirect3DVolume8); 57 | QUERYINTERFACE(IDirect3DSwapChain8); 58 | } 59 | -------------------------------------------------------------------------------- /Wrappers/d3d8/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Wrappers/d3d8to9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "External\d3d8to9\source\d3d8to9.hpp" 4 | 5 | typedef IDirect3D8 *(WINAPI *Direct3DCreate8Proc)(UINT); 6 | 7 | void EnableD3d8to9(); 8 | HRESULT WINAPI d8_ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL flag, DWORD* toto); 9 | HRESULT WINAPI d8_ValidateVertexShader(DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, BOOL flag, DWORD* toto); 10 | Direct3D8 *WINAPI Direct3DCreate8to9(UINT SDKVersion); 11 | 12 | extern bool IsUsingD3d8to9; 13 | extern Direct3DCreate8Proc m_pDirect3DCreate8; 14 | -------------------------------------------------------------------------------- /Wrappers/d3d9/IDirect3D9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3D9 : public IDirect3D9 4 | { 5 | private: 6 | LPDIRECT3D9 ProxyInterface; 7 | 8 | void LogAdapterNames(); 9 | 10 | template 11 | static void init_runtime_d3d(T *&device, D3DDEVTYPE device_type, D3DPRESENT_PARAMETERS pp, bool use_software_rendering); 12 | 13 | public: 14 | m_IDirect3D9(LPDIRECT3D9 pDirect3D) : ProxyInterface(pDirect3D) 15 | { 16 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 17 | 18 | LogAdapterNames(); 19 | } 20 | ~m_IDirect3D9() 21 | { 22 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 23 | } 24 | 25 | /*** IUnknown methods ***/ 26 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 27 | STDMETHOD_(ULONG, AddRef)(THIS); 28 | STDMETHOD_(ULONG, Release)(THIS); 29 | 30 | /*** IDirect3D9 methods ***/ 31 | STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction); 32 | STDMETHOD_(UINT, GetAdapterCount)(THIS); 33 | STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier); 34 | STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter, D3DFORMAT Format); 35 | STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode); 36 | STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter, D3DDISPLAYMODE* pMode); 37 | STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter, D3DDEVTYPE DevType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed); 38 | STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); 39 | STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels); 40 | STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat); 41 | STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat); 42 | STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps); 43 | STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter); 44 | STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface); 45 | }; 46 | -------------------------------------------------------------------------------- /Wrappers/d3d9/IDirect3DSwapChain9.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 Patrick Mours. All rights reserved. 3 | * License: https://github.com/crosire/reshade#license 4 | * 5 | * Copyright (C) 2024 Elisha Riedlinger 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 8 | * authors be held liable for any damages arising from the use of this software. 9 | * Permission is granted to anyone to use this software for any purpose, including commercial 10 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 13 | * original software. If you use this software in a product, an acknowledgment in the product 14 | * documentation would be appreciated but is not required. 15 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 16 | * being the original software. 17 | * 3. This notice may not be removed or altered from any source distribution. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "d3d9wrapper.h" 23 | #include 24 | 25 | namespace reshade::d3d9 { class runtime_d3d9; } 26 | 27 | class m_IDirect3DSwapChain9 : public IDirect3DSwapChain9 28 | { 29 | private: 30 | LPDIRECT3DSWAPCHAIN9 ProxyInterface; 31 | m_IDirect3DDevice9 *const D3Device; 32 | 33 | public: 34 | std::shared_ptr _runtime; 35 | 36 | public: 37 | m_IDirect3DSwapChain9(m_IDirect3DDevice9 *device, IDirect3DSwapChain9 *original, const std::shared_ptr &runtime) : 38 | ProxyInterface(original), 39 | D3Device(device), 40 | _runtime(runtime) 41 | { 42 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 43 | 44 | assert(ProxyInterface != nullptr && D3Device != nullptr && _runtime != nullptr); 45 | } 46 | ~m_IDirect3DSwapChain9() 47 | { 48 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 49 | } 50 | 51 | /*** IUnknown methods ***/ 52 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 53 | STDMETHOD_(ULONG, AddRef)(THIS); 54 | STDMETHOD_(ULONG, Release)(THIS); 55 | 56 | /*** IDirect3DSwapChain9 methods ***/ 57 | STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags); 58 | STDMETHOD(GetFrontBufferData)(THIS_ IDirect3DSurface9* pDestSurface); 59 | STDMETHOD(GetBackBuffer)(THIS_ UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer); 60 | STDMETHOD(GetRasterStatus)(THIS_ D3DRASTER_STATUS* pRasterStatus); 61 | STDMETHOD(GetDisplayMode)(THIS_ D3DDISPLAYMODE* pMode); 62 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 63 | STDMETHOD(GetPresentParameters)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters); 64 | 65 | static bool is_presenting_entire_surface(const RECT *source_rect, HWND hwnd); 66 | }; 67 | -------------------------------------------------------------------------------- /Wrappers/d3d9/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Patrick Mours. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /Wrappers/d3d9/d3d9wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INITGUID 4 | 5 | #define NOMINMAX 6 | #define WIN32_LEAN_AND_MEAN 7 | #include 8 | 9 | class m_IDirect3D9; 10 | class m_IDirect3DDevice9; 11 | class m_IDirect3DSwapChain9; 12 | 13 | #include "Logging\Logging.h" 14 | #include "Common\Settings.h" 15 | 16 | #define MAX_D3D9ON12_QUEUES 2 17 | 18 | typedef struct _D3D9ON12_ARGS 19 | { 20 | BOOL Enable9On12; 21 | IUnknown* pD3D12Device; 22 | IUnknown* ppD3D12Queues[MAX_D3D9ON12_QUEUES]; 23 | UINT NumQueues; 24 | UINT NodeMask; 25 | } D3D9ON12_ARGS; 26 | 27 | typedef IDirect3D9*(WINAPI* Direct3DCreate9Proc)(UINT SDKVersion); 28 | typedef IDirect3D9*(WINAPI* Direct3DCreate9On12Proc)(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries); 29 | 30 | IDirect3D9 *WINAPI Direct3DCreate9Wrapper(UINT SDKVersion); 31 | 32 | #include "IDirect3D9.h" 33 | #include "IDirect3DDevice9.h" 34 | #include "IDirect3DSwapChain9.h" 35 | #include "runtime_d3d9.hpp" 36 | #include "ReShade\Runtime\runtime_config.hpp" 37 | #include "ReShade\Runtime\runtime_objects.hpp" 38 | 39 | extern Direct3DCreate9Proc m_pDirect3DCreate9; 40 | extern Direct3DCreate9On12Proc m_pDirect3DCreate9On12; 41 | -------------------------------------------------------------------------------- /Wrappers/d3d9/d3dx9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NOMINMAX 4 | #define NOMINMAX 5 | #endif 6 | 7 | #ifndef DIRECT3D_VERSION 8 | #include 9 | #endif 10 | 11 | #if(DIRECT3D_VERSION < 0x0900) 12 | typedef struct IDirect3DSurface9* LPDIRECT3DSURFACE9, *PDIRECT3DSURFACE9; 13 | #endif 14 | 15 | #ifndef __D3DX8_H__ 16 | #define D3DX_FILTER_NONE 1 17 | 18 | #define D3DXASM_DEBUG 0x0001 19 | #define D3DXASM_SKIPVALIDATION 0x0010 20 | 21 | DECLARE_INTERFACE_(ID3DXBuffer, IUnknown) 22 | { 23 | // IUnknown 24 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 25 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 26 | STDMETHOD_(ULONG, Release)(THIS) PURE; 27 | 28 | // ID3DXBuffer 29 | STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE; 30 | STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE; 31 | }; 32 | #endif 33 | 34 | #define D3DCOMPILE_OPTIMIZATION_LEVEL0 (1 << 14) 35 | #define D3DCOMPILE_OPTIMIZATION_LEVEL1 0 36 | #define D3DCOMPILE_OPTIMIZATION_LEVEL2 ((1 << 14) | (1 << 15)) 37 | #define D3DCOMPILE_OPTIMIZATION_LEVEL3 (1 << 15) 38 | 39 | #define D3D_DISASM_ENABLE_COLOR_CODE 0x00000001 40 | #define D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS 0x00000002 41 | #define D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING 0x00000004 42 | #define D3D_DISASM_ENABLE_INSTRUCTION_CYCLE 0x00000008 43 | #define D3D_DISASM_DISABLE_DEBUG_INFO 0x00000010 44 | 45 | #ifdef NDEBUG 46 | #define D3DXASM_FLAGS 0 47 | #else 48 | #define D3DXASM_FLAGS D3DXASM_DEBUG 49 | #endif // NDEBUG 50 | 51 | struct D3DXMACRO 52 | { 53 | LPCSTR Name; 54 | LPCSTR Definition; 55 | }; 56 | typedef struct D3DXMACRO D3D_SHADER_MACRO; 57 | 58 | typedef interface ID3DXBuffer *LPD3DXBUFFER; 59 | typedef interface ID3DInclude *LPD3DINCLUDE; 60 | typedef interface ID3DXInclude *LPD3DXINCLUDE; 61 | 62 | typedef ID3DXBuffer ID3DBlob; 63 | 64 | HRESULT WINAPI D3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER *ppShader, LPD3DXBUFFER *ppErrorMsgs); 65 | HRESULT WINAPI D3DXDisassembleShader(const DWORD *pShader, BOOL EnableColorCode, LPCSTR pComments, LPD3DXBUFFER *ppDisassembly); 66 | HRESULT WINAPI D3DXLoadSurfaceFromSurface(LPDIRECT3DSURFACE9 pDestSurface, const PALETTEENTRY *pDestPalette, const RECT *pDestRect, LPDIRECT3DSURFACE9 pSrcSurface, const PALETTEENTRY *pSrcPalette, const RECT *pSrcRect, DWORD Filter, D3DCOLOR ColorKey); 67 | HRESULT WINAPI D3DAssemble(const void *pSrcData, SIZE_T SrcDataSize, const char *pFileName, const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, UINT Flags, ID3DBlob **ppShader, ID3DBlob **ppErrorMsgs); 68 | HRESULT WINAPI D3DCompile(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs); 69 | HRESULT WINAPI D3DDisassemble(LPCVOID pSrcData, SIZE_T SrcDataSize, UINT Flags, LPCSTR szComments, ID3DBlob **ppDisassembly); 70 | -------------------------------------------------------------------------------- /Wrappers/d3d9/runtime_d3d9.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 Patrick Mours. All rights reserved. 3 | * License: https://github.com/crosire/reshade#license 4 | * 5 | * Copyright (C) 2024 Elisha Riedlinger 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 8 | * authors be held liable for any damages arising from the use of this software. 9 | * Permission is granted to anyone to use this software for any purpose, including commercial 10 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 13 | * original software. If you use this software in a product, an acknowledgment in the product 14 | * documentation would be appreciated but is not required. 15 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 16 | * being the original software. 17 | * 3. This notice may not be removed or altered from any source distribution. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "ReShade\Runtime\runtime.hpp" 23 | #include "state_block.hpp" 24 | #include "buffer_detection.hpp" 25 | 26 | namespace reshade::d3d9 27 | { 28 | class runtime_d3d9 : public runtime 29 | { 30 | public: 31 | runtime_d3d9(IDirect3DDevice9 *device, IDirect3DSwapChain9 *swapchain, buffer_detection *bdc); 32 | ~runtime_d3d9(); 33 | 34 | bool on_init(const D3DPRESENT_PARAMETERS &pp); 35 | void on_reset(); 36 | void on_present(); 37 | 38 | private: 39 | bool init_effect(size_t index) override; 40 | void unload_effect(size_t index) override; 41 | void unload_effects() override; 42 | 43 | bool init_texture(texture &texture) override; 44 | void upload_texture(const texture &texture, const uint8_t *pixels) override; 45 | void destroy_texture(texture &texture) override; 46 | 47 | void render_technique(technique &technique) override; 48 | 49 | state_block _app_state; 50 | com_ptr _d3d; 51 | const com_ptr _device; 52 | const com_ptr _swapchain; 53 | buffer_detection *const _buffer_detection; 54 | 55 | unsigned int _max_vertices = 0; 56 | unsigned int _num_samplers; 57 | unsigned int _num_simultaneous_rendertargets; 58 | unsigned int _behavior_flags; 59 | 60 | D3DFORMAT _backbuffer_format = D3DFMT_UNKNOWN; 61 | com_ptr _backbuffer; 62 | com_ptr _backbuffer_resolved; 63 | com_ptr _backbuffer_texture; 64 | com_ptr _backbuffer_texture_surface; 65 | 66 | HMODULE _d3d_compiler = nullptr; 67 | com_ptr _effect_stencil; 68 | com_ptr _effect_vertex_buffer; 69 | com_ptr _effect_vertex_layout; 70 | 71 | std::unordered_map> _compile_cache; 72 | 73 | void update_depth_texture_bindings(com_ptr surface); 74 | 75 | com_ptr _depth_texture; 76 | com_ptr _depth_surface; 77 | 78 | bool _disable_intz = false; 79 | bool _reset_buffer_detection = false; 80 | bool _filter_aspect_ratio = true; 81 | IDirect3DSurface9 *_depth_surface_override = nullptr; 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /Wrappers/d3d9/state_block.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 Patrick Mours. All rights reserved. 3 | * License: https://github.com/crosire/reshade#license 4 | * 5 | * Copyright (C) 2024 Elisha Riedlinger 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 8 | * authors be held liable for any damages arising from the use of this software. 9 | * Permission is granted to anyone to use this software for any purpose, including commercial 10 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 13 | * original software. If you use this software in a product, an acknowledgment in the product 14 | * documentation would be appreciated but is not required. 15 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 16 | * being the original software. 17 | * 3. This notice may not be removed or altered from any source distribution. 18 | */ 19 | 20 | #include "state_block.hpp" 21 | #include 22 | 23 | reshade::d3d9::state_block::state_block(IDirect3DDevice9 *device) 24 | { 25 | ZeroMemory(this, sizeof(*this)); 26 | 27 | _device = device; 28 | 29 | D3DCAPS9 caps; 30 | device->GetDeviceCaps(&caps); 31 | _num_simultaneous_rendertargets = std::min(caps.NumSimultaneousRTs, DWORD(8)); 32 | } 33 | reshade::d3d9::state_block::~state_block() 34 | { 35 | release_all_device_objects(); 36 | } 37 | 38 | void reshade::d3d9::state_block::capture() 39 | { 40 | _state_block->Capture(); 41 | 42 | _device->GetViewport(&_viewport); 43 | 44 | for (DWORD target = 0; target < _num_simultaneous_rendertargets; target++) 45 | _device->GetRenderTarget(target, &_render_targets[target]); 46 | _device->GetDepthStencilSurface(&_depth_stencil); 47 | } 48 | void reshade::d3d9::state_block::apply_and_release() 49 | { 50 | _state_block->Apply(); 51 | 52 | for (DWORD target = 0; target < _num_simultaneous_rendertargets; target++) 53 | _device->SetRenderTarget(target, _render_targets[target].get()); 54 | _device->SetDepthStencilSurface(_depth_stencil.get()); 55 | 56 | // Set viewport after render targets have been set, since 'SetRenderTarget' causes the viewport to be set to the full size of the render target 57 | _device->SetViewport(&_viewport); 58 | 59 | release_all_device_objects(); 60 | } 61 | 62 | bool reshade::d3d9::state_block::init_state_block() 63 | { 64 | return SUCCEEDED(_device->CreateStateBlock(D3DSBT_ALL, &_state_block)); 65 | } 66 | void reshade::d3d9::state_block::release_state_block() 67 | { 68 | _state_block.reset(); 69 | } 70 | void reshade::d3d9::state_block::release_all_device_objects() 71 | { 72 | _depth_stencil.reset(); 73 | for (auto &render_target : _render_targets) 74 | render_target.reset(); 75 | } 76 | -------------------------------------------------------------------------------- /Wrappers/d3d9/state_block.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 Patrick Mours. All rights reserved. 3 | * License: https://github.com/crosire/reshade#license 4 | * 5 | * Copyright (C) 2024 Elisha Riedlinger 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 8 | * authors be held liable for any damages arising from the use of this software. 9 | * Permission is granted to anyone to use this software for any purpose, including commercial 10 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 13 | * original software. If you use this software in a product, an acknowledgment in the product 14 | * documentation would be appreciated but is not required. 15 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 16 | * being the original software. 17 | * 3. This notice may not be removed or altered from any source distribution. 18 | */ 19 | 20 | #pragma once 21 | 22 | #define NOMINMAX 23 | #define WIN32_LEAN_AND_MEAN 24 | #include 25 | #include "com_ptr.hpp" 26 | 27 | namespace reshade::d3d9 28 | { 29 | class state_block 30 | { 31 | public: 32 | explicit state_block(IDirect3DDevice9 *device); 33 | ~state_block(); 34 | 35 | bool init_state_block(); 36 | void release_state_block(); 37 | 38 | void capture(); 39 | void apply_and_release(); 40 | 41 | private: 42 | void release_all_device_objects(); 43 | 44 | com_ptr _device; 45 | com_ptr _state_block; 46 | UINT _num_simultaneous_rendertargets; 47 | D3DVIEWPORT9 _viewport; 48 | com_ptr _depth_stencil; 49 | com_ptr _render_targets[8]; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /Wrappers/dinput8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define VISIT_PROCS_DINPUT8(visit) \ 4 | visit(DirectInput8Create, jmpaddr) 5 | 6 | #ifdef PROC_CLASS 7 | PROC_CLASS(dinput8, dll, VISIT_PROCS_DINPUT8) 8 | #endif 9 | -------------------------------------------------------------------------------- /Wrappers/dinput8/AddressLookupTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | constexpr UINT MaxDIIndex = 4; 7 | 8 | template 9 | class AddressLookupTableDinput8 10 | { 11 | public: 12 | explicit AddressLookupTableDinput8() {} 13 | ~AddressLookupTableDinput8() 14 | { 15 | ConstructorFlag = true; 16 | 17 | for (const auto& cache : g_map) 18 | { 19 | for (const auto& entry : cache) 20 | { 21 | entry.second->DeleteMe(); 22 | } 23 | } 24 | } 25 | 26 | template 27 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 0; }; 28 | template <> 29 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 1; }; 30 | template <> 31 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 2; }; 32 | template <> 33 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 3; }; 34 | 35 | template 36 | T *FindAddress(void *Proxy) 37 | { 38 | if (!Proxy) 39 | { 40 | return nullptr; 41 | } 42 | 43 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 44 | auto it = g_map[CacheIndex].find(Proxy); 45 | 46 | if (it != std::end(g_map[CacheIndex])) 47 | { 48 | return static_cast(it->second); 49 | } 50 | 51 | return new T(static_cast(Proxy)); 52 | } 53 | 54 | template 55 | void SaveAddress(T *Wrapper, void *Proxy) 56 | { 57 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 58 | if (Wrapper && Proxy) 59 | { 60 | g_map[CacheIndex][Proxy] = Wrapper; 61 | } 62 | } 63 | 64 | template 65 | void DeleteAddress(T *Wrapper) 66 | { 67 | if (!Wrapper || ConstructorFlag) 68 | { 69 | return; 70 | } 71 | 72 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 73 | auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), 74 | [=](auto Map) -> bool { return Map.second == Wrapper; }); 75 | 76 | if (it != std::end(g_map[CacheIndex])) 77 | { 78 | it = g_map[CacheIndex].erase(it); 79 | } 80 | } 81 | 82 | private: 83 | bool ConstructorFlag = false; 84 | D *unused = nullptr; 85 | std::unordered_map g_map[MaxDIIndex]; 86 | }; 87 | 88 | class AddressLookupTableDinput8Object 89 | { 90 | public: 91 | virtual ~AddressLookupTableDinput8Object() { } 92 | 93 | void DeleteMe() 94 | { 95 | delete this; 96 | } 97 | }; 98 | -------------------------------------------------------------------------------- /Wrappers/dinput8/IDirectInput8A.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInput8A : public IDirectInput8A, public AddressLookupTableDinput8Object 4 | { 5 | private: 6 | IDirectInput8A *ProxyInterface; 7 | 8 | public: 9 | m_IDirectInput8A(IDirectInput8A *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 12 | 13 | ProxyAddressLookupTableDinput8.SaveAddress(this, ProxyInterface); 14 | } 15 | ~m_IDirectInput8A() 16 | { 17 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 18 | 19 | ProxyAddressLookupTableDinput8.DeleteAddress(this); 20 | } 21 | 22 | /*** IUnknown methods ***/ 23 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 24 | STDMETHOD_(ULONG, AddRef)(THIS); 25 | STDMETHOD_(ULONG, Release)(THIS); 26 | 27 | /*** IDirectInput8A methods ***/ 28 | STDMETHOD(CreateDevice)(THIS_ REFGUID, LPDIRECTINPUTDEVICE8A *, LPUNKNOWN); 29 | STDMETHOD(EnumDevices)(THIS_ DWORD, LPDIENUMDEVICESCALLBACKA, LPVOID, DWORD); 30 | STDMETHOD(GetDeviceStatus)(THIS_ REFGUID); 31 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 32 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD); 33 | STDMETHOD(FindDevice)(THIS_ REFGUID, LPCSTR, LPGUID); 34 | STDMETHOD(EnumDevicesBySemantics)(THIS_ LPCSTR, LPDIACTIONFORMATA, LPDIENUMDEVICESBYSEMANTICSCBA, LPVOID, DWORD); 35 | STDMETHOD(ConfigureDevices)(THIS_ LPDICONFIGUREDEVICESCALLBACK, LPDICONFIGUREDEVICESPARAMSA, DWORD, LPVOID); 36 | }; 37 | -------------------------------------------------------------------------------- /Wrappers/dinput8/IDirectInputDevice8A.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Patches\InputTweaks.h" 4 | 5 | class m_IDirectInputDevice8A : public IDirectInputDevice8A, public AddressLookupTableDinput8Object 6 | { 7 | private: 8 | IDirectInputDevice8A *ProxyInterface; 9 | 10 | public: 11 | m_IDirectInputDevice8A(IDirectInputDevice8A *aOriginal) : ProxyInterface(aOriginal) 12 | { 13 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 14 | 15 | ProxyAddressLookupTableDinput8.SaveAddress(this, ProxyInterface); 16 | } 17 | ~m_IDirectInputDevice8A() 18 | { 19 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 20 | 21 | ProxyAddressLookupTableDinput8.DeleteAddress(this); 22 | } 23 | 24 | /*** IUnknown methods ***/ 25 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 26 | STDMETHOD_(ULONG, AddRef)(THIS); 27 | STDMETHOD_(ULONG, Release)(THIS); 28 | 29 | /*** IDirectInputDevice8A methods ***/ 30 | STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS); 31 | STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA, LPVOID, DWORD); 32 | STDMETHOD(GetProperty)(THIS_ REFGUID, LPDIPROPHEADER); 33 | STDMETHOD(SetProperty)(THIS_ REFGUID, LPCDIPROPHEADER); 34 | STDMETHOD(Acquire)(THIS); 35 | STDMETHOD(Unacquire)(THIS); 36 | STDMETHOD(GetDeviceState)(THIS_ DWORD, LPVOID); 37 | STDMETHOD(GetDeviceData)(THIS_ DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD); 38 | STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT); 39 | STDMETHOD(SetEventNotification)(THIS_ HANDLE); 40 | STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD); 41 | STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA, DWORD, DWORD); 42 | STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA); 43 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 44 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD, REFGUID); 45 | STDMETHOD(CreateEffect)(THIS_ REFGUID, LPCDIEFFECT, LPDIRECTINPUTEFFECT *, LPUNKNOWN); 46 | STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA, LPVOID, DWORD); 47 | STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA, REFGUID); 48 | STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD); 49 | STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD); 50 | STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, LPVOID, DWORD); 51 | STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE); 52 | STDMETHOD(Poll)(THIS); 53 | STDMETHOD(SendDeviceData)(THIS_ DWORD, LPCDIDEVICEOBJECTDATA, LPDWORD, DWORD); 54 | STDMETHOD(EnumEffectsInFile)(THIS_ LPCSTR, LPDIENUMEFFECTSINFILECALLBACK, LPVOID, DWORD); 55 | STDMETHOD(WriteEffectToFile)(THIS_ LPCSTR, DWORD, LPDIFILEEFFECT, DWORD); 56 | STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATA, LPCSTR, DWORD); 57 | STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATA, LPCSTR, DWORD); 58 | STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERA); 59 | }; 60 | -------------------------------------------------------------------------------- /Wrappers/dinput8/IDirectInputEffect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInputEffect : public IDirectInputEffect, public AddressLookupTableDinput8Object 4 | { 5 | private: 6 | IDirectInputEffect *ProxyInterface; 7 | 8 | bool IsStatic = false; 9 | static constexpr WORD MaxVibrationIntensity = 65535; 10 | bool m_vibrating = false; 11 | 12 | public: 13 | m_IDirectInputEffect(IDirectInputEffect *aOriginal) : ProxyInterface(aOriginal) 14 | { 15 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 16 | 17 | if (!ProxyInterface) 18 | { 19 | IsStatic = true; 20 | } 21 | 22 | ProxyAddressLookupTableDinput8.SaveAddress(this, ProxyInterface); 23 | } 24 | ~m_IDirectInputEffect() 25 | { 26 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 27 | 28 | ProxyAddressLookupTableDinput8.DeleteAddress(this); 29 | } 30 | 31 | /*** IUnknown methods ***/ 32 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 33 | STDMETHOD_(ULONG, AddRef)(THIS); 34 | STDMETHOD_(ULONG, Release)(THIS); 35 | 36 | /*** IDirectInputEffect methods ***/ 37 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD, REFGUID); 38 | STDMETHOD(GetEffectGuid)(THIS_ LPGUID); 39 | STDMETHOD(GetParameters)(THIS_ LPDIEFFECT, DWORD); 40 | STDMETHOD(SetParameters)(THIS_ LPCDIEFFECT, DWORD); 41 | STDMETHOD(Start)(THIS_ DWORD, DWORD); 42 | STDMETHOD(Stop)(THIS); 43 | STDMETHOD(GetEffectStatus)(THIS_ LPDWORD); 44 | STDMETHOD(Download)(THIS); 45 | STDMETHOD(Unload)(THIS); 46 | STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE); 47 | 48 | void SetProxyInterface(IDirectInputEffect *NewInterface) { ProxyInterface = NewInterface; } 49 | }; 50 | -------------------------------------------------------------------------------- /Wrappers/dinput8/InterfaceQuery.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8wrapper.h" 18 | 19 | void genericQueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if (!ppvObj || !*ppvObj) 22 | { 23 | return; 24 | } 25 | 26 | #define QUERYINTERFACE(x) \ 27 | if (riid == IID_ ## x) \ 28 | { \ 29 | *ppvObj = ProxyAddressLookupTableDinput8.FindAddress(*ppvObj); \ 30 | } 31 | 32 | #define CREATEINTERFACE(x) \ 33 | if (riid == IID_ ## x) \ 34 | { \ 35 | *ppvObj = new m_ ## x((x*)*ppvObj); \ 36 | } 37 | 38 | QUERYINTERFACE(IDirectInput8A); 39 | QUERYINTERFACE(IDirectInputDevice8A); 40 | QUERYINTERFACE(IDirectInputEffect); 41 | } 42 | -------------------------------------------------------------------------------- /Wrappers/dinput8/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Wrappers/dinput8/dinput8wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INITGUID 4 | 5 | #define DIRECTINPUT_VERSION 0x0800 6 | #include 7 | 8 | class m_IDirectInput8A; 9 | class m_IDirectInputDevice8A; 10 | class m_IDirectInputEffect; 11 | 12 | #include "AddressLookupTable.h" 13 | #include "Common\Settings.h" 14 | #include "Logging\Logging.h" 15 | 16 | typedef HRESULT(WINAPI *DirectInput8CreateProc)(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN); 17 | 18 | void genericQueryInterface(REFIID CalledID, LPVOID * ppvObj); 19 | extern AddressLookupTableDinput8 ProxyAddressLookupTableDinput8; 20 | 21 | extern bool LostWindowFocus; 22 | extern HWND CooperativeLevelWindow; 23 | 24 | #include "IDirectInput8A.h" 25 | #include "IDirectInputDevice8A.h" 26 | #include "IDirectInputEffect.h" 27 | -------------------------------------------------------------------------------- /Wrappers/dsound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define VISIT_PROCS_DSOUND(visit) \ 4 | visit(DirectSoundCreate, jmpaddr) \ 5 | visit(DirectSoundEnumerateA, jmpaddr) \ 6 | visit(DirectSoundEnumerateW, jmpaddr) \ 7 | visit(DllCanUnloadNow, jmpaddr) \ 8 | visit(DllGetClassObject, jmpaddr) \ 9 | visit(DirectSoundCaptureCreate, jmpaddr) \ 10 | visit(DirectSoundCaptureEnumerateA, jmpaddr) \ 11 | visit(DirectSoundCaptureEnumerateW, jmpaddr) \ 12 | visit(GetDeviceID, jmpaddr) \ 13 | visit(DirectSoundFullDuplexCreate, jmpaddr) \ 14 | visit(DirectSoundCreate8, jmpaddr) \ 15 | visit(DirectSoundCaptureCreate8, jmpaddr) 16 | 17 | #ifdef PROC_CLASS 18 | PROC_CLASS(dsound, dll, VISIT_PROCS_DSOUND) 19 | #endif 20 | -------------------------------------------------------------------------------- /Wrappers/dsound/AddressLookupTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | constexpr UINT MaxDSIndex = 3; 7 | 8 | template 9 | class AddressLookupTableDsound 10 | { 11 | public: 12 | explicit AddressLookupTableDsound() {} 13 | ~AddressLookupTableDsound() 14 | { 15 | ConstructorFlag = true; 16 | 17 | for (const auto& cache : g_map) 18 | { 19 | for (const auto& entry : cache) 20 | { 21 | entry.second->DeleteMe(); 22 | } 23 | } 24 | } 25 | 26 | template 27 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 0; }; 28 | template <> 29 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 1; }; 30 | template <> 31 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 2; }; 32 | 33 | template 34 | T *FindAddress(void *Proxy) 35 | { 36 | if (!Proxy) 37 | { 38 | return nullptr; 39 | } 40 | 41 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 42 | auto it = g_map[CacheIndex].find(Proxy); 43 | 44 | if (it != std::end(g_map[CacheIndex])) 45 | { 46 | return static_cast(it->second); 47 | } 48 | 49 | return new T(static_cast(Proxy)); 50 | } 51 | 52 | template 53 | void SaveAddress(T *Wrapper, void *Proxy) 54 | { 55 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 56 | if (Wrapper && Proxy) 57 | { 58 | g_map[CacheIndex][Proxy] = Wrapper; 59 | } 60 | } 61 | 62 | template 63 | void DeleteAddress(T *Wrapper) 64 | { 65 | if (!Wrapper || ConstructorFlag) 66 | { 67 | return; 68 | } 69 | 70 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 71 | auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), 72 | [=](auto Map) -> bool { return Map.second == Wrapper; }); 73 | 74 | if (it != std::end(g_map[CacheIndex])) 75 | { 76 | it = g_map[CacheIndex].erase(it); 77 | } 78 | } 79 | 80 | private: 81 | bool ConstructorFlag = false; 82 | D *unused = nullptr; 83 | std::unordered_map g_map[MaxDSIndex]; 84 | }; 85 | 86 | class AddressLookupTableDsoundObject 87 | { 88 | public: 89 | virtual ~AddressLookupTableDsoundObject() { } 90 | 91 | void DeleteMe() 92 | { 93 | delete this; 94 | } 95 | }; 96 | -------------------------------------------------------------------------------- /Wrappers/dsound/IDirectSound8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectSound8 : public IDirectSound8, public AddressLookupTableDsoundObject 4 | { 5 | private: 6 | LPDIRECTSOUND8 ProxyInterface; 7 | 8 | // Helper functions 9 | void InitDevice(); 10 | void ReleaseDevice(); 11 | 12 | public: 13 | m_IDirectSound8(LPDIRECTSOUND8 pSound8) : ProxyInterface(pSound8) 14 | { 15 | Logging::LogDebug() << "Creating device " << __FUNCTION__ << "(" << this << ")"; 16 | 17 | InitDevice(); 18 | 19 | ProxyAddressLookupTableDsound.SaveAddress(this, ProxyInterface); 20 | } 21 | ~m_IDirectSound8() 22 | { 23 | Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; 24 | 25 | ReleaseDevice(); 26 | 27 | ProxyAddressLookupTableDsound.DeleteAddress(this); 28 | } 29 | 30 | LPDIRECTSOUND8 GetProxyInterface() { return ProxyInterface; } 31 | 32 | // IUnknown methods 33 | STDMETHOD(QueryInterface)(THIS_ _In_ REFIID, _Outptr_ LPVOID*); 34 | STDMETHOD_(ULONG, AddRef)(THIS); 35 | STDMETHOD_(ULONG, Release)(THIS); 36 | 37 | // IDirectSound methods 38 | STDMETHOD(CreateSoundBuffer)(THIS_ _In_ LPCDSBUFFERDESC pcDSBufferDesc, _Out_ LPDIRECTSOUNDBUFFER *ppDSBuffer, _Pre_null_ LPUNKNOWN pUnkOuter); 39 | STDMETHOD(GetCaps)(THIS_ _Out_ LPDSCAPS pDSCaps); 40 | STDMETHOD(DuplicateSoundBuffer)(THIS_ _In_ LPDIRECTSOUNDBUFFER pDSBufferOriginal, _Out_ LPDIRECTSOUNDBUFFER *ppDSBufferDuplicate); 41 | STDMETHOD(SetCooperativeLevel)(THIS_ HWND hwnd, DWORD dwLevel); 42 | STDMETHOD(Compact)(THIS); 43 | STDMETHOD(GetSpeakerConfig)(THIS_ _Out_ LPDWORD pdwSpeakerConfig); 44 | STDMETHOD(SetSpeakerConfig)(THIS_ DWORD dwSpeakerConfig); 45 | STDMETHOD(Initialize)(THIS_ _In_opt_ LPCGUID pcGuidDevice); 46 | 47 | // IDirectSound8 methods 48 | STDMETHOD(VerifyCertification)(THIS_ _Out_ LPDWORD pdwCertified); 49 | 50 | // Helper functions 51 | HRESULT CreateWAVSoundBuffer(const char* filePath, m_IDirectSoundBuffer8** ppDSBuffer); 52 | }; 53 | -------------------------------------------------------------------------------- /Wrappers/dsound/InterfaceQuery.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dsoundwrapper.h" 18 | 19 | void WINAPI genericQueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if (!ppvObj || !*ppvObj) 22 | { 23 | return; 24 | } 25 | 26 | #define QUERYINTERFACE(x) \ 27 | if (riid == IID_ ## x) \ 28 | { \ 29 | *ppvObj = ProxyAddressLookupTableDsound.FindAddress(*ppvObj); \ 30 | } 31 | 32 | #define QUERYINTERFACE8(x) \ 33 | if (riid == IID_ ## x || riid == IID_ ## x ## 8) \ 34 | { \ 35 | *ppvObj = ProxyAddressLookupTableDsound.FindAddress(*ppvObj); \ 36 | } 37 | 38 | QUERYINTERFACE8(IDirectSound); 39 | QUERYINTERFACE8(IDirectSoundBuffer); 40 | } 41 | -------------------------------------------------------------------------------- /Wrappers/dsound/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Wrappers/dsound/dsoundwrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | #include 7 | 8 | class m_IDirectSound8; 9 | class m_IDirectSoundBuffer8; 10 | 11 | #include "AddressLookupTable.h" 12 | #include "Common\Settings.h" 13 | #include "Logging\Logging.h" 14 | 15 | typedef HRESULT(WINAPI *DirectSoundCreate8Proc)(LPCGUID, LPDIRECTSOUND8*, LPUNKNOWN); 16 | extern "C" HRESULT WINAPI DSOAL_DirectSoundCreate8(LPCGUID lpcGUID, IDirectSound8 * *ppDS, IUnknown * pUnkOuter); 17 | 18 | void WINAPI genericQueryInterface(REFIID riid, LPVOID * ppvObj); 19 | 20 | // Volume array falloff 21 | constexpr LONG VolumeArray[] = { -10000, -2401, -1799, -1411, -1170, -961, -809, -665, -555, -445, -359, -270, -198, -124, -63, 0 }; 22 | 23 | extern std::vector BufferList; 24 | extern AddressLookupTableDsound ProxyAddressLookupTableDsound; 25 | 26 | #include "IDirectSound8.h" 27 | #include "IDirectSoundBuffer8.h" 28 | -------------------------------------------------------------------------------- /Wrappers/wrapper.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | 4 | 5 | ; **** 6 | ;LIBRARY "dsound" <--- Needs to have the correct ordinals since some programs use the ordinal numbers for dsound APIs 7 | ; **** 8 | DirectSoundCreate @1 9 | DirectSoundEnumerateA @2 10 | DirectSoundEnumerateW @3 11 | DllCanUnloadNow PRIVATE 12 | DllGetClassObject PRIVATE 13 | DirectSoundCaptureCreate @6 14 | DirectSoundCaptureEnumerateA @7 15 | DirectSoundCaptureEnumerateW @8 16 | GetDeviceID @9 17 | DirectSoundFullDuplexCreate @10 18 | DirectSoundCreate8 @11 19 | DirectSoundCaptureCreate8 @12 20 | 21 | 22 | ; **** 23 | ;LIBRARY "d3d8" 24 | ; **** 25 | ValidatePixelShader 26 | ValidateVertexShader 27 | Direct3DCreate8 28 | 29 | 30 | ; **** 31 | ;LIBRARY "dinput8" 32 | ; **** 33 | DirectInput8Create 34 | 35 | ; **** 36 | ;LIBRARY "SH2EE" 37 | ; **** 38 | VerifySH2EE 39 | -------------------------------------------------------------------------------- /Wrappers/wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum _DLLTYPE 4 | { 5 | DTYPE_ASI = 0, 6 | DTYPE_D3D8 = 1, 7 | DTYPE_DINPUT8 = 2, 8 | DTYPE_DSOUND = 3 9 | } DLLTYPE; 10 | 11 | // Designated Initializer does not work in VS 2015 so must pay attention to the order 12 | static constexpr wchar_t* dtypename[] = { 13 | L"sh2-enhce.asi", // 0 14 | L"d3d8.dll", // 1 15 | L"dinput8.dll", // 2 16 | L"dsound.dll", // 3 17 | }; 18 | static constexpr int dtypeArraySize = (sizeof(dtypename) / sizeof(*dtypename)); 19 | 20 | namespace Wrapper 21 | { 22 | extern DLLTYPE dtype; 23 | void GetWrapperMode(); 24 | HMODULE CreateWrapper(HMODULE hWrapper); 25 | } 26 | 27 | #define VISIT_DLLS(visit) \ 28 | visit(d3d8) \ 29 | visit(dinput8) \ 30 | visit(dsound) 31 | 32 | // Wrappers 33 | #include "d3d8.h" 34 | #include "dinput8.h" 35 | #include "dsound.h" 36 | 37 | typedef struct IUnknown *LPUNKNOWN; 38 | typedef struct IDirect3D8 *LPDIRECT3D8; 39 | typedef struct IDirectSound8 *LPDIRECTSOUND8; 40 | 41 | HMODULE GetD3d8ScriptDll(); 42 | void HookDirect3DCreate8(HMODULE ScriptDll); 43 | void HookDirectInput8Create(); 44 | void HookDirectSoundCreate8(); 45 | IDirect3D8 *WINAPI Direct3DCreate8Wrapper(UINT SDKVersion); 46 | HRESULT WINAPI DirectInput8CreateWrapper(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, LPUNKNOWN punkOuter); 47 | HRESULT WINAPI DirectSoundCreate8Wrapper(LPCGUID pcGuidDevice, LPDIRECTSOUND8 *ppDS8, LPUNKNOWN pUnkOuter); 48 | 49 | #define DECLARE_FORWARD_FUNCTIONS(procName, unused) \ 50 | extern "C" void __stdcall procName(); 51 | 52 | #define DECLARE_PROC_VARIABLES(procName, unused) \ 53 | extern FARPROC procName ## _var; 54 | 55 | namespace d3d8 56 | { 57 | VISIT_PROCS_D3D8(DECLARE_PROC_VARIABLES); 58 | } 59 | -------------------------------------------------------------------------------- /d3dx/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /d3dx/dllmain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2024 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | 20 | typedef void (WINAPI* DelayedStartProc)(); 21 | 22 | BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) 23 | { 24 | static HMODULE d3d8_dll = nullptr; 25 | 26 | switch (dwReason) 27 | { 28 | case DLL_PROCESS_ATTACH: 29 | { 30 | // Get process path 31 | wchar_t Path[MAX_PATH] = {}; 32 | DWORD ret = GetModuleFileName(hModule, Path, MAX_PATH); 33 | 34 | // Get d3d8 local path 35 | wchar_t* pdest = wcsrchr(Path, '\\'); 36 | if (ret && pdest) 37 | { 38 | *pdest = '\0'; 39 | } 40 | wcscat_s(Path, MAX_PATH, L"\\d3d8.dll"); 41 | 42 | // Load d3d8 module locally if not already loaded 43 | if (!GetModuleHandle(Path)) 44 | { 45 | d3d8_dll = LoadLibrary(Path); 46 | } 47 | break; 48 | } 49 | case DLL_PROCESS_DETACH: 50 | if (d3d8_dll) 51 | { 52 | FreeLibrary(d3d8_dll); 53 | } 54 | break; 55 | } 56 | 57 | return TRUE; 58 | } 59 | --------------------------------------------------------------------------------