Skip to content

Commit

Permalink
Fix Update Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinPtrl committed Mar 29, 2022
1 parent c82a156 commit ebfb8e7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
37 changes: 23 additions & 14 deletions SoTCoreExternal/SotCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Newtonsoft.Json.Converters;
using System.IO;
using SoT.Game.Service;
using System.Threading;

namespace SoT
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public Island[] Islands
return _Islands;
else
{
OnTickElapsed(null, null);
Update();
return _Islands;
}
}
Expand All @@ -68,34 +69,32 @@ public Crew[] Crews
{
get
{
if(_Crews != null)
if (_Crews != null)
return _Crews;
else
{
OnTickElapsed(null, null);
Update();
return Crews;
}
}
}

private UE4Actor[] Actors;

public Dictionary<String, JsonManager.Actor> ActorsName = new Dictionary<String, JsonManager.Actor>();
public Dictionary<String, ulong> Offsets = new Dictionary<String, ulong>();

private UE4Actor[] Actors;
private List<String> IncludesActors = new List<string>();
private int IntervalUpdate;
private Thread ThreadUpdate;


private static Timer Ticker;
public SotCore(float IntervalUpdate = 30)
public SotCore(int IntervalUpdate = 1)
{
if (Instance == null)
Instance = this;
Ticker = new Timer(IntervalUpdate);
Ticker.SynchronizingObject = null;
Ticker.Start();

ActorsName = JsonManager.GetJsonActors();
Offsets = JsonManager.GetJsonOffsets();
this.IntervalUpdate = IntervalUpdate;

IncludesActors.AddRange(new String[] { "BP_PlayerPirate_C", "IslandService", "CrewService" });
IncludesActors.AddRange(ActorsName.Keys);
Expand Down Expand Up @@ -133,13 +132,14 @@ public bool Prepare(bool IsSteam)
offset = Memory.ReadProcessMemory<UInt32>(UWorldPattern + 3);
UWorld = UWorldPattern + offset + 7;

Ticker.Elapsed += OnTickElapsed;
ThreadUpdate = new Thread(UpdateThread);
ThreadUpdate.Start();
return true;
}
return false;
}

private void OnTickElapsed(object Sender, ElapsedEventArgs e)
private void Update()
{
UEObject Level = new UEObject(Memory.ReadProcessMemory<UInt64>(Memory.ReadProcessMemory<UInt64>(UWorld) + 0x30));
UE4Actor Actors = new UE4Actor(Level.Address + 0xA0);
Expand Down Expand Up @@ -185,12 +185,21 @@ private void OnTickElapsed(object Sender, ElapsedEventArgs e)
this.Actors = actorList.ToArray();
}

private void UpdateThread()
{
while (true)
{
Update();
Thread.Sleep(IntervalUpdate);
}
}

