Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Modlist patchpack v1.4.8
BepInEx/patchers/ValuablesPatchpack/ValuablesPatchpack.Preloader.dll
Decompiled 7 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ByteSizeMetal")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 ByteSizeMetal")] [assembly: AssemblyFileVersion("1.4.8.0")] [assembly: AssemblyInformationalVersion("1.4.8")] [assembly: AssemblyProduct("Modlist-patchpack")] [assembly: AssemblyTitle("ValuablesPatchpack.Preloader")] [assembly: AssemblyMetadata("Author", "ByteSizeMetal")] [assembly: AssemblyVersion("1.4.8.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValuablesPatchpack { public static class SillyApiCompatPatcher { private sealed class Wanted { public string Type; public string Name; public string Return; public bool HasThis; public string[] Params; public readonly SortedSet<string> Mods = new SortedSet<string>(); public string Sig => Type + "." + Name + "(" + string.Join(", ", Params) + ")"; public string BridgeName => "__SillyValuablesFix__" + Name + "__" + Digest(Key(Type, Name, HasThis, Return, Params)).Substring(0, 12); } private const string BridgePrefix = "__SillyValuablesFix__"; private static readonly ManualLogSource Log = Logger.CreateLogSource("Modlist-patchpack API"); public static IEnumerable<string> TargetDLLs { get { if (!SillyPaths().Any() || !ModuleSettings.SillyEnabled) { return Array.Empty<string>(); } return new string[1] { "Assembly-CSharp.dll" }; } } public static void Initialize() { try { MoreUpgradesInputPatcher.Prepare(); } catch (Exception ex) { Log.LogError((object)("MoreUpgrades input preparation failed; other modules continue: " + ex)); } try { PresentsApiPatcher.Prepare(); } catch (Exception ex2) { Log.LogError((object)("REPOPresents preparation failed; other modules continue: " + ex2)); } try { LegacySpeedPatcher.Prepare(); } catch (Exception ex3) { Log.LogError((object)("Legacy speed preparation failed; other modules continue: " + ex3)); } if (!ModuleSettings.SillyEnabled) { RestoreOriginalCallNames(); } } public static void Patch(AssemblyDefinition assembly) { if (!ModuleSettings.SillyEnabled) { return; } ModuleDefinition mainModule = assembly.MainModule; Dictionary<string, Wanted> dictionary; try { dictionary = CollectMissingCalls(mainModule); } catch (Exception ex) { Log.LogError((object)("Scanning plugins failed, nothing patched: " + ex)); return; } int num = 0; foreach (Wanted w in dictionary.Values.OrderBy((Wanted x) => x.Sig)) { try { TypeDefinition type = mainModule.GetType(w.Type); if (type == null) { Log.LogWarning((object)(w.Sig + ": type no longer exists, can't fix (used by " + string.Join(", ", w.Mods) + ").")); } else if (!((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == w.BridgeName)) { MethodDefinition val = ((w.Type == "PhysGrabber" && w.Name == "ReleaseObjectRPC" && w.HasThis && w.Params.SequenceEqual(new string[2] { "System.Boolean", "System.Single" })) ? ReleaseObjectRpcShim(mainModule, type) : DefaultsShim(mainModule, type, w)); if (val == null) { Log.LogWarning((object)(w.Sig + " is missing and can't be rebuilt automatically (used by " + string.Join(", ", w.Mods) + ").")); continue; } ((MemberReference)val).Name = w.BridgeName; type.Methods.Add(val); num++; Log.LogInfo((object)("Added compatibility bridge for " + w.Sig + " (" + string.Join(", ", w.Mods) + ").")); } } catch (Exception ex2) { Log.LogWarning((object)(w.Sig + ": couldn't add it, skipped. " + ex2.Message)); } } Log.LogInfo((object)((num == 0) ? "No supported outdated SillyValuables calls found." : $"Prepared {num} SillyValuables compatibility bridge(s); original game API overloads unchanged.")); RewriteSillyReferences(mainModule); } private static Dictionary<string, Wanted> CollectMissingCalls(ModuleDefinition game) { //IL_00b7: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown HashSet<string> hashSet = new HashSet<string>(from m in ((IEnumerable<TypeDefinition>)game.Types).SelectMany(AllTypes).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) select Key(((MemberReference)m.DeclaringType).FullName, ((MemberReference)m).Name, ((MethodReference)m).HasThis, ((MemberReference)((MethodReference)m).ReturnType).FullName, ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName))); Dictionary<string, Wanted> dictionary = new Dictionary<string, Wanted>(); if (!Directory.Exists(Paths.PluginPath)) { return dictionary; } foreach (string item2 in SillyPaths()) { if (Path.GetFileName(item2).StartsWith("MMHOOK", StringComparison.OrdinalIgnoreCase)) { continue; } try { ModuleDefinition val = ModuleDefinition.ReadModule(item2, new ReaderParameters { ReadingMode = (ReadingMode)2, ReadSymbols = false }); try { string item = PluginFolderName(item2); foreach (MemberReference memberReference in val.GetMemberReferences()) { MethodReference val2 = (MethodReference)(object)((memberReference is MethodReference) ? memberReference : null); if (val2 == null || memberReference is MethodSpecification) { continue; } TypeReference declaringType = ((MemberReference)val2).DeclaringType; if (declaringType == null || declaringType.IsGenericInstance) { continue; } IMetadataScope scope = declaringType.Scope; if (((scope != null) ? scope.Name : null) != "Assembly-CSharp" || val2.HasGenericParameters || ((MemberReference)val2).Name == ".ctor" || ((MemberReference)val2).Name == ".cctor") { continue; } string[] array = ((IEnumerable<ParameterDefinition>)val2.Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName).ToArray(); string text = OriginalName(((MemberReference)val2).Name); string text2 = Key(((MemberReference)declaringType).FullName, text, val2.HasThis, ((MemberReference)val2.ReturnType).FullName, array); if (!(((MemberReference)val2).Name == text) || !hashSet.Contains(text2)) { if (!dictionary.TryGetValue(text2, out var value)) { Wanted obj = new Wanted { Type = ((MemberReference)declaringType).FullName, Name = text, HasThis = val2.HasThis, Return = ((MemberReference)val2.ReturnType).FullName, Params = array }; value = obj; dictionary[text2] = obj; } value.Mods.Add(item); } } } finally { ((IDisposable)val)?.Dispose(); } } catch { } } return dictionary; } private static IEnumerable<TypeDefinition> AllTypes(TypeDefinition t) { return ((IEnumerable<TypeDefinition>)(object)new TypeDefinition[1] { t }).Concat(((IEnumerable<TypeDefinition>)t.NestedTypes).SelectMany(AllTypes)); } private static string Key(string type, string name, bool hasThis, string ret, IEnumerable<string> ps) { return string.Format("{0}::{1}|{2}|{3}|{4}", type, name, hasThis, ret, string.Join(",", ps)); } private static string PluginFolderName(string path) { string text = path.Substring(Paths.PluginPath.Length).TrimStart('\\', '/').Split('\\', '/')[0]; if (!text.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { return text; } return Path.GetFileNameWithoutExtension(text); } private static bool Matches(MethodDefinition m, Wanted w, int count) { if (((MemberReference)m).Name != w.Name || ((MethodReference)m).HasThis != w.HasThis || ((MethodReference)m).HasGenericParameters || ((MemberReference)((MethodReference)m).ReturnType).FullName != w.Return) { return false; } if (((MethodReference)m).Parameters.Count != count) { return false; } for (int i = 0; i < count; i++) { if (((MemberReference)((ParameterReference)((MethodReference)m).Parameters[i]).ParameterType).FullName != w.Params[i]) { return false; } } return true; } private static MethodDefinition DefaultsShim(ModuleDefinition module, TypeDefinition type, Wanted w) { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) int n = w.Params.Length; MethodDefinition val = (from m in (IEnumerable<MethodDefinition>)type.Methods where ((MemberReference)m).Name == w.Name && ((MethodReference)m).HasThis == w.HasThis && !((MethodReference)m).HasGenericParameters && ((MemberReference)((MethodReference)m).ReturnType).FullName == w.Return && ((MethodReference)m).Parameters.Count >= n where Enumerable.Range(0, n).All((int i) => ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[i]).ParameterType).FullName == w.Params[i]) where ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Skip(n).All(CanEmitDefault) orderby ((MethodReference)m).Parameters.Count select m).FirstOrDefault(); if (val == null) { return null; } MethodDefinition val2 = NewShim(val, n); ILProcessor iLProcessor = val2.Body.GetILProcessor(); if (((MethodReference)val).HasThis) { iLProcessor.Emit(OpCodes.Ldarg_0); } for (int num = 0; num < n; num++) { iLProcessor.Emit(OpCodes.Ldarg, ((MethodReference)val2).Parameters[num]); } foreach (ParameterDefinition item in ((IEnumerable<ParameterDefinition>)((MethodReference)val).Parameters).Skip(n)) { EmitDefault(iLProcessor, item); } iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val); iLProcessor.Emit(OpCodes.Ret); return val2; } private static MethodDefinition NewShim(MethodDefinition target, int paramCount) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown MethodAttributes val = (MethodAttributes)(0x86 | (target.IsStatic ? 16 : 0)); MethodDefinition val2 = new MethodDefinition(((MemberReference)target).Name, val, ((MethodReference)target).ReturnType); for (int i = 0; i < paramCount; i++) { ParameterDefinition val3 = ((MethodReference)target).Parameters[i]; ((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)val3).Name, (ParameterAttributes)0, ((ParameterReference)val3).ParameterType)); } return val2; } private static bool CanEmitDefault(ParameterDefinition p) { if (!p.HasConstant || ((ParameterReference)p).ParameterType.IsByReference) { return false; } object constant = p.Constant; if (constant == null) { return !((ParameterReference)p).ParameterType.IsValueType; } if (!(constant is bool) && !(constant is int) && !(constant is uint) && !(constant is short) && !(constant is ushort) && !(constant is byte) && !(constant is sbyte) && !(constant is char) && !(constant is long) && !(constant is ulong) && !(constant is float) && !(constant is double)) { return constant is string; } return true; } private static void EmitDefault(ILProcessor il, ParameterDefinition p) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) object constant = p.Constant; if (constant != null) { if (!(constant is bool flag)) { if (!(constant is float num)) { if (!(constant is double num2)) { if (!(constant is long num3)) { if (!(constant is ulong num4)) { if (constant is string text) { il.Emit(OpCodes.Ldstr, text); } else { il.Emit(OpCodes.Ldc_I4, Convert.ToInt32(constant)); } } else { il.Emit(OpCodes.Ldc_I8, (long)num4); } } else { il.Emit(OpCodes.Ldc_I8, num3); } } else { il.Emit(OpCodes.Ldc_R8, num2); } } else { il.Emit(OpCodes.Ldc_R4, num); } } else { il.Emit(OpCodes.Ldc_I4, flag ? 1 : 0); } } else { il.Emit(OpCodes.Ldnull); } } private static IEnumerable<string> SillyPaths() { if (!Directory.Exists(Paths.PluginPath)) { return Array.Empty<string>(); } return Directory.GetFiles(Paths.PluginPath, "SillyValuables.dll", SearchOption.AllDirectories); } private static string OriginalName(string name) { if (!name.StartsWith("__SillyValuablesFix__", StringComparison.Ordinal)) { return name; } int num = name.LastIndexOf("__", StringComparison.Ordinal); if (num <= "__SillyValuablesFix__".Length) { return name; } return name.Substring("__SillyValuablesFix__".Length, num - "__SillyValuablesFix__".Length); } private static string Digest(string value) { return Digest(Encoding.UTF8.GetBytes(value)); } private static string Digest(byte[] data) { using SHA256 sHA = SHA256.Create(); return BitConverter.ToString(sHA.ComputeHash(data)).Replace("-", "").ToLowerInvariant(); } private static void RewriteSillyReferences(ModuleDefinition game) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown foreach (string item in SillyPaths()) { try { byte[] array = File.ReadAllBytes(item); int num = 0; byte[] bytes; using (MemoryStream memoryStream = new MemoryStream(array)) { ModuleDefinition val = ModuleDefinition.ReadModule((Stream)memoryStream, new ReaderParameters { ReadSymbols = false }); try { if (((AssemblyNameReference)val.Assembly.Name).Name != "SillyValuables") { continue; } if (((AssemblyNameReference)val.Assembly.Name).HasPublicKey) { Log.LogWarning((object)("Signed SillyValuables build skipped: " + item)); continue; } foreach (MemberReference memberReference in val.GetMemberReferences()) { MethodReference val2 = (MethodReference)(object)((memberReference is MethodReference) ? memberReference : null); if (val2 == null || memberReference is MethodSpecification) { continue; } TypeReference declaringType = ((MemberReference)val2).DeclaringType; object obj; if (declaringType == null) { obj = null; } else { IMetadataScope scope = declaringType.Scope; obj = ((scope != null) ? scope.Name : null); } if ((string?)obj != "Assembly-CSharp") { continue; } Wanted wanted = new Wanted { Type = ((MemberReference)((MemberReference)val2).DeclaringType).FullName, Name = OriginalName(((MemberReference)val2).Name), HasThis = val2.HasThis, Return = ((MemberReference)val2.ReturnType).FullName, Params = ((IEnumerable<ParameterDefinition>)val2.Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName).ToArray() }; if (!(((MemberReference)val2).Name == wanted.BridgeName)) { TypeDefinition type = game.GetType(wanted.Type); if (type != null && ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == wanted.BridgeName)) { ((MemberReference)val2).Name = wanted.BridgeName; num++; } } } if (num == 0) { Log.LogInfo((object)("SillyValuables references already compatible: " + item)); continue; } using (MemoryStream memoryStream2 = new MemoryStream()) { val.Write((Stream)memoryStream2); bytes = memoryStream2.ToArray(); } goto IL_025f; } finally { ((IDisposable)val)?.Dispose(); } } IL_025f: string text = Path.Combine(Paths.BepInExRootPath, "cache", "SillyValuablesFix", Digest(array)); Directory.CreateDirectory(text); string text2 = Path.Combine(text, "SillyValuables.dll.original"); if (!File.Exists(text2)) { File.WriteAllBytes(text2, array); } if (!File.ReadAllBytes(text2).SequenceEqual(array)) { throw new IOException("Backup verification failed"); } if (!File.ReadAllBytes(item).SequenceEqual(array)) { throw new IOException("SillyValuables changed during preload; retry next launch"); } string text3 = item + ".svfix.pending"; File.WriteAllBytes(text3, bytes); File.Replace(text3, item, null); Log.LogInfo((object)$"Updated {num} outdated SillyValuables reference(s). Original backup: {text2}"); } catch (Exception ex) { Log.LogError((object)("Could not prepare SillyValuables; original backup is retained: " + ex)); } } } private static void RestoreOriginalCallNames() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown foreach (string item in SillyPaths()) { try { byte[] array = File.ReadAllBytes(item); int num = 0; byte[] bytes; using (MemoryStream memoryStream = new MemoryStream(array)) { ModuleDefinition val = ModuleDefinition.ReadModule((Stream)memoryStream, new ReaderParameters { ReadSymbols = false }); try { if (((AssemblyNameReference)val.Assembly.Name).Name != "SillyValuables" || ((AssemblyNameReference)val.Assembly.Name).HasPublicKey) { continue; } foreach (MemberReference memberReference in val.GetMemberReferences()) { MethodReference val2 = (MethodReference)(object)((memberReference is MethodReference) ? memberReference : null); if (val2 == null) { continue; } TypeReference declaringType = ((MemberReference)val2).DeclaringType; object obj; if (declaringType == null) { obj = null; } else { IMetadataScope scope = declaringType.Scope; obj = ((scope != null) ? scope.Name : null); } if (!((string?)obj != "Assembly-CSharp")) { string text = OriginalName(((MemberReference)val2).Name); if (!(text == ((MemberReference)val2).Name)) { ((MemberReference)val2).Name = text; num++; } } } if (num == 0) { continue; } using (MemoryStream memoryStream2 = new MemoryStream()) { val.Write((Stream)memoryStream2); bytes = memoryStream2.ToArray(); } goto IL_014f; } finally { ((IDisposable)val)?.Dispose(); } } IL_014f: string text2 = Path.Combine(Paths.BepInExRootPath, "cache", "ValuablesPatchpack", "disabled-SillyValuables", Digest(array)); Directory.CreateDirectory(text2); string text3 = Path.Combine(text2, "SillyValuables.dll.before-disable"); if (!File.Exists(text3)) { File.WriteAllBytes(text3, array); } if (!File.ReadAllBytes(text3).SequenceEqual(array)) { throw new IOException("Disable backup verification failed"); } if (!File.ReadAllBytes(item).SequenceEqual(array)) { throw new IOException("SillyValuables changed while disabling its module"); } string text4 = item + ".vp-disable.pending"; File.WriteAllBytes(text4, bytes); File.Replace(text4, item, null); Log.LogInfo((object)$"SillyValuables module disabled: restored {num} original call name(s). Backup: {text3}"); } catch (Exception ex) { Log.LogError((object)("Could not undo SillyValuables compatibility redirection: " + ex)); } } } private static MethodDefinition ReleaseObjectRpcShim(ModuleDefinition module, TypeDefinition type) { //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016e: 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_0186: 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_019f: 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_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: 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_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown FieldDefinition val = ((IEnumerable<FieldDefinition>)type.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == "isLocal" && (int)((FieldReference)f).FieldType.MetadataType == 2)); FieldDefinition val2 = ((IEnumerable<FieldDefinition>)type.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == "grabbed" && (int)((FieldReference)f).FieldType.MetadataType == 2)); FieldDefinition val3 = ((IEnumerable<FieldDefinition>)type.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == "grabDisableTimer" && (int)((FieldReference)f).FieldType.MetadataType == 12)); MethodDefinition val4 = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "ReleaseObject" && ((MethodReference)m).HasThis && ((MethodReference)m).Parameters.Count == 2 && (int)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType.MetadataType == 8 && (int)((ParameterReference)((MethodReference)m).Parameters[1]).ParameterType.MetadataType == 12)); if (val == null || val2 == null || val3 == null || val4 == null) { return null; } TypeSystem typeSystem = module.TypeSystem; MethodDefinition val5 = new MethodDefinition("ReleaseObjectRPC", (MethodAttributes)134, typeSystem.Void); ((MethodReference)val5).Parameters.Add(new ParameterDefinition("_physGrabEnded", (ParameterAttributes)0, typeSystem.Boolean)); ((MethodReference)val5).Parameters.Add(new ParameterDefinition("_disableTimer", (ParameterAttributes)0, typeSystem.Single)); VariableDefinition val6 = new VariableDefinition(typeSystem.Boolean); val5.Body.Variables.Add(val6); val5.Body.InitLocals = true; ILProcessor iLProcessor = val5.Body.GetILProcessor(); Instruction val7 = iLProcessor.Create(OpCodes.Ret); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val); iLProcessor.Emit(OpCodes.Brfalse, val7); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val2); iLProcessor.Emit(OpCodes.Stloc, val6); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldc_I4_M1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val4); iLProcessor.Emit(OpCodes.Ldloc, val6); iLProcessor.Emit(OpCodes.Brtrue, val7); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Stfld, (FieldReference)(object)val3); iLProcessor.Append(val7); return val5; } } internal static class MoreUpgradesInputPatcher { internal const string HelperName = "ModlistPatchpackCompat.MoreUpgradesInputApi"; private static readonly string[] Names = new string[3] { "KeyUp", "KeyDown", "KeyHold" }; private static readonly ManualLogSource Log = Logger.CreateLogSource("Modlist-patchpack MoreUpgrades"); internal static void Prepare() { if (!Directory.Exists(Paths.PluginPath)) { return; } foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, "MoreUpgrades.dll", SearchOption.AllDirectories)) { try { byte[] array = File.ReadAllBytes(item); using MemoryStream memoryStream = new MemoryStream(array); ModuleDefinition val = ModuleDefinition.ReadModule((Stream)memoryStream); try { TypeDefinition type = val.GetType("MoreUpgrades.Plugin"); if (!(((AssemblyNameReference)val.Assembly.Name).Name == "MoreUpgrades") || type == null || !((IEnumerable<CustomAttribute>)type.CustomAttributes).Any(delegate(CustomAttribute a) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (((MemberReference)a.AttributeType).FullName == "BepInEx.BepInPlugin" && a.ConstructorArguments.Count == 3) { CustomAttributeArgument val3 = a.ConstructorArguments[0]; return object.Equals(((CustomAttributeArgument)(ref val3)).Value, "bulletbot.moreupgrades"); } return false; }) || ((AssemblyNameReference)val.Assembly.Name).HasPublicKey) { continue; } bool moreUpgradesEnabled = ModuleSettings.MoreUpgradesEnabled; int num; if (moreUpgradesEnabled) { ModuleDefinition val2 = ModuleDefinition.ReadModule(Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll")); try { num = Rewrite(val, val2) + MoreUpgradesShopPatcher.Rewrite(val, val2); } finally { ((IDisposable)val2)?.Dispose(); } } else { num = Restore(val) + MoreUpgradesShopPatcher.Restore(val); } if (num != 0) { byte[] updated; using (MemoryStream memoryStream2 = new MemoryStream()) { val.Write((Stream)memoryStream2); updated = memoryStream2.ToArray(); } Save(item, array, updated, moreUpgradesEnabled); Log.LogInfo((object)(moreUpgradesEnabled ? $"Prepared {num} MoreUpgrades input/shop compatibility change(s). Native input blocking and current shop rules retained." : $"MoreUpgrades module disabled: restored {num} original input/shop part(s).")); } } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Log.LogError((object)("Could not prepare MoreUpgrades input compatibility; backup retained if created: " + ex)); } } } private static IEnumerable<TypeDefinition> AllTypes(IEnumerable<TypeDefinition> types) { return types.SelectMany((TypeDefinition t) => ((IEnumerable<TypeDefinition>)(object)new TypeDefinition[1] { t }).Concat(AllTypes((IEnumerable<TypeDefinition>)t.NestedTypes))); } private static bool Legacy(MethodReference method) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Invalid comparison between Unknown and I4 if (method != null && method.HasThis && ((MemberReference)((MemberReference)method).DeclaringType).FullName == "InputManager") { IMetadataScope scope = ((MemberReference)method).DeclaringType.Scope; if (((scope != null) ? scope.Name : null) == "Assembly-CSharp" && Names.Contains(((MemberReference)method).Name) && (int)method.ReturnType.MetadataType == 2 && method.Parameters.Count == 1) { return ((MemberReference)((ParameterReference)method.Parameters[0]).ParameterType).FullName == "InputKey"; } } return false; } internal static int Rewrite(ModuleDefinition mod, ModuleDefinition game) { //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) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_0155: Expected O, but got Unknown //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Expected O, but got Unknown //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Expected O, but got Unknown //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Expected O, but got Unknown //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0227: 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_023d: 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 type = game.GetType("InputManager"); if (type == null) { return 0; } TypeDefinition val = mod.GetType("ModlistPatchpackCompat.MoreUpgradesInputApi"); int num = 0; TypeDefinition[] array = AllTypes((IEnumerable<TypeDefinition>)mod.Types).ToArray(); foreach (TypeDefinition val2 in array) { if (val2 == val) { continue; } foreach (MethodDefinition item in ((IEnumerable<MethodDefinition>)val2.Methods).Where((MethodDefinition m) => m.HasBody)) { Enumerator<Instruction> enumerator2 = item.Body.Instructions.GetEnumerator(); try { while (enumerator2.MoveNext()) { Instruction current = enumerator2.Current; if (current.OpCode != OpCodes.Callvirt) { continue; } object operand = current.Operand; MethodReference old = (MethodReference)((operand is MethodReference) ? operand : null); if (old == null || !Legacy(old) || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == ((MemberReference)old).Name && ((MethodReference)m).HasThis && ((MethodReference)m).Parameters.Count == 1 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "InputKey" && (int)((MethodReference)m).ReturnType.MetadataType == 2)) { continue; } MethodDefinition val3 = ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == ((MemberReference)old).Name && ((MethodReference)m).HasThis && !((MethodReference)m).HasGenericParameters && (int)((MethodReference)m).ReturnType.MetadataType == 2 && ((MethodReference)m).Parameters.Count == 2 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "InputKey" && (int)((ParameterReference)((MethodReference)m).Parameters[1]).ParameterType.MetadataType == 2 && ((MethodReference)m).Parameters[1].IsOptional && ((MethodReference)m).Parameters[1].HasConstant && object.Equals(((MethodReference)m).Parameters[1].Constant, false))); if (val3 != null) { if (val == null) { val = new TypeDefinition("ModlistPatchpackCompat", "MoreUpgradesInputApi", (TypeAttributes)384, mod.TypeSystem.Object); mod.Types.Add(val); } MethodDefinition val4 = ((IEnumerable<MethodDefinition>)val.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == ((MemberReference)old).Name)); if (val4 == null) { val4 = new MethodDefinition(((MemberReference)old).Name, (MethodAttributes)147, mod.TypeSystem.Boolean); ((MethodReference)val4).Parameters.Add(new ParameterDefinition("manager", (ParameterAttributes)0, mod.ImportReference(((MemberReference)old).DeclaringType))); ((MethodReference)val4).Parameters.Add(new ParameterDefinition("key", (ParameterAttributes)0, mod.ImportReference(((ParameterReference)old.Parameters[0]).ParameterType))); val.Methods.Add(val4); ILProcessor iLProcessor = val4.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Callvirt, mod.ImportReference((MethodReference)(object)val3)); iLProcessor.Emit(OpCodes.Ret); } current.OpCode = OpCodes.Call; current.Operand = val4; num++; } } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } } } return num; } internal static int Restore(ModuleDefinition mod) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_016f: 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_017d: Expected O, but got Unknown //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Expected O, but got Unknown //IL_01a2: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = mod.GetType("ModlistPatchpackCompat.MoreUpgradesInputApi"); if (type == null) { return 0; } int num = 0; foreach (TypeDefinition item in AllTypes((IEnumerable<TypeDefinition>)mod.Types)) { foreach (MethodDefinition item2 in ((IEnumerable<MethodDefinition>)item.Methods).Where((MethodDefinition m) => m.HasBody)) { Enumerator<Instruction> enumerator3 = item2.Body.Instructions.GetEnumerator(); try { while (enumerator3.MoveNext()) { Instruction current = enumerator3.Current; if (!(current.OpCode != OpCodes.Call)) { object operand = current.Operand; MethodReference val = (MethodReference)((operand is MethodReference) ? operand : null); if (val != null && !(((MemberReference)((MemberReference)val).DeclaringType).FullName != "ModlistPatchpackCompat.MoreUpgradesInputApi") && Names.Contains(((MemberReference)val).Name) && !val.HasThis && val.Parameters.Count == 2 && !(((MemberReference)((ParameterReference)val.Parameters[0]).ParameterType).FullName != "InputManager") && !(((MemberReference)((ParameterReference)val.Parameters[1]).ParameterType).FullName != "InputKey")) { MethodReference val2 = new MethodReference(((MemberReference)val).Name, mod.TypeSystem.Boolean, ((ParameterReference)val.Parameters[0]).ParameterType) { HasThis = true }; val2.Parameters.Add(new ParameterDefinition(((ParameterReference)val.Parameters[1]).ParameterType)); current.OpCode = OpCodes.Callvirt; current.Operand = val2; num++; } } } } finally { ((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose(); } } } if (num > 0) { mod.Types.Remove(type); } return num; } private static void Save(string path, byte[] original, byte[] updated, bool enabled) { string text; using (SHA256 sHA = SHA256.Create()) { text = BitConverter.ToString(sHA.ComputeHash(original)).Replace("-", "").ToLowerInvariant(); } string text2 = Path.Combine(Paths.BepInExRootPath, "cache", "Modlist-patchpack", "MoreUpgrades-input", text); Directory.CreateDirectory(text2); string text3 = Path.Combine(text2, enabled ? "MoreUpgrades.dll.original" : "MoreUpgrades.dll.before-disable"); if (!File.Exists(text3)) { File.WriteAllBytes(text3, original); } if (!File.ReadAllBytes(text3).SequenceEqual(original)) { throw new IOException("MoreUpgrades input backup verification failed"); } if (!File.ReadAllBytes(path).SequenceEqual(original)) { throw new IOException("MoreUpgrades changed during input preparation; retry next launch"); } string text4 = path + ".modlist-input.pending"; File.WriteAllBytes(text4, updated); File.Replace(text4, path, null); Log.LogInfo((object)("Verified pre-change backup: " + text3)); } } internal static class MoreUpgradesShopPatcher { internal const string BackupName = "__ModlistOriginal_GetWeightedUpgradeExcludingTranspiler"; internal const string InventoryBackupName = "__ModlistOriginal_GetAllItemsFromStatsManagerTranspiler"; internal static int Rewrite(ModuleDefinition mod, ModuleDefinition game) { return RewriteOne(mod, game, "MoreUpgrades.Patches.UpgradeStandPatch", "GetWeightedUpgradeExcludingTranspiler", "__ModlistOriginal_GetWeightedUpgradeExcludingTranspiler", "UpgradeStand", "GetWeightedUpgradeExcluding", 4) + RewriteOne(mod, game, "MoreUpgrades.Patches.ShopManagerPatch", "GetAllItemsFromStatsManagerTranspiler", "__ModlistOriginal_GetAllItemsFromStatsManagerTranspiler", "ShopManager", "GetAllItemsFromStatsManager", 0); } private static int RewriteOne(ModuleDefinition mod, ModuleDefinition game, string typeName, string methodName, string backupName, string nativeType, string nativeMethod, int parameters) { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = mod.GetType(typeName); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == methodName && m.IsStatic && ((MethodReference)m).Parameters.Count == 1)) : null); TypeDefinition type2 = game.GetType(nativeType); MethodDefinition val2 = ((type2 != null) ? ((IEnumerable<MethodDefinition>)type2.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == nativeMethod && ((MethodReference)m).Parameters.Count == parameters)) : null); if (val == null || val2 == null || !val2.HasBody || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == backupName)) { return 0; } bool num = val.HasBody && ((IEnumerable<Instruction>)val.Body.Instructions).Any(delegate(Instruction i) { object operand = i.Operand; TypeReference val4 = (TypeReference)((operand is TypeReference) ? operand : null); return val4 != null && ((MemberReference)val4).FullName.Contains("/ValueCollection/Enumerator"); }); bool flag = ((IEnumerable<Instruction>)val2.Body.Instructions).Any(delegate(Instruction i) { object operand = i.Operand; MethodReference val4 = (MethodReference)((operand is MethodReference) ? operand : null); return val4 != null && ((MemberReference)val4).Name == "get_Current" && ((MemberReference)((MemberReference)val4).DeclaringType).FullName.StartsWith("System.Collections.Generic.IEnumerator`1", StringComparison.Ordinal); }); if (!num || !flag) { return 0; } MethodDefinition val3 = new MethodDefinition(backupName, (MethodAttributes)145, ((MethodReference)val).ReturnType); Enumerator<ParameterDefinition> enumerator = ((MethodReference)val).Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; ((MethodReference)val3).Parameters.Add(new ParameterDefinition(((ParameterReference)current).Name, current.Attributes, ((ParameterReference)current).ParameterType)); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } CopyBody(val, val3); type.Methods.Add(val3); val.Body = new MethodBody(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ret); return 1; } internal static int Restore(ModuleDefinition mod) { return RestoreOne(mod, "MoreUpgrades.Patches.UpgradeStandPatch", "GetWeightedUpgradeExcludingTranspiler", "__ModlistOriginal_GetWeightedUpgradeExcludingTranspiler") + RestoreOne(mod, "MoreUpgrades.Patches.ShopManagerPatch", "GetAllItemsFromStatsManagerTranspiler", "__ModlistOriginal_GetAllItemsFromStatsManagerTranspiler"); } private static int RestoreOne(ModuleDefinition mod, string typeName, string methodName, string backupName) { TypeDefinition type = mod.GetType(typeName); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == backupName)) : null); MethodDefinition val2 = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == methodName && ((MethodReference)m).Parameters.Count == 1)) : null); if (val == null || val2 == null) { return 0; } CopyBody(val, val2); type.Methods.Remove(val); return 1; } internal static void CopyBody(MethodDefinition source, MethodDefinition target) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0089: 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_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_025d: 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_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Expected O, but got Unknown MethodBody val = new MethodBody(target) { InitLocals = source.Body.InitLocals, MaxStackSize = source.Body.MaxStackSize }; Dictionary<VariableDefinition, VariableDefinition> dictionary = ((IEnumerable<VariableDefinition>)source.Body.Variables).ToDictionary((Func<VariableDefinition, VariableDefinition>)((VariableDefinition v) => v), (Func<VariableDefinition, VariableDefinition>)((VariableDefinition v) => new VariableDefinition(((VariableReference)v).VariableType))); Enumerator<VariableDefinition> enumerator = source.Body.Variables.GetEnumerator(); try { while (enumerator.MoveNext()) { VariableDefinition current = enumerator.Current; val.Variables.Add(dictionary[current]); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } Dictionary<Instruction, Instruction> instructions = ((IEnumerable<Instruction>)source.Body.Instructions).ToDictionary((Instruction i) => i, (Instruction i) => Instruction.Create(OpCodes.Nop)); Enumerator<Instruction> enumerator2 = source.Body.Instructions.GetEnumerator(); try { while (enumerator2.MoveNext()) { Instruction current2 = enumerator2.Current; Instruction val2 = instructions[current2]; val2.OpCode = current2.OpCode; object operand = current2.Operand; Instruction val3 = (Instruction)((operand is Instruction) ? operand : null); object operand4; if (val3 == null) { if (!(current2.Operand is Instruction[] source2)) { object operand2 = current2.Operand; VariableDefinition val4 = (VariableDefinition)((operand2 is VariableDefinition) ? operand2 : null); if (val4 == null) { object operand3 = current2.Operand; ParameterDefinition val5 = (ParameterDefinition)((operand3 is ParameterDefinition) ? operand3 : null); operand4 = ((val5 != null) ? ((MethodReference)target).Parameters[((ParameterReference)val5).Index] : current2.Operand); } else { operand4 = dictionary[val4]; } } else { operand4 = source2.Select((Instruction i) => instructions[i]).ToArray(); } } else { operand4 = instructions[val3]; } val2.Operand = operand4; val.Instructions.Add(val2); } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } Enumerator<ExceptionHandler> enumerator3 = source.Body.ExceptionHandlers.GetEnumerator(); try { while (enumerator3.MoveNext()) { ExceptionHandler current3 = enumerator3.Current; val.ExceptionHandlers.Add(new ExceptionHandler(current3.HandlerType) { CatchType = current3.CatchType, TryStart = Map(current3.TryStart), TryEnd = Map(current3.TryEnd), HandlerStart = Map(current3.HandlerStart), HandlerEnd = Map(current3.HandlerEnd), FilterStart = Map(current3.FilterStart) }); } } finally { ((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose(); } target.Body = val; Instruction Map(Instruction instruction) { if (instruction != null) { return instructions[instruction]; } return null; } } } internal static class PresentsApiPatcher { internal const string HelperName = "ModlistPatchpackCompat.REPOPresentsValuableApi"; private static readonly ManualLogSource Log = Logger.CreateLogSource("Modlist-patchpack REPOPresents"); private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> source) { return source.SelectMany((TypeDefinition t) => ((IEnumerable<TypeDefinition>)(object)new TypeDefinition[1] { t }).Concat(Types((IEnumerable<TypeDefinition>)t.NestedTypes))); } internal static void Prepare() { if (!Directory.Exists(Paths.PluginPath)) { return; } foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, "REPOPresents.dll", SearchOption.AllDirectories)) { try { byte[] array = File.ReadAllBytes(item); ModuleDefinition val = ModuleDefinition.ReadModule((Stream)new MemoryStream(array)); try { if (!(((AssemblyNameReference)val.Assembly.Name).Name == "REPOPresents") || !Types((IEnumerable<TypeDefinition>)val.Types).Any((TypeDefinition t) => ((IEnumerable<CustomAttribute>)t.CustomAttributes).Any(delegate(CustomAttribute a) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (((MemberReference)a.AttributeType).FullName == "BepInEx.BepInPlugin" && a.ConstructorArguments.Count == 3) { CustomAttributeArgument val4 = a.ConstructorArguments[0]; return object.Equals(((CustomAttributeArgument)(ref val4)).Value, "REPOPresents"); } return false; })) || ((AssemblyNameReference)val.Assembly.Name).HasPublicKey) { continue; } bool presentsEnabled = ModuleSettings.PresentsEnabled; int num = 0; if (!presentsEnabled) { num = Restore(val); goto IL_0142; } string text = Directory.EnumerateFiles(Paths.PluginPath, "REPOLib.dll", SearchOption.AllDirectories).FirstOrDefault(); if (text == null) { continue; } ModuleDefinition val2 = ModuleDefinition.ReadModule(text); try { ModuleDefinition val3 = ModuleDefinition.ReadModule(Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll")); try { num = Rewrite(val, val2) + PresentsPoolPatcher.Rewrite(val, val3) + PresentsSpawnPatcher.Rewrite(val, val2, val3); } finally { ((IDisposable)val3)?.Dispose(); } } finally { ((IDisposable)val2)?.Dispose(); } goto IL_0142; IL_0142: if (num != 0) { byte[] bytes; using (MemoryStream memoryStream = new MemoryStream()) { val.Write((Stream)memoryStream); bytes = memoryStream.ToArray(); } string text2; using (SHA256 sHA = SHA256.Create()) { text2 = BitConverter.ToString(sHA.ComputeHash(array)).Replace("-", "").ToLowerInvariant(); } string text3 = Path.Combine(Paths.BepInExRootPath, "cache", "Modlist-patchpack", "REPOPresents", text2); Directory.CreateDirectory(text3); string text4 = Path.Combine(text3, presentsEnabled ? "REPOPresents.dll.original" : "REPOPresents.dll.before-disable"); if (!File.Exists(text4)) { File.WriteAllBytes(text4, array); } if (!File.ReadAllBytes(text4).SequenceEqual(array) || !File.ReadAllBytes(item).SequenceEqual(array)) { throw new IOException("REPOPresents backup verification/concurrent change check failed"); } string text5 = item + ".modlist-presents.pending"; File.WriteAllBytes(text5, bytes); File.Replace(text5, item, null); Log.LogInfo((object)((presentsEnabled ? "Adapted " : "Restored ") + num + " REPOPresents registration/pool/spawn part(s). Verified backup: " + text4)); } } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Log.LogError((object)("REPOPresents preparation failed; other modules continue: " + ex)); } } } internal static int Rewrite(ModuleDefinition mod, ModuleDefinition repo) { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = repo.GetType("REPOLib.Modules.Valuables"); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "RegisterValuable" && m.IsStatic && ((MethodReference)m).Parameters.Count == 1 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "UnityEngine.GameObject" && ((MemberReference)((MethodReference)m).ReturnType).FullName == "PrefabRef")) : null); if (val == null) { return 0; } List<Instruction> list = (from m in Types((IEnumerable<TypeDefinition>)mod.Types).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m).SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions).Where(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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Invalid comparison between Unknown and I4 if (i.OpCode == OpCodes.Call) { object operand = i.Operand; MethodReference val4 = (MethodReference)((operand is MethodReference) ? operand : null); if (val4 != null && ((MemberReference)((MemberReference)val4).DeclaringType).FullName == "REPOLib.Modules.Valuables") { IMetadataScope scope = ((MemberReference)val4).DeclaringType.Scope; if (((scope != null) ? scope.Name : null) == "REPOLib" && ((MemberReference)val4).Name == "RegisterValuable" && !val4.HasThis && val4.Parameters.Count == 1 && ((MemberReference)((ParameterReference)val4.Parameters[0]).ParameterType).FullName == "UnityEngine.GameObject") { return (int)val4.ReturnType.MetadataType == 1; } } } return false; }).ToList(); if (list.Count == 0) { return 0; } if (mod.GetType("ModlistPatchpackCompat.REPOPresentsValuableApi") != null) { throw new InvalidOperationException("Unexpected existing REPOPresents helper with unresolved calls"); } TypeDefinition val2 = new TypeDefinition("ModlistPatchpackCompat", "REPOPresentsValuableApi", (TypeAttributes)384, mod.TypeSystem.Object); mod.Types.Add(val2); MethodDefinition val3 = new MethodDefinition("RegisterValuable", (MethodAttributes)147, mod.TypeSystem.Void); ((MethodReference)val3).Parameters.Add(new ParameterDefinition("prefab", (ParameterAttributes)0, mod.ImportReference(((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType))); val2.Methods.Add(val3); ILProcessor iLProcessor = val3.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Call, mod.ImportReference((MethodReference)(object)val)); iLProcessor.Emit(OpCodes.Pop); iLProcessor.Emit(OpCodes.Ret); foreach (Instruction item in list) { item.Operand = val3; } return list.Count; } internal static int Restore(ModuleDefinition mod) { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: 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_01a7: Unknown result type (might be due to invalid IL or missing references) int num = PresentsPoolPatcher.Restore(mod) + PresentsSpawnPatcher.Restore(mod); TypeDefinition helper = mod.GetType("ModlistPatchpackCompat.REPOPresentsValuableApi"); if (helper == null) { return num; } MethodReference val = (from i in ((IEnumerable<MethodDefinition>)helper.Methods).SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions) select i.Operand).OfType<MethodReference>().SingleOrDefault((Func<MethodReference, bool>)((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "REPOLib.Modules.Valuables" && ((MemberReference)m).Name == "RegisterValuable")); if (val == null) { return 0; } MethodReference val2 = new MethodReference("RegisterValuable", mod.TypeSystem.Void, ((MemberReference)val).DeclaringType) { HasThis = false }; val2.Parameters.Add(new ParameterDefinition(((ParameterReference)val.Parameters[0]).ParameterType)); int num2 = 0; foreach (MethodDefinition item in from m in (from t in Types((IEnumerable<TypeDefinition>)mod.Types) where t != helper select t).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m) { Enumerator<Instruction> enumerator2 = item.Body.Instructions.GetEnumerator(); try { while (enumerator2.MoveNext()) { Instruction current = enumerator2.Current; if (current.OpCode == OpCodes.Call) { object operand = current.Operand; MethodReference val3 = (MethodReference)((operand is MethodReference) ? operand : null); if (val3 != null && ((MemberReference)((MemberReference)val3).DeclaringType).FullName == "ModlistPatchpackCompat.REPOPresentsValuableApi") { current.Operand = val2; num2++; } } } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } } mod.Types.Remove(helper); return num2 + num; } } internal static class PresentsPoolPatcher { internal const string BackupName = "__ModlistOriginal_GetValuablesByVolumeType"; internal static int Rewrite(ModuleDefinition mod, ModuleDefinition game) { //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Expected O, but got Unknown //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Expected O, but got Unknown //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = mod.GetType("REPOPresents.ValuableUtil"); MethodDefinition method = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "GetValuablesByVolumeType" && m.IsStatic && ((MethodReference)m).Parameters.Count == 2)) : null); if (method == null || !method.HasBody || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "__ModlistOriginal_GetValuablesByVolumeType")) { return 0; } List<FieldReference> list = (from f in ((IEnumerable<Instruction>)method.Body.Instructions).Select((Instruction i) => i.Operand).OfType<FieldReference>() where ((MemberReference)((MemberReference)f).DeclaringType).FullName == "LevelValuables" select f).ToList(); TypeDefinition native = game.GetType("LevelValuables"); if (list.Count != 7 || list.Any(delegate(FieldReference f) { if (!(((MemberReference)f.FieldType).FullName != "System.Collections.Generic.List`1<UnityEngine.GameObject>")) { TypeDefinition obj = native; object obj2; if (obj == null) { obj2 = null; } else { FieldDefinition? obj3 = ((IEnumerable<FieldDefinition>)obj.Fields).SingleOrDefault((Func<FieldDefinition, bool>)((FieldDefinition n) => ((MemberReference)n).Name == ((MemberReference)f).Name)); obj2 = ((obj3 != null) ? ((MemberReference)((FieldReference)obj3).FieldType).FullName : null); } return (string?)obj2 != "System.Collections.Generic.List`1<PrefabRef>"; } return true; })) { return 0; } MethodReference val = ((IEnumerable<Instruction>)method.Body.Instructions).Select((Instruction i) => i.Operand).OfType<MethodReference>().SingleOrDefault((Func<MethodReference, bool>)((MethodReference m) => ((MemberReference)m).Name == ".ctor" && ((MemberReference)((MemberReference)m).DeclaringType).FullName == ((MemberReference)((MethodReference)method).ReturnType).FullName && m.Parameters.Count == 0)); if (val == null || ((MemberReference)((MethodReference)method).ReturnType).FullName != "System.Collections.Generic.List`1<UnityEngine.GameObject>") { return 0; } MethodDefinition val2 = new MethodDefinition("__ModlistOriginal_GetValuablesByVolumeType", (MethodAttributes)145, ((MethodReference)method).ReturnType); Enumerator<ParameterDefinition> enumerator = ((MethodReference)method).Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; ((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)current).Name, current.Attributes, ((ParameterReference)current).ParameterType)); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } MoreUpgradesShopPatcher.CopyBody(method, val2); type.Methods.Add(val2); method.Body = new MethodBody(method); ILProcessor iLProcessor = method.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Newobj, val); iLProcessor.Emit(OpCodes.Ret); return 1; } internal static int Restore(ModuleDefinition mod) { TypeDefinition type = mod.GetType("REPOPresents.ValuableUtil"); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "__ModlistOriginal_GetValuablesByVolumeType")) : null); MethodDefinition val2 = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "GetValuablesByVolumeType" && ((MethodReference)m).Parameters.Count == 2)) : null); if (val == null || val2 == null) { return 0; } MoreUpgradesShopPatcher.CopyBody(val, val2); type.Methods.Remove(val); return 1; } } internal static class PresentsSpawnPatcher { internal const string HelperName = "ModlistPatchpackCompat.REPOPresentsSpawnApi"; private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> types) { return types.SelectMany((TypeDefinition t) => ((IEnumerable<TypeDefinition>)(object)new TypeDefinition[1] { t }).Concat(Types((IEnumerable<TypeDefinition>)t.NestedTypes))); } internal static int Rewrite(ModuleDefinition mod, ModuleDefinition repo, ModuleDefinition game) { //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Expected O, but got Unknown //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Expected O, but got Unknown //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Expected O, but got Unknown //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Expected O, but got Unknown //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033f: Expected O, but got Unknown //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Expected O, but got Unknown //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Expected O, but got Unknown //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Expected O, but got Unknown //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Expected O, but got Unknown //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Expected O, but got Unknown //IL_03d8: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Expected O, but got Unknown //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Expected O, but got Unknown //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Expected O, but got Unknown //IL_0446: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Unknown result type (might be due to invalid IL or missing references) //IL_0462: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_0485: Unknown result type (might be due to invalid IL or missing references) //IL_0493: Unknown result type (might be due to invalid IL or missing references) //IL_049f: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: 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_04d2: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_04ee: Unknown result type (might be due to invalid IL or missing references) //IL_04fc: Unknown result type (might be due to invalid IL or missing references) //IL_050a: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Unknown result type (might be due to invalid IL or missing references) //IL_0532: Unknown result type (might be due to invalid IL or missing references) //IL_0546: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_059a: Unknown result type (might be due to invalid IL or missing references) //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05b4: Unknown result type (might be due to invalid IL or missing references) //IL_05c0: Unknown result type (might be due to invalid IL or missing references) //IL_05d3: Unknown result type (might be due to invalid IL or missing references) //IL_05e8: Unknown result type (might be due to invalid IL or missing references) //IL_05f4: Unknown result type (might be due to invalid IL or missing references) //IL_0600: Unknown result type (might be due to invalid IL or missing references) //IL_0617: Unknown result type (might be due to invalid IL or missing references) //IL_0625: Unknown result type (might be due to invalid IL or missing references) //IL_0633: Unknown result type (might be due to invalid IL or missing references) //IL_0641: Unknown result type (might be due to invalid IL or missing references) //IL_064d: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Expected O, but got Unknown TypeDefinition type = repo.GetType("REPOLib.Modules.Valuables"); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "SpawnValuable" && m.IsStatic && ((MemberReference)((MethodReference)m).ReturnType).FullName == "UnityEngine.GameObject" && ((MethodReference)m).Parameters.Count == 3 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "PrefabRef" && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[1]).ParameterType).FullName == "UnityEngine.Vector3" && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[2]).ParameterType).FullName == "UnityEngine.Quaternion")) : null); MethodDefinition val2 = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "get_AllValuables" && m.IsStatic && ((MethodReference)m).Parameters.Count == 0 && ((MemberReference)((MethodReference)m).ReturnType).FullName == "System.Collections.Generic.IReadOnlyList`1<PrefabRef>")) : null); TypeDefinition type2 = game.GetType("PrefabRef"); if (val != null && val2 != null) { TypeReference obj = ((type2 != null) ? type2.BaseType : null); GenericInstanceType val3 = (GenericInstanceType)(object)((obj is GenericInstanceType) ? obj : null); if (val3 != null) { List<MethodDefinition> source = (from m in Types((IEnumerable<TypeDefinition>)mod.Types).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m).ToList(); List<Instruction> list = source.SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions).Where(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) if (i.OpCode == OpCodes.Call) { object operand = i.Operand; MethodReference val20 = (MethodReference)((operand is MethodReference) ? operand : null); if (val20 != null && ((MemberReference)((MemberReference)val20).DeclaringType).FullName == "REPOLib.Modules.Valuables") { IMetadataScope scope = ((MemberReference)val20).DeclaringType.Scope; if (((scope != null) ? scope.Name : null) == "REPOLib" && !val20.HasThis && ((MemberReference)val20).Name == "SpawnValuable" && ((MemberReference)val20.ReturnType).FullName == "UnityEngine.GameObject" && val20.Parameters.Count == 3 && ((MemberReference)((ParameterReference)val20.Parameters[0]).ParameterType).FullName == "ValuableObject" && ((MemberReference)((ParameterReference)val20.Parameters[1]).ParameterType).FullName == "UnityEngine.Vector3") { return ((MemberReference)((ParameterReference)val20.Parameters[2]).ParameterType).FullName == "UnityEngine.Quaternion"; } } } return false; }).ToList(); if (list.Count == 0) { return 0; } if (mod.GetType("ModlistPatchpackCompat.REPOPresentsSpawnApi") != null) { throw new InvalidOperationException("Unexpected existing Presents spawn adapter"); } MethodReference val4 = (from i in source.SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions) select i.Operand).OfType<MethodReference>().FirstOrDefault((Func<MethodReference, bool>)((MethodReference m) => ((MemberReference)((MemberReference)m).DeclaringType).FullName == "UnityEngine.Object" && ((MemberReference)m).Name == "get_name")); if (val4 == null) { return 0; } MethodReference val5 = (MethodReference)list[0].Operand; TypeDefinition val6 = new TypeDefinition("ModlistPatchpackCompat", "REPOPresentsSpawnApi", (TypeAttributes)384, mod.TypeSystem.Object); mod.Types.Add(val6); MethodDefinition val7 = new MethodDefinition("SpawnValuable", (MethodAttributes)147, mod.ImportReference(((MethodReference)val).ReturnType)); Enumerator<ParameterDefinition> enumerator = val5.Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; ((MethodReference)val7).Parameters.Add(new ParameterDefinition(((ParameterReference)current).Name, current.Attributes, mod.ImportReference(((ParameterReference)current).ParameterType))); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } val6.Methods.Add(val7); val7.Body.InitLocals = true; GenericInstanceType val8 = (GenericInstanceType)mod.ImportReference(((MethodReference)val2).ReturnType); if (((TypeSpecification)val8).ElementType.GenericParameters.Count == 0) { ((TypeSpecification)val8).ElementType.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)((TypeSpecification)val8).ElementType)); } MethodReference val9 = new MethodReference("get_Item", (TypeReference)(object)((TypeSpecification)val8).ElementType.GenericParameters[0], (TypeReference)(object)val8) { HasThis = true }; val9.Parameters.Add(new ParameterDefinition(mod.TypeSystem.Int32)); TypeReference val10 = new TypeReference("System.Collections.Generic", "IReadOnlyCollection`1", mod, ((TypeSpecification)val8).ElementType.Scope); val10.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)val10)); GenericInstanceType val11 = new GenericInstanceType(val10); val11.GenericArguments.Add(mod.ImportReference((TypeReference)(object)type2)); MethodReference val12 = new MethodReference("get_Count", mod.TypeSystem.Int32, (TypeReference)(object)val11) { HasThis = true }; MethodReference val13 = new MethodReference("get_PrefabName", mod.TypeSystem.String, mod.ImportReference((TypeReference)(object)val3)) { HasThis = true }; VariableDefinition val14 = new VariableDefinition((TypeReference)(object)val8); VariableDefinition val15 = new VariableDefinition(mod.TypeSystem.Int32); VariableDefinition val16 = new VariableDefinition(mod.ImportReference((TypeReference)(object)type2)); val7.Body.Variables.Add(val14); val7.Body.Variables.Add(val15); val7.Body.Variables.Add(val16); ILProcessor iLProcessor = val7.Body.GetILProcessor(); Instruction val17 = Instruction.Create(OpCodes.Ldloc, val15); Instruction val18 = Instruction.Create(OpCodes.Ldloc, val14); Instruction val19 = Instruction.Create(OpCodes.Ldloc, val15); iLProcessor.Emit(OpCodes.Call, mod.ImportReference((MethodReference)(object)val2)); iLProcessor.Emit(OpCodes.Stloc, val14); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Stloc, val15); iLProcessor.Emit(OpCodes.Br, val17); iLProcessor.Append(val18); iLProcessor.Emit(OpCodes.Ldloc, val15); iLProcessor.Emit(OpCodes.Callvirt, val9); iLProcessor.Emit(OpCodes.Stloc, val16); iLProcessor.Emit(OpCodes.Ldloc, val16); iLProcessor.Emit(OpCodes.Brfalse, val19); iLProcessor.Emit(OpCodes.Ldloc, val16); iLProcessor.Emit(OpCodes.Callvirt, val13); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Callvirt, mod.ImportReference(val4)); iLProcessor.Emit(OpCodes.Call, mod.ImportReference((MethodBase)typeof(string).GetMethod("op_Equality", new Type[2] { typeof(string), typeof(string) }))); iLProcessor.Emit(OpCodes.Brfalse, val19); iLProcessor.Emit(OpCodes.Ldloc, val16); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Call, mod.ImportReference((MethodReference)(object)val)); iLProcessor.Emit(OpCodes.Ret); iLProcessor.Append(val19); iLProcessor.Emit(OpCodes.Ldc_I4_1); iLProcessor.Emit(OpCodes.Add); iLProcessor.Emit(OpCodes.Stloc, val15); iLProcessor.Append(val17); iLProcessor.Emit(OpCodes.Ldloc, val14); iLProcessor.Emit(OpCodes.Callvirt, val12); iLProcessor.Emit(OpCodes.Blt, val18); iLProcessor.Emit(OpCodes.Ldnull); iLProcessor.Emit(OpCodes.Ret); foreach (Instruction item in list) { item.Operand = val7; } return list.Count; } } return 0; } internal static int Restore(ModuleDefinition mod) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0197: 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) TypeDefinition helper = mod.GetType("ModlistPatchpackCompat.REPOPresentsSpawnApi"); if (helper == null) { return 0; } MethodDefinition val = ((IEnumerable<MethodDefinition>)helper.Methods).Single(); MethodReference val2 = ((IEnumerable<Instruction>)val.Body.Instructions).Select((Instruction i) => i.Operand).OfType<MethodReference>().Single((MethodReference m) => ((MemberReference)m).Name == "SpawnValuable" && ((MemberReference)((MemberReference)m).DeclaringType).FullName == "REPOLib.Modules.Valuables"); MethodReference val3 = new MethodReference("SpawnValuable", ((MethodReference)val).ReturnType, ((MemberReference)val2).DeclaringType); Enumerator<ParameterDefinition> enumerator = ((MethodReference)val).Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; val3.Parameters.Add(new ParameterDefinition(((ParameterReference)current).ParameterType)); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } int num = 0; foreach (MethodDefinition item in from m in (from t in Types((IEnumerable<TypeDefinition>)mod.Types) where t != helper select t).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m) { Enumerator<Instruction> enumerator3 = item.Body.Instructions.GetEnumerator(); try { while (enumerator3.MoveNext()) { Instruction current2 = enumerator3.Current; if (current2.OpCode == OpCodes.Call) { object operand = current2.Operand; MethodReference val4 = (MethodReference)((operand is MethodReference) ? operand : null); if (val4 != null && ((MemberReference)((MemberReference)val4).DeclaringType).FullName == "ModlistPatchpackCompat.REPOPresentsSpawnApi") { current2.Operand = val3; num++; } } } } finally { ((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose(); } } mod.Types.Remove(helper); return num; } } internal static class LegacySpeedPatcher { internal const string HelperName = "ModlistPatchpackCompat.LegacySpeedApi"; private static readonly Dictionary<string, string> Supported = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { ["ExtraBattleUpgrades.dll"] = "DarkSpider90.ExtraBattleUpgrades", ["JNL_Assist.dll"] = "HERO.JNL_Assist", ["WesleysEnemies.dll"] = "WesleysEnemies", ["SteampunkItems.dll"] = "SteampunkItems" }; private static readonly ManualLogSource Log = Logger.CreateLogSource("Modlist-patchpack speed API"); private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> types) { return types.SelectMany((TypeDefinition t) => ((IEnumerable<TypeDefinition>)(object)new TypeDefinition[1] { t }).Concat(Types((IEnumerable<TypeDefinition>)t.NestedTypes))); } internal static void Prepare() { if (!Directory.Exists(Paths.PluginPath)) { return; } foreach (KeyValuePair<string, string> spec in Supported) { foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, spec.Key, SearchOption.AllDirectories)) { try { byte[] array = File.ReadAllBytes(item); ModuleDefinition val = ModuleDefinition.ReadModule((Stream)new MemoryStream(array)); try { if (!Types((IEnumerable<TypeDefinition>)val.Types).Any((TypeDefinition t) => ((IEnumerable<CustomAttribute>)t.CustomAttributes).Any(delegate(CustomAttribute a) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (((MemberReference)a.AttributeType).FullName == "BepInEx.BepInPlugin" && a.ConstructorArguments.Count == 3) { CustomAttributeArgument val3 = a.ConstructorArguments[0]; return object.Equals(((CustomAttributeArgument)(ref val3)).Value, spec.Value); } return false; })) || ((AssemblyNameReference)val.Assembly.Name).HasPublicKey) { continue; } bool flag = ModuleSettings.EnabledFor(spec.Value); int num; if (flag) { ModuleDefinition val2 = ModuleDefinition.ReadModule(Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll")); try { num = Rewrite(val, val2); } finally { ((IDisposable)val2)?.Dispose(); } } else { num = Restore(val); } if (num != 0) { byte[] bytes; using (MemoryStream memoryStream = new MemoryStream()) { val.Write((Stream)memoryStream); bytes = memoryStream.ToArray(); } string text; using (SHA256 sHA = SHA256.Create()) { text = BitConverter.ToString(sHA.ComputeHash(array)).Replace("-", "").ToLowerInvariant(); } string text2 = Path.Combine(Paths.BepInExRootPath, "cache", "Modlist-patchpack", "speed-api", text); Directory.CreateDirectory(text2); string text3 = Path.Combine(text2, Path.GetFileName(item) + (flag ? ".original" : ".before-disable")); if (!File.Exists(text3)) { File.WriteAllBytes(text3, array); } if (!File.ReadAllBytes(text3).SequenceEqual(array) || !File.ReadAllBytes(item).SequenceEqual(array)) { throw new IOException("Speed API backup/concurrent change check failed"); } string text4 = item + ".modlist-speed.pending"; File.WriteAllBytes(text4, bytes); File.Replace(text4, item, null); Log.LogInfo((object)((flag ? "Adapted " : "Restored ") + num + " OverrideSpeed call(s) for " + spec.Value + "; backup: " + text3)); } } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Log.LogError((object)("Speed API preparation failed for " + spec.Value + ": " + ex)); } } } } internal static int Rewrite(ModuleDefinition mod, ModuleDefinition game) { //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Expected O, but got Unknown //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Expected O, but got Unknown //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01f4: 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_020a: 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_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = game.GetType("PlayerController"); if (type == null || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "OverrideSpeed" && ((MethodReference)m).Parameters.Count == 2)) { return 0; } MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "OverrideSpeed" && ((MethodReference)m).HasThis && (int)((MethodReference)m).ReturnType.MetadataType == 1 && ((MethodReference)m).Parameters.Count == 3 && ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).All((ParameterDefinition p) => (int)((ParameterReference)p).ParameterType.MetadataType == 12) && ((MethodReference)m).Parameters[2].IsOptional && ((MethodReference)m).Parameters[2].HasConstant && object.Equals(((MethodReference)m).Parameters[2].Constant, -1f))); if (val == null) { return 0; } List<Instruction> list = (from m in Types((IEnumerable<TypeDefinition>)mod.Types).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m).SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions).Where(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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Invalid comparison between Unknown and I4 if (i.OpCode == OpCodes.Callvirt) { object operand = i.Operand; MethodReference val4 = (MethodReference)((operand is MethodReference) ? operand : null); if (val4 != null && val4.HasThis && ((MemberReference)((MemberReference)val4).DeclaringType).FullName == "PlayerController") { IMetadataScope scope = ((MemberReference)val4).DeclaringType.Scope; if (((scope != null) ? scope.Name : null) == "Assembly-CSharp" && ((MemberReference)val4).Name == "OverrideSpeed" && (int)val4.ReturnType.MetadataType == 1 && val4.Parameters.Count == 2) { return ((IEnumerable<ParameterDefinition>)val4.Parameters).All((ParameterDefinition p) => (int)((ParameterReference)p).ParameterType.MetadataType == 12); } } } return false; }).ToList(); if (list.Count == 0) { return 0; } if (mod.GetType("ModlistPatchpackCompat.LegacySpeedApi") != null) { throw new InvalidOperationException("Unexpected speed helper collision"); } TypeDefinition val2 = new TypeDefinition("ModlistPatchpackCompat", "LegacySpeedApi", (TypeAttributes)384, mod.TypeSystem.Object); mod.Types.Add(val2); MethodDefinition val3 = new MethodDefinition("OverrideSpeed", (MethodAttributes)147, mod.TypeSystem.Void); ((MethodReference)val3).Parameters.Add(new ParameterDefinition("controller", (ParameterAttributes)0, mod.ImportReference((TypeReference)(object)type))); ((MethodReference)val3).Parameters.Add(new ParameterDefinition("speed", (ParameterAttributes)0, mod.TypeSystem.Single)); ((MethodReference)val3).Parameters.Add(new ParameterDefinition("time", (ParameterAttributes)0, mod.TypeSystem.Single)); val2.Methods.Add(val3); ILProcessor iLProcessor = val3.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Ldc_R4, -1f); iLProcessor.Emit(OpCodes.Callvirt, mod.ImportReference((MethodReference)(object)val)); iLProcessor.Emit(OpCodes.Ret); foreach (Instruction item in list) { item.OpCode = OpCodes.Call; item.Operand = val3; } return list.Count; } internal static int Restore(ModuleDefinition mod) { //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_00c1: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: 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) TypeDefinition helper = mod.GetType("ModlistPatchpackCompat.LegacySpeedApi"); if (helper == null) { return 0; } MethodReference val = (from i in ((IEnumerable<MethodDefinition>)helper.Methods).SelectMany((MethodDefinition m) => (IEnumerable<Instruction>)m.Body.Instructions) select i.Operand).OfType<MethodReference>().Single((MethodReference m) => ((MemberReference)m).Name == "OverrideSpeed"); MethodReference val2 = new MethodReference("OverrideSpeed", mod.TypeSystem.Void, ((MemberReference)val).DeclaringType) { HasThis = true }; val2.Parameters.Add(new ParameterDefinition(mod.TypeSystem.Single)); val2.Parameters.Add(new ParameterDefinition(mod.TypeSystem.Single)); int num = 0; foreach (MethodDefinition item in from m in (from t in Types((IEnumerable<TypeDefinition>)mod.Types) where t != helper select t).SelectMany((TypeDefinition t) => (IEnumerable<MethodDefinition>)t.Methods) where m.HasBody select m) { Enumerator<Instruction> enumerator2 = item.Body.Instructions.GetEnumerator(); try { while (enumerator2.MoveNext()) { Instruction current = enumerator2.Current; if (current.OpCode == OpCodes.Call) { object operand = current.Operand; MethodReference val3 = (MethodReference)((operand is MethodReference) ? operand : null); if (val3 != null && ((MemberReference)((MemberReference)val3).DeclaringType).FullName == "ModlistPatchpackCompat.LegacySpeedApi") { current.OpCode = OpCodes.Callvirt; current.Operand = val2; num++; } } } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } } mod.Types.Remove(helper); return num; } } internal static class ModuleSettings { private static ConfigFile _file; internal static ConfigFile File { get { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown object obj = _file; if (obj == null) { ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "ValuablesPatchpack.cfg"), true); _file = val; obj = (object)val; } return (ConfigFile)obj; } } internal static bool SillyEnabled => File.Bind<bool>("Mods", "SillyValuables", true, "Enable ALL Modlist-patchpack fixes for SillyValuables, including API compatibility, melee networking and ItemLight visual initialization. Requires that mod to be installed. Restart after changing.").Value; internal static bool SteampunkEnabled => File.Bind<bool>("Mods", "SteampunkItems", true, "Enable ALL Modlist-patchpack fixes for SteampunkItems. Requires that mod to be installed. Restart after changing.").Value; internal static bool MinecraftEnabled => File.Bind<bool>("Mods", "MinecraftStrongholdLevel", true, "Enable ALL Modlist-patchpack fixes for MinecraftStrongholdLevel, including Diamond Sword, source-attributed SDK prefabs and the minecart's missing optional value display. Requires that mod to be installed. Restart after changing.").Value; internal static bool KeybindEnabled => File.Bind<bool>("Mods", "KeybindLib", true, "Enable ALL Modlist-patchpack fixes for KeybindLib's obsolete inputToggle injection on current R.E.P.O., plus startup-only input-load diagnostics. Requires that mod to be installed. Restart after changing.").Value; internal static bool MoreUpgradesEnabled => File.Bind<bool>("Mods", "MoreUpgrades", true, "Enable ALL Modlist-patchpack fixes for MoreUpgrades: legacy input API, current shop selection/pricing and verified duplicate-manager retirement. Requires that mod to be installed. Disabling restores original input/shop code during preload; restart after changing.").Value; internal static bool PresentsEnabled => File.Bind<bool>("Mods", "REPOPresents", true, "Enable ALL Modlist-patchpack fixes for REPOPresents: registration/spawning APIs and lazy current PrefabRef valuable pools. Disabling restores original calls and pool body during preload; restart after changing.").Value; internal static bool RepoWarningsEnabled => File.Bind<bool>("Mods", "REPOLib", true, "Enable the pack's REPOLib-specific registration logging compatibility: duplicate valuable-name collisions become warnings with the existing skip behavior explained. Missing references and other errors remain errors. Other source mods retain their own master switches. Restart after changing.").Value; internal static bool ExtraBattleEnabled => File.Bind<bool>("Mods", "DarkSpider90.ExtraBattleUpgrades", true, "Enable ALL pack fixes for Extra Battle Upgrades, including the legacy OverrideSpeed call in Panic Response. Retains its existing source-plugin master key. Restart after changing.").Value; internal static bool JnlEnabled => File.Bind<bool>("Mods", "HERO.JNL_Assist", true, "Enable ALL pack fixes for JNL_Assist, including its legacy OverrideSpeed call. Retains its existing source-plugin master key. Restart after changing.").Value; internal static bool WesleysEnemiesEnabled => File.Bind<bool>("Mods", "WesleysEnemies", true, "Enable ALL pack fixes for Wesley's Enemies, including Voodoo's legacy OverrideSpeed call. Restart after changing.").Value; internal static bool ValorantEnabled => File.Bind<bool>("Mods", "ValorantWeapons", true, "Enable ALL pack fixes for Neofeng's asset-only Valorant Weapons package, detected from its SDK bundle path and manifest. Excludes unsupported Standard-shader targets from ItemLight glow animation without changing models/materials. Restart after changing.").Value; internal static bool DandyEnabled => File.Bind<bool>("Mods", "DandysWorldItems", true, "Enable ALL pack fixes for SushiWolf's asset-only Dandy's World Items, detected from its actual SDK bundle path and manifest. Repairs the missing radioactive loop audio source at initialization without changing radiation/gameplay logic. Restart after changing.").Value; internal static bool MelanieEnabled => File.Bind<bool>("Mods", "MelanieLevels", true, "Enable ALL pack fixes for MelanieMelicious's asset-only level package. Skip only verified Mel Mausoleum registration with no entrance-room references, preventing selection of an unloadable map. Does not rebuild the map. Updated content with a valid entrance remains enabled. Restart after changing.").Value; internal static bool ShopSpawnEnabled => File.Bind<bool>("Mods", "AllShopItemsInLevel", true, "Enable ALL pack fixes for ALL Shop Items spawn in Level (REPO_All_Shop_Items_in_Level). Use each item's registered prefab path for multiplayer spawning instead of guessing Items/<name>. Restart after changing.").Value; internal static bool EnabledFor(string guid) { return guid switch { "Sangrento.SillyValuables" => SillyEnabled, "SteampunkItems" => SteampunkEnabled, "MinecraftStrongholdLevel" => MinecraftEnabled, "bulletbot.keybindlib" => KeybindEnabled, "bulletbot.moreupgrades" => MoreUpgradesEnabled, "REPOPresents" => PresentsEnabled, "REPOLib" => RepoWarningsEnabled, "DarkSpider90.ExtraBattleUpgrades" => ExtraBattleEnabled, "HERO.JNL_Assist" => JnlEnabled, "WesleysEnemies" => WesleysEnemiesEnabled, "asset:Neofeng:valorant_weapons_mod" => ValorantEnabled, "asset:SushiWolf:Dandys_World_Items" => DandyEnabled, "asset:MelanieMelicious:Melanie_REPO_Levels_MelanieMelicious" => MelanieEnabled, "REPO_All_Shop_Items_in_Level" => ShopSpawnEnabled, _ => File.Bind<bool>("Mods", Safe(guid), true, "Enable ALL automatic prefab compatibility fixes for detected plugin " + guid + ". Repairs obsolete ItemMelee observations, invalid ItemLight setup and missing optional cart displays only on source-attributed prefabs. Restart after changing.").Value, }; } private static string Safe(string guid) { return (guid ?? "").Replace('[', '_').Replace(']', '_').Replace('=', '_') .Replace('\\', '_') .Replace('/', '_'); } } }
BepInEx/plugins/ValuablesPatchpack/ValuablesPatchpack.dll
Decompiled 7 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ByteSizeMetal")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 ByteSizeMetal")] [assembly: AssemblyFileVersion("1.4.8.0")] [assembly: AssemblyInformationalVersion("1.4.8")] [assembly: AssemblyProduct("Modlist-patchpack")] [assembly: AssemblyTitle("ValuablesPatchpack")] [assembly: AssemblyMetadata("Author", "ByteSizeMetal")] [assembly: AssemblyVersion("1.4.8.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValuablesPatchpack { [BepInPlugin("local.SillyValuablesFix.ItemNetworking", "Modlist-patchpack", "1.4.8")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class ObservationRepairPlugin : BaseUnityPlugin { public const string Guid = "local.SillyValuablesFix.ItemNetworking"; private static ObservationRepairPlugin _instance; private Harmony _harmony; private void Awake() { //IL_066c: Unknown result type (might be due to invalid IL or missing references) //IL_067a: Expected O, but got Unknown //IL_0693: Unknown result type (might be due to invalid IL or missing references) //IL_06a1: Expected O, but got Unknown //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown PluginInfo value; bool flag = Chainloader.PluginInfos.TryGetValue("Sangrento.SillyValuables", out value) && (Object)(object)value.Instance != (Object)null; PluginInfo value2; bool flag2 = Chainloader.PluginInfos.TryGetValue("SteampunkItems", out value2) && (Object)(object)value2.Instance != (Object)null; PluginInfo value3; bool flag3 = Chainloader.PluginInfos.TryGetValue("MinecraftStrongholdLevel", out value3) && (Object)(object)value3.Instance != (Object)null; bool sillyEnabled = ModuleSettings.SillyEnabled; bool steampunkEnabled = ModuleSettings.SteampunkEnabled; string value4 = ModuleSettings.File.Bind<string>("Additional prefabs", "SillyValuables", "", "Optional comma-separated prefab names to include in the SillyValuables module. Its mod must be installed and its master toggle enabled; only invalid ItemMelee observations are removed. Restart after changing.").Value; string value5 = ModuleSettings.File.Bind<string>("Additional prefabs", "SteampunkItems", "", "Optional comma-separated prefab names to include in the SteampunkItems module. Its mod must be installed and its master toggle enabled; only invalid ItemMelee observations are removed. Restart after changing.").Value; MeleeObservationRepair.Modules = new PatchModules(flag && sillyEnabled, flag2 && steampunkEnabled, value4, value5, flag3 && ModuleSettings.MinecraftEnabled); _instance = this; _harmony = new Harmony("local.SillyValuablesFix.ItemNetworking"); try { Chainloader.PluginInfos.TryGetValue("REPOPresents", out var value6); PresentsPoolCompat.Apply(_harmony, (value6 != null) ? value6.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("REPOPresents pool compatibility unavailable: " + ex.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("REPO_All_Shop_Items_in_Level", out var value7); ShopSpawnPathCompat.Apply(_harmony, (value7 != null) ? value7.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex2) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Shop-item spawn-path compatibility unavailable: " + ex2.GetBaseException().Message)); } try { CartDisplayCompat.Apply(_harmony, flag3, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogWarning((object)message); }); } catch (Exception ex3) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Cart value-display compatibility unavailable: " + ex3.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("REPOLib", out var value8); RegistrationWarnings.Apply(_harmony, (value8 == null) ? null : ((object)value8.Instance)?.GetType().Assembly); } catch (Exception ex4) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("REPOLib registration warning compatibility unavailable: " + ex4.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("REPOLib", out var value9); MelanieLevelGuard.Apply(_harmony, (value9 == null) ? null : ((object)value9.Instance)?.GetType().Assembly, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogWarning((object)message); }); } catch (Exception ex5) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Melanie level registration guard unavailable: " + ex5.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("REPOLib", out var value10); DandyUraniumRepair.Apply(_harmony, (value10 == null) ? null : ((object)value10.Instance)?.GetType().Assembly, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogWarning((object)message); }); } catch (Exception ex6) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Dandy's World uranium audio compatibility unavailable: " + ex6.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("bulletbot.moreupgrades", out var value11); MoreUpgradesShopCompat.Apply(_harmony, (value11 != null) ? value11.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex7) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("MoreUpgrades shop compatibility unavailable: " + ex7.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("bulletbot.moreupgrades", out var value12); MoreShopInventoryCompat.Apply(_harmony, (value12 != null) ? value12.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex8) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("MoreUpgrades shop inventory compatibility unavailable: " + ex8.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("bulletbot.moreupgrades", out var value13); MoreManagerCompat.Apply(_harmony, (value13 != null) ? value13.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex9) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("MoreUpgrades manager compatibility unavailable: " + ex9.GetBaseException().Message)); } try { SillyHealthMeshRepair.Apply(_harmony, flag, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex10) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("SillyValuables health mesh compatibility unavailable: " + ex10.GetBaseException().Message)); } try { Chainloader.PluginInfos.TryGetValue("bulletbot.keybindlib", out var value14); KeybindCompat.Apply(_harmony, (value14 != null) ? value14.Instance : null, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex11) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("KeybindLib compatibility unavailable: " + ex11.GetBaseException().Message)); } try { if (flag && sillyEnabled) { ExceptionVisibility.Apply(_harmony, ((object)value.Instance).GetType().Assembly); } } catch (Exception ex12) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("SillyValuables exception visibility fix unavailable: " + ex12.GetBaseException().Message)); } try { ItemLightRepair.Apply(_harmony, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogWarning((object)message); }); } catch (Exception ex13) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("ItemLight compatibility unavailable: " + ex13.GetBaseException().Message)); } try { RegisteredPrefabRepair.Apply(_harmony, delegate(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); }); } catch (Exception ex14) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Automatic prefab audit unavailable; known prefab fallbacks remain active: " + ex14.GetBaseException().Message)); } if (typeof(IPunObservable).IsAssignableFrom(typeof(ItemMelee))) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"ItemMelee already implements IPunObservable; no obsolete observation repair needed."); return; } try { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(PhotonView), "Awake", Type.EmptyTypes, (Type[])null); MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(ItemMelee), "Start", Type.EmptyTypes, (Type[])null); if (methodInfo == null || methodInfo2 == null) { throw new MissingMethodException("PhotonView.Awake / ItemMelee.Start"); } _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ObservationRepairPlugin), "ViewAwakePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(ObservationRepairPlugin), "MeleeStartPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); if (flag && sillyEnabled) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"SillyValuables module active: Baguette, Comic Large Pencil, Moonlight Greatsword, Halloween Hammer and configured extra prefabs."); } if (flag2 && steampunkEnabled) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"SteampunkItems module active: Pickaxe_SP and configured extra prefabs."); } if (flag3 && ModuleSettings.MinecraftEnabled) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"MinecraftStrongholdLevel module active: Diamond Sword and automatic SDK prefab auditing."); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Repairs remove only obsolete, non-observable ItemMelee entries; items and valid networking components retained."); } catch (Exception ex15) { ((BaseUnityPlugin)this).Logger.LogError((object)("Item networking repair inactive because the game API is incompatible: " + ex15)); } } private static void ViewAwakePrefix(PhotonView __instance) { int num = MeleeObservationRepair.Repair(__instance); if (num != 0) { ObservationRepairPlugin instance = _instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)$"Removed {num} obsolete ItemMelee observation(s) from {((Object)((Component)__instance).gameObject).name}; gameplay components retained."); } } } private static void MeleeStartPrefix(ItemMelee __instance) { int num = MeleeObservationRepair.RepairForMelee(__instance); if (num != 0) { ObservationRepairPlugin instance = _instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)$"Removed {num} obsolete ItemMelee observation(s) from {((Object)((Component)__instance).gameObject).name} before melee initialization."); } } } private void OnDestroy() { if ((Object)(object)_instance == (Object)(object)this) { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _instance = null; } } } internal static class MeleeObservationRepair { internal static PatchModules Modules = new PatchModules(sillyPresentAndEnabled: false, steampunkPresentAndEnabled: false); internal static bool HasObsoleteMelee(PhotonView view) { if (view?.ObservedComponents == null) { return false; } foreach (Component observedComponent in view.ObservedComponents) { if (observedComponent is ItemMelee && (Object)(object)observedComponent.gameObject == (Object)(object)((Component)view).gameObject && !(observedComponent is IPunObservable)) { return true; } } return false; } internal static int Repair(PhotonView view) { if ((Object)(object)view == (Object)null || !Modules.TryGetModule(((Object)((Component)view).gameObject).name, out var _)) { return 0; } List<Component> observedComponents = view.ObservedComponents; if (observedComponents == null) { return 0; } int num = 0; for (int num2 = observedComponents.Count - 1; num2 >= 0; num2--) { Component val = observedComponents[num2]; if (val is ItemMelee && (Object)(object)val.gameObject == (Object)(object)((Component)view).gameObject && !(val is IPunObservable)) { observedComponents.RemoveAt(num2); num++; } } return num; } internal static int RepairForMelee(ItemMelee melee) { if (!((Object)(object)melee != (Object)null)) { return 0; } return Repair(((Component)melee).GetComponent<PhotonView>()); } } internal sealed class PatchModules { private readonly Dictionary<string, string> _owners = new Dictionary<string, string>(StringComparer.Ordinal); private readonly Dictionary<string, string> _lightOwners = new Dictionary<string, string>(StringComparer.Ordinal); internal bool Any => _owners.Count > 0; internal PatchModules(bool sillyPresentAndEnabled, bool steampunkPresentAndEnabled, string extraSilly = "", string extraSteampunk = "", bool minecraftPresentAndEnabled = false) { if (sillyPresentAndEnabled) { string[] array = new string[3] { "Item Gun Guts", "Item Stop Sign", "Item Pet Rock" }; foreach (string key in array) { _lightOwners[key] = "Sangrento.SillyValuables"; } Add("Sangrento.SillyValuables", new string[4] { "Item Baguette", "Item Comic Large Pencil", "Item The Moonlight Greatsword", "Item Halloween Hammer" }); AddExtra("Sangrento.SillyValuables", extraSilly); } if (steampunkPresentAndEnabled) { Add("SteampunkItems", new string[1] { "Item Melee Pickaxe_SP" }); AddExtra("SteampunkItems", extraSteampunk); } if (minecraftPresentAndEnabled) { Add("MinecraftStrongholdLevel", new string[1] { "MC Item Diamond Sword" }); } } private void Add(string owner, IEnumerable<string> names) { foreach (string name in names) { if (!string.IsNullOrWhiteSpace(name)) { _owners[Normalize(name)] = owner; } } } private void AddExtra(string owner, string names) { Add(owner, (names ?? "").Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)); } private static string Normalize(string name) { if (name == null) { return ""; } name = name.Trim(); while (name.EndsWith("(Clone)", StringComparison.Ordinal)) { name = name.Substring(0, name.Length - 7).TrimEnd(); } return name; } internal bool TryGetModule(string prefabName, out string owner) { return _owners.TryGetValue(Normalize(prefabName), out owner); } internal bool TryGetLightModule(string prefabName, out string owner) { return _lightOwners.TryGetValue(Normalize(prefabName), out owner); } internal bool RegisterOwnedPrefab(string prefabName, string owner) { string text = Normalize(prefabName); if (text.Length == 0 || string.IsNullOrWhiteSpace(owner)) { return false; } if (_owners.TryGetValue(text, out var value)) { return value == owner; } _owners[text] = owner; return true; } } internal static class ModuleSettings { private static ConfigFile _file; internal static ConfigFile File { get { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown object obj = _file; if (obj == null) { ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "ValuablesPatchpack.cfg"), true); _file = val; obj = (object)val; } return (ConfigFile)obj; } } internal static bool SillyEnabled => File.Bind<bool>("Mods", "SillyValuables", true, "Enable ALL Modlist-patchpack fixes for SillyValuables, including API compatibility, melee networking and ItemLight visual initialization. Requires that mod to be installed. Restart after changing.").Value; internal static bool SteampunkEnabled => File.Bind<bool>("Mods", "SteampunkItems", true, "Enable ALL Modlist-patchpack fixes for SteampunkItems. Requires that mod to be installed. Restart after changing.").Value; internal static bool MinecraftEnabled => File.Bind<bool>("Mods", "MinecraftStrongholdLevel", true, "Enable ALL Modlist-patchpack fixes for MinecraftStrongholdLevel, including Diamond Sword, source-attributed SDK prefabs and the minecart's missing optional value display. Requires that mod to be installed. Restart after changing.").Value; internal static bool KeybindEnabled => File.Bind<bool>("Mods", "KeybindLib", true, "Enable ALL Modlist-patchpack fixes for KeybindLib's obsolete inputToggle injection on current R.E.P.O., plus startup-only input-load diagnostics. Requires that mod to be installed. Restart after changing.").Value; internal static bool MoreUpgradesEnabled => File.Bind<bool>("Mods", "MoreUpgrades", true, "Enable ALL Modlist-patchpack fixes for MoreUpgrades: legacy input API, current shop selection/pricing and verified duplicate-manager retirement. Requires that mod to be installed. Disabling restores original input/shop code during preload; restart after changing.").Value; internal static bool PresentsEnabled => File.Bind<bool>("Mods", "REPOPresents", true, "Enable ALL Modlist-patchpack fixes for REPOPresents: registration/spawning APIs and lazy current PrefabRef valuable pools. Disabling restores original calls and pool body during preload; restart after changing.").Value; internal static bool RepoWarningsEnabled => File.Bind<bool>("Mods", "REPOLib", true, "Enable the pack's REPOLib-specific registration logging compatibility: duplicate valuable-name collisions become warnings with the existing skip behavior explained. Missing references and other errors remain errors. Other source mods retain their own master switches. Restart after changing.").Value; internal static bool ExtraBattleEnabled => File.Bind<bool>("Mods", "DarkSpider90.ExtraBattleUpgrades", true, "Enable ALL pack fixes for Extra Battle Upgrades, including the legacy OverrideSpeed call in Panic Response. Retains its existing source-plugin master key. Restart after changing.").Value; internal static bool JnlEnabled => File.Bind<bool>("Mods", "HERO.JNL_Assist", true, "Enable ALL pack fixes for JNL_Assist, including its legacy OverrideSpeed call. Retains its existing source-plugin master key. Restart after changing.").Value; internal static bool WesleysEnemiesEnabled => File.Bind<bool>("Mods", "WesleysEnemies", true, "Enable ALL pack fixes for Wesley's Enemies, including Voodoo's legacy OverrideSpeed call. Restart after changing.").Value; internal static bool ValorantEnabled => File.Bind<bool>("Mods", "ValorantWeapons", true, "Enable ALL pack fixes for Neofeng's asset-only Valorant Weapons package, detected from its SDK bundle path and manifest. Excludes unsupported Standard-shader targets from ItemLight glow animation without changing models/materials. Restart after changing.").Value; internal static bool DandyEnabled => File.Bind<bool>("Mods", "DandysWorldItems", true, "Enable ALL pack fixes for SushiWolf's asset-only Dandy's World Items, detected from its actual SDK bundle path and manifest. Repairs the missing radioactive loop audio source at initialization without changing radiation/gameplay logic. Restart after changing.").Value; internal static bool MelanieEnabled => File.Bind<bool>("Mods", "MelanieLevels", true, "Enable ALL pack fixes for MelanieMelicious's asset-only level package. Skip only verified Mel Mausoleum registration with no entrance-room references, preventing selection of an unloadable map. Does not rebuild the map. Updated content with a valid entrance remains enabled. Restart after changing.").Value; internal static bool ShopSpawnEnabled => File.Bind<bool>("Mods", "AllShopItemsInLevel", true, "Enable ALL pack fixes for ALL Shop Items spawn in Level (REPO_All_Shop_Items_in_Level). Use each item's registered prefab path for multiplayer spawning instead of guessing Items/<name>. Restart after changing.").Value; internal static bool EnabledFor(string guid) { return guid switch { "Sangrento.SillyValuables" => SillyEnabled, "SteampunkItems" => SteampunkEnabled, "MinecraftStrongholdLevel" => MinecraftEnabled, "bulletbot.keybindlib" => KeybindEnabled, "bulletbot.moreupgrades" => MoreUpgradesEnabled, "REPOPresents" => PresentsEnabled, "REPOLib" => RepoWarningsEnabled, "DarkSpider90.ExtraBattleUpgrades" => ExtraBattleEnabled, "HERO.JNL_Assist" => JnlEnabled, "WesleysEnemies" => WesleysEnemiesEnabled, "asset:Neofeng:valorant_weapons_mod" => ValorantEnabled, "asset:SushiWolf:Dandys_World_Items" => DandyEnabled, "asset:MelanieMelicious:Melanie_REPO_Levels_MelanieMelicious" => MelanieEnabled, "REPO_All_Shop_Items_in_Level" => ShopSpawnEnabled, _ => File.Bind<bool>("Mods", Safe(guid), true, "Enable ALL automatic prefab compatibility fixes for detected plugin " + guid + ". Repairs obsolete ItemMelee observations, invalid ItemLight setup and missing optional cart displays only on source-attributed prefabs. Restart after changing.").Value, }; } private static string Safe(string guid) { return (guid ?? "").Replace('[', '_').Replace(']', '_').Replace('=', '_') .Replace('\\', '_') .Replace('/', '_'); } } internal sealed class ContentSources { private readonly Dictionary<string, HashSet<string>> _roots = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase); internal void Add(string directory, string guid) { if (!string.IsNullOrWhiteSpace(directory) && !string.IsNullOrWhiteSpace(guid)) { string key = Path.GetFullPath(directory).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; if (!_roots.TryGetValue(key, out var value)) { value = (_roots[key] = new HashSet<string>(StringComparer.Ordinal)); } value.Add(guid); } } internal string Resolve(string path) { if (string.IsNullOrWhiteSpace(path)) { return null; } string absolute; try { absolute = Path.GetFullPath(path); } catch { return null; } KeyValuePair<string, HashSet<string>> keyValuePair = (from p in _roots where absolute.StartsWith(p.Key, StringComparison.OrdinalIgnoreCase) orderby p.Key.Length descending select p).FirstOrDefault(); HashSet<string> value = keyValuePair.Value; if (value == null || value.Count != 1) { return null; } return keyValuePair.Value.Single(); } } internal static class RegisteredPrefabRepair { private static readonly ContentSources Sources = new ContentSources(); private static readonly Dictionary<AssetBundle, string> Owners = new Dictionary<AssetBundle, string>(); private static readonly Dictionary<Type, PropertyInfo[]> ContentProperties = new Dictionary<Type, PropertyInfo[]>(); private static readonly HashSet<string> Warnings = new HashSet<string>(); private static PropertyInfo _operationPath; private static Action<string> _log; internal static string OwnerFor(AssetBundle bundle) { if (!((Object)(object)bundle != (Object)null) || !Owners.TryGetValue(bundle, out var value) || !ModuleSettings.EnabledFor(value)) { return null; } return value; } internal static void Apply(Harmony harmony, Action<string> log) { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown if (Chainloader.PluginInfos.TryGetValue("REPOLib", out var value) && !((Object)(object)value.Instance == (Object)null)) { Assembly assembly = ((object)value.Instance).GetType().Assembly; MethodInfo methodInfo = assembly.GetType("REPOLib.BundleLoader")?.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault((MethodInfo m) => m.Name == "LoadBundleContent" && m.GetParameters().Length == 2 && m.GetParameters()[1].ParameterType == typeof(AssetBundle)); Type type = assembly.GetType("REPOLib.Objects.Sdk.ItemContent"); Type? type2 = assembly.GetType("REPOLib.Objects.Sdk.ValuableContent"); MethodInfo methodInfo2 = type?.GetMethod("Initialize"); MethodInfo methodInfo3 = type2?.GetMethod("Initialize"); _operationPath = (((object)methodInfo != null) ? methodInfo.GetParameters()[0].ParameterType.GetProperty("Path") : null); if (methodInfo == null || _operationPath == null || methodInfo2 == null || methodInfo3 == null) { throw new MissingMemberException("REPOLib content registration API changed"); } DiscoverSources(); _log = log; harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RegisteredPrefabRepair), "BundlePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(RegisteredPrefabRepair), "ContentPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(RegisteredPrefabRepair), "ContentPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); log("Automatic item prefab audit ready: SDK ownership, obsolete melee observers and invalid ItemLight setup; a master switch for each source mod. No per-frame scans."); } } private static void DiscoverSources() { string[] primary = new string[3] { "Sangrento.SillyValuables", "SteampunkItems", "MinecraftStrongholdLevel" }; foreach (IGrouping<string, PluginInfo> item in Chainloader.PluginInfos.Values.Where((PluginInfo p) => (Object)(object)p.Instance != (Object)null && !string.IsNullOrEmpty(p.Location)).ToList().GroupBy<PluginInfo, string>((PluginInfo p) => Path.GetDirectoryName(p.Location), StringComparer.OrdinalIgnoreCase)) { if (string.Equals(Path.GetFullPath(item.Key).TrimEnd(Path.DirectorySeparatorChar), Path.GetFullPath(Paths.PluginPath).TrimEnd(Path.DirectorySeparatorChar), StringComparison.OrdinalIgnoreCase)) { continue; } PluginInfo val = ((IEnumerable<PluginInfo>)item).FirstOrDefault((Func<PluginInfo, bool>)((PluginInfo p) => primary.Contains(p.Metadata.GUID))); if (val != null) { Sources.Add(item.Key, val.Metadata.GUID); continue; } foreach (PluginInfo item2 in item) { Sources.Add(item.Key, item2.Metadata.GUID); } } } private static void BundlePrefix(object __0, AssetBundle __1) { try { TrackBundle(__0, __1); } catch (Exception error) { Warn("bundle", error); } } private static void TrackBundle(object operation, AssetBundle bundle) { if (!((Object)(object)bundle == (Object)null)) { string text = _operationPath.GetValue(operation) as string; string text2 = Sources.Resolve(text); if (text2 == null) { DiscoverSources(); text2 = Sources.Resolve(text); } if (text2 == null) { text2 = KnownAssetModules.Resolve(text); } if (text2 != null && ModuleSettings.EnabledFor(text2)) { Owners[bundle] = text2; } } } private static void ContentPrefix(object __instance) { try { AuditContent(__instance); } catch (Exception error) { Warn("content", error); } } private static void AuditContent(object __instance) { if (__instance == null) { return; } Type type = __instance.GetType(); if (!ContentProperties.TryGetValue(type, out var value)) { Dictionary<Type, PropertyInfo[]> contentProperties = ContentProperties; PropertyInfo[] obj = new PropertyInfo[2] { type.GetProperty("Bundle"), type.GetProperty("Prefab") }; value = obj; contentProperties[type] = obj; } if (value[0] == null || value[1] == null) { return; } object? value2 = value[0].GetValue(__instance); AssetBundle val = (AssetBundle)((value2 is AssetBundle) ? value2 : null); if (val == null || !Owners.TryGetValue(val, out var value3)) { return; } object? value4 = value[1].GetValue(__instance); Component val2 = (Component)((value4 is Component) ? value4 : null); if (val2 == null) { return; } ItemLightRepair.Audit(val2.gameObject, value3); PhotonView[] componentsInChildren = val2.GetComponentsInChildren<PhotonView>(true); foreach (PhotonView val3 in componentsInChildren) { if (MeleeObservationRepair.HasObsoleteMelee(val3) && MeleeObservationRepair.Modules.RegisterOwnedPrefab(((Object)((Component)val3).gameObject).name, value3)) { int num = MeleeObservationRepair.Repair(val3); if (num > 0) { _log($"[{value3}] Repaired prefab {((Object)((Component)val3).gameObject).name}: removed {num} obsolete ItemMelee observation(s); gameplay retained."); } } } } private static void Warn(string phase, Exception error) { if (Warnings.Add(phase)) { _log?.Invoke("Automatic prefab " + phase + " audit failed; original content registration continues: " + error.GetBaseException().Message); } } } internal static class InputRegistration { internal static bool Add(InputKey key, InputAction action, string tag, bool? toggle, Dictionary<InputKey, InputAction> actions, Dictionary<InputKey, bool> keyboard, Dictionary<InputKey, bool> gamepad, Dictionary<string, InputKey> tags) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (Enum.IsDefined(typeof(InputKey), key) || (key & 0x40000000) == 0 || action == null) { return false; } if (actions.TryGetValue(key, out var value) && value != action) { return false; } bool flag = false; if (!actions.ContainsKey(key)) { actions.Add(key, action); flag = true; } if (toggle.HasValue) { if (!keyboard.ContainsKey(key)) { keyboard.Add(key, toggle.Value); } if (!gamepad.ContainsKey(key)) { gamepad.Add(key, toggle.Value); } } if (!string.IsNullOrEmpty(tag) && tags != null && !tags.ContainsKey(tag)) { tags.Add(tag, key); } if (flag) { action.Enable(); } return flag; } } internal static class KeybindCompat { private static FieldInfo _registered; private static FieldInfo _actions; private static FieldInfo _keyboard; private static FieldInfo _gamepad; private static FieldInfo _tags; private static PropertyInfo _key; private static PropertyInfo _action; private static PropertyInfo _tag; private static PropertyInfo _toggle; private static FieldInfo _defaultToggle; private static object _plugin; private static Action<string> _log; private static bool _warned; internal static bool Apply(Harmony harmony, object plugin, Action<string> log) { //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Expected O, but got Unknown //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Expected O, but got Unknown //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Expected O, but got Unknown //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Expected O, but got Unknown //IL_0309: Expected O, but got Unknown //IL_0309: Expected O, but got Unknown //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Expected O, but got Unknown if (plugin == null || !ModuleSettings.KeybindEnabled) { return false; } Assembly assembly = plugin.GetType().Assembly; Type? type = assembly.GetType("KeybindLib.Patches.InputManagerPatch"); MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "InitializeInputsTranspiler", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.DeclaredMethod(type, "StartTranspiler", (Type[])null, (Type[])null); if (typeof(InputManager).GetField("inputToggle", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null || methodInfo == null || methodInfo2 == null || !PatchProcessor.ReadMethodBody((MethodBase)methodInfo).Any((KeyValuePair<OpCode, object> i) => i.Key == OpCodes.Ldstr && object.Equals(i.Value, "inputToggle"))) { return false; } _actions = AccessTools.Field(typeof(InputManager), "inputActions"); _keyboard = AccessTools.Field(typeof(InputManager), "inputToggleKeyboardMouse"); _gamepad = AccessTools.Field(typeof(InputManager), "inputToggleGamepad"); _tags = AccessTools.Field(typeof(InputManager), "tagDictionary"); _registered = AccessTools.Field(plugin.GetType(), "registeredKeybinds"); Type? type2 = assembly.GetType("KeybindLib.Classes.Keybind"); _key = type2?.GetProperty("inputKey"); _action = type2?.GetProperty("inputAction"); _tag = type2?.GetProperty("tag"); _toggle = type2?.GetProperty("toggle"); _defaultToggle = _toggle?.PropertyType.GetField("defaultValue"); if (_actions == null || _keyboard == null || _gamepad == null || _tags == null || _registered == null || _key == null || _action == null || _tag == null || _toggle == null || _defaultToggle == null) { throw new MissingMemberException("KeybindLib/input registration layout changed"); } _plugin = plugin; _log = log; harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(KeybindCompat), "PassThrough", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(KeybindCompat), "PassThrough", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(InputManager), "InitializeInputs", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(KeybindCompat), "InitializePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(InputManager), "Start", (Type[])null, (Type[])null), new HarmonyMethod(typeof(KeybindCompat), "StartPrefix", (Type[])null), new HarmonyMethod(typeof(KeybindCompat), "LoadedPostfix", (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(KeybindCompat), "StartFinalizer", (Type[])null), (HarmonyMethod)null); MethodInfo methodInfo3 = AccessTools.DeclaredMethod(typeof(InputManager), "LoadKeyBindings", new Type[1] { typeof(string) }, (Type[])null); if (methodInfo3 != null) { harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(KeybindCompat), "LoadedPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } log("KeybindLib compatibility active: replaced the removed inputToggle field injection with idempotent keyboard/gamepad custom-key registration. Startup input diagnostics enabled."); return true; } private static bool PassThrough(IEnumerable<CodeInstruction> __0, ref IEnumerable<CodeInstruction> __result) { __result = __0; return false; } private static void InitializePostfix(InputManager __instance) { Register(__instance); } private static void StartPrefix(InputManager __instance) { Register(__instance); _log("InputManager.Start entered; saved controls should load next."); } private static void Register(InputManager manager) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) try { if (!(_registered.GetValue(_plugin) is IEnumerable enumerable)) { return; } Dictionary<InputKey, InputAction> actions = (Dictionary<InputKey, InputAction>)_actions.GetValue(manager); Dictionary<InputKey, bool> keyboard = (Dictionary<InputKey, bool>)_keyboard.GetValue(manager); Dictionary<InputKey, bool> gamepad = (Dictionary<InputKey, bool>)_gamepad.GetValue(manager); Dictionary<string, InputKey> tags = _tags.GetValue(manager) as Dictionary<string, InputKey>; foreach (object item in enumerable) { object value = _toggle.GetValue(item); InputKey key = (InputKey)_key.GetValue(item); object? value2 = _action.GetValue(item); InputRegistration.Add(key, (InputAction)((value2 is InputAction) ? value2 : null), _tag.GetValue(item) as string, (value == null) ? ((bool?)null) : new bool?((bool)_defaultToggle.GetValue(value)), actions, keyboard, gamepad, tags); } } catch (Exception ex) { if (!_warned) { _warned = true; _log("Custom key registration failed: " + ex.GetBaseException()); } } } private static void LoadedPostfix(InputManager __instance) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) Dictionary<InputKey, InputAction> dictionary = _actions.GetValue(__instance) as Dictionary<InputKey, InputAction>; Dictionary<InputKey, bool> dictionary2 = _keyboard.GetValue(__instance) as Dictionary<InputKey, bool>; string text = "unavailable"; if (dictionary != null && dictionary.TryGetValue((InputKey)15, out var value)) { text = string.Join(", ", ((IEnumerable<InputBinding>)(object)value.bindings).Select((InputBinding b) => ((InputBinding)(ref b)).effectivePath)); } bool value2; bool? flag = ((dictionary2 != null && dictionary2.TryGetValue((InputKey)12, out value2)) ? new bool?(value2) : ((bool?)null)); Action<string> log = _log; string[] obj = new string[5] { "Input startup checkpoint: Sprint=", text, "; keyboard crouch toggle=", null, null }; bool? flag2 = flag; obj[3] = flag2.ToString(); obj[4] = "."; log(string.Concat(obj)); } private static Exception StartFinalizer(Exception __exception) { if (__exception != null) { _log("InputManager.Start failed (saved controls may not have loaded): " + __exception); } return __exception; } } internal static class ExceptionVisibility { private static FieldInfo _original; internal static bool Unrelated(string stack) { if (!string.IsNullOrEmpty(stack)) { if (stack.IndexOf("SillyValuables", StringComparison.Ordinal) < 0) { return stack.IndexOf("SuprimirLogsUnity", StringComparison.Ordinal) < 0; } return false; } return true; } internal static void Apply(Harmony harmony, Assembly silly) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown if (!(silly == null) && ModuleSettings.SillyEnabled) { Type? type = silly.GetType("SuprimirLogsUnity+CustomLogHandler"); MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "LogException", (Type[])null, (Type[])null); _original = AccessTools.Field(type, "originalHandler"); if (!(methodInfo == null) && !(_original == null)) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ExceptionVisibility), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } } private static bool Prefix(object __instance, Exception __0, Object __1) { if (Unrelated(__0?.StackTrace)) { object? value = _original.GetValue(__instance); ILogHandler val = (ILogHandler)((value is ILogHandler) ? value : null); if (val != null && val != __instance) { val.LogException(__0, __1); return false; } } return true; } } public sealed class ItemVisualSource : MonoBehaviour { public string Owner; public string PrefabName; } internal static class ItemLightRepair { private static readonly HashSet<string> Reported = new HashSet<string>(); private static Action<string> _log; private static Action<string> _warn; internal static void Apply(Harmony harmony, Action<string> log, Action<string> warn) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ItemLight), "Start", Type.EmptyTypes, (Type[])null); if (methodInfo == null) { throw new MissingMethodException("ItemLight.Start"); } _log = log; _warn = warn; harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ItemLightRepair), "StartPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static void Audit(GameObject root, string owner) { if ((Object)(object)root == (Object)null || string.IsNullOrEmpty(owner) || !ModuleSettings.EnabledFor(owner)) { return; } ItemLight[] componentsInChildren = root.GetComponentsInChildren<ItemLight>(true); if (componentsInChildren.Length != 0 || root.GetComponentsInChildren<UraniumScript>(true).Length != 0 || root.GetComponentsInChildren<PhysGrabCart>(true).Length != 0) { ItemVisualSource itemVisualSource = root.GetComponent<ItemVisualSource>() ?? root.AddComponent<ItemVisualSource>(); itemVisualSource.Owner = owner; itemVisualSource.PrefabName = ((Object)root).name; ItemLight[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Repair(array[i], root, owner, itemVisualSource.PrefabName); } } } private static bool StartPrefix(ItemLight __instance) { ItemVisualSource componentInParent = ((Component)__instance).GetComponentInParent<ItemVisualSource>(); if ((Object)(object)componentInParent != (Object)null && ModuleSettings.EnabledFor(componentInParent.Owner)) { return Repair(__instance, ((Component)componentInParent).gameObject, componentInParent.Owner, componentInParent.PrefabName); } Transform val = ((Component)__instance).transform; while ((Object)(object)val != (Object)null) { if (MeleeObservationRepair.Modules.TryGetLightModule(((Object)((Component)val).gameObject).name, out var owner) && ModuleSettings.EnabledFor(owner)) { return Repair(__instance, ((Component)val).gameObject, owner, ((Object)((Component)val).gameObject).name); } val = val.parent; } return true; } internal static bool Repair(ItemLight controller, GameObject root, string owner, string prefabName) { if ((Object)(object)controller == (Object)null || (Object)(object)root == (Object)null) { return true; } if (!((Behaviour)controller).enabled) { return false; } int num = 0; if (controller.meshRenderers == null) { controller.meshRenderers = new List<MeshRenderer>(); } for (int num2 = controller.meshRenderers.Count - 1; num2 >= 0; num2--) { MeshRenderer val = controller.meshRenderers[num2]; if ((Object)(object)val == (Object)null || (Object)(object)((Renderer)val).sharedMaterial == (Object)null || !((Renderer)val).sharedMaterial.HasProperty("_FresnelScale")) { controller.meshRenderers.RemoveAt(num2); num++; } } if (num > 0) { Report(owner, prefabName, "fresnel", $"Excluded {num} unsupported glow target(s) from ItemLight's animation list; renderers/materials retained."); } if ((Object)(object)controller.itemLight == (Object)null) { Light[] componentsInChildren = ((Component)controller).GetComponentsInChildren<Light>(true); Light val2 = ((componentsInChildren.Length == 1) ? componentsInChildren[0] : null); if ((Object)(object)val2 == (Object)null && componentsInChildren.Length == 0 && owner == "Sangrento.SillyValuables" && BaseName(prefabName) == "Item Stop Sign") { Light[] componentsInChildren2 = root.GetComponentsInChildren<Light>(true); if (componentsInChildren2.Length == 1 && ((Object)((Component)componentsInChildren2[0]).gameObject).name == "Point Light") { val2 = componentsInChildren2[0]; } } if (!((Object)(object)val2 != (Object)null)) { ((Behaviour)controller).enabled = false; Report(owner, prefabName, "disabled", "Disabled only the invalid ItemLight visual controller: no unambiguous local Light exists. Item/gameplay retained.", warning: true); return false; } controller.itemLight = val2; Report(owner, prefabName, "rebind", "Restored ItemLight's missing reference to its existing local Light."); } if (controller.lightIntensityCurve == null) { controller.lightIntensityCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f); Report(owner, prefabName, "curve", "Restored a missing ItemLight fade curve with a linear fade."); } return true; } private static string BaseName(string name) { name = name ?? ""; while (name.EndsWith("(Clone)", StringComparison.Ordinal)) { name = name.Substring(0, name.Length - 7).TrimEnd(); } return name; } private static void Report(string owner, string prefab, string kind, string message, bool warning = false) { if (Reported.Add(owner + "|" + prefab + "|" + kind)) { (warning ? _warn : _log)?.Invoke("[" + owner + "] " + prefab + ": " + message); } } } internal static class MoreUpgradesShopCompat { private static Func<Item, bool> _skip; private static Func<Item, float> _multiplier; private static Action<string> _log; private static bool _warned; private static bool _applied; internal static bool Apply(Harmony harmony, object plugin, Action<string> log) { //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown if (plugin == null || !ModuleSettings.MoreUpgradesEnabled) { return false; } Assembly assembly = plugin.GetType().Assembly; Type type = assembly.GetType("MoreUpgrades.Patches.UpgradeStandPatch"); if (type?.GetMethod("__ModlistOriginal_GetWeightedUpgradeExcludingTranspiler", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) == null) { return false; } MethodInfo method = type.GetMethod("GetWeightedUpgradeExcluding", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Item) }, null); MethodInfo methodInfo = assembly.GetType("MoreUpgrades.Classes.MoreUpgradesAPI")?.GetMethod("ItemValueMultiplier", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Item) }, null); MethodInfo methodInfo2 = typeof(UpgradeStand).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault((MethodInfo m) => m.Name == "GetWeightedUpgradeExcluding" && m.GetParameters().Length == 4); if (method == null || methodInfo == null || methodInfo2 == null) { throw new MissingMemberException("MoreUpgrades shop API changed"); } _skip = AccessTools.MethodDelegate<Func<Item, bool>>(method, (object)null, true); _multiplier = AccessTools.MethodDelegate<Func<Item, float>>(methodInfo, (object)null, true); _log = log; _applied = false; harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MoreUpgradesShopCompat), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); if (_applied) { log("MoreUpgrades shop compatibility ready: current upgrade selection respects disabled upgrades and per-item price multipliers."); } return _applied; } private static bool Skip(Item item) { return _skip(item); } private static float Multiplier(Item item) { return _multiplier(item); } internal static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod) { //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Expected O, but got Unknown //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Expected O, but got Unknown List<CodeInstruction> code = instructions.ToList(); _applied = false; List<int> list = (from i in Enumerable.Range(0, Math.Max(0, code.Count - 1)) where code[i].operand is MethodInfo { Name: "get_Current" } methodInfo && methodInfo.ReturnType == typeof(Item) && LocalIndex(code[i + 1]) >= 0 select i).ToList(); if (list.Count != 1) { return Unchanged(code, "candidate loop not uniquely identified"); } int num = list[0] + 1; int num2 = LocalIndex(code[num]); if (num + 4 >= code.Count) { return Unchanged(code, "candidate loop is incomplete"); } IList<LocalVariableInfo> list2 = __originalMethod.GetMethodBody()?.LocalVariables; if (list2 == null || num2 >= list2.Count || list2[num2].LocalType != typeof(Item)) { return Unchanged(code, "candidate local type changed"); } int num3 = Enumerable.Range(num + 1, Math.Min(12, code.Count - num - 3)).FirstOrDefault((int i) => code[i].operand is FieldInfo fieldInfo && fieldInfo.DeclaringType == typeof(Item) && fieldInfo.Name == "itemType" && (code[i + 2].opcode == OpCodes.Bne_Un || code[i + 2].opcode == OpCodes.Bne_Un_S) && code[i + 2].operand is Label); if (num3 == 0) { return Unchanged(code, "native item-type continue branch changed"); } if (code[num + 1].blocks.Count != 0) { return Unchanged(code, "candidate boundary has exception metadata"); } CodeInstruction val = LoadFor(code[num]); List<int> list3 = (from i in Enumerable.Range(0, Math.Max(0, code.Count - 1)) where code[i].opcode == OpCodes.Ldsfld && code[i].operand is FieldInfo fieldInfo && fieldInfo.DeclaringType == typeof(ShopManager) && fieldInfo.Name == "instance" && code[i + 1].opcode == OpCodes.Ldfld && code[i + 1].operand is FieldInfo fieldInfo2 && fieldInfo2.DeclaringType == typeof(ShopManager) && fieldInfo2.Name == "itemValueMultiplier" select i).ToList(); if (list3.Count != 1) { return Unchanged(code, "native price multiplier not uniquely identified"); } int num4 = list3[0]; code[num4].opcode = val.opcode; code[num4].operand = val.operand; code[num4 + 1].opcode = OpCodes.Call; code[num4 + 1].operand = AccessTools.DeclaredMethod(typeof(MoreUpgradesShopCompat), "Multiplier", (Type[])null, (Type[])null); CodeInstruction val2 = LoadFor(code[num]); CodeInstructionExtensions.MoveLabelsTo(code[num + 1], val2); code.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { val2, new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(MoreUpgradesShopCompat), "Skip", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Brtrue, code[num3 + 2].operand) }); _applied = true; return code; } private static IEnumerable<CodeInstruction> Unchanged(List<CodeInstruction> code, string reason) { if (!_warned) { _warned = true; _log?.Invoke("MoreUpgrades shop compatibility skipped: " + reason + ". Native selection retained."); } return code; } internal static int LocalIndex(CodeInstruction i) { if (i.opcode == OpCodes.Stloc_0) { return 0; } if (i.opcode == OpCodes.Stloc_1) { return 1; } if (i.opcode == OpCodes.Stloc_2) { return 2; } if (i.opcode == OpCodes.Stloc_3) { return 3; } if (i.opcode != OpCodes.Stloc && i.opcode != OpCodes.Stloc_S) { return -1; } if (!(i.operand is LocalBuilder localBuilder)) { if (!(i.operand is LocalVariableInfo localVariableInfo)) { object operand = i.operand; if (operand is int) { return (int)operand; } operand = i.operand; if (operand is byte) { return (byte)operand; } return -1; } return localVariableInfo.LocalIndex; } return localBuilder.LocalIndex; } internal static CodeInstruction LoadFor(CodeInstruction store) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown if (!(store.opcode == OpCodes.Stloc_0)) { if (!(store.opcode == OpCodes.Stloc_1)) { if (!(store.opcode == OpCodes.Stloc_2)) { if (!(store.opcode == OpCodes.Stloc_3)) { return new CodeInstruction((store.opcode == OpCodes.Stloc_S) ? OpCodes.Ldloc_S : OpCodes.Ldloc, store.operand); } return new CodeInstruction(OpCodes.Ldloc_3, (object)null); } return new CodeInstruction(OpCodes.Ldloc_2, (object)null); } return new CodeInstruction(OpCodes.Ldloc_1, (object)null); } return new CodeInstruction(OpCodes.Ldloc_0, (object)null); } } internal static class MoreShopInventoryCompat { private static Func<Item, bool> _skip; private static Func<Item, float> _multiplier; private static Action<string> _log; private static bool _applied; private static bool _warned; internal static bool Apply(Harmony harmony, object plugin, Action<string> log) { //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown if (plugin == null || !ModuleSettings.MoreUpgradesEnabled) { return false; } Assembly assembly = plugin.GetType().Assembly; Type type = assembly.GetType("MoreUpgrades.Patches.ShopManagerPatch"); if (type?.GetMethod("__ModlistOriginal_GetAllItemsFromStatsManagerTranspiler", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) == null) { return false; } MethodInfo method = type.GetMethod("GetAllItemsFromStatsManager", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Item) }, null); MethodInfo methodInfo = assembly.GetType("MoreUpgrades.Classes.MoreUpgradesAPI")?.GetMethod("ItemValueMultiplier", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Item) }, null); MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(ShopManager), "GetAllItemsFromStatsManager", Type.EmptyTypes, (Type[])null); if (method == null || methodInfo == null || methodInfo2 == null) { throw new MissingMemberException("MoreUpgrades shop inventory API changed"); } _skip = AccessTools.MethodDelegate<Func<Item, bool>>(method, (object)null, true); _multiplier = AccessTools.MethodDelegate<Func<Item, float>>(methodInfo, (object)null, true); _log = log; _applied = false; harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MoreShopInventoryCompat), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); if (_applied) { log("MoreUpgrades shop inventory compatibility ready: disabled-item filtering and per-item pricing retained; native stock rules unchanged."); } return _applied; } private static bool Skip(Item item) { return _skip(item); } private static float Multiplier(Item item) { return _multiplier(item); } internal static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod) { //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Expected O, but got Unknown //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Expected O, but got Unknown List<CodeInstruction> code = instructions.ToList(); _applied = false; List<int> list = (from i in Enumerable.Range(1, Math.Max(0, code.Count - 2)) where code[i].operand is MethodInfo { Name: "get_Current" } methodInfo && methodInfo.DeclaringType == typeof(IEnumerator<Item>) && methodInfo.ReturnType == typeof(Item) && MoreUpgradesShopCompat.LocalIndex(code[i + 1]) >= 0 select i).ToList(); List<int> list2 = (from i in Enumerable.Range(1, Math.Max(0, code.Count - 2)) where code[i].operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(IEnumerator) && methodInfo.Name == "MoveNext" && (code[i + 1].opcode == OpCodes.Brtrue || code[i + 1].opcode == OpCodes.Brtrue_S) && code[i + 1].operand is Label select i).ToList(); List<int> list3 = (from i in Enumerable.Range(0, Math.Max(0, code.Count - 1)) where code[i].opcode == OpCodes.Ldarg_0 && code[i + 1].opcode == OpCodes.Ldfld && code[i + 1].operand is FieldInfo fieldInfo && fieldInfo.DeclaringType == typeof(ShopManager) && fieldInfo.Name == "itemValueMultiplier" select i).ToList(); if (list.Count != 1 || list2.Count != 1 || list3.Count != 1) { return Unchanged(code, "native inventory loop/price sites not unique"); } int num = list[0]; int num2 = num + 1; int num3 = list2[0]; int num4 = list3[0]; IList<LocalVariableInfo> list4 = __originalMethod.GetMethodBody()?.LocalVariables; int num5 = MoreUpgradesShopCompat.LocalIndex(code[num2]); if (list4 == null || num5 >= list4.Count || list4[num5].LocalType != typeof(Item) || num2 + 1 >= code.Count || num3 <= num2 || num4 <= num2 || num4 >= num3 || code[num2 + 1].blocks.Count != 0) { return Unchanged(code, "native item local or loop boundary changed"); } CodeInstruction val = code[num3 - 1]; if (val.opcode != code[num - 1].opcode || !object.Equals(val.operand, code[num - 1].operand)) { return Unchanged(code, "enumerator receivers differ"); } IList receiverLabels = typeof(CodeInstruction).GetField("labels")?.GetValue(val) as IList; if (receiverLabels == null) { return Unchanged(code, "native continue labels unavailable"); } List<CodeInstruction> list5 = (from i in code.Take(num - 1) where (i.opcode == OpCodes.Br || i.opcode == OpCodes.Br_S) && i.operand is Label && receiverLabels.Contains(i.operand) select i).ToList(); if (list5.Count != 1) { return Unchanged(code, "native continue target not unique"); } CodeInstruction val2 = MoreUpgradesShopCompat.LoadFor(code[num2]); code[num4].opcode = val2.opcode; code[num4].operand = val2.operand; code[num4 + 1].opcode = OpCodes.Call; code[num4 + 1].operand = AccessTools.DeclaredMethod(typeof(MoreShopInventoryCompat), "Multiplier", (Type[])null, (Type[])null); CodeInstruction val3 = MoreUpgradesShopCompat.LoadFor(code[num2]); CodeInstructionExtensions.MoveLabelsTo(code[num2 + 1], val3); code.InsertRange(num2 + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { val3, new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(MoreShopInventoryCompat), "Skip", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Brtrue, list5[0].operand) }); _applied = true; return code; } private static IEnumerable<CodeInstruction> Unchanged(List<CodeInstruction> code, string reason) { if (!_warned) { _warned = true; _log?.Invoke("MoreUpgrades shop inventory compatibility skipped: " + reason + ". Native inventory retained."); } return code; } } internal static class RegistrationWarnings { private static Action<object, bool> _warning; internal static bool IsDuplicateName(object message) { if (message is string text && text.StartsWith("Failed to register valuable \"", StringComparison.Ordinal)) { return text.EndsWith("\". A valuable prefab is already registered with the same name.", StringComparison.Ordinal); } return false; } internal static void Apply(Harmony harmony, Assembly repo) { //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown if (!(repo == null) && ModuleSettings.RepoWarningsEnabled) { Type type = repo.GetType("REPOLib.Logger"); MethodInfo methodInfo = type?.GetMethod("LogError", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(object), typeof(bool) }, null); MethodInfo methodInfo2 = type?.GetMethod("LogWarning", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(object), typeof(bool) }, null); if (methodInfo == null || methodInfo2 == null) { throw new MissingMethodException("REPOLib registration logger"); } _warning = AccessTools.MethodDelegate<Action<object, bool>>(methodInfo2, (object)null, true); harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RegistrationWarnings), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static bool Prefix(object __0, bool __1) { if (!IsDuplicateName(__0)) { return true; } _warning(__0?.ToString() + " Existing prefab retained; incoming duplicate skipped. Names and registration behavior are unchanged.", __1); return false; } } internal static class SillyHealthMeshRepair { private static readonly HashSet<string> Names = new HashSet<string> { "Item Health Chips for Noobs (100)", "Item Health Candy Bucket", "Item Health Pizza" }; private static readonly HashSet<string> Reported = new HashSet<string>(); private static Action<string> _log; internal static void Apply(Harmony harmony, bool sillyPresent, Action<string> log) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown if (sillyPresent && ModuleSettings.SillyEnabled) { _log = log; harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ItemHealthPack), "Start", Type.EmptyTypes, (Type[])null), new HarmonyMethod(typeof(SillyHealthMeshRepair), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } internal static void Prefix(ItemHealthPack __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.mesh != (Object)null) { return; } string text = ((Object)((Component)__instance).gameObject).name; while (text.EndsWith("(Clone)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - 7).TrimEnd(); } if (!Names.Contains(text)) { return; } MeshRenderer[] array = (from r in ((Component)__instance).GetComponentsInChildren<MeshRenderer>(true) where ((Object)((Component)r).gameObject).name == "Handle1" && (Object)(object)((Renderer)r).sharedMaterial != (Object)null select r).ToArray(); if (array.Length != 1) { if (Reported.Add(text + "|missing")) { _log?.Invoke(text + ": health mesh repair skipped; no unique Handle1 renderer. Original health behavior retained."); } return; } __instance.mesh = array[0]; if (Reported.Add(text)) { _log?.Invoke("[Sangrento.SillyValuables] " + text + ": restored missing health-pack mesh reference to the existing Handle1 renderer."); } } } internal static class MoreManagerCompat { private static FieldInfo _instance; private static Action<string> _log; private const int ExpectedId = 876842; internal static void Apply(Harmony harmony, object plugin, Action<string> log) { //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Expected O, but got Unknown if (plugin == null || !ModuleSettings.MoreUpgradesEnabled) { return; } Type type = plugin.GetType().Assembly.GetType("MoreUpgrades.Classes.MoreUpgradesManager"); FieldInfo fieldInfo = type?.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo methodInfo = type?.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(fieldInfo == null) && !(methodInfo == null) && !(fieldInfo.FieldType != type)) { List<KeyValuePair<OpCode, object>> list = (from i in PatchProcessor.ReadMethodBody((MethodBase)methodInfo) where i.Key != OpCodes.Nop select i).ToList(); if (list.Count >= 2 && !(list[0].Key != OpCodes.Ldarg_0) && !(list[1].Key != OpCodes.Stsfld) && object.Equals(list[1].Value, fieldInfo) && list.Any((KeyValuePair<OpCode, object> i) => i.Key == OpCodes.Ldc_I4 && object.Equals(i.Value, 876842)) && !list.Any((KeyValuePair<OpCode, object> i) => i.Value is MethodInfo methodInfo2 && (methodInfo2.Name == "Destroy" || (methodInfo2.DeclaringType == typeof(PhotonView) && methodInfo2.Name == "Find")))) { _instance = fieldInfo; _log = log; harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MoreManagerCompat), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } } private static void Prefix(Component __instance) { MonoBehaviour previous = default(MonoBehaviour); ref MonoBehaviour reference = ref previous; object? value = _instance.GetValue(null); reference = (MonoBehaviour)((value is MonoBehaviour) ? value : null); if ((Object)(object)previous == (Object)null || (Object)(object)previous == (Object)(object)__instance || (Object)(object)((Component)previous).gameObject == (Object)(object)__instance.gameObject) { return; } PhotonView view = ((Component)previous).GetComponent<PhotonView>(); if (!((Object)(object)view == (Object)null) && view.ViewID == 876842 && !((Object)(object)PhotonView.Find(876842) != (Object)(object)view)) { view.ViewID = 0; ((Behaviour)previous).enabled = false; previous.StopAllCoroutines(); bool num = ((Component)previous).GetComponents<Component>().All((Component c) => c is Transform || (Object)(object)c == (Object)(object)previous || (Object)(object)c == (Object)(object)view); Object.Destroy((Object)(object)view); Object.Destroy((Object)(object)previous); if (num) { Object.Destroy((Object)(object)((Component)previous).gameObject); } _log("MoreUpgrades: retired the previous verified manager before registering its replacement; fixed Photon ID preserved."); } } } internal static class KnownAssetModules { internal const string ValorantOwner = "asset:Neofeng:valorant_weapons_mod"; internal const string DandyOwner = "asset:SushiWolf:Dandys_World_Items"; internal const string MelanieOwner = "asset:MelanieMelicious:Melanie_REPO_Levels_MelanieMelicious"; internal static string Resolve(string bundlePath) { if (string.IsNullOrEmpty(bundlePath)) { return null; } try { if (ModuleSettings.ValorantEnabled && Matches("Neofeng-valorant_weapons_mod", "valorant_weapons_mod")) { return "asset:Neofeng:valorant_weapons_mod"; } if (ModuleSettings.DandyEnabled && Matches("SushiWolf-Dandys_World_Items", "Dandys_World_Items")) { return "asset:SushiWolf:Dandys_World_Items"; } if (ModuleSettings.MelanieEnabled && Matches("MelanieMelicious-Melanie_REPO_Levels_MelanieMelicious", "Melanie_REPO_Levels_MelanieMelicious", "melanierepointeriors")) { return "asset:MelanieMelicious:Melanie_REPO_Levels_MelanieMelicious"; } return null; } catch (IOException) { return null; } catch (UnauthorizedAccessException) { return null; } catch (ArgumentException) { return null; } bool Matches(string directory, string name, string bundleName = null) { string path = Path.Combine(Paths.PluginPath, directory); string fullPath = Path.GetFullPath(Path.Combine(path, (bundleName ?? name) + ".repobundle")); if (!string.Equals(Path.GetFullPath(bundlePath), fullPath, StringComparison.OrdinalIgnoreCase) || !File.Exists(fullPath)) { return false; } string path2 = Path.Combine(path, "manifest.json"); if (File.Exists(path2)) { return Regex.IsMatch(File.ReadAllText(path2), "\"name\"\\s*:\\s*\"" + Regex.Escape(name) + "\"", RegexOptions.CultureInvariant); } return false; } } } internal static class MelanieLevelGuard { private static PropertyInfo _bundle; private static PropertyInfo _level; private static PropertyInfo _starts; private static Action<string> _log; private static readonly HashSet<string> Reported = new HashSet<string>(); internal static void Apply(Harmony harmony, Assembly repo, Action<string> log) { //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown if (!ModuleSettings.MelanieEnabled || repo == null) { return; } Type type = repo.GetType("REPOLib.Objects.Sdk.LevelContent"); MethodInfo methodInfo = repo.GetType("REPOLib.Modules.Levels")?.GetMethod("RegisterLevel", BindingFlags.Static | BindingFlags.Public, null, (type == null) ? Type.EmptyTypes : new Type[1] { type }, null); if (!(type == null) && !(methodInfo == null)) { _bundle = type.GetProperty("Bundle"); _level = type.GetProperty("Level"); _starts = type.GetProperty("StartRooms"); if (!(_bundle?.PropertyType != typeof(AssetBundle)) && !(_level?.PropertyType != typeof(Level)) && !(_starts?.PropertyType != typeof(List<GameObject>))) { _log = log; harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MelanieLevelGuard), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } } internal static bool Prefix(object __0) { if (!ModuleSettings.MelanieEnabled || __0 == null) { return true; } try { Object val = (Object)((__0 is Object) ? __0 : null); if (val != null && !(val.name != "MelanieMausoleumLevel")) { object? value = _bundle.GetValue(__0); AssetBundle val2 = (AssetBundle)((value is AssetBundle) ? value : null); if (val2 != null && !(RegisteredPrefabRepair.OwnerFor(val2) != "asset:MelanieMelicious:Melanie_REPO_Levels_MelanieMelicious")) { object? value2 = _level.GetValue(__0); Level val3 = (Level)((value2 is Level) ? value2 : null); if (val3 != null && !(((Object)val3).name != "Mel Mausoleum")) { if (_starts.GetValue(__0) is IList list) { foreach (object item in list) { GameObject val4 = (GameObject)((item is GameObject) ? item : null); if (val4 != null && (Object)(object)val4 != (Object)null) { return true; } } } if (Reported.Add("skip")) { _log?.Invoke("[MelanieLevels] Skipped Mel Mausoleum: its LevelContent has no entrance-room references on this SDK and would fail StartRoomGeneration. Other maps remain available. Update the map's SDK content asset to restore it; set Mods/MelanieLevels=false to disable this guard."); } return false; } } } return true; } catch (Exception ex) { if (Reported.Add("error")) { _log?.Invoke("[MelanieLevels] Registration guard unavailable; original registration retained: " + ex.GetBaseException().Message); } return true; } } } internal static class DandyUraniumRepair { private static readonly HashSet<string> Reported = new HashSet<string>(); private static Action<string> _log; private static Action<GameObject> _fixAudio; internal static void Apply(Harmony harmony, Assembly repo, Action<string> log) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown if (ModuleSettings.DandyEnabled && !(repo == null)) { _log = log; MethodInfo methodInfo = repo.GetType("REPOLib.Modules.Utilities")?.GetMethod("FixAudioMixerGroups", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(GameObject) }, null); if (methodInfo != null) { _fixAudio = AccessTools.MethodDelegate<Action<GameObject>>(methodInfo, (object)null, true); } harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(UraniumScript), "Start", Type.EmptyTypes, (Type[])null), new HarmonyMethod(typeof(DandyUraniumRepair), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } internal static void Prefix(UraniumScript __instance) { //IL_00a6: 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) if ((Object)(object)__instance == (Object)null || __instance.instant || !ModuleSettings.DandyEnabled) { return; } ItemVisualSource componentInParent = ((Component)__instance).GetComponentInParent<ItemVisualSource>(); if ((Object)(object)componentInParent == (Object)null || componentInParent.Owner != "asset:SushiWolf:Dandys_World_Items") { return; } Sound uraniumSoundLoop = __instance.uraniumSoundLoop; if (uraniumSoundLoop == null || (Object)(object)uraniumSoundLoop.Source != (Object)null || uraniumSoundLoop.Sounds == null || uraniumSoundLoop.Sounds.Length == 0) { return; } AudioSource[] array = (((Object)(object)__instance.geigerLoopObject == (Object)null) ? Array.Empty<AudioSource>() : __instance.geigerLoopObject.GetComponentsInChildren<AudioSource>(true)); AudioSource val = ((array.Length == 1) ? array[0] : null); if ((Object)(object)val != (Object)null) { GameObject val2 = new GameObject("Modlist Uranium Loop"); val2.transform.SetParent(((Component)__instance).transform, false); AudioSource val3 = val2.AddComponent<AudioSource>(); CopySettings(val, val3); uraniumSoundLoop.Source = val3; try { _fixAudio?.Invoke(((Component)val3).gameObject); } catch (Exception ex) { Report(componentInParent.PrefabName, "routing", "Audio routing repair unavailable: " + ex.GetBaseException().Message); } Report(componentInParent.PrefabName, "source", "Restored a dedicated loop AudioSource using the authored geiger audio settings; native radiation behavior retained."); } else { uraniumSoundLoop.Sounds = Array.Empty<AudioClip>(); Report(componentInParent.PrefabName, "muted", "Missing loop source and no unique audio template: disabled only the invalid loop playlist; item/radiation behavior retained."); } } private static void CopySettings(AudioSource from, AudioSource to) { //IL_0081: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) to.playOnAwake = false; to.outputAudioMixerGroup = from.outputAudioMixerGroup; to.volume = from.volume; to.pitch = from.pitch; to.panStereo = from.panStereo; to.spatialBlend = from.spatialBlend; to.reverbZoneMix = from.reverbZoneMix; to.dopplerLevel = from.dopplerLevel; to.spread = from.spread; to.minDistance = from.minDistance; to.maxDistance = from.maxDistance; to.rolloffMode = from.rolloffMode; to.priority = from.priority; to.bypassEffects = from.bypassEffects; to.bypassListenerEffects = from.bypassListenerEffects; to.bypassReverbZones = from.bypassReverbZones; to.spatialize = from.spatialize; to.spatializePostEffects = from.spatializePostEffects; to.ignoreListenerPause = from.ignoreListenerPause; to.ignoreListenerVolume = from.ignoreListenerVolume; to.velocityUpdateMode = from.velocityUpdateMode; AudioSourceCurveType[] array = new AudioSourceCurveType[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); AudioSourceCurveType[] array2 = (AudioSourceCurveType[])(object)array; foreach (AudioSourceCurveType val in array2) { AnimationCurve customCurve = from.GetCustomCurve(val); if (customCurve != null) { to.SetCustomCurve(val, customCurve); } } } private static void Report(string prefab, string kind, string message) { if (Reported.Add(prefab + "|" + kind)) { _log?.Invoke("[DandysWorldItems] " + prefab + ": " + message); } } } internal static class PresentsPoolCompat { private sealed class Pool { internal List<PrefabRef> Items; } private static readonly ConditionalWeakTable<object, Pool> Pools = new ConditionalWeakTable<object, Pool>(); private static Func<GameObject, bool> _self; internal static void Apply(Harmony harmony, object plugin, Action<string> log) { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown if (plugin == null || !ModuleSettings.PresentsEnabled) { return; } Assembly assembly = plugin.GetType().Assembly; if (!(assembly.GetType("REPOPresents.ValuableUtil")?.GetMethod("__ModlistOriginal_GetValuablesByVolumeType", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) == null)) { Type? type = assembly.GetType("REPOPresents.ValuablePresent"); MethodInfo methodInfo = type?.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo methodInfo2 = type?.GetMethod("FindReplacement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo method = plugin.GetType().GetMethod("WasRegisteredBySelf", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(GameObject) }, null); if (!(methodInfo == null) && !(methodInfo2?.ReturnType != typeof(GameObject)) && !(method?.ReturnType != typeof(bool))) { _self = (Func<GameObject, bool>)Delegate.CreateDelegate(typeof(Func<GameObject, bool>), plugin, method); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PresentsPoolCompat), "AwakePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(PresentsPoolCompat), "FindPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); log("REPOPresents: current valuable pools retained as PrefabRefs; only selected replacements are resolved, with the original five-attempt/self-exclusion rule."); } } } private static void AwakePostfix(Component __instance) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected I4, but got Unknown if (ModuleSettings.PresentsEnabled) { ValuableObject component = __instance.GetComponent<ValuableObject>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)RunManager.instance == (Object)null) && !((Object)(object)RunManager.instance.levelCurrent == (Object)null)) { Cache(__instance, RunManager.instance.levelCurrent, (int)component.volumeType); } } } internal static void Cache(object owner, Level level, int volume) { List<PrefabRef> list = new List<PrefabRef>(); if (level?.ValuablePresets != null) { foreach (LevelValuables valuablePreset in level.ValuablePresets) { if (!((Object)(object)valuablePreset == (Object)null)) { List<PrefabRef> list2 = volume switch { 6 => valuablePreset.veryTall, 5 => valuablePreset.tall, 4 => valuablePreset.wide, 3 => valuablePreset.big, 2 => valuablePreset.medium, 1 => valuablePreset.small, 0 => valuablePreset.tiny, _ => null, }; if (list2 != null) { list.AddRange(list2); } } } } Pools.Remove(owner); Pools.Add(owner, new Pool { Items = list }); } internal static bool FindPrefix(object __instance, ref GameObject __result) { if (!ModuleSettings.PresentsEnabled || !Pools.TryGetValue(__instance, out var value)) { return true; } __result = Choose(value.Items, _self, (int count) => Random.Range(0, count)); return false; } internal static GameObject Choose(List<PrefabRef> refs, Func<GameObject, bool> self, Func<int, int> pick) { for (int i = 0; i < 5; i++) { if (refs.Count <= 0) { break; } GameObject val = ((PrefabRef<GameObject>)(object)refs[pick(refs.Count)])?.Prefab; if ((Object)(object)val != (Object)null && !self(val)) { return val; } } return null; } } internal static class CartDisplayCompat { private sealed class Policy { internal string Owner; } private static readonly ConditionalWeakTable<PhysGrabCart, Policy> Missing = new ConditionalWeakTable<PhysGrabCart, Policy>(); private static readonly HashSet<string> Reported = new HashSet<string>(); private static bool _minecraft; private static Action<string> _log; internal static void Apply(Harmony harmony, bool minecraft, Action<string> log) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown _minecraft = minecraft; _log = log; harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(PhysGrabCart), "Start", Type.EmptyTypes, (Type[])null), new HarmonyMethod(typeof(CartDisplayCompat), "StartPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(PhysGrabCart), "ObjectsInCart", Type.EmptyTypes, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(CartDisplayCompat), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } internal static void StartPrefix(PhysGrabCart __instance) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.valueScreen != (Object)null) { return; } string text = ((Component)__instance).GetComponentInParent<ItemVisualSource>()?.Owner; if (text == null && _minecraft && (((Object)((Component)__instance).gameObject).name == "Item Minecart" || ((Object)((Component)__instance).gameObject).name == "Item Minecart(Clone)")) { text = "MinecraftStrongholdLevel"; } if (text == null || text == "rpgmod.semibotrpg" || !ModuleSettings.EnabledFor(text)) { return; } ValueScreen[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<ValueScreen>(true); if (componentsInChildren.Length == 1) { __instance.valueScreen = componentsInChildren[0]; return; } Missing.GetValue(__instance, (PhysGrabCart key) => new Policy()).Owner = text; if (Reported.Add(text + "|" + ((Object)((Component)__instance).gameObject).name)) { _log?.Invoke("[" + text + "] " + ((Object)((Component)__instance).gameObject).name + ": no unambiguous cart ValueScreen; keep native cargo counting/physics and omit only the unassigned display update."); } } internal static void Display(ValueScreen screen, int value, PhysGrabCart cart) { if (!((Object)(object)screen == (Object)null) || !((Object)(object)cart != (Object)null) || !Missing.TryGetValue(cart, out var value2) || !ModuleSettings.EnabledFor(value2.Owner)) { screen.UpdateValue(value); } } internal static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); MethodInfo target = AccessTools.DeclaredMethod(typeof(ValueScreen), "UpdateValue", new Type[1] { typeof(int) }, (Type[])null); List<CodeInstruction> list2 = list.Where((CodeInstruction i) => i.opcode == OpCodes.Callvirt && object.Equals(i.operand, target)).ToList(); if (list2.Count != 1 || list2[0].blocks.Count != 0) { return list; } int index = list.IndexOf(list2[0]); CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null); CodeInstructionExtensions.MoveLabelsTo(list2[0], val); list2[0].opcode = OpCodes.Call; list2[0].operand = AccessTools.DeclaredMethod(typeof(CartDisplayCompat), "Display", (Type[])null, (Type[])null); list.Insert(index, val); return list; } } internal static class ShopSpawnPathCompat { private static bool _applied; internal static bool Apply(Harmony harmony, object plugin, Action<string> log) { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown if (plugin == null || !ModuleSettings.ShopSpawnEnabled) { return false; } MethodInfo methodInfo = plugin.GetType().Assembly.GetType("REPO_All_Shop_Items_in_Level.Plugin")?.GetMethod("SpawnItem", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[4] { typeof(Item), typeof(Vector3), typeof(Quaternion), typeof(bool) }, null); if (methodInfo?.ReturnType != typeof(GameObject)) { return false; } _applied = false; harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ShopSpawnPathCompat), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); if (_applied) { log("ALL Shop Items in Level: item spawns use registered prefab resource paths, including aliases and asset bundles, instead of guessing Items/<item name>."); } return _applied; } internal static string PathFor(Item item) { if (item?.prefab == null || string.IsNullOrEmpty(((PrefabRef<GameObject>)(object)item.prefab).ResourcePath)) { return "Items/" + ((item != null) ? ((Object)item).name : null); } return ((PrefabRef<GameObject>)(object)item.prefab).ResourcePath; } internal static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> code = instructions.ToList(); _applied = false; List<int> list = (from i in Enumerable.Range(0, Math.Max(0, code.Count - 2)) where code[i].opcode == OpCodes.Ldstr && object.Equals(code[i].operand, "Items/") && (code[i + 1].opcode == OpCodes.Ldloc_0 || code[i + 1].opcode == OpCodes.Ldloc || code[i + 1].opcode == OpCodes.Ldloc_S) && code[i + 2].opcode == OpCodes.Call && code[i + 2].operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(string) && methodInfo.Name == "Concat" && methodInfo.GetParameters().Length == 2 && methodInfo.GetParameters().All((ParameterInfo p) => p.ParameterType == typeof(string)) select i).ToList(); if (list.Count != 1) { return code; } int num = list[0]; for (int num2 = num + 1; num2 <= num + 2; num2++) { if (code[num2].blocks.Count != 0 || !(typeof(CodeInstruction).GetField("labels")?.GetValue(code[num2]) is IList { Count: 0 })) { return code; } } code[num].opcode = OpCodes.Ldarg_0; code[num].operand = null; code[num + 1].opcode = OpCodes.Call; code[num + 1].operand = AccessTools.DeclaredMethod(typeof(ShopSpawnPathCompat), "PathFor", (Type[])null, (Type[])null); code[num + 2].opcode = OpCodes.Nop; code[num + 2].operand = null; _applied = true; return code; } } }