// Internal, not static, so the static cctor of TorchBase can hookup the GameStatePatchShim which tells us when // its safe to patch the rest of the game. internal static void AddPatchShim(Type type) { lock (_patchShims) if (!_patchShims.Add(type)) { return; } if (!type.IsSealed || !type.IsAbstract) { _log.Warn($"Registering type {type.FullName} as a patch shim type, even though it isn't declared singleton"); } MethodInfo method = type.GetMethod("Patch", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (method == null) { _log.Error($"Patch shim type {type.FullName} doesn't have a static Patch method."); return; } ParameterInfo[] ps = method.GetParameters(); if (ps.Length != 1 || ps[0].IsOut || ps[0].IsOptional || ps[0].ParameterType.IsByRef || ps[0].ParameterType != typeof(PatchContext) || method.ReturnType != typeof(void)) { _log.Error($"Patch shim type {type.FullName} doesn't have a method with signature `void Patch(PatchContext)`"); return; } var context = new PatchContext(); lock (_coreContexts) _coreContexts.Add(context); method.Invoke(null, new object[] { context }); }
public void FreeContext(PatchContext context) { Assembly assembly = Assembly.GetCallingAssembly(); context.RemoveAll(); lock (_contexts) { if (_contexts.TryGetValue(assembly, out List <PatchContext> localContexts)) { localContexts.Remove(context); } } }
public PatchContext AcquireContext() { Assembly assembly = Assembly.GetCallingAssembly(); var context = new PatchContext(); lock (_contexts) { if (!_contexts.TryGetValue(assembly, out List <PatchContext> localContexts)) { _contexts.Add(assembly, localContexts = new List <PatchContext>()); } localContexts.Add(context); } return(context); }