Decompiled source of Line Tool Lite v1.3.5
LineToolLite/0Harmony.dll
Decompiled 9 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using HarmonyLib.Internal.Patching; using HarmonyLib.Internal.RuntimeFixes; using HarmonyLib.Internal.Util; using HarmonyLib.Public.Patching; using HarmonyLib.Tools; using JetBrains.Annotations; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; using MonoMod.Cil; using MonoMod.RuntimeDetour; using MonoMod.Utils; using MonoMod.Utils.Cil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: ComVisible(false)] [assembly: InternalsVisibleTo("HarmonyTests")] [assembly: InternalsVisibleTo("MonoMod.Utils.Cil.ILGeneratorProxy")] [assembly: Guid("69aee16a-b6e7-4642-8081-3928b32455df")] [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] [assembly: AssemblyCompany("BepInEx")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © BepInEx 2022")] [assembly: AssemblyDescription("A library for patching, replacing and decorating .NET and Mono methods during runtime powered by MonoMod.")] [assembly: AssemblyFileVersion("2.10.2.0")] [assembly: AssemblyInformationalVersion("2.10.2")] [assembly: AssemblyProduct("HarmonyX")] [assembly: AssemblyTitle("0Harmony")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.10.2.0")] [module: UnverifiableCode] namespace System { internal struct ValueTuple<T1, T2> { public T1 Item1; public T2 Item2; public ValueTuple(T1 first, T2 second) { Item1 = first; Item2 = second; } } internal struct ValueTuple<T1, T2, T3> { public T1 Item1; public T2 Item2; public T3 Item3; public ValueTuple(T1 first, T2 second, T3 third) { Item1 = first; Item2 = second; Item3 = third; } } } namespace JetBrains.Annotations { [AttributeUsage(AttributeTargets.All)] internal sealed class UsedImplicitlyAttribute : Attribute { public ImplicitUseKindFlags UseKindFlags { get; } public ImplicitUseTargetFlags TargetFlags { get; } public UsedImplicitlyAttribute() : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) : this(useKindFlags, ImplicitUseTargetFlags.Default) { } public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) : this(ImplicitUseKindFlags.Default, targetFlags) { } public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) { UseKindFlags = useKindFlags; TargetFlags = targetFlags; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Parameter | AttributeTargets.GenericParameter)] internal sealed class MeansImplicitUseAttribute : Attribute { [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; } [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; } public MeansImplicitUseAttribute() : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) : this(useKindFlags, ImplicitUseTargetFlags.Default) { } public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) : this(ImplicitUseKindFlags.Default, targetFlags) { } public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) { UseKindFlags = useKindFlags; TargetFlags = targetFlags; } } [Flags] internal enum ImplicitUseKindFlags { Default = 7, Access = 1, Assign = 2, InstantiatedWithFixedConstructorSignature = 4, InstantiatedNoFixedConstructorSignature = 8 } [Flags] internal enum ImplicitUseTargetFlags { Default = 1, Itself = 1, Members = 2, WithInheritors = 4, WithMembers = 3 } } namespace HarmonyLib { public class DelegateTypeFactory { private class DelegateEntry { public CallingConvention? callingConvention; public Type delegateType; } private static int counter; private static readonly Dictionary<MethodInfo, List<DelegateEntry>> TypeCache = new Dictionary<MethodInfo, List<DelegateEntry>>(); private static readonly MethodBase CallingConvAttr = AccessTools.Constructor(typeof(UnmanagedFunctionPointerAttribute), new Type[1] { typeof(CallingConvention) }); public static readonly DelegateTypeFactory instance = new DelegateTypeFactory(); public Type CreateDelegateType(Type returnType, Type[] argTypes) { return CreateDelegateType(returnType, argTypes, null); } public Type CreateDelegateType(Type returnType, Type[] argTypes, CallingConvention? convention) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_0127: 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) //IL_0134: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown //IL_01a1: 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_01af: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00f1: Unknown result type (might be due to invalid IL or missing references) counter++; AssemblyDefinition val = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition($"HarmonyDTFAssembly{counter}", new Version(1, 0)), $"HarmonyDTFModule{counter}", (ModuleKind)0); ModuleDefinition module = val.MainModule; TypeDefinition val2 = new TypeDefinition("", $"HarmonyDTFType{counter}", (TypeAttributes)257) { BaseType = module.ImportReference(typeof(MulticastDelegate)) }; module.Types.Add(val2); if (convention.HasValue) { CustomAttribute val3 = new CustomAttribute(module.ImportReference(CallingConvAttr)); val3.ConstructorArguments.Add(new CustomAttributeArgument(module.ImportReference(typeof(CallingConvention)), (object)convention.Value)); val2.CustomAttributes.Add(val3); } MethodDefinition val4 = new MethodDefinition(".ctor", (MethodAttributes)4230, module.ImportReference(typeof(void))) { ImplAttributes = (MethodImplAttributes)3 }; Extensions.AddRange<ParameterDefinition>(((MethodReference)val4).Parameters, (IEnumerable<ParameterDefinition>)(object)new ParameterDefinition[2] { new ParameterDefinition(module.ImportReference(typeof(object))), new ParameterDefinition(module.ImportReference(typeof(IntPtr))) }); val2.Methods.Add(val4); MethodDefinition val5 = new MethodDefinition("Invoke", (MethodAttributes)198, module.ImportReference(returnType)) { ImplAttributes = (MethodImplAttributes)3 }; Extensions.AddRange<ParameterDefinition>(((MethodReference)val5).Parameters, ((IEnumerable<Type>)argTypes).Select((Func<Type, ParameterDefinition>)((Type t) => new ParameterDefinition(module.ImportReference(t))))); val2.Methods.Add(val5); return ReflectionHelper.Load(val.MainModule).GetType($"HarmonyDTFType{counter}"); } public Type CreateDelegateType(MethodInfo method) { return CreateDelegateType(method, null); } public Type CreateDelegateType(MethodInfo method, CallingConvention? convention) { DelegateEntry delegateEntry; if (TypeCache.TryGetValue(method, out var value) && (delegateEntry = value.FirstOrDefault((DelegateEntry e) => e.callingConvention == convention)) != null) { return delegateEntry.delegateType; } if (value == null) { value = (TypeCache[method] = new List<DelegateEntry>()); } delegateEntry = new DelegateEntry { delegateType = CreateDelegateType(method.ReturnType, method.GetParameters().Types().ToArray(), convention), callingConvention = convention }; value.Add(delegateEntry); return delegateEntry.delegateType; } } [Obsolete("Use AccessTools.FieldRefAccess<T, S> for fields and AccessTools.MethodDelegate<Func<T, S>> for property getters")] public delegate S GetterHandler<in T, out S>(T source); [Obsolete("Use AccessTools.FieldRefAccess<T, S> for fields and AccessTools.MethodDelegate<Action<T, S>> for property setters")] public delegate void SetterHandler<in T, in S>(T source, S value); public delegate T InstantiationHandler<out T>(); public static class FastAccess { public static InstantiationHandler<T> CreateInstantiationHandler<T>() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) ConstructorInfo constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], null); if ((object)constructor == null) { throw new ApplicationException($"The type {typeof(T)} must declare an empty constructor (the constructor may be private, internal, protected, protected internal, or public)."); } DynamicMethodDefinition val = new DynamicMethodDefinition("InstantiateObject_" + typeof(T).Name, typeof(T), (Type[])null); ILGenerator iLGenerator = val.GetILGenerator(); iLGenerator.Emit(OpCodes.Newobj, constructor); iLGenerator.Emit(OpCodes.Ret); return (InstantiationHandler<T>)val.Generate().CreateDelegate(typeof(InstantiationHandler<T>)); } [Obsolete("Use AccessTools.MethodDelegate<Func<T, S>>(PropertyInfo.GetGetMethod(true))")] public static GetterHandler<T, S> CreateGetterHandler<T, S>(PropertyInfo propertyInfo) { MethodInfo getMethod = propertyInfo.GetGetMethod(nonPublic: true); DynamicMethodDefinition obj = CreateGetDynamicMethod<T, S>(propertyInfo.DeclaringType); ILGenerator iLGenerator = obj.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Call, getMethod); iLGenerator.Emit(OpCodes.Ret); return (GetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(GetterHandler<T, S>)); } [Obsolete("Use AccessTools.FieldRefAccess<T, S>(fieldInfo)")] public static GetterHandler<T, S> CreateGetterHandler<T, S>(FieldInfo fieldInfo) { DynamicMethodDefinition obj = CreateGetDynamicMethod<T, S>(fieldInfo.DeclaringType); ILGenerator iLGenerator = obj.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldfld, fieldInfo); iLGenerator.Emit(OpCodes.Ret); return (GetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(GetterHandler<T, S>)); } [Obsolete("Use AccessTools.FieldRefAccess<T, S>(name) for fields and AccessTools.MethodDelegate<Func<T, S>>(AccessTools.PropertyGetter(typeof(T), name)) for properties")] public static GetterHandler<T, S> CreateFieldGetter<T, S>(params string[] names) { foreach (string name in names) { FieldInfo field = typeof(T).GetField(name, AccessTools.all); if ((object)field != null) { return CreateGetterHandler<T, S>(field); } PropertyInfo property = typeof(T).GetProperty(name, AccessTools.all); if ((object)property != null) { return CreateGetterHandler<T, S>(property); } } return null; } [Obsolete("Use AccessTools.MethodDelegate<Action<T, S>>(PropertyInfo.GetSetMethod(true))")] public static SetterHandler<T, S> CreateSetterHandler<T, S>(PropertyInfo propertyInfo) { MethodInfo setMethod = propertyInfo.GetSetMethod(nonPublic: true); DynamicMethodDefinition obj = CreateSetDynamicMethod<T, S>(propertyInfo.DeclaringType); ILGenerator iLGenerator = obj.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Call, setMethod); iLGenerator.Emit(OpCodes.Ret); return (SetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(SetterHandler<T, S>)); } [Obsolete("Use AccessTools.FieldRefAccess<T, S>(fieldInfo)")] public static SetterHandler<T, S> CreateSetterHandler<T, S>(FieldInfo fieldInfo) { DynamicMethodDefinition obj = CreateSetDynamicMethod<T, S>(fieldInfo.DeclaringType); ILGenerator iLGenerator = obj.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); iLGenerator.Emit(OpCodes.Stfld, fieldInfo); iLGenerator.Emit(OpCodes.Ret); return (SetterHandler<T, S>)obj.Generate().CreateDelegate(typeof(SetterHandler<T, S>)); } private static DynamicMethodDefinition CreateGetDynamicMethod<T, S>(Type type) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown return new DynamicMethodDefinition("DynamicGet_" + type.Name, typeof(S), new Type[1] { typeof(T) }); } private static DynamicMethodDefinition CreateSetDynamicMethod<T, S>(Type type) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown return new DynamicMethodDefinition("DynamicSet_" + type.Name, typeof(void), new Type[2] { typeof(T), typeof(S) }); } } public delegate object FastInvokeHandler(object target, params object[] parameters); public static class MethodInvoker { public static FastInvokeHandler GetHandler(MethodInfo methodInfo, bool directBoxValueAccess = false) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown DynamicMethodDefinition val = new DynamicMethodDefinition("FastInvoke_" + methodInfo.Name + "_" + (directBoxValueAccess ? "direct" : "indirect"), typeof(object), new Type[2] { typeof(object), typeof(object[]) }); ILGenerator iLGenerator = val.GetILGenerator(); if (!methodInfo.IsStatic) { Emit(iLGenerator, OpCodes.Ldarg_0); EmitUnboxIfNeeded(iLGenerator, methodInfo.DeclaringType); } bool flag = true; ParameterInfo[] parameters = methodInfo.GetParameters(); for (int i = 0; i < parameters.Length; i++) { Type type = parameters[i].ParameterType; bool isByRef = type.IsByRef; if (isByRef) { type = type.GetElementType(); } bool isValueType = type.IsValueType; if (isByRef && isValueType && !directBoxValueAccess) { Emit(iLGenerator, OpCodes.Ldarg_1); EmitFastInt(iLGenerator, i); } Emit(iLGenerator, OpCodes.Ldarg_1); EmitFastInt(iLGenerator, i); if (isByRef && !isValueType) { Emit(iLGenerator, OpCodes.Ldelema, typeof(object)); continue; } Emit(iLGenerator, OpCodes.Ldelem_Ref); if (!isValueType) { continue; } if (!isByRef || !directBoxValueAccess) { Emit(iLGenerator, OpCodes.Unbox_Any, type); if (isByRef) { Emit(iLGenerator, OpCodes.Box, type); Emit(iLGenerator, OpCodes.Dup); if (flag) { flag = false; iLGenerator.DeclareLocal(typeof(object), pinned: false); } Emit(iLGenerator, OpCodes.Stloc_0); Emit(iLGenerator, OpCodes.Stelem_Ref); Emit(iLGenerator, OpCodes.Ldloc_0); Emit(iLGenerator, OpCodes.Unbox, type); } } else { Emit(iLGenerator, OpCodes.Unbox, type); } } if (methodInfo.IsStatic) { EmitCall(iLGenerator, OpCodes.Call, methodInfo); } else { EmitCall(iLGenerator, OpCodes.Callvirt, methodInfo); } if (methodInfo.ReturnType == typeof(void)) { Emit(iLGenerator, OpCodes.Ldnull); } else { EmitBoxIfNeeded(iLGenerator, methodInfo.ReturnType); } Emit(iLGenerator, OpCodes.Ret); return (FastInvokeHandler)val.Generate().CreateDelegate(typeof(FastInvokeHandler)); } internal static void Emit(ILGenerator il, OpCode opcode) { il.Emit(opcode); } internal static void Emit(ILGenerator il, OpCode opcode, Type type) { il.Emit(opcode, type); } internal static void EmitCall(ILGenerator il, OpCode opcode, MethodInfo methodInfo) { il.EmitCall(opcode, methodInfo, null); } private static void EmitUnboxIfNeeded(ILGenerator il, Type type) { if (type.IsValueType) { Emit(il, OpCodes.Unbox_Any, type); } } private static void EmitBoxIfNeeded(ILGenerator il, Type type) { if (type.IsValueType) { Emit(il, OpCodes.Box, type); } } internal static void EmitFastInt(ILGenerator il, int value) { switch (value) { case -1: il.Emit(OpCodes.Ldc_I4_M1); return; case 0: il.Emit(OpCodes.Ldc_I4_0); return; case 1: il.Emit(OpCodes.Ldc_I4_1); return; case 2: il.Emit(OpCodes.Ldc_I4_2); return; case 3: il.Emit(OpCodes.Ldc_I4_3); return; case 4: il.Emit(OpCodes.Ldc_I4_4); return; case 5: il.Emit(OpCodes.Ldc_I4_5); return; case 6: il.Emit(OpCodes.Ldc_I4_6); return; case 7: il.Emit(OpCodes.Ldc_I4_7); return; case 8: il.Emit(OpCodes.Ldc_I4_8); return; } if (value > -129 && value < 128) { il.Emit(OpCodes.Ldc_I4_S, (sbyte)value); } else { il.Emit(OpCodes.Ldc_I4, value); } } } internal class AccessCache { internal enum MemberType { Any, Static, Instance } private const BindingFlags BasicFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty; private static readonly Dictionary<MemberType, BindingFlags> declaredOnlyBindingFlags = new Dictionary<MemberType, BindingFlags> { { MemberType.Any, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty }, { MemberType.Instance, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty }, { MemberType.Static, BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty } }; private readonly Dictionary<Type, Dictionary<string, FieldInfo>> declaredFields = new Dictionary<Type, Dictionary<string, FieldInfo>>(); private readonly Dictionary<Type, Dictionary<string, PropertyInfo>> declaredProperties = new Dictionary<Type, Dictionary<string, PropertyInfo>>(); private readonly Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>> declaredMethods = new Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>>(); private readonly Dictionary<Type, Dictionary<string, FieldInfo>> inheritedFields = new Dictionary<Type, Dictionary<string, FieldInfo>>(); private readonly Dictionary<Type, Dictionary<string, PropertyInfo>> inheritedProperties = new Dictionary<Type, Dictionary<string, PropertyInfo>>(); private readonly Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>> inheritedMethods = new Dictionary<Type, Dictionary<string, Dictionary<int, MethodBase>>>(); private static T Get<T>(Dictionary<Type, Dictionary<string, T>> dict, Type type, string name, Func<T> fetcher) { lock (dict) { if (!dict.TryGetValue(type, out var value)) { value = (dict[type] = new Dictionary<string, T>()); } if (!value.TryGetValue(name, out var value2)) { value2 = (value[name] = fetcher()); } return value2; } } private static T Get<T>(Dictionary<Type, Dictionary<string, Dictionary<int, T>>> dict, Type type, string name, Type[] arguments, Func<T> fetcher) { lock (dict) { if (!dict.TryGetValue(type, out var value)) { value = (dict[type] = new Dictionary<string, Dictionary<int, T>>()); } if (!value.TryGetValue(name, out var value2)) { value2 = (value[name] = new Dictionary<int, T>()); } int key = AccessTools.CombinedHashCode(arguments); if (!value2.TryGetValue(key, out var value3)) { value3 = (value2[key] = fetcher()); } return value3; } } internal FieldInfo GetFieldInfo(Type type, string name, MemberType memberType = MemberType.Any, bool declaredOnly = false) { FieldInfo fieldInfo = Get(declaredFields, type, name, () => type.GetField(name, declaredOnlyBindingFlags[memberType])); if ((object)fieldInfo == null && !declaredOnly) { fieldInfo = Get(inheritedFields, type, name, () => AccessTools.FindIncludingBaseTypes(type, (Type t) => t.GetField(name, AccessTools.all))); } return fieldInfo; } internal PropertyInfo GetPropertyInfo(Type type, string name, MemberType memberType = MemberType.Any, bool declaredOnly = false) { PropertyInfo propertyInfo = Get(declaredProperties, type, name, () => type.GetProperty(name, declaredOnlyBindingFlags[memberType])); if ((object)propertyInfo == null && !declaredOnly) { propertyInfo = Get(inheritedProperties, type, name, () => AccessTools.FindIncludingBaseTypes(type, (Type t) => t.GetProperty(name, AccessTools.all))); } return propertyInfo; } internal MethodBase GetMethodInfo(Type type, string name, Type[] arguments, MemberType memberType = MemberType.Any, bool declaredOnly = false) { MethodBase methodBase = Get(declaredMethods, type, name, arguments, () => type.GetMethod(name, declaredOnlyBindingFlags[memberType], null, arguments, null)); if ((object)methodBase == null && !declaredOnly) { methodBase = Get(inheritedMethods, type, name, arguments, () => AccessTools.Method(type, name, arguments)); } return methodBase; } } internal static class PatchArgumentExtensions { private static HarmonyArgument[] AllHarmonyArguments(object[] attributes) { return (from attr in attributes select (attr.GetType().Name != "HarmonyArgument") ? null : AccessTools.MakeDeepCopy<HarmonyArgument>(attr) into harg where harg != null select harg).ToArray(); } private static HarmonyArgument GetArgumentAttribute(this ParameterInfo parameter) { return AllHarmonyArguments(parameter.GetCustomAttributes(inherit: false)).FirstOrDefault(); } private static HarmonyArgument[] GetArgumentAttributes(this MethodInfo method) { if ((object)method == null || method is DynamicMethod) { return null; } return AllHarmonyArguments(method.GetCustomAttributes(inherit: false)); } private static HarmonyArgument[] GetArgumentAttributes(this Type type) { return AllHarmonyArguments(type.GetCustomAttributes(inherit: false)); } private static string GetOriginalArgumentName(this ParameterInfo parameter, string[] originalParameterNames) { HarmonyArgument argumentAttribute = parameter.GetArgumentAttribute(); if (argumentAttribute == null) { return null; } if (!string.IsNullOrEmpty(argumentAttribute.OriginalName)) { return argumentAttribute.OriginalName; } if (argumentAttribute.Index >= 0 && argumentAttribute.Index < originalParameterNames.Length) { return originalParameterNames[argumentAttribute.Index]; } return null; } private static string GetOriginalArgumentName(HarmonyArgument[] attributes, string name, string[] originalParameterNames) { if (((attributes != null && attributes.Length != 0) ? 1 : 0) <= (false ? 1 : 0)) { return null; } HarmonyArgument harmonyArgument = attributes.SingleOrDefault((HarmonyArgument p) => p.NewName == name); if (harmonyArgument == null) { return null; } if (!string.IsNullOrEmpty(harmonyArgument.OriginalName)) { return harmonyArgument.OriginalName; } if (originalParameterNames != null && harmonyArgument.Index >= 0 && harmonyArgument.Index < originalParameterNames.Length) { return originalParameterNames[harmonyArgument.Index]; } return null; } private static string GetOriginalArgumentName(this MethodInfo method, string[] originalParameterNames, string name) { string originalArgumentName = GetOriginalArgumentName(((object)method != null) ? method.GetArgumentAttributes() : null, name, originalParameterNames); if (originalArgumentName != null) { return originalArgumentName; } object attributes; if ((object)method == null) { attributes = null; } else { Type? declaringType = method.DeclaringType; attributes = (((object)declaringType != null) ? declaringType.GetArgumentAttributes() : null); } originalArgumentName = GetOriginalArgumentName((HarmonyArgument[])attributes, name, originalParameterNames); if (originalArgumentName != null) { return originalArgumentName; } return name; } internal static int GetArgumentIndex(this MethodInfo patch, string[] originalParameterNames, ParameterInfo patchParam) { if (patch is DynamicMethod) { return Array.IndexOf<string>(originalParameterNames, patchParam.Name); } string originalArgumentName = patchParam.GetOriginalArgumentName(originalParameterNames); if (originalArgumentName != null) { return Array.IndexOf(originalParameterNames, originalArgumentName); } originalArgumentName = patch.GetOriginalArgumentName(originalParameterNames, patchParam.Name); if (originalArgumentName != null) { return Array.IndexOf(originalParameterNames, originalArgumentName); } return -1; } } internal static class PatchFunctions { internal static List<MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches, bool debug) { return new PatchSorter(patches, debug).Sort(original); } internal static Patch[] GetSortedPatchMethodsAsPatches(MethodBase original, Patch[] patches, bool debug) { return new PatchSorter(patches, debug).SortAsPatches(original); } internal static MethodInfo UpdateWrapper(MethodBase original, PatchInfo patchInfo) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown MethodPatcher methodPatcher = original.GetMethodPatcher(); DynamicMethodDefinition val = methodPatcher.PrepareOriginal(); if (val != null) { ILContext ctx = new ILContext(val.Definition); HarmonyManipulator.Manipulate(original, patchInfo, ctx); } try { return methodPatcher.DetourTo((val != null) ? val.Generate() : null) as MethodInfo; } catch (Exception ex) { object body; if (val == null) { body = null; } else { MethodDefinition definition = val.Definition; body = ((definition != null) ? definition.Body : null); } throw HarmonyException.Create(ex, (MethodBody)body); } } internal static MethodInfo ReversePatch(HarmonyMethod standin, MethodBase original, MethodInfo postTranspiler, MethodInfo postManipulator) { //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0169: 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_017e: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Expected O, but got Unknown if (standin == null) { throw new ArgumentNullException("standin"); } if ((object)standin.method == null) { throw new ArgumentNullException("standin", "standin.method is NULL"); } if (!standin.method.IsStatic) { throw new ArgumentException("standin", "standin.method is not static"); } bool debug = standin.debug.GetValueOrDefault(); List<MethodInfo> transpilers = new List<MethodInfo>(); List<MethodInfo> ilmanipulators = new List<MethodInfo>(); if (standin.reversePatchType == HarmonyReversePatchType.Snapshot) { Patches patchInfo = Harmony.GetPatchInfo(original); transpilers.AddRange(GetSortedPatchMethods(original, patchInfo.Transpilers.ToArray(), debug)); ilmanipulators.AddRange(GetSortedPatchMethods(original, patchInfo.ILManipulators.ToArray(), debug)); } if ((object)postTranspiler != null) { transpilers.Add(postTranspiler); } if ((object)postManipulator != null) { ilmanipulators.Add(postManipulator); } Logger.Log(Logger.LogChannel.Info, delegate { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Reverse patching " + standin.method.FullDescription() + " with " + original.FullDescription()); PrintInfo(stringBuilder, transpilers, "Transpiler"); PrintInfo(stringBuilder, ilmanipulators, "Manipulators"); return stringBuilder.ToString(); }, debug); MethodBody patchBody = null; ILHook val = new ILHook((MethodBase)standin.method, (Manipulator)delegate(ILContext ctx) { //IL_00b8: 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) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) if (original is MethodInfo methodInfo2) { patchBody = ctx.Body; MethodPatcher methodPatcher = methodInfo2.GetMethodPatcher(); DynamicMethodDefinition val2 = methodPatcher.CopyOriginal(); if (val2 == null) { throw new NullReferenceException("Cannot reverse patch " + methodInfo2.FullDescription() + ": method patcher (" + methodPatcher.GetType().FullDescription() + ") can't copy original method body"); } ILManipulator iLManipulator = new ILManipulator(val2.Definition.Body, debug); ctx.Body.Variables.Clear(); Enumerator<VariableDefinition> enumerator2 = iLManipulator.Body.Variables.GetEnumerator(); try { while (enumerator2.MoveNext()) { VariableDefinition current2 = enumerator2.Current; ctx.Body.Variables.Add(new VariableDefinition(ctx.Module.ImportReference(((VariableReference)current2).VariableType))); } } finally { ((IDisposable)enumerator2).Dispose(); } foreach (MethodInfo item in transpilers) { iLManipulator.AddTranspiler(item); } iLManipulator.WriteTo(ctx.Body, standin.method); HarmonyManipulator.ApplyManipulators(ctx, original, ilmanipulators, null); Instruction val3 = null; foreach (Instruction item2 in ((IEnumerable<Instruction>)ctx.Instrs).Where((Instruction i) => i.OpCode == OpCodes.Ret)) { if (val3 == null) { val3 = ctx.IL.Create(OpCodes.Ret); } item2.OpCode = OpCodes.Br; item2.Operand = val3; } if (val3 != null) { ctx.IL.Append(val3); } Logger.Log(Logger.LogChannel.IL, () => "Generated reverse patcher (" + ((MemberReference)ctx.Method).FullName + "):\n" + ctx.Body.ToILDasmString(), debug); } }, new ILHookConfig { ManualApply = true }); try { val.Apply(); } catch (Exception ex) { throw HarmonyException.Create(ex, patchBody); } MethodInfo methodInfo = val.GetCurrentTarget() as MethodInfo; PatchTools.RememberObject(standin.method, methodInfo); return methodInfo; static void PrintInfo(StringBuilder sb, ICollection<MethodInfo> methods, string name) { if (methods.Count <= 0) { return; } sb.AppendLine(name + ":"); foreach (MethodInfo method in methods) { sb.AppendLine(" * " + method.FullDescription()); } } } internal static IEnumerable<CodeInstruction> ApplyTranspilers(MethodBase methodBase, ILGenerator generator, int maxTranspilers = 0) { MethodPatcher methodPatcher = methodBase.GetMethodPatcher(); DynamicMethodDefinition val = methodPatcher.CopyOriginal(); if (val == null) { throw new NullReferenceException("Cannot reverse patch " + methodBase.FullDescription() + ": method patcher (" + methodPatcher.GetType().FullDescription() + ") can't copy original method body"); } ILManipulator iLManipulator = new ILManipulator(val.Definition.Body, debug: false); PatchInfo patchInfo = methodBase.GetPatchInfo(); if (patchInfo != null) { List<MethodInfo> sortedPatchMethods = GetSortedPatchMethods(methodBase, patchInfo.transpilers, debug: false); for (int i = 0; i < maxTranspilers && i < sortedPatchMethods.Count; i++) { iLManipulator.AddTranspiler(sortedPatchMethods[i]); } } return iLManipulator.GetInstructions(generator, methodBase); } internal static void UnpatchConditional(Func<Patch, bool> executionCondition) { foreach (MethodBase item in PatchProcessor.GetAllPatchedMethods().ToList()) { bool num = item.HasMethodBody(); Patches patchInfo2 = PatchProcessor.GetPatchInfo(item); PatchProcessor patchProcessor = new PatchProcessor(null, item); if (num) { patchInfo2.Postfixes.DoIf(executionCondition, delegate(Patch patchInfo) { patchProcessor.Unpatch(patchInfo.PatchMethod); }); patchInfo2.Prefixes.DoIf(executionCondition, delegate(Patch patchInfo) { patchProcessor.Unpatch(patchInfo.PatchMethod); }); } patchInfo2.ILManipulators.DoIf(executionCondition, delegate(Patch patchInfo) { patchProcessor.Unpatch(patchInfo.PatchMethod); }); patchInfo2.Transpilers.DoIf(executionCondition, delegate(Patch patchInfo) { patchProcessor.Unpatch(patchInfo.PatchMethod); }); if (num) { patchInfo2.Finalizers.DoIf(executionCondition, delegate(Patch patchInfo) { patchProcessor.Unpatch(patchInfo.PatchMethod); }); } } } } internal class PatchJobs<T> { internal class Job { internal MethodBase original; internal T replacement; internal List<HarmonyMethod> prefixes = new List<HarmonyMethod>(); internal List<HarmonyMethod> postfixes = new List<HarmonyMethod>(); internal List<HarmonyMethod> transpilers = new List<HarmonyMethod>(); internal List<HarmonyMethod> finalizers = new List<HarmonyMethod>(); internal List<HarmonyMethod> ilmanipulators = new List<HarmonyMethod>(); internal void AddPatch(AttributePatch patch) { HarmonyPatchType? type = patch.type; if (type.HasValue) { switch (type.GetValueOrDefault()) { case HarmonyPatchType.Prefix: prefixes.Add(patch.info); break; case HarmonyPatchType.Postfix: postfixes.Add(patch.info); break; case HarmonyPatchType.Transpiler: transpilers.Add(patch.info); break; case HarmonyPatchType.Finalizer: finalizers.Add(patch.info); break; case HarmonyPatchType.ILManipulator: ilmanipulators.Add(patch.info); break; case HarmonyPatchType.ReversePatch: break; } } } } internal Dictionary<MethodBase, Job> state = new Dictionary<MethodBase, Job>(); internal Job GetJob(MethodBase method) { if ((object)method == null) { return null; } if (!state.TryGetValue(method, out var value)) { value = new Job { original = method }; state[method] = value; } return value; } internal List<Job> GetJobs() { return state.Values.Where((Job job) => job.prefixes.Count + job.postfixes.Count + job.transpilers.Count + job.finalizers.Count + job.ilmanipulators.Count > 0).ToList(); } internal List<T> GetReplacements() { return state.Values.Select((Job job) => job.replacement).ToList(); } } internal class AttributePatch { private static readonly HarmonyPatchType[] allPatchTypes = new HarmonyPatchType[6] { HarmonyPatchType.Prefix, HarmonyPatchType.Postfix, HarmonyPatchType.Transpiler, HarmonyPatchType.Finalizer, HarmonyPatchType.ReversePatch, HarmonyPatchType.ILManipulator }; internal HarmonyMethod info; internal HarmonyPatchType? type; private static readonly string harmonyAttributeName = typeof(HarmonyAttribute).FullName; internal static IEnumerable<AttributePatch> Create(MethodInfo patch, bool collectIncomplete = false) { if ((object)patch == null) { throw new NullReferenceException("Patch method cannot be null"); } object[] customAttributes = patch.GetCustomAttributes(inherit: true); string name = patch.Name; HarmonyPatchType? type = GetPatchType(name, customAttributes); if (!type.HasValue) { return Enumerable.Empty<AttributePatch>(); } if (type != HarmonyPatchType.ReversePatch && !patch.IsStatic) { throw new ArgumentException("Patch method " + patch.FullDescription() + " must be static"); } List<HarmonyMethod> list = (from attr in customAttributes where attr.GetType().BaseType.FullName == harmonyAttributeName select AccessTools.Field(attr.GetType(), "info").GetValue(attr) into harmonyInfo select AccessTools.MakeDeepCopy<HarmonyMethod>(harmonyInfo)).ToList(); List<HarmonyMethod> list2 = new List<HarmonyMethod>(); ILookup<bool, HarmonyMethod> lookup = list.ToLookup((HarmonyMethod m) => IsComplete(m, collectIncomplete)); List<HarmonyMethod> incomplete = lookup[false].ToList(); HarmonyMethod info = HarmonyMethod.Merge(incomplete); List<HarmonyMethod> list3 = lookup[true].Where((HarmonyMethod m) => !Same(m, info)).ToList(); if (list3.Count > 1) { list2.AddRange(list3.Select((HarmonyMethod m) => HarmonyMethod.Merge(incomplete.AddItem(m)))); } else { list2.Add(HarmonyMethod.Merge(list)); } foreach (HarmonyMethod item in list2) { item.method = patch; } return list2.Select((HarmonyMethod i) => new AttributePatch { info = i, type = type }).ToList(); static bool IsComplete(HarmonyMethod m, bool collectIncomplete) { if (collectIncomplete || m.GetDeclaringType() != null) { return m.methodName != null; } return false; } static bool Same(HarmonyMethod m1, HarmonyMethod m2) { if (m1.GetDeclaringType() == m2.GetDeclaringType() && m1.methodName == m2.methodName) { return m1.GetArgumentList().SequenceEqual(m2.GetArgumentList()); } return false; } } private static HarmonyPatchType? GetPatchType(string methodName, object[] allAttributes) { HashSet<string> hashSet = new HashSet<string>(from attr in allAttributes select attr.GetType().FullName into name where name.StartsWith("Harmony") select name); HarmonyPatchType? result = null; HarmonyPatchType[] array = allPatchTypes; for (int i = 0; i < array.Length; i++) { HarmonyPatchType value = array[i]; string text = value.ToString(); if (text == methodName || hashSet.Contains("HarmonyLib.Harmony" + text)) { result = value; break; } } return result; } } internal class PatchSorter { private class PatchSortingWrapper : IComparable { internal readonly HashSet<PatchSortingWrapper> after; internal readonly HashSet<PatchSortingWrapper> before; internal readonly Patch innerPatch; internal PatchSortingWrapper(Patch patch) { innerPatch = patch; before = new HashSet<PatchSortingWrapper>(); after = new HashSet<PatchSortingWrapper>(); } public int CompareTo(object obj) { return PatchInfoSerialization.PriorityComparer((obj as PatchSortingWrapper)?.innerPatch, innerPatch.index, innerPatch.priority); } public override bool Equals(object obj) { if (obj is PatchSortingWrapper patchSortingWrapper) { return innerPatch.PatchMethod == patchSortingWrapper.innerPatch.PatchMethod; } return false; } public override int GetHashCode() { return innerPatch.PatchMethod.GetHashCode(); } internal void AddBeforeDependency(IEnumerable<PatchSortingWrapper> dependencies) { foreach (PatchSortingWrapper dependency in dependencies) { before.Add(dependency); dependency.after.Add(this); } } internal void AddAfterDependency(IEnumerable<PatchSortingWrapper> dependencies) { foreach (PatchSortingWrapper dependency in dependencies) { after.Add(dependency); dependency.before.Add(this); } } internal void RemoveAfterDependency(PatchSortingWrapper afterNode) { after.Remove(afterNode); afterNode.before.Remove(this); } internal void RemoveBeforeDependency(PatchSortingWrapper beforeNode) { before.Remove(beforeNode); beforeNode.after.Remove(this); } } internal class PatchDetailedComparer : IEqualityComparer<Patch> { public bool Equals(Patch x, Patch y) { if (y != null && x != null && x.owner == y.owner && x.PatchMethod == y.PatchMethod && x.index == y.index && x.priority == y.priority && x.before.Length == y.before.Length && x.after.Length == y.after.Length && x.before.All(((IEnumerable<string>)y.before).Contains<string>)) { return x.after.All(((IEnumerable<string>)y.after).Contains<string>); } return false; } public int GetHashCode(Patch obj) { return obj.GetHashCode(); } } private List<PatchSortingWrapper> patches; private HashSet<PatchSortingWrapper> handledPatches; private List<PatchSortingWrapper> result; private List<PatchSortingWrapper> waitingList; internal Patch[] sortedPatchArray; private readonly bool debug; internal PatchSorter(Patch[] patches, bool debug = false) { this.patches = patches.Select((Patch x) => new PatchSortingWrapper(x)).ToList(); this.debug = debug; foreach (PatchSortingWrapper node in this.patches) { node.AddBeforeDependency(this.patches.Where((PatchSortingWrapper x) => node.innerPatch.before.Contains(x.innerPatch.owner))); node.AddAfterDependency(this.patches.Where((PatchSortingWrapper x) => node.innerPatch.after.Contains(x.innerPatch.owner))); } this.patches.Sort(); } internal List<MethodInfo> Sort(MethodBase original) { return (from x in SortAsPatches(original) select x.GetMethod(original)).ToList(); } internal Patch[] SortAsPatches(MethodBase original) { if (sortedPatchArray != null) { return sortedPatchArray; } handledPatches = new HashSet<PatchSortingWrapper>(); waitingList = new List<PatchSortingWrapper>(); result = new List<PatchSortingWrapper>(patches.Count); Queue<PatchSortingWrapper> queue = new Queue<PatchSortingWrapper>(patches); while (queue.Count != 0) { foreach (PatchSortingWrapper item in queue) { if (item.after.All((PatchSortingWrapper x) => handledPatches.Contains(x))) { AddNodeToResult(item); if (item.before.Count != 0) { ProcessWaitingList(); } } else { waitingList.Add(item); } } CullDependency(); queue = new Queue<PatchSortingWrapper>(waitingList); waitingList.Clear(); } sortedPatchArray = result.Select((PatchSortingWrapper x) => x.innerPatch).ToArray(); handledPatches = null; waitingList = null; patches = null; return sortedPatchArray; } internal bool ComparePatchLists(Patch[] patches) { if (sortedPatchArray == null) { Sort(null); } if (patches != null && sortedPatchArray.Length == patches.Length) { return sortedPatchArray.All((Patch x) => patches.Contains(x, new PatchDetailedComparer())); } return false; } private void CullDependency() { for (int i = waitingList.Count - 1; i >= 0; i--) { foreach (PatchSortingWrapper afterNode in waitingList[i].after) { if (!handledPatches.Contains(afterNode)) { waitingList[i].RemoveAfterDependency(afterNode); Logger.Log(Logger.LogChannel.Debug, delegate { string text = afterNode.innerPatch.PatchMethod.FullDescription(); string text2 = waitingList[i].innerPatch.PatchMethod.FullDescription(); return "Breaking dependence between " + text + " and " + text2; }, debug); return; } } } } private void ProcessWaitingList() { int num = waitingList.Count; int num2 = 0; while (num2 < num) { PatchSortingWrapper patchSortingWrapper = waitingList[num2]; if (patchSortingWrapper.after.All(handledPatches.Contains)) { waitingList.Remove(patchSortingWrapper); AddNodeToResult(patchSortingWrapper); num--; num2 = 0; } else { num2++; } } } private void AddNodeToResult(PatchSortingWrapper node) { result.Add(node); handledPatches.Add(node); } } internal static class PatchTools { [ThreadStatic] private static Dictionary<object, object> objectReferences; internal static void RememberObject(object key, object value) { if (objectReferences == null) { objectReferences = new Dictionary<object, object>(); } objectReferences[key] = value; } internal static MethodInfo GetPatchMethod(Type patchType, string attributeName) { MethodInfo methodInfo = patchType.GetMethods(AccessTools.all).FirstOrDefault((MethodInfo m) => m.GetCustomAttributes(inherit: true).Any((object a) => a.GetType().FullName == attributeName)); if ((object)methodInfo == null) { string name = attributeName.Replace("HarmonyLib.Harmony", ""); methodInfo = patchType.GetMethod(name, AccessTools.all); } return methodInfo; } internal static AssemblyBuilder DefineDynamicAssembly(string name) { AssemblyName assemblyName = new AssemblyName(name); return AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); } internal static List<AttributePatch> GetPatchMethods(Type type, bool collectIncomplete = false) { return (from attributePatch in AccessTools.GetDeclaredMethods(type).SelectMany((MethodInfo m) => AttributePatch.Create(m, collectIncomplete)) where attributePatch != null select attributePatch).ToList(); } internal static MethodBase GetOriginalMethod(this HarmonyMethod attr) { try { MethodType? methodType = attr.methodType; if (methodType.HasValue) { switch (methodType.GetValueOrDefault()) { case MethodType.Normal: if (attr.methodName == null) { return null; } return AccessTools.DeclaredMethod(attr.GetDeclaringType(), attr.methodName, attr.argumentTypes); case MethodType.Getter: if (attr.methodName == null) { return null; } return AccessTools.DeclaredProperty(attr.GetDeclaringType(), attr.methodName).GetGetMethod(nonPublic: true); case MethodType.Setter: if (attr.methodName == null) { return null; } return AccessTools.DeclaredProperty(attr.GetDeclaringType(), attr.methodName).GetSetMethod(nonPublic: true); case MethodType.Constructor: return AccessTools.DeclaredConstructor(attr.GetDeclaringType(), attr.argumentTypes); case MethodType.StaticConstructor: return AccessTools.GetDeclaredConstructors(attr.GetDeclaringType()).FirstOrDefault((ConstructorInfo c) => c.IsStatic); case MethodType.Enumerator: if (attr.methodName == null) { return null; } return AccessTools.EnumeratorMoveNext(AccessTools.DeclaredMethod(attr.GetDeclaringType(), attr.methodName, attr.argumentTypes)); } } } catch (AmbiguousMatchException ex) { throw new HarmonyException("Ambiguous match for HarmonyMethod[" + attr.Description() + "]", ex.InnerException ?? ex); } return null; } } public enum MethodType { Normal, Getter, Setter, Constructor, StaticConstructor, Enumerator } public enum ArgumentType { Normal, Ref, Out, Pointer } public enum HarmonyPatchType { All, Prefix, Postfix, Transpiler, Finalizer, ReversePatch, ILManipulator } public enum HarmonyReversePatchType { Original, Snapshot } public enum MethodDispatchType { VirtualCall, Call } [MeansImplicitUse] public class HarmonyAttribute : Attribute { public HarmonyMethod info = new HarmonyMethod(); } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Delegate, AllowMultiple = true)] public class HarmonyPatch : HarmonyAttribute { public HarmonyPatch() { } public HarmonyPatch(Type declaringType) { info.declaringType = declaringType; } public HarmonyPatch(Type declaringType, Type[] argumentTypes) { info.declaringType = declaringType; info.argumentTypes = argumentTypes; } public HarmonyPatch(Type declaringType, string methodName) { info.declaringType = declaringType; info.methodName = methodName; } public HarmonyPatch(Type declaringType, string methodName, params Type[] argumentTypes) { info.declaringType = declaringType; info.methodName = methodName; info.argumentTypes = argumentTypes; } public HarmonyPatch(Type declaringType, string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations) { info.declaringType = declaringType; info.methodName = methodName; ParseSpecialArguments(argumentTypes, argumentVariations); } public HarmonyPatch(string typeName, string methodName) { info.declaringType = AccessTools.TypeByName(typeName); info.methodName = methodName; } public HarmonyPatch(string typeName, string methodName, MethodType methodType, Type[] argumentTypes = null, ArgumentType[] argumentVariations = null) { info.declaringType = AccessTools.TypeByName(typeName); info.methodName = methodName; info.methodType = methodType; if (argumentTypes != null) { ParseSpecialArguments(argumentTypes, argumentVariations); } } public HarmonyPatch(Type declaringType, MethodType methodType) { info.declaringType = declaringType; info.methodType = methodType; } public HarmonyPatch(Type declaringType, MethodType methodType, params Type[] argumentTypes) { info.declaringType = declaringType; info.methodType = methodType; info.argumentTypes = argumentTypes; } public HarmonyPatch(Type declaringType, MethodType methodType, Type[] argumentTypes, ArgumentType[] argumentVariations) { info.declaringType = declaringType; info.methodType = methodType; ParseSpecialArguments(argumentTypes, argumentVariations); } public HarmonyPatch(Type declaringType, string methodName, MethodType methodType) { info.declaringType = declaringType; info.methodName = methodName; info.methodType = methodType; } public HarmonyPatch(string methodName) { info.methodName = methodName; } public HarmonyPatch(string methodName, params Type[] argumentTypes) { info.methodName = methodName; info.argumentTypes = argumentTypes; } public HarmonyPatch(string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations) { info.methodName = methodName; ParseSpecialArguments(argumentTypes, argumentVariations); } public HarmonyPatch(string methodName, MethodType methodType) { info.methodName = methodName; info.methodType = methodType; } public HarmonyPatch(MethodType methodType) { info.methodType = methodType; } public HarmonyPatch(MethodType methodType, params Type[] argumentTypes) { info.methodType = methodType; info.argumentTypes = argumentTypes; } public HarmonyPatch(MethodType methodType, Type[] argumentTypes, ArgumentType[] argumentVariations) { info.methodType = methodType; ParseSpecialArguments(argumentTypes, argumentVariations); } public HarmonyPatch(Type[] argumentTypes) { info.argumentTypes = argumentTypes; } public HarmonyPatch(Type[] argumentTypes, ArgumentType[] argumentVariations) { ParseSpecialArguments(argumentTypes, argumentVariations); } public HarmonyPatch(string typeName, string methodName, MethodType methodType = MethodType.Normal) { info.declaringType = AccessTools.TypeByName(typeName); info.methodName = methodName; info.methodType = methodType; } private void ParseSpecialArguments(Type[] argumentTypes, ArgumentType[] argumentVariations) { if (argumentVariations == null || argumentVariations.Length == 0) { info.argumentTypes = argumentTypes; return; } if (argumentTypes.Length < argumentVariations.Length) { throw new ArgumentException("argumentVariations contains more elements than argumentTypes", "argumentVariations"); } List<Type> list = new List<Type>(); for (int i = 0; i < argumentTypes.Length; i++) { Type type = argumentTypes[i]; switch (argumentVariations[i]) { case ArgumentType.Ref: case ArgumentType.Out: type = type.MakeByRefType(); break; case ArgumentType.Pointer: type = type.MakePointerType(); break; } list.Add(type); } info.argumentTypes = list.ToArray(); } } [AttributeUsage(AttributeTargets.Delegate, AllowMultiple = true)] public class HarmonyDelegate : HarmonyPatch { public HarmonyDelegate(Type declaringType) : base(declaringType) { } public HarmonyDelegate(Type declaringType, Type[] argumentTypes) : base(declaringType, argumentTypes) { } public HarmonyDelegate(Type declaringType, string methodName) : base(declaringType, methodName) { } public HarmonyDelegate(Type declaringType, string methodName, params Type[] argumentTypes) : base(declaringType, methodName, argumentTypes) { } public HarmonyDelegate(Type declaringType, string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations) : base(declaringType, methodName, argumentTypes, argumentVariations) { } public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType) : base(declaringType, MethodType.Normal) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType, params Type[] argumentTypes) : base(declaringType, MethodType.Normal, argumentTypes) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(Type declaringType, MethodDispatchType methodDispatchType, Type[] argumentTypes, ArgumentType[] argumentVariations) : base(declaringType, MethodType.Normal, argumentTypes, argumentVariations) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(Type declaringType, string methodName, MethodDispatchType methodDispatchType) : base(declaringType, methodName, MethodType.Normal) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(string methodName) : base(methodName) { } public HarmonyDelegate(string methodName, params Type[] argumentTypes) : base(methodName, argumentTypes) { } public HarmonyDelegate(string methodName, Type[] argumentTypes, ArgumentType[] argumentVariations) : base(methodName, argumentTypes, argumentVariations) { } public HarmonyDelegate(string methodName, MethodDispatchType methodDispatchType) : base(methodName, MethodType.Normal) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(MethodDispatchType methodDispatchType) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(MethodDispatchType methodDispatchType, params Type[] argumentTypes) : base(MethodType.Normal, argumentTypes) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(MethodDispatchType methodDispatchType, Type[] argumentTypes, ArgumentType[] argumentVariations) : base(MethodType.Normal, argumentTypes, argumentVariations) { info.nonVirtualDelegate = methodDispatchType == MethodDispatchType.Call; } public HarmonyDelegate(Type[] argumentTypes) : base(argumentTypes) { } public HarmonyDelegate(Type[] argumentTypes, ArgumentType[] argumentVariations) : base(argumentTypes, argumentVariations) { } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public class HarmonyReversePatch : HarmonyAttribute { public HarmonyReversePatch(HarmonyReversePatchType type = HarmonyReversePatchType.Original) { info.reversePatchType = type; } } [AttributeUsage(AttributeTargets.Class)] public class HarmonyPatchAll : HarmonyAttribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyPriority : HarmonyAttribute { public HarmonyPriority(int priority) { info.priority = priority; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyBefore : HarmonyAttribute { public HarmonyBefore(params string[] before) { info.before = before; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyAfter : HarmonyAttribute { public HarmonyAfter(params string[] after) { info.after = after; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyDebug : HarmonyAttribute { public HarmonyDebug() { info.debug = true; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyEmitIL : HarmonyAttribute { public HarmonyEmitIL() { info.debugEmitPath = "./"; } public HarmonyEmitIL(string dir) { info.debugEmitPath = dir; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class HarmonyWrapSafe : HarmonyAttribute { public HarmonyWrapSafe() { info.wrapTryCatch = true; } } [AttributeUsage(AttributeTargets.Method)] public class HarmonyPrepare : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyCleanup : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyTargetMethod : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyTargetMethods : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyPrefix : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyPostfix : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyTranspiler : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyILManipulator : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class HarmonyFinalizer : Attribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Parameter, AllowMultiple = true)] public class HarmonyArgument : Attribute { public string OriginalName { get; private set; } public int Index { get; private set; } public string NewName { get; private set; } public HarmonyArgument(string originalName) : this(originalName, null) { } public HarmonyArgument(int index) : this(index, null) { } public HarmonyArgument(string originalName, string newName) { OriginalName = originalName; Index = -1; NewName = newName; } public HarmonyArgument(int index, string name) { OriginalName = null; Index = index; NewName = name; } } public class CodeInstruction { public OpCode opcode; public object operand; public List<Label> labels = new List<Label>(); public List<ExceptionBlock> blocks = new List<ExceptionBlock>(); internal CodeInstruction() { } public CodeInstruction(OpCode opcode, object operand = null) { this.opcode = opcode; this.operand = operand; } public CodeInstruction(CodeInstruction instruction) { opcode = instruction.opcode; operand = instruction.operand; labels = instruction.labels.ToList(); blocks = instruction.blocks.ToList(); } public CodeInstruction Clone() { return new CodeInstruction(this) { labels = new List<Label>(), blocks = new List<ExceptionBlock>() }; } public CodeInstruction Clone(OpCode opcode) { CodeInstruction codeInstruction = Clone(); codeInstruction.opcode = opcode; return codeInstruction; } public CodeInstruction Clone(object operand) { CodeInstruction codeInstruction = Clone(); codeInstruction.operand = operand; return codeInstruction; } public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null) { MethodInfo methodInfo = AccessTools.Method(type, name, parameters, generics); if ((object)methodInfo == null) { throw new ArgumentException($"No method found for type={type}, name={name}, parameters={parameters.Description()}, generics={generics.Description()}"); } return new CodeInstruction(OpCodes.Call, methodInfo); } public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null) { MethodInfo methodInfo = AccessTools.Method(typeColonMethodname, parameters, generics); if ((object)methodInfo == null) { throw new ArgumentException("No method found for " + typeColonMethodname + ", parameters=" + parameters.Description() + ", generics=" + generics.Description()); } return new CodeInstruction(OpCodes.Call, methodInfo); } public static CodeInstruction Call(Expression<Action> expression) { return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression)); } public static CodeInstruction Call<T>(Expression<Action<T>> expression) { return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression)); } public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression) { return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression)); } public static CodeInstruction Call(LambdaExpression expression) { return new CodeInstruction(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression)); } public static CodeInstruction CallClosure<T>(T closure) where T : Delegate { return Transpilers.EmitDelegate(closure); } public static CodeInstruction LoadField(Type type, string name, bool useAddress = false) { FieldInfo fieldInfo = AccessTools.Field(type, name); if ((object)fieldInfo == null) { throw new ArgumentException($"No field found for {type} and {name}"); } return new CodeInstruction((!useAddress) ? (fieldInfo.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld) : (fieldInfo.IsStatic ? OpCodes.Ldsflda : OpCodes.Ldflda), fieldInfo); } public static CodeInstruction StoreField(Type type, string name) { FieldInfo fieldInfo = AccessTools.Field(type, name); if ((object)fieldInfo == null) { throw new ArgumentException($"No field found for {type} and {name}"); } return new CodeInstruction(fieldInfo.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fieldInfo); } public override string ToString() { List<string> list = new List<string>(); foreach (Label label in labels) { list.Add($"Label{label.GetHashCode()}"); } foreach (ExceptionBlock block in blocks) { list.Add("EX_" + block.blockType.ToString().Replace("Block", "")); } string text = ((list.Count > 0) ? (" [" + string.Join(", ", list.ToArray()) + "]") : ""); string text2 = FormatArgument(operand); if (text2.Length > 0) { text2 = " " + text2; } OpCode opCode = opcode; return opCode.ToString() + text2 + text; } internal static string FormatArgument(object argument, string extra = null) { if (argument == null) { return "NULL"; } Type type = argument.GetType(); if (argument is MethodBase member) { return member.FullDescription() + ((extra != null) ? (" " + extra) : ""); } if (argument is FieldInfo fieldInfo) { return fieldInfo.FieldType.FullDescription() + " " + fieldInfo.DeclaringType.FullDescription() + "::" + fieldInfo.Name; } if (type == typeof(Label)) { return $"Label{((Label)argument).GetHashCode()}"; } if (type == typeof(Label[])) { return "Labels" + string.Join(",", ((Label[])argument).Select((Label l) => l.GetHashCode().ToString()).ToArray()); } if (type == typeof(LocalBuilder)) { return $"{((LocalBuilder)argument).LocalIndex} ({((LocalBuilder)argument).LocalType})"; } if (type == typeof(string)) { return argument.ToString().ToLiteral(); } return argument.ToString().Trim(); } } public enum ExceptionBlockType { BeginExceptionBlock, BeginCatchBlock, BeginExceptFilterBlock, BeginFaultBlock, BeginFinallyBlock, EndExceptionBlock } public class ExceptionBlock { public ExceptionBlockType blockType; public Type catchType; public ExceptionBlock(ExceptionBlockType blockType, Type catchType = null) { this.blockType = blockType; this.catchType = catchType ?? typeof(object); } } public class InvalidHarmonyPatchArgumentException : Exception { public MethodBase Original { get; } public MethodInfo Patch { get; } public override string Message => "(" + Patch.FullDescription() + "): " + base.Message; public InvalidHarmonyPatchArgumentException(string message, MethodBase original, MethodInfo patch) : base(message) { Original = original; Patch = patch; } } public class MemberNotFoundException : Exception { public MemberNotFoundException(string message) : base(message) { } } public class Harmony : IDisposable { [Obsolete("Use HarmonyFileLog.Enabled instead")] public static bool DEBUG; public string Id { get; } static Harmony() { StackTraceFixes.Install(); } public Harmony(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id cannot be null or empty"); } try { string environmentVariable = Environment.GetEnvironmentVariable("HARMONY_DEBUG"); if (environmentVariable != null && environmentVariable.Length > 0) { environmentVariable = environmentVariable.Trim(); DEBUG = environmentVariable == "1" || bool.Parse(environmentVariable); } } catch { } if (DEBUG) { HarmonyFileLog.Enabled = true; } MethodBase callingMethod = (Logger.IsEnabledFor(Logger.LogChannel.Info) ? AccessTools.GetOutsideCaller() : null); Logger.Log(Logger.LogChannel.Info, delegate { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); Assembly assembly = typeof(Harmony).Assembly; Version version = assembly.GetName().Version; string text = assembly.Location; string text2 = Environment.Version.ToString(); string text3 = Environment.OSVersion.Platform.ToString(); if (string.IsNullOrEmpty(text)) { text = new Uri(assembly.CodeBase).LocalPath; } int size = IntPtr.Size; Platform current = PlatformHelper.Current; stringBuilder.AppendLine($"### Harmony id={id}, version={version}, location={text}, env/clr={text2}, platform={text3}, ptrsize:runtime/env={size}/{current}"); if ((object)callingMethod?.DeclaringType != null) { Assembly assembly2 = callingMethod.DeclaringType.Assembly; text = assembly2.Location; if (string.IsNullOrEmpty(text)) { text = new Uri(assembly2.CodeBase).LocalPath; } stringBuilder.AppendLine("### Started from " + callingMethod.FullDescription() + ", location " + text); stringBuilder.Append($"### At {DateTime.Now:yyyy-MM-dd hh.mm.ss}"); } return stringBuilder.ToString(); }); Id = id; } public void PatchAll() { Assembly assembly = new StackTrace().GetFrame(1).GetMethod().ReflectedType.Assembly; PatchAll(assembly); } public PatchProcessor CreateProcessor(MethodBase original) { return new PatchProcessor(this, original); } public PatchClassProcessor CreateClassProcessor(Type type) { return new PatchClassProcessor(this, type); } public PatchClassProcessor CreateClassProcessor(Type type, bool allowUnannotatedType) { return new PatchClassProcessor(this, type, allowUnannotatedType); } public ReversePatcher CreateReversePatcher(MethodBase original, HarmonyMethod standin) { return new ReversePatcher(this, original, standin); } public void PatchAll(Assembly assembly) { AccessTools.GetTypesFromAssembly(assembly).Do(delegate(Type type) { CreateClassProcessor(type).Patch(); }); } public void PatchAll(Type type) { CreateClassProcessor(type, allowUnannotatedType: true).Patch(); } public MethodInfo Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null, HarmonyMethod finalizer = null, HarmonyMethod ilmanipulator = null) { PatchProcessor patchProcessor = CreateProcessor(original); patchProcessor.AddPrefix(prefix); patchProcessor.AddPostfix(postfix); patchProcessor.AddTranspiler(transpiler); patchProcessor.AddFinalizer(finalizer); patchProcessor.AddILManipulator(ilmanipulator); return patchProcessor.Patch(); } [Obsolete("Use newer Patch() instead", true)] public MethodInfo Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler, HarmonyMethod finalizer) { return Patch(original, prefix, postfix, transpiler, finalizer, null); } public static MethodInfo ReversePatch(MethodBase original, HarmonyMethod standin, MethodInfo transpiler = null, MethodInfo ilmanipulator = null) { return PatchFunctions.ReversePatch(standin, original, transpiler, ilmanipulator); } [Obsolete("Use newer ReversePatch() instead", true)] public static MethodInfo ReversePatch(MethodBase original, HarmonyMethod standin, MethodInfo transpiler) { return PatchFunctions.ReversePatch(standin, original, transpiler, null); } public static void UnpatchID(string harmonyID) { if (string.IsNullOrEmpty(harmonyID)) { throw new ArgumentNullException("harmonyID", "UnpatchID was called with a null or empty harmonyID."); } PatchFunctions.UnpatchConditional((Patch patchInfo) => patchInfo.owner == harmonyID); } void IDisposable.Dispose() { UnpatchSelf(); } public void UnpatchSelf() { UnpatchID(Id); } public static void UnpatchAll() { Logger.Log(Logger.LogChannel.Warn, () => "UnpatchAll has been called - This will remove ALL HARMONY PATCHES."); PatchFunctions.UnpatchConditional((Patch _) => true); } [Obsolete("Use UnpatchSelf() to unpatch the current instance. The functionality to unpatch either other ids or EVERYTHING has been moved the static methods UnpatchID() and UnpatchAll() respectively", true)] public void UnpatchAll(string harmonyID = null) { if (harmonyID == null) { if (HarmonyGlobalSettings.DisallowLegacyGlobalUnpatchAll) { Logger.Log(Logger.LogChannel.Warn, () => "Legacy UnpatchAll has been called AND DisallowLegacyGlobalUnpatchAll=true. Skipping execution of UnpatchAll"); } else { UnpatchAll(); } } else if (harmonyID.Length == 0) { Logger.Log(Logger.LogChannel.Warn, () => "Legacy UnpatchAll was called with harmonyID=\"\" which is an invalid id. Skipping execution of UnpatchAll"); } else { UnpatchID(harmonyID); } } public void Unpatch(MethodBase original, HarmonyPatchType type, string harmonyID = "*") { CreateProcessor(original).Unpatch(type, harmonyID); } public void Unpatch(MethodBase original, MethodInfo patch) { CreateProcessor(original).Unpatch(patch); } public static bool HasAnyPatches(string harmonyID) { return (from original in GetAllPatchedMethods() select GetPatchInfo(original)).Any((Patches info) => info.Owners.Contains(harmonyID)); } public static Patches GetPatchInfo(MethodBase method) { return PatchProcessor.GetPatchInfo(method); } public IEnumerable<MethodBase> GetPatchedMethods() { return from original in GetAllPatchedMethods() where GetPatchInfo(original).Owners.Contains(Id) select original; } public static IEnumerable<MethodBase> GetAllPatchedMethods() { return PatchProcessor.GetAllPatchedMethods(); } public static MethodBase GetOriginalMethod(MethodInfo replacement) { if (replacement == null) { throw new ArgumentNullException("replacement"); } return PatchManager.GetOriginal(replacement); } public static MethodBase GetMethodFromStackframe(StackFrame frame) { if (frame == null) { throw new ArgumentNullException("frame"); } return PatchManager.FindReplacement(frame) ?? frame.GetMethod(); } public static MethodBase GetOriginalMethodFromStackframe(StackFrame frame) { MethodBase methodBase = GetMethodFromStackframe(frame); if (methodBase is MethodInfo replacement) { methodBase = GetOriginalMethod(replacement) ?? methodBase; } return methodBase; } public static Dictionary<string, Version> VersionInfo(out Version currentVersion) { return PatchProcessor.VersionInfo(out currentVersion); } public static Harmony CreateAndPatchAll(Type type, string harmonyInstanceId = null) { Harmony harmony = new Harmony(harmonyInstanceId ?? $"harmony-auto-{Guid.NewGuid()}"); harmony.PatchAll(type); return harmony; } public static Harmony CreateAndPatchAll(Assembly assembly, string harmonyInstanceId = null) { Harmony harmony = new Harmony(harmonyInstanceId ?? $"harmony-auto-{Guid.NewGuid()}"); harmony.PatchAll(assembly); return harmony; } } [Serializable] public class HarmonyException : Exception { private Dictionary<int, CodeInstruction> instructions = new Dictionary<int, CodeInstruction>(); private int errorOffset = -1; internal HarmonyException() { } internal HarmonyException(string message) : base(message) { } internal HarmonyException(string message, Exception innerException) : base(message, innerException) { } protected HarmonyException(SerializationInfo serializationInfo, StreamingContext streamingContext) { throw new NotImplementedException(); } internal HarmonyException(Exception innerException, Dictionary<int, CodeInstruction> instructions, int errorOffset) : base("IL Compile Error", innerException) { this.instructions = instructions; this.errorOffset = errorOffset; } internal static Exception Create(Exception ex, MethodBody body) { if (ex is HarmonyException ex2) { Dictionary<int, CodeInstruction> dictionary = ex2.instructions; if (dictionary != null && dictionary.Count > 0 && ex2.errorOffset >= 0) { return ex; } } Match match = Regex.Match(ex.Message.TrimEnd(new char[0]), "(?:Reason: )?Invalid IL code in.+: IL_(\\d{4}): (.+)$"); if (!match.Success) { return new HarmonyException("IL Compile Error (unknown location)", ex); } Dictionary<int, CodeInstruction> dictionary2 = ILManipulator.GetInstructions(body) ?? new Dictionary<int, CodeInstruction>(); int num = int.Parse(match.Groups[1].Value, NumberStyles.HexNumber); Regex.Replace(match.Groups[2].Value, " {2,}", " "); if (ex is HarmonyException ex3) { if (dictionary2.Count != 0) { ex3.instructions = dictionary2; ex3.errorOffset = num; } return ex3; } return new HarmonyException(ex, dictionary2, num); } public List<KeyValuePair<int, CodeInstruction>> GetInstructionsWithOffsets() { return instructions.OrderBy((KeyValuePair<int, CodeInstruction> ins) => ins.Key).ToList(); } public List<CodeInstruction> GetInstructions() { return (from ins in instructions orderby ins.Key select ins.Value).ToList(); } public int GetErrorOffset() { return errorOffset; } public int GetErrorIndex() { if (instructions.TryGetValue(errorOffset, out var value)) { return GetInstructions().IndexOf(value); } return -1; } } public static class HarmonyGlobalSettings { public static bool DisallowLegacyGlobalUnpatchAll { get; set; } } public class HarmonyMethod { public MethodInfo method; public Type declaringType; public string methodName; public MethodType? methodType; public Type[] argumentTypes; public int priority = -1; public string[] before; public string[] after; public HarmonyReversePatchType? reversePatchType; public bool? debug; public string debugEmitPath; public bool nonVirtualDelegate; public bool? wrapTryCatch; public HarmonyMethod() { } private void ImportMethod(MethodInfo theMethod) { if ((object)theMethod == null) { throw new ArgumentNullException("theMethod", "Harmony method is null (did you target a wrong or missing method?)"); } if (!theMethod.IsStatic) { throw new ArgumentException("Harmony method must be static", "theMethod"); } method = theMethod; List<HarmonyMethod> fromMethod = HarmonyMethodExtensions.GetFromMethod(method); if (fromMethod != null) { Merge(fromMethod).CopyTo(this); } } public HarmonyMethod(MethodInfo method) { if ((object)method == null) { throw new ArgumentNullException("method"); } ImportMethod(method); } public HarmonyMethod(MethodInfo method, int priority = -1, string[] before = null, string[] after = null, bool? debug = null) { if ((object)method == null) { throw new ArgumentNullException("method"); } ImportMethod(method); this.priority = priority; this.before = before; this.after = after; this.debug = debug; } public HarmonyMethod(Type methodType, string methodName, Type[] argumentTypes = null) { MethodInfo methodInfo = AccessTools.Method(methodType, methodName, argumentTypes); if ((object)methodInfo == null) { throw new ArgumentException($"Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}"); } ImportMethod(methodInfo); } public static List<string> HarmonyFields() { return (from s in AccessTools.GetFieldNames(typeof(HarmonyMethod)) where s != "method" select s).ToList(); } public static HarmonyMethod Merge(List<HarmonyMethod> attributes) { return Merge((IEnumerable<HarmonyMethod>)attributes); } internal static HarmonyMethod Merge(IEnumerable<HarmonyMethod> attributes) { HarmonyMethod harmonyMethod = new HarmonyMethod(); if (attributes == null) { return harmonyMethod; } Traverse resultTrv = Traverse.Create(harmonyMethod); attributes.Do(delegate(HarmonyMethod attribute) { Traverse trv = Traverse.Create(attribute); HarmonyFields().ForEach(delegate(string f) { object value = trv.Field(f).GetValue(); if (value != null && (f != "priority" || (int)value != -1)) { HarmonyMethodExtensions.SetValue(resultTrv, f, value); } }); }); return harmonyMethod; } public override string ToString() { string result = ""; Traverse trv = Traverse.Create(this); HarmonyFields().ForEach(delegate(string f) { if (result.Length > 0) { result += ", "; } result += $"{f}={trv.Field(f).GetValue()}"; }); return "HarmonyMethod[" + result + "]"; } internal string Description() { string text = (((object)declaringType != null) ? declaringType.FullDescription() : "undefined"); string text2 = methodName ?? "undefined"; string text3 = (methodType.HasValue ? methodType.Value.ToString() : "undefined"); string text4 = ((argumentTypes != null) ? argumentTypes.Description() : "undefined"); return "(class=" + text + ", methodname=" + text2 + ", type=" + text3 + ", args=" + text4 + ")"; } internal Type GetDeclaringType() { return declaringType; } internal Type[] GetArgumentList() { return argumentTypes ?? EmptyType.NoArgs; } } internal static class EmptyType { internal static readonly Type[] NoArgs = new Type[0]; } public static class HarmonyMethodExtensions { internal static void SetValue(Traverse trv, string name, object val) { if (val != null) { Traverse traverse = trv.Field(name); if (name == "methodType" || name == "reversePatchType") { val = Enum.ToObject(Nullable.GetUnderlyingType(traverse.GetValueType()), (int)val); } traverse.SetValue(val); } } public static void CopyTo(this HarmonyMethod from, HarmonyMethod to) { if (to == null) { return; } Traverse fromTrv = Traverse.Create(from); Traverse toTrv = Traverse.Create(to); HarmonyMethod.HarmonyFields().ForEach(delegate(string f) { object value = fromTrv.Field(f).GetValue(); if (value != null) { SetValue(toTrv, f, value); } }); } public static HarmonyMethod Clone(this HarmonyMethod original) { HarmonyMethod harmonyMethod = new HarmonyMethod(); original.CopyTo(harmonyMethod); return harmonyMethod; } public static HarmonyMethod Merge(this HarmonyMethod master, HarmonyMethod detail) { if (detail == null) { return master; } HarmonyMethod harmonyMethod = new HarmonyMethod(); Traverse resultTrv = Traverse.Create(harmonyMethod); Traverse masterTrv = Traverse.Create(master); Traverse detailTrv = Traverse.Create(detail); HarmonyMethod.HarmonyFields().ForEach(delegate(string f) { object value = masterTrv.Field(f).GetValue(); object value2 = detailTrv.Field(f).GetValue(); if (f != "priority" || (int)value2 != -1) { SetValue(resultTrv, f, value2 ?? value); } }); return harmonyMethod; } private static HarmonyMethod GetHarmonyMethodInfo(object attribute) { FieldInfo field = attribute.GetType().GetField("info", AccessTools.all); if ((object)field == null) { return null; } if (field.FieldType.FullName != typeof(HarmonyMethod).FullName) { return null; } return AccessTools.MakeDeepCopy<HarmonyMethod>(field.GetValue(attribute)); } public static List<HarmonyMethod> GetFromType(Type type) { return (from attr in type.GetCustomAttributes(inherit: true) select GetHarmonyMethodInfo(attr) into info where info != null select info).ToList(); } public static HarmonyMethod GetMergedFromType(Type type) { return HarmonyMethod.Merge(GetFromType(type)); } public static List<HarmonyMethod> GetFromMethod(MethodBase method) { return (from attr in method.GetCustomAttributes(inherit: true) select GetHarmonyMethodInfo(attr) into info where info != null select info).ToList(); } public static HarmonyMethod GetMergedFromMethod(MethodBase method) { return HarmonyMethod.Merge(GetFromMethod(method)); } } public class InlineSignature : ICallSiteGenerator { public class ModifierType { public bool IsOptional; public Type Modifier; public object Type; public override string ToString() { return ((Type is Type type) ? type.FullDescription() : Type?.ToString()) + " mod" + (IsOptional ? "opt" : "req") + "(" + Modifier?.FullDescription() + ")"; } internal TypeReference ToTypeReference(ModuleDefinition module) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown if (!IsOptional) { return (TypeReference)new RequiredModifierType(module.ImportReference(Modifier), GetTypeReference(module, Type)); } return (TypeReference)new OptionalModifierType(module.ImportReference(Modifier), GetTypeReference(module, Type)); } } public bool HasThis { get; set; } public bool ExplicitThis { get; set; } public CallingConvention CallingConvention { get; set; } = CallingConvention.Winapi; public List<object> Parameters { get; set; } = new List<object>(); public object ReturnType { get; set; } = typeof(void); public override string ToString() { return ((ReturnType is Type type) ? type.FullDescription() : ReturnType?.ToString()) + " (" + Parameters.Join((object p) => (!(p is Type type2)) ? p?.ToString() : type2.FullDescription()) + ")"; } internal static TypeReference GetTypeReference(ModuleDefinition module, object param) { if (!(param is Type type)) { if (!(param is InlineSignature inlineSignature)) { if (param is ModifierType modifierType) { return modifierType.ToTypeReference(module); } throw new NotSupportedException($"Unsupported inline signature parameter type: {param} ({param?.GetType().FullDescription()})"); } return (TypeReference)(object)inlineSignature.ToFunctionPointer(module); } return module.ImportReference(type); } CallSite ICallSiteGenerator.ToCallSite(ModuleDefinition module) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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) //IL_003a: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown CallSite val = new CallSite(GetTypeReference(module, ReturnType)) { HasThis = HasThis, ExplicitThis = ExplicitThis, CallingConvention = (MethodCallingConvention)(byte)((byte)CallingConvention - 1) }; foreach (object parameter in Parameters) { val.Parameters.Add(new ParameterDefinition(GetTypeReference(module, parameter))); } return val; } private FunctionPointerType ToFunctionPointer(ModuleDefinition module) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown FunctionPointerType val = new FunctionPointerType { ReturnType = GetTypeReference(module, ReturnType), HasThis = HasThis, ExplicitThis = ExplicitThis, CallingConvention = (MethodCallingConvention)(byte)((byte)CallingConvention - 1) }; foreach (object parameter in Parameters) { val.Parameters.Add(new ParameterDefinition(GetTypeReference(module, parameter))); } return val; } } internal static class PatchInfoSerialization { private class Binder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { Type[] array = new Type[3] { typeof(PatchInfo), typeof(Patch[]), typeof(Patch) }; foreach (Type type in array) { if (typeName == type.FullName) { return type; } } return Type.GetType($"{typeName}, {assemblyName}"); } } internal static byte[] Serialize(this PatchInfo patchInfo) { using MemoryStream memoryStream = new MemoryStream(); new BinaryFormatter().Serialize(memoryStream, patchInfo); return memoryStream.GetBuffer(); } internal static PatchInfo Deserialize(byte[] bytes) { BinaryFormatter obj = new BinaryFormatter { Binder = new Binder() }; MemoryStream serializationStream = new MemoryStream(bytes); return (PatchInfo)obj.Deserialize(serializationStream); } internal static int PriorityComparer(object obj, int index, int priority) { Traverse traverse = Traverse.Create(obj); int value = traverse.Field("priority").GetValue<int>(); int value2 = traverse.Field("index").GetValue<int>(); if (priority != value) { return -priority.CompareTo(value); } return index.CompareTo(value2); } } [Serializable] public class PatchInfo { public Patch[] prefixes = new Patch[0]; public Patch[] postfixes = new Patch[0]; public Patch[] transpilers = new Patch[0]; public Patch[] finalizers = new Patch[0]; public Patch[] ilmanipulators = new Patch[0]; public bool Debugging { get { if (!prefixes.Any((Patch p) => p.debug) && !postfixes.Any((Patch p) => p.debug) && !transpilers.Any((Patch p) => p.debug) && !finalizers.Any((Patch p) => p.debug)) { return ilmanipulators.Any((Patch p) => p.debug); } return true; } } public string[] DebugEmitPaths => (from p in prefixes.Concat(postfixes).Concat(transpilers).Concat(finalizers) .Concat(ilmanipulators) select p.debugEmitPath into p where p != null select p).ToArray(); internal void AddPrefixes(string owner, params HarmonyMethod[] methods) { prefixes = Add(owner, methods, prefixes); } [Obsolete("This method only exists for backwards compatibility since the class is public.")] public void AddPrefix(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug) { AddPrefixes(owner, new HarmonyMethod(patch, priority, before, after, debug)); } public void RemovePrefix(string owner) { prefixes = Remove(owner, prefixes); } internal void AddPostfixes(string owner, params HarmonyMethod[] methods) { postfixes = Add(owner, methods, postfixes); } [Obsolete("This method only exists for backwards compatibility since the class is public.")] public void AddPostfix(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug) { AddPostfixes(owner, new HarmonyMethod(patch, priority, before, after, debug)); } public void RemovePostfix(string owner) { postfixes = Remove(owner, postfixes); } internal void AddTranspilers(string owner, params HarmonyMethod[] methods) { transpilers = Add(owner, methods, transpilers); } [Obsolete("This method only exists for backwards compatibility since the class is public.")] public void AddTranspiler(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug) { AddTranspilers(owner, new HarmonyMethod(patch, priority, before, after, debug)); } public void RemoveTranspiler(string owner) { transpilers = Remove(owner, transpilers); } internal void AddFinalizers(string owner, params HarmonyMethod[] methods) { finalizers = Add(owner, methods, finalizers); } [Obsolete("This method only exists for backwards compatibility since the class is public.")] public void AddFinalizer(MethodInfo patch, string owner, int priority, string[] before, string[] after, bool debug) { AddFinalizers(owner, new HarmonyMethod(patch, priority, before, after, debug)); } public void RemoveFinalizer(string owner) { finalizers = Remove(owner, finalizers); } internal void AddILManipulators(string owner, params HarmonyMethod[] methods) { ilmanipulators = Add(owner, methods, ilmanipulators); } public void RemoveILManipulator(string owner) { ilmanipulators = Remove(owner, ilmanipulators); } public void RemovePatch(MethodInfo patch) { prefixes = prefixes.Where((Patch p) => p.PatchMethod != patch).ToArray(); postfixes = postfixes.Where((Patch p) => p.PatchMethod != patch).ToArray(); transpilers = transpilers.Where((Patch p) => p.PatchMethod != patch).ToArray(); finalizers = finalizers.Where((Patch p) => p.PatchMethod != patch).ToArray(); ilmanipulators = ilmanipulators.Where((Patch p) => p.PatchMethod != patch).ToArray(); } private static Patch[] Add(string owner, HarmonyMethod[] add, Patch[] current) { if (add.Length == 0) { return current; } int initialIndex = current.Length; return current.Concat(add.Where((HarmonyMethod method) => method != null).Select((HarmonyMethod method, int i) => new Patch(method, i + initialIndex, owner))).ToArray(); } private static Patch[] Remove(string owner, Patch[] current) { if (!(owner == "*")) { return current.Where((Patch patch) => patch.owner != owner).ToArray(); } return new Patch[0]; } } [Serializable] public class Patch : IComparable { public readonly int index; public readonly string owner; public readonly int priority; public readonly string[] before; public readonly string[] after; public readonly bool debug; public readonly string debugEmitPath; public readonly bool wrapTryCatch; [NonSerialized] private MethodInfo patchMethod; private int methodToken; private string moduleGUID; public MethodInfo PatchMethod { get { if ((object)patchMethod == null) { Module module = (from a in AppDomain.CurrentDomain.GetAssemblies() where !a.FullName.StartsWith("Microsoft.VisualStudio") select a).SelectMany((Assembly a) => a.GetLoadedModules()).First((Module m) => m.ModuleVersionId.ToString() == moduleGUID); patchMethod = (MethodInfo)module.ResolveMethod(methodToken); } return patchMethod; } set { patchMethod = value; methodToken = patchMethod.MetadataToken; moduleGUID = patchMethod.Module.ModuleVersionId.ToString(); } } public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug) { if (patch is DynamicMethod) { throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method."); } this.index = index; this.owner = owner; this.priority = ((priority == -1) ? 400 : priority); this.before = before ?? new string[0]; this.after = after ?? new string[0]; this.debug = debug; PatchMethod = patch; } public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug, bool wrapTryCatch) { if (patch is DynamicMethod) { throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method."); } this.index = index; this.owner = owner; this.priority = ((priority == -1) ? 400 : priority); this.before = before ?? new string[0]; this.after = after ?? new string[0]; this.debug = debug; this.wrapTryCatch = wrapTryCatch; PatchMethod = patch; } public Patch(MethodInfo patch, int index, string owner, int priority, string[] before, string[] after, bool debug, bool wrapTryCatch, string debugEmitPath) { if (patch is DynamicMethod) { throw new Exception("Cannot directly reference dynamic method \"" + patch.FullDescription() + "\" in Harmony. Use a factory method instead that will return the dynamic method."); } this.index = index; this.owner = owner; this.priority = ((priority == -1) ? 400 : priority); this.before = before ?? new string[0]; this.after = after ?? new string[0]; this.debug = debug; this.debugEmitPath = debugEmitPath; this.wrapTryCatch = wrapTryCatch; PatchMethod = patch; } public Patch(HarmonyMethod method, int index, string owner) : this(method.method, index, owner, method.priority, method.before, method.after, method.debug.GetValueOrDefault(), method.wrapTryCatch.GetValueOrDefault(), method.debugEmitPath) { } public MethodInfo GetMethod(MethodBase original) { MethodInfo methodInfo = PatchMethod; if (methodInfo.ReturnType != typeof(DynamicMethod) && methodInfo.ReturnType != typeof(MethodInfo)) { return methodInfo; } if (!methodInfo.IsStatic) { return methodInfo; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length != 1) { return methodInfo; } if (parameters[0].ParameterType != typeof(MethodBase)) { return methodInfo; } return methodInfo.Invoke(null, new object[1] { original }) as MethodInfo; } public override bool Equals(object obj) { if (obj != null && obj is Patch) { return PatchMethod == ((Patch)obj).PatchMethod; } return false; } public int CompareTo(object obj) { return PatchInfoSerialization.PriorityComparer(obj, index, priority); } public override int GetHashCode() { return PatchMethod.GetHashCode(); } } public class PatchClassProcessor { private readonly Harmony instance; private readonly Type containerType; private readonly HarmonyMethod containerAttributes; private readonly Dictionary<Type, MethodInfo> auxilaryMethods; private readonly List<AttributePatch> patchMethods; private static readonly List<Type> auxilaryTypes = new List<Type> { typeof(HarmonyPrepare), typeof(HarmonyCleanup), typeof(HarmonyTargetMethod), typeof(HarmonyTargetMethods) }; public PatchClassProcessor(Harmony instance, Type type) : this(instance, type, allowUnannotatedType: false) { } public PatchClassProcessor(Harmony instance, Type type, bool allowUnannotatedType) { if (instance == null) { throw new ArgumentNullException("instance"); } if ((object)type == null) { throw new ArgumentNullException("type"); } this.instance = instance; containerType = type; List<HarmonyMethod> fromType = HarmonyMethodExtensions.GetFromType(type); if (!allowUnannotatedType && (fromType == null || fromType.Count == 0)) { return; } containerAttributes = HarmonyMethod.Merge(fromType); MethodType? methodType = containerAttributes.methodType; if (!methodType.HasValue) { containerAttributes.methodType = MethodType.Normal; } auxilaryMethods = new Dictionary<Type, MethodInfo>(); foreach (Type auxilaryType in auxilaryTypes) { MethodInfo patchMethod = PatchTools.GetPatchMethod(containerType, auxilaryType.FullName); if ((object)patchMethod != null) { auxilaryMethods[auxilaryType] = patchMethod; } } patchMethods = PatchTools.GetPatchMethods(containerType, containerAttributes.GetDeclaringType() != null); foreach (AttributePatch patchMethod2 in patchMethods) { MethodInfo method = patchMethod2.info.method; patchMethod2.info = containerAttributes.Merge(patchMethod2.info); patchMethod2.info.method = method; } } public List<MethodInfo> Patch() { if (containerAttributes == null) { return null; } Exception exception = null; if (!RunMethod<HarmonyPrepare, bool>(defaultIfNotExisting: true, defaultIfFailing: false, null, new object[0])) { RunMethod<HarmonyCleanup>(ref exception, new object[0]); ReportException(exception, null); return new List<MethodInfo>(); } List<MethodInfo> result = new List<MethodInfo>(); MethodBase lastOriginal = null; try { List<MethodBase> bulkMethods = GetBulkMethods(); if (bulkMethods.Count == 1) { lastOriginal = bulkMethods[0]; } ReversePatch(ref lastOriginal); result = ((bulkMethods.Count > 0) ? BulkPatch(bulkMethods, ref lastOriginal) : PatchWithAttributes(ref lastOriginal)); } catch (Exception ex) { exception = ex; } RunMethod<HarmonyCleanup>(ref exception, new object[1] { exception }); ReportException(exception, lastOriginal); return result; } private void ReversePatch(ref MethodBase lastOriginal) { for (int i = 0; i < patchMethods.Count; i++) { AttributePatch attributePatch = patchMethods[i]; if (attributePatch.type == HarmonyPatchType.ReversePatch) { MethodBase originalMethod = attributePatch.info.GetOriginalMethod(); if ((object)originalMethod != null) { lastOriginal = originalMethod; } ReversePatcher reversePatcher = instance.CreateReversePatcher(lastOriginal, attributePatch.info); lock (PatchProcessor.locker) { reversePatcher.Patch(); } } } } private List<MethodInfo> BulkPatch(List<MethodBase> originals, ref MethodBase lastOriginal) { PatchJobs<MethodInfo> patchJobs = new PatchJobs<MethodInfo>(); for (int i = 0; i < originals.Count; i++) { lastOriginal = originals[i]; PatchJobs<MethodInfo>.Job job = patchJobs.GetJob(lastOriginal); foreach (AttributePatch patchMethod in patchMethods) { string text = "You cannot combine TargetMethod, TargetMethods or [HarmonyPatchAll] with individual annotations"; HarmonyMethod info = patchMethod.info; if (info.methodName != null) { throw new ArgumentException(text + " [" + info.methodName + "]"); } if (info.methodType.HasValue && info.methodType.Value != 0) { throw new ArgumentException($"{text} [{info.methodType}]"); } if (info.argumentTypes != null) { throw new ArgumentException(text + " [" + info.argumentTypes.Description() + "]"); } job.AddPatch(patchMethod); } } foreach (PatchJobs<MethodInfo>.Job job2 in patchJobs.GetJobs()) { lastO
LineToolLite/LineToolLite.dll
Decompiled 9 months 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 System.Runtime.Versioning; using System.Text; using BepInEx; using Colossal; using Colossal.Entities; using Colossal.Localization; using Colossal.Logging; using Colossal.Mathematics; using Colossal.Serialization.Entities; using Colossal.UI; using Game; using Game.Common; using Game.Input; using Game.Modding; using Game.Net; using Game.Objects; using Game.Prefabs; using Game.Rendering; using Game.SceneFlow; using Game.Simulation; using Game.Tools; using Game.UI; using Game.UI.Tooltip; using Game.UI.Widgets; using HarmonyLib; using Unity.Collections; using Unity.Entities; using Unity.Jobs; using Unity.Mathematics; using UnityEngine; using UnityEngine.InputSystem; using cohtml.Net; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("algernon")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © 2023-24 algernon (github.com/algernon-A). All rights reserved.")] [assembly: AssemblyDescription("A Cities: Skylines 2 mod.")] [assembly: AssemblyFileVersion("1.3.4.0")] [assembly: AssemblyInformationalVersion("1.3.4+8e82b5e756aada19745596d0a57ab34bdac159c4")] [assembly: AssemblyProduct("Line Tool Lite")] [assembly: AssemblyTitle("Line Tool Lite")] [assembly: AssemblyVersion("1.3.4.0")] namespace LineTool; [BepInPlugin("com.github.algernon-A.CS2.LineToolLite", "Line Tool Lite", "1.3.4")] [HarmonyPatch] public class Plugin : BaseUnityPlugin { public const string GUID = "com.github.algernon-A.CS2.LineToolLite"; private Mod _mod; public void Awake() { _mod = new Mod(); _mod.OnLoad(); _mod.Log.Info((object)"Plugin.Awake"); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.github.algernon-A.CS2.LineToolLite"); } [HarmonyPatch(typeof(SystemOrder), "Initialize")] [HarmonyPostfix] private static void InjectSystems(UpdateSystem updateSystem) { Mod.Instance.OnCreateWorld(updateSystem); } } public class Circle : LineBase { public Circle(LineBase mode) : base(mode) { } public override void CalculatePoints(float3 currentPos, SpacingMode spacingMode, float spacing, float randomSpacing, float randomOffset, int rotation, Bounds1 zBounds, NativeList<PointData> pointList, ref TerrainHeightData heightData) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_0145: 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_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) if (!m_validStart) { return; } float3 val = currentPos - m_startPos; float num = math.length(val); float num2 = num * (float)Math.PI * 2f; float num3 = ((spacingMode == SpacingMode.FullLength) ? math.round(num2 / spacing) : math.floor(num2 / spacing)); float num4 = (float)Math.PI * 2f / num3; float num5 = math.atan2(val.z, val.x); Random random = new Random((int)num2 * 1000); float3 val2 = default(float3); for (float num6 = num5; num6 < num5 + (float)Math.PI * 2f; num6 += num4) { float num7 = num6; if (randomSpacing > 0f && spacingMode != SpacingMode.FenceMode) { float num8 = (float)(random.NextDouble() * (double)randomSpacing * 2.0) - randomSpacing; num7 += num8 * (float)Math.PI * 2f / num2; } float num9 = num * math.cos(num7); float num10 = num * math.sin(num7); ((float3)(ref val2))..ctor(m_startPos.x + num9, m_startPos.y, m_startPos.z + num10); if (randomOffset > 0f && spacingMode != SpacingMode.FenceMode) { val2 += math.normalize(val2 - m_startPos) * ((float)((double)randomOffset * random.NextDouble() * 2.0) - randomOffset); } val2.y = TerrainUtils.SampleHeight(ref heightData, val2); PointData pointData = new PointData { Position = val2, Rotation = quaternion.Euler(0f, math.radians((float)rotation) - num6, 0f, (RotationOrder)4) }; pointList.Add(ref pointData); } m_endPos = currentPos; } public override void ItemsPlaced(float3 location) { } } public abstract class LineBase { protected const float PointRadius = 8f; protected bool m_validStart; protected float3 m_startPos; protected float3 m_endPos; public bool HasStart => m_validStart; public virtual bool HasAllPoints => m_validStart; public LineBase() { m_validStart = false; } public LineBase(LineBase mode) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) m_validStart = mode.m_validStart; m_startPos = mode.m_startPos; } public virtual bool HandleClick(float3 position) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) if (!m_validStart) { m_startPos = position; m_endPos = position; m_validStart = true; return false; } return true; } public virtual void ItemsPlaced(float3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) m_startPos = position; } public virtual void CalculatePoints(float3 currentPos, SpacingMode spacingMode, float spacing, float randomSpacing, float randomOffset, int rotation, Bounds1 zBounds, NativeList<PointData> pointList, ref TerrainHeightData heightData) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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_01b9: 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_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0188: 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_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: 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_00ec: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) if (!m_validStart) { return; } float3 val = currentPos - m_startPos; float num = math.length(val); Random random = new Random((int)num * 1000); float num2 = math.radians((float)rotation); if (spacingMode == SpacingMode.FenceMode) { num2 = math.atan2(val.x, val.z); } quaternion rotation2 = quaternion.Euler(0f, num2, 0f, (RotationOrder)4); float num3 = spacing; if (spacingMode == SpacingMode.FullLength) { num3 = num / math.round(num / spacing); } float num4 = ((spacingMode == SpacingMode.FenceMode) ? (0f - zBounds.min) : 0f); for (float num5 = ((spacingMode == SpacingMode.FenceMode) ? (num - zBounds.max) : num); num4 < num5; num4 += num3) { float num6 = 0f; if (randomSpacing > 0f && spacingMode != SpacingMode.FenceMode) { num6 = (float)(random.NextDouble() * (double)randomSpacing * 2.0) - randomSpacing; } float3 val2 = math.lerp(m_startPos, currentPos, (num4 + num6) / num); if (randomOffset > 0f && spacingMode != SpacingMode.FenceMode) { float3 val3 = math.normalize(new float3(0f - val.z, 0f, val.x)); val2 += val3 * ((float)((double)randomOffset * random.NextDouble() * 2.0) - randomOffset); } val2.y = TerrainUtils.SampleHeight(ref heightData, val2); PointData pointData = new PointData { Position = val2, Rotation = rotation2 }; pointList.Add(ref pointData); } if (spacingMode == SpacingMode.FullLength && num4 < num + num3) { float3 val4 = currentPos; val4.y = TerrainUtils.SampleHeight(ref heightData, val4); PointData pointData = new PointData { Position = val4, Rotation = rotation2 }; pointList.Add(ref pointData); } m_endPos = currentPos; } public virtual void DrawOverlay(Buffer overlayBuffer, NativeList<TooltipInfo> tooltips) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (m_validStart) { DrawDashedLine(m_startPos, m_endPos, new Segment(m_startPos, m_endPos), overlayBuffer, tooltips); } } public virtual void DrawPointOverlays(Buffer overlayBuffer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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) Color cyan = Color.cyan; cyan.a *= 0.1f; ((Buffer)(ref overlayBuffer)).DrawCircle(Color.cyan, cyan, 0.3f, (StyleFlags)0, new float2(0f, 1f), m_startPos, 16f); ((Buffer)(ref overlayBuffer)).DrawCircle(Color.cyan, cyan, 0.3f, (StyleFlags)0, new float2(0f, 1f), m_endPos, 16f); } public virtual void Reset() { m_validStart = false; } internal virtual LineToolSystem.DragMode CheckDragHit(float3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (math.distancesq(position, m_startPos) < 64f) { return LineToolSystem.DragMode.StartPos; } if (math.distancesq(position, m_endPos) < 64f) { return LineToolSystem.DragMode.EndPos; } return LineToolSystem.DragMode.None; } internal virtual void HandleDrag(LineToolSystem.DragMode dragMode, float3 position) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (dragMode == LineToolSystem.DragMode.StartPos) { m_startPos = position; } } protected void DrawDashedLine(float3 startPos, float3 endPos, Segment segment, Buffer overlayBuffer, NativeList<TooltipInfo> tooltips) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) float num = math.distance(((float3)(ref startPos)).xz, ((float3)(ref endPos)).xz); if (num > 8f) { float3 val = (segment.b - segment.a) * (4f / num); Segment val2 = default(Segment); ((Segment)(ref val2))..ctor(segment.a + val, segment.b - val); ((Buffer)(ref overlayBuffer)).DrawDashedLine(Color.white, val2, 3f, 5f, 3f); int num2 = Mathf.RoundToInt(math.distance(((float3)(ref startPos)).xz, ((float3)(ref endPos)).xz)); if (num2 > 0) { TooltipInfo val3 = new TooltipInfo((TooltipType)1, (startPos + endPos) * 0.5f, num2); tooltips.Add(ref val3); } } } } public enum LineMode { Straight, SimpleCurve, Circle } public struct PointData { public float3 Position; public quaternion Rotation; } public class SimpleCurve : LineBase { private bool _validElbow; private bool _validPreviousElbow; private float3 _elbowPoint; private float3 _previousElbowPoint; private Bezier4x3 _thisBezier; public override bool HasAllPoints => m_validStart & _validElbow; public SimpleCurve(LineBase mode) : base(mode) { } public override bool HandleClick(float3 position) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!m_validStart) { m_startPos = position; m_endPos = position; m_validStart = true; return false; } if (!_validElbow) { _elbowPoint = ConstrainPos(position); _validElbow = true; return false; } return true; } public override void ItemsPlaced(float3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) m_startPos = position; _validElbow = false; _previousElbowPoint = _elbowPoint; _validPreviousElbow = true; } public override void CalculatePoints(float3 currentPos, SpacingMode spacingMode, float spacing, float randomSpacing, float randomOffset, int rotation, Bounds1 zBounds, NativeList<PointData> pointList, ref TerrainHeightData heightData) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0206: 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_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0210: 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_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_0145: 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_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0153: 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_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) if (!m_validStart) { return; } if (!_validElbow) { m_endPos = ConstrainPos(currentPos); base.CalculatePoints(m_endPos, spacingMode, spacing, randomSpacing, randomOffset, rotation, zBounds, pointList, ref heightData); return; } _thisBezier = NetUtils.FitCurve(new Segment(m_startPos, _elbowPoint), new Segment(currentPos, _elbowPoint)); float num = spacing; float num2 = MathUtils.Length(_thisBezier); if (spacingMode == SpacingMode.FullLength) { num = num2 / math.round(num2 / spacing); } quaternion rotation2 = quaternion.Euler(0f, math.radians((float)rotation), 0f, (RotationOrder)4); Random random = new Random((int)(currentPos.x + currentPos.z) * 1000); float num3 = ((spacingMode == SpacingMode.FenceMode) ? BezierStep(0f, spacing / 2f) : 0f); float num4 = 0f; while (num3 < 1f) { float num5 = num3; if (randomSpacing > 0f && spacingMode != SpacingMode.FenceMode) { float num6 = (float)(random.NextDouble() * (double)randomSpacing * 2.0) - randomSpacing; num5 = ((num6 < 0f) ? BezierStepReverse(num3, num6) : BezierStep(num3, num6)); } float3 val = MathUtils.Position(_thisBezier, num5); if (randomOffset > 0f && spacingMode != SpacingMode.FenceMode) { float3 val2 = MathUtils.Tangent(_thisBezier, num5); float3 val3 = math.normalize(new float3(0f - val2.z, 0f, val2.x)); val += val3 * ((float)((double)randomOffset * random.NextDouble() * 2.0) - randomOffset); } num3 = BezierStep(num3, num); num4 += num; if (spacingMode == SpacingMode.FenceMode) { float3 val4 = MathUtils.Position(_thisBezier, num3) - val; rotation2 = quaternion.Euler(0f, math.atan2(val4.x, val4.z), 0f, (RotationOrder)4); } val.y = TerrainUtils.SampleHeight(ref heightData, val); PointData pointData = new PointData { Position = val, Rotation = rotation2 }; pointList.Add(ref pointData); } if (spacingMode == SpacingMode.FullLength && num4 < num2 + num) { float3 val5 = currentPos; val5.y = TerrainUtils.SampleHeight(ref heightData, val5); PointData pointData = new PointData { Position = val5, Rotation = rotation2 }; pointList.Add(ref pointData); } m_endPos = currentPos; } public override void DrawOverlay(Buffer overlayBuffer, NativeList<TooltipInfo> tooltips) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_004d: 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_005a: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) if (m_validStart) { if (_validElbow) { Segment val = default(Segment); ((Segment)(ref val))..ctor(m_startPos, _elbowPoint); Segment val2 = default(Segment); ((Segment)(ref val2))..ctor(_elbowPoint, m_endPos); DrawDashedLine(m_startPos, _elbowPoint, val, overlayBuffer, tooltips); DrawDashedLine(_elbowPoint, m_endPos, val2, overlayBuffer, tooltips); DrawAngleIndicator(val, val2, 8f, 8f, overlayBuffer, tooltips); } else { base.DrawOverlay(overlayBuffer, tooltips); } } } public override void DrawPointOverlays(Buffer overlayBuffer) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) base.DrawPointOverlays(overlayBuffer); if (_validElbow) { Color cyan = Color.cyan; cyan.a *= 0.1f; ((Buffer)(ref overlayBuffer)).DrawCircle(Color.cyan, cyan, 0.3f, (StyleFlags)0, new float2(0f, 1f), _elbowPoint, 16f); } } public override void Reset() { if (_validElbow) { _validElbow = false; return; } _validPreviousElbow = false; base.Reset(); } internal override LineToolSystem.DragMode CheckDragHit(float3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) LineToolSystem.DragMode dragMode = base.CheckDragHit(position); if (dragMode == LineToolSystem.DragMode.None && _validElbow && math.distancesq(position, _elbowPoint) < 64f) { return LineToolSystem.DragMode.ElbowPos; } return dragMode; } internal override void HandleDrag(LineToolSystem.DragMode dragMode, float3 position) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (dragMode == LineToolSystem.DragMode.ElbowPos) { _elbowPoint = position; } else { base.HandleDrag(dragMode, position); } } private float3 ConstrainPos(float3 currentPos) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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) if (m_validStart && !_validElbow && _validPreviousElbow) { return math.project(currentPos - _previousElbowPoint, m_startPos - _previousElbowPoint) + _previousElbowPoint; } return currentPos; } private float BezierStep(float tStart, float distance) { float num = Travel(tStart, distance); float num2 = CubicBezierArcLengthXZGauss04(tStart, num); for (int i = 0; i < 12; i++) { float num3 = distance - num2; if (num3 * num3 < 1.0000001E-06f) { break; } num2 = CubicBezierArcLengthXZGauss04(tStart, num); num += (distance - num2) / CubicSpeedXZ(num); } return num; } private float BezierStepReverse(float tStart, float distance) { float num = Travel(tStart, 0f - distance); float num2 = CubicBezierArcLengthXZGauss04(num, tStart); for (int i = 0; i < 12; i++) { float num3 = distance - num2; if (num3 * num3 < 1.0000001E-06f) { break; } num2 = CubicBezierArcLengthXZGauss04(num, tStart); num -= (distance - num2) / CubicSpeedXZ(num); } return num; } private float CubicSpeedXZ(float t) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) float3 val = MathUtils.Tangent(_thisBezier, t); float num = val.x * val.x; float num2 = val.z * val.z; return math.sqrt(num + num2); } private float CubicBezierArcLengthXZGauss04(float t1, float t2) { float num = (t2 - t1) / 2f; float num2 = CubicSpeedXZGaussPoint(0.33998105f, 0.65214515f, t1, t2); float num3 = CubicSpeedXZGaussPoint(-0.33998105f, 0.65214515f, t1, t2); float num4 = CubicSpeedXZGaussPoint(0.8611363f, 0.34785485f, t1, t2); float num5 = CubicSpeedXZGaussPoint(-0.8611363f, 0.34785485f, t1, t2); return num * (num2 + num3 + num4 + num5); } private float CubicSpeedXZGaussPoint(float x_i, float w_i, float a, float b) { float num = (b - a) / 2f; float num2 = (a + b) / 2f; return w_i * CubicSpeedXZ(num * x_i + num2); } private float Travel(float start, float distance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0133: 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_006e: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) Vector3 val = float3.op_Implicit(MathUtils.Position(_thisBezier, start)); if (distance < 0f) { distance = 0f - distance; float num = 0f; float num2 = start; float num3 = Vector3.SqrMagnitude(float3.op_Implicit(_thisBezier.a - float3.op_Implicit(val))); float num4 = 0f; for (int i = 0; i < 8; i++) { float num5 = (num + num2) * 0.5f; float num6 = Vector3.SqrMagnitude(float3.op_Implicit(MathUtils.Position(_thisBezier, num5)) - val); if (num6 < distance * distance) { num2 = num5; num4 = num6; } else { num = num5; num3 = num6; } } num3 = Mathf.Sqrt(num3); num4 = Mathf.Sqrt(num4); float num7 = num3 - num4; if (num7 == 0f) { return num2; } return Mathf.Lerp(num2, num, Mathf.Clamp01((distance - num4) / num7)); } float num8 = start; float num9 = 1f; float num10 = 0f; float num11 = Vector3.SqrMagnitude(float3.op_Implicit(_thisBezier.d - float3.op_Implicit(val))); for (int j = 0; j < 8; j++) { float num12 = (num8 + num9) * 0.5f; float num13 = Vector3.SqrMagnitude(float3.op_Implicit(MathUtils.Position(_thisBezier, num12)) - val); if (num13 < distance * distance) { num8 = num12; num10 = num13; } else { num9 = num12; num11 = num13; } } num10 = Mathf.Sqrt(num10); num11 = Mathf.Sqrt(num11); float num14 = num11 - num10; if (num14 == 0f) { return num8; } return Mathf.Lerp(num8, num9, Mathf.Clamp01((distance - num10) / num14)); } private void DrawAngleIndicator(Segment line1, Segment line2, float lineWidth, float lineLength, Buffer overlayBuffer, NativeList<TooltipInfo> tooltips) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: 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_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0301: 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_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0449: Unknown result type (might be due to invalid IL or missing references) //IL_044c: Unknown result type (might be due to invalid IL or missing references) //IL_0451: Unknown result type (might be due to invalid IL or missing references) //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_045c: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0463: Unknown result type (might be due to invalid IL or missing references) //IL_0464: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0473: Unknown result type (might be due to invalid IL or missing references) //IL_047f: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) //IL_0487: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_0491: Unknown result type (might be due to invalid IL or missing references) //IL_049e: Unknown result type (might be due to invalid IL or missing references) //IL_04a3: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04ac: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04c1: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_04cc: Unknown result type (might be due to invalid IL or missing references) //IL_04d1: Unknown result type (might be due to invalid IL or missing references) //IL_04d6: Unknown result type (might be due to invalid IL or missing references) //IL_04db: Unknown result type (might be due to invalid IL or missing references) //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_04e4: Unknown result type (might be due to invalid IL or missing references) //IL_04f0: Unknown result type (might be due to invalid IL or missing references) //IL_04f5: Unknown result type (might be due to invalid IL or missing references) //IL_04f7: Unknown result type (might be due to invalid IL or missing references) //IL_04f9: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_050d: Unknown result type (might be due to invalid IL or missing references) //IL_050f: Unknown result type (might be due to invalid IL or missing references) //IL_051a: Unknown result type (might be due to invalid IL or missing references) //IL_051b: Unknown result type (might be due to invalid IL or missing references) //IL_0520: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) //IL_052b: Unknown result type (might be due to invalid IL or missing references) //IL_052d: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_053a: Unknown result type (might be due to invalid IL or missing references) //IL_053c: Unknown result type (might be due to invalid IL or missing references) //IL_0549: Unknown result type (might be due to invalid IL or missing references) //IL_054e: Unknown result type (might be due to invalid IL or missing references) //IL_055b: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0576: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_057c: Unknown result type (might be due to invalid IL or missing references) //IL_0581: Unknown result type (might be due to invalid IL or missing references) //IL_0586: Unknown result type (might be due to invalid IL or missing references) //IL_0589: Unknown result type (might be due to invalid IL or missing references) //IL_058e: Unknown result type (might be due to invalid IL or missing references) //IL_059a: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_05ae: Unknown result type (might be due to invalid IL or missing references) //IL_05a5: Unknown result type (might be due to invalid IL or missing references) //IL_05a6: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_0365: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: 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_015c: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0196: 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_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: 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_01fa: 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_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: 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_0226: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: 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) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0261: 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_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0277: 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_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_028d: 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_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: 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_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_05b8: Unknown result type (might be due to invalid IL or missing references) //IL_05b9: Unknown result type (might be due to invalid IL or missing references) //IL_05be: Unknown result type (might be due to invalid IL or missing references) //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05cc: Unknown result type (might be due to invalid IL or missing references) //IL_05d1: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_038c: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_05f1: Unknown result type (might be due to invalid IL or missing references) //IL_05f3: Unknown result type (might be due to invalid IL or missing references) //IL_05e8: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_05ff: Unknown result type (might be due to invalid IL or missing references) //IL_0604: Unknown result type (might be due to invalid IL or missing references) //IL_0606: Unknown result type (might be due to invalid IL or missing references) //IL_0608: Unknown result type (might be due to invalid IL or missing references) //IL_060a: Unknown result type (might be due to invalid IL or missing references) //IL_060c: Unknown result type (might be due to invalid IL or missing references) //IL_0617: Unknown result type (might be due to invalid IL or missing references) //IL_0618: Unknown result type (might be due to invalid IL or missing references) //IL_061d: Unknown result type (might be due to invalid IL or missing references) //IL_0622: Unknown result type (might be due to invalid IL or missing references) //IL_0627: Unknown result type (might be due to invalid IL or missing references) //IL_0628: Unknown result type (might be due to invalid IL or missing references) //IL_062a: Unknown result type (might be due to invalid IL or missing references) //IL_0631: Unknown result type (might be due to invalid IL or missing references) //IL_0637: Unknown result type (might be due to invalid IL or missing references) //IL_0639: Unknown result type (might be due to invalid IL or missing references) //IL_0646: Unknown result type (might be due to invalid IL or missing references) //IL_064b: Unknown result type (might be due to invalid IL or missing references) //IL_0658: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) bool flag = false; float num = math.distance(((float3)(ref line1.a)).xz, ((float3)(ref line1.b)).xz); float num2 = math.distance(((float3)(ref line2.a)).xz, ((float3)(ref line2.b)).xz); if (num > lineWidth * 7f && num2 > lineWidth * 7f) { float2 val = (((float3)(ref line1.b)).xz - ((float3)(ref line1.a)).xz) / num; float2 val2 = (((float3)(ref line2.a)).xz - ((float3)(ref line2.b)).xz) / num2; float num3 = math.min(lineLength, math.min(num, num2)) * 0.5f; int num4 = Mathf.RoundToInt(math.degrees(math.acos(math.clamp(math.dot(val, val2), -1f, 1f)))); if (num4 < 180) { flag = math.dot(MathUtils.Right(val), val2) < 0f; } if (num4 == 180) { float2 val3 = (flag ? MathUtils.Right(val) : MathUtils.Left(val)); float2 val4 = (flag ? MathUtils.Right(val2) : MathUtils.Left(val2)); float3 b = line1.b; ((float3)(ref b)).xz = ((float3)(ref b)).xz - val * num3; float3 b2 = line1.b; float3 b3 = line1.b; ((float3)(ref b2)).xz = ((float3)(ref b2)).xz + (val3 * (num3 - lineWidth * 0.5f) - val * num3); ((float3)(ref b3)).xz = ((float3)(ref b3)).xz + (val3 * num3 - val * (num3 + lineWidth * 0.5f)); float3 a = line2.a; float3 a2 = line2.a; ((float3)(ref a)).xz = ((float3)(ref a)).xz - (val4 * num3 + val2 * (num3 + lineWidth * 0.5f)); ((float3)(ref a2)).xz = ((float3)(ref a2)).xz - (val4 * (num3 - lineWidth * 0.5f) + val2 * num3); float3 a3 = line2.a; ((float3)(ref a3)).xz = ((float3)(ref a3)).xz - val2 * num3; ((Buffer)(ref overlayBuffer)).DrawLine(Color.white, new Segment(b, b2), lineWidth); ((Buffer)(ref overlayBuffer)).DrawLine(Color.white, new Segment(b3, a), lineWidth); ((Buffer)(ref overlayBuffer)).DrawLine(Color.white, new Segment(a2, a3), lineWidth); float3 b4 = line1.b; ((float3)(ref b4)).xz = ((float3)(ref b4)).xz + val3 * (num3 * 1.5f); TooltipInfo val5 = default(TooltipInfo); ((TooltipInfo)(ref val5))..ctor((TooltipType)0, b4, num4); tooltips.Add(ref val5); } else if (num4 > 90) { float2 val6 = math.normalize(val + val2); float3 b5 = line1.b; ((float3)(ref b5)).xz = ((float3)(ref b5)).xz - val * num3; float3 val7 = default(float3); ((float3)(ref val7)).xz = (flag ? MathUtils.Right(val) : MathUtils.Left(val)); float3 b6 = line1.b; ((float3)(ref b6)).xz = ((float3)(ref b6)).xz - val6 * num3; float3 val8 = default(float3); ((float3)(ref val8)).xz = (flag ? MathUtils.Right(val6) : MathUtils.Left(val6)); float3 a4 = line2.a; ((float3)(ref a4)).xz = ((float3)(ref a4)).xz - val2 * num3; float3 val9 = default(float3); ((float3)(ref val9)).xz = (flag ? MathUtils.Right(val2) : MathUtils.Left(val2)); ((Buffer)(ref overlayBuffer)).DrawCurve(Color.white, NetUtils.FitCurve(b5, val7, val8, b6), lineWidth); ((Buffer)(ref overlayBuffer)).DrawCurve(Color.white, NetUtils.FitCurve(b6, val8, val9, a4), lineWidth); float3 b7 = line1.b; ((float3)(ref b7)).xz = ((float3)(ref b7)).xz - val6 * (num3 * 1.5f); TooltipInfo val10 = default(TooltipInfo); ((TooltipInfo)(ref val10))..ctor((TooltipType)0, b7, num4); tooltips.Add(ref val10); } else if (num4 == 90) { float3 b8 = line1.b; ((float3)(ref b8)).xz = ((float3)(ref b8)).xz - val * num3; float3 b9 = line1.b; float3 b10 = line1.b; ((float3)(ref b9)).xz = ((float3)(ref b9)).xz - (val2 * (num3 - lineWidth * 0.5f) + val * num3); ((float3)(ref b10)).xz = ((float3)(ref b10)).xz - (val2 * num3 + val * (num3 + lineWidth * 0.5f)); float3 a5 = line2.a; ((float3)(ref a5)).xz = ((float3)(ref a5)).xz - val2 * num3; ((Buffer)(ref overlayBuffer)).DrawLine(Color.white, new Segment(b8, b9), lineWidth); ((Buffer)(ref overlayBuffer)).DrawLine(Color.white, new Segment(b10, a5), lineWidth); float3 b11 = line1.b; ((float3)(ref b11)).xz = ((float3)(ref b11)).xz - math.normalizesafe(val + val2, default(float2)) * (num3 * 1.5f); TooltipInfo val11 = default(TooltipInfo); ((TooltipInfo)(ref val11))..ctor((TooltipType)0, b11, num4); tooltips.Add(ref val11); } else if (num4 > 0) { float3 b12 = line1.b; ((float3)(ref b12)).xz = ((float3)(ref b12)).xz - val * num3; float3 val12 = default(float3); ((float3)(ref val12)).xz = (flag ? MathUtils.Right(val) : MathUtils.Left(val)); float3 a6 = line2.a; ((float3)(ref a6)).xz = ((float3)(ref a6)).xz - val2 * num3; float3 val13 = default(float3); ((float3)(ref val13)).xz = (flag ? MathUtils.Right(val2) : MathUtils.Left(val2)); ((Buffer)(ref overlayBuffer)).DrawCurve(Color.white, NetUtils.FitCurve(b12, val12, val13, a6), lineWidth); float3 b13 = line1.b; ((float3)(ref b13)).xz = ((float3)(ref b13)).xz - math.normalizesafe(val + val2, default(float2)) * (num3 * 1.5f); TooltipInfo val14 = default(TooltipInfo); ((TooltipInfo)(ref val14))..ctor((TooltipType)0, b13, num4); tooltips.Add(ref val14); } } } } public enum SpacingMode { Manual, FenceMode, FullLength } public class StraightLine : LineBase { public StraightLine() { m_validStart = false; } public StraightLine(LineBase mode) : base(mode) { } } public static class Localization { public static void LoadTranslations(ILog log) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown try { using StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("LineToolLite.l10n.csv")); List<string> list = new List<string>(); while (!streamReader.EndOfStream) { string text = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(text)) { list.Add(text); } } log.Info((object)"parsing translation file"); IEnumerable<string[]> source = list.Select((string x) => x.Split(new char[1] { '\t' })); string[] supportedLocales = GameManager.instance.localizationManager.GetSupportedLocales(); foreach (string text2 in supportedLocales) { try { int valueColumn = Array.IndexOf(source.First(), text2); if (valueColumn > 1) { log.Debug((object)("found translation for " + text2)); MemorySource val = new MemorySource(source.Skip(1).ToDictionary((string[] x) => x[0] + "." + x[1], (string[] x) => x.ElementAtOrDefault(valueColumn))); GameManager.instance.localizationManager.AddSource(text2, (IDictionarySource)(object)val); } } catch (Exception ex) { log.Error(ex, (object)("exception reading localization for locale " + text2)); } } } catch (Exception ex2) { log.Error(ex2, (object)"exception reading settings localization file"); } } } public sealed class Mod : IMod { public const string ModName = "Line Tool"; public static Mod Instance { get; private set; } internal ILog Log { get; private set; } public void OnLoad() { Instance = this; Log = LogManager.GetLogger("Line Tool", true); Log.Info((object)string.Format("loading {0} version {1}", "Line Tool", Assembly.GetExecutingAssembly().GetName().Version)); } public void OnCreateWorld(UpdateSystem updateSystem) { Log.Info((object)"starting OnCreateWorld"); Localization.LoadTranslations(Log); updateSystem.UpdateAt<LineToolSystem>((SystemUpdatePhase)17); updateSystem.UpdateAt<LineToolUISystem>((SystemUpdatePhase)22); updateSystem.UpdateAt<LineToolTooltipSystem>((SystemUpdatePhase)23); IResourceHandler resourceHandler = GameManager.instance.userInterface.view.uiSystem.resourceHandler; IResourceHandler obj = ((resourceHandler is GameUIResourceHandler) ? resourceHandler : null); if (obj != null) { ((DefaultResourceHandler)obj).HostLocationsMap.Add("linetool", new List<string> { Path.GetDirectoryName(typeof(Plugin).Assembly.Location) + "/" }); } } public void OnDispose() { Log.Info((object)"disposing"); Instance = null; } } public sealed class LineToolSystem : ObjectToolBaseSystem { internal enum DragMode { None, StartPos, EndPos, ElbowPos } private readonly NativeList<Entity> _previewEntities = new NativeList<Entity>(AllocatorHandle.op_Implicit((Allocator)4)); private readonly NativeList<TooltipInfo> _tooltips = new NativeList<TooltipInfo>(8, AllocatorHandle.op_Implicit((Allocator)4)); private readonly NativeList<PointData> _points = new NativeList<PointData>(AllocatorHandle.op_Implicit((Allocator)4)); private bool _fixedPreview; private float3 _fixedPos; private Random _random; private ControlPoint _raycastPoint; private float3 _previousPos; private Entity _cursorEntity = Entity.Null; private ToolBaseSystem _previousTool; private ObjectGeometryPrefab _selectedPrefab; private Entity _selectedEntity = Entity.Null; private int _originalXP; private Bounds1 _zBounds; private ILog _log; private TerrainSystem _terrainSystem; private TerrainHeightData _terrainHeightData; private Buffer _overlayBuffer; private ProxyAction _applyAction; private ProxyAction _cancelAction; private InputAction _fixedPreviewAction; private InputAction _keepBuildingAction; private LineBase _mode; private LineMode _currentMode; private DragMode _dragMode; private SpacingMode _spacingMode; private float _spacing = 20f; private bool _randomRotation; private int _rotation; private float _randomSpacing; private float _randomOffset; private bool _dirty; private ToolBaseSystem _treeControllerTool; private PropertyInfo _nextTreeState; public override string toolID => "Line Tool"; internal float Spacing { get { return _spacing; } set { _spacing = (float)Math.Round(math.max(value, math.max(math.abs(_zBounds.max), math.abs(_zBounds.min) + 0.1f)), 1); ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<LineToolUISystem>().UpdateSpacing(); _dirty = true; } } internal float EffectiveSpacing { get { if (_spacingMode != SpacingMode.FenceMode) { return _spacing; } return _zBounds.max - _zBounds.min; } } internal SpacingMode CurrentSpacingMode { get { return _spacingMode; } set { _spacingMode = value; _dirty = true; } } internal bool RandomRotation { get { return _randomRotation; } set { _randomRotation = value; _dirty = true; } } internal float RandomSpacing { get { return _randomSpacing; } set { _randomSpacing = value; _dirty = true; } } internal float RandomOffset { get { return _randomOffset; } set { _randomOffset = value; _dirty = true; } } internal int Rotation { get { return _rotation; } set { _rotation = value; _dirty = true; } } internal NativeList<TooltipInfo> Tooltips => _tooltips; internal LineMode Mode { get { return _currentMode; } set { if (value != _currentMode) { switch (value) { case LineMode.Straight: _mode = new StraightLine(_mode); break; case LineMode.SimpleCurve: _mode = new SimpleCurve(_mode); break; case LineMode.Circle: _mode = new Circle(_mode); break; } _currentMode = value; } } } internal Entity SelectedEntity => _selectedEntity; private PrefabBase SelectedPrefab { set { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_00b8: 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) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) _selectedPrefab = (ObjectGeometryPrefab)(object)((value is ObjectGeometryPrefab) ? value : null); if (_selectedPrefab == null) { _selectedEntity = Entity.Null; return; } _selectedEntity = ((ToolBaseSystem)this).m_PrefabSystem.GetEntity((PrefabBase)(object)_selectedPrefab); _zBounds.min = 0f; _zBounds.max = 0f; ObjectMeshInfo[] meshes = _selectedPrefab.m_Meshes; for (int i = 0; i < meshes.Length; i++) { RenderPrefabBase mesh = meshes[i].m_Mesh; RenderPrefab val = (RenderPrefab)(object)((mesh is RenderPrefab) ? mesh : null); if (val != null) { ref Bounds1 zBounds = ref _zBounds; float min = _zBounds.min; Bounds3 bounds = val.bounds; zBounds.min = math.min(min, ((Bounds3)(ref bounds)).z.min); ref Bounds1 zBounds2 = ref _zBounds; float max = _zBounds.max; bounds = val.bounds; zBounds2.max = math.max(max, ((Bounds3)(ref bounds)).z.max); } } SaveXP(); } } public override void InitializeRaycast() { ((ToolBaseSystem)this).InitializeRaycast(); ((ToolBaseSystem)this).m_ToolRaycastSystem.typeMask = (TypeMask)1; } public override PrefabBase GetPrefab() { return (PrefabBase)(object)_selectedPrefab; } public override bool TrySetPrefab(PrefabBase prefab) { ToolBaseSystem previousTool = _previousTool; if (previousTool == null) { return false; } return previousTool.TrySetPrefab(prefab); } public override void ElevationUp() { Spacing = _spacing + 1f; } public override void ElevationDown() { Spacing = _spacing - 1f; } internal void EnableTool() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (((ToolBaseSystem)this).m_ToolSystem.activeTool != this) { _previousTool = ((ToolBaseSystem)this).m_ToolSystem.activeTool; SelectedPrefab = (PrefabBase)(object)((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ObjectToolSystem>().prefab; if ((Object)(object)_selectedPrefab != (Object)null) { ((ToolBaseSystem)this).m_ToolSystem.selected = Entity.Null; ((ToolBaseSystem)this).m_ToolSystem.activeTool = (ToolBaseSystem)(object)this; } } } internal void RestorePreviousTool() { if (_previousTool != null) { ((ToolBaseSystem)this).m_ToolSystem.activeTool = _previousTool; } else { _log.Error((object)"null tool set when restoring previous tool"); } } internal void RefreshTreeControl() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) ResetTreeState(_cursorEntity); for (int i = 0; i < _previewEntities.Length; i++) { ResetTreeState(_previewEntities[i]); } _dirty = true; } protected override void OnCreate() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_0102: 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_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) ((ObjectToolBaseSystem)this).OnCreate(); _log = Mod.Instance.Log; _terrainSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<TerrainSystem>(); JobHandle val = default(JobHandle); _overlayBuffer = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<OverlayRenderSystem>().GetBuffer(ref val); _currentMode = LineMode.Straight; _mode = new StraightLine(); _applyAction = InputManager.instance.FindAction("Tool", "Apply"); _cancelAction = InputManager.instance.FindAction("Tool", "Mouse Cancel"); _fixedPreviewAction = new InputAction("LineTool-FixPreview", (InputActionType)0, (string)null, (string)null, (string)null, (string)null); CompositeSyntax val2 = InputActionSetupExtensions.AddCompositeBinding(_fixedPreviewAction, "ButtonWithOneModifier", (string)null, (string)null); val2 = ((CompositeSyntax)(ref val2)).With("Modifier", "<Keyboard>/ctrl", (string)null, (string)null); ((CompositeSyntax)(ref val2)).With("Button", "<Mouse>/leftButton", (string)null, (string)null); _fixedPreviewAction.Enable(); _keepBuildingAction = new InputAction("LineTool-KeepBuilding", (InputActionType)0, (string)null, (string)null, (string)null, (string)null); val2 = InputActionSetupExtensions.AddCompositeBinding(_keepBuildingAction, "ButtonWithOneModifier", (string)null, (string)null); val2 = ((CompositeSyntax)(ref val2)).With("Modifier", "<Keyboard>/shift", (string)null, (string)null); ((CompositeSyntax)(ref val2)).With("Button", "<Mouse>/leftButton", (string)null, (string)null); _keepBuildingAction.Enable(); } protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) ((GameSystemBase)this).OnGameLoadingComplete(purpose, mode); ToolBaseSystem val = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ToolSystem>().tools.Find((ToolBaseSystem x) => x.toolID.Equals("Tree Controller Tool")); if (val != null) { _log.Info((object)"found tree controller"); _nextTreeState = ((object)val).GetType().GetProperty("NextTreeState"); if ((object)_nextTreeState != null) { _treeControllerTool = val; _log.Info((object)"reflected NextTreeState"); } } else { _log.Info((object)"tree controller tool not found"); } } protected override JobHandle OnUpdate(JobHandle inputDeps) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0475: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Unknown result type (might be due to invalid IL or missing references) //IL_04bd: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04d6: Unknown result type (might be due to invalid IL or missing references) //IL_04db: Unknown result type (might be due to invalid IL or missing references) //IL_044c: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04e8: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00c0: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_0513: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_0521: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) //IL_052f: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022b: 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_0208: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: 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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: 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_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0541: Unknown result type (might be due to invalid IL or missing references) //IL_054d: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_056d: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_057c: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0362: 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_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_0597: Unknown result type (might be due to invalid IL or missing references) //IL_059c: Unknown result type (might be due to invalid IL or missing references) //IL_058d: Unknown result type (might be due to invalid IL or missing references) //IL_0615: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023a: 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_0242: 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_05a1: Unknown result type (might be due to invalid IL or missing references) //IL_05a6: Unknown result type (might be due to invalid IL or missing references) //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05b0: Unknown result type (might be due to invalid IL or missing references) //IL_05b3: Unknown result type (might be due to invalid IL or missing references) //IL_05b8: Unknown result type (might be due to invalid IL or missing references) //IL_05bc: Unknown result type (might be due to invalid IL or missing references) //IL_05be: Unknown result type (might be due to invalid IL or missing references) //IL_05c6: Unknown result type (might be due to invalid IL or missing references) //IL_05cb: Unknown result type (might be due to invalid IL or missing references) //IL_05cf: Unknown result type (might be due to invalid IL or missing references) //IL_05d8: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_05e1: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_027b: 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_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) _tooltips.Clear(); if (_selectedPrefab == null) { return inputDeps; } float3 val = (_fixedPreview ? _fixedPos : _previousPos); EntityManager entityManager; Enumerator<Entity> enumerator; if (((ToolBaseSystem)this).GetRaycastResult(ref _raycastPoint)) { val = (_fixedPreview ? _fixedPos : _raycastPoint.m_HitPosition); _terrainHeightData = _terrainSystem.GetHeightData(false); val.y = TerrainUtils.SampleHeight(ref _terrainHeightData, val); if (_dragMode != 0) { if (_applyAction.WasReleasedThisFrame() || _fixedPreviewAction.WasReleasedThisFrame()) { _dragMode = DragMode.None; } else { if (_dragMode == DragMode.EndPos) { val = (_fixedPos = _raycastPoint.m_HitPosition); } else { _mode.HandleDrag(_dragMode, _raycastPoint.m_HitPosition); } _dirty = true; } } if (_cancelAction.WasPressedThisFrame()) { _mode.Reset(); enumerator = _previewEntities.GetEnumerator(); try { while (enumerator.MoveNext()) { Entity current = enumerator.Current; entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(current); } } finally { ((IDisposable)enumerator).Dispose(); } _previewEntities.Clear(); _dragMode = DragMode.None; return inputDeps; } if (_fixedPreviewAction.WasPressedThisFrame() && _mode.HasAllPoints) { if (_fixedPreview) { _dragMode = _mode.CheckDragHit(_raycastPoint.m_HitPosition); if (_dragMode != 0) { return inputDeps; } } else { _fixedPreview = true; _fixedPos = val; } } else if (_applyAction.WasPressedThisFrame() || _keepBuildingAction.WasPressedThisFrame()) { if (_fixedPreview) { _dragMode = _mode.CheckDragHit(_raycastPoint.m_HitPosition); if (_dragMode != 0) { return inputDeps; } _fixedPreview = false; } if (_mode.HandleClick(val)) { enumerator = _previewEntities.GetEnumerator(); try { while (enumerator.MoveNext()) { Entity current2 = enumerator.Current; entityManager = ((ComponentSystemBase)this).EntityManager; if (((EntityManager)(ref entityManager)).HasComponent<Overridden>(current2)) { entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(current2); continue; } entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).RemoveComponent<Highlighted>(current2); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Updated>(current2); } } finally { ((IDisposable)enumerator).Dispose(); } _previewEntities.Clear(); _mode.ItemsPlaced(val); if (!_keepBuildingAction.WasPressedThisFrame()) { _mode.Reset(); } return inputDeps; } } if (!_mode.HasStart) { if (val.x != _previousPos.x || val.z != _previousPos.z) { if (_cursorEntity != Entity.Null) { entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(_cursorEntity); } _cursorEntity = CreateEntity(); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Highlighted>(_cursorEntity); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).SetComponentData<Transform>(_cursorEntity, new Transform { m_Position = val, m_Rotation = GetEffectiveRotation(val) }); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<BatchesUpdated>(_cursorEntity); EnsureTreeState(_cursorEntity); _previousPos = val; } return inputDeps; } if (_cursorEntity != Entity.Null) { entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(_cursorEntity); _cursorEntity = Entity.Null; } } else if (_cursorEntity != Entity.Null) { entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(_cursorEntity); } _mode.DrawOverlay(_overlayBuffer, _tooltips); if (_fixedPreview) { _mode.DrawPointOverlays(_overlayBuffer); } if (!_dirty && val.x == _previousPos.x && val.z == _previousPos.y) { return inputDeps; } _previousPos = val; _dirty = false; _points.Clear(); _mode.CalculatePoints(val, _spacingMode, EffectiveSpacing, RandomSpacing, RandomOffset, _rotation, _zBounds, _points, ref _terrainHeightData); enumerator = _previewEntities.GetEnumerator(); try { while (enumerator.MoveNext()) { Entity current3 = enumerator.Current; entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(current3); } } finally { ((IDisposable)enumerator).Dispose(); } _previewEntities.Clear(); Enumerator<PointData> enumerator2 = _points.GetEnumerator(); try { while (enumerator2.MoveNext()) { PointData current4 = enumerator2.Current; Random.InitState((int)(current4.Position.x + current4.Position.y + current4.Position.z)); Transform val2 = default(Transform); val2.m_Position = current4.Position; val2.m_Rotation = (_randomRotation ? GetEffectiveRotation(current4.Position) : current4.Rotation); Transform val3 = val2; Entity val4 = CreateEntity(); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).SetComponentData<Transform>(val4, val3); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Highlighted>(val4); entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Updated>(val4); _previewEntities.Add(ref val4); } return inputDeps; } finally { ((IDisposable)enumerator2).Dispose(); } } protected override void OnStartRunning() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) _log.Debug((object)"OnStartRunning"); ((COSystemBase)this).OnStartRunning(); ((ComponentSystemBase)this).World.GetExistingSystemManaged<LineToolUISystem>().ClearTooltip(); _applyAction.shouldBeEnabled = true; _cancelAction.shouldBeEnabled = true; _raycastPoint = default(ControlPoint); _mode.Reset(); ((ToolBaseSystem)this).applyMode = (ApplyMode)2; } protected override void OnStopRunning() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) _log.Debug((object)"OnStopRunning"); _tooltips.Clear(); ((ComponentSystemBase)this).World.GetExistingSystemManaged<LineToolUISystem>().ClearTooltip(); _applyAction.shouldBeEnabled = false; _cancelAction.shouldBeEnabled = false; EntityManager entityManager; if (_cursorEntity != Entity.Null) { entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(_cursorEntity); _cursorEntity = Entity.Null; } Enumerator<Entity> enumerator = _previewEntities.GetEnumerator(); try { while (enumerator.MoveNext()) { Entity current = enumerator.Current; entityManager = ((ComponentSystemBase)this).EntityManager; ((EntityManager)(ref entityManager)).AddComponent<Deleted>(current); } } fin