using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx.Logging; using Mono.Cecil; using Mono.Cecil.Cil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("GigaStationsPatcher")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4b5d9c564b6a0858631024f070c85d16f8d9fa20")] [assembly: AssemblyProduct("GigaStationsPatcher")] [assembly: AssemblyTitle("GigaStationsPatcher")] [assembly: AssemblyVersion("1.0.0.0")] namespace GigaStations; public static class Preloader { public static ManualLogSource logSource; public static IEnumerable TargetDLLs { get; } = new string[1] { "Assembly-CSharp.dll" }; public static void Initialize() { logSource = Logger.CreateLogSource("GigaStations Preloader"); } public static void Patch(AssemblyDefinition assembly) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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) try { ModuleDefinition mainModule = assembly.MainModule; TypeDefinition val = ((IEnumerable)mainModule.Types).First((TypeDefinition t) => ((MemberReference)t).FullName == "UIControlPanelStationEntry"); TypeDefinition val2 = ((IEnumerable)mainModule.Types).First((TypeDefinition t) => ((MemberReference)t).FullName == "UIControlPanelStorageItem"); TypeReference val3 = mainModule.ImportReference(typeof(List<>)); GenericInstanceType val4 = new GenericInstanceType(val3); val4.GenericArguments.Add((TypeReference)(object)val2); FieldDefinition val5 = new FieldDefinition("extraStorageItems", (FieldAttributes)1, (TypeReference)(object)val4); val.Fields.Add(val5); MethodReference val6 = new MethodReference(".ctor", mainModule.TypeSystem.Void, (TypeReference)(object)val4) { HasThis = true, ExplicitThis = false, CallingConvention = (MethodCallingConvention)0 }; MethodDefinition val7 = ((IEnumerable)val.Methods).FirstOrDefault((Func)((MethodDefinition m) => ((MemberReference)m).Name == "_OnCreate")); if (val7 != null) { ILProcessor iLProcessor = val7.Body.GetILProcessor(); Instruction val8 = ((IEnumerable)val7.Body.Instructions).First(); Instruction val9 = iLProcessor.Create(OpCodes.Ldarg_0); Instruction val10 = iLProcessor.Create(OpCodes.Newobj, val6); Instruction val11 = iLProcessor.Create(OpCodes.Stfld, (FieldReference)(object)val5); iLProcessor.InsertBefore(val8, val9); iLProcessor.InsertAfter(val9, val10); iLProcessor.InsertAfter(val10, val11); } logSource.LogInfo((object)"Preloader patching is successful!"); } catch (Exception) { logSource.LogError((object)"Preloader patching failed!"); throw; } } }