// Copyright (c) 2022 bradson // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. //#define DEBUG global using System; global using System.Collections.Generic; global using System.Reflection; global using HarmonyLib; global using FisheryLib.Utility.Diagnostics; global using CodeInstructions = System.Collections.Generic.IEnumerable; using System.Security; using System.Diagnostics; using System.Runtime.CompilerServices; using JetBrains.Annotations; [assembly: AllowPartiallyTrustedCallers] [assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)] [assembly: Debuggable(false, false)] [assembly: AssemblyVersion(FisheryLib.FisheryLib.VERSION_STRING)] [module: SkipLocalsInit] namespace FisheryLib; [PublicAPI] public static class FisheryLib { public const decimal VERSION = 0.39995M; public static decimal CurrentlyLoadedVersion { get; } = VERSION; public const string VERSION_STRING = "0.3.999.5"; // public static string GetVersion() // { // var text = File.ReadAllText("Fishery.cs"); // const string VERSION_FIELD_NAME = "VERSION_STRING = \""; // var versionIndex = text.IndexOf(VERSION_FIELD_NAME, StringComparison.InvariantCulture); // versionIndex += VERSION_FIELD_NAME.Length; // var versionEndIndex = versionIndex; // while (text[versionEndIndex] != '"') // versionEndIndex++; // // return text.Substring(versionIndex, versionEndIndex - versionIndex); // } } /*namespace FisheryLib; public class Fishery : Harmony { /// Creates a new Fishery instance /// A unique identifier (you choose your own) /// A Fishery instance public Fishery(string id) : base(id) { } /// Creates a patch class processor from an annotated class /// The class/type /// A new instance public new FisheryPatchClassProcessor CreateClassProcessor(Type type) => new(this, type); /// Creates patches by manually specifying the methods /// The original method/constructor /// An optional prefix method wrapped in a object /// An optional postfix method wrapped in a object /// An optional infix method wrapped in a object /// An optional transpiler method wrapped in a object /// An optional finalizer method wrapped in a object /// The replacement method that was created to patch the original method public MethodInfo Patch(MethodBase original, HarmonyMethod? prefix = null, HarmonyMethod? postfix = null, InfixMethod? infix = null, HarmonyMethod? transpiler = null, HarmonyMethod? finalizer = null) { Guard.IsNotNull(original, nameof(original)); return HarmonyPatchExtensions.Patch(this, original, prefix, postfix, infix, transpiler, finalizer); } /// Searches the current assembly for Harmony and Fishery annotations, using them to create patches /// This method can fail to use the correct assembly when being inlined. It calls StackTrace.GetFrame(1) which can point to the wrong method/assembly. If you are unsure or run into problems, use PatchAll(Assembly.GetExecutingAssembly()) instead. public new void PatchAll() => PatchAll(UtilityF.GetCallingAssembly()); /// Searches an assembly for Harmony annotations and uses them to create patches /// The assembly public new void PatchAll(Assembly assembly) { Guard.IsNotNull(assembly, nameof(assembly)); foreach (var type in AccessTools.GetTypesFromAssembly(assembly)) CreateClassProcessor(type).Patch(); } }*/