public UE4Actor[] GetActors()
{
if (this.Actors != null)
return this.Actors;

OnTickElapsed(null, null);
Update();

return this.Actors;
}
Expand Down
67 changes: 32 additions & 35 deletions SotCoreTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,49 @@ static void Main(string[] args)
SotCore core = new SotCore();
if (core.Prepare(false))
{
while (true)
UE4Actor[] actors = core.GetActors();
foreach (UE4Actor actor in actors)
{
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("Position {0} Custom Position {1}", actor.Position, actor.GetCustomPosition<Vector3>());
Console.WriteLine("Name : {0} Class Name : {1} Parent Class Name {2}", actor.Name, actor.ClassName, actor.ParentClassName);
Console.WriteLine("Position {0} Custom Position {1}", actor.Position, actor.GetCustomPosition<Vector3>());

if (actor.Name.Equals("BP_PlayerPirate_C"))
{
Player PiratePlayer = new Player(actor);
Console.WriteLine("Player Name : {0} Current Health : {1} Max Health : {2} Wielded Item : {3}", PiratePlayer.PlayerName, PiratePlayer.CurrentHealth, PiratePlayer.MaxHealth, PiratePlayer.CurrentWieldedItem);
}
else if (actor.Name.Equals("BP_SmallShipTemplate_C") || actor.Name.Equals("BP_SmallShipNetProxy") || actor.Name.Equals("BP_MediumShipTemplate_C") || actor.Name.Equals("BP_MediumShipNetProxy") || actor.Name.Equals("BP_LargeShipTemplate_C") || actor.Name.Equals("BP_LargeShipNetProxy") || actor.Name.Equals("BP_Rowboat_C") || actor.Name.Equals("BP_RowboatRowingSeat_C") || actor.Name.Equals("BP_RowboatRowingSeat_C") || actor.Name.Equals("BP_Rowboat_WithFrontHarpoon_C"))
{
Ship ship = new Ship(actor);
ShipInternalWater InternalWaterComponent = ship.ShipInternalWater;
SinkingShipParams SinkingShipParams = ship.SinkingShipParams;
Console.WriteLine("Water Level {0} Water Amount {1} Crew Id : {2}", InternalWaterComponent.CurrentVisualWaterLevel, InternalWaterComponent.WaterAmount, ship.CrewId);
}
if (actor.Name.Equals("BP_PlayerPirate_C"))
{
Player PiratePlayer = new Player(actor);
Console.WriteLine("Player Name : {0} Current Health : {1} Max Health : {2} Wielded Item : {3}", PiratePlayer.PlayerName, PiratePlayer.CurrentHealth, PiratePlayer.MaxHealth, PiratePlayer.CurrentWieldedItem);
}

Console.WriteLine("Crew Service :");
foreach (Crew crew in core.Crews)
else if (actor.Name.Equals("BP_SmallShipTemplate_C") || actor.Name.Equals("BP_SmallShipNetProxy") || actor.Name.Equals("BP_MediumShipTemplate_C") || actor.Name.Equals("BP_MediumShipNetProxy") || actor.Name.Equals("BP_LargeShipTemplate_C") || actor.Name.Equals("BP_LargeShipNetProxy") || actor.Name.Equals("BP_Rowboat_C") || actor.Name.Equals("BP_RowboatRowingSeat_C") || actor.Name.Equals("BP_RowboatRowingSeat_C") || actor.Name.Equals("BP_Rowboat_WithFrontHarpoon_C"))
{
Console.WriteLine("\t Crew : {0}", crew.CrewId.ToString());
foreach (Player player in crew.PreProcessedPlayers)
{
Console.WriteLine("\t \t Player Name : {0} Crew : {1}", player.PlayerName, crew.CrewId);
}
Ship ship = new Ship(actor);
ShipInternalWater InternalWaterComponent = ship.ShipInternalWater;
SinkingShipParams SinkingShipParams = ship.SinkingShipParams;
Console.WriteLine("Water Level {0} Water Amount {1} Crew Id : {2}", InternalWaterComponent.CurrentVisualWaterLevel, InternalWaterComponent.WaterAmount, ship.CrewId);
}
}

Console.WriteLine("Island Service :");
foreach (Island island in core.Islands)
Console.WriteLine("Crew Service :");
foreach (Crew crew in core.Crews)
{
Console.WriteLine("\t Crew : {0}", crew.CrewId.ToString());
foreach (Player player in crew.PreProcessedPlayers)
{
Console.WriteLine("\t Island : {0}", island.ToString());

Console.WriteLine("\t \t Player Name : {0} Crew : {1}", player.PlayerName, crew.CrewId);
}
}

Console.WriteLine("Island Service :");
foreach (Island island in core.Islands)
{
Console.WriteLine("\t Island : {0}", island.ToString());

Player LocalPlayer = core.LocalPlayer;
Console.WriteLine("Local Player Name : {0} Current Health : {1} Max Health : {2} Oxygen Level : {3} Wielded Item : {4}", LocalPlayer.PlayerName, LocalPlayer.CurrentHealth, LocalPlayer.MaxHealth, LocalPlayer.OxygenLevel, LocalPlayer.CurrentWieldedItem);

CameraManager cameraManager = core.CameraManager;
Console.WriteLine("Camera Manager Location : {0} Rotation : {1} FOV : {2}", cameraManager.Location, cameraManager.Rotation, cameraManager.FOV);
}


Player LocalPlayer = core.LocalPlayer;
Console.WriteLine("Local Player Name : {0} Current Health : {1} Max Health : {2} Oxygen Level : {3} Wielded Item : {4}", LocalPlayer.PlayerName, LocalPlayer.CurrentHealth, LocalPlayer.MaxHealth, LocalPlayer.OxygenLevel, LocalPlayer.CurrentWieldedItem);

CameraManager cameraManager = core.CameraManager;
Console.WriteLine("Camera Manager Location : {0} Rotation : {1} FOV : {2}", cameraManager.Location, cameraManager.Rotation, cameraManager.FOV);
}
}
}
Expand Down

0 comments on commit ebfb8e7

Please sign in to comment.