diff --git a/GliFixVf/config.c b/GliFixVf/config.c index 742c0d4..848ac15 100644 --- a/GliFixVf/config.c +++ b/GliFixVf/config.c @@ -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; @@ -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 ) diff --git a/GliFixVf/config.h b/GliFixVf/config.h index 5b3c657..893fc4c 100644 --- a/GliFixVf/config.h +++ b/GliFixVf/config.h @@ -16,6 +16,7 @@ tdstDisplayMode; */ extern tdstDisplayMode CFG_stDispMode; +extern float CFG_fAspectRatio; extern BOOL CFG_bHalfRefRate; extern BOOL CFG_bIsMainModuleR2; diff --git a/GliFixVf/defs.h b/GliFixVf/defs.h index 7d95d88..daca809 100644 --- a/GliFixVf/defs.h +++ b/GliFixVf/defs.h @@ -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; diff --git a/GliFixVf/fix.c b/GliFixVf/fix.c index 9127113..221899e 100644 --- a/GliFixVf/fix.c +++ b/GliFixVf/fix.c @@ -1,5 +1,6 @@ #include "framework.h" #include +#include #include "fix.h" #include "imports.h" #include "r2fn.h" @@ -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 @@ -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(); } @@ -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(); } diff --git a/GliFixVf/r2fn.c b/GliFixVf/r2fn.c index ebab1c4..cb1b7c8 100644 --- a/GliFixVf/r2fn.c +++ b/GliFixVf/r2fn.c @@ -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; \ No newline at end of file diff --git a/GliFixVf/r2fn.h b/GliFixVf/r2fn.h index 85cbf1c..35f92f2 100644 --- a/GliFixVf/r2fn.h +++ b/GliFixVf/r2fn.h @@ -1,5 +1,6 @@ #pragma once +#include "defs.h" #include "framework.h" #include "fix.h" @@ -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 ); \ No newline at end of file diff --git a/R2FixCfg/config.c b/R2FixCfg/config.c index a9d24e8..f83c3f2 100644 --- a/R2FixCfg/config.c +++ b/R2FixCfg/config.c @@ -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 ) diff --git a/R2FixCfg/display.c b/R2FixCfg/display.c index 05827e0..39461be 100644 --- a/R2FixCfg/display.c +++ b/R2FixCfg/display.c @@ -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);