From 89ec2ae09ce91a3eadfbe0a672dd4e3901e2e6fb Mon Sep 17 00:00:00 2001 From: gary Date: Sun, 28 Apr 2024 10:09:03 -0700 Subject: [PATCH] Fix slowlook on reset --- .../AchievementsTracker/GameManager.cs | 2 +- .../AchievementsTracker/MemoryReader.cs | 33 +++++++++++++++++++ .../AchievementsTracker/Tracker.cs | 10 ++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/AchievementsTracker/AchievementsTracker/GameManager.cs b/AchievementsTracker/AchievementsTracker/GameManager.cs index 23bcb98..94e245a 100644 --- a/AchievementsTracker/AchievementsTracker/GameManager.cs +++ b/AchievementsTracker/AchievementsTracker/GameManager.cs @@ -5,7 +5,7 @@ namespace AchievementsTracker class GameManager { private Tracker tracker; - private MemoryReader memoryReader; + public MemoryReader memoryReader; private ScreenState state; private int charSelect; diff --git a/AchievementsTracker/AchievementsTracker/MemoryReader.cs b/AchievementsTracker/AchievementsTracker/MemoryReader.cs index 1789498..7fd65e0 100644 --- a/AchievementsTracker/AchievementsTracker/MemoryReader.cs +++ b/AchievementsTracker/AchievementsTracker/MemoryReader.cs @@ -8,6 +8,9 @@ class MemoryReader [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead); + [DllImport("kernel32.dll")] + public static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int nSize, ref int lpNumberOfBytesWrittent); + private int[] SCREEN_STATE = { 0x15446C, 0x58 }; private int[] PLAYER_ONE_HEALTH = { 0x15446C, 0x440694 }; private int[] PLAYER_TWO_HEALTH = { 0x15446C, 0x441B38 }; @@ -29,6 +32,8 @@ class MemoryReader private int[] TUNNEL_REMAINING = { 0x15446C, 0x445BE8 }; private int[] TUTORIAL_STATUS = { 0x15446C, 0x445BE0 }; + private int[] CAMERA_SPEED = { 0x154510, 0x38 }; + private int processHandle; private int baseAddress; @@ -38,6 +43,12 @@ public MemoryReader(int processHandle, int baseAddress) this.baseAddress = baseAddress; } + public void FixSlowLook() + { + byte[] buffer = BitConverter.GetBytes(1.0f); + WriteMemory(buffer, baseAddress, CAMERA_SPEED); + } + public int ReadTutorialStatus() { byte[] buffer = new byte[1]; @@ -203,5 +214,27 @@ private byte[] ReadMemory(byte[] buffer, int addr, int[] offsets) return buffer; } + + private bool WriteMemory(byte[] buffer, int addr, int[] offsets) + { + int bytesRead = 0; + int bytesWritten = 0; + + // Buffer for next pointer + byte[] pointer = new byte[4]; + + // Traverse pointer path + for (int i = 0; i < offsets.Length - 1; i++) + { + addr += offsets[i]; + ReadProcessMemory(processHandle, addr, pointer, pointer.Length, ref bytesRead); + addr = BitConverter.ToInt32(pointer, 0); + } + + // Read value from final address + addr += offsets[offsets.Length - 1]; + + return WriteProcessMemory(processHandle, addr, buffer, buffer.Length, ref bytesWritten); + } } } \ No newline at end of file diff --git a/AchievementsTracker/AchievementsTracker/Tracker.cs b/AchievementsTracker/AchievementsTracker/Tracker.cs index e4a83d8..2cffe80 100644 --- a/AchievementsTracker/AchievementsTracker/Tracker.cs +++ b/AchievementsTracker/AchievementsTracker/Tracker.cs @@ -13,7 +13,9 @@ namespace AchievementsTracker { class Tracker { - private const int PROCESS_WM_READ = 0x0010; + private const int PROCESS_VM_OPERATION = 0x0008; + private const int PROCESS_VM_READ = 0x0010; + private const int PROCESS_VM_WRITE = 0x0020; private const int DAY_IN_MS = 1000 * 60 * 60 * 24; @@ -56,6 +58,10 @@ public void SetMultiplayerRoom(string roomCode, bool host) public void Reset() { roomCode = null; + if (gameManager != null) + { + gameManager.memoryReader.FixSlowLook(); + } lock (_runManagerLock) { @@ -524,7 +530,7 @@ public void Main() }); Log.WriteLine("Spelunky process detected"); - processHandle = (int)OpenProcess(PROCESS_WM_READ, false, spelunky.Id); + processHandle = (int)OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, spelunky.Id); baseAddress = spelunky.MainModule.BaseAddress.ToInt32(); } catch (Exception e)