internal static void ToggleTechniPatches(bool value, TechniPatchType patchType) { if (_techniPatchActive !.TryGetValue(patchType, out bool activeValue)) { if (value != activeValue) { HeckPatchDataManager.TogglePatches(_techniPatchInstances ![patchType], value);
internal static void InitPatchType(ref List <TechniPatchData> patchDatas, TechniPatchType patchType) { if (patchDatas == null) { patchDatas = new List <TechniPatchData>(); foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) { IEnumerable <object> attributes = type.GetCustomAttributes(typeof(TechniPatch), true); if (attributes.Count() > 0) { Type declaringType = null; List <string> methodNames = new List <string>(); TechniPatchType?patchPatchType = null; foreach (TechniPatch n in attributes) { if (n.DeclaringType != null) { declaringType = n.DeclaringType; } if (n.MethodName != null) { methodNames.Add(n.MethodName); } if (n.PatchType != null) { patchPatchType = n.PatchType; } } if (declaringType == null || !methodNames.Any() || patchPatchType == null) { throw new ArgumentException("Type or Method Name not described"); } if (patchPatchType == patchType) { MethodInfo prefix = AccessTools.Method(type, "Prefix"); MethodInfo postfix = AccessTools.Method(type, "Postfix"); MethodInfo transpiler = AccessTools.Method(type, "Transpiler"); foreach (string methodName in methodNames) { MethodInfo methodInfo = declaringType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); if (methodInfo == null) { throw new ArgumentException($"Could not find method '{methodName}' of '{declaringType}'"); } patchDatas.Add(new TechniPatchData(methodInfo, prefix, postfix, transpiler)); } } } } } }
internal static void ToggleTechniPatches(bool value, TechniPatchType patchType) { if (value) { if (!Harmony.HasAnyPatches(HARMONYID + Enum.GetName(typeof(TechniPatchType), patchType))) { List <TechniPatchData> list = null; switch (patchType) { case TechniPatchType.LIGHTS: list = _lightPatches; break; case TechniPatchType.OBSTACLES: list = _obstaclePatches; break; case TechniPatchType.NOTES: list = _notePatches; break; case TechniPatchType.BOMBS: list = _bombPatches; break; } if (list != null) { Harmony harmony = _techniPatchInstances[patchType]; list.ForEach(n => harmony.Patch( n.OriginalMethod, n.Prefix != null ? new HarmonyMethod(n.Prefix) : null, n.Postfix != null ? new HarmonyMethod(n.Postfix) : null, n.Transpiler != null ? new HarmonyMethod(n.Transpiler) : null)); } } } else { _techniPatchInstances[patchType].UnpatchAll(HARMONYID + Enum.GetName(typeof(TechniPatchType), patchType)); } }
internal TechniPatch(TechniPatchType patchType) { PatchType = patchType; }