Decompiled source of TheDudeV1 v1.0.0
D1Dude.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using DM; using HarmonyLib; using Landfall.TABS; using Landfall.TABS.AI; using Landfall.TABS.AI.Components; using Landfall.TABS.GameMode; using Landfall.TABS.GameState; using Microsoft.CodeAnalysis; using RootMotion.FinalIK; using TFBGames; using Unity.Mathematics; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TheV1 { [BepInPlugin("com.c3b3z.thev1", "The V1", "1.0.0")] public sealed class Plugin : BaseUnityPlugin { private static Harmony harmony; private static Plugin instance; internal static Plugin Instance => instance; internal static Harmony Harmony => harmony; private void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown instance = this; harmony = new Harmony("com.c3b3z.thev1"); V1Database.Initialize(); V1Harmony.Apply(); SceneManager.sceneUnloaded += OnSceneUnloaded; SceneManager.sceneLoaded += OnSceneLoaded; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); ((Component)this).gameObject.AddComponent<V1Bootstrap>(); V1Database.EnsureRegistered(); } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { V1Harmony.Apply(); } private void OnSceneUnloaded(Scene scene) { V1Harmony.Remove(); V1Runtime.CleanupScene(); } internal static void ReapplyHooks() { V1Harmony.Apply(); } } internal static class V1Database { internal sealed class DatabaseIDHolder { internal string Name = "The V1"; } internal static readonly DatabaseIDHolder Ids = new DatabaseIDHolder(); internal static Faction Faction { get; private set; } internal static UnitBlueprint Blueprint { get; private set; } internal static UnitBlueprint VisualSource { get; private set; } internal static void Initialize() { //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Faction != (Object)null && (Object)(object)Blueprint != (Object)null) { return; } ContentDatabase val = ContentDatabase.Instance(); if ((Object)(object)Blueprint == (Object)null) { VisualSource = FindVisualSource(val); if ((Object)(object)VisualSource == (Object)null || (Object)(object)VisualSource.UnitBase == (Object)null) { return; } Blueprint = Object.Instantiate<UnitBlueprint>(VisualSource); Blueprint.RightWeapon = null; Blueprint.LeftWeapon = null; Blueprint.rightProjectile = null; Blueprint.leftProjectile = null; Blueprint.m_props = (GameObject[])(object)new GameObject[0]; Blueprint.objectsToSpawnAsChildren = (GameObject[])(object)new GameObject[0]; Blueprint.Mount = null; Blueprint.SetNoCustomRider(); try { FieldInfo field = typeof(UnitBlueprint).GetField("Riders", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(Blueprint, null); } } catch { } Blueprint.holdinigWithTwoHands = false; ((Object)Blueprint).name = "The V1 Dummy"; Blueprint.Entity.Name = "The V1"; Blueprint.Entity.GenerateNewID(); Blueprint.excludeFromWinCondition = false; Blueprint.forceNoRandomSize = true; Blueprint.sizeMultiplier = 1.85f; Blueprint.customCost = 1; Blueprint.useCustomCost = true; Blueprint.HasMissingComponents = false; } if ((Object)(object)Faction == (Object)null) { Faction = ScriptableObject.CreateInstance<Faction>(); ((Object)Faction).name = "The V1"; Faction.Init(); Faction.Entity.Name = "The V1"; Faction.Entity.GenerateNewID(); Faction.m_displayFaction = true; Faction.m_FactionCatagory = (FactionCatagory)1; Faction.m_FactionColor = new Color(0.08f, 0.75f, 1f, 1f); Faction.IsCustom = true; Faction.modID = 0; Faction.index = 9999; Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint }; try { CustomFactionColor[] customFacionColors = val.GetCustomFactionColorDatabase().CustomFacionColors; if (customFacionColors != null && customFacionColors.Length != 0) { Faction.CustomFactionColor = customFacionColors[0]; } } catch { } } Register(val); } internal static void EnsureRegistered() { Initialize(); if (!((Object)(object)Faction == (Object)null) && !((Object)(object)Blueprint == (Object)null)) { EnforceBlueprintIntegrity(); ContentDatabase database = ContentDatabase.Instance(); Register(database); } } private static void EnforceBlueprintIntegrity() { if ((Object)(object)Blueprint == (Object)null) { return; } V1Runtime.BeginInternalMutation(); try { Blueprint.RightWeapon = null; Blueprint.LeftWeapon = null; Blueprint.rightProjectile = null; Blueprint.leftProjectile = null; Blueprint.m_props = (GameObject[])(object)new GameObject[0]; Blueprint.objectsToSpawnAsChildren = (GameObject[])(object)new GameObject[0]; Blueprint.Mount = null; Blueprint.SetNoCustomRider(); Blueprint.holdinigWithTwoHands = false; Blueprint.Entity.Name = "The V1"; Blueprint.excludeFromWinCondition = false; Blueprint.forceNoRandomSize = true; Blueprint.sizeMultiplier = 1.85f; Blueprint.customCost = 1; Blueprint.useCustomCost = true; Blueprint.HasMissingComponents = false; try { FieldInfo field = typeof(UnitBlueprint).GetField("Riders", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(Blueprint, null); } } catch { } if ((Object)(object)Faction != (Object)null) { Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint }; } } finally { V1Runtime.EndInternalMutation(); } } private static void Register(ContentDatabase database) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if (database != null && !((Object)(object)Faction == (Object)null) && !((Object)(object)Blueprint == (Object)null) && Blueprint.Entity != null) { database.AddUserUnitBlueprint(Blueprint); UnitBlueprint val = database.GetUnitBlueprint(Blueprint.Entity.GUID); if ((Object)(object)val == (Object)null) { database.UserContentDatabase.AddUnitBlueprint(Blueprint); val = Blueprint; } Blueprint = val; Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint }; database.AddUserFaction(Faction); Faction faction = database.GetFaction(Faction.Entity.GUID); if ((Object)(object)faction == (Object)null) { database.UserContentDatabase.AddFaction(Faction); } } } private static UnitBlueprint FindVisualSource(ContentDatabase database) { IEnumerable<UnitBlueprint> allUnitBlueprints = database.GetAllUnitBlueprints(); UnitBlueprint result = null; int num = int.MinValue; foreach (UnitBlueprint item in allUnitBlueprints) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item.UnitBase == (Object)null) && !((Object)(object)item.UnitBase.GetComponent<Unit>() == (Object)null) && item.Entity != null) { int num2 = 0; num2 = ((!((Object)(object)item.RightWeapon == (Object)null)) ? (num2 - 60) : (num2 + 30)); num2 = ((!((Object)(object)item.LeftWeapon == (Object)null)) ? (num2 - 60) : (num2 + 30)); num2 = ((item.m_props != null && item.m_props.Length != 0) ? (num2 - 40) : (num2 + 25)); num2 = ((item.objectsToSpawnAsChildren != null && item.objectsToSpawnAsChildren.Length != 0) ? (num2 - 40) : (num2 + 25)); if ((Object)(object)item.Mount == (Object)null) { num2 += 10; } try { UnitBlueprint[] unitRiders = item.UnitRiders; num2 = ((unitRiders != null && unitRiders.Length != 0) ? (num2 - 120) : (num2 + 120)); } catch { } string text = item.Entity.Name ?? string.Empty; string text2 = text.ToLowerInvariant(); if (text2.Contains("peasant")) { num2 += 80; } if (text2.Contains("halfling")) { num2 -= 20; } if (text2.Contains("dummy")) { num2 -= 50; } if (text2.Contains("squire") || text2.Contains("clubber") || text2.Contains("protector")) { num2 -= 20; } if (num2 > num) { num = num2; result = item; } } } return result; } } internal static class V1Harmony { private const string Id = "com.c3b3z.thev1"; private static bool applied; internal static void Apply() { if (!applied && !((Object)(object)V1Database.Blueprint == (Object)null)) { V1Runtime.BindPatchState(); PatchSpawn(); PatchWinnerLogic(); PatchBattleEndAndPauseHooks(); PatchUnityPauseState(); PatchProtectionHooks(); PatchNativeRecoveryHooks(); PatchNativeMeleeHooks(); PatchUnitAndContentHooks(); PatchFactionHooks(); applied = true; } } private static void PatchSpawn() { MethodBase methodBase = AccessTools.Method(typeof(UnitBlueprint), "Spawn", new Type[9] { typeof(Vector3), typeof(Quaternion), typeof(Team), typeof(Unit).MakeByRefType(), typeof(float), typeof(bool), typeof(bool), typeof(int), typeof(Nullable<>).MakeGenericType(typeof(UnitPoolInfo)) }, (Type[])null); if (!(methodBase == null)) { HarmonyMethod val = MakePriority("UnitSpawnPrefix", int.MaxValue); HarmonyMethod val2 = MakePriority("UnitSpawnPostfix", int.MaxValue); Plugin.Harmony.Patch(methodBase, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void PatchWinnerLogic() { PatchWithPrefix(AccessTools.Method(typeof(BaseGameMode), "DecideWinner", new Type[2] { typeof(Team), typeof(string) }, (Type[])null), "DecideWinnerPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(BaseGameMode), "OnWinnerDecided", new Type[2] { typeof(Team), typeof(string) }, (Type[])null), "OnWinnerDecidedPrefix", int.MaxValue); } private static void PatchBattleEndAndPauseHooks() { Assembly assembly = typeof(Unit).Assembly; Type[] array; try { array = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { array = ex.Types.Where((Type t) => t != null).ToArray(); } string[] array2 = new string[8] { "Battle", "GameMode", "GameState", "Pause", "Victory", "Winner", "Simulation", "Time" }; string[] array3 = new string[49] { "DecideWinner", "OnWinnerDecided", "CampaignBattleEnded", "OnServerBattleEnded", "SandboxBattleEnded", "BattleOver", "CheckIfBattleOver", "ClientToServerBattleOver", "ClientBattleOver", "BattlesOver", "IsBattleAlreadyOver", "SetPrematureBattleEnd", "PlayerPrematurelyEndedBattle", "ServerToClientForceEndBattle", "OnLocalOrRemotePrematurelyEndedBattle", "DelayBattleEnd", "RequestEndBattle", "ForceEndBattle", "EndBattle", "SetPause", "UnPause", "LeanPause", "SetTimeToPaused", "PauseAll", "PauseInteraction", "OnInteractionPause", "set_isPaused", "TogglePause", "PauseGame", "SetPaused", "Pause", "Unpause", "UnPauseGame", "PauseGame", "ResumeGame", "Resume", "SetGamePaused", "SetBattlePaused", "SetPausedState", "EnterPause", "ExitPause", "EnablePause", "DisablePause", "PauseSimulation", "ResumeSimulation", "SetSimulationPaused", "SetTimePaused", "SetTimeScale", "SetTimescale" }; foreach (Type type in array) { if (type == null) { continue; } string text = type.FullName ?? type.Name; bool flag = false; for (int num2 = 0; num2 < array2.Length; num2++) { if (text.IndexOf(array2[num2], StringComparison.OrdinalIgnoreCase) >= 0) { flag = true; break; } } if (!flag) { MethodInfo[] methods; try { methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } catch { continue; } for (int num3 = 0; num3 < methods.Length; num3++) { string text2 = ((methods[num3] == null) ? string.Empty : methods[num3].Name); if (text2.IndexOf("pause", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("unpause", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("timescale", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("timeScale", StringComparison.OrdinalIgnoreCase) >= 0) { flag = true; break; } } } if (!flag) { continue; } MethodInfo[] methods2; try { methods2 = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } catch { continue; } foreach (MethodInfo methodInfo in methods2) { if (methodInfo == null || methodInfo.IsAbstract || methodInfo.ContainsGenericParameters) { continue; } for (int num5 = 0; num5 < array3.Length; num5++) { if (string.Equals(methodInfo.Name, array3[num5], StringComparison.Ordinal)) { PatchWithPrefix(methodInfo, "BattleControlPrefix", int.MaxValue); break; } } } } } private static void PatchUnityPauseState() { try { PropertyInfo property = typeof(Time).GetProperty("timeScale", BindingFlags.Static | BindingFlags.Public); MethodInfo methodInfo = ((property == null) ? null : property.GetSetMethod(nonPublic: true)); if (methodInfo != null) { PatchWithPrefix(methodInfo, "TimeScalePrefix", int.MaxValue); } } catch { } try { Type type = AccessTools.TypeByName("UnityEngine.AudioListener"); PropertyInfo propertyInfo = ((type == null) ? null : type.GetProperty("pause", BindingFlags.Static | BindingFlags.Public)); MethodInfo methodInfo2 = ((propertyInfo == null) ? null : propertyInfo.GetSetMethod(nonPublic: true)); if (methodInfo2 != null) { PatchWithPrefix(methodInfo2, "AudioPausePrefix", int.MaxValue); } } catch { } } private static bool TimeScalePrefix(ref float value) { if (!V1Runtime.ShouldBlockBattleControl()) { return true; } if (value <= 0.0001f) { value = 1f; } return true; } private static bool AudioPausePrefix(ref bool value) { if (V1Runtime.ShouldBlockBattleControl() & value) { value = false; } return true; } private static void PatchProtectionHooks() { PatchWithPrefix(AccessTools.Method(typeof(Object), "Destroy", new Type[1] { typeof(Object) }, (Type[])null), "DestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Object), "DestroyImmediate", new Type[1] { typeof(Object) }, (Type[])null), "DestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Object), "Destroy", new Type[2] { typeof(Object), typeof(float) }, (Type[])null), "DestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Object), "DestroyImmediate", new Type[2] { typeof(Object), typeof(bool) }, (Type[])null), "DestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(GameObject), "SetActive", new Type[1] { typeof(bool) }, (Type[])null), "SetActivePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetActive", (Type[])null, (Type[])null), "UnitApiSetActivePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsDead", Type.EmptyTypes, (Type[])null), "UnitApiDeadPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsInPool", Type.EmptyTypes, (Type[])null), "UnitApiPoolPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "UnitApiRemoteControlPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(GeneralInput), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "GeneralInputRemoteControlPrefix", int.MaxValue); MethodBase target = AccessTools.PropertySetter(typeof(Behaviour), "enabled"); PatchWithPrefix(target, "BehaviourEnabledPrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(GameObject), "AddComponent", new Type[1] { typeof(Type) }, (Type[])null), "AddComponentTypePostfix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "TakeDamage", new Type[4] { typeof(float), typeof(Vector3), typeof(Unit), typeof(DamageType) }, (Type[])null), "HealthTakeDamagePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "EnableRagdoll", Type.EmptyTypes, (Type[])null), "RagdollEnablePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "RagdollEnabler", Type.EmptyTypes, (Type[])null), "RagdollEnablePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetAttackTarget", (Type[])null, (Type[])null), "SetAttackTargetPrefix", int.MaxValue); PatchProjectilePhysicsHooks(); } private static void PatchNativeRecoveryHooks() { PatchWithPrefix(AccessTools.PropertySetter(typeof(DataHandler), "Dead"), "DataDeadSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(DataHandler), "CanSeeTarget"), "DataCanSeeTargetSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(DataHandler), "DontWalkFor", new Type[1] { typeof(float) }, (Type[])null), "DataDontWalkForPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(DataHandler), "BatchedUpdate", Type.EmptyTypes, (Type[])null), "DataHandlerBatchedUpdatePrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(DataHandler), "BatchedUpdate", Type.EmptyTypes, (Type[])null), "DataHandlerBatchedUpdatePostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(DataHandler), "BatchedFixedUpdate", Type.EmptyTypes, (Type[])null), "DataHandlerBatchedFixedUpdatePostfix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(MovementHandler), "BatchedFixedUpdate", Type.EmptyTypes, (Type[])null), "MovementHandlerBatchedFixedUpdatePrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(MovementHandler), "BatchedFixedUpdate", Type.EmptyTypes, (Type[])null), "MovementHandlerBatchedFixedUpdatePostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(MovementHandler), "Move", new Type[2] { typeof(RigidbodyHolder), typeof(MovementInstance) }, (Type[])null), "MovementMovePostfix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(UnitAPI), "Active"), "UnitApiActiveSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(UnitAPI), "IsPossessed"), "UnitApiPossessedSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(UnitAPI), "IsRemotelyControlled"), "UnitApiRemoteSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsDead", Type.EmptyTypes, (Type[])null), "UnitApiDeadPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsInPool", Type.EmptyTypes, (Type[])null), "UnitApiPoolPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "UnitApiRemoteControlPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetIsRider", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null), "UnitApiRiderPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "SetCanSeeTarget", new Type[1] { typeof(bool) }, (Type[])null), "UnitApiCanSeeTargetPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UnitAPI), "OnDestroy", Type.EmptyTypes, (Type[])null), "UnitApiOnDestroyPrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(UnitAPI), "SetActive", new Type[2] { typeof(bool), typeof(Nullable<>).MakeGenericType(typeof(bool)) }, (Type[])null), "UnitApiRecoveryPostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(UnitAPI), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "UnitApiRemoteRecoveryPostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(UnitAPI), "SetIsOutOfPool", Type.EmptyTypes, (Type[])null), "UnitApiPoolRecoveryPostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(UnitAPI), "InitializeECSUnit", Type.EmptyTypes, (Type[])null), "UnitApiECSRecoveryPostfix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(UnitAPI), "UpdateECSValues", Type.EmptyTypes, (Type[])null), "UnitApiECSRecoveryPostfix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Unit), "DestroyUnit", Type.EmptyTypes, (Type[])null), "UnitDestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Unit), "OnDestroy", Type.EmptyTypes, (Type[])null), "UnitOnDestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Unit), "FreezeBody", Type.EmptyTypes, (Type[])null), "UnitFreezeBodyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Unit), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "UnitRemoteControlPrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(Unit), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "UnitRemoteRecoveryPostfix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(GeneralInput), "IsRemotelyControlled"), "GeneralInputRemoteSetterPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(GeneralInput), "SetIsRemotelyControlled", new Type[1] { typeof(bool) }, (Type[])null), "GeneralInputRemoteControlPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "Die", new Type[1] { typeof(Unit) }, (Type[])null), "HealthDieUnitPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "Die", new Type[1] { typeof(bool) }, (Type[])null), "HealthDieBoolPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "SetInvulnerable", new Type[1] { typeof(bool) }, (Type[])null), "HealthInvulnerablePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "Update", Type.EmptyTypes, (Type[])null), "HealthUpdatePrefix", int.MaxValue); PatchWithPostfix(AccessTools.Method(typeof(HealthHandler), "Update", Type.EmptyTypes, (Type[])null), "HealthUpdatePostfix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(HealthHandler), "TakeDamage", new Type[4] { typeof(float), typeof(Vector3), typeof(Unit), typeof(DamageType) }, (Type[])null), "HealthTakeDamagePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "EnableRagdoll", Type.EmptyTypes, (Type[])null), "RagdollEnablePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "RagdollEnabler", Type.EmptyTypes, (Type[])null), "RagdollEnablePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "Update", Type.EmptyTypes, (Type[])null), "RagdollUpdatePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "FixedUpdate", Type.EmptyTypes, (Type[])null), "RagdollFixedUpdatePrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(RagdollUtility), "LateUpdate", Type.EmptyTypes, (Type[])null), "RagdollLateUpdatePrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(Rigidbody), "isKinematic"), "RigidbodyKinematicPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(Rigidbody), "constraints"), "RigidbodyConstraintsPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(Rigidbody), "detectCollisions"), "RigidbodyDetectCollisionsPrefix", int.MaxValue); PatchWithPrefix(AccessTools.PropertySetter(typeof(Rigidbody), "useGravity"), "RigidbodyUseGravityPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Rigidbody), "Sleep", Type.EmptyTypes, (Type[])null), "RigidbodySleepPrefix", int.MaxValue); } private static void PatchNativeMeleeHooks() { PatchWithPrefix(AccessTools.Method(typeof(MeleeWeapon), "Attack", new Type[4] { typeof(Vector3), typeof(Rigidbody), typeof(Vector3), typeof(bool) }, (Type[])null), "MeleeAttackPostfix", int.MaxValue); } private static void PatchUnitAndContentHooks() { PatchWithPrefix(AccessTools.Method(typeof(Unit), "DestroyUnit", Type.EmptyTypes, (Type[])null), "UnitDestroyPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(ContentDatabase), "RemoveUserUnitBlueprintAndEmptyFactionsCreated", new Type[1] { typeof(DatabaseID) }, (Type[])null), "RemoveV1BlueprintPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(ContentDatabase), "AddUserUnitBlueprint", new Type[1] { typeof(UnitBlueprint) }, (Type[])null), "AddUserBlueprintPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UserContentDatabase), "RemoveUnitBlueprint", new Type[1] { typeof(DatabaseID) }, (Type[])null), "RemoveV1BlueprintPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(UserContentDatabase), "AddUnitBlueprint", new Type[1] { typeof(UnitBlueprint) }, (Type[])null), "AddUserBlueprintPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(Faction), "RemoveUnit", new Type[1] { typeof(UnitBlueprint) }, (Type[])null), "FactionRemoveUnitPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(LandfallUnitDatabase), "RemoveUnit", new Type[1] { typeof(UnitBlueprint) }, (Type[])null), "LandfallUnitDatabaseRemoveUnitPrefix", int.MaxValue); MethodInfo target = AccessTools.Method(typeof(CustomContentSideBar), "DeleteUnit", Type.EmptyTypes, (Type[])null); PatchWithPrefix(target, "CustomContentSidebarDeletePrefix", int.MaxValue); } private static void PatchWithPostfix(MethodBase target, string methodName, int priority) { if (target == null) { return; } try { Plugin.Harmony.Patch(target, (HarmonyMethod)null, MakePriority(methodName, priority), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch { } } private static void PatchProjectilePhysicsHooks() { PatchWithPrefix(AccessTools.Method(typeof(ProjectileHit), "DoGameplayEffects", new Type[3] { typeof(HitData), typeof(float), typeof(Unit) }, (Type[])null), "ProjectileGameplayPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(CollisionDamage), "OnCollisionEnter", new Type[1] { typeof(Collision) }, (Type[])null), "CollisionDamagePrefix", int.MaxValue); } private static void PatchFactionHooks() { PatchWithPrefix(AccessTools.Method(typeof(ExpandedFactionUI), "Start", (Type[])null, (Type[])null), "EnsureFactionPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(CustomContentFactionBrowser), "Populate", (Type[])null, (Type[])null), "EnsureFactionPrefix", int.MaxValue); PatchWithPrefix(AccessTools.Method(typeof(PlacementFactionBar), "Spawn", new Type[2] { typeof(Faction[]), typeof(bool) }, (Type[])null), "EnsureFactionPrefix", int.MaxValue); } private static void PatchWithPrefix(MethodBase target, string methodName, int priority) { if (target == null) { return; } try { Plugin.Harmony.Patch(target, MakePriority(methodName, priority), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch { } } private static HarmonyMethod MakePriority(string methodName, int priority) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown HarmonyMethod val = new HarmonyMethod(typeof(V1Harmony), methodName, (Type[])null); val.priority = priority; return val; } internal static void Remove() { if (applied) { Plugin.Harmony.UnpatchAll("com.c3b3z.thev1"); applied = false; } } private static bool UnitSpawnPrefix(UnitBlueprint __instance, Vector3 posistion, Team team, ref Unit unitToSpawn, ref GameObject[] __result) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } if (!V1Runtime.ShouldBlockCorruptedRespawn(__instance, team, posistion, out var _)) { return true; } unitToSpawn = null; __result = null; return false; } private static void UnitSpawnPostfix(UnitBlueprint __instance, Vector3 posistion, Quaternion rotation, Team team, ref Unit unitToSpawn, GameObject[] __result) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)unitToSpawn == (Object)null) { return; } if ((Object)(object)V1Database.Blueprint != (Object)null && __instance.Entity.GUID == V1Database.Blueprint.Entity.GUID) { if (V1Runtime.ReplaceDummySpawn(unitToSpawn, team, posistion, rotation)) { } } else { V1Runtime.PrepareSpawnForReuse(unitToSpawn); V1Runtime.TryCorruptRespawn(__instance, unitToSpawn, team, posistion); } } private static void EnsureFactionPrefix() { V1Database.EnsureRegistered(); } private static bool SetActivePrefix(GameObject __instance, bool value) { if (!V1Runtime.IsProtected(__instance) || V1Runtime.IsInternalMutation) { return true; } return value; } private static bool UnitApiSetActivePrefix(UnitAPI __instance, bool active) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } Unit component = ((Component)__instance).GetComponent<Unit>(); if ((Object)(object)component == (Object)null || !V1Runtime.IsProtected(((Component)component).gameObject)) { return true; } return active; } private static bool UnitApiDeadPrefix(UnitAPI __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } Unit component = ((Component)__instance).GetComponent<Unit>(); return (Object)(object)component == (Object)null || !V1Runtime.IsProtected(((Component)component).gameObject); } private static bool UnitApiPoolPrefix(UnitAPI __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } Unit component = ((Component)__instance).GetComponent<Unit>(); return (Object)(object)component == (Object)null || !V1Runtime.IsProtected(((Component)component).gameObject); } private static bool UnitApiRemoteControlPrefix(UnitAPI __instance, [HarmonyArgument(0)] bool isRemotelyControlled) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } Unit component = ((Component)__instance).GetComponent<Unit>(); if ((Object)(object)component == (Object)null || !V1Runtime.IsProtected(((Component)component).gameObject)) { return true; } return !isRemotelyControlled; } private static bool GeneralInputRemoteControlPrefix(GeneralInput __instance, [HarmonyArgument(0)] bool isRemotelyControlled) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } if (!V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } return !isRemotelyControlled; } private static bool BehaviourEnabledPrefix(Behaviour __instance, bool value) { if ((Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject) || V1Runtime.IsInternalMutation) { return true; } return value; } private static bool DecideWinnerPrefix(BaseGameMode __instance, Team winningTeam, string subText) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return !V1Runtime.ShouldBlockVictory(winningTeam); } private static bool OnWinnerDecidedPrefix(BaseGameMode __instance, Team winningTeam, string winSubText) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return !V1Runtime.ShouldBlockVictory(winningTeam); } private static bool BattleControlPrefix() { return !V1Runtime.ShouldBlockBattleControl(); } private static bool SetAttackTargetPrefix(UnitAPI __instance, DataHandler unitData) { if ((Object)(object)__instance == (Object)null || (Object)(object)unitData == (Object)null) { return true; } Unit component = ((Component)__instance).GetComponent<Unit>(); if ((Object)(object)component == (Object)null || !V1Runtime.IsProtected(((Component)component).gameObject)) { return true; } if (V1Runtime.IsCorrupted(unitData.unit) || ((Object)(object)unitData.unit != (Object)null && V1SessionCorruption.IsCorruptedUnit(((Component)unitData.unit).gameObject)) || ((Object)(object)unitData.unit != (Object)null && V1SessionCorruption.IsCorruptedBlueprint(unitData.unit.unitBlueprint))) { return false; } return true; } private static bool HealthTakeDamagePrefix(HealthHandler __instance) { return (Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool HealthUpdatePrefix(HealthHandler __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } V1Runtime.ReassertProtectedHealth(__instance); return true; } private static void HealthUpdatePostfix(HealthHandler __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertProtectedHealth(__instance); } } private static bool RagdollEnablePrefix(RagdollUtility __instance) { return (Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool ProjectileGameplayPrefix(HitData hit) { return hit == null || (Object)(object)hit.rigidbody == (Object)null || !V1Runtime.IsProtected(((Component)hit.rigidbody).gameObject); } private static bool CollisionDamagePrefix(Collision collision) { return collision == null || (Object)(object)collision.rigidbody == (Object)null || !V1Runtime.IsProtected(((Component)collision.rigidbody).gameObject); } private static void AddComponentTypePostfix(GameObject __instance, Type componentType, Component __result) { if ((Object)(object)__instance == (Object)null || componentType == null || (Object)(object)__result == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(__instance) || V1Runtime.IsV1OwnedType(componentType) || V1Runtime.IsAllowedBaselineComponent(__instance, componentType)) { return; } V1Runtime.BeginInternalMutation(); try { Object.Destroy((Object)(object)__result); } finally { V1Runtime.EndInternalMutation(); } } private static bool DataHandlerBatchedUpdatePrefix(DataHandler __instance) { if ((Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject) || V1Runtime.IsInternalMutation) { return true; } V1Runtime.ReassertNativeControl(__instance); return true; } private static bool MovementHandlerBatchedFixedUpdatePrefix(MovementHandler __instance) { if ((Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject) || V1Runtime.IsInternalMutation) { return true; } V1Runtime.ReassertNativeMovement(__instance); return true; } private static bool DataCanSeeTargetSetterPrefix(DataHandler __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = true; return true; } private static bool DataDontWalkForPrefix(DataHandler __instance, [HarmonyArgument(0)] ref float seconds) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } seconds = 0f; return true; } private static void DataHandlerBatchedUpdatePostfix(DataHandler __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeControl(__instance); } } private static void DataHandlerBatchedFixedUpdatePostfix(DataHandler __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeRig(((Component)__instance).gameObject); } } private static void MovementHandlerBatchedFixedUpdatePostfix(MovementHandler __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeMovement(__instance); } } private static void MovementMovePostfix(MovementHandler __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeMovement(__instance); } } private static bool UnitApiActiveSetterPrefix(UnitAPI __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = true; return true; } private static bool UnitApiPossessedSetterPrefix(UnitAPI __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static bool UnitApiRemoteSetterPrefix(UnitAPI __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static bool UnitApiRiderPrefix(UnitAPI __instance, [HarmonyArgument(0)] ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static bool UnitApiCanSeeTargetPrefix(UnitAPI __instance, [HarmonyArgument(0)] ref bool canSee) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } canSee = true; return true; } private static bool UnitApiOnDestroyPrefix(UnitAPI __instance) { return (Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static void UnitApiECSRecoveryPostfix(UnitAPI __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeControl(__instance); } } private static bool UnitOnDestroyPrefix(Unit __instance) { return (Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool UnitFreezeBodyPrefix(Unit __instance) { return (Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool GeneralInputRemoteSetterPrefix(GeneralInput __instance, [HarmonyArgument(0)] ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static bool HealthDieUnitPrefix(HealthHandler __instance) { return (Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool HealthDieBoolPrefix(HealthHandler __instance) { return (Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool HealthInvulnerablePrefix(HealthHandler __instance, [HarmonyArgument(0)] bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } return true; } private static void RagdollFixedUpdatePrefix(RagdollUtility __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertRagdollState(__instance); } } private static void RagdollLateUpdatePrefix(RagdollUtility __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertRagdollState(__instance); } } private static bool RigidbodyDetectCollisionsPrefix(Rigidbody __instance, [HarmonyArgument(0)] ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = true; return true; } private static bool RigidbodyUseGravityPrefix(Rigidbody __instance, [HarmonyArgument(0)] ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = true; return true; } private static bool DataDeadSetterPrefix(DataHandler __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || !V1Runtime.IsProtected(((Component)__instance).gameObject) || V1Runtime.IsInternalMutation) { return true; } value = false; return true; } private static void UnitApiRecoveryPostfix(UnitAPI __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation) { V1Runtime.ReassertNativeControl(__instance); } } private static void UnitApiRemoteRecoveryPostfix(UnitAPI __instance, bool isRemotelyControlled) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeControl(__instance); } } private static void UnitApiPoolRecoveryPostfix(UnitAPI __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeControl(__instance); } } private static bool UnitRemoteControlPrefix(Unit __instance, [HarmonyArgument(0)] ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static void UnitRemoteRecoveryPostfix(Unit __instance, bool isRemotelyControlled) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeControl(__instance); } } private static void RagdollRecoveryPostfix(RagdollUtility __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertNativeRig(((Component)__instance).gameObject); } } private static void RagdollUpdatePrefix(RagdollUtility __instance) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.ReassertRagdollState(__instance); } } private static bool RigidbodyKinematicPrefix(Rigidbody __instance, ref bool value) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } value = false; return true; } private static bool RigidbodyConstraintsPrefix(Rigidbody __instance, ref RigidbodyConstraints value) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected I4, but got Unknown if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation || !V1Runtime.IsProtected(((Component)__instance).gameObject)) { return true; } if (V1Runtime.TryGetBaselineConstraints(__instance, out var constraints)) { value = (RigidbodyConstraints)(int)constraints; } return true; } private static bool RigidbodySleepPrefix(Rigidbody __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } return !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static void MeleeAttackPostfix(MeleeWeapon __instance, Vector3 position, Rigidbody targetRig, Vector3 forcedDirection, bool recursive) { if (!((Object)(object)__instance == (Object)null) && !V1Runtime.IsInternalMutation && V1Runtime.IsProtected(((Component)__instance).gameObject)) { V1Runtime.WidenNativeMelee(__instance); } } private static bool UnitDestroyPrefix(Unit __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } return !V1Runtime.IsProtected(((Component)__instance).gameObject); } private static bool RemoveV1BlueprintPrefix(DatabaseID id) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return !V1Runtime.IsV1Blueprint(id) || V1Runtime.IsInternalMutation; } private static bool AddUserBlueprintPrefix(UnitBlueprint unitBlueprint) { if ((Object)(object)unitBlueprint == (Object)null || V1Runtime.IsInternalMutation) { return true; } return !V1Runtime.IsV1BlueprintReplacement(unitBlueprint); } private static bool FactionRemoveUnitPrefix([HarmonyArgument(0)] UnitBlueprint unitToRemove) { if ((Object)(object)unitToRemove == (Object)null || V1Runtime.IsInternalMutation) { return true; } return !V1Runtime.IsV1Blueprint(unitToRemove); } private static bool LandfallUnitDatabaseRemoveUnitPrefix([HarmonyArgument(0)] UnitBlueprint unit) { if ((Object)(object)unit == (Object)null || V1Runtime.IsInternalMutation) { return true; } return !V1Runtime.IsV1Blueprint(unit); } private static bool CustomContentSidebarDeletePrefix(CustomContentSideBar __instance) { if ((Object)(object)__instance == (Object)null || V1Runtime.IsInternalMutation) { return true; } FieldInfo fieldInfo = AccessTools.Field(((object)__instance).GetType(), "loadedUnit"); UnitBlueprint val = (UnitBlueprint)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); return (Object)(object)val == (Object)null || !V1Runtime.IsV1Blueprint(val); } private static bool DestroyPrefix(Object obj) { if (V1Runtime.IsInternalMutation) { return true; } GameObject val = (GameObject)(object)((obj is GameObject) ? obj : null); if (val != null && V1Runtime.IsProtected(val)) { return false; } Component val2 = (Component)(object)((obj is Component) ? obj : null); if (val2 != null && V1Runtime.IsProtected(val2.gameObject)) { return false; } return true; } } internal static class V1Runtime { private enum AttackStyle { MeleeVortex, MeleeBurst, RangedHypercube, RangedLance, RangedNova } private sealed class State { internal GameObject Visual; internal Unit NativeUnit; internal Team Team; internal Vector3 SpawnPosition; internal Vector3 LastSafePosition; internal float DecisionTimer; internal float AttackTimer; internal float ProjectileTimer; internal float AttackStyleTimer; internal Unit PendingAttackTarget; internal bool VortexActive; internal bool Active; internal bool HasSafeGround; internal float AirborneTime; internal Quaternion LastSafeRotation; internal Animator NativeAnimator; internal AttackStyle Style; internal RigidbodyConstraints BaselineConstraints; internal bool BaselineConstraintsCaptured; internal float StalledTime; internal Vector3 LastRigPosition; internal bool LastKinematicState; } private sealed class CorruptionRecord { internal string BlueprintId; internal Team Team; internal Vector3 Position; internal int RuntimeIndex; internal string SessionInvalidGuid; internal float ExpiresAt; } private static readonly List<State> states = new List<State>(); private static readonly List<GameObject> effects = new List<GameObject>(); private static readonly HashSet<int> protectedIds = new HashSet<int>(); private static readonly HashSet<int> consumedUnitIds = new HashSet<int>(); private static readonly HashSet<string> corruptedSpawnKeys = new HashSet<string>(StringComparer.Ordinal); private static readonly HashSet<string> sessionCorruptedBlueprintIds = new HashSet<string>(StringComparer.Ordinal); private static readonly Dictionary<string, Shader> embeddedShaders = new Dictionary<string, Shader>(StringComparer.OrdinalIgnoreCase); private static readonly List<CorruptionRecord> pendingCorruptions = new List<CorruptionRecord>(); private static AssetBundle shaderBundle; private static CameraEffect cameraEffect; private static bool battleWasActive; private static int internalMutationDepth; private static int lastV1SpawnFrame = -1; private static Team lastV1SpawnTeam; private static Vector3 lastV1SpawnPosition; private static FieldInfo ragdollIsRagdollField = AccessTools.Field(typeof(RagdollUtility), "isRagdoll"); private static FieldInfo ragdollWeightField = AccessTools.Field(typeof(RagdollUtility), "ragdollWeight"); internal static bool IsInternalMutation => internalMutationDepth > 0; internal static void BeginInternalMutation() { internalMutationDepth++; } internal static void EndInternalMutation() { if (internalMutationDepth > 0) { internalMutationDepth--; } } internal static void BindPatchState() { LoadEmbeddedShaders(); } internal static void UnloadEmbeddedShaders() { embeddedShaders.Clear(); if ((Object)(object)shaderBundle != (Object)null) { shaderBundle.Unload(false); shaderBundle = null; } } private static void LoadEmbeddedShaders() { if ((Object)(object)shaderBundle != (Object)null) { return; } Assembly assembly = typeof(V1Runtime).Assembly; string text = assembly.GetManifestResourceNames().FirstOrDefault((string x) => x.EndsWith(".v22.unity3d", StringComparison.OrdinalIgnoreCase)) ?? assembly.GetManifestResourceNames().FirstOrDefault((string x) => x.EndsWith(".v11.unity3d", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(text)) { return; } using (Stream stream = assembly.GetManifestResourceStream(text)) { if (stream == null) { return; } byte[] array = new byte[stream.Length]; int num; int num2; for (num = 0; num < array.Length; num += num2) { num2 = stream.Read(array, num, array.Length - num); if (num2 <= 0) { break; } } if (num != array.Length) { return; } shaderBundle = AssetBundle.LoadFromMemory(array); } if ((Object)(object)shaderBundle == (Object)null) { return; } Shader[] array2 = shaderBundle.LoadAllAssets<Shader>(); foreach (Shader val in array2) { if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(((Object)val).name)) { embeddedShaders[((Object)val).name] = val; } } } internal static Shader GetShader(string shaderName) { LoadEmbeddedShaders(); if (!string.IsNullOrEmpty(shaderName) && embeddedShaders.TryGetValue(shaderName, out var value) && (Object)(object)value != (Object)null) { return value; } if (!string.IsNullOrEmpty(shaderName)) { foreach (KeyValuePair<string, Shader> embeddedShader in embeddedShaders) { if ((Object)(object)embeddedShader.Value == (Object)null || (!embeddedShader.Key.EndsWith(shaderName, StringComparison.OrdinalIgnoreCase) && !shaderName.EndsWith(embeddedShader.Key, StringComparison.OrdinalIgnoreCase))) { continue; } return embeddedShader.Value; } value = Shader.Find(shaderName); if ((Object)(object)value != (Object)null) { return value; } } value = Shader.Find("TheV1/Static"); if ((Object)(object)value != (Object)null) { return value; } return Shader.Find("Standard"); } internal static bool ReplaceDummySpawn(Unit carrier, Team team, Vector3 position, Quaternion rotation) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)carrier == (Object)null || (Object)(object)V1Database.Blueprint == (Object)null) { return false; } if (IsProtected(((Component)carrier).gameObject)) { return false; } if (lastV1SpawnFrame == Time.frameCount && lastV1SpawnTeam == team) { Vector3 val = lastV1SpawnPosition - position; if (((Vector3)(ref val)).sqrMagnitude < 0.122499995f) { BeginInternalMutation(); try { if ((Object)(object)((Component)carrier).gameObject != (Object)null) { Object.Destroy((Object)(object)((Component)carrier).gameObject); } } finally { EndInternalMutation(); } return false; } } lastV1SpawnFrame = Time.frameCount; lastV1SpawnTeam = team; lastV1SpawnPosition = position; for (int num = states.Count - 1; num >= 0; num--) { DestroyState(states[num]); } PrepareNativeV1(((Component)carrier).gameObject); DisableV1ArmPostProcessors(((Component)carrier).gameObject); V1RigStability v1RigStability = ((Component)carrier).gameObject.GetComponent<V1RigStability>(); if ((Object)(object)v1RigStability == (Object)null) { v1RigStability = ((Component)carrier).gameObject.AddComponent<V1RigStability>(); } v1RigStability.Initialize(((Component)carrier).gameObject); ((Object)((Component)carrier).gameObject).name = "The V1 Native Body"; ((Component)carrier).transform.SetPositionAndRotation(position, rotation); ((Component)carrier).gameObject.SetActive(true); RemoveLegacyV1Interferers(((Component)carrier).gameObject); V1VisualMarker v1VisualMarker = ((Component)carrier).gameObject.GetComponent<V1VisualMarker>(); if ((Object)(object)v1VisualMarker == (Object)null) { v1VisualMarker = ((Component)carrier).gameObject.AddComponent<V1VisualMarker>(); } v1VisualMarker.Initialize(team); protectedIds.Add(((Object)((Component)carrier).gameObject).GetInstanceID()); Animator val2 = ((IEnumerable<Animator>)((Component)carrier).GetComponentsInChildren<Animator>(true)).FirstOrDefault((Func<Animator, bool>)((Animator x) => (Object)(object)x != (Object)null)); State state = new State { Visual = ((Component)carrier).gameObject, NativeUnit = carrier, Team = team, SpawnPosition = position, LastSafePosition = position + Vector3.up * 0.25f, LastSafeRotation = rotation, HasSafeGround = false, AirborneTime = 0f, DecisionTimer = 0f, AttackTimer = 0.35f, ProjectileTimer = Random.Range(1.5f, 2.8f), AttackStyleTimer = Random.Range(0.45f, 1f), Active = true, NativeAnimator = val2, Style = (AttackStyle)Random.Range(0, 5), StalledTime = 0f, LastRigPosition = ((Component)carrier).transform.position, LastKinematicState = false }; ConfigureNativeAnimator(val2); if ((Object)(object)carrier.data != (Object)null && (Object)(object)carrier.data.mainRig != (Object)null) { state.BaselineConstraints = carrier.data.mainRig.constraints; state.BaselineConstraintsCaptured = true; state.LastKinematicState = carrier.data.mainRig.isKinematic; state.LastRigPosition = carrier.data.mainRig.position; } states.Add(state); V1ComponentGuard v1ComponentGuard = ((Component)carrier).gameObject.GetComponent<V1ComponentGuard>(); if ((Object)(object)v1ComponentGuard == (Object)null) { v1ComponentGuard = ((Component)carrier).gameObject.AddComponent<V1ComponentGuard>(); } v1ComponentGuard.Initialize(((Component)carrier).gameObject); EnsureCameraEffect(); return true; } private static void DisableNativeWeaponSystems(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if ((Object)(object)val == (Object)null || val is Transform) { continue; } string name = ((object)val).GetType().Name; if (name.IndexOf("HoldingHandler", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("WeaponHandler", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("WeaponHandler", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("HoldableHandler", StringComparison.OrdinalIgnoreCase) >= 0) { Behaviour val2 = (Behaviour)(object)((val is Behaviour) ? val : null); if ((Object)(object)val2 != (Object)null) { val2.enabled = false; } } } Transform[] componentsInChildren2 = root.GetComponentsInChildren<Transform>(true); foreach (Transform val3 in componentsInChildren2) { if ((Object)(object)val3 == (Object)null || !IsExcludedVisualNode(val3)) { continue; } Renderer[] componentsInChildren3 = ((Component)val3).GetComponentsInChildren<Renderer>(true); for (int k = 0; k < componentsInChildren3.Length; k++) { if ((Object)(object)componentsInChildren3[k] != (Object)null) { componentsInChildren3[k].enabled = false; } } Collider[] componentsInChildren4 = ((Component)val3).GetComponentsInChildren<Collider>(true); for (int l = 0; l < componentsInChildren4.Length; l++) { if ((Object)(object)componentsInChildren4[l] != (Object)null) { componentsInChildren4[l].enabled = false; } } } } private static void DisableV1ArmPostProcessors(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } string text = ((object)val).GetType().FullName ?? ((object)val).GetType().Name; if (text != "RootMotion.FinalIK.FBBIKArmBending" && text != "RootMotion.FinalIK.ShoulderRotator") { continue; } Behaviour val2 = (Behaviour)(object)((val is Behaviour) ? val : null); if ((Object)(object)val2 != (Object)null) { try { val2.enabled = false; } catch { } } } } private static void PrepareNativeV1(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { bool flag = (Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root.transform && IsExcludedVisualNode(val); SkinnedMeshRenderer val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<SkinnedMeshRenderer>() : null); if ((Object)(object)val2 != (Object)null) { val2.updateWhenOffscreen = true; if (flag) { ((Renderer)val2).enabled = false; } else { ((Renderer)val2).enabled = true; ((Renderer)val2).sharedMaterials = BuildMaterialArray((((Renderer)val2).sharedMaterials == null) ? 1 : ((Renderer)val2).sharedMaterials.Length, CreateMaterial("TheV1/Static")); } } MeshRenderer val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshRenderer>() : null); if ((Object)(object)val3 != (Object)null) { if (flag) { ((Renderer)val3).enabled = false; } else { ((Renderer)val3).enabled = true; ((Renderer)val3).sharedMaterials = BuildMaterialArray((((Renderer)val3).sharedMaterials == null) ? 1 : ((Renderer)val3).sharedMaterials.Length, CreateMaterial("TheV1/Static")); } } Animator val4 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Animator>() : null); if ((Object)(object)val4 != (Object)null) { ((Behaviour)val4).enabled = true; val4.cullingMode = (AnimatorCullingMode)0; val4.updateMode = (AnimatorUpdateMode)0; val4.speed = 1f; } } } private static void RemoveLegacyV1Interferers(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } string name = ((object)val).GetType().Name; if (name == "V1ProceduralPose" || name == "V1HandRigCleanup") { BeginInternalMutation(); try { Object.Destroy((Object)(object)val); } finally { EndInternalMutation(); } } } } internal static bool IsV1OwnedType(Type type) { return type != null && type.Assembly == typeof(V1Runtime).Assembly && type.Namespace == typeof(V1Runtime).Namespace; } internal static bool IsAllowedBaselineComponent(GameObject go, Type type) { if ((Object)(object)go == (Object)null || type == null) { return true; } return V1ComponentGuard.IsBaselineTypeAllowed(go, type); } internal static bool IsV1Blueprint(DatabaseID id) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) return (Object)(object)V1Database.Blueprint != (Object)null && V1Database.Blueprint.Entity != null && V1Database.Blueprint.Entity.GUID == id; } internal static bool IsV1Blueprint(UnitBlueprint blueprint) { return (Object)(object)blueprint != (Object)null && (Object)(object)V1Database.Blueprint != (Object)null && (Object)(object)blueprint == (Object)(object)V1Database.Blueprint; } internal static bool IsV1BlueprintReplacement(UnitBlueprint blueprint) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) return (Object)(object)blueprint != (Object)null && (Object)(object)V1Database.Blueprint != (Object)null && blueprint != V1Database.Blueprint && blueprint.Entity != null && V1Database.Blueprint.Entity != null && blueprint.Entity.GUID == V1Database.Blueprint.Entity.GUID; } internal static void WidenNativeMelee(MeleeWeapon weapon) { if (!((Object)(object)weapon == (Object)null) && IsProtected(((Component)weapon).gameObject)) { V1NativeMeleeWidening v1NativeMeleeWidening = ((Component)weapon).GetComponent<V1NativeMeleeWidening>(); if ((Object)(object)v1NativeMeleeWidening == (Object)null) { v1NativeMeleeWidening = ((Component)weapon).gameObject.AddComponent<V1NativeMeleeWidening>(); } v1NativeMeleeWidening.Trigger(1.45f, 0.34f); ((Weapon)weapon).maxRange = Mathf.Max(((Weapon)weapon).maxRange, 4.25f); } } internal static bool IsProtected(GameObject go) { if ((Object)(object)go == (Object)null) { return false; } if (protectedIds.Contains(((Object)go).GetInstanceID())) { return true; } Transform val = go.transform; int num = 0; while ((Object)(object)val != (Object)null && num++ < 96) { if (protectedIds.Contains(((Object)((Component)val).gameObject).GetInstanceID())) { return true; } val = val.parent; } return false; } internal static bool ShouldBlockVictory(Team winningTeam) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) State state = states.FirstOrDefault((State x) => x.Active && (Object)(object)x.Visual != (Object)null); return state != null && winningTeam != state.Team; } internal static void Tick() { BeginInternalMutation(); try { for (int num = states.Count - 1; num >= 0; num--) { State state = states[num]; if ((Object)(object)state.Visual == (Object)null) { states.RemoveAt(num); } else { state.Visual.SetActive(true); MaintainSafeGround(state); UpdateNativeAnimator(state); if (!IsBattleState()) { state.DecisionTimer = 0f; state.AttackTimer = 0.25f; state.ProjectileTimer = 0.75f; state.AttackStyleTimer = 0.5f; } else { state.DecisionTimer -= Time.unscaledDeltaTime; state.AttackTimer -= Time.unscaledDeltaTime; state.ProjectileTimer -= Time.unscaledDeltaTime; if (state.DecisionTimer <= 0f) { RunAI(state); state.DecisionTimer = 0.035f; } state.AttackStyleTimer -= Time.unscaledDeltaTime; if (state.AttackStyleTimer <= 0f) { state.Style = SelectCombatStyle(state); state.AttackStyleTimer = Random.Range(0.14f, 0.28f); state.AttackTimer = Mathf.Min(state.AttackTimer, 0.02f); } if (state.AttackTimer <= 0f) { TryAttack(state); state.AttackTimer = (IsRangedStyle(state.Style) ? Random.Range(0.18f, 0.32f) : Random.Range(0.12f, 0.2f)); } if (state.ProjectileTimer <= 0f && IsRangedStyle(state.Style) && Random.value < 0.8f) { TryHyperProjectile(state); state.ProjectileTimer = Random.Range(1.15f, 2.35f); } } } } bool flag = states.Any((State x) => x.Active && (Object)(object)x.Visual != (Object)null) && IsBattleState(); if (flag && !battleWasActive && Random.value < 0.55f) { State state2 = states.FirstOrDefault((State x) => x.Active && (Object)(object)x.Visual != (Object)null); if (state2 != null) { SpawnHypercubeVolley(state2); } } battleWasActive = flag; } finally { EndInternalMutation(); } } internal static void CleanupScene() { for (int num = states.Count - 1; num >= 0; num--) { DestroyState(states[num]); } for (int num2 = effects.Count - 1; num2 >= 0; num2--) { if ((Object)(object)effects[num2] != (Object)null) { Object.Destroy((Object)(object)effects[num2]); } } effects.Clear(); protectedIds.Clear(); consumedUnitIds.Clear(); corruptedSpawnKeys.Clear(); sessionCorruptedBlueprintIds.Clear(); V1SessionCorruption.Clear(); battleWasActive = false; cameraEffect = null; lastV1SpawnFrame = -1; } private static bool IsBattleState() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 GameStateManager service = ServiceLocator.GetService<GameStateManager>(); return service != null && (int)service.GameState == 1; } internal static void ReassertProtectedHealth(HealthHandler health) { if ((Object)(object)health == (Object)null || !IsProtected(((Component)health).gameObject)) { return; } DataHandler val = ((Component)health).GetComponent<DataHandler>(); if ((Object)(object)val == (Object)null) { val = ((Component)health).GetComponentInParent<DataHandler>(); } if ((Object)(object)val == (Object)null) { val = ((Component)health).GetComponentInChildren<DataHandler>(true); } if ((Object)(object)val == (Object)null) { return; } BeginInternalMutation(); try { float num = val.maxHealth; if (float.IsNaN(num) || float.IsInfinity(num) || num <= 0f) { num = (val.maxHealth = 100f); } if (float.IsNaN(val.health) || float.IsInfinity(val.health) || val.health <= 0f) { val.health = num; } if (val.health > num) { val.health = num; } if (val.Dead) { val.Dead = false; } } finally { EndInternalMutation(); } } internal static void ReassertNativeControl(DataHandler data) { if (!((Object)(object)data == (Object)null) && IsProtected(((Component)data).gameObject)) { Unit val = ((Component)data).GetComponent<Unit>(); if ((Object)(object)val == (Object)null) { val = ((Component)data).GetComponentInParent<Unit>(); } ReassertNativeControl(val); } } internal static void ReassertNativeControl(UnitAPI api) { if (!((Object)(object)api == (Object)null) && IsProtected(((Component)api).gameObject)) { Unit component = ((Component)api).GetComponent<Unit>(); ReassertNativeControl(component); } } internal static void ReassertNativeControl(Unit unit) { if ((Object)(object)unit == (Object)null || (Object)(object)((Component)unit).gameObject == (Object)null || !IsProtected(((Component)unit).gameObject)) { return; } BeginInternalMutation(); try { GameObject gameObject = ((Component)unit).gameObject; if (!gameObject.activeSelf) { gameObject.SetActive(true); } if ((Object)(object)unit.api == (Object)null) { unit.api = gameObject.GetComponent<UnitAPI>(); } if ((Object)(object)unit.Input == (Object)null) { unit.Input = gameObject.GetComponent<GeneralInput>(); } if ((Object)(object)unit.data == (Object)null) { unit.data = gameObject.GetComponentInChildren<DataHandler>(true); } UnitAPI api = unit.api; if ((Object)(object)api != (Object)null) { if (api.IsRemotelyControlled || api.IsPossessed || !api.Active) { api.SetActive(true, (bool?)false); } try { api.SetIsOutOfPool(); } catch { } } DataHandler data = unit.data; if ((Object)(object)data != (Object)null) { data.Dead = false; data.playingStaticAnim = false; data.fallTime = 0f; data.ragdollControl = 1f; data.muscleControl = 1f; data.cantFallForSeconds = 0f; } Component[] componentsInChildren = gameObject.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } string name = ((object)val).GetType().Name; switch (name) { default: if (!(name == "RigidbodyHolder")) { continue; } break; case "UnitAPI": case "MovementHandler": case "DataHandler": case "GeneralInput": case "AnimationHandler": break; } Behaviour val2 = (Behaviour)(object)((val is Behaviour) ? val : null); if ((Object)(object)val2 != (Object)null) { val2.enabled = true; } } ReassertNativeRig(gameObject); } finally { EndInternalMutation(); } } internal static void ReassertNativeMovement(MovementHandler movement) { if (!((Object)(object)movement == (Object)null) && IsProtected(((Component)movement).gameObject)) { Unit val = ((Component)movement).GetComponent<Unit>(); if ((Object)(object)val == (Object)null) { val = ((Component)movement).GetComponentInParent<Unit>(); } ReassertNativeControl(val); } } internal static void ReassertNativeRig(GameObject root) { //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)root == (Object)null || !IsProtected(root)) { return; } Unit val = root.GetComponent<Unit>(); if ((Object)(object)val == (Object)null) { val = root.GetComponentInParent<Unit>(); } DataHandler val2 = (((Object)(object)val != (Object)null) ? val.data : root.GetComponentInChildren<DataHandler>(true)); Rigidbody val3 = (((Object)(object)val2 != (Object)null) ? val2.mainRig : null); if ((Object)(object)val3 == (Object)null) { return; } BeginInternalMutation(); try { if (val3.isKinematic) { val3.isKinematic = false; } if (!val3.detectCollisions) { val3.detectCollisions = true; } if (!val3.useGravity) { val3.useGravity = true; } State state = states.FirstOrDefault((State x) => x != null && x.Active && (Object)(object)x.Visual != (Object)null && (Object)(object)x.NativeUnit != (Object)null && (Object)(object)((Component)x.NativeUnit).gameObject == (Object)(object)root); if (state != null && state.BaselineConstraintsCaptured && val3.constraints != state.BaselineConstraints) { val3.constraints = state.BaselineConstraints; } } finally { EndInternalMutation(); } } internal static bool TryGetBaselineConstraints(Rigidbody rig, out RigidbodyConstraints constraints) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected I4, but got Unknown constraints = (RigidbodyConstraints)0; if ((Object)(object)rig == (Object)null || !IsProtected(((Component)rig).gameObject)) { return false; } for (int i = 0; i < states.Count; i++) { State state = states[i]; if (state != null && state.BaselineConstraintsCaptured && !((Object)(object)state.NativeUnit == (Object)null) && !((Object)(object)state.NativeUnit.data == (Object)null) && (Object)(object)state.NativeUnit.data.mainRig == (Object)(object)rig) { constraints = (RigidbodyConstraints)(int)state.BaselineConstraints; return true; } } return false; } internal static void ReassertRagdollState(RagdollUtility ragdoll) { if ((Object)(object)ragdoll == (Object)null || !IsProtected(((Component)ragdoll).gameObject)) { return; } try { if (ragdollIsRagdollField != null) { ragdollIsRagdollField.SetValue(ragdoll, false); } if (ragdollWeightField != null) { ragdollWeightField.SetValue(ragdoll, 0f); } } catch { } ReassertNativeRig(((Component)ragdoll).gameObject); } private static void ClearNativeTarget(State state) { if (state != null && !((Object)(object)state.NativeUnit == (Object)null) && !((Object)(object)state.NativeUnit.data == (Object)null)) { DataHandler data = state.NativeUnit.data; data.targetMainRig = null; data.targetData = null; data.distanceToTarget = float.MaxValue; data.inRange = false; state.PendingAttackTarget = null; } } private static void RunAI(State state) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)state.Visual == (Object)null || (Object)(object)state.NativeUnit == (Object)null || (Object)(object)state.NativeUnit.data == (Object)null) { return; } if ((Object)(object)state.PendingAttackTarget != (Object)null && ((Object)(object)state.PendingAttackTarget.data == (Object)null || state.PendingAttackTarget.data.Dead || IsCorrupted(state.PendingAttackTarget))) { ClearNativeTarget(state); } Unit val = FindNearestEnemy(state.Team, state.Visual.transform.position, 60f); if ((Object)(object)val == (Object)null || (Object)(object)val.data == (Object)null || val.data.Dead || IsCorrupted(val)) { ClearNativeTarget(state); return; } Vector3 val2 = (((Object)(object)val.data.mainRig != (Object)null) ? val.data.mainRig.worldCenterOfMass : ((Component)val).transform.position); if ((Object)(object)val.data.mainRig != (Object)null) { val2 += Vector3.ClampMagnitude(val.data.mainRig.velocity, 18f) * 0.22f; } Vector3 val3 = val2 - state.Visual.transform.position; val3.y = 0f; float magnitude = ((Vector3)(ref val3)).magnitude; if (!(((Vector3)(ref val3)).sqrMagnitude > 0.02f)) { return; } Vector3 normalized = ((Vector3)(ref val3)).normalized; Rigidbody mainRig = state.NativeUnit.data.mainRig; float num = (IsRangedStyle(state.Style) ? 8f : 2.4f); bool flag = magnitude > num + 0.35f; if ((Object)(object)mainRig != (Object)null) { Vector3 velocity = mainRig.velocity; float num2 = (flag ? 25f : 0.6f); Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(velocity.x, 0f, velocity.z); Vector3 val5 = (flag ? (normalized * num2) : Vector3.zero); Vector3 val6 = Vector3.MoveTowards(val4, val5, (flag ? 42f : 60f) * Time.unscaledDeltaTime); float num3 = Mathf.Clamp(velocity.y, -4.5f, 4.5f); mainRig.velocity = new Vector3(val6.x, num3, val6.z); if (flag) { Quaternion val7 = Quaternion.LookRotation(normalized, Vector3.up); mainRig.MoveRotation(Quaternion.Slerp(mainRig.rotation, val7, Time.unscaledDeltaTime * 10f)); } } if ((Object)(object)state.NativeUnit.api != (Object)null && (Object)(object)val.data.mainRig != (Object)null) { float num4 = (IsRangedStyle(state.Style) ? 8f : 2.8f); TargetData val8 = new TargetData { DistanceToTarget = magnitude, TargetInPreferredRange = ((magnitude <= num4) ? 1 : 0), TargetInAttackRange = ((magnitude <= Mathf.Max(3f, state.NativeUnit.m_AttackDistance + 3f)) ? 1 : 0) }; bool flag2 = magnitude <= Mathf.Max(6f, state.NativeUnit.m_AttackDistance + 3f); bool flag3 = !IsRangedStyle(state.Style); state.NativeUnit.api.SetAttackTarget(float3.op_Implicit(val.data.mainRig.position), val.data.mainRig, val.data, val8, flag2, flag3); if (flag3 && flag2) { state.AttackTimer = Mathf.Min(state.AttackTimer, 0.03f); } } } private static bool IsRangedStyle(AttackStyle style) { return style == AttackStyle.RangedHypercube || style == AttackStyle.RangedLance || style == AttackStyle.RangedNova; } private static void ConfigureNativeAnimator(Animator animator) { if ((Object)(object)animator == (Object)null) { return; } try { ((Behaviour)animator).enabled = true; animator.cullingMode = (AnimatorCullingMode)0; animator.updateMode = (AnimatorUpdateMode)0; animator.speed = 1f; animator.applyRootMotion = false; } catch { } } private static void UpdateNativeAnimator(State state) { Animator nativeAnimator = state.NativeAnimator; if ((Object)(object)nativeAnimator == (Object)null || ((Behaviour)nativeAnimator).enabled) { return; } try { ((Behaviour)nativeAnimator).enabled = true; } catch { } } private static void MaintainSafeGround(State state) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) if (state == null || (Object)(object)state.Visual == (Object)null || (Object)(object)state.NativeUnit == (Object)null || (Object)(object)state.NativeUnit.data == (Object)null) { return; } Vector3 position = state.Visual.transform.position; Rigidbody mainRig = state.NativeUnit.data.mainRig; RaycastHit val = default(RaycastHit); bool flag = Physics.SphereCast(position + Vector3.up * 1.4f, 0.42f, Vector3.down, ref val, 9f, -1, (QueryTriggerInteraction)1); if (flag && (Object)(object)((RaycastHit)(ref val)).collider != (Object)null && !IsProtected(((Component)((RaycastHit)(ref val)).collider).gameObject) && ((RaycastHit)(ref val)).normal.y > 0.25f) { state.LastSafePosition = position; state.LastSafeRotation = Quaternion.Euler(0f, state.Visual.transform.eulerAngles.y, 0f); state.HasSafeGround = true; state.AirborneTime = 0f; } else { state.AirborneTime += Time.unscaledDeltaTime; } if ((Object)(object)mainRig != (Object)null) { Vector3 velocity = mainRig.velocity; velocity.y = Mathf.Clamp(velocity.y, -4.5f, 4.5f); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(velocity.x, 0f, velocity.z); if (((Vector3)(ref val2)).sqrMagnitude > 484f) { val2 = ((Vector3)(ref val2)).normalized * 22f; } mainRig.velocity = new Vector3(val2.x, velocity.y, val2.z); mainRig.angularVelocity = Vector3.ClampMagnitude(mainRig.angularVelocity, 6f); } float num = (state.HasSafeGround ? (state.LastSafePosition.y - position.y) : 0f); float num2 = (state.HasSafeGround ? (position.y - state.LastSafePosition.y) : 0f); bool flag2 = position.y < -4f || (state.HasSafeGround && num > 2.75f); bool flag3 = state.HasSafeGround && num2 > 4.5f && state.AirborneTime > 0.08f; int num3; if (state.HasSafeGround) { Vector3 val3 = position - state.LastSafePosition; if (((Vector3)(ref val3)).sqrMagnitude > 100f) { num3 = ((state.AirborneTime > 0.12f) ? 1 : 0); goto IL_029e; } } num3 = 0; goto IL_029e; IL_029e: bool flag4 = (byte)num3 != 0; if (!(flag2 || flag3 || flag4) && (!state.HasSafeGround || !(state.AirborneTime > 0.75f) || flag)) { return; } BeginInternalMutation(); try { state.Visual.transform.SetPositionAndRotation(state.LastSafePosition, state.LastSafeRotation); if ((Object)(object)mainRig != (Object)null) { mainRig.position = state.LastSafePosition; mainRig.velocity = Vector3.zero; mainRig.angularVelocity = Vector3.zero; } state.AirborneTime = 0f; } finally { EndInternalMutation(); } } private static AttackStyle SelectCombatStyle(State state) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (state == null || (Object)(object)state.NativeUnit == (Object)null || (Object)(object)state.Visual == (Object)null) { return AttackStyle.MeleeBurst; } Unit val = FindNearestEnemy(state.Team, state.Visual.transform.position, 60f); if ((Object)(object)val == (Object)null || (Object)(object)val.data == (Object)null || (Object)(object)val.data.mainRig == (Object)null) { return AttackStyle.MeleeBurst; } float num = Vector3.Distance(state.Visual.transform.position, val.data.mainRig.position); if (num <= Mathf.Max(7.5f, state.NativeUnit.m_AttackDistance + 3.5f)) { return (Random.value < 0.82f) ? AttackStyle.MeleeBurst : AttackStyle.MeleeVortex; } float value = Random.value; if (value < 0.42f) { return AttackStyle.RangedHypercube; } if (value < 0.72f) { return AttackStyle.RangedLance; } return AttackStyle.RangedNova; } internal static bool ShouldBlockBattleControl() { return states.Any((State x) => x != null && x.Active && (Object)(object)x.Visual != (Object)null && IsBattleState()); } internal static bool IsCorrupted(Unit unit) { if ((Object)(object)unit == (Object)null || (Object)(object)((Component)unit).gameObject == (Object)null) { return false; } int instanceID = ((Object)((Component)unit).gameObject).GetInstanceID(); if (consumedUnitIds.Contains(instanceID)) { return true; } if ((Object)(object)((Component)unit).gameObject.GetComponent<V1NoiseCorruption>() != (Object)null) { return true; } if ((Object)(object)((Component)unit).gameObject.GetComponent<V1CorruptedMarker>() != (Object)null) { return true; } if ((Object)(object)((Component)unit).GetComponentInChildren<V1CorruptedMarker>(true) != (Object)null) { return true; } if (!((Component)unit).gameObject.activeInHierarchy && consumedUnitIds.Contains(instanceID)) { return true; } return HasKnownCorruptedSpawn(unit); } private static string BuildCorruptionKey(Unit unit) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected I4, but got Unknown if ((Object)(object)unit == (Object)null || (Object)(object)unit.unitBlueprint == (Object)null) { return null; } Vector3 position = ((Component)unit).transform.position; int num = Mathf.RoundToInt(position.x / 3f); int num2 = Mathf.RoundToInt(position.y / 3f); int num3 = Mathf.RoundToInt(position.z / 3f); return ((object)unit.unitBlueprint.Entity.GUID/*cast due to .constrained prefix*/).ToString() + "|" + (int)unit.Team + "|" + num + ":" + num2 + ":" + num3; } private static bool HasKnownCorruptedSpawn(Unit unit) { string text = BuildCorruptionKey(unit); return !string.IsNullOrEmpty(text) && corruptedSpawnKeys.Contains(text); } internal static Unit FindNearestEnemy(Team ownTeam, Vector3 origin, float radius) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) Unit[] array = Object.FindObjectsOfType<Unit>(); Unit result = null; float num = radius * radius; foreach (Unit val in array) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.data == (Object)null) && !val.data.Dead && val.Team != ownTeam && !IsCorrupted(val)) { Vector3 val2 = ((Component)val).transform.position - origin; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = val; } } } return result; } private static void TryAttack(State state) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) if (state.VortexActive || (Object)(object)state.NativeUnit == (Object)null || (Object)(object)state.NativeUnit.data == (Object)null) { return; } if ((Object)(object)state.PendingAttackTarget != (Object)null && IsCorrupted(state.PendingAttackTarget)) { state.PendingAttackTarget = null; } Unit val = FindNearestEnemy(state.Team, state.Visual.transform.position, 14f); if ((Object)(object)val == (Object)null || IsCorrupted(val)) { ClearNativeTarget(state); return; } state.PendingAttackTarget = val; float num = Vector3.Distance(state.Visual.transform.position, ((Component)val).transform.position); if (!IsRangedStyle(state.Style) && num <= Mathf.Max(6f, state.NativeUnit.m_AttackDistance + 3f)) { if ((Object)(object)state.NativeUnit.api != (Object)null && (Object)(object)val.data.mainRig != (Object)null) { TargetData val2 = new TargetData { DistanceToTarget = num, TargetInPreferredRange = ((num <= 2.8f) ? 1 : 0), TargetInAttackRange = 1 }; state.NativeUnit.api.SetAttackTarget(float3.op_Implicit(val.data.mainRig.position), val.data.mainRig, val.data, val2, true, true); } state.PendingAttackTarget = val; } else if (state.Style == AttackStyle.RangedHypercube || state.Style == AttackStyle.RangedLance || state.Style == AttackStyle.RangedNova) { SpawnSpecialRangedAttack(state, val); } } private static void SpawnSpecialRangedAttack(State state, Unit target) { if ((Object)(object)target == (Object)null) { return; } switch (state.Style) { case AttackStyle.RangedHypercube: { for (int i = 0; i < 3; i++) { SpawnDirectedHypercube(state, target, 0.38f + (float)i * 0.09f, (float)(i - 1) * 1.2f); } break; } case AttackStyle.RangedLance: SpawnEnergyLance(state, target); break; case AttackStyle.RangedNova: SpawnNova(state, target); break; } TriggerChromaticFlash(0.28f, 0.1f); } private static void SpawnDirectedHypercube(St