diff --git a/TechbloxModdingAPI/App/GameMenuEngine.cs b/TechbloxModdingAPI/App/GameMenuEngine.cs index f356a0d..276bda8 100644 --- a/TechbloxModdingAPI/App/GameMenuEngine.cs +++ b/TechbloxModdingAPI/App/GameMenuEngine.cs @@ -175,7 +175,7 @@ namespace TechbloxModdingAPI.App public static MethodBase TargetMethod() { - return AccessTools.Method(typeof(FullGameCompositionRoot), "GoToMenu"); + return AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToMenu"); } } diff --git a/TechbloxModdingAPI/Blocks/Engine.cs b/TechbloxModdingAPI/Blocks/Engine.cs index 6140b11..9684108 100644 --- a/TechbloxModdingAPI/Blocks/Engine.cs +++ b/TechbloxModdingAPI/Blocks/Engine.cs @@ -22,7 +22,7 @@ namespace TechbloxModdingAPI.Blocks base(new EGID(id, CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP)) { } - + /* /// /// Gets or sets the Engine's On property. May not be saved. /// @@ -34,6 +34,7 @@ namespace TechbloxModdingAPI.Blocks } set { + Techblox.BlockColours.BlockColoursCompositionRoot BlockEngine.GetBlockInfo(this).engineOn = value; } } @@ -377,6 +378,6 @@ namespace TechbloxModdingAPI.Blocks { BlockEngine.GetBlockInfo(this).manualToAutoGearCoolOffTime = value; } - } + }*/ } } diff --git a/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs b/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs index 2ba15ce..789076e 100644 --- a/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs @@ -173,7 +173,8 @@ namespace TechbloxModdingAPI.Blocks.Engines foreach (var block in blocks) { GhostChildUtility.BuildGhostChild(in playerID, block.Id, in pos, in rot, entitiesDB, - BuildGhostBlueprintFactory, false, bssesopt.Get().buildingDroneReference); + BuildGhostBlueprintFactory, false, bssesopt.Get().buildingDroneReference, + FullGameFields._managers.blockLabelResourceManager); } } @@ -272,7 +273,8 @@ namespace TechbloxModdingAPI.Blocks.Engines uint ghostChildBlockId = CommonExclusiveGroups.GetNewGhostChildBlockID(); var ghostEntityReference = GhostBlockUtils.GetGhostEntityReference(sourceId.entityID, entitiesDB); var entityInitializer = BuildGhostBlueprintFactory.Build( - new EGID(ghostChildBlockId, BoxSelectExclusiveGroups.GhostChildEntitiesExclusiveGroup), /*dbStruct.DBID*/ (uint)BlockIDs.Cube); + new EGID(ghostChildBlockId, BoxSelectExclusiveGroups.GhostChildEntitiesExclusiveGroup), /*dbStruct.DBID*/ (uint)BlockIDs.Cube, + FullGameFields._managers.blockLabelResourceManager); entityInitializer.Init(dbStruct); entityInitializer.Init(new GFXPrefabEntityStructGPUI( PrefabsID.GetOrCreatePrefabID((ushort)entityInitializer.Get().prefabAssetID, diff --git a/TechbloxModdingAPI/Blocks/Engines/MovementEngine.cs b/TechbloxModdingAPI/Blocks/Engines/MovementEngine.cs index 07bfbe6..f9d65d8 100644 --- a/TechbloxModdingAPI/Blocks/Engines/MovementEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/MovementEngine.cs @@ -1,4 +1,5 @@ using RobocraftX.Common; +using RobocraftX.DOTS; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Unity.Mathematics; @@ -39,7 +40,7 @@ namespace TechbloxModdingAPI.Blocks.Engines ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault(block); - ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault(block); + ref DOTSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault(block); // main (persistent) position posStruct.position = vector; // placement grid position @@ -49,7 +50,7 @@ namespace TechbloxModdingAPI.Blocks.Engines // collision position if (phyStruct.ID != default) { //It exists - FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation + FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.dotsEntity, new Translation { Value = posStruct.position }); diff --git a/TechbloxModdingAPI/Blocks/Engines/RotationEngine.cs b/TechbloxModdingAPI/Blocks/Engines/RotationEngine.cs index b2be508..4186bfd 100644 --- a/TechbloxModdingAPI/Blocks/Engines/RotationEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/RotationEngine.cs @@ -1,5 +1,5 @@ using RobocraftX.Common; -using RobocraftX.UECS; +using RobocraftX.DOTS; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Unity.Mathematics; @@ -40,7 +40,7 @@ namespace TechbloxModdingAPI.Blocks.Engines ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault(block); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault(block); - ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault(block); + ref DOTSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault(block); // main (persistent) rotation Quaternion newRotation = rotStruct.rotation; newRotation.eulerAngles = vector; @@ -52,7 +52,7 @@ namespace TechbloxModdingAPI.Blocks.Engines // collision rotation if (phyStruct.ID != default) { //It exists - FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, + FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.dotsEntity, new Unity.Transforms.Rotation { Value = rotStruct.rotation diff --git a/TechbloxModdingAPI/Blocks/Engines/ScalingEngine.cs b/TechbloxModdingAPI/Blocks/Engines/ScalingEngine.cs index 9ca77f0..ef5cfe4 100644 --- a/TechbloxModdingAPI/Blocks/Engines/ScalingEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/ScalingEngine.cs @@ -2,7 +2,7 @@ using HarmonyLib; using RobocraftX.Common; -using RobocraftX.UECS; +using RobocraftX.DOTS; using Svelto.ECS; using Unity.Entities; @@ -13,7 +13,7 @@ namespace TechbloxModdingAPI.Blocks.Engines { public class ScalingEngine : IApiEngine { - private static IReactOnAddAndRemove physicsEngine; + private static IReactOnAddAndRemove physicsEngine; public void Ready() { @@ -34,16 +34,16 @@ namespace TechbloxModdingAPI.Blocks.Engines if (_entityManager == default) _entityManager = FullGameFields._physicsWorld.EntityManager; //Assuming the block exists - var entity = entitiesDB.QueryEntity(egid).uecsEntity; - var pes = new UECSPhysicsEntityCreationStruct(); - physicsEngine.Add(ref pes, egid); //Create new UECS entity + var entity = entitiesDB.QueryEntity(egid).dotsEntity; + var pes = new DOTSPhysicsEntityCreationStruct(); + physicsEngine.Add(ref pes, egid); //Create new DOTS entity _entityManager.DestroyEntity(entity); } [HarmonyPatch] class PhysicsEnginePatch { - static void Postfix(IReactOnAddAndRemove __instance) + static void Postfix(IReactOnAddAndRemove __instance) { physicsEngine = __instance; Logging.MetaDebugLog("Physics engine injected."); @@ -51,7 +51,7 @@ namespace TechbloxModdingAPI.Blocks.Engines static MethodBase TargetMethod(Harmony instance) { - return AccessTools.Method("RobocraftX.StateSync.HandleUECSPhysicEntitiesWithPrefabCreationEngine" + + return AccessTools.Method("RobocraftX.StateSync.HandleDOTSPhysicEntitiesWithPrefabCreationEngine" + ":Ready"); } } diff --git a/TechbloxModdingAPI/Commands/CommandPatch.cs b/TechbloxModdingAPI/Commands/CommandPatch.cs deleted file mode 100644 index b928c1d..0000000 --- a/TechbloxModdingAPI/Commands/CommandPatch.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Reflection; - -using HarmonyLib; -using Svelto.ECS; -using RobocraftX.CR.MainGame; -using RobocraftX.Multiplayer; -using RobocraftX.StateSync; -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Commands -{ - /// - /// Patch of RobocraftX.CR.MainGame.MainGameCompositionRoot.DeterministicCompose() - /// Initializes custom commands - /// - [HarmonyPatch] - static class CommandPatch - { - public static void Postfix(StateSyncRegistrationHelper stateSyncReg) - { - /*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters, - stateSyncReg); - uREPL C# compilation not supported anymore */ - var enginesRoot = stateSyncReg.enginesRoot; - CommandManager.RegisterEngines(enginesRoot); - } - - public static MethodInfo TargetMethod() - { - return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose") - .MakeGenericMethod(typeof(object)); - } - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Engines/EnginePatches.cs b/TechbloxModdingAPI/Engines/EnginePatches.cs index 8b6e6a5..7c9524b 100644 --- a/TechbloxModdingAPI/Engines/EnginePatches.cs +++ b/TechbloxModdingAPI/Engines/EnginePatches.cs @@ -6,12 +6,13 @@ using RobocraftX.FrontEnd; using RobocraftX.StateSync; using Svelto.ECS; using Svelto.ECS.Schedulers; +using TechbloxModdingAPI.Commands; using TechbloxModdingAPI.Utility; namespace TechbloxModdingAPI.Engines { [HarmonyPatch] - class GameLoadedEnginePatch + static class GameLoadedTimeStoppedEnginePatch { public static EntitiesSubmissionScheduler Scheduler { get; private set; } public static void Postfix(StateSyncRegistrationHelper stateSyncReg) @@ -19,11 +20,30 @@ namespace TechbloxModdingAPI.Engines // register all game engines, including deterministic GameEngineManager.RegisterEngines(stateSyncReg); Scheduler = stateSyncReg.enginesRoot.scheduler; + // register command engines + /*CommandLineCompositionRoot.Compose(contextHolder, stateSyncReg.enginesRoot, reloadGame, multiplayerParameters, + stateSyncReg); - uREPL C# compilation not supported anymore */ + CommandManager.RegisterEngines(stateSyncReg.enginesRoot); } public static MethodBase TargetMethod() { - return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose").MakeGenericMethod(typeof(object)); + return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeStoppedCompose").MakeGenericMethod(typeof(object)); + } + } + + [HarmonyPatch] + static class GameLoadedTimeRunningEnginePatch + { + public static EntitiesSubmissionScheduler Scheduler { get; private set; } + public static void Postfix(StateSyncRegistrationHelper stateSyncReg) + { + GameLoadedTimeStoppedEnginePatch.Postfix(stateSyncReg); + } + + public static MethodBase TargetMethod() + { + return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicTimeRunningCompose").MakeGenericMethod(typeof(object)); } } diff --git a/TechbloxModdingAPI/Main.cs b/TechbloxModdingAPI/Main.cs index 610aa8e..0961576 100644 --- a/TechbloxModdingAPI/Main.cs +++ b/TechbloxModdingAPI/Main.cs @@ -1,15 +1,15 @@ using System; +using System.Collections.Generic; using System.Reflection; using HarmonyLib; using RobocraftX; -using RobocraftX.Schedulers; using RobocraftX.Services; using Svelto.Context; -using Svelto.Tasks.ExtraLean; +using Svelto.Tasks; + using TechbloxModdingAPI.App; using TechbloxModdingAPI.Blocks; -using TechbloxModdingAPI.Events; using TechbloxModdingAPI.Tasks; using TechbloxModdingAPI.Utility; @@ -78,9 +78,20 @@ namespace TechbloxModdingAPI // init UI Interface.IMGUI.Constants.Init(); Interface.IMGUI.IMGUIManager.Init(); + 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)); 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. @@ -109,5 +120,34 @@ 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/Player.cs b/TechbloxModdingAPI/Player.cs index f4386db..125f2e0 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -187,8 +187,6 @@ namespace TechbloxModdingAPI public float Mass => 1f / playerEngine.GetCharacterStruct(Id).Get().physicsMass.InverseMass; - private float _ping = -1f; - /// /// The player's latest network ping time. /// @@ -197,12 +195,7 @@ namespace TechbloxModdingAPI { get { - var opt = playerEngine.GetPlayerStruct(Id, Type); - if (opt) - { - _ping = opt.Get().lastPingTimeSinceLevelLoad ?? _ping; - } - return _ping; + return playerEngine.GetPing() / 1000f; } } diff --git a/TechbloxModdingAPI/Players/PlayerEngine.cs b/TechbloxModdingAPI/Players/PlayerEngine.cs index 0dc2298..2722258 100644 --- a/TechbloxModdingAPI/Players/PlayerEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEngine.cs @@ -10,6 +10,7 @@ using RobocraftX.Physics; using RobocraftX.Blocks.Ghost; using Gamecraft.GUI.HUDFeedbackBlocks; using RobocraftX.Blocks; +using RobocraftX.Multiplayer; using RobocraftX.PilotSeat; using Svelto.ECS; using Techblox.Camera; @@ -227,5 +228,12 @@ namespace TechbloxModdingAPI.Players opt.Get().instantExit = true; entitiesDB.PublishEntityChange(egid); } + + public uint GetPing() + { + return entitiesDB + .QueryUniqueEntity(MultiplayerExclusiveGroups.MultiplayerStateGroup) + .networkStats.PingMs; + } } } diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index 75d0cc4..1cdfe9e 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -360,15 +360,6 @@ namespace TechbloxModdingAPI.Tests return modsString = sb.ToString(); } - public override void OnUpdate() - { - if (UnityEngine.Input.GetKeyDown(KeyCode.End)) - { - Console.WriteLine("Pressed button to toggle console"); - FakeInput.CustomInput(new LocalCosmeticInputEntityComponent {commandLineToggleInput = true}); - } - } - [HarmonyPatch] public class MinimumSpecsPatch { diff --git a/TechbloxModdingAPI/Utility/FullGameFields.cs b/TechbloxModdingAPI/Utility/FullGameFields.cs index 7ab1978..0aec467 100644 --- a/TechbloxModdingAPI/Utility/FullGameFields.cs +++ b/TechbloxModdingAPI/Utility/FullGameFields.cs @@ -1,20 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using DataLoader; +using DataLoader; using HarmonyLib; using RobocraftX; -using RobocraftX.Common.Utilities; +using RobocraftX.CR.MainGame; using RobocraftX.GUI; using RobocraftX.Multiplayer; -using RobocraftX.Rendering; using Svelto.Context; using Svelto.DataStructures; using Svelto.ECS; -using Svelto.ECS.Schedulers; using UnityEngine; using Unity.Entities; using Unity.Physics.Systems; @@ -128,11 +120,11 @@ namespace TechbloxModdingAPI.Utility } } - public static ECSGameObjectResourceManager _eCsGameObjectResourceManager + public static ECSResourceManagers _managers { get { - return (ECSGameObjectResourceManager)fgcr?.Field("_eCsGameObjectResourceManager").GetValue(); + return (ECSResourceManagers)fgcr?.Field("_managers").GetValue(); } }