From ebfb8e719704a3cdfd05ac4ad17970561c408127 Mon Sep 17 00:00:00 2001 From: CorentinPtrl Date: Wed, 30 Mar 2022 00:24:07 +0200 Subject: [PATCH] Fix Update Thread --- SoTCoreExternal/SotCore.cs | 37 +++++++++++++-------- SotCoreTest/Program.cs | 67 ++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/SoTCoreExternal/SotCore.cs b/SoTCoreExternal/SotCore.cs index f8f0f2f..b8f81e8 100644 --- a/SoTCoreExternal/SotCore.cs +++ b/SoTCoreExternal/SotCore.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json.Converters; using System.IO; using SoT.Game.Service; +using System.Threading; namespace SoT { @@ -58,7 +59,7 @@ public Island[] Islands return _Islands; else { - OnTickElapsed(null, null); + Update(); return _Islands; } } @@ -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 ActorsName = new Dictionary(); public Dictionary Offsets = new Dictionary(); - + private UE4Actor[] Actors; private List IncludesActors = new List(); + 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); @@ -133,13 +132,14 @@ public bool Prepare(bool IsSteam) offset = Memory.ReadProcessMemory(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(Memory.ReadProcessMemory(UWorld) + 0x30)); UE4Actor Actors = new UE4Actor(Level.Address + 0xA0); @@ -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; } diff --git a/SotCoreTest/Program.cs b/SotCoreTest/Program.cs index b03414f..1ec2bea 100644 --- a/SotCoreTest/Program.cs +++ b/SotCoreTest/Program.cs @@ -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()); + 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()); - 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); } } }