using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using BepInEx.Logging; using Mono.Cecil; using Mono.Collections.Generic; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] namespace ItemQualitiesPatcher; internal static class AssemblyNames { public const string RoR2 = "RoR2.dll"; } public static class BuffPatcher { private static readonly LogWriter _log = new LogWriter(); public static IEnumerable TargetDLLs { get; } = new string[1] { "RoR2.dll" }; public static void Initialize() { _log.SetLogSource(Logger.CreateLogSource("BuffPatcher")); } public static void Patch(AssemblyDefinition assembly) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) TypeDefinition type = assembly.MainModule.GetType("RoR2.CharacterBody"); if (type == null) { _log.Error("Failed to find type: CharacterBody"); return; } Enumerator enumerator = type.Methods.GetEnumerator(); try { while (enumerator.MoveNext()) { MethodDefinition current = enumerator.Current; if (((MemberReference)current).Name == "GetBuffCount" || ((MemberReference)current).Name == "HasBuff") { disableInlining(current); } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } } private static void disableInlining(MethodDefinition method) { //IL_0002: 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_0014: 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) method.ImplAttributes = (MethodImplAttributes)(method.ImplAttributes & 0xFEFF); method.ImplAttributes = (MethodImplAttributes)(method.ImplAttributes | 8); _log.Debug("Disabled inlining for method " + ((MemberReference)method).FullName); } } internal sealed class LogWriter { private ManualLogSource _logSource; public LogWriter(ManualLogSource logSource) { _logSource = logSource; } public LogWriter() : this(null) { } public void SetLogSource(ManualLogSource logSource) { _logSource = logSource; } public void Fatal(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogFatal(message); } } public void Error(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogError(message); } } public void Warning(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogWarning(message); } } public void Message(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogMessage(message); } } public void Info(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogInfo(message); } } public void Debug(object message) { ManualLogSource logSource = _logSource; if (logSource != null) { logSource.LogDebug(message); } } }