Additional compatibility code for widescreen fixes

This commit is contained in:
Silent 2014-09-14 20:02:57 +02:00
parent ee0adecc4b
commit 048999d74a
3 changed files with 110 additions and 37 deletions

View File

@ -37,31 +37,44 @@ static void (*PrintString)(float,float,const wchar_t*);
static bool* bWantsToDrawHud; static bool* bWantsToDrawHud;
static bool* bCamCheck; static bool* bCamCheck;
static RsGlobalType* RsGlobal; static RsGlobalType* RsGlobal;
static const float* ResolutionWidthMult;
static const float* ResolutionHeightMult;
static const void* SubtitlesShadowFix_JumpBack; static const void* SubtitlesShadowFix_JumpBack;
inline float GetWidthMult()
{
static const float& ResolutionWidthMult = **AddressByVersion<float**>(0x57E956, 0x57ECA6, 0x57EBA6);
return ResolutionWidthMult;
}
inline float GetHeightMult()
{
static const float& ResolutionHeightMult = **AddressByVersion<float**>(0x57E940, 0x57EC90, 0x57EB90);
return ResolutionHeightMult;
}
void ShowRadarTrace(float fX, float fY, unsigned int nScale, BYTE r, BYTE g, BYTE b, BYTE a) void ShowRadarTrace(float fX, float fY, unsigned int nScale, BYTE r, BYTE g, BYTE b, BYTE a)
{ {
if ( *bWantsToDrawHud == true && !*bCamCheck ) if ( *bWantsToDrawHud == true && !*bCamCheck )
{ {
DrawRect(CRect( fX - ((nScale+1.0f) * *ResolutionWidthMult * RsGlobal->MaximumWidth), float fWidthMult = GetWidthMult();
fY + ((nScale+1.0f) * *ResolutionHeightMult * RsGlobal->MaximumHeight), float fHeightMult = GetHeightMult();
fX + ((nScale+1.0f) * *ResolutionWidthMult * RsGlobal->MaximumWidth),
fY - ((nScale+1.0f) * *ResolutionHeightMult * RsGlobal->MaximumHeight)), DrawRect(CRect( fX - ((nScale+1.0f) * fWidthMult * RsGlobal->MaximumWidth),
fY + ((nScale+1.0f) * fHeightMult * RsGlobal->MaximumHeight),
fX + ((nScale+1.0f) * fWidthMult * RsGlobal->MaximumWidth),
fY - ((nScale+1.0f) * fHeightMult * RsGlobal->MaximumHeight)),
CRGBA(0, 0, 0, a)); CRGBA(0, 0, 0, a));
DrawRect(CRect( fX - (nScale * *ResolutionWidthMult * RsGlobal->MaximumWidth), DrawRect(CRect( fX - (nScale * fWidthMult * RsGlobal->MaximumWidth),
fY + (nScale * *ResolutionHeightMult * RsGlobal->MaximumHeight), fY + (nScale * fHeightMult * RsGlobal->MaximumHeight),
fX + (nScale * *ResolutionWidthMult * RsGlobal->MaximumWidth), fX + (nScale * fWidthMult * RsGlobal->MaximumWidth),
fY - (nScale * *ResolutionHeightMult * RsGlobal->MaximumHeight)), fY - (nScale * fHeightMult * RsGlobal->MaximumHeight)),
CRGBA(r, g, b, a)); CRGBA(r, g, b, a));
} }
} }
void SetScaleProperly(float fX, float fY) void SetScaleProperly(float fX, float fY)
{ {
SetScale(fX * *ResolutionWidthMult * RsGlobal->MaximumWidth, fY * *ResolutionHeightMult * RsGlobal->MaximumHeight); SetScale(fX * GetWidthMult() * RsGlobal->MaximumWidth, fY * GetHeightMult() * RsGlobal->MaximumHeight);
} }
void PurpleNinesGlitchFix() void PurpleNinesGlitchFix()
@ -117,8 +130,8 @@ static float fShadowXSize, fShadowYSize;
void __stdcall Recalculate(signed int nShadow) void __stdcall Recalculate(signed int nShadow)
{ {
fShadowXSize = nShadow * *ResolutionWidthMult * RsGlobal->MaximumWidth; fShadowXSize = nShadow * GetWidthMult() * RsGlobal->MaximumWidth;
fShadowYSize = nShadow * *ResolutionHeightMult * RsGlobal->MaximumHeight; fShadowYSize = nShadow * GetHeightMult() * RsGlobal->MaximumHeight;
} }
template<int pFltX, int pFltY> template<int pFltX, int pFltY>
@ -126,7 +139,7 @@ void AlteredPrintString(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX - fMarginX + (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY - fMarginY + (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
template<int pFltX, int pFltY> template<int pFltX, int pFltY>
@ -134,21 +147,21 @@ void AlteredPrintStringMinus(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX + fMarginX - (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY + fMarginY - (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX + fMarginX - (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY + fMarginY - (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
template<int pFltX> template<int pFltX>
void AlteredPrintStringXOnly(float fX, float fY, const wchar_t* pText) void AlteredPrintStringXOnly(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
PrintString(fX - fMarginX + (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY, pText); PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY, pText);
} }
template<int pFltY> template<int pFltY>
void AlteredPrintStringYOnly(float fX, float fY, const wchar_t* pText) void AlteredPrintStringYOnly(float fX, float fY, const wchar_t* pText)
{ {
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX, fY - fMarginY + (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX, fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
float FixedRefValue() float FixedRefValue()
@ -182,8 +195,6 @@ void Patch_III_10()
bWantsToDrawHud = *(bool**)0x4A5877; bWantsToDrawHud = *(bool**)0x4A5877;
bCamCheck = *(bool**)0x4A588C; bCamCheck = *(bool**)0x4A588C;
RsGlobal = *(RsGlobalType**)0x584C42; RsGlobal = *(RsGlobalType**)0x584C42;
ResolutionWidthMult = *(float**)0x57E956;
ResolutionHeightMult = *(float**)0x57E940;
HeadlightsFix_JumpBack = (void*)0x5382F2; HeadlightsFix_JumpBack = (void*)0x5382F2;
SubtitlesShadowFix_JumpBack = (void*)0x500D32; SubtitlesShadowFix_JumpBack = (void*)0x500D32;
@ -295,8 +306,6 @@ void Patch_III_11()
bWantsToDrawHud = *(bool**)0x4A5967; bWantsToDrawHud = *(bool**)0x4A5967;
bCamCheck = *(bool**)0x4A597C; bCamCheck = *(bool**)0x4A597C;
RsGlobal = *(RsGlobalType**)0x584F82; RsGlobal = *(RsGlobalType**)0x584F82;
ResolutionWidthMult = *(float**)0x57ECA6;
ResolutionHeightMult = *(float**)0x57EC90;
HeadlightsFix_JumpBack = (void*)0x538532; HeadlightsFix_JumpBack = (void*)0x538532;
SubtitlesShadowFix_JumpBack = (void*)0x500E12; SubtitlesShadowFix_JumpBack = (void*)0x500E12;
@ -402,8 +411,6 @@ void Patch_III_Steam()
bWantsToDrawHud = *(bool**)0x4A58F7; bWantsToDrawHud = *(bool**)0x4A58F7;
bCamCheck = *(bool**)0x4A590C; bCamCheck = *(bool**)0x4A590C;
RsGlobal = *(RsGlobalType**)0x584E72; RsGlobal = *(RsGlobalType**)0x584E72;
ResolutionWidthMult = *(float**)0x57EBA6;
ResolutionHeightMult = *(float**)0x57EB90;
SubtitlesShadowFix_JumpBack = (void*)0x500DA2; SubtitlesShadowFix_JumpBack = (void*)0x500DA2;
CTimer::ms_fTimeScale = *(float**)0x43F73F; CTimer::ms_fTimeScale = *(float**)0x43F73F;

View File

@ -35,6 +35,66 @@ inline void* GetDummy()
return &dwDummy; return &dwDummy;
} }
#if defined SILENTPATCH_III_VER
// This function initially detects III version then chooses the address basing on game version
template<typename T>
inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
{
signed char* bVer = GetVer();
if ( *bVer == -1 )
{
if (*(DWORD*)0x5C1E70 == 0x53E58955) *bVer = 0;
else if (*(DWORD*)0x5C2130 == 0x53E58955) *bVer = 1;
else if (*(DWORD*)0x5C6FD0 == 0x53E58955) *bVer = 2;
}
switch ( *bVer )
{
case 1:
assert(address11);
return (T)address11;
case 2:
assert(addressSteam);
return (T)addressSteam;
default:
assert(address10);
return (T)address10;
}
}
#elif defined SILENTPATCH_VC_VER
// This function initially detects VC version then chooses the address basing on game version
template<typename T>
inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
{
signed char* bVer = GetVer();
if ( *bVer == -1 )
{
if (*(DWORD*)0x667BF0 == 0x53E58955) *bVer = 0;
else if (*(DWORD*)0x667C40 == 0x53E58955) *bVer = 1;
else if (*(DWORD*)0x666BA0 == 0x53E58955) *bVer = 2;
}
switch ( *bVer )
{
case 1:
assert(address11);
return (T)address11;
case 2:
assert(addressSteam);
return (T)addressSteam;
default:
assert(address10);
return (T)address10;
}
}
#else
// This function initially detects SA version then chooses the address basing on game version // This function initially detects SA version then chooses the address basing on game version
template<typename T> template<typename T>
inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam)
@ -180,6 +240,8 @@ inline T AddressByRegion_11(DWORD address11)
return (T)address11; return (T)address11;
} }
#endif
namespace Memory namespace Memory
{ {
template<typename T, typename AT> template<typename T, typename AT>

View File

@ -24,10 +24,20 @@ void (__stdcall *AudioResetTimers)(unsigned int);
static void (*PrintString)(float,float,const wchar_t*); static void (*PrintString)(float,float,const wchar_t*);
static RsGlobalType* RsGlobal; static RsGlobalType* RsGlobal;
static const float* ResolutionWidthMult;
static const float* ResolutionHeightMult;
static const void* SubtitlesShadowFix_JumpBack; static const void* SubtitlesShadowFix_JumpBack;
inline float GetWidthMult()
{
static const float& ResolutionWidthMult = **AddressByVersion<float**>(0x5FA15E, 0x5FA17E, 0x5F9DBE);
return ResolutionWidthMult;
}
inline float GetHeightMult()
{
static const float& ResolutionHeightMult = **AddressByVersion<float**>(0x5FA148, 0x5FA168, 0x5F9DA8);
return ResolutionHeightMult;
}
void __declspec(naked) RosiesAudioFix() void __declspec(naked) RosiesAudioFix()
{ {
@ -41,8 +51,8 @@ void __declspec(naked) RosiesAudioFix()
void __stdcall Recalculate(float& fX, float& fY, signed int nShadow) void __stdcall Recalculate(float& fX, float& fY, signed int nShadow)
{ {
fX = nShadow * *ResolutionWidthMult * RsGlobal->MaximumWidth; fX = nShadow * GetWidthMult() * RsGlobal->MaximumWidth;
fY = nShadow * *ResolutionHeightMult * RsGlobal->MaximumHeight; fY = nShadow * GetHeightMult() * RsGlobal->MaximumHeight;
} }
template<int pFltX, int pFltY> template<int pFltX, int pFltY>
@ -50,7 +60,7 @@ void AlteredPrintString(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX - fMarginX + (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY - fMarginY + (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
template<int pFltX, int pFltY> template<int pFltX, int pFltY>
@ -58,21 +68,21 @@ void AlteredPrintStringMinus(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX + fMarginX - (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY + fMarginY - (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX + fMarginX - (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY + fMarginY - (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
template<int pFltX> template<int pFltX>
void AlteredPrintStringXOnly(float fX, float fY, const wchar_t* pText) void AlteredPrintStringXOnly(float fX, float fY, const wchar_t* pText)
{ {
float fMarginX = **reinterpret_cast<float**>(pFltX); float fMarginX = **reinterpret_cast<float**>(pFltX);
PrintString(fX - fMarginX + (fMarginX * *ResolutionWidthMult * RsGlobal->MaximumWidth), fY, pText); PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY, pText);
} }
template<int pFltY> template<int pFltY>
void AlteredPrintStringYOnly(float fX, float fY, const wchar_t* pText) void AlteredPrintStringYOnly(float fX, float fY, const wchar_t* pText)
{ {
float fMarginY = **reinterpret_cast<float**>(pFltY); float fMarginY = **reinterpret_cast<float**>(pFltY);
PrintString(fX, fY - fMarginY + (fMarginY * *ResolutionHeightMult * RsGlobal->MaximumHeight), pText); PrintString(fX, fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
} }
float FixedRefValue() float FixedRefValue()
@ -106,8 +116,6 @@ void Patch_VC_10()
bSnapShotActive = *(bool**)0x4D1239; bSnapShotActive = *(bool**)0x4D1239;
RsGlobal = *(RsGlobalType**)0x602D32; RsGlobal = *(RsGlobalType**)0x602D32;
ResolutionWidthMult = *(float**)0x5FA15E;
ResolutionHeightMult = *(float**)0x5FA148;
RosieAudioFix_JumpBack = (void*)0x42BFFE; RosieAudioFix_JumpBack = (void*)0x42BFFE;
SubtitlesShadowFix_JumpBack = (void*)0x551701; SubtitlesShadowFix_JumpBack = (void*)0x551701;
@ -166,8 +174,6 @@ void Patch_VC_11()
bSnapShotActive = *(bool**)0x4D1259; bSnapShotActive = *(bool**)0x4D1259;
RsGlobal = *(RsGlobalType**)0x602D12; RsGlobal = *(RsGlobalType**)0x602D12;
ResolutionWidthMult = *(float**)0x5FA17E;
ResolutionHeightMult = *(float**)0x5FA168;
RosieAudioFix_JumpBack = (void*)0x42BFFE; RosieAudioFix_JumpBack = (void*)0x42BFFE;
SubtitlesShadowFix_JumpBack = (void*)0x551721; SubtitlesShadowFix_JumpBack = (void*)0x551721;
@ -226,8 +232,6 @@ void Patch_VC_Steam()
bSnapShotActive = *(bool**)0x4D10F9; bSnapShotActive = *(bool**)0x4D10F9;
RsGlobal = *(RsGlobalType**)0x602952; RsGlobal = *(RsGlobalType**)0x602952;
ResolutionWidthMult = *(float**)0x5F9DBE;
ResolutionHeightMult = *(float**)0x5F9DA8;
RosieAudioFix_JumpBack = (void*)0x42BFCE; RosieAudioFix_JumpBack = (void*)0x42BFCE;
SubtitlesShadowFix_JumpBack = (void*)0x5515F1; SubtitlesShadowFix_JumpBack = (void*)0x5515F1;