Decompiled source of Aetherial Endeavors Fixes v0.1.6
patchers/ValCoopCompatibility.Patcher.dll
Decompiled 18 hours 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.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using System.Xml; using BepInEx; using BepInEx.Logging; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; [assembly: AssemblyTitle("Aetherial Endeavors Fixes")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyDescription("Verified startup repairs for the Aetherial Endeavors modpack.")] [assembly: AssemblyFileVersion("0.1.6.0")] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.1.6.0")] namespace ValCoopCompatibility; public static class AssemblyRepairs { public static string[] ReferenceDirectories = new string[0]; public static byte[] Repair(byte[] source, string repairId) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Expected O, but got Unknown DefaultAssemblyResolver val = new DefaultAssemblyResolver(); try { using MemoryStream memoryStream = new MemoryStream(source); string[] referenceDirectories = ReferenceDirectories; foreach (string text in referenceDirectories) { ((BaseAssemblyResolver)val).AddSearchDirectory(text); } ReaderParameters val2 = new ReaderParameters(); val2.AssemblyResolver = (IAssemblyResolver)(object)val; AssemblyDefinition val3 = AssemblyDefinition.ReadAssembly((Stream)memoryStream, val2); try { switch (repairId) { case "customattributes-leech": RepairLeech(val3.MainModule); break; case "dragonknight-helper": if (!((IEnumerable<MethodDefinition>)FindType(val3.MainModule, "LastStand.LastStandEffect").Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "ValCoop_MakeStatusEffectPrefab")) { RepairDragonKnight(val3.MainModule); } if (((IEnumerable<Instruction>)((IEnumerable<MethodDefinition>)FindType(val3.MainModule, "LastStand.LastStandEffect").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "OnPacksLoaded").Body.Instructions).Any((Instruction val5) => val5.OpCode == OpCodes.Ldstr && (string)val5.Operand == "LastStandEffect")) { ExtraRepairs.DragonIcon(val3.MainModule); } break; case "skiplogos-field": RepairSkipLogos(val3.MainModule); break; case "extended-event-log": ExtraRepairs.ExtendedEffects(val3.MainModule); break; case "npc-loot-iteration": ExtraRepairs.NpcLoot(val3.MainModule); break; case "sideloader-content": ExtraRepairs.SideLoader(val3.MainModule); break; case "vendavel-after-load": ExtraRepairs.VendavelAfterLoad(val3.MainModule); break; case "communicator-optional-overrides": ExtraRepairs.OptionalOverrides(val3.MainModule); break; case "enchantments-viewer-descriptions": Repairs015.Viewer(val3.MainModule); break; default: if (repairId.StartsWith("deferred-runic-")) { Repairs015.DeferredRunicVisuals(val3.MainModule); break; } switch (repairId) { case "crusader-effect-name": Repairs015.EffectName(val3.MainModule, "MakeOnConsecrationAllyPrefab"); break; case "relic-effect-name": Repairs015.EffectName(val3.MainModule, "MakeCurseOfVulnrability"); break; case "martial-owner": Repairs016.MartialOwner(val3.MainModule); break; case "banker-collision": Repairs016.Bank(val3.MainModule); break; case "flame-anor-tag": Repairs016.FlameTag(val3.MainModule); break; default: throw new InvalidOperationException("Unknown assembly repair: " + repairId); } break; } using MemoryStream memoryStream2 = new MemoryStream(); WriterParameters val4 = new WriterParameters(); val4.Timestamp = BitConverter.ToUInt32(source, BitConverter.ToInt32(source, 60) + 8); val3.Write((Stream)memoryStream2, val4); return memoryStream2.ToArray(); } finally { ((IDisposable)val3)?.Dispose(); } } finally { ((IDisposable)val)?.Dispose(); } } private static TypeDefinition FindType(ModuleDefinition module, string name) { TypeDefinition[] array = (from t in AllTypes((IEnumerable<TypeDefinition>)module.Types) where ((MemberReference)t).FullName == name select t).ToArray(); Require(array.Length == 1, "Expected one type: " + name); return array[0]; } private static IEnumerable<TypeDefinition> AllTypes(IEnumerable<TypeDefinition> types) { foreach (TypeDefinition type in types) { yield return type; foreach (TypeDefinition item in AllTypes((IEnumerable<TypeDefinition>)type.NestedTypes)) { yield return item; } } } public static void Require(bool condition, string message) { if (!condition) { throw new InvalidOperationException(message); } } public static void WidenBranches(MethodDefinition method) { //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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_002d: 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_006a: Expected I4, but got Unknown //IL_007b: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Invalid comparison between Unknown and I4 //IL_0130: Unknown result type (might be due to invalid IL or missing references) Enumerator<Instruction> enumerator = method.Body.Instructions.GetEnumerator(); try { while (enumerator.MoveNext()) { Instruction current = enumerator.Current; OpCode opCode = current.OpCode; Code code = ((OpCode)(ref opCode)).Code; switch (code - 42) { case 0: current.OpCode = OpCodes.Br; continue; case 2: current.OpCode = OpCodes.Brtrue; continue; case 1: current.OpCode = OpCodes.Brfalse; continue; case 3: current.OpCode = OpCodes.Beq; continue; case 8: current.OpCode = OpCodes.Bne_Un; continue; case 4: current.OpCode = OpCodes.Bge; continue; case 9: current.OpCode = OpCodes.Bge_Un; continue; case 5: current.OpCode = OpCodes.Bgt; continue; case 10: current.OpCode = OpCodes.Bgt_Un; continue; case 6: current.OpCode = OpCodes.Ble; continue; case 11: current.OpCode = OpCodes.Ble_Un; continue; case 7: current.OpCode = OpCodes.Blt; continue; case 12: current.OpCode = OpCodes.Blt_Un; continue; } if ((int)code == 188) { current.OpCode = OpCodes.Leave; } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } } private static void CopyBody(MethodDefinition from, MethodDefinition to) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_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_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Expected O, but got Unknown //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Expected O, but got Unknown //IL_01d8: Unknown result type (might be due to invalid IL or missing references) Require(from.Body.ExceptionHandlers.Count == 0, "Unexpected exception handler in template."); MethodBody val = (to.Body = new MethodBody(to)); val.InitLocals = from.Body.InitLocals; val.MaxStackSize = Math.Max(from.Body.MaxStackSize, 8); Dictionary<VariableDefinition, VariableDefinition> dictionary = new Dictionary<VariableDefinition, VariableDefinition>(); Enumerator<VariableDefinition> enumerator = from.Body.Variables.GetEnumerator(); try { while (enumerator.MoveNext()) { VariableDefinition current = enumerator.Current; VariableDefinition val3 = new VariableDefinition(((VariableReference)current).VariableType); dictionary.Add(current, val3); val.Variables.Add(val3); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } Dictionary<Instruction, Instruction> instructions = new Dictionary<Instruction, Instruction>(); Enumerator<Instruction> enumerator2 = from.Body.Instructions.GetEnumerator(); try { while (enumerator2.MoveNext()) { Instruction current2 = enumerator2.Current; Instruction val4 = Instruction.Create(OpCodes.Nop); val4.OpCode = current2.OpCode; instructions.Add(current2, val4); val.Instructions.Add(val4); } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } Enumerator<Instruction> enumerator3 = from.Body.Instructions.GetEnumerator(); try { while (enumerator3.MoveNext()) { Instruction current3 = enumerator3.Current; object obj = current3.Operand; if (obj is Instruction) { obj = instructions[(Instruction)obj]; } else if (obj is Instruction[]) { obj = ((Instruction[])obj).Select((Instruction i) => instructions[i]).ToArray(); } else if (obj is VariableDefinition) { obj = dictionary[(VariableDefinition)obj]; } else if (obj is ParameterDefinition) { obj = ((MethodReference)to).Parameters[((ParameterReference)(ParameterDefinition)obj).Index]; } instructions[current3].Operand = obj; } } finally { ((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose(); } WidenBranches(to); } private static void RepairLeech(ModuleDefinition module) { //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Expected O, but got Unknown //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Expected O, but got Unknown //IL_0374: 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_038e: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: 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_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0407: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_044b: 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_046b: 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_0494: 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_04c4: Unknown result type (might be due to invalid IL or missing references) //IL_052e: Unknown result type (might be due to invalid IL or missing references) //IL_0538: Expected O, but got Unknown //IL_054d: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_0565: Unknown result type (might be due to invalid IL or missing references) //IL_0571: Unknown result type (might be due to invalid IL or missing references) //IL_057f: 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) TypeDefinition val = FindType(module, "CustomAttributes.CustomAttributesBase"); TypeDefinition val2 = FindType(module, "CustomAttributes.CustomAttributeComponent"); TypeDefinition val3 = FindType(module, "CustomAttributes.CustomAttributeManager/Character_ReceiveHit"); FieldDefinition val4 = ((IEnumerable<FieldDefinition>)val.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "OnCharacterCritEvent"); FieldDefinition val5 = ((IEnumerable<FieldDefinition>)val.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "Instance"); Require(!((IEnumerable<FieldDefinition>)val.Fields).Any((FieldDefinition f) => ((MemberReference)f).Name == "OnCharacterLeechEvent"), "Leech event already exists."); GenericInstanceType eventType = default(GenericInstanceType); ref GenericInstanceType reference = ref eventType; TypeReference fieldType = ((FieldReference)val4).FieldType; reference = (GenericInstanceType)(object)((fieldType is GenericInstanceType) ? fieldType : null); Require(eventType != null && eventType.GenericArguments.Count == 3 && ((MemberReference)eventType.GenericArguments[2]).FullName == "System.Single", "Unexpected event signature."); FieldDefinition val6 = new FieldDefinition("OnCharacterLeechEvent", (FieldAttributes)6, (TypeReference)(object)eventType); val.Fields.Add(val6); MethodDefinition doLeech = ((IEnumerable<MethodDefinition>)val2.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "DoLeech" && ((MethodReference)m).Parameters.Count == 1); Require(((MemberReference)((ParameterReference)((MethodReference)doLeech).Parameters[0]).ParameterType).FullName == "System.Single", "Unexpected DoLeech signature."); MethodDefinition val7 = new MethodDefinition("ValCoop_DoLeechWithTarget", doLeech.Attributes, ((MethodReference)doLeech).ReturnType); ((MethodReference)val7).Parameters.Add(new ParameterDefinition("totalDamage", (ParameterAttributes)0, module.TypeSystem.Single)); ((MethodReference)val7).Parameters.Add(new ParameterDefinition("enemy", (ParameterAttributes)0, eventType.GenericArguments[1])); val2.Methods.Add(val7); CopyBody(doLeech, val7); Require(val7.Body.Variables.Count == 4 && ((MemberReference)((VariableReference)val7.Body.Variables[1]).VariableType).FullName == "System.Single", "Leech amount local changed."); MethodDefinition val8 = ((IEnumerable<MethodDefinition>)val2.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "get_parentPlayer"); MethodDefinition val9 = ((IEnumerable<MethodDefinition>)val3.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Prefix"); MethodReference[] array = (from m in ((IEnumerable<Instruction>)val9.Body.Instructions).Select(delegate(Instruction i) { object operand = i.Operand; return (MethodReference)((operand is MethodReference) ? operand : null); }) where m != null && ((MemberReference)m).Name == "Invoke" && ((MemberReference)((MemberReference)m).DeclaringType).FullName == ((MemberReference)eventType).FullName select m).ToArray(); Require(array.Length > 0, "Cannot reuse event Invoke signature."); Instruction[] array2 = ((IEnumerable<Instruction>)val7.Body.Instructions).Where(delegate(Instruction i) { object operand = i.Operand; MethodReference val16 = (MethodReference)((operand is MethodReference) ? operand : null); return val16 != null && ((MemberReference)((MemberReference)val16).DeclaringType).FullName == "CharacterStats" && (((MemberReference)val16).Name == "AffectStamina" || ((MemberReference)val16).Name == "RestaureMana"); }).ToArray(); Require(array2.Length == 2, "Expected two leech recovery branches."); ILProcessor iLProcessor = val7.Body.GetILProcessor(); Instruction[] array3 = array2; foreach (Instruction val10 in array3) { Instruction val11 = Instruction.Create(OpCodes.Nop); Instruction val12 = Instruction.Create(OpCodes.Ldfld, (FieldReference)(object)val6); Instruction val13 = Instruction.Create(OpCodes.Ldarg_0); Instruction[] array4 = (Instruction[])(object)new Instruction[19] { Instruction.Create(OpCodes.Ldloc, val7.Body.Variables[1]), Instruction.Create(OpCodes.Ldc_R4, 0f), Instruction.Create(OpCodes.Ble_Un, val11), Instruction.Create(OpCodes.Ldsfld, (FieldReference)(object)val5), Instruction.Create(OpCodes.Dup), Instruction.Create(OpCodes.Brtrue, val12), Instruction.Create(OpCodes.Pop), Instruction.Create(OpCodes.Br, val11), val12, Instruction.Create(OpCodes.Dup), Instruction.Create(OpCodes.Brtrue, val13), Instruction.Create(OpCodes.Pop), Instruction.Create(OpCodes.Br, val11), val13, Instruction.Create(OpCodes.Call, (MethodReference)(object)val8), Instruction.Create(OpCodes.Ldarg_2), Instruction.Create(OpCodes.Ldloc, val7.Body.Variables[1]), Instruction.Create(OpCodes.Callvirt, array[0]), val11 }; Instruction val14 = val10; Instruction[] array5 = array4; foreach (Instruction val15 in array5) { iLProcessor.InsertAfter(val14, val15); val14 = val15; } } doLeech.Body = new MethodBody(doLeech); ILProcessor iLProcessor2 = doLeech.Body.GetILProcessor(); iLProcessor2.Emit(OpCodes.Ldarg_0); iLProcessor2.Emit(OpCodes.Ldarg_1); iLProcessor2.Emit(OpCodes.Ldnull); iLProcessor2.Emit(OpCodes.Call, (MethodReference)(object)val7); iLProcessor2.Emit(OpCodes.Ret); Instruction[] array6 = ((IEnumerable<Instruction>)val9.Body.Instructions).Where(delegate(Instruction i) { object operand = i.Operand; MethodReference val16 = (MethodReference)((operand is MethodReference) ? operand : null); return val16 != null && ((MemberReference)val16).FullName == ((MemberReference)doLeech).FullName; }).ToArray(); Require(array6.Length == 1 && ((MemberReference)((ParameterReference)((MethodReference)val9).Parameters[0]).ParameterType).FullName == "Character", "Expected one player-hit leech call."); val9.Body.GetILProcessor().InsertBefore(array6[0], Instruction.Create(OpCodes.Ldarg, ((MethodReference)val9).Parameters[0])); array6[0].Operand = val7; WidenBranches(val9); } private static void RepairDragonKnight(ModuleDefinition module) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_017b: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = FindType(module, "LastStand.LastStandEffect"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "MakeLastStandDamagePrefab"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "MakeStatusEffectPrefab"); MethodReference val4 = (MethodReference)val3.Operand; Require(val4.Parameters.Count == 13 && ((MemberReference)val4.ReturnType).FullName == "StatusEffect", "Unexpected helper call."); MethodDefinition val5 = new MethodDefinition("ValCoop_MakeStatusEffectPrefab", (MethodAttributes)17, val4.ReturnType); Enumerator<ParameterDefinition> enumerator = val4.Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; ((MethodReference)val5).Parameters.Add(new ParameterDefinition(((ParameterReference)current).Name, (ParameterAttributes)0, ((ParameterReference)current).ParameterType)); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } val.Methods.Add(val5); val5.Body.InitLocals = true; VariableDefinition val6 = new VariableDefinition(module.ImportReference(typeof(MethodInfo))); val5.Body.Variables.Add(val6); ILProcessor iLProcessor = val5.Body.GetILProcessor(); Instruction val7 = Instruction.Create(OpCodes.Nop); Instruction val8 = Instruction.Create(OpCodes.Nop); EmitFindHelper(module, iLProcessor, val4, newSignature: true); iLProcessor.Emit(OpCodes.Stloc, val6); iLProcessor.Emit(OpCodes.Ldloc, val6); iLProcessor.Emit(OpCodes.Brfalse, val7); EmitInvokeHelper(module, iLProcessor, val5, val6, newSignature: true); iLProcessor.Append(val7); EmitFindHelper(module, iLProcessor, val4, newSignature: false); iLProcessor.Emit(OpCodes.Stloc, val6); iLProcessor.Emit(OpCodes.Ldloc, val6); iLProcessor.Emit(OpCodes.Brfalse, val8); EmitInvokeHelper(module, iLProcessor, val5, val6, newSignature: false); iLProcessor.Append(val8); iLProcessor.Emit(OpCodes.Ldstr, "ValCoop: TinyHelper exposes neither supported status-effect factory signature."); iLProcessor.Emit(OpCodes.Newobj, module.ImportReference((MethodBase)typeof(MissingMethodException).GetConstructor(new Type[1] { typeof(string) }))); iLProcessor.Emit(OpCodes.Throw); val3.Operand = val5; } private static void EmitFindHelper(ModuleDefinition module, ILProcessor il, MethodReference original, bool newSignature) { //IL_001c: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0086: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) MethodReference val = module.ImportReference((MethodBase)typeof(Type).GetMethod("GetTypeFromHandle")); il.Emit(OpCodes.Ldtoken, ((MemberReference)original).DeclaringType); il.Emit(OpCodes.Call, val); il.Emit(OpCodes.Ldstr, "MakeStatusEffectPrefab"); il.Emit(OpCodes.Ldc_I4, original.Parameters.Count + (newSignature ? 1 : 0)); il.Emit(OpCodes.Newarr, module.ImportReference(typeof(Type))); for (int i = 0; i < original.Parameters.Count + (newSignature ? 1 : 0); i++) { il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldtoken, (i < original.Parameters.Count) ? ((ParameterReference)original.Parameters[i]).ParameterType : module.TypeSystem.String); il.Emit(OpCodes.Call, val); il.Emit(OpCodes.Stelem_Ref); } il.Emit(OpCodes.Callvirt, module.ImportReference((MethodBase)typeof(Type).GetMethod("GetMethod", new Type[2] { typeof(string), typeof(Type[]) }))); } private static void EmitInvokeHelper(ModuleDefinition module, ILProcessor il, MethodDefinition bridge, VariableDefinition info, bool newSignature) { //IL_0001: 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_0018: 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_005e: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) il.Emit(OpCodes.Ldloc, info); il.Emit(OpCodes.Ldnull); il.Emit(OpCodes.Ldc_I4, ((MethodReference)bridge).Parameters.Count + (newSignature ? 1 : 0)); il.Emit(OpCodes.Newarr, module.TypeSystem.Object); for (int i = 0; i < ((MethodReference)bridge).Parameters.Count; i++) { ParameterDefinition val = ((MethodReference)bridge).Parameters[i]; il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldarg, val); if (((ParameterReference)val).ParameterType.IsValueType) { il.Emit(OpCodes.Box, ((ParameterReference)val).ParameterType); } il.Emit(OpCodes.Stelem_Ref); } il.Emit(OpCodes.Callvirt, module.ImportReference((MethodBase)typeof(MethodBase).GetMethod("Invoke", new Type[2] { typeof(object), typeof(object[]) }))); il.Emit(OpCodes.Castclass, ((MethodReference)bridge).ReturnType); il.Emit(OpCodes.Ret); } private static void RepairSkipLogos(ModuleDefinition module) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0174: 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_0192: 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) TypeDefinition val = FindType(module, "SkipLogos.SkipLogos"); FieldDefinition field = ((IEnumerable<FieldDefinition>)val.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "fieldStartupVideoDone"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Awake"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single(delegate(Instruction i) { //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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_002f: Unknown result type (might be due to invalid IL or missing references) OpCode opCode = i.OpCode; return (int)((OpCode)(ref opCode)).Code == 37 && i.Previous.Operand is MethodReference && ((MemberReference)(MethodReference)i.Previous.Operand).Name == "GetField"; }); val3.OpCode = OpCodes.Stsfld; val3.Operand = field; MethodDefinition[] array = (from t in (IEnumerable<TypeDefinition>)val.NestedTypes where ((MemberReference)t).Name == "StartupVideo_Awake" || ((MemberReference)t).Name == "StartupVideo_Start" select ((IEnumerable<MethodDefinition>)t.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Patch")).ToArray(); Require(array.Length == 2, "Expected two startup hooks."); MethodDefinition[] array2 = array; foreach (MethodDefinition val4 in array2) { Instruction val5 = ((IEnumerable<Instruction>)val4.Body.Instructions).Single(delegate(Instruction i) { //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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) OpCode opCode = i.OpCode; return (int)((OpCode)(ref opCode)).Code == 123 && ((MemberReference)(FieldReference)i.Operand).Name == ((MemberReference)field).Name; }); ILProcessor iLProcessor = val4.Body.GetILProcessor(); Instruction next = val5.Next; Instruction val6 = val5; Instruction[] array3 = (Instruction[])(object)new Instruction[4] { Instruction.Create(OpCodes.Dup), Instruction.Create(OpCodes.Brtrue, next), Instruction.Create(OpCodes.Pop), Instruction.Create(OpCodes.Ret) }; foreach (Instruction val7 in array3) { iLProcessor.InsertAfter(val6, val7); val6 = val7; } WidenBranches(val4); } } } public static class ExtraRepairs { private static void Require(bool ok, string message) { AssemblyRepairs.Require(ok, message); } public static void VendavelAfterLoad(ModuleDefinition module) { //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: 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_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) MethodDefinition val = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "QuestsOfAurai.Vendavel.VendavelQuest").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "AfterLoad"); MethodReference val2 = module.GetMemberReferences().OfType<MethodReference>().First((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "UnityEngine.Object" && ((MemberReference)m).Name == "op_Implicit"); Instruction[] array = val.Body.Instructions.ToArray(); Instruction[] array2 = array; foreach (Instruction val3 in array2) { object operand = val3.Operand; MethodReference val4 = (MethodReference)((operand is MethodReference) ? operand : null); bool flag = false; bool flag2 = false; if (val3.OpCode == OpCodes.Ldsfld && ((MemberReference)((MemberReference)(FieldReference)val3.Operand).DeclaringType).Name == "CharacterManager") { flag2 = true; flag = true; } if (val4 != null && (((MemberReference)val4).Name == "GetWorldHostCharacter" || ((MemberReference)val4).Name == "GetComponent")) { flag2 = true; flag = true; } if (val4 != null && (((MemberReference)val4).Name == "get_Inventory" || ((MemberReference)val4).Name == "get_QuestKnowledge")) { flag2 = true; } if (val3.OpCode == OpCodes.Isinst && ((MemberReference)(TypeReference)val3.Operand).Name == "Quest") { flag2 = true; flag = true; } if (!flag2) { continue; } Instruction next = val3.Next; ILProcessor iLProcessor = val.Body.GetILProcessor(); Instruction val5 = val3; List<Instruction> list = new List<Instruction>(); list.Add(Instruction.Create(OpCodes.Dup)); List<Instruction> list2 = list; if (flag) { list2.Add(Instruction.Create(OpCodes.Call, val2)); } list2.Add(Instruction.Create(OpCodes.Brtrue, next)); list2.Add(Instruction.Create(OpCodes.Pop)); list2.Add(Instruction.Create(OpCodes.Ret)); foreach (Instruction item in list2) { iLProcessor.InsertAfter(val5, item); val5 = item; } } AssemblyRepairs.WidenBranches(val); } public static void OptionalOverrides(ModuleDefinition module) { //IL_00cb: 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_00e7: 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) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "OutwardModsCommunicator.OMC"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)val.NestedTypes).Single((TypeDefinition t) => ((MemberReference)t).Name == "ResourcesPrefabManager_Load").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Postfix"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "GetPlayerOverrideLocation"); Instruction next = val3.Next.Next.Next; Require(next.Operand is MethodReference && ((MemberReference)(MethodReference)next.Operand).Name == "IsNullOrEmpty" && next.Next.OpCode == OpCodes.Brtrue_S, "Unexpected optional override check"); next.Operand = module.ImportReference((MethodBase)typeof(File).GetMethod("Exists", new Type[1] { typeof(string) })); next.Next.OpCode = OpCodes.Brfalse; AssemblyRepairs.WidenBranches(val2); } public static void DragonIcon(ModuleDefinition module) { TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "LastStand.LastStandEffect"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "OnPacksLoaded"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.OpCode == OpCodes.Ldstr && (string)i.Operand == "LastStandEffect"); val3.Operand = "SaintDE-DragonKnight"; } public static void ExtendedEffects(ModuleDefinition module) { //IL_0086: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader_ExtendedEffects.Containers.Triggers.TriggeredEffect`1"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ActivateLocally"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.OpCode == OpCodes.Ldstr && (string)i.Operand == "Event already registered"); Require(val3.Previous.OpCode == OpCodes.Call && val3.Next.OpCode == OpCodes.Callvirt, "Unexpected duplicate-registration branch"); Instruction[] array = (Instruction[])(object)new Instruction[3] { val3.Previous, val3, val3.Next }; foreach (Instruction val4 in array) { val4.OpCode = OpCodes.Nop; val4.Operand = null; } } public static void NpcLoot(ModuleDefinition module) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0105: 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_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0245: 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_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: 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) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "JohBenjiNPCWeapons.JohBenjiNPCWeapons"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "SL_OnPacksLoaded"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "get_Keys"); TypeReference declaringType = ((MemberReference)(MethodReference)val3.Operand).DeclaringType; Require(declaringType is GenericInstanceType && ((MemberReference)declaringType).Name.StartsWith("Dictionary`"), "Unexpected loot dictionary type"); Type typeFromHandle = typeof(Dictionary<, >); ConstructorInfo constructorInfo = typeFromHandle.GetConstructors().Single((ConstructorInfo c) => c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType.Name == "IDictionary`2"); MethodReference val4 = module.ImportReference((MethodBase)constructorInfo); ((MemberReference)val4).DeclaringType = declaringType; if (val3.Previous.OpCode != OpCodes.Newobj) { val2.Body.GetILProcessor().InsertBefore(val3, Instruction.Create(OpCodes.Newobj, val4)); } AssemblyRepairs.WidenBranches(val2); string[] array = new string[2] { "BloodSpearPatch", "BloodSwordPatch" }; foreach (string name in array) { Collection<TypeDefinition> types = module.Types; Func<TypeDefinition, bool> predicate = (TypeDefinition t) => ((MemberReference)t).Name == name; MethodDefinition val5 = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)types).Single(predicate).Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "PatchItem"); Instruction val6 = ((IEnumerable<Instruction>)val5.Body.Instructions).Single((Instruction i) => i.Operand is GenericInstanceMethod && ((MemberReference)(GenericInstanceMethod)i.Operand).Name == "AddComponent" && ((MemberReference)((GenericInstanceMethod)i.Operand).GenericArguments[0]).Name == "ItemInteraction"); VariableDefinition operand = ((IEnumerable<VariableDefinition>)val5.Body.Variables).Single((VariableDefinition v) => ((MemberReference)((VariableReference)v).VariableType).Name == "InteractionTake"); Require(val6.Previous.OpCode == OpCodes.Ldloc_0, "Unexpected blood weapon interaction receiver"); val6.Previous.OpCode = OpCodes.Ldloc; val6.Previous.Operand = operand; val6.OpCode = OpCodes.Nop; val6.Operand = null; } MethodDefinition val7 = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).Name == "DTAppend").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Apply"); VariableDefinition val8 = ((IEnumerable<VariableDefinition>)val7.Body.Variables).Single((VariableDefinition v) => ((MemberReference)((VariableReference)v).VariableType).FullName == "Character"); Instruction val9 = ((IEnumerable<Instruction>)val7.Body.Instructions).First((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "get_gameObject"); Instruction val10 = ((IEnumerable<Instruction>)val7.Body.Instructions).Last((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "MoveNext"); Instruction previous = val10.Previous; MethodReference val11 = module.GetMemberReferences().OfType<MethodReference>().First((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "UnityEngine.Object" && ((MemberReference)m).Name == "op_Implicit"); Instruction previous2 = val9.Previous; ILProcessor iLProcessor = val7.Body.GetILProcessor(); iLProcessor.InsertBefore(previous2, Instruction.Create(OpCodes.Ldloc, val8)); iLProcessor.InsertBefore(previous2, Instruction.Create(OpCodes.Call, val11)); iLProcessor.InsertBefore(previous2, Instruction.Create(OpCodes.Brfalse, previous)); AssemblyRepairs.WidenBranches(val7); } private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> types) { foreach (TypeDefinition t in types) { yield return t; foreach (TypeDefinition item in Types((IEnumerable<TypeDefinition>)t.NestedTypes)) { yield return item; } } } private static TypeDefinition InjectSupport(ModuleDefinition target) { //IL_0127: 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_013e: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0187: 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) //IL_01a3: Expected O, but got Unknown //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Expected O, but got Unknown //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Expected O, but got Unknown //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Expected O, but got Unknown //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_06ee: Unknown result type (might be due to invalid IL or missing references) //IL_06f3: 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_0385: Expected O, but got Unknown //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_0733: Unknown result type (might be due to invalid IL or missing references) //IL_0738: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_0762: Unknown result type (might be due to invalid IL or missing references) //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0457: Unknown result type (might be due to invalid IL or missing references) //IL_07ac: Unknown result type (might be due to invalid IL or missing references) //IL_07b1: Unknown result type (might be due to invalid IL or missing references) //IL_0482: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Expected O, but got Unknown //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_04d6: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Expected O, but got Unknown //IL_04f6: Unknown result type (might be due to invalid IL or missing references) //IL_05ba: Unknown result type (might be due to invalid IL or missing references) //IL_05bf: Unknown result type (might be due to invalid IL or missing references) //IL_05c6: Expected O, but got Unknown //IL_07f6: Unknown result type (might be due to invalid IL or missing references) //IL_07fb: Unknown result type (might be due to invalid IL or missing references) //IL_0515: Unknown result type (might be due to invalid IL or missing references) //IL_051f: Expected O, but got Unknown //IL_052f: Unknown result type (might be due to invalid IL or missing references) //IL_0539: Expected O, but got Unknown //IL_0549: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Expected O, but got Unknown //IL_084a: Unknown result type (might be due to invalid IL or missing references) //IL_084f: Unknown result type (might be due to invalid IL or missing references) //IL_08dc: Unknown result type (might be due to invalid IL or missing references) //IL_08e6: Expected O, but got Unknown Dictionary<string, IMetadataScope> known = (from t in target.GetTypeReferences() group t by ((MemberReference)t).FullName).ToDictionary((IGrouping<string, TypeReference> g) => g.Key, (IGrouping<string, TypeReference> g) => g.First().Scope); foreach (TypeDefinition item in Types((IEnumerable<TypeDefinition>)target.Types)) { known[((MemberReference)item).FullName] = (IMetadataScope)(object)target; } using Stream stream = typeof(ExtraRepairs).Assembly.GetManifestResourceStream("InjectionTemplate.dll"); AssemblyDefinition val = AssemblyDefinition.ReadAssembly(stream); try { TypeDefinition val2 = ((IEnumerable<TypeDefinition>)val.MainModule.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "AetherialInjected.Support"); TypeDefinition val3 = new TypeDefinition(((TypeReference)val2).Namespace, ((MemberReference)val2).Name, val2.Attributes, target.TypeSystem.Object); target.Types.Add(val3); known[((MemberReference)val3).FullName] = (IMetadataScope)(object)target; Enumerator<FieldDefinition> enumerator2 = val2.Fields.GetEnumerator(); try { while (enumerator2.MoveNext()) { FieldDefinition current2 = enumerator2.Current; val3.Fields.Add(new FieldDefinition(((MemberReference)current2).Name, current2.Attributes, target.ImportReference(((FieldReference)current2).FieldType))); } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } Enumerator<MethodDefinition> enumerator3 = val2.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition current3 = enumerator3.Current; MethodDefinition val4 = new MethodDefinition(((MemberReference)current3).Name, current3.Attributes, target.ImportReference(((MethodReference)current3).ReturnType)); Enumerator<ParameterDefinition> enumerator4 = ((MethodReference)current3).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current; ((MethodReference)val4).Parameters.Add(new ParameterDefinition(((ParameterReference)current4).Name, current4.Attributes, target.ImportReference(((ParameterReference)current4).ParameterType))); } } finally { ((IDisposable)enumerator4/*cast due to .constrained prefix*/).Dispose(); } val3.Methods.Add(val4); } } finally { ((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose(); } Enumerator<MethodDefinition> enumerator5 = val2.Methods.GetEnumerator(); try { while (enumerator5.MoveNext()) { MethodDefinition oldMethod = enumerator5.Current; Collection<MethodDefinition> methods = val3.Methods; Func<MethodDefinition, bool> predicate = (MethodDefinition x) => ((MemberReference)x).Name == ((MemberReference)oldMethod).Name; MethodDefinition val5 = ((IEnumerable<MethodDefinition>)methods).Single(predicate); MethodBody val6 = new MethodBody(val5); val6.InitLocals = oldMethod.Body.InitLocals; val6.MaxStackSize = oldMethod.Body.MaxStackSize; val5.Body = val6; Dictionary<VariableDefinition, VariableDefinition> dictionary = new Dictionary<VariableDefinition, VariableDefinition>(); Enumerator<VariableDefinition> enumerator6 = oldMethod.Body.Variables.GetEnumerator(); try { while (enumerator6.MoveNext()) { VariableDefinition current5 = enumerator6.Current; VariableDefinition val7 = (dictionary[current5] = new VariableDefinition(target.ImportReference(((VariableReference)current5).VariableType))); val5.Body.Variables.Add(val7); } } finally { ((IDisposable)enumerator6/*cast due to .constrained prefix*/).Dispose(); } Dictionary<Instruction, Instruction> ins = new Dictionary<Instruction, Instruction>(); Enumerator<Instruction> enumerator7 = oldMethod.Body.Instructions.GetEnumerator(); try { while (enumerator7.MoveNext()) { Instruction current6 = enumerator7.Current; Instruction val9 = Instruction.Create(OpCodes.Nop); val9.OpCode = current6.OpCode; ins[current6] = val9; val5.Body.Instructions.Add(val9); } } finally { ((IDisposable)enumerator7/*cast due to .constrained prefix*/).Dispose(); } Enumerator<Instruction> enumerator8 = oldMethod.Body.Instructions.GetEnumerator(); try { while (enumerator8.MoveNext()) { Instruction current7 = enumerator8.Current; object obj = current7.Operand; if (obj is Instruction) { obj = ins[(Instruction)obj]; } else if (obj is Instruction[]) { obj = ((Instruction[])obj).Select((Instruction x) => ins[x]).ToArray(); } else if (obj is VariableDefinition) { obj = dictionary[(VariableDefinition)obj]; } else if (obj is ParameterDefinition) { obj = ((MethodReference)val5).Parameters[((ParameterReference)(ParameterDefinition)obj).Index]; } else if (obj is MethodReference) { obj = target.ImportReference((MethodReference)obj); } else if (obj is FieldReference) { obj = target.ImportReference((FieldReference)obj); } else if (obj is TypeReference) { obj = target.ImportReference((TypeReference)obj); } ins[current7].Operand = obj; } } finally { ((IDisposable)enumerator8/*cast due to .constrained prefix*/).Dispose(); } Enumerator<ExceptionHandler> enumerator9 = oldMethod.Body.ExceptionHandlers.GetEnumerator(); try { while (enumerator9.MoveNext()) { ExceptionHandler current8 = enumerator9.Current; Collection<ExceptionHandler> exceptionHandlers = val5.Body.ExceptionHandlers; ExceptionHandler val10 = new ExceptionHandler(current8.HandlerType); val10.TryStart = ins[current8.TryStart]; val10.TryEnd = ((current8.TryEnd == null) ? null : ins[current8.TryEnd]); val10.HandlerStart = ins[current8.HandlerStart]; val10.HandlerEnd = ((current8.HandlerEnd == null) ? null : ins[current8.HandlerEnd]); val10.FilterStart = ((current8.FilterStart == null) ? null : ins[current8.FilterStart]); val10.CatchType = ((current8.CatchType == null) ? null : target.ImportReference(current8.CatchType)); exceptionHandlers.Add(val10); } } finally { ((IDisposable)enumerator9/*cast due to .constrained prefix*/).Dispose(); } } } finally { ((IDisposable)enumerator5/*cast due to .constrained prefix*/).Dispose(); } Action<TypeReference> map = null; map = delegate(TypeReference t) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (t != null && !(t is GenericParameter) && !(t is TypeDefinition)) { GenericInstanceType val14 = (GenericInstanceType)(object)((t is GenericInstanceType) ? t : null); if (val14 != null) { Enumerator<TypeReference> enumerator16 = val14.GenericArguments.GetEnumerator(); try { while (enumerator16.MoveNext()) { TypeReference current15 = enumerator16.Current; map(current15); } } finally { ((IDisposable)enumerator16/*cast due to .constrained prefix*/).Dispose(); } } TypeSpecification val15 = (TypeSpecification)(object)((t is TypeSpecification) ? t : null); if (val15 != null) { map(val15.ElementType); } else { if (((MemberReference)t).DeclaringType != null) { map(((MemberReference)t).DeclaringType); } if (known.TryGetValue(((MemberReference)t).FullName, out var value)) { t.Scope = value; } else { Require(t.Scope.Name != "InjectionTemplate", "Unknown injected type " + ((MemberReference)t).FullName); } } } }; Enumerator<FieldDefinition> enumerator10 = val3.Fields.GetEnumerator(); try { while (enumerator10.MoveNext()) { FieldDefinition current9 = enumerator10.Current; map(((FieldReference)current9).FieldType); } } finally { ((IDisposable)enumerator10/*cast due to .constrained prefix*/).Dispose(); } Enumerator<MethodDefinition> enumerator11 = val3.Methods.GetEnumerator(); try { while (enumerator11.MoveNext()) { MethodDefinition current10 = enumerator11.Current; map(((MethodReference)current10).ReturnType); Enumerator<ParameterDefinition> enumerator12 = ((MethodReference)current10).Parameters.GetEnumerator(); try { while (enumerator12.MoveNext()) { ParameterDefinition current11 = enumerator12.Current; map(((ParameterReference)current11).ParameterType); } } finally { ((IDisposable)enumerator12/*cast due to .constrained prefix*/).Dispose(); } Enumerator<VariableDefinition> enumerator13 = current10.Body.Variables.GetEnumerator(); try { while (enumerator13.MoveNext()) { VariableDefinition current12 = enumerator13.Current; map(((VariableReference)current12).VariableType); } } finally { ((IDisposable)enumerator13/*cast due to .constrained prefix*/).Dispose(); } Enumerator<Instruction> enumerator14 = current10.Body.Instructions.GetEnumerator(); try { while (enumerator14.MoveNext()) { Instruction current13 = enumerator14.Current; object operand = current13.Operand; MethodReference val11 = (MethodReference)((operand is MethodReference) ? operand : null); if (val11 != null) { map(((MemberReference)val11).DeclaringType); map(val11.ReturnType); Enumerator<ParameterDefinition> enumerator15 = val11.Parameters.GetEnumerator(); try { while (enumerator15.MoveNext()) { ParameterDefinition current14 = enumerator15.Current; map(((ParameterReference)current14).ParameterType); } } finally { ((IDisposable)enumerator15/*cast due to .constrained prefix*/).Dispose(); } } object operand2 = current13.Operand; FieldReference val12 = (FieldReference)((operand2 is FieldReference) ? operand2 : null); if (val12 != null) { map(((MemberReference)val12).DeclaringType); map(val12.FieldType); } if (current13.Operand is TypeReference) { map((TypeReference)current13.Operand); } } } finally { ((IDisposable)enumerator14/*cast due to .constrained prefix*/).Dispose(); } } } finally { ((IDisposable)enumerator11/*cast due to .constrained prefix*/).Dispose(); } AssemblyNameReference[] array = ((IEnumerable<AssemblyNameReference>)target.AssemblyReferences).Where((AssemblyNameReference r) => r.Name == "InjectionTemplate").ToArray(); foreach (AssemblyNameReference val13 in array) { target.AssemblyReferences.Remove(val13); } return val3; } finally { ((IDisposable)val)?.Dispose(); } } public static void SideLoader(ModuleDefinition module) { //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0262: 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_0288: 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) if (((IEnumerable<TypeDefinition>)module.Types).Any((TypeDefinition t) => ((MemberReference)t).FullName == "AetherialInjected.Support")) { FullExceptions(module); RandomStatusSettings(module); Repairs014.SideLoader(module); Repairs015.SideLoader(module); Repairs016.SideLoader(module); return; } TypeDefinition val = InjectSupport(module); TypeDefinition val2 = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SLPacks.SLPackManager"); MethodDefinition val3 = ((IEnumerable<MethodDefinition>)val2.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "LoadBaseSLPacks"); Instruction val4 = ((IEnumerable<Instruction>)val3.Body.Instructions).First((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).FullName.Contains("System.IO.Directory::GetDirectories")); val4.Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "PackDirectories"); Instruction val5 = ((IEnumerable<Instruction>)val3.Body.Instructions).First((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name.Contains("g__AddSLPack")); Instruction previous = val5.Previous.Previous; Require(previous.Operand is MethodReference && ((MemberReference)(MethodReference)previous.Operand).Name == "GetFileName", "Unexpected pack folder argument"); previous.Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "PackFolderName"); TypeDefinition val6 = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_CharacterTrainer"); MethodDefinition val7 = ((IEnumerable<MethodDefinition>)val6.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ApplyToCharacter"); Instruction val8 = ((IEnumerable<Instruction>)val7.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "ConnectNodes"); FieldDefinition val9 = ((IEnumerable<FieldDefinition>)val6.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "SkillTree"); ILProcessor iLProcessor = val7.Body.GetILProcessor(); iLProcessor.InsertBefore(val8, Instruction.Create(OpCodes.Ldarg_0)); iLProcessor.InsertBefore(val8, Instruction.Create(OpCodes.Ldfld, (FieldReference)(object)val9)); val8.OpCode = OpCodes.Call; val8.Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ConnectTrainer"); AssemblyRepairs.WidenBranches(val7); TypeDefinition val10 = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SLPack"); MethodDefinition val11 = ((IEnumerable<MethodDefinition>)val10.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "LoadAssetBundle"); ((IEnumerable<Instruction>)val11.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "LoadFromFile").Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "LoadScrollBundle"); TypeDefinition val12 = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_Item"); MethodDefinition val13 = ((IEnumerable<MethodDefinition>)val12.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ApplyTexAndMats"); Instruction val14 = ((IEnumerable<Instruction>)val13.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "get_Item" && ((MemberReference)((MemberReference)(MethodReference)i.Operand).DeclaringType).FullName == "System.Collections.Generic.Dictionary`2<System.String,System.Collections.Generic.List`1<UnityEngine.Texture2D>>"); val14.OpCode = OpCodes.Call; val14.Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "MaterialTextures"); FullExceptions(module); RandomStatusSettings(module); Repairs014.SideLoader(module); Repairs015.SideLoader(module); Repairs016.SideLoader(module); } private static void RandomStatusSettings(ModuleDefinition module) { //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0197: 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_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: 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_0215: 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_023c: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_AddStatusEffect"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ApplyToComponent"); TypeDefinition random = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_AddStatusEffectRandom"); if (!((IEnumerable<Instruction>)val2.Body.Instructions).Any((Instruction i) => i.OpCode == OpCodes.Isinst && i.Operand is TypeReference && ((MemberReference)(TypeReference)i.Operand).FullName == ((MemberReference)random).FullName)) { FieldDefinition val3 = ((IEnumerable<FieldDefinition>)val.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "StatusEffect"); Instruction previous = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.OpCode == OpCodes.Ldfld && ((MemberReference)(FieldReference)i.Operand).FullName.Contains("::NoDealer")).Previous.Previous; VariableDefinition val4 = ((IEnumerable<VariableDefinition>)val2.Body.Variables).Single((VariableDefinition v) => ((MemberReference)((VariableReference)v).VariableType).FullName == "AddStatusEffect"); Instruction val5 = val2.Body.Instructions[0]; ILProcessor iLProcessor = val2.Body.GetILProcessor(); Instruction[] array = (Instruction[])(object)new Instruction[12] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Isinst, (TypeReference)(object)random), Instruction.Create(OpCodes.Brfalse, val5), Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldfld, (FieldReference)(object)val3), Instruction.Create(OpCodes.Call, module.ImportReference((MethodBase)typeof(string).GetMethod("IsNullOrEmpty"))), Instruction.Create(OpCodes.Brfalse, val5), Instruction.Create(OpCodes.Ldarg_1), Instruction.Create(OpCodes.Box, (TypeReference)(object)((MethodReference)val2).GenericParameters[0]), Instruction.Create(OpCodes.Isinst, ((VariableReference)val4).VariableType), Instruction.Create(OpCodes.Stloc, val4), Instruction.Create(OpCodes.Br, previous) }; foreach (Instruction val6 in array) { iLProcessor.InsertBefore(val5, val6); } AssemblyRepairs.WidenBranches(val2); } } private static void FullExceptions(ModuleDefinition module) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "LogInnerException"); MethodDefinition val3 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "LogWarning" && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "System.String"); val2.Body = new MethodBody(val2); ILProcessor iLProcessor = val2.Body.GetILProcessor(); Instruction val4 = Instruction.Create(OpCodes.Ret); iLProcessor.Append(Instruction.Create(OpCodes.Ldarg_0)); iLProcessor.Append(Instruction.Create(OpCodes.Brfalse, val4)); iLProcessor.Append(Instruction.Create(OpCodes.Ldarg_0)); iLProcessor.Append(Instruction.Create(OpCodes.Callvirt, module.ImportReference((MethodBase)typeof(Exception).GetMethod("ToString", Type.EmptyTypes)))); iLProcessor.Append(Instruction.Create(OpCodes.Call, (MethodReference)(object)val3)); iLProcessor.Append(val4); } } public static class Repairs014 { public static void SideLoader(ModuleDefinition module) { OptionalShadowRecipes(module); LateApplyContext(module); } private static void OptionalShadowRecipes(ModuleDefinition module) { //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: 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_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: 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_030a: Unknown result type (might be due to invalid IL or missing references) //IL_0318: 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_0337: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_035c: 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_037f: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: 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_03ee: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_Recipe"); if (!((IEnumerable<MethodDefinition>)val.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "Aetherial_OptionalRecipeReady")) { MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Internal_ApplyRecipe"); FieldDefinition val3 = ((IEnumerable<FieldDefinition>)val.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "UID"); MethodReference[] source = (from m in ((IEnumerable<Instruction>)val2.Body.Instructions).Select(delegate(Instruction i) { object operand = i.Operand; return (MethodReference)((operand is MethodReference) ? operand : null); }) where m != null select m).ToArray(); MethodReference val4 = source.First((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "ResourcesPrefabManager" && ((MemberReference)m).Name == "get_Instance"); MethodReference val5 = source.First((MethodReference m) => ((MemberReference)m).Name == "GetItemPrefab" && ((MemberReference)((ParameterReference)m.Parameters[0]).ParameterType).FullName == "System.Int32"); MethodReference val6 = module.GetMemberReferences().OfType<MethodReference>().First((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "UnityEngine.Object" && ((MemberReference)m).Name == "op_Implicit"); MethodReference val7 = source.First((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "SideLoader.SL" && ((MemberReference)m).Name == "Log"); MethodDefinition val8 = new MethodDefinition("Aetherial_OptionalRecipeReady", (MethodAttributes)1, module.TypeSystem.Boolean); val.Methods.Add(val8); ILProcessor iLProcessor = val8.Body.GetILProcessor(); Instruction val9 = Instruction.Create(OpCodes.Call, val4); Instruction val10 = Instruction.Create(OpCodes.Ldc_I4_1); Instruction val11 = Instruction.Create(OpCodes.Ldstr, "Aetherial Endeavors: optional Shadow conversion skipped because its required items are not installed."); string[] array = new string[2] { "!Shadow-daggerTOknife-custom Recipe", "!Shadow-knifeTOdagger-custom Recipe" }; foreach (string text in array) { iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val3); iLProcessor.Emit(OpCodes.Ldstr, text); iLProcessor.Emit(OpCodes.Call, module.ImportReference((MethodBase)typeof(string).GetMethod("op_Equality", new Type[2] { typeof(string), typeof(string) }))); iLProcessor.Emit(OpCodes.Brtrue, val9); } iLProcessor.Emit(OpCodes.Br, val10); iLProcessor.Append(val9); iLProcessor.Emit(OpCodes.Ldc_I4, -23076); iLProcessor.Emit(OpCodes.Callvirt, val5); iLProcessor.Emit(OpCodes.Call, val6); iLProcessor.Emit(OpCodes.Brfalse, val11); iLProcessor.Emit(OpCodes.Call, val4); iLProcessor.Emit(OpCodes.Ldc_I4, -23848); iLProcessor.Emit(OpCodes.Callvirt, val5); iLProcessor.Emit(OpCodes.Call, val6); iLProcessor.Emit(OpCodes.Brfalse, val11); iLProcessor.Append(val10); iLProcessor.Emit(OpCodes.Ret); iLProcessor.Append(val11); iLProcessor.Emit(OpCodes.Call, val7); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Ret); Instruction val12 = val2.Body.Instructions[0]; ILProcessor iLProcessor2 = val2.Body.GetILProcessor(); Instruction[] array2 = (Instruction[])(object)new Instruction[4] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Call, (MethodReference)(object)val8), Instruction.Create(OpCodes.Brtrue, val12), Instruction.Create(OpCodes.Ret) }; foreach (Instruction val13 in array2) { iLProcessor2.InsertBefore(val12, val13); } AssemblyRepairs.WidenBranches(val2); } } private static void LateApplyContext(ModuleDefinition module) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0164: 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_019c: 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_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_025d: 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_0305: 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_0358: 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_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SLPacks.SLPackManager"); if (((IEnumerable<MethodDefinition>)val.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "Aetherial_LateApplyContext")) { return; } MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "InvokeLateApplyListener"); TypeDefinition val3 = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_StatusEffect"); MethodDefinition val4 = new MethodDefinition("Aetherial_LateApplyContext", (MethodAttributes)17, module.TypeSystem.String); ((MethodReference)val4).Parameters.Add(new ParameterDefinition("listener", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val2).Parameters[0]).ParameterType)); val4.Body.InitLocals = true; VariableDefinition val5 = new VariableDefinition((TypeReference)(object)val3); val4.Body.Variables.Add(val5); val.Methods.Add(val4); ILProcessor iLProcessor = val4.Body.GetILProcessor(); Instruction val6 = Instruction.Create(OpCodes.Ldstr, "Exception invoking OnLateApply listener!"); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Brfalse, val6); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Callvirt, module.ImportReference((MethodBase)typeof(Delegate).GetProperty("Target").GetGetMethod())); iLProcessor.Emit(OpCodes.Isinst, (TypeReference)(object)val3); iLProcessor.Emit(OpCodes.Stloc, val5); iLProcessor.Emit(OpCodes.Ldloc, val5); iLProcessor.Emit(OpCodes.Brfalse, val6); iLProcessor.Emit(OpCodes.Ldc_I4, 6); iLProcessor.Emit(OpCodes.Newarr, module.TypeSystem.String); string[] array = new string[6] { "Exception applying status '", null, "', source '", null, "', family: ", null }; string[] fields = new string[6] { null, "StatusIdentifier", null, "TargetStatusIdentifier", null, "ReferenceFamilyUID" }; int i; for (i = 0; i < array.Length; i++) { iLProcessor.Emit(OpCodes.Dup); iLProcessor.Emit(OpCodes.Ldc_I4, i); if (array[i] != null) { iLProcessor.Emit(OpCodes.Ldstr, array[i]); } else { iLProcessor.Emit(OpCodes.Ldloc, val5); iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)((IEnumerable<FieldDefinition>)val3.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == fields[i])); } iLProcessor.Emit(OpCodes.Stelem_Ref); } iLProcessor.Emit(OpCodes.Call, module.ImportReference((MethodBase)typeof(string).GetMethod("Concat", new Type[1] { typeof(string[]) }))); iLProcessor.Emit(OpCodes.Ret); iLProcessor.Append(val6); iLProcessor.Emit(OpCodes.Ret); Instruction val7 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction val8) => val8.OpCode == OpCodes.Ldstr && (string)val8.Operand == "Exception invoking OnLateApply listener!"); val7.OpCode = OpCodes.Ldarg_0; val7.Operand = null; val2.Body.GetILProcessor().InsertAfter(val7, Instruction.Create(OpCodes.Call, (MethodReference)(object)val4)); AssemblyRepairs.WidenBranches(val2); } } public static class Repairs015 { private static void Require(bool value, string message) { AssemblyRepairs.Require(value, message); } public static void SideLoader(ModuleDefinition module) { //IL_00e8: 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) if (!((IEnumerable<TypeDefinition>)module.Types).Any((TypeDefinition t) => ((MemberReference)t).FullName == "AetherialInjected.Chef015")) { MethodDefinition operand = ((IEnumerable<MethodDefinition>)TemplateInjector015.Inject(module, "AetherialInjected.Chef015").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Texture"); MethodDefinition val = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_SkillTree").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "CreateSchool"); Instruction val2 = ((IEnumerable<Instruction>)val.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "TryGetValue"); val.Body.GetILProcessor().InsertBefore(val2, Instruction.Create(OpCodes.Ldarg_0)); val2.OpCode = OpCodes.Call; val2.Operand = operand; AssemblyRepairs.WidenBranches(val); OptionalRunicImbues(module); } } private static void OptionalRunicImbues(ModuleDefinition module) { //IL_00d7: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Expected O, but got Unknown //IL_01bb: 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_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: 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_0201: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Expected O, but got Unknown //IL_020f: 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) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == "SideLoader.SL_RunicBlade"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "ApplyToComponent"); ILProcessor iLProcessor = val2.Body.GetILProcessor(); Instruction[] array = ((IEnumerable<Instruction>)val2.Body.Instructions).Where((Instruction i) => i.Operand is FieldReference && i.OpCode == OpCodes.Ldfld && ((MemberReference)(FieldReference)i.Operand).Name.Contains("ImbueID")).ToArray(); Require(array.Length == 2, "Expected both runic imbue lookups"); Instruction[] array2 = array; foreach (Instruction lookup in array2) { Instruction previous = lookup.Previous.Previous; Require(previous.OpCode == OpCodes.Call && ((MemberReference)(MethodReference)previous.Operand).Name == "get_Instance", "Unexpected runic lookup stack"); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).SkipWhile((Instruction i) => i != lookup).First((Instruction i) => i.OpCode == OpCodes.Stfld); object operand = val3.Next.Next.Operand; Instruction val4 = (Instruction)((operand is Instruction) ? operand : null); Require(val4 != null, "Missing runic continuation"); Instruction[] array3 = (Instruction[])(object)new Instruction[8] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldfld, (FieldReference)lookup.Operand), Instruction.Create(OpCodes.Ldc_I4_M1), Instruction.Create(OpCodes.Bne_Un, previous), Instruction.Create(OpCodes.Ldloc_0), Instruction.Create(OpCodes.Ldnull), Instruction.Create(OpCodes.Stfld, (FieldReference)val3.Operand), Instruction.Create(OpCodes.Br, val4) }; Enumerator<Instruction> enumerator = val2.Body.Instructions.GetEnumerator(); try { while (enumerator.MoveNext()) { Instruction current = enumerator.Current; if (current.Operand == previous) { current.Operand = array3[0]; } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } Instruction[] array4 = array3; foreach (Instruction val5 in array4) { iLProcessor.InsertBefore(previous, val5); } } AssemblyRepairs.WidenBranches(val2); } public static void Viewer(ModuleDefinition module) { //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_0248: 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_0105: 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_0146: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = TemplateInjector015.Inject(module, "AetherialInjected.Viewer015"); MethodDefinition operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "StatusName"); int num = 0; foreach (TypeDefinition item in ((IEnumerable<TypeDefinition>)module.Types).Where((TypeDefinition t) => ((MemberReference)t).Name == "ItemEnchantmentInformationHelper" || ((MemberReference)t).Name == "EnchantmentInformationHelper")) { MethodDefinition val2 = ((IEnumerable<MethodDefinition>)item.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "GetAddStatusEffectsDescription"); Instruction[] array = ((IEnumerable<Instruction>)val2.Body.Instructions).Where((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "get_StatusName").ToArray(); foreach (Instruction val3 in array) { Require(val3.Previous.OpCode == OpCodes.Ldfld && ((MemberReference)(FieldReference)val3.Previous.Operand).FullName == "StatusEffect AddStatusEffect::Status", "Unexpected status name access"); val3.Previous.OpCode = OpCodes.Nop; val3.Previous.Operand = null; val3.OpCode = OpCodes.Call; val3.Operand = operand; num++; } AssemblyRepairs.WidenBranches(val2); } Require(num == 6, "Expected six enchantment status descriptions"); MethodDefinition val4 = ((IEnumerable<MethodDefinition>)((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).Name == "ItemEnchantmentInformationHelper").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "BuildDescriptions"); Instruction val5 = ((IEnumerable<Instruction>)val4.Body.Instructions).Single((Instruction i) => i.Operand is MethodReference && ((MemberReference)(MethodReference)i.Operand).Name == "get_Message"); val4.Body.GetILProcessor().InsertBefore(val5, Instruction.Create(OpCodes.Ldarg_1)); val4.Body.GetILProcessor().InsertBefore(val5, Instruction.Create(OpCodes.Ldarg_0)); val5.OpCode = OpCodes.Call; val5.Operand = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Error"); AssemblyRepairs.WidenBranches(val4); } public static void DeferredRunicVisuals(ModuleDefinition module) { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //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_0141: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((IEnumerable<MethodDefinition>)t.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "TryRefreshCapturedTextureState")); Require(((IEnumerable<MethodDefinition>)val.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "PreloadRunicBladeMaterialWhenReady"), "Expected existing deferred visual loader"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Awake"); int num = 0; Instruction[] array = ((IEnumerable<Instruction>)val2.Body.Instructions).Where((Instruction i) => i.Operand is MethodReference && new string[2] { "TryRefreshCapturedTextureState", "TryRefreshRunicBladeSourceMaterial" }.Contains(((MemberReference)(MethodReference)i.Operand).Name)).ToArray(); foreach (Instruction val3 in array) { MethodReference val4 = (MethodReference)val3.Operand; Instruction previous = val3.Previous; if (val4.Parameters.Count == 1) { Require(previous.OpCode == OpCodes.Ldc_I4_0, "Unexpected eager visual argument"); previous.OpCode = OpCodes.Nop; previous.Operand = null; previous = previous.Previous; } Require(previous.OpCode == OpCodes.Ldarg_0, "Unexpected eager visual receiver"); previous.OpCode = OpCodes.Nop; previous.Operand = null; val3.OpCode = OpCodes.Nop; val3.Operand = null; num++; } Require(num == 2, "Expected two eager visual probes"); } public static void EffectName(ModuleDefinition module, string methodName) { //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //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_0122: Unknown result type (might be due to invalid IL or missing references) TypeDefinition val = ((IEnumerable<TypeDefinition>)module.Types).Single((TypeDefinition t) => ((MemberReference)t).Name == "EffectInitializer"); MethodDefinition val2 = ((IEnumerable<MethodDefinition>)val.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == methodName); Instruction val3 = ((IEnumerable<Instruction>)val2.Body.Instructions).Single((Instruction i) => i.OpCode == OpCodes.Newobj && ((MemberReference)((MemberReference)(MethodReference)i.Operand).DeclaringType).FullName == "SideLoader.SL_EffectTransform"); Require(!((IEnumerable<Instruction>)val2.Body.Instructions).Any((Instruction i) => i.OpCode == OpCodes.Stfld && ((MemberReference)(FieldReference)i.Operand).Name == "TransformName"), "Effect name already supplied"); FieldReference val4 = new FieldReference("TransformName", module.TypeSystem.String, ((MemberReference)(MethodReference)val3.Operand).DeclaringType); ILProcessor iLProcessor = val2.Body.GetILProcessor(); Instruction val5 = Instruction.Create(OpCodes.Dup); Instruction val6 = Instruction.Create(OpCodes.Ldstr, "Normal"); iLProcessor.InsertAfter(val3, val5); iLProcessor.InsertAfter(val5, val6); iLProcessor.InsertAfter(val6, Instruction.Create(OpCodes.Stfld, val4)); AssemblyRepairs.WidenBranches(val2); } } public static class TemplateInjector015 { private static void Require(bool value, string message) { AssemblyRepairs.Require(value, message); } private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> ts) { foreach (TypeDefinition t in ts) { yield return t; foreach (TypeDefinition item in Types((IEnumerable<TypeDefinition>)t.NestedTypes)) { yield return item; } } } public static TypeDefinition Inject(ModuleDefinition target, string typeName) { //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Expected O, but got Unknown //IL_019d: 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_01bf: 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_01db: Expected O, but got Unknown //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: 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_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Expected O, but got Unknown //IL_0238: 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_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: 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_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Expected O, but got Unknown //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Expected O, but got Unknown //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_0726: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Expected O, but got Unknown //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_076b: Unknown result type (might be due to invalid IL or missing references) //IL_0770: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_079a: Unknown result type (might be due to invalid IL or missing references) //IL_079f: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_07e4: Unknown result type (might be due to invalid IL or missing references) //IL_07e9: Unknown result type (might be due to invalid IL or missing references) //IL_04ba: Unknown result type (might be due to invalid IL or missing references) //IL_04c4: Expected O, but got Unknown //IL_05cf: Unknown result type (might be due to invalid IL or missing references) //IL_05d4: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Expected O, but got Unknown //IL_052e: Unknown result type (might be due to invalid IL or missing references) //IL_05f2: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_05fe: Expected O, but got Unknown //IL_082e: Unknown result type (might be due to invalid IL or missing references) //IL_0833: 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_0557: Expected O, but got Unknown //IL_0567: Unknown result type (might be due to invalid IL or missing references) //IL_0571: Expected O, but got Unknown //IL_0581: Unknown result type (might be due to invalid IL or missing references) //IL_058b: Expected O, but got Unknown //IL_0882: Unknown result type (might be due to invalid IL or missing references) //IL_0887: Unknown result type (might be due to invalid IL or missing references) //IL_0914: Unknown result type (might be due to invalid IL or missing references) //IL_091e: Expected O, but got Unknown Dictionary<string, IMetadataScope> known = (from t in target.GetTypeReferences() group t by ((MemberReference)t).FullName).ToDictionary((IGrouping<string, TypeReference> g) => g.Key, (IGrouping<string, TypeReference> g) => g.First().Scope); foreach (TypeDefinition item in Types((IEnumerable<TypeDefinition>)target.Types)) { known[((MemberReference)item).FullName] = (IMetadataScope)(object)target; } if (known.ContainsKey("AddStatusEffect")) { known["AddStatusEffectRandom"] = known["AddStatusEffect"]; } using Stream stream = typeof(TemplateInjector015).Assembly.GetManifestResourceStream("Template015.dll"); AssemblyDefinition val = AssemblyDefinition.ReadAssembly(stream); try { TypeDefinition val2 = ((IEnumerable<TypeDefinition>)val.MainModule.Types).Single((TypeDefinition t) => ((MemberReference)t).FullName == typeName); TypeDefinition val3 = new TypeDefinition(((TypeReference)val2).Namespace, ((MemberReference)val2).Name, val2.Attributes, target.TypeSystem.Object); target.Types.Add(val3); known[((MemberReference)val3).FullName] = (IMetadataScope)(object)target; Enumerator<FieldDefinition> enumerator2 = val2.Fields.GetEnumerator(); try { while (enumerator2.MoveNext()) { FieldDefinition current2 = enumerator2.Current; val3.Fields.Add(new FieldDefinition(((MemberReference)current2).Name, current2.Attributes, target.ImportReference(((FieldReference)current2).FieldType))); } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } Enumerator<MethodDefinition> enumerator3 = val2.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition current3 = enumerator3.Current; MethodDefinition val4 = new MethodDefinition(((MemberReference)current3).Name, current3.Attributes, target.ImportReference(((MethodReference)current3).ReturnType)); Enumerator<ParameterDefinition> enumerator4 = ((MethodReference)current3).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current;
plugins/AetherialEndeavorsFixes/AetherialEndeavorsFixes.Runtime.dll
Decompiled 18 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Cryptography; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.AI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyTitle("Aetherial Endeavors Fixes Runtime")] [assembly: AssemblyFileVersion("0.1.6.0")] [assembly: AssemblyVersion("0.1.6.0")] namespace AetherialEndeavorsFixes; [BepInPlugin("Outwardz.AetherialEndeavorsFixes.Runtime", "Aetherial Endeavors Fixes Runtime", "0.1.6")] public sealed class RuntimePlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Character), "SpellCast", new Type[] { })] private static class CastingContext { private static string scene; private static readonly HashSet<string> seen = new HashSet<string>(); private static void Prefix(Character __instance, GameObject ___m_castingEventReceiver, Skill ___m_lastUsedSkill) { //IL_00ec: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)___m_castingEventReceiver) || !Object.op_Implicit((Object)(object)__instance) || log == null) { return; } try { string activeSceneName = SceneManagerHelper.ActiveSceneName; if (activeSceneName != scene) { scene = activeSceneName; seen.Clear(); } string text = (Object.op_Implicit((Object)(object)___m_lastUsedSkill) ? (((Item)___m_lastUsedSkill).ItemID + " / " + ((Object)___m_lastUsedSkill).name) : "none"); string item = ((Object)__instance).GetInstanceID() + " / " + text; if (seen.Count < 24 && seen.Add(item)) { log.LogInfo((object)string.Concat("Casting diagnostic: scene=", activeSceneName, ", actor=", ((Object)__instance).name, ", last skill=", text, ", position=", ((Component)__instance).transform.position, ". Animation has no casting receiver; no cast was changed or replayed.")); } } catch (Exception ex) { log.LogWarning((object)("Casting diagnostic failed: " + ex)); } } } [HarmonyPatch(typeof(ResourcesPrefabManager), "GetStatusEffectPrefab", new Type[] { typeof(string) })] private static class StatusLookupContext { private static readonly HashSet<string> seen = new HashSet<string>(); private static void Postfix(string __0, StatusEffect __result) { if (Object.op_Implicit((Object)(object)__result) || log == null || (__0 != "Infuse Blood" && __0 != "Infuse Light" && __0 != "alchemicalExpansion-lifeRegeneration" && __0 != "alchemicalExpansion-manaRegeneration" && __0 != "alchemicalExpansion-unstableFlameEffect" && __0 != "alchemicalExpansion-SpeedUp25" && __0 != "CallElements")) { return; } try { if (seen.Add(__0)) { log.LogInfo((object)("Status lookup diagnostic: " + __0 + " was not registered when requested. Caller: " + new StackTrace(1, fNeedFileInfo: false))); } } catch (Exception ex) { log.LogWarning((object)("Status lookup diagnostic failed: " + ex)); } } } [HarmonyPatch(typeof(CharacterStats), "UpdateEquipmentStats")] private static class EquipmentRefresh { private static void Postfix(CharacterStats __instance, Character ___m_character, Stat ___m_detectability, Stat ___m_visualDetectability) { if (!enabledRepair) { return; } try { ThiefEquipment.Refresh(__instance, ___m_character, ___m_detectability, ___m_visualDetectability); } catch (Exception ex) { log.LogError((object)("Thief equipment update failed: " + ex)); } } } private static bool enabledRepair; private static ManualLogSource log; private void Awake() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) log = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Running fixes runtime " + typeof(RuntimePlugin).Assembly.GetName().Version)); ((Component)this).gameObject.AddComponent<NavigationDiagnostics>().Log = ((BaseUnityPlugin)this).Logger; try { enabledRepair = HasSupportedThief(Paths.PluginPath); new Harmony("Outwardz.AetherialEndeavorsFixes.Runtime").PatchAll(typeof(RuntimePlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)(enabledRepair ? "Thief equipment fix ready." : "Thief equipment fix inactive: supported repaired definition not found.")); } catch (Exception ex) { enabledRepair = false; ((BaseUnityPlugin)this).Logger.LogError((object)("Runtime patches could not start: " + ex)); } } private static bool HasSupportedThief(string directory) { string[] files = Directory.GetFiles(directory, "-30442_ Thief.xml"); foreach (string path in files) { if ((File.GetAttributes(path) & FileAttributes.ReparsePoint) != FileAttributes.None) { continue; } using FileStream inputStream = File.OpenRead(path); using SHA256 sHA = SHA256.Create(); if (BitConverter.ToString(sHA.ComputeHash(inputStream)).Replace("-", "").ToLowerInvariant() == "42652e4c9a5f3acaea53852bda2e519de7647caeae1620192a3bc82a43c4c4a8") { return true; } } string[] directories = Directory.GetDirectories(directory); foreach (string text in directories) { if (!text.EndsWith(".disabled", StringComparison.OrdinalIgnoreCase) && !text.EndsWith(".old", StringComparison.OrdinalIgnoreCase) && (File.GetAttributes(text) & FileAttributes.ReparsePoint) == 0 && HasSupportedThief(text)) { return true; } } return false; } } internal static class RuntimeKnown { public const string ThiefHash = "42652e4c9a5f3acaea53852bda2e519de7647caeae1620192a3bc82a43c4c4a8"; } public static class ThiefEquipment { private sealed class State { public Stat DetectStat; public Stat VisualStat; public StatStack Detect; public StatStack Visual; } public const int EnchantmentId = -30442; private static readonly ConditionalWeakTable<CharacterStats, State> states = new ConditionalWeakTable<CharacterStats, State>(); public static void Refresh(CharacterStats stats, Character character, Stat detect, Stat visual) { //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown if ((Object)(object)stats == (Object)null) { return; } bool flag = false; if ((Object)(object)character != (Object)null && (Object)(object)character.Inventory != (Object)null && (Object)(object)character.Inventory.Equipment != (Object)null) { Item equippedItem = character.Inventory.Equipment.GetEquippedItem((EquipmentSlotIDs)7); Equipment val = (Equipment)(object)((equippedItem is Equipment) ? equippedItem : null); flag = (Object)(object)val != (Object)null && val.ActiveEnchantmentIDs != null && val.ActiveEnchantmentIDs.Contains(-30442); } if (states.TryGetValue(stats, out var value)) { if (flag && detect == value.DetectStat && visual == value.VisualStat) { return; } Stop(value); states.Remove(stats); value = null; } if (!flag || detect == null || visual == null) { return; } State state = new State(); state.DetectStat = detect; state.VisualStat = visual; value = state; try { value.Detect = detect.AddStack(new StatStack("AetherialFixes.Thief.Detect", -1f, -12f, (Tag[])null), false); value.Visual = visual.AddStack(new StatStack("AetherialFixes.Thief.Visual", -1f, -12f, (Tag[])null), false); if (value.Detect == null || value.Visual == null) { throw new InvalidOperationException("Could not attach Thief stat bonuses."); } detect.Update(); visual.Update(); states.Add(stats, value); } catch { Stop(value); throw; } } private static void Stop(State state) { if (state.Detect != null) { state.Detect.Stop(); } if (state.Visual != null) { state.Visual.Stop(); } if (state.DetectStat != null) { state.DetectStat.Update(); } if (state.VisualStat != null) { state.VisualStat.Update(); } } } public sealed class NavigationDiagnostics : MonoBehaviour { public ManualLogSource Log; private bool pending; private float due; private int warnings; private void OnEnable() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Application.logMessageReceived += new LogCallback(OnMessage); } private void OnDisable() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Application.logMessageReceived -= new LogCallback(OnMessage); pending = false; warnings = 0; } private void OnMessage(string message, string trace, LogType type) { if (message != null && message.StartsWith("Failed to create agent because it is not close enough to the NavMesh", StringComparison.Ordinal)) { warnings++; if (!pending) { pending = true; due = Time.realtimeSinceStartup + 10f; } } } private void Update() { //IL_008e: 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) if (!pending || Time.realtimeSinceStartup < due) { return; } pending = false; int num = warnings; warnings = 0; if (Log == null) { return; } try { int num2 = 0; NavMeshAgent[] array = Object.FindObjectsOfType<NavMeshAgent>(); foreach (NavMeshAgent val in array) { if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).enabled || !((Component)val).gameObject.activeInHierarchy || val.isOnNavMesh) { continue; } num2++; if (num2 <= 12) { Vector3 position = ((Component)val).transform.position; string text = ((Object)val).name; Transform parent = ((Component)val).transform.parent; while ((Object)(object)parent != (Object)null) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } Log.LogWarning((object)("Navigation check: " + SceneManagerHelper.ActiveSceneName + " / " + text + " at " + position.x.ToString("F2", CultureInfo.InvariantCulture) + ", " + position.y.ToString("F2", CultureInfo.InvariantCulture) + ", " + position.z.ToString("F2", CultureInfo.InvariantCulture) + " is still off the NavMesh.")); } } Log.LogInfo((object)("Navigation check after " + num + " placement warnings: " + num2 + " active agents still off the NavMesh. No agents were changed.")); } catch (Exception ex) { Log.LogWarning((object)("Navigation diagnostic could not finish: " + ex)); } } }