diff --git a/Source/Sonic Lost World/Fixes/Graphics/Fix Steam Profile Picture.hmm b/Source/Sonic Lost World/Fixes/Graphics/Fix Steam Profile Picture.hmm new file mode 100644 index 00000000..957a8903 --- /dev/null +++ b/Source/Sonic Lost World/Fixes/Graphics/Fix Steam Profile Picture.hmm @@ -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 + ) +} \ No newline at end of file