namespace SPTarkov.Reflection.Patching; /// /// Cache of active patches for mod developers to use for compatibility reasons /// [Obsolete("Patches will be injectable through IEnumerable in SPT 4.1, making this redundant")] public static class ModPatchCache { private static readonly List _activePatches = []; // This class contains tighter access rules than we usually would implement in the project, // the reason for this is so that the data is a true representation of what's happening with patches without any external interference. // TODO: Mod GUID/Name associations to patches, need to think on that. // Required parameter on AbstractPatch ctor maybe? /// /// Get all active patches /// /// /// List of active patches /// /// /// This should never be called before PreSptLoad is completed, otherwise could be empty. /// [Obsolete("Patches will be injectable through IEnumerable in SPT 4.1, making this redundant")] public static IReadOnlyList GetActivePatches() { // We're not exposing _activePatches so it cant be altered outside of this class. Do NOT implement this as a property. // Mod developers can still enable/disable these patches at will, this is fine, just don't allow external removal from the cache. return _activePatches.AsReadOnly(); } /// /// Get all actively patched target method names /// /// /// List of fully quantified method names; including namespace, type and method name /// /// /// This should never be called before PreSptLoad is completed, otherwise could be empty. /// [Obsolete("Patches will be injectable through IEnumerable in SPT 4.1, making this redundant")] public static List GetActivePatchedMethodNames() { var result = new List(); foreach (var patch in _activePatches) { // Fullname includes namespace var typeName = patch.TargetMethod?.DeclaringType?.FullName; var methodName = patch.TargetMethod?.Name; if (typeName != null && methodName != null) { result.Add($"{typeName}.{methodName}"); continue; } result.Add($"{patch.HarmonyId}: Type or method is null for this patch."); } return result; } /// /// Add a patch to the cache /// /// Patch to add to cache /// /// DO NOT PATCH THIS METHOD, IT IS INTERNAL FOR A REASON. YOU ARE ONLY HARMING OTHER MOD DEVELOPERS BY DOING SO. /// internal static void AddPatch(AbstractPatch patch) { _activePatches.Add(patch); } /// /// Remove a patch from the cache /// /// Patch to remove /// /// True if patch was removed /// /// /// DO NOT PATCH THIS METHOD, IT IS INTERNAL FOR A REASON. YOU ARE ONLY HARMING OTHER MOD DEVELOPERS BY DOING SO. /// internal static bool RemovePatch(AbstractPatch patch) { return _activePatches.Remove(patch); } }