Skip to content

Commit

Permalink
Merge pull request #264 from kurokobo/major-update
Browse files Browse the repository at this point in the history
feat: add support for major update on 2021.11.9
  • Loading branch information
CarbonNeuron authored Nov 10, 2021
2 parents a3958f0 + 3ff48b4 commit 620ac31
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 74 deletions.
64 changes: 36 additions & 28 deletions AUOffsetManager/OffsetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public OffsetManager(string indexURL = "")
this.indexURL = indexURL;
if (File.Exists(StorageLocation))
{
LocalOffsetIndex = JsonConvert.DeserializeObject<Dictionary<string, GameOffsets>>(File.ReadAllText(StorageLocation));
if (LocalOffsetIndex is null)
{
LocalOffsetIndex = new Dictionary<string, GameOffsets>();
}
LocalOffsetIndex = JsonConvert.DeserializeObject<Dictionary<string, GameOffsets>>(File.ReadAllText(StorageLocation));
if (LocalOffsetIndex is null)
{
LocalOffsetIndex = new Dictionary<string, GameOffsets>();
}
}

indexTask = RefreshIndex();
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task RefreshIndex()
await sw.WriteAsync(JsonConvert.SerializeObject(OffsetIndex, Formatting.Indented));
Console.WriteLine(e);
}

}
catch (Exception e)
{
Expand All @@ -70,7 +70,7 @@ public async Task RefreshIndex()
}
Console.WriteLine("If you are reading this that means that the site is down, and you have never used our program before. If github still exists in the future, try again in 30 minutes. - Carbon ");
}

}

public GameOffsets FetchForHash(string sha256Hash)
Expand All @@ -90,7 +90,7 @@ public GameOffsets FetchForHash(string sha256Hash)
}
return offsets;
}

}

public void refreshLocal()
Expand All @@ -100,7 +100,7 @@ public void refreshLocal()
LocalOffsetIndex = JsonConvert.DeserializeObject<Dictionary<string, GameOffsets>>(File.ReadAllText(StorageLocation));
}
}
public void AddToLocalIndex(string gameHash,GameOffsets offset)
public void AddToLocalIndex(string gameHash, GameOffsets offset)
{
using StreamWriter sw = File.CreateText(StorageLocation);
LocalOffsetIndex[gameHash] = offset;
Expand All @@ -127,7 +127,7 @@ public class GameOffsets
public int ServerManagerOffset { get; set; }

public int TempDataOffset { get; set; }

public int GameOptionsOffset { get; set; }

public int[] MeetingHudPtr { get; set; }
Expand All @@ -149,35 +149,43 @@ public class GameOffsets
public bool isEpic { get; set; }
public int AddPlayerPtr { get; set; }
public int PlayerListPtr { get; set; }

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

public PlayerOutfitStructOffsets PlayerOutfitStructOffsets { get; set; }
}

