├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── GliFixVf ├── GliFixVf.c ├── GliFixVf.h ├── GliFixVf.vcxproj ├── GliFixVf.vcxproj.filters ├── config.c ├── config.h ├── defs.h ├── devinfo.c ├── devinfo.h ├── dllmain.c ├── fix.c ├── fix.h ├── framework.h ├── glide2types.h ├── imports.c ├── imports.h ├── patch.asm ├── r2fn.c └── r2fn.h ├── LICENSE ├── R2FixCfg ├── R2FixCfg.vcxproj ├── R2FixCfg.vcxproj.filters ├── Rayman2D.ico ├── Resource.rc ├── config.c ├── config.h ├── def_analog.h ├── def_button.h ├── def_pad.h ├── dialogs.h ├── display.c ├── display.h ├── framework.h ├── generaldlg.c ├── glidetect.ico ├── main.c ├── main.h ├── pad.c ├── pad.h ├── paddlg.c └── resource.h ├── README.md ├── Ray2Fix.sln ├── generate_gitver.cmd ├── inc ├── detours.h └── detver.h ├── lib └── detours.lib └── third-party-licenses.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build-master 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | workflow_dispatch: 9 | 10 | env: 11 | SOLUTION_PATH: . 12 | CONFIGURATION: Release 13 | PLATFORM: x86 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | build: 20 | runs-on: windows-latest 21 | 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v4 25 | with: 26 | fetch-depth: 0 27 | 28 | - name: Add MSBuild to PATH 29 | uses: microsoft/setup-msbuild@v2 30 | 31 | - name: Set up environment 32 | run: | 33 | mkdir .\acp 34 | echo "acplib=$(Resolve-Path .\acp)" >> $env:GITHUB_ENV 35 | 36 | - name: Get latest ACP_Ray2 artifact 37 | uses: dawidd6/action-download-artifact@v6 38 | with: 39 | repo: raytools/ACP_Ray2 40 | workflow: build.yml 41 | name: ACP_Ray2-master 42 | path: acp/ 43 | 44 | - name: Build 45 | working-directory: ${{env.GITHUB_WORKSPACE}} 46 | # Add additional options to the MSBuild command line here (like platform or verbosity level). 47 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference 48 | run: msbuild /m /p:Configuration=${{env.CONFIGURATION}} /p:Platform=${{env.PLATFORM}} ${{env.SOLUTION_PATH}} 49 | 50 | - name: Upload 51 | uses: actions/upload-artifact@v4 52 | with: 53 | name: Ray2Fix-master 54 | path: Release/ 55 | if-no-files-found: error 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb 341 | 342 | # SPT - vim swap files 343 | *.swp 344 | # SPT - this is generated by a script 345 | /gitver.h 346 | -------------------------------------------------------------------------------- /GliFixVf/GliFixVf.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "GliFixVf.h" 3 | #include "config.h" 4 | #include "devinfo.h" 5 | #include "imports.h" 6 | #include "glide2types.h" 7 | 8 | #include 9 | 10 | 11 | tdstGliCaps *g_p_stCaps = NULL; 12 | 13 | int (*GLI_MDRV_lAddDisplayMode)( BOOL bFullscreen, int x, int y, int lBitDepth ) = NULL; 14 | int (*GLI_MDRV_lComputeWaitFrameForSmoothSynchro)( int ) = NULL; 15 | int (*GLI_MDRV_xIsGliInit)( void ) = NULL; 16 | void (*GLI_MDRV_vSerialProjection)( GLI_tdstCamera *p_stCam, long lNbOfVertex, GLI_tdstAligned3DVector *p_stSource, GLI_tdstAligned2DVector *p_stDest ) = NULL; 17 | 18 | 19 | GrVertex CurrentDestXYZ[4]; 20 | 21 | #define GLI_C_3dfxBugConstant 65536.0f * 8.0f 22 | 23 | #define GLI_M_Correct3DFXBug2( a ) \ 24 | { \ 25 | a.x -= GLI_C_3dfxBugConstant; \ 26 | a.y -= GLI_C_3dfxBugConstant; \ 27 | } 28 | 29 | void GLI_fn_vCorrect3DFXBug1( GrVertex *a ) 30 | { 31 | a->x += GLI_C_3dfxBugConstant; 32 | a->y += GLI_C_3dfxBugConstant; 33 | } 34 | 35 | #define GLI_M_Restore3DFXColor( P, ulColor ) \ 36 | { \ 37 | P.b = (float) ((ulColor) & 0xFF); \ 38 | P.g = (float) (((ulColor) >> 8) & 0xFF); \ 39 | P.r = (float) (((ulColor) >> 16) & 0xFF); \ 40 | P.a = (float) (((ulColor) >> 24) & 0xFF); \ 41 | P.tmuvtx[*Vd_GLI_GLIDE1_xTmuNumber].sow *= P.oow * p_stGlobaleMT->fMulV; \ 42 | P.tmuvtx[*Vd_GLI_GLIDE1_xTmuNumber].tow *= P.oow * p_stGlobaleMT->fMulU; \ 43 | } 44 | 45 | 46 | #define M_CopyString(dst, src) strcpy_s(dst, strlen(src)+1, src) 47 | 48 | /* copies renderer info (first listbox in GxSetup) to specified memory address */ 49 | long GLI_DRV_lGetDllInfo( char const *szName, void *pData ) 50 | { 51 | if ( !strcmp(szName, "Name") ) 52 | M_CopyString(pData, GLI_szName); 53 | else if ( !strcmp(szName, "Description") ) 54 | M_CopyString(pData, GLI_szDesc); 55 | else if ( !strcmp(szName, "Version") ) 56 | M_CopyString(pData, GLI_szVersion); 57 | else if ( !strcmp(szName, "Code") ) 58 | *(DWORD *)pData = GLI_lCode; 59 | else 60 | return 0; 61 | 62 | return 1; 63 | } 64 | 65 | long GLI_DRV_lSetCommonData( char const *szName, void *pData ) 66 | { 67 | if ( !strcmp(szName, "GliCaps") ) 68 | g_p_stCaps = pData; 69 | 70 | return Vd_GLI_DRV_lSetCommonData(szName, pData); 71 | } 72 | 73 | long GLI_DRV_lSetCommonFct( char const *szName, tdfn_CommonFct pData ) 74 | { 75 | if ( !strcmp(szName, "AddDisplayMode") ) /* for GLI_DRV_fnl_EnumModes */ 76 | GLI_MDRV_lAddDisplayMode = pData; 77 | else if ( !strcmp(szName, "IsGliInit") ) /* for GLI_DRV_vFlipDeviceWithSyncro */ 78 | GLI_MDRV_xIsGliInit = pData; 79 | else if ( !strcmp(szName, "ComputeWaitFrameForSmoothSynchro") ) 80 | GLI_MDRV_lComputeWaitFrameForSmoothSynchro = pData; 81 | else if ( !strcmp(szName, "SerialProjection") ) /* for GLI_DRV_vSendSingleLineToClip */ 82 | GLI_MDRV_vSerialProjection = pData; 83 | 84 | return Vd_GLI_DRV_lSetCommonFct(szName, pData); 85 | } 86 | 87 | /* sets capability flags and populates displays, devices and resolutions */ 88 | long GLI_DRV_fn_lGetAllDisplayConfig( tdfn_lAddDisplayInfo p_fn_lAddDisplayInfo ) 89 | { 90 | long lDisp, lDev, lMode; 91 | tdstGliCaps stCaps = { 0 }; 92 | 93 | p_fn_lAddDisplayInfo(0, 0, 0, C_DI_DllBmp, 0); 94 | 95 | /* display info */ 96 | lDisp = p_fn_lAddDisplayInfo(0, 0, 0, C_DI_DisplayAdd, 0); 97 | p_fn_lAddDisplayInfo(lDisp, 0, 0, C_DI_DisplayName, (long)"Default"); 98 | p_fn_lAddDisplayInfo(lDisp, 0, 0, C_DI_DisplayDesc, (long)"Default"); 99 | 100 | /* device info */ 101 | lDev = p_fn_lAddDisplayInfo(lDisp, 0, 0, C_DI_DeviceAdd, 0); 102 | p_fn_lAddDisplayInfo(lDisp, lDev, 0, C_DI_DeviceName, (long)"Default"); 103 | p_fn_lAddDisplayInfo(lDisp, lDev, 0, C_DI_DeviceDesc, (long)"Default"); 104 | 105 | /* display mode (resolution) */ 106 | lMode = p_fn_lAddDisplayInfo(lDisp, lDev, 0, C_DI_ModeAdd, 0); 107 | p_fn_lAddDisplayInfo(lDisp, lDev, lMode, C_DI_ModeFullscreen, 1); 108 | p_fn_lAddDisplayInfo(lDisp, lDev, lMode, C_DI_ModeBpp, 16); 109 | p_fn_lAddDisplayInfo(lDisp, lDev, lMode, C_DI_ModeWidth, CFG_stDispMode.dwWidth); 110 | p_fn_lAddDisplayInfo(lDisp, lDev, lMode, C_DI_ModeHeight, CFG_stDispMode.dwHeight); 111 | 112 | p_fn_lAddDisplayInfo(lDisp, lDev, 0, C_DI_DevCaps, (long)&stCaps); 113 | 114 | 115 | /* If fix is enabled, always open R2FixCfg, 116 | if fix is disabled, ask first */ 117 | if ( !CFG_bIsFixEnabled ) 118 | { 119 | int lResult = MessageBox( 120 | NULL, "Ray2Fix is installed but not enabled.\nDo you want to open Ray2Fix Settings?", 121 | GLI_szName, MB_YESNO | MB_ICONASTERISK); 122 | 123 | if ( lResult != IDYES ) 124 | return TRUE; 125 | } 126 | 127 | if ( CFG_fn_bOpenConfigTool() ) 128 | ExitProcess(0); 129 | 130 | MessageBox(NULL, "Cannot open Ray2Fix Settings, please update or reinstall Ray2Fix.", 131 | GLI_szName, MB_OK | MB_ICONERROR); 132 | 133 | return TRUE; 134 | } 135 | 136 | long GLI_DRV_fnl_EnumModes( char *szDriverName, char *szDeviceName ) 137 | { 138 | GLI_MDRV_lAddDisplayMode(TRUE, CFG_stDispMode.dwWidth, CFG_stDispMode.dwHeight, 16); 139 | 140 | return TRUE; 141 | } 142 | 143 | void GLI_DRV_xInitDriver( HWND hWnd, BOOL bFullscreen, long lWidth, long lHeight, int lBpp ) 144 | { 145 | Vd_GLI_DRV_xInitDriver(hWnd, bFullscreen, lWidth, lHeight, lBpp); 146 | 147 | /* HACK: make sure the window has a title bar and a border 148 | Sometimes the game and/or dgVoodoo bugs out for no reason and displays the game 149 | without a title bar, making it impossible to move or resize the game window. */ 150 | int lStyle = GetWindowLong(hWnd, GWL_STYLE); 151 | SetWindowLong(hWnd, GWL_STYLE, lStyle | WS_OVERLAPPEDWINDOW); 152 | 153 | char szTitle[64]; 154 | sprintf_s(szTitle, sizeof(szTitle), "Rayman II [%s %s]", GLI_szName, GLI_szVersion); 155 | SetWindowText(hWnd, szTitle); 156 | 157 | /* HACK: Refresh rate fix for >60Hz monitors */ 158 | g_p_stCaps->xRefreshRate = CFG_bHalfRefRate ? 30.0f : 60.0f; 159 | } 160 | 161 | void GLI_DRV_vFlipDeviceWithSyncro( void ) 162 | { 163 | if ( !GLI_MDRV_xIsGliInit() ) 164 | return; 165 | 166 | int lWaitFrame = ( CFG_DEBUG_lWaitFrame > 0 ) 167 | ? CFG_DEBUG_lWaitFrame 168 | : GLI_MDRV_lComputeWaitFrameForSmoothSynchro(0); 169 | GLI_DRV_vFlipDevice(lWaitFrame); 170 | } 171 | 172 | void GLI_DRV_vSendSingleLineToClip( 173 | GLD_tdstViewportAttributes *p_stVpt, 174 | GLI_tdstAligned3DVector *p_stVertex1, 175 | GLI_tdstAligned2DVector *p_st2DVertex1, 176 | GLI_tdstAligned3DVector *p_stVertex2, 177 | GLI_tdstAligned2DVector *p_st2DVertex2, 178 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT, 179 | long lDrawModeMask, 180 | GEO_tdstColor *p_stColor 181 | ) 182 | { 183 | if ( IMP_cWhatBuildWeUsing != 'f' ) /* not final, ignore */ 184 | { 185 | Vd_GLI_DRV_vSendSingleLineToClip(p_stVpt, p_stVertex1, p_st2DVertex1, p_stVertex2, p_st2DVertex2, p_stGlobaleMT, lDrawModeMask, p_stColor); 186 | return; 187 | } 188 | 189 | /* final has an annoying bug that has to be fixed... (for mod support) */ 190 | 191 | GLI_tdstAligned2DVector stP1, stP2; 192 | GLI_tdstAligned3DVector st3DP1, st3DP2; 193 | float fFactor; 194 | 195 | grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_ITERATED, FXFALSE); 196 | grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ONE, GR_BLEND_ZERO); 197 | guColorCombineFunction(GR_COLORCOMBINE_ITRGB); 198 | 199 | /* Z clipping */ 200 | if ( p_st2DVertex1->xOoZ < p_st2DVertex2->xOoZ ) 201 | { 202 | stP1 = *p_st2DVertex1; 203 | st3DP1 = *p_stVertex1; 204 | stP2 = *p_st2DVertex2; 205 | st3DP2 = *p_stVertex2; 206 | } 207 | else 208 | { 209 | stP2 = *p_st2DVertex1; 210 | st3DP2 = *p_stVertex1; 211 | stP1 = *p_st2DVertex2; 212 | st3DP1 = *p_stVertex2; 213 | } 214 | 215 | if ( (*(unsigned long *)&stP2.xOoZ & 0x80000000) ) 216 | return; 217 | 218 | if ( (*(unsigned long *)&stP1.xOoZ & 0x80000000) ) 219 | { 220 | fFactor = (p_stGlobaleMT->p_stCurrentCamera->xNear - st3DP2.xZ) / (st3DP1.xZ - st3DP2.xZ); 221 | st3DP1.xX = st3DP2.xX + (st3DP1.xX - st3DP2.xX) * fFactor; 222 | st3DP1.xY = st3DP2.xY + (st3DP1.xY - st3DP2.xY) * fFactor; 223 | st3DP1.xZ = p_stGlobaleMT->fZClipping; 224 | GLI_MDRV_vSerialProjection(p_stGlobaleMT->p_stCurrentCamera, 1, &st3DP1, &stP1); 225 | } 226 | 227 | /* X clipping */ 228 | if ( stP1.xX < stP2.xX ) 229 | { 230 | p_st2DVertex1 = &stP1; 231 | p_stVertex1 = &st3DP1; 232 | p_st2DVertex2 = &stP2; 233 | p_stVertex2 = &st3DP2; 234 | } 235 | else 236 | { 237 | p_st2DVertex1 = &stP2; 238 | p_stVertex1 = &st3DP2; 239 | p_st2DVertex2 = &stP1; 240 | p_stVertex2 = &st3DP1; 241 | } 242 | 243 | if ( (p_st2DVertex2->xX < p_stGlobaleMT->fXMinClipping) || (p_st2DVertex1->xX > p_stGlobaleMT->fXMaxClipping) ) 244 | return; 245 | 246 | if ( p_st2DVertex1->xX < p_stGlobaleMT->fXMinClipping ) 247 | { 248 | fFactor = (p_st2DVertex2->xX - p_stGlobaleMT->fXMinClipping) / (p_st2DVertex2->xX - p_st2DVertex1->xX); 249 | p_st2DVertex1->xY = p_st2DVertex2->xY - (p_st2DVertex2->xY - p_st2DVertex1->xY) * fFactor; 250 | p_stVertex1->xZ = p_stVertex2->xZ - (p_stVertex2->xY - p_stVertex1->xY) * fFactor; 251 | p_st2DVertex1->xX = p_stGlobaleMT->fXMinClipping; 252 | } 253 | 254 | if ( p_st2DVertex2->xX > p_stGlobaleMT->fXMaxClipping ) 255 | { 256 | fFactor = (p_st2DVertex1->xX - p_stGlobaleMT->fXMaxClipping) / (p_st2DVertex2->xX - p_st2DVertex1->xX); 257 | p_st2DVertex2->xY = p_st2DVertex1->xY - (p_st2DVertex2->xY - p_st2DVertex1->xY) * fFactor; 258 | p_stVertex2->xZ = p_stVertex1->xZ - (p_stVertex2->xY - p_stVertex1->xY) * fFactor; 259 | p_st2DVertex2->xX = p_stGlobaleMT->fXMaxClipping; 260 | } 261 | 262 | /* Y clipping */ 263 | if ( stP1.xY < stP2.xY ) 264 | { 265 | p_st2DVertex1 = &stP1; 266 | p_stVertex1 = &st3DP1; 267 | p_st2DVertex2 = &stP2; 268 | p_stVertex2 = &st3DP2; 269 | } 270 | else 271 | { 272 | p_st2DVertex1 = &stP2; 273 | p_stVertex1 = &st3DP2; 274 | p_st2DVertex2 = &stP1; 275 | p_stVertex2 = &st3DP1; 276 | } 277 | 278 | if ( (p_st2DVertex2->xY < p_stGlobaleMT->fYMinClipping) || (p_st2DVertex1->xY > p_stGlobaleMT->fYMaxClipping) ) 279 | return; 280 | 281 | if ( p_st2DVertex1->xY < p_stGlobaleMT->fYMinClipping ) 282 | { 283 | fFactor = (p_st2DVertex2->xY - p_stGlobaleMT->fYMinClipping) / (p_st2DVertex2->xY - p_st2DVertex1->xY); 284 | p_st2DVertex1->xX = p_st2DVertex2->xX - (p_st2DVertex2->xX - p_st2DVertex1->xX) * fFactor; 285 | p_stVertex1->xZ = p_stVertex2->xZ - (p_stVertex2->xZ - p_stVertex1->xZ) * fFactor; 286 | p_st2DVertex1->xY = p_stGlobaleMT->fYMinClipping; 287 | } 288 | 289 | if ( p_st2DVertex2->xY > p_stGlobaleMT->fYMaxClipping ) 290 | { 291 | fFactor = (p_st2DVertex1->xY - p_stGlobaleMT->fYMaxClipping) / (p_st2DVertex2->xY - p_st2DVertex1->xY); 292 | p_st2DVertex2->xX = p_st2DVertex1->xX - (p_st2DVertex2->xX - p_st2DVertex1->xX) * fFactor; 293 | p_stVertex2->xZ = p_stVertex1->xZ - (p_stVertex2->xZ - p_stVertex1->xZ) * fFactor; 294 | p_st2DVertex2->xY = p_stGlobaleMT->fYMaxClipping; 295 | } 296 | 297 | /* GLI_M_InitLine */ 298 | CurrentDestXYZ[0].x = p_st2DVertex1->xX; 299 | CurrentDestXYZ[0].y = p_st2DVertex1->xY; 300 | CurrentDestXYZ[1].x = p_st2DVertex2->xX; 301 | CurrentDestXYZ[1].y = p_st2DVertex2->xY; 302 | CurrentDestXYZ[0].oow = p_stVertex1->xZ; 303 | CurrentDestXYZ[1].oow = p_stVertex2->xZ; 304 | //*(unsigned long *)&CurrentDestXYZ[0].r = p_st2DVertex1->ulPackedColor; 305 | //*(unsigned long *)&CurrentDestXYZ[1].r = p_st2DVertex2->ulPackedColor; 306 | 307 | /* GLI_DrawLine */ 308 | GLI_fn_vCorrect3DFXBug1(&CurrentDestXYZ[0]); 309 | GLI_fn_vCorrect3DFXBug1(&CurrentDestXYZ[1]); 310 | GLI_M_Correct3DFXBug2(CurrentDestXYZ[0]); 311 | GLI_M_Correct3DFXBug2(CurrentDestXYZ[1]); 312 | GLI_M_Restore3DFXColor(CurrentDestXYZ[0], p_st2DVertex1->ulPackedColor); 313 | GLI_M_Restore3DFXColor(CurrentDestXYZ[1], p_st2DVertex2->ulPackedColor); 314 | 315 | grDrawLine(&CurrentDestXYZ[0], &CurrentDestXYZ[1]); 316 | } 317 | 318 | 319 | /* 320 | * Redirected exports 321 | */ 322 | 323 | 324 | /**** INIT ****/ 325 | 326 | NAKED void GLI_DRV_vFlipDevice( int lWaitFrames ) 327 | { 328 | JMP(Vd_GLI_DRV_vFlipDevice); 329 | } 330 | 331 | NAKED void GLI_DRV_vClearDevice( BOOL bZBuffer, BOOL bColorBuffer, unsigned long ulColor ) 332 | { 333 | JMP(Vd_GLI_DRV_vClearDevice); 334 | } 335 | 336 | /* 337 | NAKED void GLI_DRV_vFlipDeviceWithSyncro( void ) 338 | { 339 | JMP(Vd_GLI_DRV_vFlipDeviceWithSyncro); 340 | } 341 | */ 342 | 343 | NAKED void GLI_DRV_vCloseDriver( void ) 344 | { 345 | JMP(Vd_GLI_DRV_vCloseDriver); 346 | } 347 | 348 | NAKED void GLI_DRV_vClearZBufferRegion( long lXStart, long lXEnd, long lYStart, long lYEnd ) 349 | { 350 | JMP(Vd_GLI_DRV_vClearZBufferRegion); 351 | } 352 | 353 | NAKED long GLI_DRV_hChangeMode( BOOL bFullscreen, long lWidth, long lHeight, long lBpp ) 354 | { 355 | JMP(Vd_GLI_DRV_hChangeMode); 356 | } 357 | 358 | NAKED BOOL GLI_DRV_bLockDevice( void **pp_vVirtualScreen, long *p_lPitch ) 359 | { 360 | JMP(Vd_GLI_DRV_bLockDevice); 361 | } 362 | 363 | NAKED BOOL GLI_DRV_bUnlockDevice( void ) 364 | { 365 | JMP(Vd_GLI_DRV_bUnlockDevice); 366 | } 367 | 368 | NAKED BOOL GLI_DRV_bWindowedModeIsOptimized( void ) 369 | { 370 | JMP(Vd_GLI_DRV_bWindowedModeIsOptimized); 371 | } 372 | 373 | NAKED void GLI_DRV_vOptimizedWindowedMode( void ) 374 | { 375 | JMP(Vd_GLI_DRV_vOptimizedWindowedMode); 376 | } 377 | 378 | NAKED void GLI_DRV_vNonOptimizedWindowedMode( void ) 379 | { 380 | JMP(Vd_GLI_DRV_vNonOptimizedWindowedMode); 381 | } 382 | 383 | NAKED BOOL GLI_DRV_bPrepareForGliWindowed( HWND hWnd ) 384 | { 385 | JMP(Vd_GLI_DRV_bPrepareForGliWindowed); 386 | } 387 | 388 | NAKED void GLI_DRV_vPrepareForGliFullScreen( HWND hWnd ) 389 | { 390 | JMP(Vd_GLI_DRV_vPrepareForGliFullScreen); 391 | } 392 | 393 | NAKED void GLI_DRV_vActivateGli( HWND hWnd, BOOL bActivate ) 394 | { 395 | JMP(Vd_GLI_DRV_vActivateGli); 396 | } 397 | 398 | NAKED void GLI_DRV_vReadaptDisplay( void ) 399 | { 400 | JMP(Vd_GLI_DRV_vReadaptDisplay); 401 | } 402 | 403 | 404 | /**** HDWTEX ****/ 405 | 406 | NAKED void GLI_DRV_vDownLoadTextures( long bRestore, long lTextureMode, BOOL bReloading ) 407 | { 408 | JMP(Vd_GLI_DRV_vDownLoadTextures); 409 | } 410 | 411 | NAKED void GLI_DRV_vUnLoadTextures( void ) 412 | { 413 | JMP(Vd_GLI_DRV_vUnLoadTextures); 414 | } 415 | 416 | NAKED long GLI_DRV_lGetSizeOfTexture( GLI_tdstTexture *p_stTexture ) 417 | { 418 | JMP(Vd_GLI_DRV_lGetSizeOfTexture); 419 | } 420 | 421 | 422 | /**** DOMAT ****/ 423 | 424 | NAKED void GLI_DRV_vDoOpaqueTextureSelection( GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ) 425 | { 426 | JMP(Vd_GLI_DRV_vDoOpaqueTextureSelection); 427 | } 428 | 429 | NAKED void GLI_DRV_vWrite16bBitmapToBackBuffer( 430 | void *p_vSourceBuffer, 431 | long lWidth, 432 | long lHeight, 433 | long lDestLeft, 434 | long lDestTop, 435 | long lDestRight, 436 | long lDestBottom 437 | ) 438 | { 439 | JMP(Vd_GLI_DRV_vWrite16bBitmapToBackBuffer); 440 | } 441 | 442 | NAKED void GLI_DRV_vAddBlackPolygon( long lLeft, long lTop, long lRight, long lBottom ) 443 | { 444 | JMP(Vd_GLI_DRV_vAddBlackPolygon); 445 | } 446 | 447 | NAKED void GLI_DRV_vNoBlackPolygon( void ) 448 | { 449 | JMP(Vd_GLI_DRV_vNoBlackPolygon); 450 | } 451 | 452 | NAKED void GLI_DRV_vComputeFogEffect( GLI_tdstInternalGlobalValuesFor3dEngine *p_stBG ) 453 | { 454 | JMP(Vd_GLI_DRV_vComputeFogEffect); 455 | } 456 | 457 | NAKED BOOL GLI_DRV_bBeginScene( void ) 458 | { 459 | JMP(Vd_GLI_DRV_bBeginScene); 460 | } 461 | 462 | NAKED BOOL GLI_DRV_bEndScene( void ) 463 | { 464 | JMP(Vd_GLI_DRV_bEndScene); 465 | } 466 | 467 | 468 | /**** ACCES ****/ 469 | 470 | NAKED void GLI_DRV_vSendSpriteToClip( 471 | GLI_tdstAligned2DVector *a4_st2DVertex, 472 | float xZ, 473 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 474 | ) 475 | { 476 | JMP(Vd_GLI_DRV_vSendSpriteToClip); 477 | } 478 | 479 | NAKED void GLI_DRV_vSendSpriteToClipWithUV( 480 | GLI_tdstAligned2DVector *a4_st2DVertex, 481 | float *a8_stUVVertex, 482 | float xZ, 483 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 484 | ) 485 | { 486 | JMP(Vd_GLI_DRV_vSendSpriteToClipWithUV); 487 | } 488 | 489 | NAKED void GLI_DRV_vSendSpriteToClipWithColors( 490 | GLI_tdstAligned2DVector *a4_st2DVertex, 491 | void *_Colors, 492 | float xZ, 493 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 494 | ) 495 | { 496 | JMP(Vd_GLI_DRV_vSendSpriteToClipWithColors); 497 | } 498 | 499 | /* 500 | NAKED void GLI_DRV_vSendSingleLineToClip( 501 | GLD_tdstViewportAttributes *p_stVpt, 502 | GLI_tdstAligned3DVector *p_stVertex1, 503 | GLI_tdstAligned2DVector *p_st2DVertex1, 504 | GLI_tdstAligned3DVector *p_stVertex2, 505 | GLI_tdstAligned2DVector *p_st2DVertex2, 506 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT, 507 | long lDrawModeMask, 508 | GEO_tdstColor *p_stColor 509 | ) 510 | { 511 | JMP(Vd_GLI_DRV_vSendSingleLineToClip); 512 | } 513 | */ 514 | 515 | /**** CLIP TRIANGLES ****/ 516 | 517 | NAKED void GLI_DRV_xClearViewingList( void ) 518 | { 519 | JMP(Vd_GLI_DRV_xClearViewingList); 520 | } 521 | 522 | NAKED void GLI_DRV_xSendListToViewport( GLD_tdstViewportAttributes *p_stVpt ) 523 | { 524 | JMP(Vd_GLI_DRV_xSendListToViewport); 525 | } 526 | 527 | NAKED void GLI_DRV_vSetZClip( float xZClip, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ) 528 | { 529 | JMP(Vd_GLI_DRV_vSetZClip); 530 | } 531 | 532 | NAKED void GLI_DRV_vSetClipWindow( 533 | float fXMin, 534 | float fXMax, 535 | float fYMin, 536 | float fYMax, 537 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 538 | ) 539 | { 540 | JMP(Vd_GLI_DRV_vSetClipWindow); 541 | } 542 | 543 | NAKED void GLI_DRV_xSendElementTIToClip_TRIANGLES( 544 | GEO_tdstElementIndexedTriangles *p_stLocalElementIndexedTriangle, 545 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 546 | ) 547 | { 548 | JMP(Vd_GLI_DRV_xSendElementTIToClip_TRIANGLES); 549 | } 550 | 551 | NAKED void GLI_DRV_xSendSingleTriangleToClip_TRIANGLES( 552 | GLI_tdstAligned2DVector *a3_st2DVertex, 553 | ACP_tdst2DUVValues *a3_stUV, 554 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 555 | ) 556 | { 557 | JMP(Vd_GLI_DRV_xSendSingleTriangleToClip_TRIANGLES); 558 | } 559 | -------------------------------------------------------------------------------- /GliFixVf/GliFixVf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | #include "devinfo.h" 5 | #include "defs.h" 6 | 7 | 8 | #define NAKED __declspec(naked) 9 | #define JMP(p_fn) do { __asm { jmp p_fn } } while(0) 10 | 11 | 12 | /* 13 | * Exported functions 14 | */ 15 | 16 | EXPORT long GLI_DRV_lGetDllInfo( char const *szName, void *pData ); 17 | EXPORT long GLI_DRV_lSetCommonData( char const *szName, void *pData ); 18 | EXPORT long GLI_DRV_lSetCommonFct( char const *szName, tdfn_CommonFct pData ); 19 | EXPORT long GLI_DRV_fn_lGetAllDisplayConfig( tdfn_lAddDisplayInfo p_fn_lAddDisplayInfo ); 20 | EXPORT long GLI_DRV_fnl_EnumModes( char *szDriverName, char *szDeviceName ); 21 | EXPORT void GLI_DRV_xInitDriver( HWND hWnd, BOOL bFullscreen, long lWidth, long lHeight, int lBpp ); 22 | EXPORT void GLI_DRV_vFlipDeviceWithSyncro( void ); 23 | 24 | 25 | /* 26 | * Redirected exports 27 | */ 28 | 29 | /**** INIT ****/ 30 | EXPORT void GLI_DRV_vFlipDevice( int lWaitFrames ); 31 | EXPORT void GLI_DRV_vClearDevice( BOOL bZBuffer, BOOL bColorBuffer, unsigned long ulColor ); 32 | EXPORT void GLI_DRV_vCloseDriver( void ); 33 | EXPORT void GLI_DRV_vClearZBufferRegion( long lXStart, long lXEnd, long lYStart, long lYEnd ); 34 | EXPORT long GLI_DRV_hChangeMode( BOOL bFullscreen, long lWidth, long lHeight, long lBpp ); 35 | EXPORT BOOL GLI_DRV_bLockDevice( void **pp_vVirtualScreen, long *p_lPitch ); 36 | EXPORT BOOL GLI_DRV_bUnlockDevice( void ); 37 | EXPORT BOOL GLI_DRV_bWindowedModeIsOptimized( void ); 38 | EXPORT void GLI_DRV_vOptimizedWindowedMode( void ); 39 | EXPORT void GLI_DRV_vNonOptimizedWindowedMode( void ); 40 | EXPORT BOOL GLI_DRV_bPrepareForGliWindowed( HWND hWnd ); 41 | EXPORT void GLI_DRV_vPrepareForGliFullScreen( HWND hWnd ); 42 | EXPORT void GLI_DRV_vActivateGli( HWND hWnd, BOOL bActivate ); 43 | EXPORT void GLI_DRV_vReadaptDisplay( void ); 44 | /* 45 | GLI_DRV_vGetStats() 46 | GLI_DRV_vWaitRetrace() 47 | GLI_DRV_lRequest() 48 | */ 49 | 50 | /**** HDWTEX ****/ 51 | EXPORT void GLI_DRV_vDownLoadTextures( long bRestore, long lTextureMode, BOOL bReloading ); 52 | EXPORT void GLI_DRV_vUnLoadTextures( void ); 53 | EXPORT long GLI_DRV_lGetSizeOfTexture( GLI_tdstTexture *p_stTexture ); 54 | 55 | /**** DOMAT ****/ 56 | EXPORT void GLI_DRV_vDoOpaqueTextureSelection( GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 57 | EXPORT void GLI_DRV_vWrite16bBitmapToBackBuffer( 58 | void *p_vSourceBuffer, 59 | long lWidth, 60 | long lHeight, 61 | long lDestLeft, 62 | long lDestTop, 63 | long lDestRight, 64 | long lDestBottom 65 | ); 66 | EXPORT void GLI_DRV_vAddBlackPolygon( long lLeft, long lTop, long lRight, long lBottom ); 67 | EXPORT void GLI_DRV_vNoBlackPolygon( void ); 68 | EXPORT void GLI_DRV_vComputeFogEffect( GLI_tdstInternalGlobalValuesFor3dEngine *p_stBG ); 69 | EXPORT BOOL GLI_DRV_bBeginScene( void ); 70 | EXPORT BOOL GLI_DRV_bEndScene( void ); 71 | 72 | /**** ACCES ****/ 73 | EXPORT void GLI_DRV_vSendSpriteToClip( 74 | GLI_tdstAligned2DVector *a4_st2DVertex, 75 | float xZ, 76 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 77 | ); 78 | EXPORT void GLI_DRV_vSendSpriteToClipWithUV( 79 | GLI_tdstAligned2DVector *a4_st2DVertex, 80 | float *a8_stUVVertex, 81 | float xZ, 82 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 83 | ); 84 | EXPORT void GLI_DRV_vSendSpriteToClipWithColors( 85 | GLI_tdstAligned2DVector *a4_st2DVertex, 86 | void *_Colors, 87 | float xZ, 88 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 89 | ); 90 | EXPORT void GLI_DRV_vSendSingleLineToClip( 91 | GLD_tdstViewportAttributes *p_stVpt, 92 | GLI_tdstAligned3DVector *p_stVertex1, 93 | GLI_tdstAligned2DVector *p_st2DVertex1, 94 | GLI_tdstAligned3DVector *p_stVertex2, 95 | GLI_tdstAligned2DVector *p_st2DVertex2, 96 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT, 97 | long lDrawModeMask, 98 | GEO_tdstColor *p_stColor 99 | ); 100 | 101 | /**** CLIP TRIANGLES ****/ 102 | EXPORT void GLI_DRV_xClearViewingList( void ); 103 | EXPORT void GLI_DRV_xSendListToViewport( GLD_tdstViewportAttributes *p_stVpt ); 104 | EXPORT void GLI_DRV_vSetZClip( float xZClip, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 105 | EXPORT void GLI_DRV_vSetClipWindow( 106 | float fXMin, 107 | float fXMax, 108 | float fYMin, 109 | float fYMax, 110 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 111 | ); 112 | EXPORT void GLI_DRV_xSendElementTIToClip_TRIANGLES( 113 | GEO_tdstElementIndexedTriangles *p_stLocalElementIndexedTriangle, 114 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 115 | ); 116 | EXPORT void GLI_DRV_xSendSingleTriangleToClip_TRIANGLES( 117 | GLI_tdstAligned2DVector *a3_st2DVertex, 118 | ACP_tdst2DUVValues *a3_stUV, 119 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 120 | ); 121 | -------------------------------------------------------------------------------- /GliFixVf/GliFixVf.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 16.0 15 | Win32Proj 16 | {1ec3bbc4-8138-4627-85ab-801015c5a07d} 17 | GliFixVf 18 | 10.0 19 | 20 | 21 | 22 | DynamicLibrary 23 | true 24 | v143 25 | NotSet 26 | 27 | 28 | DynamicLibrary 29 | false 30 | v143 31 | true 32 | NotSet 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | true 49 | GliFixVf 50 | 51 | 52 | false 53 | GliFixVf 54 | 55 | 56 | 57 | Level3 58 | true 59 | WIN32;_DEBUG;GLIFIXVF_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 60 | true 61 | CompileAsC 62 | $(SolutionDir)inc;$(acplib)\include;%(AdditionalIncludeDirectories) 63 | 64 | 65 | Windows 66 | true 67 | false 68 | $(SolutionDir)lib;$(acplib)\lib;%(AdditionalLibraryDirectories) 69 | detours.lib;ACP_Ray2.lib;%(AdditionalDependencies) 70 | false 71 | 72 | 73 | $(SolutionDir)generate_gitver.cmd 74 | 75 | 76 | Generating gitver.h 77 | 78 | 79 | 80 | 81 | Level3 82 | true 83 | true 84 | true 85 | WIN32;NDEBUG;GLIFIXVF_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 86 | true 87 | CompileAsC 88 | $(SolutionDir)inc;$(acplib)\include;%(AdditionalIncludeDirectories) 89 | MultiThreadedDLL 90 | 91 | 92 | Windows 93 | true 94 | true 95 | true 96 | false 97 | $(SolutionDir)lib;$(acplib)\lib;%(AdditionalLibraryDirectories) 98 | detours.lib;ACP_Ray2.lib;%(AdditionalDependencies) 99 | false 100 | 101 | 102 | $(SolutionDir)generate_gitver.cmd 103 | 104 | 105 | Generating gitver.h 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /GliFixVf/GliFixVf.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | 70 | 71 | Source Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /GliFixVf/config.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include 3 | #include 4 | #include "config.h" 5 | #include "devinfo.h" 6 | 7 | 8 | #define C_MaxGlideModes 8 9 | 10 | tdstDisplayMode a_stGlideModes[C_MaxGlideModes] = { 11 | { 320, 200 }, 12 | { 400, 300 }, 13 | { 512, 384 }, 14 | { 640, 480 }, 15 | { 800, 600 }, 16 | { 1024, 768 }, 17 | { 1280, 1024 }, 18 | { 1600, 1200 }, 19 | }; 20 | 21 | tdstDisplayMode stDefaultRes = { 1024, 768 }; 22 | 23 | char const *szDegePath = ".\\dgVoodoo.conf"; 24 | char const *szUbiPath = ".\\Ubi.ini"; 25 | 26 | 27 | /* 28 | * Global Vars 29 | */ 30 | 31 | tdstDisplayMode CFG_stActualDispMode = { 0 }; 32 | float CFG_xActualRatio = 0; 33 | 34 | tdstDisplayMode CFG_stDispMode = { 0 }; 35 | BOOL CFG_bHalfRefRate = FALSE; 36 | int CFG_DEBUG_lWaitFrame = 0; 37 | 38 | BOOL CFG_bIsMainModuleR2 = FALSE; 39 | BOOL CFG_bIsFixEnabled = TRUE; 40 | 41 | BOOL CFG_bPatchWidescreen = FALSE; 42 | BOOL CFG_bIsWidescreen = FALSE; 43 | 44 | char CFG_szModuleName[MAX_PATH] = ""; 45 | char CFG_szModuleDate[20] = ""; 46 | 47 | /* 48 | * Functions 49 | */ 50 | 51 | // Returns largest Glide resolution smaller than the provided display mode. 52 | tdstDisplayMode * fn_p_stGetClosestGlideMode( tdstDisplayMode *lpMode ) 53 | { 54 | for ( int i = C_MaxGlideModes - 1; i >= 0; i-- ) 55 | { 56 | tdstDisplayMode *lpGlideMode = &a_stGlideModes[i]; 57 | 58 | if ( lpGlideMode->dwWidth <= lpMode->dwWidth && lpGlideMode->dwHeight <= lpMode->dwHeight ) 59 | { 60 | return lpGlideMode; 61 | } 62 | } 63 | 64 | // Ruh roh, somehow even the smallest Glide mode is larger than lpMode. 65 | // That's probably an error, so let's just return the "default" value (1024x768). 66 | 67 | return &stDefaultRes; 68 | } 69 | 70 | BOOL fn_bReadDispModeFromDegeConfig( tdstDisplayMode *lpDst ) 71 | { 72 | char szBuffer[128]; 73 | char *szSection = "Glide"; 74 | 75 | GetPrivateProfileString(szSection, "Resolution", NULL, szBuffer, sizeof(szBuffer), szDegePath); 76 | 77 | int nParsed = sscanf_s(szBuffer, "h:%u, v:%u", &lpDst->dwWidth, &lpDst->dwHeight); 78 | 79 | if ( nParsed < 2 || lpDst->dwWidth <= 0 || lpDst->dwHeight <= 0 ) 80 | { 81 | // Try the other format before giving up 82 | nParsed = sscanf_s(szBuffer, "%dx%d", &lpDst->dwWidth, &lpDst->dwHeight); 83 | 84 | if ( nParsed < 2 || lpDst->dwWidth <= 0 || lpDst->dwHeight <= 0 ) 85 | return FALSE; 86 | } 87 | 88 | return TRUE; 89 | } 90 | 91 | void fn_vReadR2Config( void ) 92 | { 93 | char szBuffer[128]; 94 | tdstDisplayMode stFromConfig = { 0 }; 95 | 96 | // GLI library 97 | GetPrivateProfileString("Rayman2", "GLI_Dll", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 98 | 99 | if ( strcmp(szBuffer, GLI_szName) != 0 ) 100 | { 101 | // Ray2Fix is loaded but not enabled, set the global var to FALSE 102 | // This will show a prompt in GLI_DRV_fn_lGetAllDisplayConfig. 103 | CFG_bIsFixEnabled = FALSE; 104 | } 105 | 106 | // Display mode (resolution) 107 | GetPrivateProfileString("Rayman2", "GLI_Mode", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 108 | 109 | int nParsed = sscanf_s(szBuffer, "1 - %u x %u", &stFromConfig.dwWidth, &stFromConfig.dwHeight); 110 | 111 | if ( nParsed < 2 || stFromConfig.dwWidth <= 0 || stFromConfig.dwHeight <= 0 ) 112 | { 113 | // Try to parse resolution from dgvoodoo.conf 114 | if ( !fn_bReadDispModeFromDegeConfig(&stFromConfig) ) 115 | { 116 | // Give up and apply sane defaults (1024x768) 117 | stFromConfig = stDefaultRes; 118 | } 119 | } 120 | CFG_stActualDispMode = stFromConfig; 121 | } 122 | 123 | void fn_vReadFixConfig( void ) 124 | { 125 | char szBuffer[128]; 126 | 127 | // Widescreen patch 128 | GetPrivateProfileString("Ray2Fix", "PatchWidescreen", "0", szBuffer, sizeof(szBuffer), szUbiPath); 129 | if( strtol(szBuffer, NULL, 10) > 0 ) 130 | CFG_bPatchWidescreen = TRUE; 131 | 132 | // Refresh rate 133 | GetPrivateProfileString("Ray2Fix", "HalfRefRate", "0", szBuffer, sizeof(szBuffer), szUbiPath); 134 | if( strtol(szBuffer, NULL, 10) > 0 ) 135 | CFG_bHalfRefRate = TRUE; 136 | 137 | // DEBUG Wait frame 138 | GetPrivateProfileString("Ray2Fix", "Debug_WaitFrame", "0", szBuffer, sizeof(szBuffer), szUbiPath); 139 | int lResult = strtol(szBuffer, NULL, 10); 140 | if ( lResult > 0 ) 141 | CFG_DEBUG_lWaitFrame = lResult; 142 | } 143 | 144 | void CFG_fn_vInitGlobals( void ) 145 | { 146 | CFG_bIsMainModuleR2 = CFG_fn_bDetermineMainModule(); 147 | 148 | fn_vReadR2Config(); 149 | fn_vReadFixConfig(); 150 | 151 | unsigned int ratio = 100 * CFG_stActualDispMode.dwHeight / CFG_stActualDispMode.dwWidth; 152 | CFG_bIsWidescreen = (ratio <= 73); 153 | 154 | tdstDisplayMode *lpGlideMode = fn_p_stGetClosestGlideMode(&CFG_stActualDispMode); 155 | CFG_stDispMode = *lpGlideMode; 156 | 157 | CFG_xActualRatio = (float)CFG_stActualDispMode.dwHeight / (float)CFG_stActualDispMode.dwWidth; 158 | } 159 | 160 | BOOL CFG_fn_bOpenConfigTool( void ) 161 | { 162 | int lResult = (int)ShellExecute(NULL, NULL, ".\\R2FixCfg.exe", NULL, NULL, SW_SHOW); 163 | 164 | if ( lResult > 32 ) 165 | return TRUE; 166 | 167 | return FALSE; 168 | } 169 | 170 | BOOL CFG_fn_bDetermineMainModule( void ) 171 | { 172 | char szModuleName[MAX_PATH]; 173 | HMODULE hModule = GetModuleHandle(NULL); 174 | 175 | GetModuleFileName(hModule, szModuleName, MAX_PATH); 176 | char *pBaseName = strrchr(szModuleName, '\\') + 1; 177 | strcpy_s(CFG_szModuleName, sizeof(CFG_szModuleName), pBaseName); 178 | 179 | if ( !strcmp(pBaseName, "Rayman2.exe") ) 180 | return TRUE; 181 | 182 | // query the nt header 183 | unsigned char *pBase = (unsigned char *)hModule; 184 | IMAGE_DOS_HEADER *pDosHeader = (IMAGE_DOS_HEADER *)pBase; 185 | IMAGE_NT_HEADERS *pNtHeader = (IMAGE_NT_HEADERS *)(pBase + pDosHeader->e_lfanew); 186 | 187 | // module date 188 | time_t timestamp = pNtHeader->FileHeader.TimeDateStamp; 189 | struct tm const *pTime = gmtime(×tamp); 190 | strftime(CFG_szModuleDate, sizeof(CFG_szModuleDate), "%F", pTime); 191 | 192 | // module name 193 | if ( !pNtHeader->OptionalHeader.NumberOfRvaAndSizes ) 194 | return FALSE; 195 | 196 | IMAGE_DATA_DIRECTORY *pExpDir = &pNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; 197 | IMAGE_EXPORT_DIRECTORY *pExports = (IMAGE_EXPORT_DIRECTORY *)(pBase + pExpDir->VirtualAddress); 198 | if ( !pExpDir->Size || !pExports->Name ) 199 | return FALSE; 200 | 201 | // got original module name 202 | char const *pName = (char *)(pBase + pExports->Name); 203 | strcpy_s(CFG_szModuleName, sizeof(CFG_szModuleName), pName); 204 | 205 | if ( !_stricmp(pName, "MainWinf.exe") ) // retail RII 206 | return TRUE; 207 | 208 | return FALSE; 209 | } 210 | -------------------------------------------------------------------------------- /GliFixVf/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | typedef struct tdstDisplayMode_ 7 | { 8 | DWORD dwWidth; 9 | DWORD dwHeight; 10 | } 11 | tdstDisplayMode; 12 | 13 | 14 | /* 15 | * Global Vars 16 | */ 17 | 18 | extern tdstDisplayMode CFG_stActualDispMode; 19 | extern float CFG_xActualRatio; 20 | 21 | extern tdstDisplayMode CFG_stDispMode; 22 | extern BOOL CFG_bHalfRefRate; 23 | extern int CFG_DEBUG_lWaitFrame; 24 | 25 | extern BOOL CFG_bIsMainModuleR2; 26 | extern BOOL CFG_bIsFixEnabled; 27 | 28 | extern BOOL CFG_bPatchWidescreen; 29 | extern BOOL CFG_bIsWidescreen; 30 | 31 | extern char CFG_szModuleName[MAX_PATH]; 32 | extern char CFG_szModuleDate[20]; 33 | 34 | 35 | /* 36 | * Functions 37 | */ 38 | 39 | void CFG_fn_vInitGlobals( void ); 40 | BOOL CFG_fn_bOpenConfigTool( void ); 41 | BOOL CFG_fn_bDetermineMainModule( void ); 42 | -------------------------------------------------------------------------------- /GliFixVf/defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | typedef struct GLI_tdstInternalGlobalValuesFor3dEngine GLI_tdstInternalGlobalValuesFor3dEngine; 5 | typedef struct GLD_tdstDeviceAttributes GLD_tdstDeviceAttributes; 6 | typedef struct GLD_tdstViewportAttributes GLD_tdstViewportAttributes; 7 | typedef struct GLI_tdstAligned2DVector GLI_tdstAligned2DVector; 8 | typedef struct GLI_tdstAligned3DVector GLI_tdstAligned3DVector; 9 | typedef struct GLI_tdstTexture GLI_tdstTexture; 10 | typedef struct GEO_tdstColor GEO_tdstColor; 11 | typedef struct GEO_tdstElementIndexedTriangles GEO_tdstElementIndexedTriangles; 12 | typedef struct GLI_tdst2DUVValues ACP_tdst2DUVValues; 13 | -------------------------------------------------------------------------------- /GliFixVf/devinfo.c: -------------------------------------------------------------------------------- 1 | #include "devinfo.h" 2 | #include "../gitver.h" 3 | 4 | 5 | /* 6 | * Renderer Info 7 | */ 8 | 9 | char const *GLI_szName = "Ray2Fix"; 10 | char const *GLI_szDesc = "Spitfire's Graphics Fix GLI Passthrough"; 11 | char const *GLI_szVersion = C_GIT_VER; 12 | int const GLI_lCode = 8; 13 | -------------------------------------------------------------------------------- /GliFixVf/devinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | /* 7 | * Renderer Info 8 | */ 9 | 10 | extern char const *GLI_szName; 11 | extern char const *GLI_szDesc; 12 | extern char const *GLI_szVersion; 13 | extern int const GLI_lCode; 14 | 15 | 16 | /* 17 | * Device Capabilities 18 | */ 19 | 20 | #define C_DI_DllBmp "dll_bmp" 21 | #define C_DI_DevCaps "dev_caps" 22 | 23 | #define C_DI_DisplayAdd "dispadd" 24 | #define C_DI_DisplayName "dispname" 25 | #define C_DI_DisplayDesc "dispdesc" 26 | 27 | #define C_DI_DeviceAdd "dev_add" 28 | #define C_DI_DeviceName "dev_name" 29 | #define C_DI_DeviceDesc "dev_desc" 30 | 31 | #define C_DI_ModeAdd "modeadd" 32 | #define C_DI_ModeFullscreen "modefs" 33 | #define C_DI_ModeBpp "modebpp" 34 | #define C_DI_ModeWidth "modew" 35 | #define C_DI_ModeHeight "modeh" 36 | 37 | 38 | typedef enum tdeDriverCaps 39 | { 40 | E_DRV_IsHardware = 1 << 0, 41 | E_DRV_CanUseAGP = 1 << 1, 42 | E_DRV_CanUseSystemMemory = 1 << 2, 43 | E_DRV_CanBeWindowed = 1 << 3, 44 | E_DRV_SupportAlphaTest = 1 << 4, 45 | E_DRV_ReadjustViewport = 1 << 5 46 | // ... 47 | } 48 | tdeDriverCaps; 49 | 50 | typedef enum tdeTextureCaps 51 | { 52 | E_TEX_Support8P = 1 << 0, 53 | E_TEX_SupportNonSquare = 1 << 1, 54 | E_TEX_SupportMipMap = 1 << 2, 55 | E_TEX_SupportMirror = 1 << 3 56 | // ... 57 | } 58 | tdeTextureCaps; 59 | 60 | typedef struct tdstGliCaps 61 | { 62 | unsigned long ulSize; 63 | tdeDriverCaps ulDriverCaps; 64 | tdeTextureCaps ulTextureCaps; 65 | unsigned long ulSurfaceCaps; 66 | unsigned long ulMemoryCaps; 67 | unsigned long ulTextureMaxSize; 68 | unsigned long ulTotalTextureMemory; 69 | unsigned long ulTotalVideoMemory; /* mem local */ 70 | unsigned long ulTotalAGPMemory; /* mem non-local */ 71 | unsigned char ucPrimarySurfacePixelFormat; 72 | float xRefreshRate; 73 | } 74 | tdstGliCaps; 75 | 76 | 77 | /* GLI property set function, used in GLI_DRV_fn_lGetAllDisplayConfig */ 78 | typedef int (*tdfn_lAddDisplayInfo)( DWORD lDisplay, DWORD lDevice, DWORD lMode, const char *szName, long Value ); 79 | 80 | /* Common function, used in GLI_DRV_lSetCommonFct */ 81 | typedef int (*tdfn_CommonFct)(); 82 | -------------------------------------------------------------------------------- /GliFixVf/dllmain.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "imports.h" 3 | #include "fix.h" 4 | #include "config.h" 5 | 6 | 7 | void fn_vInitDll( void ) 8 | { 9 | CFG_fn_vInitGlobals(); 10 | IMP_fn_vLoadGliLibrary(); 11 | 12 | if ( CFG_bIsMainModuleR2 ) /* retail RII */ 13 | { 14 | /* Loaded in the game, patch all */ 15 | FIX_fn_vAttachHooks(); 16 | } 17 | else if ( !_stricmp(CFG_szModuleName, "MainWinR.exe") ) /* most likely some other flavor of RII */ 18 | { 19 | if ( !CFG_DEBUG_lWaitFrame ) /* alt framerate fix */ 20 | CFG_DEBUG_lWaitFrame = 1; 21 | 22 | if ( !_stricmp(CFG_szModuleDate, "1999-08-18") ) /* Demo 1 */ 23 | { 24 | FIX_fn_vAttachHooksMin((void *)0x502250, (void *)0x401A10); 25 | } 26 | else if ( !_stricmp(CFG_szModuleDate, "1999-09-04") ) /* Demo 2 */ 27 | { 28 | FIX_fn_vAttachHooksMin((void *)0x5129E0, (void *)0x401A10); 29 | } 30 | } 31 | else 32 | { 33 | /* Probably loaded in GxSetup/GliDetect, only patch mode enum */ 34 | FIX_fn_vRemoveModeEnum(); 35 | } 36 | } 37 | 38 | void fn_vDeInitDll( void ) 39 | { 40 | if ( CFG_bIsMainModuleR2 ) 41 | { 42 | FIX_fn_vDetachHooks(); 43 | } 44 | else if ( !_stricmp(CFG_szModuleName, "MainWinR.exe") ) 45 | { 46 | FIX_fn_vDetachHooksMin(); 47 | } 48 | } 49 | 50 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved ) 51 | { 52 | switch ( dwReason ) 53 | { 54 | case DLL_PROCESS_ATTACH: 55 | fn_vInitDll(); 56 | break; 57 | 58 | case DLL_PROCESS_DETACH: 59 | fn_vDeInitDll(); 60 | break; 61 | } 62 | 63 | return TRUE; 64 | } 65 | -------------------------------------------------------------------------------- /GliFixVf/fix.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include 3 | #include "fix.h" 4 | #include "imports.h" 5 | #include "r2fn.h" 6 | #include "config.h" 7 | #include "GliFixVf.h" 8 | 9 | #include 10 | 11 | 12 | char *szConfigMenu = "/C:Ray2Fix Config"; 13 | char szVersionString[50]; 14 | 15 | 16 | /* 17 | * Detours 18 | */ 19 | 20 | BOOL CALLBACK FIX_fn_InputEnum( void *lpddi, void *pvRef ) 21 | { 22 | // Call original function 23 | R2_fn_InputEnum(lpddi, pvRef); 24 | 25 | // HACK: Input device enumeration fix 26 | // Rayman2 returns DIENUM_STOP when it encounters a device type it cannot handle. 27 | // This usually causes it to skip enumeration of gamepads on modern PCs. 28 | // Here we fix this by always returning DIENUM_CONTINUE. 29 | return DIENUM_CONTINUE; 30 | } 31 | 32 | BOOL FIX_fn_SuspendGame() 33 | { 34 | // HACK: Disable suspended game state 35 | // Disregard whatever the game's trying to do here and always return TRUE. 36 | // This prevents the game from suspending itself when the focus is lost. 37 | return TRUE; 38 | } 39 | 40 | char * FIX_fn_szGetStringFromTextOrStringParam( void *param ) 41 | { 42 | // Call original function 43 | char *result = R2_fn_szGetStringFromTextOrStringParam(param); 44 | 45 | // HACK: Replace "Site Rayman2" in main menu with a shortcut to R2FixCfg 46 | if ( !_stricmp(GAM_fn_p_szGetLevelName(), "menu") ) 47 | { 48 | // Part 1: Replace menu text. 49 | if ( !strcmp(result, "/C:Site Rayman2") 50 | || !strcmp(result, "/C:Web de Rayman2") 51 | || !strcmp(result, "/C:Sito di Rayman2") 52 | || !strcmp(result, "/C:Rayman2 - Webseite") ) 53 | { 54 | //return szConfigMenu; 55 | return szVersionString; 56 | } 57 | 58 | // Part 2: Open R2FixCfg with ShellExecute. 59 | if ( !strcmp(result, "http://www.rayman2.com/") ) 60 | { 61 | if ( CFG_fn_bOpenConfigTool() ) 62 | SendMessage(GAM_fn_hGetWindowHandle(), WM_CLOSE, 0, 0); 63 | } 64 | } 65 | 66 | return result; 67 | } 68 | 69 | 70 | void FIX_xAdjustCameraToViewport2(GLD_tdstDeviceAttributes *p_stDev, GLD_tdstViewportAttributes *p_stVpt, GLI_tdstCamera *p_stCam ) 71 | { 72 | MTH_tdxReal xVptWidthInPix = (MTH_tdxReal)CFG_stActualDispMode.dwWidth; 73 | MTH_tdxReal xVptHeightInPix = (MTH_tdxReal)CFG_stActualDispMode.dwHeight; 74 | MTH_tdxReal xVptWidthInMeters = xVptWidthInPix * p_stDev->xPixelDimensionX; 75 | MTH_tdxReal xVptHeightInMeters = xVptHeightInPix * p_stDev->xPixelDimensionY; 76 | MTH_tdxReal xVptRatio = xVptHeightInMeters / xVptWidthInMeters; 77 | 78 | MTH_tdxReal xUsedRatio = p_stCam->xRatio; 79 | if ( xVptRatio != 0 ) 80 | xUsedRatio = xVptRatio; 81 | 82 | // Normally Y-FoV is calculated based on X-FoV. We want it the other way around 83 | // Was previously calculated as follows: 84 | //p_stCam->xAlphaX = GLI_M_Div(p_stCam->xAlphaY, xVptRatio); 85 | // Now, we use this formula to calculate the new X-FOV: 86 | // newFOV = 2*atan(( newAR )/( defaultAR ) * tan( default FOV / 2)) 87 | p_stCam->xAlphaX = 2.0f * (float)atan( (1.0 / xUsedRatio) / (1.0 / 0.75) * tan((p_stCam->xAlphaY / 0.75) / 2.0) ); 88 | 89 | GLI_xAdjustCameraToViewport2(p_stDev, p_stVpt, p_stCam); 90 | } 91 | 92 | void FIX_vDraw2DSpriteWithPercent( GLD_tdstViewportAttributes *p_stVpt, MTH_tdxReal XMin, MTH_tdxReal YMin, MTH_tdxReal XMax, MTH_tdxReal YMax, GLI_tdstMaterial *hMaterial ) 93 | { 94 | MTH_tdxReal x1, x2, y1, y2; 95 | GLI_tdstAligned2DVector a4_st2DVertex[4]; 96 | 97 | MTH_tdxReal xVptWidth = (MTH_tdxReal)p_stVpt->dwWidth; 98 | MTH_tdxReal xVptHeight = (MTH_tdxReal)p_stVpt->dwHeight; 99 | 100 | float ratio = 1.0f; 101 | float addToCenter = 0.0f; 102 | 103 | if ( XMin != 0.0f || XMax != 100.0f ) 104 | { 105 | ratio = CFG_xActualRatio / 0.75f; 106 | addToCenter = (xVptWidth - (xVptWidth * ratio)) / 2; 107 | } 108 | 109 | x1 = (XMin / 100.0f) * xVptWidth * ratio + addToCenter; 110 | x2 = (XMax / 100.0f) * xVptWidth * ratio + addToCenter; 111 | y1 = (YMin / 100.0f) * xVptHeight; 112 | y2 = (YMax / 100.0f) * xVptHeight; 113 | 114 | a4_st2DVertex[0].xX = x2; 115 | a4_st2DVertex[0].xY = y1; 116 | a4_st2DVertex[0].xOoZ = 1.0f; 117 | a4_st2DVertex[1].xX = x1; 118 | a4_st2DVertex[1].xY = y1; 119 | a4_st2DVertex[1].xOoZ = 1.0f; 120 | a4_st2DVertex[2].xX = x1; 121 | a4_st2DVertex[2].xY = y2; 122 | a4_st2DVertex[2].xOoZ = 1.0f; 123 | a4_st2DVertex[3].xX = x2; 124 | a4_st2DVertex[3].xY = y2; 125 | a4_st2DVertex[3].xOoZ = 1.0f; 126 | 127 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobals = *GLI_BIG_GLOBALS; 128 | p_stGlobals->hCurrentMaterial = hMaterial; 129 | p_stGlobals->lCurrentDrawMask = p_stGlobals->lHierachDrawMask = 130 | p_stGlobals->hCurrentMaterial->ulMaterialType = 0xFFFFFFFF - GLI_C_Mat_lIsTestingBackface - GLI_C_Mat_lIsNotGrided; 131 | 132 | GLI_vDoMaterialSelection(p_stGlobals); 133 | p_stGlobals->xTextureDontAcceptFog = 1; 134 | 135 | #if N64FONT 136 | if ( *GLI_g_bForceAAAColor ) 137 | { 138 | p_stGlobals->ulColorInitForSprite &= 0xFF000000; 139 | p_stGlobals->ulColorInitForSprite |= GLI_a3_ForcedAAAColor[0] << 16 | GLI_a3_ForcedAAAColor[1] << 8 | GLI_a3_ForcedAAAColor[2]; 140 | } 141 | 142 | GLI_DRV_vSendSpriteToClip(a4_st2DVertex, *GLI_g_fZValueForSprite, p_stGlobals); 143 | #else 144 | if ( *GLI_g_bForceAAAColor ) 145 | { 146 | unsigned long a4_ulColors[4]; 147 | unsigned long ulAlpha = p_stGlobals->ulColorInitForSprite & 0xFF000000; 148 | 149 | a4_ulColors[0] = a4_ulColors[1] = 0xFFFFFF | ulAlpha; 150 | a4_ulColors[2] = a4_ulColors[3] = GLI_a3_ForcedAAAColor[0] << 16 | GLI_a3_ForcedAAAColor[1] << 8 | GLI_a3_ForcedAAAColor[2] | ulAlpha; 151 | 152 | GLI_DRV_vSendSpriteToClipWithColors(a4_st2DVertex, a4_ulColors, *GLI_g_fZValueForSprite, p_stGlobals); 153 | } 154 | else 155 | GLI_DRV_vSendSpriteToClip(a4_st2DVertex, *GLI_g_fZValueForSprite, p_stGlobals); 156 | #endif // N64FONT 157 | } 158 | 159 | AI_tdstNodeInterpret * FIX_fn_p_stSPOSuperimpoed( HIE_tdstSuperObject * p_SuperObjPerso, AI_tdstNodeInterpret *p_stTree ) 160 | { 161 | unsigned long ulProcId = p_stTree[-1].uParam.ulValue; 162 | AI_tdstGetSetParam stParam; 163 | HIE_tdstSuperObject *hNewSuperObjPerso; 164 | 165 | MTH_tdxReal xVptWidth = (MTH_tdxReal)GAM_g_stEngineStructure->stFixViewportAttr.dwWidth; 166 | MTH_tdxReal xVptHeight = (MTH_tdxReal)GAM_g_stEngineStructure->stFixViewportAttr.dwHeight; 167 | 168 | if ( ulProcId == 409 ) 169 | { 170 | AI_fn_vGetUltraOperatorPerso(AI_fn_ucGetProcedureUltraOperator(ulProcId), p_SuperObjPerso, &hNewSuperObjPerso); 171 | 172 | long lX, lY, lZ; 173 | MTH_tdxReal xX, xY, xZ; 174 | MTH3D_tdstVector stVertex; 175 | DNM_tdstDynam *hDynam = HIE_M_hSuperObjectGetActor(hNewSuperObjPerso)->hDynam; 176 | HIE_fn_SO_vSetSuperimposedFlag(hNewSuperObjPerso); 177 | SCT_fn_vRemoveObjectInSectorList(hNewSuperObjPerso); 178 | 179 | POS_tdstCompletePosition *hPersoGlobalMatrix = hNewSuperObjPerso->p_stGlobalMatrix; 180 | 181 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 182 | lX = stParam.uParam.lValue; 183 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 184 | lY = stParam.uParam.lValue; 185 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 186 | lZ = stParam.uParam.lValue; 187 | 188 | /**************************************************************************** 189 | * SPT : superimposed ratio fix 190 | ****************************************************************************/ 191 | float ratio = CFG_xActualRatio / 0.75f; 192 | float addToCenter = (xVptWidth - (xVptWidth * ratio)) / 2 / xVptWidth; 193 | 194 | xX = ((float)lX / 1000.f * ratio) + addToCenter; 195 | xY = (float)lY / 1000.f; 196 | xZ = (float)lZ / 1000.f; 197 | /****************************************************************************/ 198 | 199 | GLI_vGet3DVertexFromScreenPos(&GAM_g_stEngineStructure->stFixViewportAttr, &stVertex, xX, xY, xZ); 200 | POS_fn_vSetTranslationVector(hPersoGlobalMatrix, &stVertex); 201 | 202 | hPersoGlobalMatrix->eType = MTH_C_Type_CompleteMatrix; 203 | /* SPT : superimposed ratio fix */ 204 | hPersoGlobalMatrix->stTransformMatrix.stCol_2.z = hPersoGlobalMatrix->stTransformMatrix.stCol_0.x = xVptHeight / 480.f * ratio; 205 | 206 | if ( hDynam ) 207 | { 208 | DNM_tdstDynamics *p_stDynamics = hDynam->p_stDynamics; 209 | MEC_vInitTranslation(p_stDynamics, hNewSuperObjPerso, &stVertex); 210 | } 211 | HIE_fn_vComputeNewRelativeMatrix(hNewSuperObjPerso); 212 | 213 | return p_stTree; 214 | } 215 | else if ( ulProcId == 410 ) 216 | { 217 | AI_fn_vGetUltraOperatorPerso(AI_fn_ucGetProcedureUltraOperator(ulProcId), p_SuperObjPerso, &hNewSuperObjPerso); 218 | 219 | MTH3D_tdstVector stVertex; 220 | DNM_tdstDynam *hDynam = HIE_M_hSuperObjectGetActor(hNewSuperObjPerso)->hDynam; 221 | HIE_fn_SO_vSetSuperimposedFlag(hNewSuperObjPerso); 222 | SCT_fn_vRemoveObjectInSectorList(hNewSuperObjPerso); 223 | 224 | POS_tdstCompletePosition *hPersoGlobalMatrix = hNewSuperObjPerso->p_stGlobalMatrix; 225 | 226 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 227 | stVertex.x = stParam.uParam.xValue; 228 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 229 | stVertex.y = stParam.uParam.xValue; 230 | p_stTree = AI_fn_p_stEvalTree(p_SuperObjPerso, p_stTree, &stParam); 231 | stVertex.z = stParam.uParam.xValue; 232 | 233 | POS_fn_vSetTranslationVector(hPersoGlobalMatrix,&stVertex); 234 | 235 | hPersoGlobalMatrix->eType = MTH_C_Type_CompleteMatrix; 236 | /* SPT : superimposed ratio fix */ 237 | float ratio = CFG_xActualRatio / 0.75f; 238 | hPersoGlobalMatrix->stTransformMatrix.stCol_2.z = hPersoGlobalMatrix->stTransformMatrix.stCol_0.x = xVptHeight / 480.f * ratio; 239 | 240 | if ( hDynam ) 241 | { 242 | DNM_tdstDynamics *p_stDynamics = hDynam->p_stDynamics; 243 | MEC_vInitTranslation(p_stDynamics, hNewSuperObjPerso, &stVertex); 244 | } 245 | HIE_fn_vComputeNewRelativeMatrix(hNewSuperObjPerso); 246 | 247 | return p_stTree; 248 | } 249 | 250 | return R2_fn_p_stSPOSuperimpoed(p_SuperObjPerso, p_stTree); 251 | } 252 | 253 | 254 | extern void *FIX_Code4Patch_Pos; 255 | extern void *FIX_Code4Patch_Size; 256 | 257 | void fn_vApplyPatch( void *pTarget, void *data, size_t size ) 258 | { 259 | DWORD dwOldProtect, dwNewProtect = PAGE_EXECUTE_READWRITE; 260 | VirtualProtect(pTarget, size, dwNewProtect, &dwOldProtect); 261 | memcpy(pTarget, data, size); 262 | VirtualProtect(pTarget, size, dwOldProtect, &dwNewProtect); 263 | } 264 | 265 | /* note: this does not account for overwritten instructions */ 266 | void fn_vApplyJmpToCode( void *pJmpAt, void *pCode ) 267 | { 268 | unsigned char code[] = { 0xB8, 0, 0, 0, 0, 0xFF, 0xE0 }; 269 | memcpy(code+1, &pCode, sizeof(void*)); 270 | 271 | fn_vApplyPatch(pJmpAt, code, sizeof(code)); 272 | } 273 | 274 | void FIX_fn_vPatchCode4( void ) 275 | { 276 | fn_vApplyJmpToCode((void*)0x475C7F, &FIX_Code4Patch_Pos); 277 | fn_vApplyJmpToCode((void*)0x475C96, &FIX_Code4Patch_Size); 278 | } 279 | 280 | 281 | /* 282 | * Functions 283 | */ 284 | 285 | void fn_vPreAttachHooks( void ) 286 | { 287 | //sprintf_s(szVersionString, sizeof(szVersionString), "/O200:%s v%s", GLI_szName, GLI_szVersion); 288 | snprintf(szVersionString, sizeof(szVersionString), "/C:%s %s", GLI_szName, GLI_szVersion); 289 | } 290 | 291 | void FIX_fn_vAttachHooks( void ) 292 | { 293 | fn_vPreAttachHooks(); 294 | 295 | DetourTransactionBegin(); 296 | DetourUpdateThread(GetCurrentThread()); 297 | 298 | DetourAttach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum); 299 | DetourAttach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame); 300 | DetourAttach((PVOID*)&R2_fn_szGetStringFromTextOrStringParam, (PVOID)FIX_fn_szGetStringFromTextOrStringParam); 301 | 302 | if ( CFG_bIsWidescreen && CFG_bPatchWidescreen ) 303 | { 304 | DetourAttach((PVOID*)&GLI_xAdjustCameraToViewport2, (PVOID)FIX_xAdjustCameraToViewport2); 305 | DetourAttach((PVOID*)&GLI_vDraw2DSpriteWithPercent, (PVOID)FIX_vDraw2DSpriteWithPercent); 306 | DetourAttach((PVOID*)&R2_fn_p_stSPOSuperimpoed, (PVOID)FIX_fn_p_stSPOSuperimpoed); 307 | FIX_fn_vPatchCode4(); 308 | } 309 | 310 | DetourTransactionCommit(); 311 | } 312 | 313 | void FIX_fn_vDetachHooks( void ) 314 | { 315 | DetourTransactionBegin(); 316 | DetourUpdateThread(GetCurrentThread()); 317 | 318 | DetourDetach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum); 319 | DetourDetach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame); 320 | DetourDetach((PVOID*)&R2_fn_szGetStringFromTextOrStringParam, (PVOID)FIX_fn_szGetStringFromTextOrStringParam); 321 | 322 | if ( CFG_bIsWidescreen && CFG_bPatchWidescreen ) 323 | { 324 | DetourDetach((PVOID *)&GLI_xAdjustCameraToViewport2, (PVOID)FIX_xAdjustCameraToViewport2); 325 | DetourDetach((PVOID *)&GLI_vDraw2DSpriteWithPercent, (PVOID)FIX_vDraw2DSpriteWithPercent); 326 | DetourDetach((PVOID *)&R2_fn_p_stSPOSuperimpoed, (PVOID)FIX_fn_p_stSPOSuperimpoed); 327 | } 328 | 329 | DetourTransactionCommit(); 330 | } 331 | 332 | /* 333 | * Minimal mode hooks 334 | */ 335 | 336 | BOOL g_bMinHooksAttached = FALSE; 337 | 338 | void FIX_fn_vAttachHooksMin( void *pInputEnum, void *pSuspendGame ) 339 | { 340 | R2_fn_InputEnum = pInputEnum; 341 | R2_fn_SuspendGame = pSuspendGame; 342 | 343 | DetourTransactionBegin(); 344 | DetourUpdateThread(GetCurrentThread()); 345 | 346 | DetourAttach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum); 347 | DetourAttach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame); 348 | 349 | DetourTransactionCommit(); 350 | 351 | g_bMinHooksAttached = TRUE; 352 | } 353 | 354 | void FIX_fn_vDetachHooksMin( void ) 355 | { 356 | if ( !g_bMinHooksAttached ) 357 | return; 358 | 359 | DetourTransactionBegin(); 360 | DetourUpdateThread(GetCurrentThread()); 361 | 362 | DetourDetach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum); 363 | DetourDetach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame); 364 | 365 | DetourTransactionCommit(); 366 | } 367 | 368 | 369 | void FIX_fn_vPatchFramerate( void ) 370 | { 371 | return; /* no longer necessary */ 372 | 373 | typedef struct 374 | { 375 | char _code1[54]; 376 | WORD nop1; 377 | char _code2[8]; 378 | WORD nop2; 379 | } FlipDeviceCode; 380 | 381 | FlipDeviceCode *lpCode = DetourCodeFromPointer((PVOID)Vd_GLI_DRV_vFlipDeviceWithSyncro, NULL); 382 | 383 | DWORD dwOldProtect; 384 | DWORD dwNewProtect = PAGE_EXECUTE_READWRITE; 385 | 386 | VirtualProtect(lpCode, sizeof(FlipDeviceCode), dwNewProtect, &dwOldProtect); 387 | 388 | lpCode->nop1 = lpCode->nop2 = (WORD)0x9090; 389 | 390 | VirtualProtect(lpCode, sizeof(FlipDeviceCode), dwOldProtect, &dwNewProtect); 391 | } 392 | 393 | void FIX_fn_vRemoveModeEnum( void ) 394 | { 395 | typedef struct 396 | { 397 | char _code1[251]; 398 | char nop1[30]; 399 | } DisplayConfigCode; 400 | 401 | DisplayConfigCode *lpCode = DetourCodeFromPointer((PVOID)Vd_GLI_DRV_fn_lGetAllDisplayConfig, NULL); 402 | 403 | DWORD dwOldProtect; 404 | DWORD dwNewProtect = PAGE_EXECUTE_READWRITE; 405 | 406 | VirtualProtect(lpCode, sizeof(DisplayConfigCode), dwNewProtect, &dwOldProtect); 407 | 408 | memset(lpCode->nop1, 0x90, sizeof(lpCode->nop1)); 409 | 410 | VirtualProtect(lpCode, sizeof(DisplayConfigCode), dwOldProtect, &dwNewProtect); 411 | } 412 | 413 | 414 | /* 415 | * Special widescreen exports 416 | */ 417 | 418 | BOOL GLI_FIX_bIsWidescreen( void ) 419 | { 420 | return ( CFG_bIsWidescreen && CFG_bPatchWidescreen ); 421 | } 422 | 423 | float GLI_FIX_xGetActualRatio( void ) 424 | { 425 | return CFG_xActualRatio; 426 | } 427 | 428 | void GLI_FIX_vGetActualDisplayMode( unsigned long *p_ulWidthOut, unsigned long *p_ulHeightOut ) 429 | { 430 | *p_ulWidthOut = CFG_stActualDispMode.dwWidth; 431 | *p_ulHeightOut = CFG_stActualDispMode.dwHeight; 432 | } 433 | -------------------------------------------------------------------------------- /GliFixVf/fix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | /* 7 | * DirectInput 8 | */ 9 | 10 | #define DIENUM_STOP 0 11 | #define DIENUM_CONTINUE 1 12 | 13 | typedef BOOL (CALLBACK *DIEnumDevicesCallback)( LPVOID lpddi, LPVOID pvRef ); 14 | 15 | 16 | /* 17 | * Detours 18 | */ 19 | 20 | void FIX_fn_vAttachHooks( void ); 21 | void FIX_fn_vDetachHooks( void ); 22 | 23 | void FIX_fn_vAttachHooksMin( void *pInputEnum, void *pSuspendGame ); 24 | void FIX_fn_vDetachHooksMin( void ); 25 | 26 | void FIX_fn_vPatchFramerate( void ); 27 | void FIX_fn_vRemoveModeEnum( void ); 28 | 29 | 30 | /* 31 | * Special widescreen exports 32 | */ 33 | 34 | EXPORT BOOL GLI_FIX_bIsWidescreen( void ); 35 | EXPORT float GLI_FIX_xGetActualRatio( void ); 36 | EXPORT void GLI_FIX_vGetActualDisplayMode( unsigned long *p_ulWidthOut, unsigned long *p_ulHeightOut ); 37 | -------------------------------------------------------------------------------- /GliFixVf/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define EXPORT __declspec(dllexport) 10 | 11 | #define ACP_NO_DRV 12 | #define ACP_NOX 13 | //#include 14 | -------------------------------------------------------------------------------- /GliFixVf/glide2types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #define FXTRUE 1 5 | #define FXFALSE 0 6 | 7 | #define GLIDE_NUM_TMU 2 8 | 9 | #define FX_CALL __stdcall 10 | 11 | 12 | typedef unsigned char FxU8; 13 | typedef signed char FxI8; 14 | typedef unsigned short FxU16; 15 | typedef signed short FxI16; 16 | typedef signed long FxI32; 17 | typedef unsigned long FxU32; 18 | typedef int FxBool; 19 | typedef float FxFloat; 20 | typedef double FxDouble; 21 | 22 | 23 | typedef struct GrTmuVertex 24 | { 25 | float sow; 26 | float tow; 27 | float oow; 28 | } 29 | GrTmuVertex; 30 | 31 | typedef struct GrVertex 32 | { 33 | float x, y, z; 34 | float r, g, b; 35 | float ooz; 36 | float a; 37 | float oow; 38 | GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; 39 | } 40 | GrVertex; 41 | 42 | 43 | #define GR_COMBINE_FUNCTION_ZERO 0x0 44 | #define GR_COMBINE_FUNCTION_NONE GR_COMBINE_FUNCTION_ZERO 45 | #define GR_COMBINE_FUNCTION_LOCAL 0x1 46 | #define GR_COMBINE_FUNCTION_LOCAL_ALPHA 0x2 47 | #define GR_COMBINE_FUNCTION_SCALE_OTHER 0x3 48 | #define GR_COMBINE_FUNCTION_BLEND_OTHER GR_COMBINE_FUNCTION_SCALE_OTHER 49 | #define GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL 0x4 50 | #define GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA 0x5 51 | #define GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL 0x6 52 | #define GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL 0x7 53 | #define GR_COMBINE_FUNCTION_BLEND GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL 54 | #define GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA 0x8 55 | #define GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL 0x9 56 | #define GR_COMBINE_FUNCTION_BLEND_LOCAL GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL 57 | #define GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA 0x10 58 | 59 | #define GR_COMBINE_FACTOR_ZERO 0x0 60 | #define GR_COMBINE_FACTOR_NONE GR_COMBINE_FACTOR_ZERO 61 | #define GR_COMBINE_FACTOR_LOCAL 0x1 62 | #define GR_COMBINE_FACTOR_OTHER_ALPHA 0x2 63 | #define GR_COMBINE_FACTOR_LOCAL_ALPHA 0x3 64 | #define GR_COMBINE_FACTOR_TEXTURE_ALPHA 0x4 65 | #define GR_COMBINE_FACTOR_DETAIL_FACTOR GR_COMBINE_FACTOR_TEXTURE_ALPHA 66 | #define GR_COMBINE_FACTOR_LOD_FRACTION 0x5 67 | #define GR_COMBINE_FACTOR_ONE 0x8 68 | #define GR_COMBINE_FACTOR_ONE_MINUS_LOCAL 0x9 69 | #define GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA 0xa 70 | #define GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA 0xb 71 | #define GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA 0xc 72 | #define GR_COMBINE_FACTOR_ONE_MINUS_DETAIL_FACTOR GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA 73 | #define GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION 0xd 74 | 75 | #define GR_COMBINE_LOCAL_ITERATED 0x0 76 | #define GR_COMBINE_LOCAL_CONSTANT 0x1 77 | #define GR_COMBINE_LOCAL_NONE GR_COMBINE_LOCAL_CONSTANT 78 | #define GR_COMBINE_LOCAL_DEPTH 0x2 79 | 80 | #define GR_COMBINE_OTHER_ITERATED 0x0 81 | #define GR_COMBINE_OTHER_TEXTURE 0x1 82 | #define GR_COMBINE_OTHER_CONSTANT 0x2 83 | #define GR_COMBINE_OTHER_NONE GR_COMBINE_OTHER_CONSTANT 84 | 85 | #define GR_BLEND_ZERO 0x0 86 | #define GR_BLEND_SRC_ALPHA 0x1 87 | #define GR_BLEND_SRC_COLOR 0x2 88 | #define GR_BLEND_DST_COLOR GR_BLEND_SRC_COLOR 89 | #define GR_BLEND_DST_ALPHA 0x3 90 | #define GR_BLEND_ONE 0x4 91 | #define GR_BLEND_ONE_MINUS_SRC_ALPHA 0x5 92 | #define GR_BLEND_ONE_MINUS_SRC_COLOR 0x6 93 | #define GR_BLEND_ONE_MINUS_DST_COLOR GR_BLEND_ONE_MINUS_SRC_COLOR 94 | #define GR_BLEND_ONE_MINUS_DST_ALPHA 0x7 95 | #define GR_BLEND_RESERVED_8 0x8 96 | #define GR_BLEND_RESERVED_9 0x9 97 | #define GR_BLEND_RESERVED_A 0xa 98 | #define GR_BLEND_RESERVED_B 0xb 99 | #define GR_BLEND_RESERVED_C 0xc 100 | #define GR_BLEND_RESERVED_D 0xd 101 | #define GR_BLEND_RESERVED_E 0xe 102 | #define GR_BLEND_ALPHA_SATURATE 0xf 103 | #define GR_BLEND_PREFOG_COLOR GR_BLEND_ALPHA_SATURATE 104 | 105 | #define GR_COLORCOMBINE_ZERO 0x0 106 | #define GR_COLORCOMBINE_CCRGB 0x1 107 | #define GR_COLORCOMBINE_ITRGB 0x2 108 | #define GR_COLORCOMBINE_ITRGB_DELTA0 0x3 109 | #define GR_COLORCOMBINE_DECAL_TEXTURE 0x4 110 | #define GR_COLORCOMBINE_TEXTURE_TIMES_CCRGB 0x5 111 | #define GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB 0x6 112 | #define GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB_DELTA0 0x7 113 | #define GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB_ADD_ALPHA 0x8 114 | #define GR_COLORCOMBINE_TEXTURE_TIMES_ALPHA 0x9 115 | #define GR_COLORCOMBINE_TEXTURE_TIMES_ALPHA_ADD_ITRGB 0xa 116 | #define GR_COLORCOMBINE_TEXTURE_ADD_ITRGB 0xb 117 | #define GR_COLORCOMBINE_TEXTURE_SUB_ITRGB 0xc 118 | #define GR_COLORCOMBINE_CCRGB_BLEND_ITRGB_ON_TEXALPHA 0xd 119 | #define GR_COLORCOMBINE_DIFF_SPEC_A 0xe 120 | #define GR_COLORCOMBINE_DIFF_SPEC_B 0xf 121 | #define GR_COLORCOMBINE_ONE 0x10 122 | 123 | 124 | extern void (FX_CALL *grAlphaBlendFunction)( FxI32 rgb_sf, FxI32 rgb_df, FxI32 alpha_sf, FxI32 alpha_df ); 125 | extern void (FX_CALL *grAlphaCombine)( FxI32 function, FxI32 factor,FxI32 local, FxI32 other,FxBool invert ); 126 | extern void (FX_CALL *guColorCombineFunction)( FxI32 fnc ); 127 | extern void (FX_CALL *grDrawLine)( const GrVertex *v1, const GrVertex *v2 ); 128 | 129 | extern FxI32 *Vd_GLI_GLIDE1_xTmuNumber; 130 | -------------------------------------------------------------------------------- /GliFixVf/imports.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "imports.h" 3 | #include "glide2types.h" 4 | 5 | 6 | /* 7 | * GLI Library imports 8 | */ 9 | 10 | /**** COMMON ****/ 11 | long (*Vd_GLI_DRV_lGetDllInfo)( char const *szName, void *pData ); 12 | long (*Vd_GLI_DRV_lSetCommonData)( char const *szName, void *pData ); 13 | long (*Vd_GLI_DRV_lSetCommonFct)( char const *szName, tdfn_CommonFct pData ); 14 | 15 | /**** INIT ****/ 16 | void (*Vd_GLI_DRV_vFlipDevice)( int lWaitFrames ); 17 | void (*Vd_GLI_DRV_vFlipDeviceWithSyncro)( void ); 18 | void (*Vd_GLI_DRV_vClearDevice)( BOOL bZBuffer, BOOL bColorBuffer, unsigned long ulColor ); 19 | void (*Vd_GLI_DRV_xInitDriver)( HWND hWnd, BOOL bFullscreen, long lWidth, long lHeight, int lBpp ); 20 | void (*Vd_GLI_DRV_vCloseDriver)( void ); 21 | void (*Vd_GLI_DRV_vClearZBufferRegion)( long lXStart, long lXEnd, long lYStart, long lYEnd ); 22 | long (*Vd_GLI_DRV_hChangeMode)( BOOL bFullscreen, long lWidth, long lHeight, long lBpp ); 23 | BOOL (*Vd_GLI_DRV_bLockDevice)( void **pp_vVirtualScreen, long *p_lPitch ); 24 | BOOL (*Vd_GLI_DRV_bUnlockDevice)( void ); 25 | BOOL (*Vd_GLI_DRV_bWindowedModeIsOptimized)( void ); 26 | void (*Vd_GLI_DRV_vOptimizedWindowedMode)( void ); 27 | void (*Vd_GLI_DRV_vNonOptimizedWindowedMode)( void ); 28 | BOOL (*Vd_GLI_DRV_bPrepareForGliWindowed)( HWND hWnd ); 29 | void (*Vd_GLI_DRV_vPrepareForGliFullScreen)( HWND hWnd ); 30 | void (*Vd_GLI_DRV_vActivateGli)( HWND hWnd, BOOL bActivate ); 31 | void (*Vd_GLI_DRV_vReadaptDisplay)( void ); 32 | long (*Vd_GLI_DRV_fn_lGetAllDisplayConfig)( tdfn_lAddDisplayInfo p_fn_lAddDisplayInfo ); 33 | long (*Vd_GLI_DRV_fnl_EnumModes)( char *szDriverName, char *szDeviceName ); 34 | 35 | /**** HDWTEX ****/ 36 | void (*Vd_GLI_DRV_vDownLoadTextures)( long bRestore, long lTextureMode, BOOL bReloading ); 37 | void (*Vd_GLI_DRV_vUnLoadTextures)( void ); 38 | long (*Vd_GLI_DRV_lGetSizeOfTexture)( GLI_tdstTexture *p_stTexture ); 39 | 40 | /**** DOMAT ****/ 41 | void (*Vd_GLI_DRV_vDoOpaqueTextureSelection)( GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 42 | void (*Vd_GLI_DRV_vWrite16bBitmapToBackBuffer)( 43 | void *p_vSourceBuffer, 44 | long lWidth, 45 | long lHeight, 46 | long lDestLeft, 47 | long lDestTop, 48 | long lDestRight, 49 | long lDestBottom 50 | ); 51 | void (*Vd_GLI_DRV_vAddBlackPolygon)( long lLeft, long lTop, long lRight, long lBottom ); 52 | void (*Vd_GLI_DRV_vNoBlackPolygon)( void ); 53 | void (*Vd_GLI_DRV_vComputeFogEffect)( GLI_tdstInternalGlobalValuesFor3dEngine *p_stBG ); 54 | BOOL (*Vd_GLI_DRV_bBeginScene)( void ); 55 | BOOL (*Vd_GLI_DRV_bEndScene)( void ); 56 | 57 | /**** ACCES ****/ 58 | void (*Vd_GLI_DRV_vSendSpriteToClip)( 59 | GLI_tdstAligned2DVector *a4_st2DVertex, 60 | float xZ, 61 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 62 | ); 63 | void (*Vd_GLI_DRV_vSendSpriteToClipWithUV)( 64 | GLI_tdstAligned2DVector *a4_st2DVertex, 65 | float *a8_stUVVertex, 66 | float xZ, 67 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 68 | ); 69 | void (*Vd_GLI_DRV_vSendSpriteToClipWithColors)( 70 | GLI_tdstAligned2DVector *a4_st2DVertex, 71 | void *_Colors, 72 | float xZ, 73 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 74 | ); 75 | void (*Vd_GLI_DRV_vSendSingleLineToClip)( 76 | GLD_tdstViewportAttributes *p_stVpt, 77 | GLI_tdstAligned3DVector *p_stVertex1, 78 | GLI_tdstAligned2DVector *p_st2DVertex1, 79 | GLI_tdstAligned3DVector *p_stVertex2, 80 | GLI_tdstAligned2DVector *p_st2DVertex2, 81 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT, 82 | long lDrawModeMask, 83 | GEO_tdstColor *p_stColor 84 | ); 85 | 86 | /**** CLIP TRIANGLES ****/ 87 | void (*Vd_GLI_DRV_xClearViewingList)( void ); 88 | void (*Vd_GLI_DRV_xSendListToViewport)( GLD_tdstViewportAttributes *p_stVpt ); 89 | void (*Vd_GLI_DRV_vSetZClip)( float xZClip, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 90 | void (*Vd_GLI_DRV_vSetClipWindow)( 91 | float fXMin, 92 | float fXMax, 93 | float fYMin, 94 | float fYMax, 95 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 96 | ); 97 | void (*Vd_GLI_DRV_xSendElementTIToClip_TRIANGLES)( 98 | GEO_tdstElementIndexedTriangles *p_stLocalElementIndexedTriangle, 99 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 100 | ); 101 | void (*Vd_GLI_DRV_xSendSingleTriangleToClip_TRIANGLES)( 102 | GLI_tdstAligned2DVector *a3_st2DVertex, 103 | ACP_tdst2DUVValues *a3_stUV, 104 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 105 | ); 106 | 107 | 108 | /* 109 | * Code starts here 110 | */ 111 | 112 | 113 | char IMP_cWhatBuildWeUsing = 0; 114 | 115 | HMODULE hGliVd = NULL; 116 | 117 | 118 | /** in glide2types.h **/ 119 | FxI32 *Vd_GLI_GLIDE1_xTmuNumber = 0; 120 | void (FX_CALL *grAlphaBlendFunction)( FxI32 rgb_sf, FxI32 rgb_df, FxI32 alpha_sf, FxI32 alpha_df ) = NULL; 121 | void (FX_CALL *grAlphaCombine)( FxI32 function, FxI32 factor, FxI32 local, FxI32 other, FxBool invert ) = NULL; 122 | void (FX_CALL *guColorCombineFunction)( FxI32 fnc ) = NULL; 123 | void (FX_CALL *grDrawLine)( const GrVertex *v1, const GrVertex *v2 ) = NULL; 124 | 125 | void fn_vLoadGlide2Lib( void ) 126 | { 127 | HMODULE hGlide2 = LoadLibrary("glide2x.dll"); 128 | if ( !hGlide2 ) 129 | { 130 | MessageBox(NULL, "Cannot load Glide2x library.", "Error", MB_OK | MB_ICONERROR); 131 | ExitProcess(1); 132 | } 133 | 134 | grAlphaBlendFunction = (void *)GetProcAddress(hGlide2, "_grAlphaBlendFunction@16"); 135 | grAlphaCombine = (void *)GetProcAddress(hGlide2, "_grAlphaCombine@20"); 136 | guColorCombineFunction = (void *)GetProcAddress(hGlide2, "_guColorCombineFunction@4"); 137 | grDrawLine = (void *)GetProcAddress(hGlide2, "_grDrawLine@8"); 138 | } 139 | 140 | 141 | void *fn_lpGetFn( LPCSTR szName ) 142 | { 143 | return (void*)GetProcAddress(hGliVd, szName); 144 | } 145 | 146 | void IMP_fn_vLoadGliLibrary( void ) 147 | { 148 | IMP_cWhatBuildWeUsing = 'f'; 149 | hGliVd = LoadLibrary(".\\DLL\\GliVd1vf.dll"); 150 | 151 | if ( !hGliVd ) 152 | { 153 | IMP_cWhatBuildWeUsing = 'r'; 154 | hGliVd = LoadLibrary(".\\DLL\\GliVd1vr.dll"); 155 | } 156 | 157 | if ( !hGliVd ) 158 | { 159 | MessageBox(NULL, "Cannot load GLI library.", "Error", MB_OK | MB_ICONERROR); 160 | ExitProcess(1); 161 | } 162 | 163 | Vd_GLI_DRV_lGetDllInfo = fn_lpGetFn("GLI_DRV_lGetDllInfo"); 164 | Vd_GLI_DRV_fn_lGetAllDisplayConfig = fn_lpGetFn("GLI_DRV_fn_lGetAllDisplayConfig"); 165 | Vd_GLI_DRV_lSetCommonData = fn_lpGetFn("GLI_DRV_lSetCommonData"); 166 | Vd_GLI_DRV_lSetCommonFct = fn_lpGetFn("GLI_DRV_lSetCommonFct"); 167 | Vd_GLI_DRV_fnl_EnumModes = fn_lpGetFn("GLI_DRV_fnl_EnumModes"); 168 | Vd_GLI_DRV_xInitDriver = fn_lpGetFn("GLI_DRV_xInitDriver"); 169 | Vd_GLI_DRV_vCloseDriver = fn_lpGetFn("GLI_DRV_vCloseDriver"); 170 | Vd_GLI_DRV_bBeginScene = fn_lpGetFn("GLI_DRV_bBeginScene"); 171 | Vd_GLI_DRV_bEndScene = fn_lpGetFn("GLI_DRV_bEndScene"); 172 | Vd_GLI_DRV_bLockDevice = fn_lpGetFn("GLI_DRV_bLockDevice"); 173 | Vd_GLI_DRV_bUnlockDevice = fn_lpGetFn("GLI_DRV_bUnlockDevice"); 174 | Vd_GLI_DRV_vClearDevice = fn_lpGetFn("GLI_DRV_vClearDevice"); 175 | Vd_GLI_DRV_vFlipDevice = fn_lpGetFn("GLI_DRV_vFlipDevice"); 176 | Vd_GLI_DRV_vFlipDeviceWithSyncro = fn_lpGetFn("GLI_DRV_vFlipDeviceWithSyncro"); 177 | Vd_GLI_DRV_vDownLoadTextures = fn_lpGetFn("GLI_DRV_vDownLoadTextures"); 178 | Vd_GLI_DRV_vUnLoadTextures = fn_lpGetFn("GLI_DRV_vUnLoadTextures"); 179 | Vd_GLI_DRV_lGetSizeOfTexture = fn_lpGetFn("GLI_DRV_lGetSizeOfTexture"); 180 | Vd_GLI_DRV_vDoOpaqueTextureSelection = fn_lpGetFn("GLI_DRV_vDoOpaqueTextureSelection"); 181 | Vd_GLI_DRV_hChangeMode = fn_lpGetFn("GLI_DRV_hChangeMode"); 182 | Vd_GLI_DRV_bWindowedModeIsOptimized = fn_lpGetFn("GLI_DRV_bWindowedModeIsOptimized"); 183 | Vd_GLI_DRV_vOptimizedWindowedMode = fn_lpGetFn("GLI_DRV_vOptimizedWindowedMode"); 184 | Vd_GLI_DRV_vNonOptimizedWindowedMode = fn_lpGetFn("GLI_DRV_vNonOptimizedWindowedMode"); 185 | Vd_GLI_DRV_bPrepareForGliWindowed = fn_lpGetFn("GLI_DRV_bPrepareForGliWindowed"); 186 | Vd_GLI_DRV_vPrepareForGliFullScreen = fn_lpGetFn("GLI_DRV_vPrepareForGliFullScreen"); 187 | Vd_GLI_DRV_vActivateGli = fn_lpGetFn("GLI_DRV_vActivateGli"); 188 | Vd_GLI_DRV_vReadaptDisplay = fn_lpGetFn("GLI_DRV_vReadaptDisplay"); 189 | Vd_GLI_DRV_vAddBlackPolygon = fn_lpGetFn("GLI_DRV_vAddBlackPolygon"); 190 | Vd_GLI_DRV_vNoBlackPolygon = fn_lpGetFn("GLI_DRV_vNoBlackPolygon"); 191 | Vd_GLI_DRV_vSetZClip = fn_lpGetFn("GLI_DRV_vSetZClip"); 192 | Vd_GLI_DRV_vSetClipWindow = fn_lpGetFn("GLI_DRV_vSetClipWindow"); 193 | Vd_GLI_DRV_vSendSingleLineToClip = fn_lpGetFn("GLI_DRV_vSendSingleLineToClip"); 194 | Vd_GLI_DRV_vSendSpriteToClip = fn_lpGetFn("GLI_DRV_vSendSpriteToClip"); 195 | Vd_GLI_DRV_vSendSpriteToClipWithColors = fn_lpGetFn("GLI_DRV_vSendSpriteToClipWithColors"); 196 | Vd_GLI_DRV_vSendSpriteToClipWithUV = fn_lpGetFn("GLI_DRV_vSendSpriteToClipWithUV"); 197 | Vd_GLI_DRV_xSendElementTIToClip_TRIANGLES = fn_lpGetFn("GLI_DRV_xSendElementTIToClip_TRIANGLES"); 198 | Vd_GLI_DRV_xSendSingleTriangleToClip_TRIANGLES = fn_lpGetFn("GLI_DRV_xSendSingleTriangleToClip_TRIANGLES"); 199 | Vd_GLI_DRV_xClearViewingList = fn_lpGetFn("GLI_DRV_xClearViewingList"); 200 | Vd_GLI_DRV_xSendListToViewport = fn_lpGetFn("GLI_DRV_xSendListToViewport"); 201 | Vd_GLI_DRV_vClearZBufferRegion = fn_lpGetFn("GLI_DRV_vClearZBufferRegion"); 202 | Vd_GLI_DRV_vComputeFogEffect = fn_lpGetFn("GLI_DRV_vComputeFogEffect"); 203 | Vd_GLI_DRV_vWrite16bBitmapToBackBuffer = fn_lpGetFn("GLI_DRV_vWrite16bBitmapToBackBuffer"); 204 | 205 | if ( IMP_cWhatBuildWeUsing == 'f' ) 206 | { 207 | unsigned char *hGliBase = (unsigned char *)hGliVd; 208 | Vd_GLI_GLIDE1_xTmuNumber = (void *)(hGliBase + 0xB704); 209 | 210 | fn_vLoadGlide2Lib(); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /GliFixVf/imports.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | #include "devinfo.h" 5 | #include "defs.h" 6 | 7 | 8 | void IMP_fn_vLoadGliLibrary( void ); 9 | 10 | extern char IMP_cWhatBuildWeUsing; 11 | 12 | 13 | /* 14 | * GLI Library imports 15 | */ 16 | 17 | /**** COMMON ****/ 18 | extern long (*Vd_GLI_DRV_lGetDllInfo)( char const *szName, void *pData ); 19 | extern long (*Vd_GLI_DRV_lSetCommonData)( char const *szName, void *pData ); 20 | extern long (*Vd_GLI_DRV_lSetCommonFct)( char const *szName, tdfn_CommonFct pData ); 21 | 22 | /**** INIT ****/ 23 | extern void (*Vd_GLI_DRV_vFlipDevice)( int lWaitFrames ); 24 | extern void (*Vd_GLI_DRV_vFlipDeviceWithSyncro)( void ); 25 | extern void (*Vd_GLI_DRV_vClearDevice)( BOOL bZBuffer, BOOL bColorBuffer, unsigned long ulColor ); 26 | extern void (*Vd_GLI_DRV_xInitDriver)( HWND hWnd, BOOL bFullscreen, long lWidth, long lHeight, int lBpp ); 27 | extern void (*Vd_GLI_DRV_vCloseDriver)( void ); 28 | extern void (*Vd_GLI_DRV_vClearZBufferRegion)( long lXStart, long lXEnd, long lYStart, long lYEnd ); 29 | extern long (*Vd_GLI_DRV_hChangeMode)( BOOL bFullscreen, long lWidth, long lHeight, long lBpp ); 30 | extern BOOL (*Vd_GLI_DRV_bLockDevice)( void **pp_vVirtualScreen, long *p_lPitch ); 31 | extern BOOL (*Vd_GLI_DRV_bUnlockDevice)( void ); 32 | extern BOOL (*Vd_GLI_DRV_bWindowedModeIsOptimized)( void ); 33 | extern void (*Vd_GLI_DRV_vOptimizedWindowedMode)( void ); 34 | extern void (*Vd_GLI_DRV_vNonOptimizedWindowedMode)( void ); 35 | extern BOOL (*Vd_GLI_DRV_bPrepareForGliWindowed)( HWND hWnd ); 36 | extern void (*Vd_GLI_DRV_vPrepareForGliFullScreen)( HWND hWnd ); 37 | extern void (*Vd_GLI_DRV_vActivateGli)( HWND hWnd, BOOL bActivate ); 38 | extern void (*Vd_GLI_DRV_vReadaptDisplay)( void ); 39 | extern long (*Vd_GLI_DRV_fn_lGetAllDisplayConfig)( tdfn_lAddDisplayInfo p_fn_lAddDisplayInfo ); 40 | extern long (*Vd_GLI_DRV_fnl_EnumModes)( char *szDriverName, char *szDeviceName ); 41 | 42 | /**** HDWTEX ****/ 43 | extern void (*Vd_GLI_DRV_vDownLoadTextures)( long bRestore, long lTextureMode, BOOL bReloading ); 44 | extern void (*Vd_GLI_DRV_vUnLoadTextures)( void ); 45 | extern long (*Vd_GLI_DRV_lGetSizeOfTexture)( GLI_tdstTexture *p_stTexture ); 46 | 47 | /**** DOMAT ****/ 48 | extern void (*Vd_GLI_DRV_vDoOpaqueTextureSelection)( GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 49 | extern void (*Vd_GLI_DRV_vWrite16bBitmapToBackBuffer)( 50 | void *p_vSourceBuffer, 51 | long lWidth, 52 | long lHeight, 53 | long lDestLeft, 54 | long lDestTop, 55 | long lDestRight, 56 | long lDestBottom 57 | ); 58 | extern void (*Vd_GLI_DRV_vAddBlackPolygon)( long lLeft, long lTop, long lRight, long lBottom ); 59 | extern void (*Vd_GLI_DRV_vNoBlackPolygon)( void ); 60 | extern void (*Vd_GLI_DRV_vComputeFogEffect)( GLI_tdstInternalGlobalValuesFor3dEngine *p_stBG ); 61 | extern BOOL (*Vd_GLI_DRV_bBeginScene)( void ); 62 | extern BOOL (*Vd_GLI_DRV_bEndScene)( void ); 63 | 64 | /**** ACCES ****/ 65 | extern void (*Vd_GLI_DRV_vSendSpriteToClip)( 66 | GLI_tdstAligned2DVector *a4_st2DVertex, 67 | float xZ, 68 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 69 | ); 70 | extern void (*Vd_GLI_DRV_vSendSpriteToClipWithUV)( 71 | GLI_tdstAligned2DVector *a4_st2DVertex, 72 | float *a8_stUVVertex, 73 | float xZ, 74 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 75 | ); 76 | extern void (*Vd_GLI_DRV_vSendSpriteToClipWithColors)( 77 | GLI_tdstAligned2DVector *a4_st2DVertex, 78 | void *_Colors, 79 | float xZ, 80 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 81 | ); 82 | extern void (*Vd_GLI_DRV_vSendSingleLineToClip)( 83 | GLD_tdstViewportAttributes *p_stVpt, 84 | GLI_tdstAligned3DVector *p_stVertex1, 85 | GLI_tdstAligned2DVector *p_st2DVertex1, 86 | GLI_tdstAligned3DVector *p_stVertex2, 87 | GLI_tdstAligned2DVector *p_st2DVertex2, 88 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT, 89 | long lDrawModeMask, 90 | GEO_tdstColor *p_stColor 91 | ); 92 | 93 | /**** CLIP TRIANGLES ****/ 94 | extern void (*Vd_GLI_DRV_xClearViewingList)( void ); 95 | extern void (*Vd_GLI_DRV_xSendListToViewport)( GLD_tdstViewportAttributes *p_stVpt ); 96 | extern void (*Vd_GLI_DRV_vSetZClip)( float xZClip, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT ); 97 | extern void (*Vd_GLI_DRV_vSetClipWindow)( 98 | float fXMin, 99 | float fXMax, 100 | float fYMin, 101 | float fYMax, 102 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 103 | ); 104 | extern void (*Vd_GLI_DRV_xSendElementTIToClip_TRIANGLES)( 105 | GEO_tdstElementIndexedTriangles *p_stLocalElementIndexedTriangle, 106 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 107 | ); 108 | extern void (*Vd_GLI_DRV_xSendSingleTriangleToClip_TRIANGLES)( 109 | GLI_tdstAligned2DVector *a3_st2DVertex, 110 | ACP_tdst2DUVValues *a3_stUV, 111 | GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT 112 | ); 113 | -------------------------------------------------------------------------------- /GliFixVf/patch.asm: -------------------------------------------------------------------------------- 1 | .586 2 | .MODEL FLAT, C 3 | 4 | PUBLIC FIX_Code4Patch_Pos 5 | PUBLIC FIX_Code4Patch_Size 6 | 7 | tdstDisplayMode STRUCT 8 | dwWidth dd ? 9 | dwHeight dd ? 10 | tdstDisplayMode ENDS 11 | 12 | EXTERN CFG_stDispMode :tdstDisplayMode 13 | EXTERN CFG_stActualDispMode :tdstDisplayMode 14 | EXTERN CFG_xActualRatio :REAL4 15 | 16 | .DATA 17 | ALIGN 4 18 | xOnePer1000 REAL4 0.001f 19 | xOrigRatio REAL4 0.75f 20 | xOrigHeight REAL4 480.f 21 | xTwo REAL4 2.f 22 | 23 | 24 | pJumpTo_Pos dd 475C88h 25 | pJumpTo_Size dd 475C9Eh 26 | 27 | .CODE 28 | 29 | ALIGN 4 30 | FIX_Code4Patch_Pos: 31 | fmul xOnePer1000 32 | ;; ratio = (xActualVptHeight / xActualVptWidth) / 0.75 33 | fld CFG_xActualRatio 34 | fdiv xOrigRatio 35 | ;; addToCenter = (1 - ratio) / 2 36 | fld1 37 | fsub st(0), st(1) 38 | fdiv xTwo 39 | ;; (x * 0.001) * ratio + addToCenter 40 | fxch 41 | fmulp st(2), st(0) 42 | faddp st(1), st(0) 43 | fstp dword ptr [esp] 44 | jmp ds:pJumpTo_Pos 45 | 46 | ALIGN 4 47 | FIX_Code4Patch_Size: 48 | fild dword ptr CFG_stDispMode.dwHeight 49 | fdiv xOrigHeight 50 | ;; ratio = (xActualVptHeight / xActualVptWidth) / 0.75 51 | fld CFG_xActualRatio 52 | fdiv xOrigRatio 53 | ;; (xActualVptHeight / 480) * ratio 54 | fmulp st(1), st(0) 55 | sub esp, 4 56 | fstp dword ptr [esp] 57 | pop eax 58 | mov ecx, eax 59 | jmp ds:pJumpTo_Size 60 | 61 | END 62 | -------------------------------------------------------------------------------- /GliFixVf/r2fn.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "r2fn.h" 3 | 4 | 5 | /* 6 | * Function pointers 7 | */ 8 | 9 | DIEnumDevicesCallback R2_fn_InputEnum = OFFSET(0x495170); 10 | BOOL (*R2_fn_SuspendGame)() = OFFSET(0x4016E0); 11 | 12 | char * (*R2_fn_szGetStringFromTextOrStringParam)( void *param ) = OFFSET(0x4829D0); 13 | 14 | AI_tdstNodeInterpret * (*R2_fn_p_stSPOSuperimpoed)( HIE_tdstSuperObject * p_SuperObjPerso, AI_tdstNodeInterpret *p_stTree ) = OFFSET(0x4710C0); 15 | -------------------------------------------------------------------------------- /GliFixVf/r2fn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | #include "fix.h" 5 | 6 | #include 7 | 8 | 9 | /* 10 | * Function pointers 11 | */ 12 | 13 | extern DIEnumDevicesCallback R2_fn_InputEnum; 14 | extern BOOL (*R2_fn_SuspendGame)(); 15 | 16 | extern char * (*R2_fn_szGetStringFromTextOrStringParam)( void *param ); 17 | 18 | extern AI_tdstNodeInterpret * (*R2_fn_p_stSPOSuperimpoed)( HIE_tdstSuperObject * p_SuperObjPerso, AI_tdstNodeInterpret *p_stTree ); 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Spitfire_x86 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R2FixCfg/R2FixCfg.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 16.0 42 | Win32Proj 43 | {5552f301-c48c-4c38-9453-c68da5d25f4f} 44 | R2FixCfg 45 | 10.0 46 | 47 | 48 | 49 | Application 50 | true 51 | v143 52 | NotSet 53 | 54 | 55 | Application 56 | false 57 | v143 58 | true 59 | NotSet 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | 81 | Level3 82 | true 83 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 84 | true 85 | CompileAsC 86 | 87 | 88 | Windows 89 | true 90 | 91 | 92 | false 93 | 94 | 95 | 96 | 97 | Level3 98 | true 99 | true 100 | true 101 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 102 | true 103 | CompileAsC 104 | MultiThreadedDLL 105 | 106 | 107 | Windows 108 | true 109 | true 110 | true 111 | 112 | 113 | false 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /R2FixCfg/R2FixCfg.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | 70 | 71 | Resource Files 72 | 73 | 74 | Resource Files 75 | 76 | 77 | 78 | 79 | Resource Files 80 | 81 | 82 | -------------------------------------------------------------------------------- /R2FixCfg/Rayman2D.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spitfirex86/Ray2Fix/92cfeaf4c39d56a561e2f0dc11c884a99c739f30/R2FixCfg/Rayman2D.ico -------------------------------------------------------------------------------- /R2FixCfg/Resource.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // Polish (Poland) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) 19 | LANGUAGE LANG_POLISH, SUBLANG_DEFAULT 20 | #pragma code_page(1250) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | #endif // Polish (Poland) resources 48 | ///////////////////////////////////////////////////////////////////////////// 49 | 50 | 51 | ///////////////////////////////////////////////////////////////////////////// 52 | // English (United States) resources 53 | 54 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 55 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 56 | #pragma code_page(1252) 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Icon 61 | // 62 | 63 | // Icon with lowest ID value placed first to ensure application icon 64 | // remains consistent on all systems. 65 | IDI_GLI_ICON ICON "glidetect.ico" 66 | 67 | IDI_RAYHEAD ICON "Rayman2D.ico" 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | // 72 | // Dialog 73 | // 74 | 75 | IDD_MAIN DIALOGEX 0, 0, 267, 236 76 | STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU 77 | EXSTYLE WS_EX_APPWINDOW 78 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 79 | BEGIN 80 | CONTROL "Show advanced settings",IDC_ADVANCED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,220,94,10 81 | DEFPUSHBUTTON "OK",IDOK,159,218,50,14 82 | PUSHBUTTON "Cancel",IDCANCEL,213,218,50,14 83 | CONTROL "",IDC_TAB1,"SysTabControl32",TCS_MULTILINE | WS_TABSTOP,4,4,259,210 84 | RTEXT "Ray2Fix",IDC_VERNUM,156,6,105,8,WS_DISABLED 85 | END 86 | 87 | IDD_GENERAL DIALOGEX 0, 0, 254, 194 88 | STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU 89 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 90 | BEGIN 91 | GROUPBOX "Status",IDC_STATIC,6,6,242,68 92 | EDITTEXT IDC_STATUSLINE,14,18,226,34,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL 93 | CONTROL "Enable Ray2Fix",IDC_MAINTOGGLE,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,14,58,65,10 94 | GROUPBOX "Resolution / Window size",IDC_STATIC,6,78,126,60 95 | COMBOBOX IDC_RESOLUTION,14,90,110,74,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 96 | EDITTEXT IDC_RESX,14,90,46,12,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE 97 | CTEXT "x",IDC_RES_LABEL,60,92,18,8,NOT WS_VISIBLE 98 | EDITTEXT IDC_RESY,78,90,46,12,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE 99 | RADIOBUTTON "Windowed*",IDC_FSMODE_WND,14,107,53,10,WS_GROUP 100 | RADIOBUTTON "Fullscreen",IDC_FSMODE_FS,74,107,48,10 101 | CONTROL "Widescreen patch",IDC_PATCHWIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,121,73,10 102 | LTEXT "* Suggested ""safe"" values for speedrunning",IDC_STATIC,6,168,144,8 103 | LTEXT "+ Largest recommended size for windowed mode",IDC_STATIC,6,180,161,8 104 | GROUPBOX "Advanced",IDC_ADVGROUP,136,78,112,84,NOT WS_VISIBLE 105 | CONTROL "Force VSync",IDC_VSYNC,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_GROUP | WS_TABSTOP,144,91,55,10 106 | LTEXT "Refresh rate",IDC_REFRATE_LABEL,144,108,42,8,NOT WS_VISIBLE 107 | COMBOBOX IDC_REFRATE,197,106,43,46,CBS_DROPDOWNLIST | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP 108 | PUSHBUTTON "Clean up files",IDC_CLEANUP,162,126,60,14,NOT WS_VISIBLE 109 | LTEXT "DEBUG Wait Frame",IDC_DEBUG_WF_LABEL,144,147,62,8,NOT WS_VISIBLE 110 | EDITTEXT IDC_DEBUG_WF,210,145,30,12,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE 111 | END 112 | 113 | IDD_PAD DIALOGEX 0, 0, 254, 194 114 | STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU 115 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 116 | BEGIN 117 | LTEXT "L Stick:",IDC_STATIC,6,11,30,8,0,WS_EX_RIGHT 118 | COMBOBOX IDC_LS,42,9,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 119 | LTEXT "LS Click:",IDC_STATIC,6,29,30,8,0,WS_EX_RIGHT 120 | COMBOBOX IDC_LSCLICK,42,27,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 121 | LTEXT "R Stick:",IDC_STATIC,126,11,30,8,0,WS_EX_RIGHT 122 | COMBOBOX IDC_RS,162,9,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 123 | LTEXT "RS Click:",IDC_STATIC,126,29,30,8,0,WS_EX_RIGHT 124 | COMBOBOX IDC_RSCLICK,162,27,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 125 | CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,6,45,246,1 126 | LTEXT "Up:",IDC_STATIC,6,53,30,8,0,WS_EX_RIGHT 127 | COMBOBOX IDC_DUP,42,51,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 128 | LTEXT "Down:",IDC_STATIC,6,71,30,8,0,WS_EX_RIGHT 129 | COMBOBOX IDC_DDOWN,42,69,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 130 | LTEXT "Left:",IDC_STATIC,6,89,30,8,0,WS_EX_RIGHT 131 | COMBOBOX IDC_DLEFT,42,87,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 132 | LTEXT "Right:",IDC_STATIC,6,107,30,8,0,WS_EX_RIGHT 133 | COMBOBOX IDC_DRIGHT,42,105,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 134 | LTEXT "A:",IDC_STATIC,126,53,30,8,0,WS_EX_RIGHT 135 | COMBOBOX IDC_AA,162,51,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 136 | LTEXT "B:",IDC_STATIC,126,71,30,8,0,WS_EX_RIGHT 137 | COMBOBOX IDC_BB,162,69,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 138 | LTEXT "X:",IDC_STATIC,126,89,30,8,0,WS_EX_RIGHT 139 | COMBOBOX IDC_XX,162,87,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 140 | LTEXT "Y:",IDC_STATIC,126,107,30,8,0,WS_EX_RIGHT 141 | COMBOBOX IDC_YY,162,105,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 142 | CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,6,123,246,1 143 | LTEXT "LT:",IDC_STATIC,6,131,30,8,0,WS_EX_RIGHT 144 | COMBOBOX IDC_LT,42,129,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 145 | LTEXT "LB:",IDC_STATIC,6,149,30,8,0,WS_EX_RIGHT 146 | COMBOBOX IDC_LB,42,147,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 147 | LTEXT "RT:",IDC_STATIC,126,131,30,8,0,WS_EX_RIGHT 148 | COMBOBOX IDC_RT,162,129,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 149 | LTEXT "RB:",IDC_STATIC,126,149,30,8,0,WS_EX_RIGHT 150 | COMBOBOX IDC_RB,162,147,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 151 | CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,6,165,246,1 152 | LTEXT "Back:",IDC_STATIC,6,173,30,8,0,WS_EX_RIGHT 153 | COMBOBOX IDC_BBACK,42,171,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 154 | LTEXT "Start:",IDC_STATIC,126,173,30,8,0,WS_EX_RIGHT 155 | COMBOBOX IDC_BSTART,162,171,78,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 156 | END 157 | 158 | 159 | ///////////////////////////////////////////////////////////////////////////// 160 | // 161 | // Version 162 | // 163 | 164 | VS_VERSION_INFO VERSIONINFO 165 | FILEVERSION 1,4,0,0 166 | PRODUCTVERSION 1,4,0,0 167 | FILEFLAGSMASK 0x3fL 168 | #ifdef _DEBUG 169 | FILEFLAGS 0x1L 170 | #else 171 | FILEFLAGS 0x0L 172 | #endif 173 | FILEOS 0x40004L 174 | FILETYPE 0x1L 175 | FILESUBTYPE 0x0L 176 | BEGIN 177 | BLOCK "StringFileInfo" 178 | BEGIN 179 | BLOCK "040904b0" 180 | BEGIN 181 | VALUE "CompanyName", "Spitfire_x86" 182 | VALUE "FileDescription", "Ray2Fix Settings" 183 | VALUE "FileVersion", "1.4.0.0" 184 | VALUE "InternalName", "R2FixCfg.exe" 185 | VALUE "LegalCopyright", "Copyright (C) 2023" 186 | VALUE "OriginalFilename", "R2FixCfg.exe" 187 | VALUE "ProductName", "R2FixCfg" 188 | VALUE "ProductVersion", "1.4.0.0" 189 | END 190 | END 191 | BLOCK "VarFileInfo" 192 | BEGIN 193 | VALUE "Translation", 0x409, 1200 194 | END 195 | END 196 | 197 | 198 | ///////////////////////////////////////////////////////////////////////////// 199 | // 200 | // DESIGNINFO 201 | // 202 | 203 | #ifdef APSTUDIO_INVOKED 204 | GUIDELINES DESIGNINFO 205 | BEGIN 206 | IDD_MAIN, DIALOG 207 | BEGIN 208 | LEFTMARGIN, 4 209 | RIGHTMARGIN, 263 210 | VERTGUIDE, 6 211 | VERTGUIDE, 10 212 | VERTGUIDE, 258 213 | TOPMARGIN, 4 214 | BOTTOMMARGIN, 232 215 | HORZGUIDE, 18 216 | HORZGUIDE, 210 217 | HORZGUIDE, 214 218 | HORZGUIDE, 218 219 | HORZGUIDE, 225 220 | END 221 | 222 | IDD_GENERAL, DIALOG 223 | BEGIN 224 | LEFTMARGIN, 6 225 | RIGHTMARGIN, 248 226 | VERTGUIDE, 14 227 | VERTGUIDE, 60 228 | VERTGUIDE, 78 229 | VERTGUIDE, 124 230 | VERTGUIDE, 132 231 | VERTGUIDE, 136 232 | VERTGUIDE, 144 233 | VERTGUIDE, 240 234 | TOPMARGIN, 6 235 | BOTTOMMARGIN, 188 236 | HORZGUIDE, 18 237 | HORZGUIDE, 52 238 | HORZGUIDE, 58 239 | HORZGUIDE, 74 240 | HORZGUIDE, 78 241 | HORZGUIDE, 90 242 | HORZGUIDE, 102 243 | HORZGUIDE, 106 244 | HORZGUIDE, 118 245 | HORZGUIDE, 124 246 | END 247 | 248 | IDD_PAD, DIALOG 249 | BEGIN 250 | LEFTMARGIN, 6 251 | RIGHTMARGIN, 248 252 | VERTGUIDE, 18 253 | VERTGUIDE, 30 254 | VERTGUIDE, 240 255 | TOPMARGIN, 6 256 | BOTTOMMARGIN, 188 257 | HORZGUIDE, 14 258 | HORZGUIDE, 20 259 | HORZGUIDE, 36 260 | HORZGUIDE, 44 261 | HORZGUIDE, 60 262 | HORZGUIDE, 74 263 | HORZGUIDE, 90 264 | HORZGUIDE, 104 265 | HORZGUIDE, 120 266 | END 267 | END 268 | #endif // APSTUDIO_INVOKED 269 | 270 | 271 | ///////////////////////////////////////////////////////////////////////////// 272 | // 273 | // AFX_DIALOG_LAYOUT 274 | // 275 | 276 | IDD_MAIN AFX_DIALOG_LAYOUT 277 | BEGIN 278 | 0 279 | END 280 | 281 | IDD_GENERAL AFX_DIALOG_LAYOUT 282 | BEGIN 283 | 0 284 | END 285 | 286 | IDD_PAD AFX_DIALOG_LAYOUT 287 | BEGIN 288 | 0 289 | END 290 | 291 | 292 | ///////////////////////////////////////////////////////////////////////////// 293 | // 294 | // Accelerator 295 | // 296 | 297 | IDR_ACCEL ACCELERATORS 298 | BEGIN 299 | VK_F10, ID_DEBUG, VIRTKEY, CONTROL, ALT, NOINVERT 300 | END 301 | 302 | 303 | ///////////////////////////////////////////////////////////////////////////// 304 | // 305 | // String Table 306 | // 307 | 308 | STRINGTABLE 309 | BEGIN 310 | IDS_APPNAME "Ray2Fix Settings" 311 | IDS_FLAVORTEXT "Leading Brand Graphics Fix-type Software" 312 | IDS_GREETING "If you're reading this, I hope you have a nice day." 313 | IDS_U_ENABLED "ENABLED" 314 | IDS_U_DISABLED "DISABLED" 315 | IDS_ASKTOSAVE "Do you want to save current settings before exiting?" 316 | IDS_ENABLED "enabled" 317 | IDS_DISABLED "disabled" 318 | END 319 | 320 | STRINGTABLE 321 | BEGIN 322 | IDS_FIXSTATUS "Ray2Fix is currently %s.\r\n" 323 | IDS_STATUSCHANGED "Ray2Fix will be %s after saving the settings.\r\n" 324 | IDS_B_ENABLE "Enable" 325 | IDS_B_DISABLE "Disable" 326 | IDS_VE_OK "File verification successful." 327 | IDS_VE_HEADER "Missing files: " 328 | IDS_VE_REINSTALLFIX "\r\nPlease reinstall Ray2Fix." 329 | IDS_VE_REINSTALLR2 "\r\nPlease reinstall Rayman 2." 330 | IDS_VE_DEGE "dgVoodoo.conf " 331 | IDS_VE_GLIDE "GliVd1Vf.dll " 332 | IDS_VE_FIX "GliFixVf.dll " 333 | IDS_VE_DINPUT "dinput.dll " 334 | IDS_VE_XIDI "Xidi.ini" 335 | IDS_VE_SETPAD "\r\nTo use a controller, choose a new layout in the Gamepad tab." 336 | IDS_VE_XIDICHANGED "\r\nGamepad config has been manually edited." 337 | IDS_WARNING "Warning:" 338 | END 339 | 340 | STRINGTABLE 341 | BEGIN 342 | IDS_VE_OKWARN "File verification completed with warnings." 343 | IDS_NEWLINE "\r\n" 344 | IDS_CLEANUPWARN "This will delete *all* extra GOG files that are not necessary for the game to run.\n\nAre you sure you want to continue?" 345 | END 346 | 347 | #endif // English (United States) resources 348 | ///////////////////////////////////////////////////////////////////////////// 349 | 350 | 351 | 352 | #ifndef APSTUDIO_INVOKED 353 | ///////////////////////////////////////////////////////////////////////////// 354 | // 355 | // Generated from the TEXTINCLUDE 3 resource. 356 | // 357 | 358 | 359 | ///////////////////////////////////////////////////////////////////////////// 360 | #endif // not APSTUDIO_INVOKED 361 | 362 | -------------------------------------------------------------------------------- /R2FixCfg/config.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "config.h" 3 | #include "pad.h" 4 | 5 | 6 | /* 7 | * Global Vars 8 | */ 9 | 10 | BOOL g_bFixState = FALSE; 11 | BOOL g_bFixPrevState = FALSE; 12 | 13 | tdstDisplayMode g_stCurrentMode = { 0 }; 14 | tdeRefRate g_eRefRate = e_RR_Full; 15 | BOOL g_bForceVsync = FALSE; 16 | BOOL g_bFullscreen = FALSE; 17 | BOOL g_bPatchWidescreen = FALSE; 18 | int g_DEBUG_lWaitFrame = 0; 19 | 20 | tdeErrorState g_eError = e_ES_Ok; 21 | tdeVerifyErr g_eErrorDetails = e_VE_Ok; 22 | 23 | 24 | /* 25 | * Strings 26 | */ 27 | 28 | char const *szDegePath = ".\\dgVoodoo.conf"; 29 | char const *szUbiPath = ".\\Ubi.ini"; 30 | 31 | char const *a_szFilesToDelete[] = { 32 | "nglide_config.exe", 33 | "nglide_readme.txt", 34 | "nGlideEULA.txt", 35 | "3DfxSpl.dll", 36 | "3DfxSpl3.dll", 37 | "glide.dll", 38 | "glide3x.dll" 39 | }; 40 | 41 | char const *a_szToManualDelete[] = { 42 | "goggame.sdb", 43 | "goglog.ini", 44 | "gog.ico", 45 | "support.ico", 46 | "EULA.txt", 47 | "webcache.zip", 48 | "goggame-1207658940.dll", 49 | "goggame-1207658940.info" 50 | }; 51 | 52 | 53 | /* 54 | * Functions 55 | */ 56 | 57 | 58 | void fn_vReadUbiIni( void ) 59 | { 60 | char szBuffer[128]; 61 | 62 | // GLI library 63 | GetPrivateProfileString("Rayman2", "GLI_Dll", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 64 | if ( !strcmp(szBuffer, "Ray2Fix") ) 65 | { 66 | g_bFixState = g_bFixPrevState = TRUE; 67 | } 68 | 69 | DWORD dwWidth = 0; 70 | DWORD dwHeight = 0; 71 | 72 | // Display mode 73 | GetPrivateProfileString("Rayman2", "GLI_Mode", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 74 | int nParsed = sscanf_s(szBuffer, "1 - %d x %d", &dwWidth, &dwHeight); 75 | 76 | if ( nParsed == 2 && dwWidth > 0 && dwHeight > 0 ) 77 | { 78 | g_stCurrentMode.dwWidth = dwWidth; 79 | g_stCurrentMode.dwHeight = dwHeight; 80 | } 81 | 82 | // Widescreen patch 83 | GetPrivateProfileString("Ray2Fix", "PatchWidescreen", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 84 | if( strtol(szBuffer, NULL, 10) > 0 ) 85 | g_bPatchWidescreen = TRUE; 86 | 87 | // DEBUG Wait frame 88 | GetPrivateProfileString("Ray2Fix", "Debug_WaitFrame", NULL, szBuffer, sizeof(szBuffer), szUbiPath); 89 | int lResult = strtol(szBuffer, NULL, 10); 90 | if ( lResult > 0 ) 91 | g_DEBUG_lWaitFrame = lResult; 92 | } 93 | 94 | void fn_vReadDegeIni( void ) 95 | { 96 | char szBuffer[128]; 97 | 98 | DWORD dwRefRate = 0; 99 | 100 | // Refresh rate 101 | GetPrivateProfileString("Glide", "Resolution", NULL, szBuffer, sizeof(szBuffer), szDegePath); 102 | char *lpLastComma = strrchr(szBuffer, ','); 103 | 104 | if ( lpLastComma != NULL ) 105 | { 106 | int nParsed = sscanf_s(++lpLastComma, " refrate:%d", &dwRefRate); 107 | 108 | if ( nParsed == 1 && dwRefRate > 0 ) 109 | g_eRefRate = dwRefRate; 110 | } 111 | 112 | // Force VSync 113 | GetPrivateProfileString("Glide", "ForceVerticalSync", NULL, szBuffer, sizeof(szBuffer), szDegePath); 114 | if ( !strcmp(szBuffer, "true") ) 115 | g_bForceVsync = TRUE; 116 | 117 | // Fullscreen mode 118 | GetPrivateProfileString("General", "FullScreenMode", NULL, szBuffer, sizeof(szBuffer), szDegePath); 119 | if ( !strcmp(szBuffer, "true") ) 120 | g_bFullscreen = TRUE; 121 | } 122 | 123 | void fn_vWriteUbiIni( void ) 124 | { 125 | char szBuffer[128]; 126 | 127 | // GLI library path & name 128 | char *szDllFile = g_bFixState ? "GliFix" : "GliVd1"; 129 | WritePrivateProfileString("Rayman2", "GLI_DllFile", szDllFile, szUbiPath); 130 | 131 | char *szDll = g_bFixState ? "Ray2Fix" : "Glide2"; 132 | WritePrivateProfileString("Rayman2", "GLI_Dll", szDll, szUbiPath); 133 | 134 | // Doesn't really matter but write "Default" anyway 135 | char *szDevice = "Default"; 136 | WritePrivateProfileString("Rayman2", "GLI_Driver", szDevice, szUbiPath); 137 | WritePrivateProfileString("Rayman2", "GLI_Device", szDevice, szUbiPath); 138 | 139 | // Display mode 140 | sprintf_s(szBuffer, sizeof(szBuffer), "1 - %i x %i x 16", g_stCurrentMode.dwWidth, g_stCurrentMode.dwHeight); 141 | WritePrivateProfileString("Rayman2", "GLI_Mode", szBuffer, szUbiPath); 142 | 143 | // Tweaks - removed 144 | WritePrivateProfileString("Ray2Fix", "Tweaks", "0", szUbiPath); 145 | 146 | // Widescreen patch 147 | sprintf_s(szBuffer, sizeof(szBuffer), "%i", g_bPatchWidescreen); 148 | WritePrivateProfileString("Ray2Fix", "PatchWidescreen", szBuffer, szUbiPath); 149 | 150 | // Refresh rate 151 | sprintf_s(szBuffer, sizeof(szBuffer), "%i", (g_eRefRate == e_RR_Half)); 152 | WritePrivateProfileString("Ray2Fix", "HalfRefRate", szBuffer, szUbiPath); 153 | 154 | // DEBUG wait frame 155 | sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_DEBUG_lWaitFrame); 156 | WritePrivateProfileString("Ray2Fix", "Debug_WaitFrame", szBuffer, szUbiPath); 157 | } 158 | 159 | void fn_vWriteDegeIni( void ) 160 | { 161 | char szBuffer[128]; 162 | 163 | // These values should never change, but write them anyway in case the user messes up the config 164 | WritePrivateProfileString("General", "ProgressiveScanlineOrder", "true", szDegePath); 165 | WritePrivateProfileString("General", "EnumerateRefreshRates", "true", szDegePath); 166 | WritePrivateProfileString("General", "ScalingMode", "stretched_ar", szDegePath); 167 | WritePrivateProfileString("General", "KeepWindowAspectRatio", "true", szDegePath); 168 | WritePrivateProfileString("Glide", "VideoCard", "voodoo_2", szDegePath); 169 | WritePrivateProfileString("Glide", "OnboardRAM", "12", szDegePath); 170 | WritePrivateProfileString("Glide", "MemorySizeOfTMU", "4096", szDegePath); 171 | WritePrivateProfileString("Glide", "NumberOfTMUs", "2", szDegePath); 172 | WritePrivateProfileString("Glide", "EnableGlideGammaRamp", "true", szDegePath); 173 | WritePrivateProfileString("Glide", "EnableInactiveAppState", "false", szDegePath); 174 | 175 | // Display mode & refresh rate 176 | sprintf_s(szBuffer, sizeof(szBuffer), "h:%i, v:%i, refrate:%i", 177 | g_stCurrentMode.dwWidth, g_stCurrentMode.dwHeight, g_eRefRate); 178 | WritePrivateProfileString("Glide", "Resolution", szBuffer, szDegePath); 179 | 180 | // Force VSync 181 | char const *szVsync = g_bForceVsync ? "true" : "false"; 182 | WritePrivateProfileString("Glide", "ForceVerticalSync", szVsync, szDegePath); 183 | 184 | // Fullscreen mode 185 | char const *szFullScreen = g_bFullscreen ? "true" : "false"; 186 | WritePrivateProfileString("General", "FullScreenMode", szFullScreen, szDegePath); 187 | } 188 | 189 | void fn_vSoftCleanUp( void ) 190 | { 191 | for ( DWORD i = 0; i < ARRAYSIZE(a_szFilesToDelete); i++ ) 192 | { 193 | char szFilePath[MAX_PATH]; 194 | sprintf_s(szFilePath, MAX_PATH, ".\\%s", a_szFilesToDelete[i]); 195 | 196 | DeleteFile(szFilePath); 197 | } 198 | } 199 | 200 | void fn_vManualCleanUp( void ) 201 | { 202 | /* do regular cleanup first */ 203 | fn_vSoftCleanUp(); 204 | 205 | for ( DWORD i = 0; i < ARRAYSIZE(a_szToManualDelete); i++ ) 206 | { 207 | char szFilePath[MAX_PATH]; 208 | sprintf_s(szFilePath, MAX_PATH, ".\\%s", a_szToManualDelete[i]); 209 | 210 | DeleteFile(szFilePath); 211 | } 212 | } 213 | 214 | void CFG_fn_vRead( void ) 215 | { 216 | fn_vReadUbiIni(); 217 | fn_vReadDegeIni(); 218 | PAD_fn_vRead(); 219 | } 220 | 221 | void CFG_fn_vWrite( void ) 222 | { 223 | fn_vWriteUbiIni(); 224 | fn_vWriteDegeIni(); 225 | PAD_fn_vWrite(); 226 | } 227 | 228 | void CFG_fn_vVerify( void ) 229 | { 230 | if ( GetFileAttributes(".\\nglide_config.exe") != INVALID_FILE_ATTRIBUTES ) 231 | { 232 | // Delete unnecessary nGlide files 233 | fn_vSoftCleanUp(); 234 | } 235 | 236 | if ( GetFileAttributes(szUbiPath) == INVALID_FILE_ATTRIBUTES ) 237 | { 238 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_UbiMissing; 239 | } 240 | 241 | if ( GetFileAttributes(szDegePath) == INVALID_FILE_ATTRIBUTES ) 242 | { 243 | g_eError |= e_ES_FixError; 244 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_DegeMissing; 245 | } 246 | 247 | if ( GetFileAttributes(".\\DLL\\GliVd1Vf.dll") == INVALID_FILE_ATTRIBUTES ) 248 | { 249 | g_eError |= e_ES_GameError; 250 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_GlideMissing; 251 | } 252 | 253 | if ( GetFileAttributes(".\\DLL\\GliFixVf.dll") == INVALID_FILE_ATTRIBUTES ) 254 | { 255 | g_eError |= e_ES_FixError; 256 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_FixMissing; 257 | } 258 | 259 | if ( GetFileAttributes(".\\dinput.dll") == INVALID_FILE_ATTRIBUTES ) 260 | { 261 | g_eError |= e_ES_FixError; 262 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_DinputMissing; 263 | } 264 | 265 | if ( GetFileAttributes(g_szXidiPath) == INVALID_FILE_ATTRIBUTES ) 266 | { 267 | g_eError |= e_ES_Warning; 268 | g_eErrorDetails |= e_VE_FilesMissing | e_VE_XidiMissing; 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /R2FixCfg/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | #include "display.h" 5 | 6 | 7 | typedef enum tdeErrorState_ 8 | { 9 | e_ES_Ok = 0, 10 | e_ES_Warning = 1 << 0, 11 | e_ES_GameError = 1 << 1, 12 | e_ES_FixError = 1 << 2, 13 | } 14 | tdeErrorState; 15 | 16 | typedef enum tdeVerifyErr_ 17 | { 18 | e_VE_Ok = 0, 19 | e_VE_FilesMissing = 1 << 0, 20 | e_VE_UbiMissing = 1 << 1, 21 | e_VE_DegeMissing = 1 << 2, 22 | e_VE_GlideMissing = 1 << 3, 23 | e_VE_FixMissing = 1 << 4, 24 | e_VE_DinputMissing = 1 << 5, 25 | e_VE_XidiMissing = 1 << 6, 26 | e_VE_XidiModified = 1 << 7, 27 | } 28 | tdeVerifyErr; 29 | 30 | 31 | /* 32 | * Global Vars 33 | */ 34 | 35 | extern BOOL g_bFixState; 36 | extern BOOL g_bFixPrevState; 37 | 38 | extern tdstDisplayMode g_stCurrentMode; 39 | extern tdeRefRate g_eRefRate; 40 | extern BOOL g_bForceVsync; 41 | extern BOOL g_bFullscreen; 42 | extern BOOL g_bPatchWidescreen; 43 | extern int g_DEBUG_lWaitFrame; 44 | 45 | extern tdeErrorState g_eError; 46 | extern tdeVerifyErr g_eErrorDetails; 47 | 48 | 49 | /* 50 | * Functions 51 | */ 52 | 53 | void CFG_fn_vRead( void ); 54 | void CFG_fn_vWrite( void ); 55 | void CFG_fn_vVerify( void ); 56 | 57 | void fn_vManualCleanUp( void ); 58 | -------------------------------------------------------------------------------- /R2FixCfg/def_analog.h: -------------------------------------------------------------------------------- 1 | #if !defined(M_DefineAction) 2 | #error You should define M_DefineAction accordingly before including this file! 3 | #endif 4 | 5 | 6 | /******************************************************************************************************************** 7 | * M_DefineAction ( Id, szName, szCfg_X, szCfg_Y ) 8 | ********************************************************************************************************************/ 9 | 10 | M_DefineAction( E_AAc_Null, "(None)", "Null", "Null" ) 11 | 12 | M_DefineAction( E_AAc_Movement, "Movement", "Axis(X)", "Axis(Y)" ) 13 | M_DefineAction( E_AAc_Camera, "Camera L/R", "Split(Button(3),Button(4))", "Null" ) 14 | M_DefineAction( E_AAc_Camera_Inverted, "Camera L/R (Inverted)", "Split(Button(4),Button(3))", "Null" ) 15 | 16 | /********************************************************************************************************************/ 17 | 18 | 19 | #if defined(M_DefineAction) 20 | #undef M_DefineAction 21 | #endif 22 | -------------------------------------------------------------------------------- /R2FixCfg/def_button.h: -------------------------------------------------------------------------------- 1 | #if !defined(M_DefineAction) 2 | #error You should define M_DefineAction accordingly before including this file! 3 | #endif 4 | 5 | 6 | /******************************************************************************************************************** 7 | * M_DefineAction ( Id, szName, szCfg ) 8 | ********************************************************************************************************************/ 9 | 10 | M_DefineAction( E_BAc_Null, "(None)", "Null" ) 11 | 12 | M_DefineAction( E_BAc_Up, "Up", "Keyboard(Up)" ) 13 | M_DefineAction( E_BAc_Down, "Down", "Keyboard(Down)" ) 14 | M_DefineAction( E_BAc_Left, "Left", "Keyboard(Left)" ) 15 | M_DefineAction( E_BAc_Right, "Right", "Keyboard(Right)" ) 16 | 17 | M_DefineAction( E_BAc_Jump, "Jump", "Keyboard(A)" ) 18 | M_DefineAction( E_BAc_Jump_Accept, "Jump / Accept", "Compound(Keyboard(A),Keyboard(Enter))" ) 19 | M_DefineAction( E_BAc_Jump_Cancel, "Jump / Cancel", "Button(2)" ) 20 | 21 | M_DefineAction( E_BAc_Shoot, "Shoot", "Keyboard(Space)" ) 22 | M_DefineAction( E_BAc_Shoot_Accept, "Shoot / Accept", "Button(1)" ) 23 | M_DefineAction( E_BAc_Shoot_Cancel, "Shoot / Cancel", "Compound(Keyboard(Space),Keyboard(Backspace))" ) 24 | 25 | M_DefineAction( E_BAc_Strafe, "Strafe / Dive", "Button(5)" ) 26 | M_DefineAction( E_BAc_Look, "Look Mode", "Keyboard(Numpad0)" ) 27 | M_DefineAction( E_BAc_Camera_Reset, "Reset Camera", "Keyboard(End)" ) 28 | M_DefineAction( E_BAc_Camera_Left, "Camera Left", "Button(4)" ) 29 | M_DefineAction( E_BAc_Camera_Right, "Camera Right", "Button(3)" ) 30 | 31 | M_DefineAction( E_BAc_Think, "Think (F1)", "Keyboard(F1)" ) 32 | M_DefineAction( E_BAc_HUD, "HUD (J)", "Button(6)" ) 33 | M_DefineAction( E_BAc_HUD_Accept, "HUD / Accept", "Compound(Button(6),Keyboard(Enter))" ) 34 | M_DefineAction( E_BAc_ScreenShot, "Screenshot", "Keyboard(F8)" ) 35 | M_DefineAction( E_BAc_Pause, "Pause", "Keyboard(Esc)" ) 36 | 37 | M_DefineAction( E_BAc_Accept, "Accept (Enter)", "Keyboard(Enter)" ) 38 | M_DefineAction( E_BAc_Cancel, "Cancel (Backspace)", "Keyboard(Backspace)" ) 39 | 40 | 41 | /********************************************************************************************************************/ 42 | 43 | 44 | #if defined(M_DefineAction) 45 | #undef M_DefineAction 46 | #endif 47 | -------------------------------------------------------------------------------- /R2FixCfg/def_pad.h: -------------------------------------------------------------------------------- 1 | #if !defined(M_DefineInput) 2 | #error You should define M_DefineInput accordingly before including this file! 3 | #endif 4 | 5 | 6 | /******************************************************************************************************************** 7 | * M_DefineInput ( Id, lCtrl, bAnalog, szCfg ) 8 | ********************************************************************************************************************/ 9 | 10 | M_DefineInput( E_Pad_LS, IDC_LS, TRUE, "StickLeft" ) 11 | M_DefineInput( E_Pad_RS, IDC_RS, TRUE, "StickRight" ) 12 | M_DefineInput( E_Pad_LS_Click, IDC_LSCLICK, FALSE, "ButtonLS" ) 13 | M_DefineInput( E_Pad_RS_Click, IDC_RSCLICK, FALSE, "ButtonRS" ) 14 | 15 | M_DefineInput( E_Pad_Up, IDC_DUP, FALSE, "DpadUp" ) 16 | M_DefineInput( E_Pad_Down, IDC_DDOWN, FALSE, "DpadDown" ) 17 | M_DefineInput( E_Pad_Left, IDC_DLEFT, FALSE, "DpadLeft" ) 18 | M_DefineInput( E_Pad_Right, IDC_DRIGHT, FALSE, "DpadRight" ) 19 | 20 | M_DefineInput( E_Pad_A, IDC_AA, FALSE, "ButtonA" ) 21 | M_DefineInput( E_Pad_B, IDC_BB, FALSE, "ButtonB" ) 22 | M_DefineInput( E_Pad_X, IDC_XX, FALSE, "ButtonX" ) 23 | M_DefineInput( E_Pad_Y, IDC_YY, FALSE, "ButtonY" ) 24 | 25 | M_DefineInput( E_Pad_LT, IDC_LT, FALSE, "TriggerLT" ) 26 | M_DefineInput( E_Pad_LB, IDC_LB, FALSE, "ButtonLB" ) 27 | M_DefineInput( E_Pad_RT, IDC_RT, FALSE, "TriggerRT" ) 28 | M_DefineInput( E_Pad_RB, IDC_RB, FALSE, "ButtonRB" ) 29 | 30 | M_DefineInput( E_Pad_Back, IDC_BBACK, FALSE, "ButtonBack" ) 31 | M_DefineInput( E_Pad_Start, IDC_BSTART, FALSE, "ButtonStart" ) 32 | 33 | /********************************************************************************************************************/ 34 | 35 | 36 | #if defined(M_DefineInput) 37 | #undef M_DefineInput 38 | #endif 39 | -------------------------------------------------------------------------------- /R2FixCfg/dialogs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | typedef enum tdeTabID_ 7 | { 8 | e_TAB_General, 9 | e_TAB_Pad, 10 | e_NbTab 11 | } 12 | tdeTabID; 13 | 14 | typedef struct tdstTabInfo_ 15 | { 16 | int lDlgId; 17 | char szTabName[50]; 18 | DLGPROC pfnDlgProc; 19 | } 20 | tdstTabInfo; 21 | 22 | 23 | BOOL CALLBACK DLG_fn_bProc_General( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 24 | BOOL CALLBACK DLG_fn_bProc_Pad( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 25 | -------------------------------------------------------------------------------- /R2FixCfg/display.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "config.h" 3 | 4 | 5 | tdstDisplayMode g_a_stDispModes[C_MaxModes]; 6 | 7 | 8 | BOOL fn_bIsSafeResolution( tdstDisplayMode *lpMode ) 9 | { 10 | // Safe resolutions are the two most commonly used in speedruns: 1024x768 and 1280x1024. 11 | // They're the most likely to work without any issues on most PCs. 12 | 13 | if ( lpMode->dwWidth == 1024 && lpMode->dwHeight == 768 ) 14 | return TRUE; 15 | 16 | if ( lpMode->dwWidth == 1280 && lpMode->dwHeight == 1024 ) 17 | return TRUE; 18 | 19 | return FALSE; 20 | } 21 | 22 | BOOL fn_bIsDuplicateMode( tdstDisplayMode *lpMode, int nModes ) 23 | { 24 | // This is dumb, but apparently EnumDisplaySettings does not always return the resolutions 25 | // in an order that makes sense. Which means we can't just compare it to the previous one 26 | // to check if it's duplicated/already present in the array. 27 | 28 | for ( int i = 0; i < nModes; i++ ) 29 | { 30 | tdstDisplayMode *prevMode = &g_a_stDispModes[i]; 31 | 32 | if ( lpMode->dwWidth == prevMode->dwWidth && lpMode->dwHeight == prevMode->dwHeight ) 33 | return TRUE; 34 | } 35 | 36 | return FALSE; 37 | } 38 | 39 | void fn_vAddCustomModeIfSet( int nModes ) 40 | { 41 | if ( g_stCurrentMode.dwWidth <= 0 || g_stCurrentMode.dwHeight <= 0 || 42 | fn_bIsDuplicateMode(&g_stCurrentMode, nModes) ) 43 | return; 44 | 45 | g_stCurrentMode.eFlags |= e_DMF_Custom; 46 | g_a_stDispModes[nModes] = g_stCurrentMode; 47 | } 48 | 49 | void fn_vFindBestResolution( int nModes ) 50 | { 51 | RECT rcWorkArea = { 0 }; 52 | SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); 53 | 54 | for ( int i = nModes - 1; i >= 0; i-- ) 55 | { 56 | tdstDisplayMode *mode = &g_a_stDispModes[i]; 57 | 58 | if ( mode->eFlags & e_DMF_Widescreen ) // skip widescreen resolutions 59 | continue; 60 | 61 | // Find the largest resolution that fits in the work area 62 | if ( (int)mode->dwWidth <= rcWorkArea.right && (int)mode->dwHeight <= rcWorkArea.bottom ) 63 | { 64 | mode->eFlags |= e_DMF_Best; 65 | return; 66 | } 67 | } 68 | } 69 | 70 | void DSP_fn_vEnumResolutions( void ) 71 | { 72 | DEVMODE dm = { 0 }; 73 | dm.dmSize = sizeof(dm); 74 | 75 | int nModes = 0; 76 | 77 | for ( int i = 0; EnumDisplaySettings(NULL, i, &dm) != 0; i++ ) 78 | { 79 | tdstDisplayMode mode = { 80 | dm.dmPelsWidth, 81 | dm.dmPelsHeight, 82 | e_DMF_None 83 | }; 84 | 85 | if ( mode.dwWidth <= 0 || mode.dwHeight <= 0 ) 86 | continue; 87 | 88 | if ( fn_bIsDuplicateMode(&mode, nModes) ) 89 | continue; 90 | 91 | DWORD ratio = 100 * dm.dmPelsHeight / dm.dmPelsWidth; 92 | 93 | // Only add resolutions "close" to 4:3 or 5:4 ratio 94 | if ( /*ratio > 73 &&*/ ratio < 82 ) // temp: allow for widescreen 95 | { 96 | if ( fn_bIsSafeResolution(&mode) ) 97 | mode.eFlags |= e_DMF_Safe; 98 | 99 | if ( ratio <= 73 ) 100 | mode.eFlags |= e_DMF_Widescreen; 101 | 102 | g_a_stDispModes[nModes++] = mode; 103 | } 104 | } 105 | 106 | fn_vFindBestResolution(nModes); 107 | fn_vAddCustomModeIfSet(nModes); 108 | } 109 | -------------------------------------------------------------------------------- /R2FixCfg/display.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | typedef enum tdeDisplayModeFlags_ 7 | { 8 | e_DMF_None = 0, 9 | e_DMF_Safe = 1 << 0, 10 | e_DMF_Best = 1 << 1, 11 | e_DMF_Custom = 1 << 2, 12 | e_DMF_Widescreen = 1 << 3 13 | } 14 | tdeDisplayModeFlags; 15 | 16 | typedef enum tdeRefRate_ 17 | { 18 | e_RR_Half = 30, 19 | e_RR_Full = 60 20 | } 21 | tdeRefRate; 22 | 23 | typedef struct tdstDisplayMode_ 24 | { 25 | DWORD dwWidth; 26 | DWORD dwHeight; 27 | tdeDisplayModeFlags eFlags; 28 | } 29 | tdstDisplayMode; 30 | 31 | 32 | /* 33 | * Global Vars 34 | */ 35 | 36 | #define C_MaxModes 64 37 | 38 | extern tdstDisplayMode g_a_stDispModes[C_MaxModes]; 39 | 40 | 41 | /* 42 | * Functions 43 | */ 44 | 45 | void DSP_fn_vEnumResolutions( void ); 46 | -------------------------------------------------------------------------------- /R2FixCfg/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | -------------------------------------------------------------------------------- /R2FixCfg/generaldlg.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "resource.h" 3 | #include "dialogs.h" 4 | #include "display.h" 5 | #include "config.h" 6 | #include "main.h" 7 | 8 | 9 | static HWND hThis; 10 | 11 | static HWND hStatus; 12 | static HWND hToggle; 13 | static HWND hResolution; 14 | static HWND hPatchWidescreen; 15 | 16 | static HWND hResX; 17 | static HWND hResY; 18 | static HWND hResLabel; 19 | 20 | static HWND hFsModeWin; 21 | static HWND hFsModeFs; 22 | 23 | static HWND hAdvGroup; 24 | static HWND hVsync; 25 | static HWND hRefRateLabel; 26 | static HWND hRefRate; 27 | static HWND hCleanup; 28 | 29 | static HWND hDEBUG_WaitFrame; 30 | static HWND hDEBUG_WaitFrameLabel; 31 | 32 | int lCbCustomIdx; 33 | tdstDisplayMode eLastMode; 34 | 35 | 36 | tdstDisplayMode * fn_p_stGetSelectedDisplayMode( HWND hCB ) 37 | { 38 | int idx = ComboBox_GetCurSel(hCB); 39 | tdstDisplayMode *lpMode = (tdstDisplayMode*)ComboBox_GetItemData(hCB, idx); 40 | 41 | return lpMode; 42 | } 43 | 44 | void fn_vSetDisplayMode( HWND hCB ) 45 | { 46 | tdstDisplayMode *lpMode = fn_p_stGetSelectedDisplayMode(hCB); 47 | 48 | if ( lpMode != NULL ) 49 | { 50 | g_stCurrentMode.dwWidth = lpMode->dwWidth; 51 | g_stCurrentMode.dwHeight = lpMode->dwHeight; 52 | } 53 | } 54 | 55 | BOOL fn_bSetCustomDisplayMode( void ) 56 | { 57 | char szBuffer[8]; 58 | 59 | Edit_GetText(hResX, szBuffer, sizeof(szBuffer) - 1); 60 | DWORD dwWidth = strtol(szBuffer, NULL, 10); 61 | Edit_GetText(hResY, szBuffer, sizeof(szBuffer) - 1); 62 | DWORD dwHeight = strtol(szBuffer, NULL, 10); 63 | 64 | if ( dwWidth > 0 && dwHeight > 0 ) 65 | { 66 | g_stCurrentMode.dwWidth = dwWidth; 67 | g_stCurrentMode.dwHeight = dwHeight; 68 | 69 | return TRUE; 70 | } 71 | 72 | g_stCurrentMode = eLastMode; 73 | return FALSE; 74 | } 75 | 76 | void fn_vUpdateStatus( HWND hEdit, HWND hButton ) 77 | { 78 | char szStatusLine[512]; 79 | char szMsgTemplate[140]; 80 | char szCurrentStatus[60]; 81 | 82 | UINT uTemplateId = (g_bFixState == g_bFixPrevState) ? IDS_FIXSTATUS : IDS_STATUSCHANGED; 83 | UINT uCurrentStatusId = (g_bFixState) ? IDS_U_ENABLED : IDS_U_DISABLED; 84 | 85 | LoadRcString(uTemplateId, szMsgTemplate); 86 | LoadRcString(uCurrentStatusId, szCurrentStatus); 87 | 88 | int nChars = 0; 89 | 90 | if ( g_eError == e_ES_Ok ) 91 | { 92 | nChars += sprintf_s(szStatusLine, sizeof(szStatusLine), szMsgTemplate, szCurrentStatus); 93 | nChars += LoadStringAtChar(IDS_VE_OK, szStatusLine, nChars); 94 | } 95 | else if ( g_eError == e_ES_Warning ) 96 | { 97 | nChars += sprintf_s(szStatusLine, sizeof(szStatusLine), szMsgTemplate, szCurrentStatus); 98 | } 99 | 100 | if ( g_eError >= e_ES_Warning ) 101 | { 102 | if ( g_eErrorDetails & e_VE_FilesMissing ) 103 | { 104 | nChars += LoadStringAtChar(IDS_VE_HEADER, szStatusLine, nChars); 105 | 106 | if ( g_eErrorDetails & e_VE_DegeMissing ) 107 | nChars += LoadStringAtChar(IDS_VE_DEGE, szStatusLine, nChars); 108 | 109 | if ( g_eErrorDetails & e_VE_FixMissing ) 110 | nChars += LoadStringAtChar(IDS_VE_FIX, szStatusLine, nChars); 111 | 112 | if ( g_eErrorDetails & e_VE_DinputMissing ) 113 | nChars += LoadStringAtChar(IDS_VE_DINPUT, szStatusLine, nChars); 114 | 115 | if ( g_eErrorDetails & e_VE_GlideMissing ) 116 | nChars += LoadStringAtChar(IDS_VE_GLIDE, szStatusLine, nChars); 117 | 118 | if ( g_eErrorDetails & e_VE_XidiMissing ) 119 | nChars += LoadStringAtChar(IDS_VE_XIDI, szStatusLine, nChars); 120 | } 121 | else 122 | { 123 | nChars += LoadStringAtChar(IDS_VE_OKWARN, szStatusLine, nChars); 124 | } 125 | 126 | if ( g_eError & e_ES_FixError ) 127 | nChars += LoadStringAtChar(IDS_VE_REINSTALLFIX, szStatusLine, nChars); 128 | 129 | if ( g_eError & e_ES_GameError ) 130 | nChars += LoadStringAtChar(IDS_VE_REINSTALLR2, szStatusLine, nChars); 131 | 132 | if ( g_eError & e_ES_Warning ) 133 | { 134 | if ( g_eErrorDetails & e_VE_XidiMissing ) 135 | nChars += LoadStringAtChar(IDS_VE_SETPAD, szStatusLine, nChars); 136 | 137 | if ( g_eErrorDetails & e_VE_XidiModified ) 138 | nChars += LoadStringAtChar(IDS_VE_XIDICHANGED, szStatusLine, nChars); 139 | } 140 | } 141 | 142 | Edit_SetText(hEdit, szStatusLine); 143 | Button_SetCheck(hButton, g_bFixState); 144 | } 145 | 146 | void fn_vShowCustomRes( void ) 147 | { 148 | char szBuffer[8]; 149 | 150 | sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_stCurrentMode.dwWidth); 151 | Edit_SetText(hResX, szBuffer); 152 | sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_stCurrentMode.dwHeight); 153 | Edit_SetText(hResY, szBuffer); 154 | 155 | eLastMode = g_stCurrentMode; 156 | 157 | ShowWindow(hResolution, SW_HIDE); 158 | ShowWindow(hResX, SW_SHOW); 159 | ShowWindow(hResY, SW_SHOW); 160 | ShowWindow(hResLabel, SW_SHOW); 161 | SetFocus(hResX); 162 | } 163 | 164 | void fn_vToggleAdvanced( BOOL bVisible ) 165 | { 166 | int nCmdShow = bVisible ? SW_SHOW : SW_HIDE; 167 | 168 | ShowWindow(hAdvGroup, nCmdShow); 169 | ShowWindow(hVsync, nCmdShow); 170 | ShowWindow(hRefRateLabel, nCmdShow); 171 | ShowWindow(hRefRate, nCmdShow); 172 | ShowWindow(hCleanup, nCmdShow); 173 | ShowWindow(hDEBUG_WaitFrame, nCmdShow); 174 | ShowWindow(hDEBUG_WaitFrameLabel, nCmdShow); 175 | } 176 | 177 | int fn_lAddThisModeToCB( HWND hCB, tdstDisplayMode *lpMode ) 178 | { 179 | char szItemText[60]; 180 | 181 | sprintf_s(szItemText, sizeof(szItemText), "%d x %d", lpMode->dwWidth, lpMode->dwHeight); 182 | 183 | if ( lpMode->eFlags & e_DMF_Safe ) 184 | strcat_s(szItemText, sizeof(szItemText), " *"); 185 | 186 | if ( lpMode->eFlags & e_DMF_Best ) 187 | strcat_s(szItemText, sizeof(szItemText), " +"); 188 | 189 | if ( lpMode->eFlags & e_DMF_Widescreen ) 190 | strcat_s(szItemText, sizeof(szItemText), " (wide)"); 191 | 192 | if ( lpMode->eFlags & e_DMF_Custom ) 193 | strcat_s(szItemText, sizeof(szItemText), " (custom)"); 194 | 195 | int idx = ComboBox_AddString(hCB, szItemText); 196 | ComboBox_SetItemData(hCB, idx, lpMode); 197 | 198 | return idx; 199 | } 200 | 201 | void fn_vPopulateDisplayModes( HWND hCB ) 202 | { 203 | int idxSelected = -1; 204 | int idxFallback = 0; 205 | 206 | for ( tdstDisplayMode *pMode = &g_a_stDispModes[0]; pMode < &g_a_stDispModes[C_MaxModes]; pMode++ ) 207 | { 208 | if ( pMode->dwWidth == 0 ) 209 | break; 210 | if ( pMode->eFlags & e_DMF_Widescreen ) 211 | continue; 212 | 213 | int idx = fn_lAddThisModeToCB(hCB, pMode); 214 | 215 | // this is just to make sure a reasonably okay res is selected if all else fails 216 | if ( pMode->eFlags & (e_DMF_Safe | e_DMF_Best) ) 217 | idxFallback = idx; 218 | 219 | if ( pMode->dwWidth == g_stCurrentMode.dwWidth && 220 | pMode->dwHeight == g_stCurrentMode.dwHeight ) 221 | idxSelected = idx; 222 | } 223 | 224 | for ( tdstDisplayMode *pMode = &g_a_stDispModes[0]; pMode < &g_a_stDispModes[C_MaxModes]; pMode++ ) 225 | { 226 | if ( pMode->dwWidth == 0 ) 227 | break; 228 | if ( !(pMode->eFlags & e_DMF_Widescreen) ) 229 | continue; 230 | 231 | int idx = fn_lAddThisModeToCB(hCB, pMode); 232 | 233 | if ( pMode->dwWidth == g_stCurrentMode.dwWidth && 234 | pMode->dwHeight == g_stCurrentMode.dwHeight ) 235 | idxSelected = idx; 236 | } 237 | 238 | ComboBox_SetCurSel(hCB, (idxSelected >= 0) ? idxSelected : idxFallback); 239 | 240 | fn_vSetDisplayMode(hResolution); 241 | 242 | // Add special "Custom..." item at the end of the combo box 243 | lCbCustomIdx = ComboBox_AddString(hCB, "Custom..."); 244 | } 245 | 246 | void fn_vPopulateRefRates( HWND hCB ) 247 | { 248 | int lFull = ComboBox_AddString(hCB, "60"); 249 | ComboBox_SetItemData(hCB, lFull, e_RR_Full); 250 | 251 | int lHalf = ComboBox_AddString(hCB, "30"); 252 | ComboBox_SetItemData(hCB, lHalf, e_RR_Half); 253 | 254 | ComboBox_SetCurSel(hCB, (g_eRefRate == e_RR_Half) ? lHalf : lFull); 255 | } 256 | 257 | void fn_vInitDebugWaitFrame( void ) 258 | { 259 | char szBuffer[8]; 260 | sprintf_s(szBuffer, sizeof(szBuffer), "%d", g_DEBUG_lWaitFrame); 261 | SendMessage(hDEBUG_WaitFrame, EM_LIMITTEXT, 2, 0); 262 | Edit_SetText(hDEBUG_WaitFrame, szBuffer); 263 | } 264 | 265 | void fn_vSetDebugWaitFrame( void ) 266 | { 267 | char szBuffer[8]; 268 | Edit_GetText(hDEBUG_WaitFrame, szBuffer, sizeof(szBuffer) - 1); 269 | 270 | char *pEnd; 271 | int lWaitFrame = strtol(szBuffer, &pEnd, 10); 272 | if ( pEnd != szBuffer && lWaitFrame != g_DEBUG_lWaitFrame ) 273 | { 274 | g_DEBUG_lWaitFrame = lWaitFrame; 275 | g_bUnsavedChanges = TRUE; 276 | } 277 | } 278 | 279 | BOOL CALLBACK DLG_fn_bProc_General( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 280 | { 281 | switch ( uMsg ) 282 | { 283 | case WM_INITDIALOG: 284 | hThis = hWnd; 285 | hStatus = GetDlgItem(hWnd, IDC_STATUSLINE); 286 | hToggle = GetDlgItem(hWnd, IDC_MAINTOGGLE); 287 | hResolution = GetDlgItem(hWnd, IDC_RESOLUTION); 288 | hResX = GetDlgItem(hWnd, IDC_RESX); 289 | hResY = GetDlgItem(hWnd, IDC_RESY); 290 | hResLabel = GetDlgItem(hWnd, IDC_RES_LABEL); 291 | hPatchWidescreen = GetDlgItem(hWnd, IDC_PATCHWIDE); 292 | 293 | hFsModeWin = GetDlgItem(hWnd, IDC_FSMODE_WND); 294 | hFsModeFs = GetDlgItem(hWnd, IDC_FSMODE_FS); 295 | 296 | hAdvGroup = GetDlgItem(hWnd, IDC_ADVGROUP); 297 | hVsync = GetDlgItem(hWnd, IDC_VSYNC); 298 | hRefRateLabel = GetDlgItem(hWnd, IDC_REFRATE_LABEL); 299 | hRefRate = GetDlgItem(hWnd, IDC_REFRATE); 300 | hCleanup = GetDlgItem(hWnd, IDC_CLEANUP); 301 | hDEBUG_WaitFrame = GetDlgItem(hWnd, IDC_DEBUG_WF); 302 | hDEBUG_WaitFrameLabel = GetDlgItem(hWnd, IDC_DEBUG_WF_LABEL); 303 | 304 | fn_vUpdateStatus(hStatus, hToggle); 305 | fn_vPopulateDisplayModes(hResolution); 306 | fn_vPopulateRefRates(hRefRate); 307 | 308 | Button_SetCheck(hVsync, g_bForceVsync); 309 | Button_SetCheck(hFsModeWin, !g_bFullscreen); 310 | Button_SetCheck(hFsModeFs, g_bFullscreen); 311 | Button_SetCheck(hPatchWidescreen, g_bPatchWidescreen); 312 | 313 | SendMessage(hResX, EM_LIMITTEXT, 7, 0); 314 | SendMessage(hResY, EM_LIMITTEXT, 7, 0); 315 | 316 | fn_vInitDebugWaitFrame(); 317 | 318 | return TRUE; 319 | 320 | case WM_ADVTOGGLE: 321 | fn_vToggleAdvanced((BOOL)wParam); 322 | return TRUE; 323 | 324 | case WM_COMMAND: 325 | switch ( LOWORD(wParam) ) 326 | { 327 | case IDC_MAINTOGGLE: 328 | g_bFixState = Button_GetCheck(hToggle); 329 | fn_vUpdateStatus(hStatus, hToggle); 330 | 331 | g_bUnsavedChanges = TRUE; 332 | return TRUE; 333 | 334 | case IDC_RESOLUTION: 335 | if ( HIWORD(wParam) == CBN_SELCHANGE ) 336 | { 337 | if ( ComboBox_GetCurSel(hResolution) == lCbCustomIdx ) 338 | { 339 | fn_vShowCustomRes(); 340 | } 341 | else 342 | { 343 | fn_vSetDisplayMode(hResolution); 344 | g_bUnsavedChanges = TRUE; 345 | } 346 | return TRUE; 347 | } 348 | break; 349 | 350 | case IDC_RESX: 351 | case IDC_RESY: 352 | if ( HIWORD(wParam) == EN_KILLFOCUS ) 353 | { 354 | if ( fn_bSetCustomDisplayMode() ) 355 | g_bUnsavedChanges = TRUE; 356 | 357 | return TRUE; 358 | } 359 | break; 360 | 361 | case IDC_PATCHWIDE: 362 | g_bPatchWidescreen = Button_GetCheck(hPatchWidescreen); 363 | g_bUnsavedChanges = TRUE; 364 | return TRUE; 365 | 366 | case IDC_FSMODE_WND: 367 | g_bFullscreen = FALSE; 368 | Button_SetCheck(hFsModeWin, BST_CHECKED); 369 | Button_SetCheck(hFsModeFs, BST_UNCHECKED); 370 | g_bUnsavedChanges = TRUE; 371 | return TRUE; 372 | 373 | case IDC_FSMODE_FS: 374 | g_bFullscreen = TRUE; 375 | Button_SetCheck(hFsModeWin, BST_UNCHECKED); 376 | Button_SetCheck(hFsModeFs, BST_CHECKED); 377 | g_bUnsavedChanges = TRUE; 378 | return TRUE; 379 | 380 | case IDC_VSYNC: 381 | g_bForceVsync = Button_GetCheck(hVsync); 382 | g_bUnsavedChanges = TRUE; 383 | return TRUE; 384 | 385 | case IDC_REFRATE: 386 | if ( HIWORD(wParam) == CBN_SELCHANGE ) 387 | { 388 | int idx = ComboBox_GetCurSel(hRefRate); 389 | tdeRefRate lRefRate = ComboBox_GetItemData(hRefRate, idx); 390 | 391 | if ( lRefRate != 0 ) 392 | g_eRefRate = lRefRate; 393 | 394 | g_bUnsavedChanges = TRUE; 395 | return TRUE; 396 | } 397 | break; 398 | 399 | case IDC_CLEANUP: 400 | { 401 | char szPrompt[250]; 402 | LoadString(g_hInst, IDS_CLEANUPWARN, szPrompt, sizeof(szPrompt)); 403 | 404 | if ( MessageBox(hWnd, szPrompt, g_szAppName, MB_OKCANCEL | MB_ICONWARNING) == IDOK ) 405 | fn_vManualCleanUp(); 406 | 407 | return TRUE; 408 | } 409 | 410 | case IDC_DEBUG_WF: 411 | if ( HIWORD(wParam) == EN_KILLFOCUS ) 412 | { 413 | fn_vSetDebugWaitFrame(); 414 | return TRUE; 415 | } 416 | break; 417 | } 418 | break; 419 | } 420 | 421 | return FALSE; 422 | } 423 | -------------------------------------------------------------------------------- /R2FixCfg/glidetect.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spitfirex86/Ray2Fix/92cfeaf4c39d56a561e2f0dc11c884a99c739f30/R2FixCfg/glidetect.ico -------------------------------------------------------------------------------- /R2FixCfg/main.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "resource.h" 3 | #include "dialogs.h" 4 | #include "config.h" 5 | #include "main.h" 6 | #include "../gitver.h" 7 | 8 | 9 | HINSTANCE g_hInst; 10 | BOOL g_bUnsavedChanges = FALSE; 11 | 12 | char g_szAppName[80]; 13 | 14 | HWND hTC; 15 | HWND hAdvanced; 16 | HWND hCurrentTab; 17 | 18 | HWND a_hTabs[e_NbTab]; 19 | 20 | tdstTabInfo a_stTabs[e_NbTab] = { 21 | [e_TAB_General] = { IDD_GENERAL, "General", DLG_fn_bProc_General }, 22 | [e_TAB_Pad] = { IDD_PAD, "Gamepad", DLG_fn_bProc_Pad }, 23 | }; 24 | 25 | 26 | void fn_vCreateTabDialogs( HWND hParent, HWND hTabCtrl ) 27 | { 28 | RECT rcTabArea, rcHeaderArea; 29 | GetClientRect(hTabCtrl, &rcTabArea); 30 | TabCtrl_AdjustRect(hTabCtrl, FALSE, &rcTabArea); 31 | TabCtrl_GetItemRect(hTabCtrl, 0, &rcHeaderArea); 32 | 33 | POINT pt = { 0 }; 34 | ClientToScreen(hTabCtrl, &pt); 35 | ScreenToClient(hParent, &pt); 36 | 37 | TCITEM tci = { 0 }; 38 | tci.mask = TCIF_TEXT; 39 | 40 | for ( int i = 0; i < e_NbTab; i++ ) 41 | { 42 | tdstTabInfo *lpTab = &a_stTabs[i]; 43 | 44 | a_hTabs[i] = CreateDialog(g_hInst, MAKEINTRESOURCE(lpTab->lDlgId), hParent, lpTab->pfnDlgProc); 45 | 46 | tci.pszText = lpTab->szTabName; 47 | TabCtrl_InsertItem(hTabCtrl, i, &tci); 48 | 49 | SetWindowPos( 50 | a_hTabs[i], NULL, 51 | rcHeaderArea.left + pt.x + 3, 52 | rcHeaderArea.bottom + pt.y + 3, 53 | rcTabArea.right - rcTabArea.left, 54 | rcTabArea.bottom - rcHeaderArea.bottom - 3, 55 | SWP_NOACTIVATE | SWP_NOZORDER); 56 | } 57 | 58 | hCurrentTab = a_hTabs[0]; 59 | ShowWindow(hCurrentTab, SW_SHOW); 60 | } 61 | 62 | BOOL fn_bAskSaveBeforeClose( HWND hWnd ) 63 | { 64 | char szPrompt[250]; 65 | LoadString(g_hInst, IDS_ASKTOSAVE, szPrompt, sizeof(szPrompt)); 66 | 67 | int result = MessageBox(hWnd, szPrompt, g_szAppName, MB_YESNOCANCEL | MB_ICONASTERISK); 68 | 69 | switch ( result ) 70 | { 71 | case IDYES: 72 | // Save and quit 73 | CFG_fn_vWrite(); 74 | g_bUnsavedChanges = FALSE; 75 | return TRUE; 76 | 77 | case IDNO: 78 | // Discard and quit 79 | return TRUE; 80 | 81 | default: 82 | // Cancelled or closed, do nothing 83 | return FALSE; 84 | } 85 | } 86 | 87 | BOOL CALLBACK fn_bProc_Main( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 88 | { 89 | HICON hIcon; 90 | int nIndex; 91 | BOOL bAdvToggle; 92 | 93 | switch ( uMsg ) 94 | { 95 | case WM_INITDIALOG: 96 | // Set caption and taskbar icon 97 | hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_GLI_ICON)); 98 | SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); 99 | SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); 100 | 101 | hTC = GetDlgItem(hWnd, IDC_TAB1); 102 | fn_vCreateTabDialogs(hWnd, hTC); 103 | 104 | hAdvanced = GetDlgItem(hWnd, IDC_ADVANCED); 105 | 106 | HWND hVerNum = GetDlgItem(hWnd, IDC_VERNUM); 107 | SetWindowText(hVerNum, "Ray2Fix " C_GIT_VER); 108 | 109 | return TRUE; 110 | 111 | case WM_SHOWWINDOW: 112 | if ( wParam == TRUE && lParam == 0 ) 113 | { 114 | HWND hBtn = GetDlgItem(hWnd, IDOK); 115 | SetFocus(hBtn); 116 | } 117 | return TRUE; 118 | 119 | case WM_NOTIFY: 120 | switch ( ((LPNMHDR)lParam)->code ) 121 | { 122 | case TCN_SELCHANGE: 123 | nIndex = TabCtrl_GetCurSel(hTC); 124 | if ( nIndex > -1 ) 125 | { 126 | ShowWindow(hCurrentTab, SW_HIDE); 127 | hCurrentTab = a_hTabs[nIndex]; 128 | ShowWindow(hCurrentTab, SW_SHOW); 129 | } 130 | return TRUE; 131 | } 132 | break; 133 | 134 | case WM_COMMAND: 135 | switch ( LOWORD(wParam) ) 136 | { 137 | case ID_DEBUG: 138 | // TODO: debug stuff 139 | return TRUE; 140 | 141 | case IDC_ADVANCED: 142 | bAdvToggle = Button_GetCheck(hAdvanced); 143 | for ( int i = 0; i < e_NbTab; i++ ) 144 | { 145 | SendMessage(a_hTabs[i], WM_ADVTOGGLE, bAdvToggle, 0); 146 | } 147 | return TRUE; 148 | 149 | case IDOK: 150 | SetFocus(NULL); 151 | CFG_fn_vWrite(); 152 | g_bUnsavedChanges = FALSE; 153 | // fall-through 154 | case IDCANCEL: 155 | SendMessage(hWnd, WM_CLOSE, 0, 0); 156 | return TRUE; 157 | } 158 | break; 159 | 160 | case WM_CLOSE: 161 | if ( g_bUnsavedChanges ) 162 | { 163 | if ( fn_bAskSaveBeforeClose(hWnd) ) 164 | DestroyWindow(hWnd); 165 | } 166 | else 167 | { 168 | DestroyWindow(hWnd); 169 | } 170 | return TRUE; 171 | 172 | case WM_DESTROY: 173 | PostQuitMessage(0); 174 | return TRUE; 175 | } 176 | 177 | return FALSE; 178 | } 179 | 180 | int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) 181 | { 182 | HWND hDlg; 183 | MSG msg; 184 | g_hInst = hInstance; 185 | 186 | LoadRcString(IDS_APPNAME, g_szAppName); 187 | 188 | HANDLE hMutex = CreateMutex(NULL, TRUE, "Ray2FixCfgSI"); 189 | 190 | if ( hMutex == NULL ) 191 | return 1; 192 | 193 | if ( GetLastError() == ERROR_ALREADY_EXISTS ) 194 | { 195 | // If another instance already exists, find the window and activate it 196 | HWND hWndExisting = FindWindow(NULL, g_szAppName); 197 | if ( hWndExisting ) 198 | { 199 | SetForegroundWindow(hWndExisting); 200 | } 201 | 202 | return 0; 203 | } 204 | 205 | CFG_fn_vVerify(); 206 | CFG_fn_vRead(); 207 | DSP_fn_vEnumResolutions(); 208 | 209 | hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, fn_bProc_Main); 210 | 211 | if ( hDlg == NULL ) 212 | return 1; 213 | 214 | SetWindowText(hDlg, g_szAppName); 215 | ShowWindow(hDlg, nCmdShow); 216 | 217 | HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCEL)); 218 | 219 | while ( GetMessage(&msg, NULL, 0, 0) > 0 ) 220 | { 221 | if ( !TranslateAccelerator(hDlg, hAccel, &msg) && !IsDialogMessage(hDlg, &msg) ) 222 | { 223 | TranslateMessage(&msg); 224 | DispatchMessage(&msg); 225 | } 226 | } 227 | 228 | ReleaseMutex(hMutex); 229 | CloseHandle(hMutex); 230 | return 0; 231 | } 232 | -------------------------------------------------------------------------------- /R2FixCfg/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "framework.h" 4 | 5 | 6 | #define LoadRcString(uID, lpBuffer) LoadString(g_hInst, (uID), (lpBuffer), sizeof(lpBuffer)) 7 | #define LoadStringAtChar(uID, lpBuffer, lChar) LoadString(g_hInst, (uID), ((lpBuffer)+(lChar)), (sizeof(lpBuffer)-(lChar)-1)) 8 | 9 | #define WM_ADVTOGGLE (WM_APP + 1) 10 | 11 | 12 | extern HINSTANCE g_hInst; 13 | extern BOOL g_bUnsavedChanges; 14 | 15 | extern char g_szAppName[80]; 16 | -------------------------------------------------------------------------------- /R2FixCfg/pad.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "resource.h" 3 | #include "pad.h" 4 | #include "config.h" 5 | 6 | 7 | char const *g_szXidiPath = ".\\Xidi.ini"; 8 | char const *szDefaultInputValue = "Null"; 9 | 10 | tdstAnalogAction g_a_stAnalogAction[E_NbAnalogAction] = { 11 | #define M_DefineAction(Id, szName, szCfg_X, szCfg_Y) { Id, szName, szCfg_X, szCfg_Y }, 12 | #include "def_analog.h" 13 | }; 14 | 15 | tdstAction g_a_stButtonAction[E_NbButtonAction] = { 16 | #define M_DefineAction(Id, szName, szCfg) { Id, szName, szCfg }, 17 | #include "def_button.h" 18 | }; 19 | 20 | tdstPadConfig g_a_stPadInput[E_NbPadInput] = { 21 | #define M_DefineInput(Id, lCtrl, bAnalog, szCfg) { Id, E_BAc_Null, bAnalog, szCfg }, 22 | #include "def_pad.h" 23 | }; 24 | 25 | 26 | tdstAnalogAction * fn_p_stFindAnalogAction( char const *szCfg_X, char const *szCfg_Y ) 27 | { 28 | for ( int i = 0; i < E_NbAnalogAction; i++ ) 29 | { 30 | tdstAnalogAction *pAction = &g_a_stAnalogAction[i]; 31 | 32 | if ( !_stricmp(pAction->szConfigString_X, szCfg_X) && !_stricmp(pAction->szConfigString_Y, szCfg_Y) ) 33 | return pAction; 34 | } 35 | 36 | return NULL; 37 | } 38 | 39 | tdstAction * fn_p_stFindButtonAction( char const *szCfg ) 40 | { 41 | for ( int i = 0; i < E_NbButtonAction; i++ ) 42 | { 43 | tdstAction *pAction = &g_a_stButtonAction[i]; 44 | 45 | if ( !_stricmp(pAction->szConfigString, szCfg) ) 46 | return pAction; 47 | } 48 | 49 | return NULL; 50 | } 51 | 52 | void PAD_fn_vRead( void ) 53 | { 54 | char szBuffer[C_Pad_MaxCfgString]; 55 | char szBuffer2[C_Pad_MaxCfgString]; 56 | 57 | for ( int i = 0; i < E_NbPadInput; i++ ) 58 | { 59 | tdstPadConfig *pInput = &g_a_stPadInput[i]; 60 | 61 | if ( pInput->bIsAnalog ) 62 | { 63 | char szNameAxis[C_Pad_MaxName]; 64 | 65 | sprintf_s(szNameAxis, C_Pad_MaxName, "%s%s", pInput->szName, "X"); 66 | GetPrivateProfileString("CustomMapper:Ray2Fix", szNameAxis, szDefaultInputValue, szBuffer, sizeof(szBuffer), g_szXidiPath); 67 | sprintf_s(szNameAxis, C_Pad_MaxName, "%s%s", pInput->szName, "Y"); 68 | GetPrivateProfileString("CustomMapper:Ray2Fix", szNameAxis, szDefaultInputValue, szBuffer2, sizeof(szBuffer2), g_szXidiPath); 69 | 70 | tdstAnalogAction *pAction = fn_p_stFindAnalogAction(szBuffer, szBuffer2); 71 | if ( pAction ) 72 | { 73 | pInput->lAction = pAction->lId; 74 | } 75 | else 76 | { 77 | pInput->lAction = C_Pad_InvalidAction; 78 | g_eError |= e_ES_Warning; 79 | g_eErrorDetails |= e_VE_XidiModified; 80 | } 81 | } 82 | else 83 | { 84 | GetPrivateProfileString("CustomMapper:Ray2Fix", pInput->szName, szDefaultInputValue, szBuffer, sizeof(szBuffer), g_szXidiPath); 85 | 86 | tdstAction *pAction = fn_p_stFindButtonAction(szBuffer); 87 | if ( pAction ) 88 | { 89 | pInput->lAction = pAction->lId; 90 | } 91 | else 92 | { 93 | pInput->lAction = C_Pad_InvalidAction; 94 | g_eError |= e_ES_Warning; 95 | g_eErrorDetails |= e_VE_XidiModified; 96 | } 97 | } 98 | } 99 | } 100 | 101 | void PAD_fn_vWrite( void ) 102 | { 103 | WritePrivateProfileString("Mapper", "Type.1", "Ray2Fix", g_szXidiPath); 104 | 105 | for ( int i = 0; i < E_NbPadInput; i++ ) 106 | { 107 | tdstPadConfig *pInput = &g_a_stPadInput[i]; 108 | 109 | if ( pInput->lAction == C_Pad_InvalidAction ) 110 | continue; 111 | 112 | if ( pInput->bIsAnalog ) 113 | { 114 | tdstAnalogAction *pAction = &g_a_stAnalogAction[pInput->lAction]; 115 | char szNameAxis[C_Pad_MaxName]; 116 | 117 | sprintf_s(szNameAxis, C_Pad_MaxName, "%s%s", pInput->szName, "X"); 118 | WritePrivateProfileString("CustomMapper:Ray2Fix", szNameAxis, pAction->szConfigString_X, g_szXidiPath); 119 | sprintf_s(szNameAxis, C_Pad_MaxName, "%s%s", pInput->szName, "Y"); 120 | WritePrivateProfileString("CustomMapper:Ray2Fix", szNameAxis, pAction->szConfigString_Y, g_szXidiPath); 121 | 122 | } 123 | else 124 | { 125 | tdstAction *pAction = &g_a_stButtonAction[pInput->lAction]; 126 | WritePrivateProfileString("CustomMapper:Ray2Fix", pInput->szName, pAction->szConfigString, g_szXidiPath); 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /R2FixCfg/pad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | 4 | 5 | #define C_Pad_InvalidAction (-1) 6 | #define C_Pad_MaxName 40 7 | #define C_Pad_MaxCfgString 80 8 | 9 | 10 | typedef enum tdeAnalogAction_ 11 | { 12 | #define M_DefineAction(Id, szName, szCfg_X, szCfg_Y) Id, 13 | #include "def_analog.h" 14 | 15 | E_NbAnalogAction 16 | } 17 | tdeAnalogAction; 18 | 19 | typedef enum tdeButtonAction_ 20 | { 21 | #define M_DefineAction(Id, szName, szCfg) Id, 22 | #include "def_button.h" 23 | 24 | E_NbButtonAction 25 | } 26 | tdeButtonAction; 27 | 28 | typedef enum tdePadInput_ 29 | { 30 | #define M_DefineInput(Id, lCtrl, bAnalog, szCfg) Id, 31 | #include "def_pad.h" 32 | 33 | E_NbPadInput 34 | } 35 | tdePadInput; 36 | 37 | 38 | typedef struct tdstAnalogAction_ 39 | { 40 | int lId; 41 | char szName[C_Pad_MaxName]; 42 | char szConfigString_X[C_Pad_MaxCfgString]; 43 | char szConfigString_Y[C_Pad_MaxCfgString]; 44 | } 45 | tdstAnalogAction; 46 | 47 | typedef struct tdstAction_ 48 | { 49 | int lId; 50 | char szName[C_Pad_MaxName]; 51 | char szConfigString[C_Pad_MaxCfgString]; 52 | } 53 | tdstAction; 54 | 55 | typedef struct tdstPadConfig_ 56 | { 57 | int lId; 58 | int lAction; 59 | BOOL bIsAnalog; 60 | char szName[C_Pad_MaxName]; 61 | } 62 | tdstPadConfig; 63 | 64 | typedef struct tdstPadDlgItem_ 65 | { 66 | int lId; 67 | int lCtrlId; 68 | HWND hCtrl; 69 | BOOL bIsAnalog; 70 | } 71 | tdstPadDlgItem; 72 | 73 | 74 | extern char const *g_szXidiPath; 75 | 76 | extern tdstAnalogAction g_a_stAnalogAction[E_NbAnalogAction]; 77 | extern tdstAction g_a_stButtonAction[E_NbButtonAction]; 78 | extern tdstPadConfig g_a_stPadInput[E_NbPadInput]; 79 | 80 | 81 | void PAD_fn_vRead( void ); 82 | void PAD_fn_vWrite( void ); 83 | -------------------------------------------------------------------------------- /R2FixCfg/paddlg.c: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | #include "resource.h" 3 | #include "dialogs.h" 4 | #include "config.h" 5 | #include "main.h" 6 | #include "pad.h" 7 | 8 | 9 | HWND hDlg; 10 | 11 | tdstPadDlgItem a_stPadDlgItem[E_NbPadInput] = { 12 | #define M_DefineInput(Id, lCtrl, bAnalog, szCfg) { Id, lCtrl, NULL, bAnalog }, 13 | #include "def_pad.h" 14 | }; 15 | 16 | 17 | void fn_vPopulateInputCB( tdstPadDlgItem *pItem ) 18 | { 19 | HWND hCtrl = pItem->hCtrl; 20 | 21 | if ( pItem->bIsAnalog ) 22 | { 23 | for ( int i = 0; i < E_NbAnalogAction; i++ ) 24 | { 25 | int lId = ComboBox_AddString(hCtrl, g_a_stAnalogAction[i].szName); 26 | ComboBox_SetItemData(hCtrl, lId, i); 27 | } 28 | } 29 | else 30 | { 31 | for ( int i = 0; i < E_NbButtonAction; i++ ) 32 | { 33 | int lId = ComboBox_AddString(hCtrl, g_a_stButtonAction[i].szName); 34 | ComboBox_SetItemData(hCtrl, lId, i); 35 | } 36 | } 37 | 38 | ComboBox_SetCurSel(hCtrl, g_a_stPadInput[pItem->lId].lAction); 39 | } 40 | 41 | tdstPadDlgItem * fn_p_stGetPadDlgItem( int lCtrlId ) 42 | { 43 | for ( int i = 0; i < E_NbPadInput; i++ ) 44 | { 45 | tdstPadDlgItem *pItem = &a_stPadDlgItem[i]; 46 | 47 | if ( pItem->lCtrlId == lCtrlId ) 48 | return pItem; 49 | } 50 | 51 | return NULL; 52 | } 53 | 54 | void fn_vUpdatePadInput( tdstPadDlgItem *pItem ) 55 | { 56 | tdstPadConfig *pInput = &g_a_stPadInput[pItem->lId]; 57 | 58 | int lIdx = ComboBox_GetCurSel(pItem->hCtrl); 59 | if ( lIdx > -1 ) 60 | { 61 | int lActionId = ComboBox_GetItemData(pItem->hCtrl, lIdx); 62 | pInput->lAction = lActionId; 63 | } 64 | else 65 | { 66 | pInput->lAction = C_Pad_InvalidAction; 67 | } 68 | } 69 | 70 | BOOL CALLBACK DLG_fn_bProc_Pad( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 71 | { 72 | switch ( uMsg ) 73 | { 74 | case WM_INITDIALOG: 75 | hDlg = hWnd; 76 | 77 | for ( int i = 0; i < E_NbPadInput; i++ ) 78 | { 79 | tdstPadDlgItem *pItem = &a_stPadDlgItem[i]; 80 | pItem->hCtrl = GetDlgItem(hWnd, pItem->lCtrlId); 81 | 82 | fn_vPopulateInputCB(pItem); 83 | } 84 | return TRUE; 85 | 86 | case WM_COMMAND: 87 | { 88 | tdstPadDlgItem *pItem = fn_p_stGetPadDlgItem(LOWORD(wParam)); 89 | if ( pItem && HIWORD(wParam) == CBN_SELCHANGE ) 90 | { 91 | fn_vUpdatePadInput(pItem); 92 | g_bUnsavedChanges = TRUE; 93 | return TRUE; 94 | } 95 | break; 96 | } 97 | } 98 | 99 | return FALSE; 100 | } 101 | -------------------------------------------------------------------------------- /R2FixCfg/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | // 5 | #define IDI_GLI_ICON 101 6 | #define IDD_MAIN 102 7 | #define IDS_APPNAME 104 8 | #define IDS_FLAVORTEXT 105 9 | #define IDS_GREETING 106 10 | #define IDD_GENERAL 106 11 | #define IDS_U_ENABLED 107 12 | #define IDS_U_DISABLED 108 13 | #define IDD_PAD 108 14 | #define IDI_RAYHEAD 109 15 | #define IDS_ASKTOSAVE 109 16 | #define IDS_ENABLED 110 17 | #define IDR_ACCEL 110 18 | #define IDS_DISABLED 111 19 | #define IDS_FIXSTATUS 112 20 | #define IDS_STATUSCHANGED 113 21 | #define IDS_B_ENABLE 114 22 | #define IDS_B_DISABLE 115 23 | #define IDS_VE_OK 116 24 | #define IDS_VE_HEADER 117 25 | #define IDS_VE_REINSTALLFIX 118 26 | #define IDS_VE_REINSTALLR2 119 27 | #define IDS_VE_DEGE 120 28 | #define IDS_VE_GLIDE 121 29 | #define IDS_VE_FIX 122 30 | #define IDS_VE_DINPUT 123 31 | #define IDS_VE_XIDI 124 32 | #define IDS_VE_SETPAD 125 33 | #define IDS_VE_XIDICHANGED 126 34 | #define IDS_WARNING 127 35 | #define IDS_VE_OKWARN 128 36 | #define IDS_NEWLINE 129 37 | #define IDS_CLEANUPWARN 130 38 | #define IDC_MAINTOGGLE 1001 39 | #define IDC_STATUSLINE 1002 40 | #define IDC_TAB1 1006 41 | #define IDC_RESOLUTION 1008 42 | #define IDC_VSYNC 1014 43 | #define IDC_ADVANCED 1019 44 | #define IDC_ADVGROUP 1020 45 | #define IDC_REFRATE 1021 46 | #define IDC_REFRATE_LABEL 1022 47 | #define IDC_FSMODE_WND 1023 48 | #define IDC_FSMODE_FS 1024 49 | #define IDC_RESX 1029 50 | #define IDC_RESY 1030 51 | #define IDC_RES_LABEL 1031 52 | #define IDC_LS 1032 53 | #define IDC_CHECK1 1036 54 | #define IDC_PATCHWIDE 1036 55 | #define IDC_CLEANUP 1037 56 | #define IDC_EDIT1 1041 57 | #define IDC_DEBUG_WF 1041 58 | #define IDC_DEBUG_WF_LABEL 1042 59 | #define IDC_VERNUM 1043 60 | #define IDC_RS 1062 61 | #define IDC_LSCLICK 1063 62 | #define IDC_RSCLICK 1064 63 | #define IDC_DUP 1065 64 | #define IDC_DDOWN 1066 65 | #define IDC_DLEFT 1067 66 | #define IDC_DRIGHT 1068 67 | #define IDC_AA 1069 68 | #define IDC_BB 1070 69 | #define IDC_XX 1071 70 | #define IDC_YY 1072 71 | #define IDC_RT 1073 72 | #define IDC_RB 1074 73 | #define IDC_LT 1075 74 | #define IDC_LB 1076 75 | #define IDC_BBACK 1077 76 | #define IDC_COMBO18 1078 77 | #define IDC_BSTART 1078 78 | #define ID_DEBUG 40001 79 | 80 | // Next default values for new objects 81 | // 82 | #ifdef APSTUDIO_INVOKED 83 | #ifndef APSTUDIO_READONLY_SYMBOLS 84 | #define _APS_NEXT_RESOURCE_VALUE 111 85 | #define _APS_NEXT_COMMAND_VALUE 40003 86 | #define _APS_NEXT_CONTROL_VALUE 1044 87 | #define _APS_NEXT_SYMED_VALUE 101 88 | #endif 89 | #endif 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ray2Fix 2 | 3 | Ray2Fix is a collection of fixes and a configuration tool that aims to simplify setting up Rayman 2 for speedrunners. 4 | 5 | **Note:** Mod loading functionality has been moved to a separate project - [Twofold](https://github.com/spitfirex86/Twofold) - and is no longer included in Ray2Fix. 6 | 7 | ## How to Install 8 | 9 | #### Game versions: 10 | - Recommended: The [GOG.com version](https://www.gog.com/game/rayman_2_the_great_escape) of the game installed using the [standalone installer](https://www.gog.com/downloads/rayman_2_the_great_escape/en1installer0). 11 | - Retail CD/DVD versions are not supported (due to a different game EXE that includes DRM). 12 | - GOG Galaxy is not recommended, but should work (use the standalone installer if possible). 13 | - Uplay/Ubisoft Connect is not officially supported - try at your own risk. 14 | 15 | #### Guide: 16 | - Download the **[latest release zip](https://github.com/spitfirex86/Ray2Fix/releases/latest)** and extract all files to Rayman 2 installation directory. 17 | - Run R2FixCfg.exe and choose your preferred display settings in the General tab. 18 | - (Optional) Customize the controller layout in the Gamepad tab. 19 | 20 | #### Controller troubleshooting: 21 | - Make sure the controller supports XInput. 22 | - Make sure only one controller is plugged in (including virtual controllers). 23 | -------------------------------------------------------------------------------- /Ray2Fix.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.11.35103.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GliFixVf", "GliFixVf\GliFixVf.vcxproj", "{1EC3BBC4-8138-4627-85AB-801015C5A07D}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "R2FixCfg", "R2FixCfg\R2FixCfg.vcxproj", "{5552F301-C48C-4C38-9453-C68DA5D25F4F}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{03FD0719-FBD1-49C1-AB3C-BECE94233FDE}" 11 | ProjectSection(SolutionItems) = preProject 12 | .gitignore = .gitignore 13 | .github\workflows\build.yml = .github\workflows\build.yml 14 | generate_gitver.cmd = generate_gitver.cmd 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|x86 = Debug|x86 20 | Release|x86 = Release|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {1EC3BBC4-8138-4627-85AB-801015C5A07D}.Debug|x86.ActiveCfg = Debug|Win32 24 | {1EC3BBC4-8138-4627-85AB-801015C5A07D}.Debug|x86.Build.0 = Debug|Win32 25 | {1EC3BBC4-8138-4627-85AB-801015C5A07D}.Release|x86.ActiveCfg = Release|Win32 26 | {1EC3BBC4-8138-4627-85AB-801015C5A07D}.Release|x86.Build.0 = Release|Win32 27 | {5552F301-C48C-4C38-9453-C68DA5D25F4F}.Debug|x86.ActiveCfg = Debug|Win32 28 | {5552F301-C48C-4C38-9453-C68DA5D25F4F}.Debug|x86.Build.0 = Debug|Win32 29 | {5552F301-C48C-4C38-9453-C68DA5D25F4F}.Release|x86.ActiveCfg = Release|Win32 30 | {5552F301-C48C-4C38-9453-C68DA5D25F4F}.Release|x86.Build.0 = Release|Win32 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | GlobalSection(ExtensibilityGlobals) = postSolution 36 | SolutionGuid = {AD38E4A1-97AD-419F-A95F-177434FE2195} 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /generate_gitver.cmd: -------------------------------------------------------------------------------- 1 | set TFILE="%~dp0\gitver.h" 2 | for /f "tokens=*" %%s in ('git describe --always --tags --abbrev^=4 --dirty^=-d') do (set TDEF1=%%s) 3 | for /f "tokens=*" %%s in ('git describe --always --tags --abbrev^=0') do (set TDEF2=%%s) 4 | 5 | >%TFILE% ( 6 | echo #pragma once 7 | echo. 8 | echo #define C_GIT_VER "%TDEF1%" 9 | echo #define C_GIT_TAG "%TDEF2%" 10 | echo. 11 | ) 12 | -------------------------------------------------------------------------------- /inc/detours.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Core Detours Functionality (detours.h of detours.lib) 4 | // 5 | // Microsoft Research Detours Package, Version 4.0.1 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | // 9 | 10 | #pragma once 11 | #ifndef _DETOURS_H_ 12 | #define _DETOURS_H_ 13 | 14 | #define DETOURS_VERSION 0x4c0c1 // 0xMAJORcMINORcPATCH 15 | 16 | ////////////////////////////////////////////////////////////////////////////// 17 | // 18 | 19 | #undef DETOURS_X64 20 | #undef DETOURS_X86 21 | #undef DETOURS_IA64 22 | #undef DETOURS_ARM 23 | #undef DETOURS_ARM64 24 | #undef DETOURS_BITS 25 | #undef DETOURS_32BIT 26 | #undef DETOURS_64BIT 27 | 28 | #if defined(_X86_) 29 | #define DETOURS_X86 30 | #define DETOURS_OPTION_BITS 64 31 | 32 | #elif defined(_AMD64_) 33 | #define DETOURS_X64 34 | #define DETOURS_OPTION_BITS 32 35 | 36 | #elif defined(_IA64_) 37 | #define DETOURS_IA64 38 | #define DETOURS_OPTION_BITS 32 39 | 40 | #elif defined(_ARM_) 41 | #define DETOURS_ARM 42 | 43 | #elif defined(_ARM64_) 44 | #define DETOURS_ARM64 45 | 46 | #else 47 | #error Unknown architecture (x86, amd64, ia64, arm, arm64) 48 | #endif 49 | 50 | #ifdef _WIN64 51 | #undef DETOURS_32BIT 52 | #define DETOURS_64BIT 1 53 | #define DETOURS_BITS 64 54 | // If all 64bit kernels can run one and only one 32bit architecture. 55 | //#define DETOURS_OPTION_BITS 32 56 | #else 57 | #define DETOURS_32BIT 1 58 | #undef DETOURS_64BIT 59 | #define DETOURS_BITS 32 60 | // If all 64bit kernels can run one and only one 32bit architecture. 61 | //#define DETOURS_OPTION_BITS 32 62 | #endif 63 | 64 | #define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) 65 | 66 | ////////////////////////////////////////////////////////////////////////////// 67 | // 68 | 69 | #if (_MSC_VER < 1299) 70 | typedef LONG LONG_PTR; 71 | typedef ULONG ULONG_PTR; 72 | #endif 73 | 74 | ///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL. 75 | // 76 | // These definitions are include so that Detours will build even if the 77 | // compiler doesn't have full SAL 2.0 support. 78 | // 79 | #ifndef DETOURS_DONT_REMOVE_SAL_20 80 | 81 | #ifdef DETOURS_TEST_REMOVE_SAL_20 82 | #undef _Analysis_assume_ 83 | #undef _Benign_race_begin_ 84 | #undef _Benign_race_end_ 85 | #undef _Field_range_ 86 | #undef _Field_size_ 87 | #undef _In_ 88 | #undef _In_bytecount_ 89 | #undef _In_count_ 90 | #undef _In_opt_ 91 | #undef _In_opt_bytecount_ 92 | #undef _In_opt_count_ 93 | #undef _In_opt_z_ 94 | #undef _In_range_ 95 | #undef _In_reads_ 96 | #undef _In_reads_bytes_ 97 | #undef _In_reads_opt_ 98 | #undef _In_reads_opt_bytes_ 99 | #undef _In_reads_or_z_ 100 | #undef _In_z_ 101 | #undef _Inout_ 102 | #undef _Inout_opt_ 103 | #undef _Inout_z_count_ 104 | #undef _Out_ 105 | #undef _Out_opt_ 106 | #undef _Out_writes_ 107 | #undef _Outptr_result_maybenull_ 108 | #undef _Readable_bytes_ 109 | #undef _Success_ 110 | #undef _Writable_bytes_ 111 | #undef _Pre_notnull_ 112 | #endif 113 | 114 | #if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_) 115 | #define _Outptr_result_maybenull_ _Deref_out_opt_z_ 116 | #endif 117 | 118 | #if defined(_In_count_) && !defined(_In_reads_) 119 | #define _In_reads_(x) _In_count_(x) 120 | #endif 121 | 122 | #if defined(_In_opt_count_) && !defined(_In_reads_opt_) 123 | #define _In_reads_opt_(x) _In_opt_count_(x) 124 | #endif 125 | 126 | #if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_) 127 | #define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x) 128 | #endif 129 | 130 | #if defined(_In_bytecount_) && !defined(_In_reads_bytes_) 131 | #define _In_reads_bytes_(x) _In_bytecount_(x) 132 | #endif 133 | 134 | #ifndef _In_ 135 | #define _In_ 136 | #endif 137 | 138 | #ifndef _In_bytecount_ 139 | #define _In_bytecount_(x) 140 | #endif 141 | 142 | #ifndef _In_count_ 143 | #define _In_count_(x) 144 | #endif 145 | 146 | #ifndef _In_opt_ 147 | #define _In_opt_ 148 | #endif 149 | 150 | #ifndef _In_opt_bytecount_ 151 | #define _In_opt_bytecount_(x) 152 | #endif 153 | 154 | #ifndef _In_opt_count_ 155 | #define _In_opt_count_(x) 156 | #endif 157 | 158 | #ifndef _In_opt_z_ 159 | #define _In_opt_z_ 160 | #endif 161 | 162 | #ifndef _In_range_ 163 | #define _In_range_(x,y) 164 | #endif 165 | 166 | #ifndef _In_reads_ 167 | #define _In_reads_(x) 168 | #endif 169 | 170 | #ifndef _In_reads_bytes_ 171 | #define _In_reads_bytes_(x) 172 | #endif 173 | 174 | #ifndef _In_reads_opt_ 175 | #define _In_reads_opt_(x) 176 | #endif 177 | 178 | #ifndef _In_reads_opt_bytes_ 179 | #define _In_reads_opt_bytes_(x) 180 | #endif 181 | 182 | #ifndef _In_reads_or_z_ 183 | #define _In_reads_or_z_ 184 | #endif 185 | 186 | #ifndef _In_z_ 187 | #define _In_z_ 188 | #endif 189 | 190 | #ifndef _Inout_ 191 | #define _Inout_ 192 | #endif 193 | 194 | #ifndef _Inout_opt_ 195 | #define _Inout_opt_ 196 | #endif 197 | 198 | #ifndef _Inout_z_count_ 199 | #define _Inout_z_count_(x) 200 | #endif 201 | 202 | #ifndef _Out_ 203 | #define _Out_ 204 | #endif 205 | 206 | #ifndef _Out_opt_ 207 | #define _Out_opt_ 208 | #endif 209 | 210 | #ifndef _Out_writes_ 211 | #define _Out_writes_(x) 212 | #endif 213 | 214 | #ifndef _Outptr_result_maybenull_ 215 | #define _Outptr_result_maybenull_ 216 | #endif 217 | 218 | #ifndef _Writable_bytes_ 219 | #define _Writable_bytes_(x) 220 | #endif 221 | 222 | #ifndef _Readable_bytes_ 223 | #define _Readable_bytes_(x) 224 | #endif 225 | 226 | #ifndef _Success_ 227 | #define _Success_(x) 228 | #endif 229 | 230 | #ifndef _Pre_notnull_ 231 | #define _Pre_notnull_ 232 | #endif 233 | 234 | #ifdef DETOURS_INTERNAL 235 | 236 | #pragma warning(disable:4615) // unknown warning type (suppress with older compilers) 237 | 238 | #ifndef _Benign_race_begin_ 239 | #define _Benign_race_begin_ 240 | #endif 241 | 242 | #ifndef _Benign_race_end_ 243 | #define _Benign_race_end_ 244 | #endif 245 | 246 | #ifndef _Field_size_ 247 | #define _Field_size_(x) 248 | #endif 249 | 250 | #ifndef _Field_range_ 251 | #define _Field_range_(x,y) 252 | #endif 253 | 254 | #ifndef _Analysis_assume_ 255 | #define _Analysis_assume_(x) 256 | #endif 257 | 258 | #endif // DETOURS_INTERNAL 259 | #endif // DETOURS_DONT_REMOVE_SAL_20 260 | 261 | ////////////////////////////////////////////////////////////////////////////// 262 | // 263 | #ifndef GUID_DEFINED 264 | #define GUID_DEFINED 265 | typedef struct _GUID 266 | { 267 | DWORD Data1; 268 | WORD Data2; 269 | WORD Data3; 270 | BYTE Data4[ 8 ]; 271 | } GUID; 272 | 273 | #ifdef INITGUID 274 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 275 | const GUID name \ 276 | = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 277 | #else 278 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 279 | const GUID name 280 | #endif // INITGUID 281 | #endif // !GUID_DEFINED 282 | 283 | #if defined(__cplusplus) 284 | #ifndef _REFGUID_DEFINED 285 | #define _REFGUID_DEFINED 286 | #define REFGUID const GUID & 287 | #endif // !_REFGUID_DEFINED 288 | #else // !__cplusplus 289 | #ifndef _REFGUID_DEFINED 290 | #define _REFGUID_DEFINED 291 | #define REFGUID const GUID * const 292 | #endif // !_REFGUID_DEFINED 293 | #endif // !__cplusplus 294 | 295 | #ifndef ARRAYSIZE 296 | #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) 297 | #endif 298 | 299 | // 300 | ////////////////////////////////////////////////////////////////////////////// 301 | 302 | #ifdef __cplusplus 303 | extern "C" { 304 | #endif // __cplusplus 305 | 306 | /////////////////////////////////////////////////// Instruction Target Macros. 307 | // 308 | #define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0) 309 | #define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1) 310 | #define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0" 311 | 312 | extern const GUID DETOUR_EXE_RESTORE_GUID; 313 | extern const GUID DETOUR_EXE_HELPER_GUID; 314 | 315 | #define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr! 316 | typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE; 317 | 318 | /////////////////////////////////////////////////////////// Binary Structures. 319 | // 320 | #pragma pack(push, 8) 321 | typedef struct _DETOUR_SECTION_HEADER 322 | { 323 | DWORD cbHeaderSize; 324 | DWORD nSignature; 325 | DWORD nDataOffset; 326 | DWORD cbDataSize; 327 | 328 | DWORD nOriginalImportVirtualAddress; 329 | DWORD nOriginalImportSize; 330 | DWORD nOriginalBoundImportVirtualAddress; 331 | DWORD nOriginalBoundImportSize; 332 | 333 | DWORD nOriginalIatVirtualAddress; 334 | DWORD nOriginalIatSize; 335 | DWORD nOriginalSizeOfImage; 336 | DWORD cbPrePE; 337 | 338 | DWORD nOriginalClrFlags; 339 | DWORD reserved1; 340 | DWORD reserved2; 341 | DWORD reserved3; 342 | 343 | // Followed by cbPrePE bytes of data. 344 | } DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER; 345 | 346 | typedef struct _DETOUR_SECTION_RECORD 347 | { 348 | DWORD cbBytes; 349 | DWORD nReserved; 350 | GUID guid; 351 | } DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD; 352 | 353 | typedef struct _DETOUR_CLR_HEADER 354 | { 355 | // Header versioning 356 | ULONG cb; 357 | USHORT MajorRuntimeVersion; 358 | USHORT MinorRuntimeVersion; 359 | 360 | // Symbol table and startup information 361 | IMAGE_DATA_DIRECTORY MetaData; 362 | ULONG Flags; 363 | 364 | // Followed by the rest of the IMAGE_COR20_HEADER 365 | } DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER; 366 | 367 | typedef struct _DETOUR_EXE_RESTORE 368 | { 369 | DWORD cb; 370 | DWORD cbidh; 371 | DWORD cbinh; 372 | DWORD cbclr; 373 | 374 | PBYTE pidh; 375 | PBYTE pinh; 376 | PBYTE pclr; 377 | 378 | IMAGE_DOS_HEADER idh; 379 | union { 380 | IMAGE_NT_HEADERS inh; 381 | IMAGE_NT_HEADERS32 inh32; 382 | IMAGE_NT_HEADERS64 inh64; 383 | BYTE raw[sizeof(IMAGE_NT_HEADERS64) + 384 | sizeof(IMAGE_SECTION_HEADER) * 32]; 385 | }; 386 | DETOUR_CLR_HEADER clr; 387 | 388 | } DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE; 389 | 390 | typedef struct _DETOUR_EXE_HELPER 391 | { 392 | DWORD cb; 393 | DWORD pid; 394 | DWORD nDlls; 395 | CHAR rDlls[4]; 396 | } DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER; 397 | 398 | #pragma pack(pop) 399 | 400 | #define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \ 401 | { \ 402 | sizeof(DETOUR_SECTION_HEADER),\ 403 | DETOUR_SECTION_HEADER_SIGNATURE,\ 404 | sizeof(DETOUR_SECTION_HEADER),\ 405 | (cbSectionSize),\ 406 | \ 407 | 0,\ 408 | 0,\ 409 | 0,\ 410 | 0,\ 411 | \ 412 | 0,\ 413 | 0,\ 414 | 0,\ 415 | 0,\ 416 | } 417 | 418 | /////////////////////////////////////////////////////////////// Helper Macros. 419 | // 420 | #define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) 421 | #define DETOURS_STRINGIFY_(x) #x 422 | 423 | ///////////////////////////////////////////////////////////// Binary Typedefs. 424 | // 425 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)( 426 | _In_opt_ PVOID pContext, 427 | _In_opt_ LPCSTR pszFile, 428 | _Outptr_result_maybenull_ LPCSTR *ppszOutFile); 429 | 430 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)( 431 | _In_opt_ PVOID pContext, 432 | _In_ LPCSTR pszOrigFile, 433 | _In_ LPCSTR pszFile, 434 | _Outptr_result_maybenull_ LPCSTR *ppszOutFile); 435 | 436 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)( 437 | _In_opt_ PVOID pContext, 438 | _In_ ULONG nOrigOrdinal, 439 | _In_ ULONG nOrdinal, 440 | _Out_ ULONG *pnOutOrdinal, 441 | _In_opt_ LPCSTR pszOrigSymbol, 442 | _In_opt_ LPCSTR pszSymbol, 443 | _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol); 444 | 445 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)( 446 | _In_opt_ PVOID pContext); 447 | 448 | typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext, 449 | _In_ ULONG nOrdinal, 450 | _In_opt_ LPCSTR pszName, 451 | _In_opt_ PVOID pCode); 452 | 453 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext, 454 | _In_opt_ HMODULE hModule, 455 | _In_opt_ LPCSTR pszFile); 456 | 457 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext, 458 | _In_ DWORD nOrdinal, 459 | _In_opt_ LPCSTR pszFunc, 460 | _In_opt_ PVOID pvFunc); 461 | 462 | // Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter. 463 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext, 464 | _In_ DWORD nOrdinal, 465 | _In_opt_ LPCSTR pszFunc, 466 | _In_opt_ PVOID* ppvFunc); 467 | 468 | typedef VOID * PDETOUR_BINARY; 469 | typedef VOID * PDETOUR_LOADED_BINARY; 470 | 471 | //////////////////////////////////////////////////////////// Transaction APIs. 472 | // 473 | LONG WINAPI DetourTransactionBegin(VOID); 474 | LONG WINAPI DetourTransactionAbort(VOID); 475 | LONG WINAPI DetourTransactionCommit(VOID); 476 | LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer); 477 | 478 | LONG WINAPI DetourUpdateThread(_In_ HANDLE hThread); 479 | 480 | LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer, 481 | _In_ PVOID pDetour); 482 | 483 | LONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer, 484 | _In_ PVOID pDetour, 485 | _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline, 486 | _Out_opt_ PVOID *ppRealTarget, 487 | _Out_opt_ PVOID *ppRealDetour); 488 | 489 | LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer, 490 | _In_ PVOID pDetour); 491 | 492 | BOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore); 493 | BOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain); 494 | PVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound); 495 | PVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound); 496 | 497 | ////////////////////////////////////////////////////////////// Code Functions. 498 | // 499 | PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule, 500 | _In_ LPCSTR pszFunction); 501 | PVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer, 502 | _Out_opt_ PVOID *ppGlobals); 503 | PVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst, 504 | _Inout_opt_ PVOID *ppDstPool, 505 | _In_ PVOID pSrc, 506 | _Out_opt_ PVOID *ppTarget, 507 | _Out_opt_ LONG *plExtra); 508 | BOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule, 509 | _In_ BOOL fLimitReferencesToModule); 510 | 511 | ///////////////////////////////////////////////////// Loaded Binary Functions. 512 | // 513 | HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr); 514 | HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast); 515 | PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule); 516 | ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule); 517 | BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule, 518 | _In_opt_ PVOID pContext, 519 | _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport); 520 | BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule, 521 | _In_opt_ PVOID pContext, 522 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, 523 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc); 524 | 525 | BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule, 526 | _In_opt_ PVOID pContext, 527 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, 528 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx); 529 | 530 | _Writable_bytes_(*pcbData) 531 | _Readable_bytes_(*pcbData) 532 | _Success_(return != NULL) 533 | PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule, 534 | _In_ REFGUID rguid, 535 | _Out_ DWORD *pcbData); 536 | 537 | _Writable_bytes_(*pcbData) 538 | _Readable_bytes_(*pcbData) 539 | _Success_(return != NULL) 540 | PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid, 541 | _Out_ DWORD * pcbData); 542 | 543 | DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule); 544 | 545 | ///////////////////////////////////////////////// Persistent Binary Functions. 546 | // 547 | 548 | PDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile); 549 | 550 | _Writable_bytes_(*pcbData) 551 | _Readable_bytes_(*pcbData) 552 | _Success_(return != NULL) 553 | PVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary, 554 | _Out_opt_ GUID *pGuid, 555 | _Out_ DWORD *pcbData, 556 | _Inout_ DWORD *pnIterator); 557 | 558 | _Writable_bytes_(*pcbData) 559 | _Readable_bytes_(*pcbData) 560 | _Success_(return != NULL) 561 | PVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary, 562 | _In_ REFGUID rguid, 563 | _Out_ DWORD *pcbData); 564 | 565 | PVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary, 566 | _In_ REFGUID rguid, 567 | _In_reads_opt_(cbData) PVOID pData, 568 | _In_ DWORD cbData); 569 | BOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid); 570 | BOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary); 571 | BOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary); 572 | BOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary, 573 | _In_opt_ PVOID pContext, 574 | _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway, 575 | _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile, 576 | _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol, 577 | _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit); 578 | BOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile); 579 | BOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary); 580 | 581 | /////////////////////////////////////////////////// Create Process & Load Dll. 582 | // 583 | typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)( 584 | _In_opt_ LPCSTR lpApplicationName, 585 | _Inout_opt_ LPSTR lpCommandLine, 586 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 587 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 588 | _In_ BOOL bInheritHandles, 589 | _In_ DWORD dwCreationFlags, 590 | _In_opt_ LPVOID lpEnvironment, 591 | _In_opt_ LPCSTR lpCurrentDirectory, 592 | _In_ LPSTARTUPINFOA lpStartupInfo, 593 | _Out_ LPPROCESS_INFORMATION lpProcessInformation); 594 | 595 | typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)( 596 | _In_opt_ LPCWSTR lpApplicationName, 597 | _Inout_opt_ LPWSTR lpCommandLine, 598 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 599 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 600 | _In_ BOOL bInheritHandles, 601 | _In_ DWORD dwCreationFlags, 602 | _In_opt_ LPVOID lpEnvironment, 603 | _In_opt_ LPCWSTR lpCurrentDirectory, 604 | _In_ LPSTARTUPINFOW lpStartupInfo, 605 | _Out_ LPPROCESS_INFORMATION lpProcessInformation); 606 | 607 | BOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName, 608 | _Inout_opt_ LPSTR lpCommandLine, 609 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 610 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 611 | _In_ BOOL bInheritHandles, 612 | _In_ DWORD dwCreationFlags, 613 | _In_opt_ LPVOID lpEnvironment, 614 | _In_opt_ LPCSTR lpCurrentDirectory, 615 | _In_ LPSTARTUPINFOA lpStartupInfo, 616 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 617 | _In_ LPCSTR lpDllName, 618 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); 619 | 620 | BOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName, 621 | _Inout_opt_ LPWSTR lpCommandLine, 622 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 623 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 624 | _In_ BOOL bInheritHandles, 625 | _In_ DWORD dwCreationFlags, 626 | _In_opt_ LPVOID lpEnvironment, 627 | _In_opt_ LPCWSTR lpCurrentDirectory, 628 | _In_ LPSTARTUPINFOW lpStartupInfo, 629 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 630 | _In_ LPCSTR lpDllName, 631 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); 632 | 633 | #ifdef UNICODE 634 | #define DetourCreateProcessWithDll DetourCreateProcessWithDllW 635 | #define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW 636 | #else 637 | #define DetourCreateProcessWithDll DetourCreateProcessWithDllA 638 | #define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA 639 | #endif // !UNICODE 640 | 641 | BOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName, 642 | _Inout_opt_ LPSTR lpCommandLine, 643 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 644 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 645 | _In_ BOOL bInheritHandles, 646 | _In_ DWORD dwCreationFlags, 647 | _In_opt_ LPVOID lpEnvironment, 648 | _In_opt_ LPCSTR lpCurrentDirectory, 649 | _In_ LPSTARTUPINFOA lpStartupInfo, 650 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 651 | _In_ LPCSTR lpDllName, 652 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); 653 | 654 | BOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName, 655 | _Inout_opt_ LPWSTR lpCommandLine, 656 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 657 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 658 | _In_ BOOL bInheritHandles, 659 | _In_ DWORD dwCreationFlags, 660 | _In_opt_ LPVOID lpEnvironment, 661 | _In_opt_ LPCWSTR lpCurrentDirectory, 662 | _In_ LPSTARTUPINFOW lpStartupInfo, 663 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 664 | _In_ LPCSTR lpDllName, 665 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); 666 | 667 | #ifdef UNICODE 668 | #define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW 669 | #else 670 | #define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA 671 | #endif // !UNICODE 672 | 673 | BOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName, 674 | _Inout_opt_ LPSTR lpCommandLine, 675 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 676 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 677 | _In_ BOOL bInheritHandles, 678 | _In_ DWORD dwCreationFlags, 679 | _In_opt_ LPVOID lpEnvironment, 680 | _In_opt_ LPCSTR lpCurrentDirectory, 681 | _In_ LPSTARTUPINFOA lpStartupInfo, 682 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 683 | _In_ DWORD nDlls, 684 | _In_reads_(nDlls) LPCSTR *rlpDlls, 685 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); 686 | 687 | BOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName, 688 | _Inout_opt_ LPWSTR lpCommandLine, 689 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, 690 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, 691 | _In_ BOOL bInheritHandles, 692 | _In_ DWORD dwCreationFlags, 693 | _In_opt_ LPVOID lpEnvironment, 694 | _In_opt_ LPCWSTR lpCurrentDirectory, 695 | _In_ LPSTARTUPINFOW lpStartupInfo, 696 | _Out_ LPPROCESS_INFORMATION lpProcessInformation, 697 | _In_ DWORD nDlls, 698 | _In_reads_(nDlls) LPCSTR *rlpDlls, 699 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); 700 | 701 | #ifdef UNICODE 702 | #define DetourCreateProcessWithDlls DetourCreateProcessWithDllsW 703 | #else 704 | #define DetourCreateProcessWithDlls DetourCreateProcessWithDllsA 705 | #endif // !UNICODE 706 | 707 | BOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid, 708 | _In_ LPCSTR lpDllName, 709 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); 710 | 711 | BOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid, 712 | _In_ LPCSTR lpDllName, 713 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); 714 | 715 | #ifdef UNICODE 716 | #define DetourProcessViaHelper DetourProcessViaHelperW 717 | #else 718 | #define DetourProcessViaHelper DetourProcessViaHelperA 719 | #endif // !UNICODE 720 | 721 | BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid, 722 | _In_ DWORD nDlls, 723 | _In_reads_(nDlls) LPCSTR *rlpDlls, 724 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); 725 | 726 | BOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid, 727 | _In_ DWORD nDlls, 728 | _In_reads_(nDlls) LPCSTR *rlpDlls, 729 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); 730 | 731 | #ifdef UNICODE 732 | #define DetourProcessViaHelperDlls DetourProcessViaHelperDllsW 733 | #else 734 | #define DetourProcessViaHelperDlls DetourProcessViaHelperDllsA 735 | #endif // !UNICODE 736 | 737 | BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess, 738 | _In_reads_(nDlls) LPCSTR *rlpDlls, 739 | _In_ DWORD nDlls); 740 | 741 | BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess, 742 | _In_ HMODULE hImage, 743 | _In_ BOOL bIs32Bit, 744 | _In_reads_(nDlls) LPCSTR *rlpDlls, 745 | _In_ DWORD nDlls); 746 | 747 | BOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess, 748 | _In_ REFGUID rguid, 749 | _In_reads_bytes_(cbData) PVOID pvData, 750 | _In_ DWORD cbData); 751 | BOOL WINAPI DetourRestoreAfterWith(VOID); 752 | BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData, 753 | _In_ DWORD cbData); 754 | BOOL WINAPI DetourIsHelperProcess(VOID); 755 | VOID CALLBACK DetourFinishHelperProcess(_In_ HWND, 756 | _In_ HINSTANCE, 757 | _In_ LPSTR, 758 | _In_ INT); 759 | 760 | // 761 | ////////////////////////////////////////////////////////////////////////////// 762 | #ifdef __cplusplus 763 | } 764 | #endif // __cplusplus 765 | 766 | //////////////////////////////////////////////// Detours Internal Definitions. 767 | // 768 | #ifdef __cplusplus 769 | #ifdef DETOURS_INTERNAL 770 | 771 | #define NOTHROW 772 | // #define NOTHROW (nothrow) 773 | 774 | ////////////////////////////////////////////////////////////////////////////// 775 | // 776 | #if (_MSC_VER < 1299) 777 | #include 778 | typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64; 779 | typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64; 780 | typedef IMAGEHLP_SYMBOL SYMBOL_INFO; 781 | typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO; 782 | 783 | static inline 784 | LONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval) 785 | { 786 | return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval); 787 | } 788 | #else 789 | #pragma warning(push) 790 | #pragma warning(disable:4091) // empty typedef 791 | #include 792 | #pragma warning(pop) 793 | #endif 794 | 795 | #ifdef IMAGEAPI // defined by DBGHELP.H 796 | typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion); 797 | 798 | typedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess, 799 | _In_opt_ LPCSTR UserSearchPath, 800 | _In_ BOOL fInvadeProcess); 801 | typedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions); 802 | typedef DWORD (NTAPI *PF_SymGetOptions)(VOID); 803 | typedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess, 804 | _In_opt_ HANDLE hFile, 805 | _In_ LPSTR ImageName, 806 | _In_opt_ LPSTR ModuleName, 807 | _In_ DWORD64 BaseOfDll, 808 | _In_opt_ DWORD SizeOfDll); 809 | typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess, 810 | _In_ DWORD64 qwAddr, 811 | _Out_ PIMAGEHLP_MODULE64 ModuleInfo); 812 | typedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess, 813 | _In_ LPSTR Name, 814 | _Out_ PSYMBOL_INFO Symbol); 815 | 816 | typedef struct _DETOUR_SYM_INFO 817 | { 818 | HANDLE hProcess; 819 | HMODULE hDbgHelp; 820 | PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx; 821 | PF_SymInitialize pfSymInitialize; 822 | PF_SymSetOptions pfSymSetOptions; 823 | PF_SymGetOptions pfSymGetOptions; 824 | PF_SymLoadModule64 pfSymLoadModule64; 825 | PF_SymGetModuleInfo64 pfSymGetModuleInfo64; 826 | PF_SymFromName pfSymFromName; 827 | } DETOUR_SYM_INFO, *PDETOUR_SYM_INFO; 828 | 829 | PDETOUR_SYM_INFO DetourLoadImageHlp(VOID); 830 | 831 | #endif // IMAGEAPI 832 | 833 | #if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS) 834 | #error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier) 835 | #endif 836 | #define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1 837 | 838 | #ifndef DETOUR_TRACE 839 | #if DETOUR_DEBUG 840 | #define DETOUR_TRACE(x) printf x 841 | #define DETOUR_BREAK() __debugbreak() 842 | #include 843 | #include 844 | #else 845 | #define DETOUR_TRACE(x) 846 | #define DETOUR_BREAK() 847 | #endif 848 | #endif 849 | 850 | #if 1 || defined(DETOURS_IA64) 851 | 852 | // 853 | // IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle. 854 | // 855 | 856 | #define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3) 857 | 858 | #define DETOUR_IA64_TEMPLATE_OFFSET (0) 859 | #define DETOUR_IA64_TEMPLATE_SIZE (5) 860 | 861 | #define DETOUR_IA64_INSTRUCTION_SIZE (41) 862 | #define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE) 863 | #define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) 864 | #define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) 865 | 866 | C_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128); 867 | 868 | __declspec(align(16)) struct DETOUR_IA64_BUNDLE 869 | { 870 | public: 871 | union 872 | { 873 | BYTE data[16]; 874 | UINT64 wide[2]; 875 | }; 876 | 877 | enum { 878 | A_UNIT = 1u, 879 | I_UNIT = 2u, 880 | M_UNIT = 3u, 881 | B_UNIT = 4u, 882 | F_UNIT = 5u, 883 | L_UNIT = 6u, 884 | X_UNIT = 7u, 885 | }; 886 | struct DETOUR_IA64_METADATA 887 | { 888 | ULONG nTemplate : 8; // Instruction template. 889 | ULONG nUnit0 : 4; // Unit for slot 0 890 | ULONG nUnit1 : 4; // Unit for slot 1 891 | ULONG nUnit2 : 4; // Unit for slot 2 892 | }; 893 | 894 | protected: 895 | static const DETOUR_IA64_METADATA s_rceCopyTable[33]; 896 | 897 | UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; 898 | 899 | bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst, 900 | _In_ BYTE slot, 901 | _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; 902 | 903 | // 120 112 104 96 88 80 72 64 56 48 40 32 24 16 8 0 904 | // f. e. d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0. 905 | 906 | // 00 907 | // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0. 908 | // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0] 909 | // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41.. 5] 910 | // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42] 911 | // 0000 0000 0007 ffff ffff c000 0000 0000 : One [ 82.. 46] 912 | // 0000 0000 0078 0000 0000 0000 0000 0000 : One [ 86.. 83] 913 | // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two [123.. 87] 914 | // f000 0000 0000 0000 0000 0000 0000 0000 : Two [127..124] 915 | BYTE GetTemplate() const; 916 | // Get 4 bit opcodes. 917 | BYTE GetInst0() const; 918 | BYTE GetInst1() const; 919 | BYTE GetInst2() const; 920 | BYTE GetUnit(BYTE slot) const; 921 | BYTE GetUnit0() const; 922 | BYTE GetUnit1() const; 923 | BYTE GetUnit2() const; 924 | // Get 37 bit data. 925 | UINT64 GetData0() const; 926 | UINT64 GetData1() const; 927 | UINT64 GetData2() const; 928 | 929 | // Get/set the full 41 bit instructions. 930 | UINT64 GetInstruction(BYTE slot) const; 931 | UINT64 GetInstruction0() const; 932 | UINT64 GetInstruction1() const; 933 | UINT64 GetInstruction2() const; 934 | void SetInstruction(BYTE slot, UINT64 instruction); 935 | void SetInstruction0(UINT64 instruction); 936 | void SetInstruction1(UINT64 instruction); 937 | void SetInstruction2(UINT64 instruction); 938 | 939 | // Get/set bitfields. 940 | static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count); 941 | static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field); 942 | 943 | // Get specific read-only fields. 944 | static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode 945 | static UINT64 GetX(UINT64 instruction); // 1bit opcode extension 946 | static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension 947 | static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension 948 | 949 | // Get/set specific fields. 950 | static UINT64 GetImm7a(UINT64 instruction); 951 | static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a); 952 | static UINT64 GetImm13c(UINT64 instruction); 953 | static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c); 954 | static UINT64 GetSignBit(UINT64 instruction); 955 | static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit); 956 | static UINT64 GetImm20a(UINT64 instruction); 957 | static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a); 958 | static UINT64 GetImm20b(UINT64 instruction); 959 | static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b); 960 | 961 | static UINT64 SignExtend(UINT64 Value, UINT64 Offset); 962 | 963 | BOOL IsMovlGp() const; 964 | 965 | VOID SetInst(BYTE Slot, BYTE nInst); 966 | VOID SetInst0(BYTE nInst); 967 | VOID SetInst1(BYTE nInst); 968 | VOID SetInst2(BYTE nInst); 969 | VOID SetData(BYTE Slot, UINT64 nData); 970 | VOID SetData0(UINT64 nData); 971 | VOID SetData1(UINT64 nData); 972 | VOID SetData2(UINT64 nData); 973 | BOOL SetNop(BYTE Slot); 974 | BOOL SetNop0(); 975 | BOOL SetNop1(); 976 | BOOL SetNop2(); 977 | 978 | public: 979 | BOOL IsBrl() const; 980 | VOID SetBrl(); 981 | VOID SetBrl(UINT64 target); 982 | UINT64 GetBrlTarget() const; 983 | VOID SetBrlTarget(UINT64 target); 984 | VOID SetBrlImm(UINT64 imm); 985 | UINT64 GetBrlImm() const; 986 | 987 | UINT64 GetMovlGp() const; 988 | VOID SetMovlGp(UINT64 gp); 989 | 990 | VOID SetStop(); 991 | 992 | UINT Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const; 993 | }; 994 | #endif // DETOURS_IA64 995 | 996 | #ifdef DETOURS_ARM 997 | 998 | #define DETOURS_PFUNC_TO_PBYTE(p) ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1)) 999 | #define DETOURS_PBYTE_TO_PFUNC(p) ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1)) 1000 | 1001 | #endif // DETOURS_ARM 1002 | 1003 | ////////////////////////////////////////////////////////////////////////////// 1004 | 1005 | #ifdef __cplusplus 1006 | extern "C" { 1007 | #endif // __cplusplus 1008 | 1009 | #define DETOUR_OFFLINE_LIBRARY(x) \ 1010 | PVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst, \ 1011 | _Inout_opt_ PVOID *ppDstPool, \ 1012 | _In_ PVOID pSrc, \ 1013 | _Out_opt_ PVOID *ppTarget, \ 1014 | _Out_opt_ LONG *plExtra); \ 1015 | \ 1016 | BOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule, \ 1017 | _In_ BOOL fLimitReferencesToModule); \ 1018 | 1019 | DETOUR_OFFLINE_LIBRARY(X86) 1020 | DETOUR_OFFLINE_LIBRARY(X64) 1021 | DETOUR_OFFLINE_LIBRARY(ARM) 1022 | DETOUR_OFFLINE_LIBRARY(ARM64) 1023 | DETOUR_OFFLINE_LIBRARY(IA64) 1024 | 1025 | #undef DETOUR_OFFLINE_LIBRARY 1026 | 1027 | ////////////////////////////////////////////////////////////////////////////// 1028 | // 1029 | // Helpers for manipulating page protection. 1030 | // 1031 | 1032 | _Success_(return != FALSE) 1033 | BOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_ HANDLE hProcess, 1034 | _In_ PVOID pAddress, 1035 | _In_ SIZE_T nSize, 1036 | _In_ DWORD dwNewProtect, 1037 | _Out_ PDWORD pdwOldProtect); 1038 | 1039 | _Success_(return != FALSE) 1040 | BOOL WINAPI DetourVirtualProtectSameExecute(_In_ PVOID pAddress, 1041 | _In_ SIZE_T nSize, 1042 | _In_ DWORD dwNewProtect, 1043 | _Out_ PDWORD pdwOldProtect); 1044 | #ifdef __cplusplus 1045 | } 1046 | #endif // __cplusplus 1047 | 1048 | ////////////////////////////////////////////////////////////////////////////// 1049 | 1050 | #define MM_ALLOCATION_GRANULARITY 0x10000 1051 | 1052 | ////////////////////////////////////////////////////////////////////////////// 1053 | 1054 | #endif // DETOURS_INTERNAL 1055 | #endif // __cplusplus 1056 | 1057 | #endif // _DETOURS_H_ 1058 | // 1059 | //////////////////////////////////////////////////////////////// End of File. 1060 | -------------------------------------------------------------------------------- /inc/detver.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Common version parameters. 4 | // 5 | // Microsoft Research Detours Package, Version 4.0.1 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | // 9 | 10 | #define _USING_V110_SDK71_ 1 11 | #include "winver.h" 12 | #if 0 13 | #include 14 | #include 15 | #else 16 | #ifndef DETOURS_STRINGIFY 17 | #define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) 18 | #define DETOURS_STRINGIFY_(x) #x 19 | #endif 20 | 21 | #define VER_FILEFLAGSMASK 0x3fL 22 | #define VER_FILEFLAGS 0x0L 23 | #define VER_FILEOS 0x00040004L 24 | #define VER_FILETYPE 0x00000002L 25 | #define VER_FILESUBTYPE 0x00000000L 26 | #endif 27 | #define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) 28 | -------------------------------------------------------------------------------- /lib/detours.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spitfirex86/Ray2Fix/92cfeaf4c39d56a561e2f0dc11c884a99c739f30/lib/detours.lib -------------------------------------------------------------------------------- /third-party-licenses.md: -------------------------------------------------------------------------------- 1 | ## Detours 2 | Copyright (c) Microsoft Corporation 3 | All rights reserved. 4 | 5 | ### MIT License 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ## Xidi 25 | Copyright (c) 2016-2023, Samuel Grossman 26 | All rights reserved. 27 | 28 | ### BSD 3-Clause License 29 | Redistribution and use in source and binary forms, with or without 30 | modification, are permitted provided that the following conditions are met: 31 | 32 | * Redistributions of source code must retain the above copyright notice, this 33 | list of conditions and the following disclaimer. 34 | 35 | * Redistributions in binary form must reproduce the above copyright notice, 36 | this list of conditions and the following disclaimer in the documentation 37 | and/or other materials provided with the distribution. 38 | 39 | * Neither the name of the copyright holder nor the names of its 40 | contributors may be used to endorse or promote products derived from 41 | this software without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 44 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 46 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 47 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 49 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 50 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 51 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 | --------------------------------------------------------------------------------