Skip to content

Commit

Permalink
[Sonic Lost World] Add "Fix Steam Profile Picture"
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaTh-G committed Feb 25, 2024
1 parent ffb4e83 commit 52e414f
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Patch "Fix Steam Profile Picture" in "Fixes/Graphics" by "ĐeäTh" does "Fixes the steam profile picture used on the Title Menu being squashed and stretched."
{
#include "Helpers" noemit

static class SteamIconFix
{
private static bool _isTitleMenuModified = false;
private static bool _isAlreadyCompared = false;

UNMANAGED_FUNCTION(void, IsTitleMenuModifiedImpl, IntPtr in_pResourceName, IntPtr in_pResource)
{
if (_isAlreadyCompared)
return;

byte* pResourceName = (byte*)in_pResourceName;
byte[] name = new byte[16];
for (int i = 0; i < 16; i++)
name[i] = pResourceName[i];

string fileName = System.Text.Encoding.UTF8.GetString(name);

if (fileName != "ui_titlemenu_ugp")
return;

int checksum = 0;
for (int i = 0; i < 0x30BD0; i++)
checksum += ((byte*)in_pResource)[i];

Console.WriteLine(checksum.ToString("X"));

_isAlreadyCompared = true;

if (checksum != 0x9D9836)
_isTitleMenuModified = true;
}

public static long IsTitleMenuModified() => GET_UNMANAGED_FUNCTION_PTR(IsTitleMenuModifiedImpl);

UNMANAGED_FUNCTION(void, UnstretchImpl, IntPtr in_pHudGoc)
{
if (_isTitleMenuModified)
return;

IntPtr rcProjects = *(IntPtr*)IntPtr.Add(in_pHudGoc, 0x40);
IntPtr rcProject = *(IntPtr*)IntPtr.Add(rcProjects, 0);
IntPtr pBinaryProject = *(IntPtr*)IntPtr.Add(rcProject, 0x64);
IntPtr pScenes = *(IntPtr*)IntPtr.Add(pBinaryProject, 0xC);
IntPtr pLayers = *(IntPtr*)IntPtr.Add(pScenes, 0x10);
IntPtr pMiiIconLayerCells = *(IntPtr*)IntPtr.Add(pLayers, 0x3C);
float* pMiiIconCellScaleX = (float*)IntPtr.Add(pMiiIconLayerCells, 0x1D4);
float* pMiiIconCellScaleY = (float*)IntPtr.Add(pMiiIconLayerCells, 0x1D8);

*pMiiIconCellScaleX = 1.0125f;
*pMiiIconCellScaleY = 1.0125f;
}

public static long Unstretch() => GET_UNMANAGED_FUNCTION_PTR(UnstretchImpl);
}

WriteAsmHook
(
$@"
push ebx
push eax
push edx
mov edx, eax
push edx
mov ebx, [ebp + 0xC]
push ebx
mov eax, {SteamIconFix.IsTitleMenuModified()}
call eax

pop edx
pop eax
pop ebx

push 0
push eax
lea ecx, [ebp + 0x10]
",
ASLR(0x0050EEF2), HookBehavior.Replace
)

WriteAsmHook
(
$@"
push ebx
mov ebx, [esi + 0xD4]
push ebx
mov eax, {SteamIconFix.Unstretch()}
call eax

pop ebx
mov ecx, [esi + 0xD4]

",
ASLR(0x005296E9), HookBehavior.Replace
)
}

0 comments on commit 52e414f

Please sign in to comment.