Skip to content

Commit

Permalink
Added support for non-4:3 resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rib committed Jul 25, 2024
1 parent dafbb83 commit 591cb13
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
7 changes: 7 additions & 0 deletions GliFixVf/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ char const *szUbiPath = ".\\Ubi.ini";
*/

tdstDisplayMode CFG_stDispMode = { 0, 0 };
float CFG_fAspectRatio = 4.0f / 3.0f;
BOOL CFG_bHalfRefRate = FALSE;

BOOL CFG_bIsMainModuleR2 = FALSE;
Expand Down Expand Up @@ -114,6 +115,12 @@ void fn_vReadFixConfig( void )
{
char szBuffer[128];

// Aspect ratio
GetPrivateProfileString("Ray2Fix", "AspectRatio", "1.333333", szBuffer, sizeof(szBuffer), szUbiPath);
CFG_fAspectRatio = strtof(szBuffer, NULL);
// use 4:3 aspect if float conversion fails
if (CFG_fAspectRatio == 0.f) CFG_fAspectRatio = 4.0f / 3.0f;

// Refresh rate
GetPrivateProfileString("Ray2Fix", "HalfRefRate", "0", szBuffer, sizeof(szBuffer), szUbiPath);
if( strtol(szBuffer, NULL, 10) > 0 )
Expand Down
1 change: 1 addition & 0 deletions GliFixVf/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tdstDisplayMode;
*/

extern tdstDisplayMode CFG_stDispMode;
extern float CFG_fAspectRatio;
extern BOOL CFG_bHalfRefRate;

extern BOOL CFG_bIsMainModuleR2;
Expand Down
2 changes: 2 additions & 0 deletions GliFixVf/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
/* sorry, no structs for those. maybe in the future */

typedef struct GLI_tdstInternalGlobalValuesFor3dEngine GLI_tdstInternalGlobalValuesFor3dEngine;
typedef struct GLD_tdstDeviceAttributes GLD_tdstDeviceAttributes;
typedef struct GLD_tdstViewportAttributes GLD_tdstViewportAttributes;
typedef struct GLI_tdstAligned2DVector GLI_tdstAligned2DVector;
typedef struct GLI_tdstAligned3DVector GLI_tdstAligned3DVector;
typedef struct GLI_tdstCamera GLI_tdstCamera;
typedef struct GLI_tdstTexture GLI_tdstTexture;
typedef struct GEO_tdstColor GEO_tdstColor;
typedef struct GEO_tdstElementIndexedTriangles GEO_tdstElementIndexedTriangles;
Expand Down
13 changes: 13 additions & 0 deletions GliFixVf/fix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "framework.h"
#include <detours.h>
#include <math.h>
#include "fix.h"
#include "imports.h"
#include "r2fn.h"
Expand Down Expand Up @@ -63,6 +64,16 @@ char * FIX_fn_szGetStringFromTextOrStringParam( void *param )
return result;
}

void FIX_GLI_xAdjustCameraToViewport2(GLD_tdstDeviceAttributes *p_stDev, GLD_tdstViewportAttributes *p_stVpt, GLI_tdstCamera *p_stCam)
{
// HACK: Calculate new FOV based on selected aspect ratio
float fOldFOV = *((float*)p_stCam + 25);
float fNewFOV = 2.0f * atan(tan(fOldFOV / 2.0f) * 0.75f * CFG_fAspectRatio);
*((float*)p_stCam + 25) = fNewFOV;

// Call original function
R2_GLI_xAdjustCameraToViewport2(p_stDev, p_stVpt, p_stCam);
}

/*
* Functions
Expand All @@ -84,6 +95,7 @@ void FIX_fn_vAttachHooks( void )
DetourAttach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum);
DetourAttach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame);
DetourAttach((PVOID*)&R2_fn_szGetStringFromTextOrStringParam, (PVOID)FIX_fn_szGetStringFromTextOrStringParam);
DetourAttach((PVOID*)&R2_GLI_xAdjustCameraToViewport2, (PVOID)FIX_GLI_xAdjustCameraToViewport2);

DetourTransactionCommit();
}
Expand All @@ -96,6 +108,7 @@ void FIX_fn_vDetachHooks( void )
DetourDetach((PVOID*)&R2_fn_InputEnum, (PVOID)FIX_fn_InputEnum);
DetourDetach((PVOID*)&R2_fn_SuspendGame, (PVOID)FIX_fn_SuspendGame);
DetourDetach((PVOID*)&R2_fn_szGetStringFromTextOrStringParam, (PVOID)FIX_fn_szGetStringFromTextOrStringParam);
DetourDetach((PVOID*)&R2_GLI_xAdjustCameraToViewport2, (PVOID)FIX_GLI_xAdjustCameraToViewport2);

DetourTransactionCommit();
}
Expand Down
2 changes: 2 additions & 0 deletions GliFixVf/r2fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ void (*R2_fn_vEngine)( void ) = 0x40ADA0;
char* (*R2_fn_szGetStringFromTextOrStringParam)( void *param ) = 0x4829D0;

HWND (*R2_GetWindowHandle)(void) = 0x401400;

void (*R2_GLI_xAdjustCameraToViewport2)(GLD_tdstDeviceAttributes* p_stDev, GLD_tdstViewportAttributes* p_stVpt, GLI_tdstCamera* p_stCam) = 0x422AB0;
3 changes: 3 additions & 0 deletions GliFixVf/r2fn.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "defs.h"
#include "framework.h"
#include "fix.h"

Expand All @@ -17,3 +18,5 @@ extern void (*R2_fn_vEngine)( void );
extern char* (*R2_fn_szGetStringFromTextOrStringParam)( void *param );

extern HWND (*R2_GetWindowHandle)( void );

extern void (*R2_GLI_xAdjustCameraToViewport2)( GLD_tdstDeviceAttributes* p_stDev, GLD_tdstViewportAttributes* p_stVpt, GLI_tdstCamera* p_stCam );
4 changes: 4 additions & 0 deletions R2FixCfg/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void fn_vWriteUbiIni( void )
// Refresh rate
sprintf_s(szBuffer, sizeof(szBuffer), "%i", (g_eRefRate == e_RR_Half));
WritePrivateProfileString("Ray2Fix", "HalfRefRate", szBuffer, szUbiPath);

// Aspect ratio
sprintf_s(szBuffer, sizeof(szBuffer), "%f", (float)g_stCurrentMode.dwWidth / (float)g_stCurrentMode.dwHeight);
WritePrivateProfileString("Ray2Fix", "AspectRatio", szBuffer, szUbiPath);
}

void fn_vWriteDegeIni( void )
Expand Down
12 changes: 3 additions & 9 deletions R2FixCfg/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ void DSP_fn_vEnumResolutions( void )
if ( fn_bIsDuplicateMode(&mode, nModes) )
continue;

DWORD ratio = 100 * dm.dmPelsHeight / dm.dmPelsWidth;
if ( fn_bIsSafeResolution(&mode) )
mode.eFlags |= e_DMF_Safe;

// Only add resolutions "close" to 4:3 or 5:4 ratio
if ( ratio > 73 && ratio < 82 )
{
if ( fn_bIsSafeResolution(&mode) )
mode.eFlags |= e_DMF_Safe;

g_a_stDispModes[nModes++] = mode;
}
g_a_stDispModes[nModes++] = mode;
}

fn_vFindBestResolution(nModes);
Expand Down

0 comments on commit 591cb13

Please sign in to comment.