Skip to content

Commit

Permalink
Add Position to Actor
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinPtrl committed Mar 15, 2022
1 parent 94aa7fa commit dab4825
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
2 changes: 2 additions & 0 deletions SoTCoreExternal/SoTCoreExternal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Player.cs" />
<Compile Include="SotCore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UE4Actor.cs" />
<Compile Include="UE4Engine.cs" />
<Compile Include="UEObject.cs" />
<Compile Include="Util\Memory.cs" />
<Compile Include="Util\SigScan.cs" />
<Compile Include="Vector3.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
56 changes: 55 additions & 1 deletion SoTCoreExternal/UE4Actor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SoT
{
public class UE4Actor : UEObject
public struct FTransform
{
public float x;
public float y;
public float z;
public float w;
public Vector3 Translation;
public Vector3 Scale3D;
};

[StructLayout(LayoutKind.Explicit)]
public struct SceneComponent
{
[FieldOffset(0x140)]
public FTransform transform;
}

[StructLayout(LayoutKind.Explicit)]
public struct AActor
{
[FieldOffset(0x18)]
public int ObjectID;


[FieldOffset(0x170)]
private ulong RootComponentPtr;

public SceneComponent GetRootComponent()
{
return SotCore.Instance.Memory.ReadProcessMemory<SceneComponent>(RootComponentPtr);
}
}


public class UE4Actor : UEObject
{
String _Name;
public String Name
Expand All @@ -30,6 +65,25 @@ public int Id
}
}

AActor _actor;
private AActor actor
{
get
{
if (_actor.Equals(default)) return _actor;
_actor = SotCore.Instance.Memory.ReadProcessMemory<AActor>(Address);
return _actor;
}
}

public Vector3 Position
{
get
{
return actor.GetRootComponent().transform.Translation;
}
}

public UE4Actor(ulong address) : base(address)
{
}
Expand Down
2 changes: 1 addition & 1 deletion SoTCoreExternal/UE4Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public String DumpClass(UInt64 classAddr)
}
}
else
sb.AppendLine(" " + fType + " " + fName + "(" + fieldObj.ClassName + ") : 0x" + offset.ToString("X"));
sb.AppendLine(" " + fType + " " + fName + "(" + fieldObj.ClassName + "Field Name "+fieldName + ") : 0x" + offset.ToString("X"));
}
pcAddr = SotCore.Instance.Memory.ReadProcessMemory<UInt64>(pcAddr + 0x40);
if (pcAddr == 0) break;
Expand Down
6 changes: 6 additions & 0 deletions SoTCoreExternal/Util/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class Memory : IDisposable
[DllImport("kernel32")] static extern Boolean WriteProcessMemory(IntPtr hProcess, UInt64 lpBaseAddress, Byte[] buffer, Int32 nSize, out Int32 lpNumberOfBytesWritten);
[DllImport("kernel32")] static extern Int32 CloseHandle(IntPtr hObject);
[DllImport("kernel32")] static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, UInt32 dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, UInt32 dwCreationFlags, IntPtr lpThreadId);

internal T ReadProcessMemory<T>(int rootComponentPtr)
{
throw new NotImplementedException();
}

[DllImport("kernel32")] static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
[DllImport("kernel32")] static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, Int32 flAllocationType, Int32 flProtect);
[DllImport("kernel32")] static extern Boolean VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, Int32 dwFreeType);
Expand Down
19 changes: 19 additions & 0 deletions SoTCoreExternal/Vector3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoT
{
public struct Vector3
{
public float X;
public float Y;
public float Z;
public override string ToString()
{
return "(X : " + X + " Y: " + Y + " Z: " + Z + ")";
}
}
}
5 changes: 3 additions & 2 deletions SotCoreTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ static void Main(string[] args)
UE4Actor[] actors = core.GetActors();
foreach (UE4Actor actor in actors)
{
Console.WriteLine("Name : {0} Class Name : {1} Parent Class Name {2}", actor.Name, actor.ClassName, actor.ParentClassName)
Console.WriteLine("Name : {0} Class Name : {1} Parent Class Name {2}", actor.Name, actor.ClassName, actor.ParentClassName);
Console.WriteLine(actor.Position);
}
}
}
}
}
}

0 comments on commit dab4825

Please sign in to comment.