diff --git a/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs b/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs new file mode 100644 index 0000000..f07921d --- /dev/null +++ b/TechbloxModdingAPI/App/AntiAntiCheatPatch.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; +using Svelto.Tasks; + +namespace TechbloxModdingAPI.App +{ + public static class AntiAntiCheatPatch + { + private delegate bool AntiAnticheatDelegate(ref object __result); + + private delegate bool AntiAnticheatDelegateBool(ref bool __result); + + private delegate bool AntiAnticheatDelegateTask(ref IEnumerator __result); + + public static void Init(Harmony harmony) + { + var type = AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.AnticheatClientService"); + harmony.Patch(type.GetConstructors()[0], new HarmonyMethod(((Func) AntiAntiCheat).Method)); + harmony.Patch(AccessTools.Method(type, "Shutdown"), new HarmonyMethod(((Func) AntiAntiCheat).Method)); + 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)); + } + + private static bool AntiAntiCheat() => false; + + private static bool AntiAntiCheat(ref object __result) + { + var targetType = + AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.StartProtectedSessionResult"); + var target = Activator.CreateInstance(targetType); + targetType.GetField("Success").SetValue(target, true); + __result = target; + return false; + } + + private static bool AntiAntiCheat(ref bool __result) + { + __result = true; + return false; + } + + private static bool AntiAntiCheatTask(ref IEnumerator __result) + { + IEnumerator Func() + { + yield return Yield.It; + } + + __result = Func(); + return false; + } + } +} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/BlockIDs.cs b/TechbloxModdingAPI/Blocks/BlockIDs.cs index e454c40..2e3618f 100644 --- a/TechbloxModdingAPI/Blocks/BlockIDs.cs +++ b/TechbloxModdingAPI/Blocks/BlockIDs.cs @@ -273,6 +273,12 @@ namespace TechbloxModdingAPI.Blocks /// /// The grid block used by the world editor, named Small Grid like the other one /// - SmallGridInWorldEditor + SmallGridInWorldEditor, + SegoeUITextblock = 376, + GravtracTextblock, + HauserTextblock, + TechnopollasTextblock, + BitBlock = 385, + Timer } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Main.cs b/TechbloxModdingAPI/Main.cs index 0961576..f11059b 100644 --- a/TechbloxModdingAPI/Main.cs +++ b/TechbloxModdingAPI/Main.cs @@ -1,12 +1,10 @@ using System; -using System.Collections.Generic; using System.Reflection; using HarmonyLib; using RobocraftX; using RobocraftX.Services; using Svelto.Context; -using Svelto.Tasks; using TechbloxModdingAPI.App; using TechbloxModdingAPI.Blocks; @@ -72,26 +70,20 @@ namespace TechbloxModdingAPI Block.Init(); BlockGroup.Init(); Wire.Init(); + // init client Logging.MetaDebugLog($"Initializing Client"); Client.Init(); Game.Init(); // init UI + Logging.MetaDebugLog($"Initializing UI"); Interface.IMGUI.Constants.Init(); Interface.IMGUI.IMGUIManager.Init(); + // init anti-anticheat Logging.MetaDebugLog("Initializing anti-anticheat"); - var type = AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.AnticheatClientService"); - harmony.Patch(type.GetConstructors()[0], new HarmonyMethod(((Func) AntiAntiCheat).Method)); - harmony.Patch(AccessTools.Method(type, "Shutdown"), new HarmonyMethod(((Func) AntiAntiCheat).Method)); - 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)); + AntiAntiCheatPatch.Init(harmony); Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} initialized"); } - public delegate bool AntiAnticheatDelegate(ref object __result); - public delegate bool AntiAnticheatDelegateBool(ref bool __result); - public delegate bool AntiAnticheatDelegateTask(ref IEnumerator __result); - /// /// Shuts down & cleans up the TechbloxModdingAPI. /// Call this as late as possible before Techblox quits. @@ -120,34 +112,5 @@ namespace TechbloxModdingAPI ErrorBuilder.DisplayMustQuitError("Failed to patch Techblox!\n" + "Make sure you're using the latest version of TechbloxModdingAPI or disable mods if the API isn't released yet."); } - - private static bool AntiAntiCheat() => false; - - private static bool AntiAntiCheat(ref object __result) - { - var targetType = - AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.StartProtectedSessionResult"); - var target = Activator.CreateInstance(targetType); - targetType.GetField("Success").SetValue(target, true); - __result = target; - return false; - } - - private static bool AntiAntiCheat(ref bool __result) - { - __result = true; - return false; - } - - private static bool AntiAntiCheatTask(ref IEnumerator __result) - { - IEnumerator Func() - { - yield return Yield.It; - } - - __result = Func(); - return false; - } } } diff --git a/TechbloxModdingAPI/Players/PlayerEventsEngine.cs b/TechbloxModdingAPI/Players/PlayerEventsEngine.cs index 2c80f24..af7d095 100644 --- a/TechbloxModdingAPI/Players/PlayerEventsEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEventsEngine.cs @@ -1,7 +1,9 @@ using RobocraftX.Character; using RobocraftX.Character.Movement; using Svelto.ECS; + using TechbloxModdingAPI.Engines; +using TechbloxModdingAPI.Utility; namespace TechbloxModdingAPI.Players { @@ -21,7 +23,7 @@ namespace TechbloxModdingAPI.Players public void MovedTo(ref CharacterPilotSeatEntityStruct entityComponent, ExclusiveGroupStruct previousGroup, EGID egid) { - var seatId = entityComponent.pilotSeatEntity.ToEGID(entitiesDB); + 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)); if (previousGroup == CharacterExclusiveGroups.InPilotSeatGroup) diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index 1cdfe9e..f528f83 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -10,12 +10,10 @@ using IllusionInjector; using RobocraftX.FrontEnd; using Unity.Mathematics; using UnityEngine; -using RobocraftX.Common.Input; using Svelto.Tasks; using Svelto.Tasks.Lean; using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Commands; -using TechbloxModdingAPI.Input; using TechbloxModdingAPI.Players; using TechbloxModdingAPI.Tasks; using TechbloxModdingAPI.Utility; diff --git a/TechbloxModdingAPI/Utility/WrappedHandler.cs b/TechbloxModdingAPI/Utility/WrappedHandler.cs index 57ff3ba..41e2fc7 100644 --- a/TechbloxModdingAPI/Utility/WrappedHandler.cs +++ b/TechbloxModdingAPI/Utility/WrappedHandler.cs @@ -34,6 +34,12 @@ namespace TechbloxModdingAPI.Utility Logging.LogWarning(wrappedException.ToString()); } }; + if (wrappers.ContainsKey(added)) + { + original.eventHandler -= wrapped; + wrappers.Remove(added); + } + wrappers.Add(added, wrapped); return new WrappedHandler { eventHandler = original.eventHandler + wrapped }; }