Skip to content

Commit

Permalink
Add the ability to change the Winning player data struct offsets, and…
Browse files Browse the repository at this point in the history
… PlayerInfo structs on the fly.
  • Loading branch information
CarbonNeuron committed May 7, 2021
1 parent e801714 commit 94356c7
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 236 deletions.
30 changes: 27 additions & 3 deletions AUOffsetHelper/Program.cs
Expand Up @@ -59,12 +59,36 @@ static void Main(string[] args)
StringOffsets = new []{0x8, 0xC},
isEpic = false,
AddPlayerPtr = 4,
PlayerListPtr = 0x10
PlayerListPtr = 0x10,
PlayerInfoStructOffsets = new PlayerInfoStructOffsets() {
PlayerIDOffset = 16,
PlayerNameOffset = 24,
ColorIDOffset = 36,
HatIDOffset = 40,
PetIDOffset = 44,
SkinIDOffset = 48,
DisconnectedOffset = 52,
TasksOffset = 56,
ImposterOffset = 64,
DeadOffset = 65,
ObjectOffset = 72
},
WinningPlayerDataStructOffsets = new WinningPlayerDataStructOffsets() {
NameOffset = 0x8,
DeadOffset = 0xC,
ImposterOffset = 0xD,
ColorOffset = 0x10,
SkinOffset = 0x14,
HatOffset = 0x18,
PetOffset = 0x1C,
IsYouOffset = 0x20
}

};

Console.Write(JsonConvert.SerializeObject(a, Formatting.Indented));
var b = new OffsetManager("");
b.AddToLocalIndex(hash, a);
//var b = new OffsetManager("");
//b.AddToLocalIndex(hash, a);
Console.ReadLine();


Expand Down
28 changes: 28 additions & 0 deletions AUOffsetManager/OffsetManager.cs
Expand Up @@ -150,6 +150,34 @@ public class GameOffsets
public int AddPlayerPtr { get; set; }
public int PlayerListPtr { get; set; }

public PlayerInfoStructOffsets PlayerInfoStructOffsets { get; set; }
public WinningPlayerDataStructOffsets WinningPlayerDataStructOffsets { get; set; }

}

public class PlayerInfoStructOffsets {
public int PlayerIDOffset { get; set; }
public int PlayerNameOffset { get; set; }
public int ColorIDOffset { get; set; }
public int HatIDOffset { get; set; }
public int PetIDOffset { get; set; }
public int SkinIDOffset { get; set; }
public int DisconnectedOffset { get; set; }
public int TasksOffset { get; set; }
public int ImposterOffset { get; set; }
public int DeadOffset { get; set; }
public int ObjectOffset { get; set; }
}

