using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FreeEquip")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeEquip")]
[assembly: AssemblyTitle("FreeEquip")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace FreeEquip
{
[BepInPlugin("Mhz.freeequip", "FreeEquip", "1.0.0")]
public class FreeEquipMod : BaseUnityPlugin
{
public const string PluginGuid = "Mhz.freeequip";
public const string PluginName = "FreeEquip";
public const string PluginVersion = "1.0.0";
private static ManualLogSource? Logger;
private Harmony? _harmony;
public static ConfigEntry<bool>? EnableDebugLogs { get; private set; }
private void Awake()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
try
{
EnableDebugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("调试", "启用调试日志", false, "是否显示详细的调试日志信息");
_harmony = new Harmony("Mhz.freeequip");
_harmony.PatchAll();
Logger.LogInfo((object)"FreeEquip v1.0.0 加载成功!蓝黄工具可跨颜色装备");
}
catch (Exception arg)
{
Logger.LogError((object)$"MOD 加载失败: {arg}");
throw;
}
}
private void OnDestroy()
{
try
{
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogInfo((object)"MOD 已卸载");
}
}
catch (Exception arg)
{
ManualLogSource? logger2 = Logger;
if (logger2 != null)
{
logger2.LogError((object)$"MOD 卸载时出错: {arg}");
}
}
}
internal static void Log(string message)
{
ConfigEntry<bool>? enableDebugLogs = EnableDebugLogs;
if (enableDebugLogs != null && enableDebugLogs.Value)
{
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogInfo((object)message);
}
}
}
internal static void LogWarning(string message)
{
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogWarning((object)message);
}
}
internal static void LogError(string message)
{
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogError((object)message);
}
}
}
[HarmonyPatch(typeof(InventoryItemToolManager), "TryPickupOrPlaceTool")]
public static class TryPickupOrPlaceToolPatch
{
private static bool Prefix(InventoryItemToolManager __instance, ToolItem tool, ref bool __result)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Invalid comparison between Unknown and I4
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)tool == (Object)null)
{
return true;
}
if ((int)tool.Type == 1 || (int)tool.Type == 2)
{
FreeEquipMod.Log("自动装备: " + GetToolTypeName(tool.Type) + " 工具 [" + tool.name + "]");
__result = TryEquipCrossColor(__instance, tool);
return false;
}
return true;
}
catch (Exception arg)
{
FreeEquipMod.LogError($"TryPickupOrPlaceTool 补丁出错: {arg}");
return true;
}
}
private static bool TryEquipCrossColor(InventoryItemToolManager manager, ToolItem tool)
{
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
try
{
PropertyInfo property = typeof(InventoryItemToolManager).GetProperty("PickedUpTool");
property.SetValue(manager, tool);
IEnumerable<InventoryToolCrestSlot> first = Enumerable.Empty<InventoryToolCrestSlot>();
IEnumerable<InventoryToolCrestSlot> second = Enumerable.Empty<InventoryToolCrestSlot>();
object obj = typeof(InventoryItemToolManager).GetField("crestList", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(manager);
if (obj != null && obj.GetType().GetMethod("GetSlots")?.Invoke(obj, null) is IEnumerable<InventoryToolCrestSlot> enumerable)
{
first = enumerable;
}
object obj2 = typeof(InventoryItemToolManager).GetField("extraSlots", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(manager);
if (obj2 != null && obj2.GetType().GetMethod("GetSlots")?.Invoke(obj2, null) is IEnumerable<InventoryToolCrestSlot> enumerable2)
{
second = enumerable2;
int num = enumerable2.Count((InventoryToolCrestSlot s) => (int)s.Type == 1);
int num2 = enumerable2.Count((InventoryToolCrestSlot s) => (int)s.Type == 2);
if (num > 0 || num2 > 0)
{
FreeEquipMod.Log($"额外槽位: {num} 个蓝色, {num2} 个黄色");
}
}
List<InventoryToolCrestSlot> source = (from s in first.Concat(second)
where (int)s.Type == 1 || (int)s.Type == 2
select s).ToList();
if (source.Any())
{
InventoryToolCrestSlot val = ((IEnumerable<InventoryToolCrestSlot>)source).FirstOrDefault((Func<InventoryToolCrestSlot, bool>)((InventoryToolCrestSlot s) => (Object)(object)s.EquippedItem == (Object)null));
InventoryToolCrestSlot val2 = val ?? source.First();
PropertyInfo property2 = typeof(InventoryItemToolManager).GetProperty("EquipState");
property2.SetValue(manager, 1);
FieldInfo field = typeof(InventoryItemToolManager).GetField("selectedBeforePickup", BindingFlags.Instance | BindingFlags.NonPublic);
object value = typeof(InventoryItemListManager<InventoryItemTool, ToolItem>).GetProperty("CurrentSelected")?.GetValue(manager);
field?.SetValue(manager, value);
val2.SetEquipped(tool, true, true);
property.SetValue(manager, null);
property2.SetValue(manager, 0);
string text = (((Object)(object)val != (Object)null) ? "空槽位" : "替换装备");
FreeEquipMod.Log("装备成功: " + GetToolTypeName(tool.Type) + " 到 " + GetToolTypeName(val2.Type) + " (" + text + ")");
return true;
}
FreeEquipMod.LogWarning("没有找到合适的蓝色/黄色槽位");
property.SetValue(manager, null);
return false;
}
catch (Exception arg)
{
FreeEquipMod.LogError($"跨颜色自动装备失败: {arg}");
return false;
}
}
private static string GetToolTypeName(ToolItemType type)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
if (1 == 0)
{
}
string result = (((int)type == 1) ? "蓝色" : (((int)type != 2) ? ((object)(ToolItemType)(ref type)).ToString() : "黄色"));
if (1 == 0)
{
}
return result;
}
}
}