diff --git a/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs b/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs index f07921d..ed249bf 100644 --- a/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs +++ b/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs @@ -21,6 +21,7 @@ namespace TechbloxModdingAPI.App harmony.Patch(AccessTools.Method(type, "StartProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegate) AntiAntiCheat).Method)); harmony.Patch(AccessTools.Method(type, "StopProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegateBool) AntiAntiCheat).Method)); harmony.Patch(AccessTools.Method("Techblox.Services.Eos.Anticheat.Client.EosGetPendingMessagesToSendServiceRequest:Execute"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method)); + harmony.Patch(AccessTools.Method("Techblox.Anticheat.Client.Engines.ShowFeedbackDialogEngine:PollAnticheatStatus"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method)); } private static bool AntiAntiCheat() => false; diff --git a/TechbloxModdingAPI/App/GameGameEngine.cs b/TechbloxModdingAPI/App/GameGameEngine.cs index 147606e..46167a4 100644 --- a/TechbloxModdingAPI/App/GameGameEngine.cs +++ b/TechbloxModdingAPI/App/GameGameEngine.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using RobocraftX.Common; using RobocraftX.Schedulers; @@ -13,6 +14,7 @@ using Techblox.Environment.Transition; using Techblox.GameSelection; using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Engines; +using TechbloxModdingAPI.Players; using TechbloxModdingAPI.Utility; namespace TechbloxModdingAPI.App @@ -30,16 +32,32 @@ namespace TechbloxModdingAPI.App public EntitiesDB entitiesDB { set; private get; } private bool enteredGame; + private bool loadingFinished; + private bool playerJoined; public void Dispose() { ExitGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID }); IsInGame = false; + loadingFinished = false; + playerJoined = false; + enteredGame = false; } public void Ready() { enteredGame = true; + Player.Joined += OnPlayerJoined; + } + + private void OnPlayerJoined(object sender, PlayerEventArgs args) + { + Console.WriteLine("Player joined: " + args.PlayerId + " asd"); + if (args.Player.Type != PlayerType.Local) return; + Console.WriteLine("Player joined is local asd"); + playerJoined = true; + Player.Joined -= OnPlayerJoined; + CheckJoinEvent(); } // game functionality @@ -142,9 +160,18 @@ namespace TechbloxModdingAPI.App public void Remove(ref LoadingActionEntityStruct entityComponent, EGID egid) { // Finished loading if (!enteredGame) return; + enteredGame = false; + loadingFinished = true; + Console.WriteLine("Loading finished - asd"); + CheckJoinEvent(); + } + + private void CheckJoinEvent() + { + Console.WriteLine($"Check: {loadingFinished} {playerJoined}"); + if (!loadingFinished || !playerJoined) return; EnterGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID }); IsInGame = true; - enteredGame = false; } } } diff --git a/TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs b/TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs index 8b3c865..c27c484 100644 --- a/TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs +++ b/TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections; using System.Collections.Generic; -using TechbloxModdingAPI.App; -using TechbloxModdingAPI.Utility; -using Rewired.Internal; -using Svelto.DataStructures; using Svelto.Tasks; using Svelto.Tasks.ExtraLean; -using Svelto.Tasks.ExtraLean.Unity; +using TechbloxModdingAPI.Tasks; using UnityEngine; namespace TechbloxModdingAPI.Interface.IMGUI diff --git a/TechbloxModdingAPI/Player.Events.cs b/TechbloxModdingAPI/Player.Events.cs index 1a07c36..8d8cd10 100644 --- a/TechbloxModdingAPI/Player.Events.cs +++ b/TechbloxModdingAPI/Player.Events.cs @@ -20,6 +20,22 @@ namespace TechbloxModdingAPI add => seatExited += value; remove => seatExited -= value; } + + internal static WrappedHandler joined; + + public static event EventHandler Joined + { + add => joined += value; + remove => joined -= value; + } + + internal static WrappedHandler left; + + public static event EventHandler Left + { + add => left += value; + remove => left -= value; + } } public struct PlayerSeatEventArgs @@ -27,4 +43,10 @@ namespace TechbloxModdingAPI public EGID SeatId; public Seat Seat => (Seat)Block.New(SeatId); } + + public struct PlayerEventArgs + { + public EGID PlayerId; + public Player Player => Player.GetInstance(PlayerId.entityID); + } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs index 125f2e0..462e44b 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -23,8 +23,8 @@ namespace TechbloxModdingAPI public partial class Player : EcsObjectBase, IEquatable, IEquatable { // static functionality - private static PlayerEngine playerEngine = new PlayerEngine(); - private static PlayerEventsEngine playerEventsEngine = new PlayerEventsEngine(); + private static readonly PlayerEngine playerEngine = new PlayerEngine(); + private static readonly PlayerEventsEngine playerEventsEngine = new PlayerEventsEngine(); private static Player localPlayer; /// @@ -76,6 +76,12 @@ namespace TechbloxModdingAPI } } + internal static Player GetInstance(uint id) + { + return EcsObjectBase.GetInstance(new EGID(id, CharacterExclusiveGroups.OnFootGroup), + e => new Player(e.entityID)); + } + /// /// Initializes a new instance of the class. /// diff --git a/TechbloxModdingAPI/Players/PlayerEventsEngine.cs b/TechbloxModdingAPI/Players/PlayerEventsEngine.cs index af7d095..4461b71 100644 --- a/TechbloxModdingAPI/Players/PlayerEventsEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEventsEngine.cs @@ -1,13 +1,13 @@ using RobocraftX.Character; using RobocraftX.Character.Movement; +using RobocraftX.Common.Input; using Svelto.ECS; using TechbloxModdingAPI.Engines; -using TechbloxModdingAPI.Utility; namespace TechbloxModdingAPI.Players { - public class PlayerEventsEngine : IApiEngine, IReactOnSwap + public class PlayerEventsEngine : IApiEngine, IReactOnSwap, IReactOnAddAndRemove { public void Ready() { @@ -24,12 +24,21 @@ namespace TechbloxModdingAPI.Players public void MovedTo(ref CharacterPilotSeatEntityStruct entityComponent, ExclusiveGroupStruct previousGroup, EGID egid) { entitiesDB.TryGetEGID(entityComponent.pilotSeatEntity, out var seatId); //TODO: Can't get EGID - var player = EcsObjectBase.GetInstance(new EGID(egid.entityID, CharacterExclusiveGroups.OnFootGroup), - e => new Player(e.entityID)); + var player = Player.GetInstance(egid.entityID); if (previousGroup == CharacterExclusiveGroups.InPilotSeatGroup) player.seatExited.Invoke(this, new PlayerSeatEventArgs { SeatId = seatId}); else if (egid.groupID == CharacterExclusiveGroups.InPilotSeatGroup) player.seatEntered.Invoke(this, new PlayerSeatEventArgs { SeatId = seatId }); } + + public void Add(ref PlayerIDStruct entityComponent, EGID egid) + { + Player.joined.Invoke(this, new PlayerEventArgs { PlayerId = egid }); + } + + public void Remove(ref PlayerIDStruct entityComponent, EGID egid) + { + Player.left.Invoke(this, new PlayerEventArgs { PlayerId = egid }); + } } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Tasks/OnGuiRunner.cs b/TechbloxModdingAPI/Tasks/OnGuiRunner.cs new file mode 100644 index 0000000..b3c4000 --- /dev/null +++ b/TechbloxModdingAPI/Tasks/OnGuiRunner.cs @@ -0,0 +1,16 @@ +using System.Collections; +using Svelto.Tasks; +using Svelto.Tasks.ExtraLean; +using Svelto.Tasks.Unity.Internal; + +namespace TechbloxModdingAPI.Tasks +{ + public class OnGuiRunner : BaseRunner> + { + public OnGuiRunner(string name, uint runningOrder = 0) + : base(name) + { + UnityCoroutineRunner.StartOnGuiCoroutine(this._processEnumerator, runningOrder); + } + } +} \ No newline at end of file