public class WinningPlayerDataStructOffsets {
public int NameOffset { get; set; }
public int DeadOffset { get; set; }
public int ImposterOffset { get; set; }
public int ColorOffset { get; set; }
public int SkinOffset { get; set; }
public int HatOffset { get; set; }
public int PetOffset { get; set; }
public int IsYouOffset { get; set; }
}

}
10 changes: 6 additions & 4 deletions AmongUsCapture/Memory/GameMemReader.cs
Expand Up @@ -103,7 +103,8 @@ public class GameMemReader {
var playerAddrPtr = allPlayers + CurrentOffsets.PlayerListPtr;
var Players = new List<PlayerInfo>(playerCount);
for (var i = 0; i < playerCount; i++) {
var pi = CurrentOffsets.isEpic ? (PlayerInfo) memInstance.Read<EpicPlayerInfo>(playerAddrPtr, 0, 0) : memInstance.Read<SteamPlayerInfo>(playerAddrPtr, 0, 0);
var pi = new PlayerInfo(playerAddrPtr, memInstance, CurrentOffsets);
//var pi = CurrentOffsets.isEpic ? (PlayerInfo) memInstance.Read<EpicPlayerInfo>(playerAddrPtr, 0, 0) : memInstance.Read<SteamPlayerInfo>(playerAddrPtr, 0, 0);
if(pi.GetPlayerName() is null || pi.GetPlayerName() == "") continue;
playerAddrPtr += CurrentOffsets.AddPlayerPtr;
Players.Add(pi);
Expand Down Expand Up @@ -137,7 +138,8 @@ public class GameMemReader {
var winnerAddrPtr = winningPlayers + CurrentOffsets.PlayerListPtr;

for (var i = 0; i < winningPlayerCount; i++) {
var wpi = CurrentOffsets.isEpic ? (WinningPlayerData) memInstance.Read<EpicWinningPlayerData>(winnerAddrPtr, 0, 0) : memInstance.Read<SteamWinningPlayerData>(winnerAddrPtr, 0, 0);
var wpi = new WinningPlayerData(winnerAddrPtr, memInstance, CurrentOffsets);
//var wpi = CurrentOffsets.isEpic ? (WinningPlayerData) memInstance.Read<EpicWinningPlayerData>(winnerAddrPtr, 0, 0) : memInstance.Read<SteamWinningPlayerData>(winnerAddrPtr, 0, 0);
winnerAddrPtr += CurrentOffsets.AddPlayerPtr;
try {
OurPlayerInfos[wpi.GetPlayerName()].IsImpostor = wpi.IsImpostor;
Expand Down Expand Up @@ -323,8 +325,8 @@ public class GameMemReader {
Disconnected = exiledPlayer.GetIsDisconnected(),
Color = exiledPlayer.GetPlayerColor()
});
impostorCount = GetPlayers(ProcessMemory.getInstance()).Count(x => x.GetIsImposter() && x.PlayerName != IntPtr.Zero && x.PlayerId != exiledPlayer.PlayerId && !x.GetIsDead() && !x.GetIsDisconnected());
innocentCount = GetPlayers(ProcessMemory.getInstance()).Count(x => !x.GetIsImposter() && x.PlayerName != IntPtr.Zero && x.PlayerId != exiledPlayer.PlayerId && !x.GetIsDead() && !x.GetIsDisconnected());
impostorCount = GetPlayers(ProcessMemory.getInstance()).Count(x => x.GetIsImposter() && x.PlayerName != "" && x.PlayerId != exiledPlayer.PlayerId && !x.GetIsDead() && !x.GetIsDisconnected());
innocentCount = GetPlayers(ProcessMemory.getInstance()).Count(x => !x.GetIsImposter() && x.PlayerName != "" && x.PlayerId != exiledPlayer.PlayerId && !x.GetIsDead() && !x.GetIsDisconnected());

if (impostorCount == 0 || impostorCount >= innocentCount) {
exileCausesEnd = true;
Expand Down
4 changes: 3 additions & 1 deletion AmongUsCapture/Memory/ProcessMemory.cs
Expand Up @@ -30,17 +30,19 @@ public static ProcessMemory getInstance()
}
return instance;
}
protected bool is64Bit;
public bool is64Bit;
public Process process;
public List<Module> modules;
public bool IsHooked { get; protected set; }
public abstract bool HookProcess(string name);
public abstract void LoadModules();
public abstract T Read<T>(IntPtr address, params int[] offsets) where T : unmanaged;
public abstract byte[] Read(IntPtr address, int numBytes);
public abstract T ReadWithDefault<T>(IntPtr address, T defaultparam, params int[] offsets) where T : unmanaged;

public abstract string ReadString(IntPtr address, int lengthOffset = 0x8, int rawOffset = 0xC);
public abstract IntPtr[] ReadArray(IntPtr address, int size);
public abstract int OffsetAddress(ref IntPtr address, params int[] offsets);

public class Module
{
Expand Down
6 changes: 3 additions & 3 deletions AmongUsCapture/Memory/ProcessMemoryLinux.cs
Expand Up @@ -181,8 +181,8 @@ public override IntPtr[] ReadArray(IntPtr address, int size)
* This is because to read and store, Linux uses 'iovec' C structs to provide the base pointer
* and length of the information being read.
* */
private int OffsetAddress(ref IntPtr address, params int[] offsets)

public override int OffsetAddress(ref IntPtr address, params int[] offsets)
{
byte[] buffer = new byte[is64Bit ? 8 : 4];
IntPtr buffer_marshal;
Expand Down Expand Up @@ -234,7 +234,7 @@ private int OffsetAddress(ref IntPtr address, params int[] offsets)
return offsets.Length > 0 ? offsets[offsets.Length - 1] : 0;
}

private byte[] Read(IntPtr address, int numBytes)
public override byte[] Read(IntPtr address, int numBytes)
{
byte[] buffer = new byte[numBytes];

Expand Down
4 changes: 2 additions & 2 deletions AmongUsCapture/Memory/ProcessMemoryWindows.cs
Expand Up @@ -112,7 +112,7 @@ public override IntPtr[] ReadArray(IntPtr address, int size)
return ints;
}

private byte[] Read(IntPtr address, int numBytes)
public override byte[] Read(IntPtr address, int numBytes)
{
byte[] buffer = new byte[numBytes];
if (process == null || address == IntPtr.Zero)
Expand All @@ -121,7 +121,7 @@ private byte[] Read(IntPtr address, int numBytes)
WinAPI.ReadProcessMemory(process.Handle, address, buffer, numBytes, out int bytesRead);
return buffer;
}
private int OffsetAddress(ref IntPtr address, params int[] offsets)
public override int OffsetAddress(ref IntPtr address, params int[] offsets)
{
byte[] buffer = new byte[is64Bit ? 8 : 4];
for (int i = 0; i < offsets.Length - 1; i++)
Expand Down
47 changes: 0 additions & 47 deletions AmongUsCapture/Memory/Structs/EpicPlayerInfo.cs

This file was deleted.

45 changes: 0 additions & 45 deletions AmongUsCapture/Memory/Structs/EpicWinningPlayerData.cs

This file was deleted.

70 changes: 47 additions & 23 deletions AmongUsCapture/Memory/Structs/PlayerInfo.cs
@@ -1,46 +1,70 @@
using System;
using System.Runtime.InteropServices;
using AUOffsetManager;
using Discord;

namespace AmongUsCapture
{

public interface PlayerInfo
public class PlayerInfo
{
public abstract byte PlayerId { get; }
public abstract IntPtr PlayerName {get; }
public abstract byte ColorId { get; }
public abstract uint HatId { get; }
public abstract uint PetId { get; }
public abstract uint SkinId { get; }
public abstract byte Disconnected { get; }
public abstract IntPtr Tasks { get; }
public abstract byte IsImpostor { get; }
public abstract byte IsDead { get; }
public abstract IntPtr _object { get; }

public bool GetIsDead()
{
return this.IsDead > 0;
public byte PlayerId;
public String PlayerName;
public PlayerColor ColorId;
public uint HatId;
public uint PetId;
public uint SkinId;
public bool Disconnected;
public IntPtr Tasks;
public bool IsImpostor;
public bool IsDead;
public IntPtr _object; //Assume this always has largest offset
public PlayerInfo(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets CurrentOffsets) {
unsafe {
var baseAddrCopy = baseAddr;
int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0);
var intPtrSize = MemInstance.is64Bit ? 8 : 4;
int size = ((int)Math.Ceiling((decimal) ((intPtrSize + CurrentOffsets.PlayerInfoStructOffsets.ObjectOffset)/8)))*8; //Find the nearest multiple of 8
byte[] buffer = MemInstance.Read(baseAddrCopy + last, size);
PlayerInfoStructOffsets pOf = CurrentOffsets.PlayerInfoStructOffsets;
fixed (byte* ptr = buffer) {
var buffptr = (IntPtr) ptr;
PlayerId = Marshal.ReadByte(buffptr, pOf.PlayerIDOffset);
var NamePTR = Marshal.ReadIntPtr(buffptr, pOf.PlayerNameOffset);
PlayerName = NamePTR == IntPtr.Zero ? "" : MemInstance.ReadString(NamePTR, CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
ColorId = (PlayerColor)(uint)Marshal.ReadInt32(buffptr, pOf.ColorIDOffset);
HatId = (uint) Marshal.ReadInt32(buffptr, pOf.HatIDOffset);
PetId = (uint) Marshal.ReadInt32(buffptr, pOf.PetIDOffset);
SkinId = (uint) Marshal.ReadInt32(buffptr, pOf.SkinIDOffset);
Disconnected = Marshal.ReadByte(buffptr, pOf.DisconnectedOffset) > 0;
Tasks = Marshal.ReadIntPtr(buffptr, pOf.TasksOffset);
IsImpostor = Marshal.ReadByte(buffptr, pOf.ImposterOffset) == 1;
IsDead = Marshal.ReadByte(buffptr, pOf.DeadOffset) > 0;
_object = Marshal.ReadIntPtr(buffptr, pOf.ObjectOffset);
}
}
}

public string GetPlayerName()
public string GetPlayerName() {
return PlayerName;
}
public bool GetIsDead()
{
return ProcessMemory.getInstance().ReadString((IntPtr)this.PlayerName, 0x10, 0x14);
return IsDead;
}

public bool GetIsImposter()
{
return this.IsImpostor == 1;
return IsImpostor;
}

public PlayerColor GetPlayerColor()
{
return (PlayerColor)this.ColorId;
return ColorId;
}

public bool GetIsDisconnected()
{
return this.Disconnected > 0;
return Disconnected;
}
}
}

0 comments on commit 94356c7

Please sign in to comment.