Skip to content

Commit

Permalink
Fix slowlook on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjosack committed Apr 28, 2024
1 parent b1db0fd commit 89ec2ae
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AchievementsTracker/AchievementsTracker/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AchievementsTracker
class GameManager
{
private Tracker tracker;
private MemoryReader memoryReader;
public MemoryReader memoryReader;

private ScreenState state;
private int charSelect;
Expand Down
33 changes: 33 additions & 0 deletions AchievementsTracker/AchievementsTracker/MemoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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;

Expand All @@ -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];
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 8 additions & 2 deletions AchievementsTracker/AchievementsTracker/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,6 +58,10 @@ public void SetMultiplayerRoom(string roomCode, bool host)
public void Reset()
{
roomCode = null;
if (gameManager != null)
{
gameManager.memoryReader.FixSlowLook();
}

lock (_runManagerLock)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 89ec2ae

Please sign in to comment.