using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Riverboat.MagicBucket;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ILoveMagic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("ILoveMagic")]
[assembly: AssemblyTitle("ILoveMagic")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI (e.g., Code Suggestions, Refactoring, Documentation Generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "DeepSeek")]
[assembly: AssemblyMetadata("AI_Model_Name", "deepseek-v4-flash")]
[assembly: AssemblyMetadata("AI_Agent", "Claude Code")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace VoodooFishin.MagicBucketSummon
{
[BepInPlugin("voodoofishin.magicbucketsummon", "ILoveMagic", "0.2.0")]
public class Plugin : BasePlugin
{
public const string Guid = "voodoofishin.magicbucketsummon";
internal static ConfigEntry<bool> CfgEnabled;
internal static ConfigEntry<Key> CfgKeyA;
internal static ConfigEntry<Key> CfgKeyB;
internal static ManualLogSource Logger;
private static int _lastGrabbedId = -1;
private static int _pendingPartnerId = -1;
public override void Load()
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BasePlugin)this).Log;
CfgEnabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "总开关。");
CfgKeyA = ((BasePlugin)this).Config.Bind<Key>("General", "SummonKeyA", (Key)99, "把地图上的一个魔法桶拿到手上。取值是 UnityEngine.InputSystem.Key 的枚举名。");
CfgKeyB = ((BasePlugin)this).Config.Bind<Key>("General", "SummonKeyB", (Key)100, "把刚才那个桶的搭档拿到手上。通常先按 A 再按 B。");
new Harmony("voodoofishin.magicbucketsummon").PatchAll(typeof(MagicBucketController_LateUpdate_Patch));
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ILoveMagic loaded (A=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Key>(CfgKeyA.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", B=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Key>(CfgKeyB.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
}
log.LogInfo(val);
}
internal static void OnKeyA()
{
MagicBucketController instance = MagicBucketController.Instance;
if ((Object)(object)instance == (Object)null)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)"找不到 MagicBucketController。");
}
return;
}
Teleporter val = FindCandidate(-1);
if ((Object)(object)val == (Object)null)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)"地图上没找到可拿的魔法桶(可能都被拿在手上,或者还没刷出来)。");
}
return;
}
_lastGrabbedId = val.BucketId;
Teleporter linkedTeleporter = val.LinkedTeleporter;
_pendingPartnerId = (((Object)(object)linkedTeleporter != (Object)null) ? linkedTeleporter.BucketId : (-1));
Pickup(instance, val.BucketId);
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogInfo((object)((_pendingPartnerId >= 0) ? $"拿起桶 {val.BucketId},搭档是 {_pendingPartnerId}(按 B 拿它)。" : $"拿起桶 {val.BucketId},但没解析到搭档(按 B 会随便拿另一个)。"));
}
}
internal static void OnKeyB()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
MagicBucketController instance = MagicBucketController.Instance;
if ((Object)(object)instance == (Object)null)
{
return;
}
if (_pendingPartnerId >= 0)
{
Teleporter val = FindByBucketId(_pendingPartnerId);
if ((Object)(object)val != (Object)null)
{
Pickup(instance, val.BucketId);
_pendingPartnerId = -1;
return;
}
ManualLogSource logger = Logger;
if (logger != null)
{
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("搭档桶 ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(_pendingPartnerId);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" 找不到了,改为随便拿一个。");
}
logger.LogWarning(val2);
}
_pendingPartnerId = -1;
}
Teleporter val3 = FindCandidate(_lastGrabbedId);
if ((Object)(object)val3 == (Object)null)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)"没有别的魔法桶可拿了。");
}
}
else
{
_lastGrabbedId = val3.BucketId;
Pickup(instance, val3.BucketId);
}
}
private static Teleporter FindCandidate(int excludeId)
{
Teleporter val = null;
Teleporter val2 = null;
foreach (Teleporter item in Object.FindObjectsOfType<Teleporter>())
{
if ((Object)(object)item == (Object)null || item.BucketId == excludeId || item.IsBeingHeld)
{
continue;
}
if (item.IsExitOnlyPair)
{
if ((Object)(object)val == (Object)null || item.BucketId < val.BucketId)
{
val = item;
}
}
else if ((Object)(object)val2 == (Object)null || item.BucketId < val2.BucketId)
{
val2 = item;
}
}
return val2 ?? val;
}
private static Teleporter FindByBucketId(int bucketId)
{
foreach (Teleporter item in Object.FindObjectsOfType<Teleporter>())
{
if ((Object)(object)item != (Object)null && item.BucketId == bucketId)
{
return item;
}
}
return null;
}
private static void Pickup(MagicBucketController manager, int bucketId)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
try
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)"NetworkManager 不可用,拾取取消。");
}
}
else
{
manager.RequestPickupServerRpc(bucketId, singleton.LocalClientId);
}
}
catch (Exception ex)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(11, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("请求拾取桶 ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(bucketId);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" 失败: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
logger2.LogError(val);
}
}
}
}
[HarmonyPatch(typeof(MagicBucketController), "LateUpdate")]
internal static class MagicBucketController_LateUpdate_Patch
{
[HarmonyPostfix]
private static void Postfix()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.CfgEnabled.Value)
{
return;
}
Keyboard current = Keyboard.current;
if (current != null)
{
if (IsDown(current, Plugin.CfgKeyA.Value))
{
Plugin.OnKeyA();
}
else if (IsDown(current, Plugin.CfgKeyB.Value))
{
Plugin.OnKeyB();
}
}
}
private static bool IsDown(Keyboard kb, Key key)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
KeyControl val = kb[key];
if (val != null)
{
return ((ButtonControl)val).wasPressedThisFrame;
}
return false;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ILoveMagic";
public const string PLUGIN_NAME = "ILoveMagic";
public const string PLUGIN_VERSION = "0.2.0";
}
}