Skip to content

Commit

Permalink
Implement Player In-Game Name
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinPtrl committed Mar 17, 2022
1 parent f483e63 commit 0256385
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
10 changes: 10 additions & 0 deletions SoTCoreExternal/Game/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ private UHealthComponent HealthComponent
return SotCore.Instance.Memory.ReadProcessMemory<UHealthComponent>(SotCore.Instance.Memory.ReadProcessMemory<ulong>(Address + 2136));
}
}

public String PlayerName
{
get
{
ulong PlayerState = SotCore.Instance.Memory.ReadProcessMemory<ulong>(Address + 0x3F0);
return SotCore.Instance.Memory.ReadProcessMemory<FString>(PlayerState+ 0x3d8).ToString();
}
}

public float MaxHealth
{
get
Expand Down
10 changes: 10 additions & 0 deletions SoTCoreExternal/Game/SotStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public struct SceneComponent
public FTransform transform;
}

public struct FString
{
private ulong pData;
private int DataSize;
public override string ToString()
{
return Encoding.Unicode.GetString(SotCore.Instance.Memory.ReadProcessMemory(pData, DataSize * 0x4)).Split('\0')[0];
}
}

[StructLayout(LayoutKind.Explicit)]
public struct AActor
{
Expand Down
4 changes: 2 additions & 2 deletions SoTCoreExternal/SotCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public bool Prepare(bool IsSteam)

public UE4Actor[] GetActors()
{
var Level = new UEObject(Memory.ReadProcessMemory<UInt64>(Memory.ReadProcessMemory<UInt64>(UWorld)+ 0x30));
var Actors = new UEObject(Level.Address + 0xA0);
UEObject Level = new UEObject(Memory.ReadProcessMemory<UInt64>(Memory.ReadProcessMemory<UInt64>(UWorld)+ 0x30));
UEObject Actors = new UEObject(Level.Address + 0xA0);
UE4Actor[] result = new UE4Actor[Actors.Num];

for (var i = 0u; i < Actors.Num; i++)
Expand Down
31 changes: 31 additions & 0 deletions SoTCoreExternal/Util/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ public void OpenProcess(Int32 procId)
{
procHandle = OpenProcess(0x38, 1, procId);
}
public byte[] ReadProcessMemory(UInt64 addr, int size)
{
var buffer = new Byte[size];
ReadProcessMemory(procHandle, addr, buffer, size, out Int32 bytesRead);
return buffer;
}

public String ReadProcessMemoryWstring(UInt64 addr)
{
List<Byte> bytes = new List<Byte>();
var isUtf16 = false;
for (UInt32 i = 0; i < 32; i++)
{
var letters8 = ReadProcessMemory<UInt64>(addr + i * 8);
var tempBytes = BitConverter.GetBytes(letters8);
for (int j = 0; j < 8; j++)
{
if (tempBytes[j] == 0 && j == 1 && bytes.Count == 1)
isUtf16 = true;
if (isUtf16 && j % 2 == 1)
continue;
if (tempBytes[j] == 0)
return (String)Encoding.BigEndianUnicode.GetString(bytes.ToArray());
if ((tempBytes[j] < 32 || tempBytes[j] > 126) && tempBytes[j] != '\n')
return (String)"null";
bytes.Add(tempBytes[j]);
}
}
return (String)Encoding.BigEndianUnicode.GetString(bytes.ToArray());
}

public unsafe Object ReadProcessMemory(Type type, UInt64 addr)
{
if (type == typeof(String))
Expand Down
2 changes: 1 addition & 1 deletion SotCoreTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
if(actor.Name.Equals("BP_PlayerPirate_C"))
{
Player player = new Player(actor);
Console.WriteLine("Current Health {0} : Max Health {1}", player.CurrentHealth, player.MaxHealth);
Console.WriteLine("Player Name : {0} Current Health : {1} Max Health : {1}",player.PlayerName, player.CurrentHealth, player.MaxHealth);
Console.ReadKey();
}
}
Expand Down

0 comments on commit 0256385

Please sign in to comment.