-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sonic Lost World] Add "Fix Steam Profile Picture"
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
Source/Sonic Lost World/Fixes/Graphics/Fix Steam Profile Picture.hmm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |