using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using Gear;
using Hikaria.Core;
using Hikaria.Core.SNetworkExt;
using Hikaria.ExchangeItem.Features;
using Hikaria.ExchangeItem.Handlers;
using Hikaria.ExchangeItem.Managers;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Localization;
using Player;
using SNetwork;
using TheArchive.Core;
using TheArchive.Core.Attributes;
using TheArchive.Core.Attributes.Feature.Settings;
using TheArchive.Core.FeaturesAPI;
using TheArchive.Core.Localization;
using TheArchive.Interfaces;
using TheArchive.Loader;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: ModDefaultFeatureGroupName("Exchange Item")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Hikaria.ExchangeItem
{
[ArchiveDependency(/*Could not decode attribute arguments.*/)]
[ArchiveModule("Hikaria.ExchangeItem", "ExchangeItem", "2.0.2")]
public class EntryPoint : IArchiveModule
{
public static EntryPoint Instance { get; private set; }
public bool ApplyHarmonyPatches => false;
public bool UsesLegacyPatches => false;
public ArchiveLegacyPatcher Patcher { get; set; }
public string ModuleGroup => "Exchange Item";
public Dictionary<Language, string> ModuleGroupLanguages => new Dictionary<Language, string>
{
{
(Language)0,
"Exchange Item"
},
{
(Language)1,
"资源交换"
}
};
public void Init()
{
Instance = this;
Logs.LogMessage("OK");
}
public void OnSceneWasLoaded(int buildIndex, string sceneName)
{
}
public void OnLateUpdate()
{
}
public void OnExit()
{
}
}
internal static class Logs
{
private static IArchiveLogger _logger;
private static IArchiveLogger Logger => _logger ?? (_logger = LoaderWrapper.CreateLoggerInstance("Hikaria.ExchangeItem", ConsoleColor.White));
public static void LogDebug(object data)
{
Logger.Debug(data.ToString());
}
public static void LogError(object data)
{
Logger.Error(data.ToString());
}
public static void LogInfo(object data)
{
Logger.Info(data.ToString());
}
public static void LogMessage(object data)
{
Logger.Msg(ConsoleColor.White, data.ToString());
}
public static void LogWarning(object data)
{
Logger.Warning(data.ToString());
}
public static void LogNotice(object data)
{
Logger.Notice(data.ToString());
}
public static void LogSuccess(object data)
{
Logger.Success(data.ToString());
}
public static void LogException(Exception ex)
{
Logger.Exception(ex);
}
}
public static class PluginInfo
{
public const string GUID = "Hikaria.ExchangeItem";
public const string NAME = "ExchangeItem";
public const string VERSION = "2.0.2";
}
}
namespace Hikaria.ExchangeItem.Managers
{
public class ExchangeItemManager
{
public enum ExchangeType : byte
{
TargetToSource,
SourceToTarget,
Exchange,
Invalid
}
public enum AgentType : byte
{
LocalAgent,
TargetAgent
}
public static bool MasterHasExchangeItem;
private static Item TargetItem;
private static Item LocalItem;
private static ItemEquippable TargetWieldItem;
private static InventorySlot TargetWieldSlot;
private static ExchangeType exchangeType;
private static bool LastFlashLightStatus;
private static SNetExt_Packet<pExchangeItemRequest> s_ExchangeItemRequestPacket;
private static SNetExt_Packet<pExchangeItemFix> s_ExchangeItemFixPacket;
public static bool InteractionAllowed { get; private set; }
private static bool IsInteractionAllowed
{
get
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Invalid comparison between Unknown and I4
if (MasterHasExchangeItem && (Object)(object)TargetPlayerAgent != (Object)null && exchangeType != ExchangeType.Invalid && (int)LocalPlayerWieldingSlot != 4)
{
return (int)((PlayerAgent)LocalPlayer).Locomotion.m_currentStateEnum != 7;
}
return false;
}
}
public static PlayerAgent TargetPlayerAgent { get; private set; }
public static ItemEquippable LocalPlayerWieldingItem { get; private set; }
public static InventorySlot LocalPlayerWieldingSlot { get; private set; }
public static float TargetAmmoInPack { get; private set; }
public static float LocalPlayerAmmoInPack { get; private set; }
public static InventorySlot ExchangeSlot { get; private set; }
public static LocalPlayerAgent LocalPlayer { get; internal set; }
public static event Action OnUpdated;
public static void Setup()
{
CoreAPI.OnPlayerModsSynced += OnPlayerModsSynced;
GameEventAPI.OnMasterChanged += OnMasterChanged;
s_ExchangeItemRequestPacket = SNetExt_Packet<pExchangeItemRequest>.Create(typeof(pExchangeItemRequest).FullName, (Action<ulong, pExchangeItemRequest>)DoExchangeItem, (Action<pExchangeItemRequest>)DoExchangeItemValidate, false, (SNet_ChannelType)2);
s_ExchangeItemFixPacket = SNetExt_Packet<pExchangeItemFix>.Create(typeof(pExchangeItemFix).FullName, (Action<ulong, pExchangeItemFix>)ReceiveExchangeItemFix, (Action<pExchangeItemFix>)null, true, (SNet_ChannelType)2);
}
private static void OnPlayerModsSynced(SNet_Player player, IEnumerable<pModInfo> mods)
{
if (player.IsMaster)
{
MasterHasExchangeItem = mods.Any((pModInfo m) => m.GUID == "Hikaria.ExchangeItem");
}
}
private static void OnMasterChanged()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
MasterHasExchangeItem = CoreAPI.IsPlayerInstalledMod(SNet.Master, "Hikaria.ExchangeItem", default(Version));
}
private static void ReceiveExchangeItemFix(ulong sender, pExchangeItemFix data)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
((PlayerAgent)LocalPlayer).Sync.WantsToSetFlashlightEnabled(LastFlashLightStatus, true);
((PlayerAgent)LocalPlayer).Inventory.ReceiveSetFlashlightStatus(LastFlashLightStatus, false);
GuiManager.PlayerLayer.Inventory.UpdateAllSlots(SNet.LocalPlayer, ((PlayerAgent)LocalPlayer).Inventory.WieldedSlot);
}
private static void DoExchangeItemValidate(pExchangeItemRequest data)
{
if (SNet.IsMaster)
{
DoExchangeItem(SNet.LocalPlayer.Lookup, data);
}
}
private static void DoExchangeItem(ulong sender, pExchangeItemRequest data)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: 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_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
SNet_Player val = default(SNet_Player);
SNet_Player val2 = default(SNet_Player);
if (!SNet.IsMaster || !((pPlayer)(ref data.Source)).TryGetPlayer(ref val) || !((pPlayer)(ref data.Target)).TryGetPlayer(ref val2))
{
return;
}
InventorySlot slot = data.Slot;
AmmoType val3 = (AmmoType)(((int)slot == 4) ? 3 : 5);
PlayerBackpack val4 = default(PlayerBackpack);
PlayerBackpackManager.TryGetBackpack(val, ref val4);
PlayerBackpack val5 = default(PlayerBackpack);
PlayerBackpackManager.TryGetBackpack(val2, ref val5);
BackpackItem val6 = default(BackpackItem);
bool flag = val4.TryGetBackpackItem(slot, ref val6);
BackpackItem val7 = default(BackpackItem);
bool flag2 = val5.TryGetBackpackItem(slot, ref val7);
if (flag2 && flag)
{
pItemData_Custom val8 = default(pItemData_Custom);
val8.ammo = val4.AmmoStorage.GetAmmoInPack(val3);
val8.byteId = val6.Instance.pItemData.custom.byteId;
val8.byteState = val6.Instance.pItemData.custom.byteState;
pItemData_Custom val9 = val8;
val6.Instance.SetCustomData(val9, false);
val8 = default(pItemData_Custom);
val8.ammo = val5.AmmoStorage.GetAmmoInPack(val3);
val8.byteId = val7.Instance.pItemData.custom.byteId;
val8.byteState = val7.Instance.pItemData.custom.byteState;
pItemData_Custom val10 = val8;
val7.Instance.SetCustomData(val10, false);
PlayerBackpackManager.MasterRemoveItem(val6.Instance, val);
PlayerBackpackManager.MasterRemoveItem(val7.Instance, val2);
PlayerBackpackManager.MasterAddItem(val6.Instance, val2);
PlayerBackpackManager.MasterAddItem(val7.Instance, val);
}
else if (!flag2 && flag)
{
pItemData_Custom val8 = default(pItemData_Custom);
val8.ammo = val4.AmmoStorage.GetAmmoInPack(val3);
val8.byteId = val6.Instance.pItemData.custom.byteId;
val8.byteState = val6.Instance.pItemData.custom.byteState;
pItemData_Custom val11 = val8;
val6.Instance.SetCustomData(val11, false);
PlayerBackpackManager.MasterRemoveItem(val6.Instance, val);
PlayerBackpackManager.MasterAddItem(val6.Instance, val2);
}
else
{
if (!flag2 || flag)
{
return;
}
pItemData_Custom val8 = default(pItemData_Custom);
val8.ammo = val5.AmmoStorage.GetAmmoInPack(val3);
val8.byteId = val7.Instance.pItemData.custom.byteId;
val8.byteState = val7.Instance.pItemData.custom.byteState;
pItemData_Custom val12 = val8;
val7.Instance.SetCustomData(val12, false);
PlayerBackpackManager.MasterRemoveItem(val7.Instance, val2);
PlayerBackpackManager.MasterAddItem(val7.Instance, val);
}
s_ExchangeItemFixPacket.Send(default(pExchangeItemFix), (SNet_Player[])(object)new SNet_Player[2] { val, val2 });
}
public static void Update()
{
SetInventoryItem();
InteractionAllowed = IsInteractionAllowed;
Action onUpdated = ExchangeItemManager.OnUpdated;
if (ExchangeItemManager.OnUpdated != null)
{
onUpdated();
}
}
public static void DoClear()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
InteractionAllowed = false;
LocalPlayerWieldingItem = null;
LocalPlayerWieldingSlot = (InventorySlot)0;
TargetWieldItem = null;
TargetWieldSlot = (InventorySlot)0;
LocalItem = null;
LocalPlayerAmmoInPack = 0f;
TargetItem = null;
TargetAmmoInPack = 0f;
exchangeType = ExchangeType.Invalid;
}
public static void SetTargetPlayerAgent(PlayerAgent targetPlayerAgent)
{
IntPtr intPtr = IntPtr.Zero;
IntPtr intPtr2 = IntPtr.Zero;
if ((Object)(object)TargetPlayerAgent != (Object)null)
{
intPtr = ((Il2CppObjectBase)TargetPlayerAgent).Pointer;
}
if ((Object)(object)targetPlayerAgent != (Object)null)
{
intPtr2 = ((Il2CppObjectBase)targetPlayerAgent).Pointer;
}
if (intPtr != intPtr2)
{
TargetPlayerAgent = targetPlayerAgent;
Update();
}
}
public static void SetInventoryItem()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Invalid comparison between Unknown and I4
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
ExchangeSlot = (InventorySlot)4;
InventorySlot val = (InventorySlot)4;
AmmoType val2 = (AmmoType)3;
if ((int)LocalPlayerWieldingSlot == 5)
{
ExchangeSlot = (InventorySlot)5;
val = (InventorySlot)5;
val2 = (AmmoType)5;
}
PlayerBackpack val3 = default(PlayerBackpack);
BackpackItem val4 = default(BackpackItem);
BackpackItem val5 = default(BackpackItem);
while (!((Object)(object)TargetPlayerAgent == (Object)null) && PlayerBackpackManager.TryGetBackpack(TargetPlayerAgent.Owner, ref val3))
{
bool flag = val3.TryGetBackpackItem(val, ref val4);
bool flag2 = PlayerBackpackManager.LocalBackpack.TryGetBackpackItem(val, ref val5);
if (flag)
{
TargetAmmoInPack = val3.AmmoStorage.GetAmmoInPack(val2);
TargetItem = val4.Instance;
}
else
{
TargetItem = null;
TargetAmmoInPack = 0f;
}
if (flag2)
{
LocalPlayerAmmoInPack = PlayerBackpackManager.LocalBackpack.AmmoStorage.GetAmmoInPack(val2);
LocalItem = val5.Instance;
}
else
{
LocalItem = null;
LocalPlayerAmmoInPack = 0f;
}
if (!(flag && flag2))
{
if (!(!flag && flag2))
{
if (!(!flag2 && flag))
{
if ((int)val != 4)
{
break;
}
ExchangeSlot = (InventorySlot)5;
val = (InventorySlot)5;
val2 = (AmmoType)5;
continue;
}
exchangeType = ExchangeType.TargetToSource;
return;
}
exchangeType = ExchangeType.SourceToTarget;
return;
}
exchangeType = ExchangeType.Exchange;
return;
}
exchangeType = ExchangeType.Invalid;
}
public static void WantToExchangeItem(SNet_Player target, InventorySlot slot)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
LastFlashLightStatus = ((PlayerAgent)LocalPlayer).Inventory.WantsFlashlightEnabled;
s_ExchangeItemRequestPacket.Ask(new pExchangeItemRequest(SNet.LocalPlayer, target, slot));
}
public static string GenerateExchangeItemPrompt()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
float num = (((int)ExchangeSlot == 4) ? 20f : 1f);
return exchangeType switch
{
ExchangeType.TargetToSource => string.Format(Hikaria.ExchangeItem.Features.ExchangeItem.Prompt_TargetToSource, TargetPlayerAgent.PlayerName, TargetAmmoInPack / num, TargetItem.ArchetypeName),
ExchangeType.SourceToTarget => string.Format(Hikaria.ExchangeItem.Features.ExchangeItem.Prompt_SourceToTarget, LocalPlayerAmmoInPack / num, LocalItem.ArchetypeName, TargetPlayerAgent.PlayerName),
ExchangeType.Exchange => string.Format(Hikaria.ExchangeItem.Features.ExchangeItem.Prompt_Exchange, LocalPlayerAmmoInPack / num, LocalItem.ArchetypeName, TargetPlayerAgent.PlayerName, TargetAmmoInPack / num, TargetItem.ArchetypeName),
_ => string.Empty,
};
}
public static void SetWieldingItem(ItemEquippable wieldingItem, InventorySlot slot, AgentType agentType)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if (agentType == AgentType.LocalAgent)
{
IntPtr intPtr = IntPtr.Zero;
IntPtr intPtr2 = IntPtr.Zero;
if ((Object)(object)LocalPlayerWieldingItem != (Object)null)
{
intPtr = ((Il2CppObjectBase)LocalPlayerWieldingItem).Pointer;
}
if ((Object)(object)wieldingItem != (Object)null)
{
intPtr2 = ((Il2CppObjectBase)wieldingItem).Pointer;
}
if (intPtr != intPtr2)
{
LocalPlayerWieldingItem = wieldingItem;
LocalPlayerWieldingSlot = slot;
Update();
}
}
else
{
IntPtr intPtr3 = IntPtr.Zero;
IntPtr intPtr4 = IntPtr.Zero;
if ((Object)(object)TargetWieldItem != (Object)null)
{
intPtr3 = ((Il2CppObjectBase)TargetWieldItem).Pointer;
}
if ((Object)(object)wieldingItem != (Object)null)
{
intPtr4 = ((Il2CppObjectBase)wieldingItem).Pointer;
}
if (intPtr3 != intPtr4)
{
TargetWieldItem = wieldingItem;
TargetWieldSlot = slot;
Update();
}
}
}
}
[StructLayout(LayoutKind.Sequential, Size = 1)]
public struct pExchangeItemFix
{
}
public struct pExchangeItemRequest
{
public pPlayer Source;
public pPlayer Target;
public InventorySlot Slot;
public pExchangeItemRequest(SNet_Player source, SNet_Player target, InventorySlot slot)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
Source = default(pPlayer);
Target = default(pPlayer);
Slot = (InventorySlot)0;
((pPlayer)(ref Source)).SetPlayer(source);
((pPlayer)(ref Target)).SetPlayer(target);
Slot = slot;
}
}
}
namespace Hikaria.ExchangeItem.Handlers
{
internal class ExchangeItemHandler : MonoBehaviour
{
public static KeyCode ExchangeItemKey = (KeyCode)116;
private bool HoldingKey;
private static string ExchangeItemButtonText = string.Empty;
private static string InteractionPrompt = string.Empty;
private bool InteractionAllowed;
private Coroutine InteractionCoroutine;
private void Awake()
{
ExchangeItemManager.OnUpdated += ExchangeItemManager_OnUpdated;
}
private void OnDestroy()
{
ExchangeItemManager.OnUpdated -= ExchangeItemManager_OnUpdated;
}
private void Update()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (InteractionAllowed && !HoldingKey)
{
if (Input.GetKeyDown(ExchangeItemKey))
{
StartRoutine();
HoldingKey = true;
}
}
else if (Input.GetKeyUp(ExchangeItemKey))
{
StopRoutine();
HoldingKey = false;
}
}
[HideFromIl2Cpp]
private void ExchangeItemManager_OnUpdated()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Invalid comparison between Unknown and I4
InteractionAllowed = ExchangeItemManager.InteractionAllowed;
if (InteractionAllowed)
{
UpdateExchangeItemPrompt();
SetExchangeItemPrompt();
}
else if ((int)ExchangeItemManager.LocalPlayerWieldingSlot != 4)
{
GuiManager.InteractionLayer.InteractPromptVisible = false;
GuiManager.InteractionLayer.SetInteractPrompt(string.Empty, string.Empty, (ePUIMessageStyle)0);
}
}
[HideFromIl2Cpp]
private static void UpdateExchangeItemPrompt()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
InteractionPrompt = ExchangeItemManager.GenerateExchangeItemPrompt();
ExchangeItemButtonText = string.Format(Text.Get(827u), ExchangeItemKey);
}
private static void SetExchangeItemPrompt()
{
GuiManager.InteractionLayer.InteractPromptVisible = true;
GuiManager.InteractionLayer.SetInteractPrompt(InteractionPrompt, ExchangeItemButtonText, (ePUIMessageStyle)0);
}
[HideFromIl2Cpp]
private void StartRoutine()
{
StopRoutine();
InteractionCoroutine = ((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Interaction(0.4f)));
StartInteraction();
}
[HideFromIl2Cpp]
private void StopRoutine()
{
if (InteractionCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(InteractionCoroutine);
StopInteraction();
}
}
[HideFromIl2Cpp]
private static void StartInteraction()
{
GuiManager.InteractionLayer.InteractPromptVisible = true;
GuiManager.InteractionLayer.TimerVisible = true;
}
[HideFromIl2Cpp]
private static void StopInteraction()
{
GuiManager.InteractionLayer.InteractPromptVisible = false;
GuiManager.InteractionLayer.TimerVisible = false;
}
[HideFromIl2Cpp]
private IEnumerator Interaction(float interactionTime)
{
SetExchangeItemPrompt();
float timer = 0f;
bool timerInterrupted = false;
while (timer <= interactionTime)
{
if (!ExchangeItemManager.InteractionAllowed)
{
timerInterrupted = true;
break;
}
SetExchangeItemPrompt();
GuiManager.InteractionLayer.SetTimer(timer / interactionTime);
timer += Time.deltaTime;
yield return null;
}
if (!timerInterrupted)
{
ExchangeItemManager.WantToExchangeItem(ExchangeItemManager.TargetPlayerAgent.Owner, ExchangeItemManager.ExchangeSlot);
}
StopInteraction();
InteractionCoroutine = null;
}
}
internal sealed class ExchangeItemUpdater : MonoBehaviour
{
private void Awake()
{
ExchangeItemManager.DoClear();
}
private void OnDestroy()
{
ExchangeItemManager.DoClear();
}
private void FixedUpdate()
{
UpdatePlayersInSphere();
UpdateWieldingItem();
}
private void UpdatePlayersInSphere()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((PlayerAgent)ExchangeItemManager.LocalPlayer).FPSCamera.Position;
Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position, 2.4f, LayerManager.MASK_GIVE_RESOURCE_PACK));
if (!array.Any())
{
ExchangeItemManager.SetTargetPlayerAgent(null);
return;
}
Vector3 forward = ((PlayerAgent)ExchangeItemManager.LocalPlayer).FPSCamera.Forward;
float num = 5f;
PlayerAgent targetPlayerAgent = null;
for (int i = 0; i < array.Length; i++)
{
iResourcePackReceiver componentInParent = ((Component)array[i]).GetComponentInParent<iResourcePackReceiver>();
if (componentInParent == null)
{
continue;
}
PlayerAgent val = ((Il2CppObjectBase)componentInParent).TryCast<PlayerAgent>();
if (!((Object)(object)val != (Object)null))
{
continue;
}
Vector3 position2 = ((Agent)val).AimTarget.position;
if (Vector3.Angle(position2 - position, forward) < 45f)
{
float num2 = Vector3.Distance(position2, position);
if (num2 < num)
{
num = num2;
targetPlayerAgent = val;
}
}
}
ExchangeItemManager.SetTargetPlayerAgent(targetPlayerAgent);
}
private void UpdateWieldingItem()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
PlayerInventoryBase inventory = ((PlayerAgent)ExchangeItemManager.LocalPlayer).Inventory;
if ((Object)(object)inventory != (Object)null)
{
InventorySlot wieldedSlot = inventory.WieldedSlot;
ExchangeItemManager.SetWieldingItem(inventory.WieldedItem, wieldedSlot, ExchangeItemManager.AgentType.LocalAgent);
}
else
{
ExchangeItemManager.SetWieldingItem(null, (InventorySlot)0, ExchangeItemManager.AgentType.LocalAgent);
}
if ((Object)(object)ExchangeItemManager.TargetPlayerAgent != (Object)null)
{
PlayerInventoryBase inventory2 = ExchangeItemManager.TargetPlayerAgent.Inventory;
if ((Object)(object)inventory2 != (Object)null)
{
InventorySlot wieldedSlot2 = inventory2.WieldedSlot;
ExchangeItemManager.SetWieldingItem(inventory2.WieldedItem, wieldedSlot2, ExchangeItemManager.AgentType.TargetAgent);
}
else
{
ExchangeItemManager.SetWieldingItem(null, (InventorySlot)0, ExchangeItemManager.AgentType.TargetAgent);
}
}
}
}
}
namespace Hikaria.ExchangeItem.Features
{
[EnableFeatureByDefault]
[DisallowInGameToggle]
public class ExchangeItem : Feature
{
public class ExchangeItemSetting
{
[FSDisplayName("物品交换按键")]
public KeyCode ExchangeItemKey
{
get
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
return ExchangeItemHandler.ExchangeItemKey;
}
set
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
ExchangeItemHandler.ExchangeItemKey = value;
}
}
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class PlayerInteraction__UpdateWorldInteractions__Patch
{
private static bool Prefix()
{
return !ExchangeItemManager.InteractionAllowed;
}
}
[ArchivePatch(/*Could not decode attribute arguments.*/)]
private class LocalPlayerAgent__Setup__Patch
{
private static void Postfix(LocalPlayerAgent __instance)
{
ExchangeItemManager.LocalPlayer = __instance;
GameObject gameObject = ((Component)__instance).gameObject;
if ((Object)(object)gameObject.GetComponent<ExchangeItemHandler>() == (Object)null)
{
gameObject.AddComponent<ExchangeItemHandler>();
}
if ((Object)(object)gameObject.GetComponent<ExchangeItemUpdater>() == (Object)null)
{
gameObject.AddComponent<ExchangeItemUpdater>();
}
}
}
public override string Name => "Exchange Item";
public override bool InlineSettingsIntoParentMenu => true;
public static ExchangeItem Instance { get; private set; }
[FeatureConfig]
public static ExchangeItemSetting Settings { get; set; }
public static string Prompt_Exchange => ((Feature)Instance).Localization.Get(1u);
public static string Prompt_TargetToSource => ((Feature)Instance).Localization.Get(2u);
public static string Prompt_SourceToTarget => ((Feature)Instance).Localization.Get(3u);
public override void Init()
{
Instance = this;
ClassInjector.RegisterTypeInIl2Cpp<ExchangeItemHandler>(false);
ClassInjector.RegisterTypeInIl2Cpp<ExchangeItemUpdater>(false);
ExchangeItemManager.Setup();
}
}
}