public static void Unload(Harmony harmony) { harmony.UnpatchAll(harmony.Id); if (Logger != null) { Logger.CallReceived -= Logger_CallReceived; } Logger = null; Plugin = null; }
public static void Unload(Harmony harmony) { Plugin?.m_Logger.LogInformation("Unloading RPCDetectorCore..."); harmony?.UnpatchAll(harmony?.Id); if (Logger != null) { lock (Logger) Logger.CallReceived -= Logger_CallReceived; } Logger = null; Plugin = null; }
/// <summary> /// Initializes the RPCDetectorCore. /// </summary> public static void Init(Harmony harmony, RPCDetectorPlugin instance) { instance.m_Logger.LogInformation("Loading RPCDetectorCore..."); Plugin = instance; Logger = new RPCLogger(); Dictionary <MethodInfo, MethodInfo> patchMappings = new Dictionary <MethodInfo, MethodInfo>(); foreach (MethodInfo patchMethod in typeof(RPCDetectorCore).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Where(x => Attribute.IsDefined(x, typeof(MPatch)))) { var patchParameters = patchMethod.GetParameters().ToList(); patchParameters.RemoveAll(x => x.Name.StartsWith("__")); foreach (MethodInfo BaseMethod in typeof(SteamChannel).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)) { var baseParameters = BaseMethod.GetParameters(); if (patchMethod.Name.Equals(BaseMethod.Name, StringComparison.InvariantCultureIgnoreCase) && patchParameters.Count == baseParameters.Length) { bool equal = true; for (int i = 0; i < baseParameters.Length; i++) { if (patchParameters[i].ParameterType != baseParameters[i].ParameterType) { equal = false; } } if (equal && !patchMappings.ContainsKey(patchMethod)) { patchMappings.Add(patchMethod, BaseMethod); } } } } foreach (var patchMapping in patchMappings) { harmony.CreateProcessor(patchMapping.Value) .AddPrefix(patchMapping.Key) .Patch(); } lock (Logger) Logger.CallReceived += Logger_CallReceived; Plugin.m_Logger.Log(LogLevel.Information, "RPCDetectorCore loaded; Created {0} patches.", patchMappings.Count); }