Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AAA Crafting Max Fix v1.1.0
BepInEx/plugins/swear-AAACraftingMaxFix/AAACraftingMaxFix.dll
Decompiled 2 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using AzuAntiArthriticCrafting; using AzuAntiArthriticCrafting.Compatibility.AzuCraftyBoxes; using AzuAntiArthriticCrafting.Patches; using AzuAntiArthriticCrafting.Utilities; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AAACraftingMaxFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0+cf3fc78d0d582b3feee5761944dbec6d9b19a473")] [assembly: AssemblyProduct("AAACraftingMaxFix")] [assembly: AssemblyTitle("AAACraftingMaxFix")] [assembly: AssemblyVersion("1.1.0.0")] namespace ValheimDuoQoL; [BepInPlugin("swear.valheim.AAACraftingMaxFix", "AAA Crafting Max Fix", "1.1.0")] [BepInDependency("Azumatt.AzuAntiArthriticCrafting", "2.1.11")] [BepInDependency("Azumatt.AzuCraftyBoxes", "1.8.27")] public sealed class AAACraftingMaxFix : BaseUnityPlugin { public const string Id = "swear.valheim.AAACraftingMaxFix"; private Harmony harmony; private IEnumerator Start() { yield return null; try { BridgeCompatibility.Validate(typeof(AzuCraftyBoxes)); harmony = new Harmony("swear.valheim.AAACraftingMaxFix"); harmony.PatchAll(typeof(AAACraftingMaxFix).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"AAA Crafting Max Fix 1.1.0 applied: per-material totals, zero limit and 0.5s refresh."); } catch (Exception ex) { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } ((BaseUnityPlugin)this).Logger.LogError((object)("Max fix could not be applied; no patches retained. " + ex)); } } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } } internal static class BridgeCompatibility { internal static void Validate(Type bridge) { MethodInfo method = bridge.GetField("_begin", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as MethodInfo; MethodInfo method2 = bridge.GetField("_total", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as MethodInfo; MethodInfo methodInfo = bridge.GetField("_nearby", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as MethodInfo; MethodInfo method3 = bridge.GetField("_prevent", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as MethodInfo; FieldInfo fieldInfo = bridge.GetField("_range", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as FieldInfo; FieldInfo fieldInfo2 = bridge.GetField("_queryFrame", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as FieldInfo; if (methodInfo == null || !methodInfo.IsStatic || methodInfo.ContainsGenericParameters || methodInfo.GetParameters().Length != 2 || methodInfo.GetParameters()[0].ParameterType.FullName != "Player" || methodInfo.GetParameters()[1].ParameterType != typeof(float) || !Matches(method, typeof(void), methodInfo.ReturnType) || !Matches(method2, typeof(int), typeof(string)) || !Matches(method3, typeof(bool)) || fieldInfo == null || !fieldInfo.IsStatic || !(fieldInfo.GetValue(null) is ConfigEntry<float>) || fieldInfo2 == null || !fieldInfo2.IsStatic || fieldInfo2.FieldType != typeof(int)) { throw new InvalidOperationException("AAA-to-AzuCraftyBoxes bridge is missing or incompatible."); } } private static bool Matches(MethodInfo method, Type result, params Type[] parameters) { if (method != null && method.IsStatic && method.ReturnType == result) { return (from p in method.GetParameters() select p.ParameterType).SequenceEqual(parameters); } return false; } } [HarmonyPatch(typeof(Utilities), "GetAvailableItems")] internal static class AvailableItemsPatch { internal static bool Prefix(string __0, ref int __result) { int total = AzuCraftyBoxes.GetTotal(__0); if (total < 0) { return true; } __result = total; return false; } } [HarmonyPatch(typeof(AAACraft), "CalculateMaxCraftAmount")] internal static class ZeroLimitPatch { internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); MethodInfo method = typeof(Mathf).GetMethod("Clamp", new Type[3] { typeof(int), typeof(int), typeof(int) }); int num = 0; for (int i = 2; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method) && CodeInstructionExtensions.LoadsConstant(list[i - 1], 100L) && list[i - 2].opcode == OpCodes.Ldc_I4_1) { list[i - 2].opcode = OpCodes.Ldc_I4_0; num++; } } if (num != 1) { throw new InvalidOperationException("Expected one Max clamp; found " + num); } return list; } } [HarmonyPatch(typeof(MaxCraftAmount), "Update")] internal static class RefreshPatch { private static float nextRefresh; internal static void Prefix() { if (!(Time.unscaledTime < nextRefresh)) { nextRefresh = Time.unscaledTime + 0.5f; MaxCraftAmount.InventoryChanged = true; } } }