public static void Team_AddUnit_Postfix(Team __instance, AbstractActor unit) { // The added unit is a reinforcement if round > 0 if (__instance.Combat.TurnDirector.CurrentRound > 1 && Mod.Config.Combat.SpawnProtection.ApplyToReinforcements) { HostilityMatrix hm = __instance.Combat.HostilityMatrix; Mod.Log.Info($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}"); List <AbstractActor> actor = new List <AbstractActor>(); if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies) { actor.Add(unit); } else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals) { actor.Add(unit); } else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies) { actor.Add(unit); } if (actor.Count == 1) { Mod.Log.Info($"Applying protection to reinforcement:{CombatantUtils.Label(unit)}"); ProtectionHelper.ProtectActors(actor); } } }
static void Postfix(Team __instance, AbstractActor unit) { if (__instance.Combat.TurnDirector.CurrentRound <= 1) // always protect on first round of contract. { HostilityMatrix hm = __instance.Combat.HostilityMatrix; Mod.Log.Info?.Write($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}"); if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies) { ProtectionHelper.ProtectActor(unit); } else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals) { ProtectionHelper.ProtectActor(unit); } else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies) { ProtectionHelper.ProtectActor(unit); } else if (unit.team.IsLocalPlayer) { ProtectionHelper.ProtectActor(unit); } else { Mod.Log.Info?.Write($" -- skipping unknown actor: {unit.DistinctId()}"); } } // The added unit is a reinforcement if round > 1 else if (__instance.Combat.TurnDirector.CurrentRound > 1 && Mod.Config.Combat.SpawnProtection.ApplyToReinforcements) { HostilityMatrix hm = __instance.Combat.HostilityMatrix; Mod.Log.Info?.Write($"Checking actor:{CombatantUtils.Label(unit)} that belongs to team:{unit?.team?.Name}"); if (hm.IsLocalPlayerEnemy(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies) { ProtectionHelper.ProtectActor(unit); } else if (hm.IsLocalPlayerNeutral(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals) { ProtectionHelper.ProtectActor(unit); } else if (hm.IsLocalPlayerFriendly(unit.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies) { ProtectionHelper.ProtectActor(unit); } else if (unit.team.IsLocalPlayer) { ProtectionHelper.ProtectActor(unit); } else { Mod.Log.Info?.Write($" -- skipping unknown actor: {unit.DistinctId()}"); } } }
public static void TurnDirector_BeginNewRound_Postfix(TurnDirector __instance) { Mod.Log.Info($"Protecting lances on firstContact during first round:{__instance.CurrentRound}"); if (__instance.CurrentRound == 1) { ProtectionHelper.ProtectOnFirstRound(); } }
static void Postfix(TurnDirector __instance) { Mod.Log.Info?.Write($"Protecting lances on firstContact during first round:{__instance.CurrentRound}"); if (__instance.CurrentRound == 1) { Mod.Log.Info?.Write($"Protecting units on first turn"); CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat; HostilityMatrix hm = combatState.HostilityMatrix; Team playerTeam = combatState.LocalPlayerTeam; // Includes player units List <AbstractActor> actors = new List <AbstractActor>(); foreach (AbstractActor actor in combatState.AllActors) { if (hm.IsLocalPlayerEnemy(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToEnemies) { Mod.Log.Info?.Write($" -- adding enemy actor: {actor.DistinctId()}"); actors.Add(actor); } else if (hm.IsLocalPlayerNeutral(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToNeutrals) { Mod.Log.Info?.Write($" -- adding neutral actor: {actor.DistinctId()}"); actors.Add(actor); } else if (hm.IsLocalPlayerFriendly(actor.TeamId) && Mod.Config.Combat.SpawnProtection.ApplyToAllies) { Mod.Log.Info?.Write($" -- adding allied actor: {actor.DistinctId()}"); actors.Add(actor); } else if (actor.team.IsLocalPlayer) { Mod.Log.Info?.Write($" -- adding player actor: {actor.DistinctId()}"); actors.Add(actor); } else { Mod.Log.Info?.Write($" -- skipping unknown actor: {actor.DistinctId()}"); } } List <AbstractActor> actorsToProtect = actors.Distinct().ToList(); ProtectionHelper.ProtectActors(actorsToProtect); } }
/// <summary> /// Perform basic checks, method 1 /// Checks are very fast, there is no CPU overhead. /// </summary> public static bool PerformChecks() { var isProcessRemote = AntiDebug.CheckRemoteDebugger(); var isManagedCodesAttached = AntiDebug.CheckDebuggerManagedPresent(); var isUnManagedCodesAttached = AntiDebug.CheckDebuggerUnmanagedPresent(); var checkDebugPort = AntiDebug.CheckDebugPort(); var checkKernelDebugInformation = AntiDebug.CheckKernelDebugInformation(); var detectEmulation = ProtectionHelper.DetectEmulation(); var detectSandbox = ProtectionHelper.DetectSandbox(); var detectVirtualMachine = ProtectionHelper.DetectVirtualMachine(); var detachFromDebuggerProcess = AntiDebug.DetachFromDebuggerProcess(); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.CheckRemoteDebugger)}", isProcessRemote); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.CheckDebuggerManagedPresent)}", isManagedCodesAttached); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.CheckDebuggerUnmanagedPresent)}", isUnManagedCodesAttached); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.CheckDebugPort)}", checkDebugPort); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.CheckKernelDebugInformation)}", checkKernelDebugInformation); WriteBooleanResult($"{nameof(ProtectionHelper)}.{nameof(ProtectionHelper.DetectEmulation)}", detectEmulation); WriteBooleanResult($"{nameof(ProtectionHelper)}.{nameof(ProtectionHelper.DetectSandbox)}", detectSandbox); WriteBooleanResult($"{nameof(ProtectionHelper)}.{nameof(ProtectionHelper.DetectVirtualMachine)}", detectVirtualMachine); WriteBooleanResult($"{nameof(AntiDebug)}.{nameof(AntiDebug.DetachFromDebuggerProcess)}", detachFromDebuggerProcess); AntiDebug.HideOsThreads(); Scanner.ScanAndKill(); if (isProcessRemote || isManagedCodesAttached || isUnManagedCodesAttached || checkDebugPort || checkKernelDebugInformation || detectEmulation || detectSandbox || detectVirtualMachine) { ProtectionHelper.FreezeMouse(); ProtectionHelper.ShowCmd("Protector", "Active debugger found!", "C"); return(true); } return(false); }