// Copyright (c) 2023 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/. // crashes to desktop somehow /*using Mono.Cecil; using Mono.Cecil.Cil; using PerformanceFish.Prepatching; namespace PerformanceFish; public class DefDatabasePatches : ClassWithFishPrepatches { public class GetNamedPatch : FishPrepatch { public override MethodBase TargetMethodBase { get; } = methodof(DefDatabase.GetNamed); public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module) => ilProcessor.ReplaceBodyWith(GetNamed); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T? GetNamed(string defName, bool errorOnFail = true) where T : Def { var value = DefDatabase.defsByName.TryGetValue(defName); if (errorOnFail && value is null) LogMissingDef(defName); return value; } [MethodImpl(MethodImplOptions.NoInlining)] public static void LogMissingDef(string defName) where T : Def => Log.Error($"Failed to find {typeof(T)} named {defName}. There are { DefDatabase.defsList.Count} defs of this type loaded."); } public class GetByShortHashPatch : FishPrepatch { public override MethodBase TargetMethodBase { get; } = methodof(DefDatabase.GetByShortHash); public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module) => ilProcessor.ReplaceBodyWith(GetByShortHash); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T? GetByShortHash(ushort shortHash) where T : Def => DefDatabase.defsByShortHash.TryGetValue(shortHash); } }*/