public class PlayerInfoStructOffsets {
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[] OutfitsOffset { get; set; }
public int PlayerLevelOffset { get; set; }
public int DisconnectedOffset { get; set; }
public int[] RoleTypeOffset { get; set; }
public int[] RoleTeamTypeOffset { get; set; }
public int TasksOffset { get; set; }
public int ImposterOffset { get; set; }
public int DeadOffset { get; set; }
public int IsDeadOffset { 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 class WinningPlayerDataStructOffsets
{
public int IsYouOffset { get; set; }
public int IsImposterOffset { get; set; }
public int IsDeadOffset { get; set; }
}

public class PlayerOutfitStructOffsets
{
public int dontCensorNameOffset { get; set; }
public int ColorIDOffset { get; set; }
public int HatIDOffset { get; set; }
public int PetIDOffset { get; set; }
public int SkinIDOffset { get; set; }
public int VisorIDOffset { get; set; }
public int NamePlateIDOffset { get; set; }
public int PlayerNameOffset { get; set; }
public int PreCensorNameOffset { get; set; }
public int PostCensorNameOffset { get; set; }
}
}
39 changes: 30 additions & 9 deletions AmongUsCapture/Memory/Structs/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ namespace AmongUsCapture
public class PlayerInfo
{
public byte PlayerId;
public String PlayerName;

public string PlayerName;
public PlayerColor ColorId;
public uint HatId;
public uint PetId;
public uint SkinId;

public uint PlayerLevel;
public bool Disconnected;

public uint RoleType;
public uint RoleTeamType;

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;
Expand All @@ -27,20 +36,32 @@ public PlayerInfo(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets Curren
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;
PlayerOutfitStructOffsets oOf = CurrentOffsets.PlayerOutfitStructOffsets;
var outfit = MemInstance.Read<IntPtr>(baseAddrCopy, pOf.OutfitsOffset);
fixed (byte* ptr = buffer) {
var buffptr = (IntPtr) ptr;
PlayerId = Marshal.ReadByte(buffptr, pOf.PlayerIDOffset);
var NamePTR = MemInstance.is64Bit ? (IntPtr) Marshal.ReadInt64(buffptr, pOf.PlayerNameOffset) : (IntPtr) Marshal.ReadInt32(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;
IsDead = Marshal.ReadByte(buffptr, pOf.IsDeadOffset) > 0;
_object = Marshal.ReadIntPtr(buffptr, pOf.ObjectOffset);

// Read from Role
RoleType = (uint)MemInstance.Read<int>(baseAddrCopy, pOf.RoleTypeOffset);
RoleTeamType = (uint)MemInstance.Read<int>(baseAddrCopy, pOf.RoleTeamTypeOffset);
IsImpostor = RoleTeamType == 1;

// Read from PlayerOutfit
PlayerName = MemInstance.ReadString(MemInstance.Read<IntPtr>(outfit, oOf.PlayerNameOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
ColorId = (PlayerColor)(uint)MemInstance.Read<int>(outfit, oOf.ColorIDOffset);
// TODO: Since IDs are changed from enum to string like "hat_police", renaming or mapping existing svgs to string is required
// TODO: As a workaround just fill with 0 as IDs
//HatId = MemInstance.ReadString(MemInstance.Read<IntPtr>(outfit, oOf.HatIDOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
//PetId = MemInstance.ReadString(MemInstance.Read<IntPtr>(outfit, oOf.PetIDOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
//SkinId = MemInstance.ReadString(MemInstance.Read<IntPtr>(outfit, oOf.SkinIDOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
HatId = 0;
PetId = 0;
SkinId = 0;
}
}
}
Expand Down
69 changes: 32 additions & 37 deletions AmongUsCapture/Memory/Structs/WinningPlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,41 @@

namespace AmongUsCapture.Memory.Structs
{

public class WinningPlayerData
{

public string Name {get;}


public class WinningPlayerData
{
public string Name {get; }
public int ColorId { get; }
public uint HatId { get; }
public uint PetId { get; }
public uint SkinId { get; }

public bool IsYou { get; }
public bool IsImpostor { get; }
public bool IsDead{get;}

public bool IsImpostor{get;}

public int ColorId{get;}

public uint SkinId{get;}

public uint HatId{get;}

public uint PetId{get;}

public bool IsYou{get;}

public WinningPlayerData(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets CurrentOffsets) {
unsafe {
var baseAddrCopy = baseAddr;
int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0);
int size = ((int)Math.Ceiling((decimal) ((1 + CurrentOffsets.WinningPlayerDataStructOffsets.IsYouOffset)/8)))*8; //Find the nearest multiple of 8
byte[] buffer = MemInstance.Read(baseAddrCopy + last, size);
WinningPlayerDataStructOffsets pOf = CurrentOffsets.WinningPlayerDataStructOffsets;
fixed (byte* ptr = buffer) {
var buffptr = (IntPtr) ptr;
var NamePTR = MemInstance.is64Bit ? (IntPtr) Marshal.ReadInt64(buffptr, pOf.NameOffset) : (IntPtr) Marshal.ReadInt32(buffptr, pOf.NameOffset);
Name = NamePTR == IntPtr.Zero ? "" : MemInstance.ReadString(NamePTR, CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
ColorId = (int)Marshal.ReadInt32(buffptr, pOf.ColorOffset);
HatId = (uint) Marshal.ReadInt32(buffptr, pOf.HatOffset);
PetId = (uint) Marshal.ReadInt32(buffptr, pOf.PetOffset);
SkinId = (uint) Marshal.ReadInt32(buffptr, pOf.SkinOffset);
IsImpostor = Marshal.ReadByte(buffptr, pOf.ImposterOffset) == 1;
IsDead = Marshal.ReadByte(buffptr, pOf.DeadOffset) > 0;
IsYou = Marshal.ReadByte(buffptr, pOf.IsYouOffset) == 1;
}
}
unsafe {
var baseAddrCopy = baseAddr;
int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0);
int size = ((int)Math.Ceiling((decimal) ((8 + CurrentOffsets.WinningPlayerDataStructOffsets.IsDeadOffset)/8)))*8; //Find the nearest multiple of 8
byte[] buffer = MemInstance.Read(baseAddrCopy + last, size);
PlayerOutfitStructOffsets oOf = CurrentOffsets.PlayerOutfitStructOffsets;
WinningPlayerDataStructOffsets pOf = CurrentOffsets.WinningPlayerDataStructOffsets;
fixed (byte* ptr = buffer) {
var buffptr = (IntPtr) ptr;
Name = MemInstance.ReadString(MemInstance.Read<IntPtr>(baseAddrCopy, oOf.PlayerNameOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
ColorId = (int)Marshal.ReadInt32(buffptr, oOf.ColorIDOffset);
// TODO: Since IDs are changed from enum to string like "hat_police", renaming or mapping existing svgs to string is required
// TODO: As a workaround just fill with 0 as IDs
HatId = 0;
PetId = 0;
SkinId = 0;
IsImpostor = Marshal.ReadByte(buffptr, pOf.IsImposterOffset) == 1;
IsDead = Marshal.ReadByte(buffptr, pOf.IsDeadOffset) > 0;
IsYou = Marshal.ReadByte(buffptr, pOf.IsYouOffset) == 1;
}
}
}

public string GetPlayerName() {
Expand Down
Loading

0 comments on commit 620ac31

Please sign in to comment.