using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using Photon.Pun;
using PiggyBank.Behaviours;
using PiggyBank.Behaviours.GUI;
using PiggyBank.Data;
using PiggyBank.Patchers;
using TMPro;
using Unity.Collections;
using Unity.Services.Lobbies.Http;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.TextCore;
using UnityEngine.UI;
using UnityEngine.UI.Extensions;
using Zorro.Core;
using Zorro.Core.CLI;
using Zorro.Core.Serizalization;
using pworld.Scripts.Extensions;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.MiiMii1205.PiggyBank")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+19acdcb6af0f4ce94a51bc5fac3bbff3ecf029d7")]
[assembly: AssemblyProduct("com.github.MiiMii1205.PiggyBank")]
[assembly: AssemblyTitle("PiggyBank")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace PiggyBank
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.github.MiiMii1205.PiggyBank", "PiggyBank", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private static bool _bankedItemValid = true;
private static int _bankedItemCarryWeight;
private static bool _isDirty = true;
private static Item? _bankedItem;
private static ItemInstanceData? _bankedItemData;
public static GameObject PiggyScreenPrefab = null;
private const string PIGGY_BAMK_FILE_NAME = ".peakpiggybank";
private static ConfigEntry<PiggyBankScopes> _itemScope = null;
private static TMP_FontAsset? _darumaFontAsset;
private static Material? _darumaShadowMaterial;
public const string Id = "com.github.MiiMii1205.PiggyBank";
internal static ManualLogSource Log { get; private set; } = null;
public static TMP_FontAsset DarumaDropOne
{
get
{
if ((Object)(object)_darumaFontAsset == (Object)null)
{
TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
_darumaFontAsset = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)delegate(TMP_FontAsset fontAsset)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
FaceInfo faceInfo = ((TMP_Asset)fontAsset).faceInfo;
return ((FaceInfo)(ref faceInfo)).familyName == "Daruma Drop One";
});
Log.LogInfo((object)"Daruma Drop One font found!");
}
return _darumaFontAsset;
}
}
public static Material DarumaDropOneShadowMaterial
{
get
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_darumaShadowMaterial == (Object)null)
{
_darumaShadowMaterial = ThrowHelper.ThrowIfArgumentNull<Material>(Object.Instantiate<Material>(((TMP_Asset)DarumaDropOne).material), "Object.Instantiate(DarumaDropOne.material)");
_darumaShadowMaterial.EnableKeyword("UNDERLAY_ON");
_darumaShadowMaterial.SetFloat("_UnderlayDilate", 1f);
_darumaShadowMaterial.SetFloat("_UnderlayOffsetY", -0.7f);
_darumaShadowMaterial.SetFloat("_UnderlaySoftness", 1f);
_darumaShadowMaterial.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.1960784f));
Log.LogInfo((object)"Shadow material for Critial Hit indicator was successfully generated!");
}
return _darumaShadowMaterial;
}
}
public static (Item? prefab, ItemInstanceData? data) BankedItemData
{
get
{
RefreshIfDirty();
return (_bankedItem, _bankedItemData);
}
}
public static int BankedItemCarryWeight => _bankedItemCarryWeight;
public static bool IsBankFree { get; private set; }
public static string PiggyBankPath => _itemScope.Value switch
{
PiggyBankScopes.GLOBAL => Paths.GameRootPath,
PiggyBankScopes.PER_PROFILE => Paths.BepInExRootPath,
_ => throw new ArgumentOutOfRangeException("_itemScope"),
};
public static bool IsBankItemValid
{
get
{
RefreshIfDirty();
if (!IsBankFree)
{
return _bankedItemValid;
}
return true;
}
}
public static string Name => "PiggyBank";
public static string Version => "1.0.0";
private static void RefreshIfDirty()
{
if (_isDirty)
{
if (IsBankFree)
{
_bankedItem = null;
_bankedItemData = null;
_bankedItemCarryWeight = 0;
}
else
{
_bankedItem = FetchBankedItemPrefab();
_bankedItemData = FetchBankedItemData();
_bankedItemCarryWeight = _bankedItem.carryWeight;
}
_isDirty = false;
}
}
private void Awake()
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
_itemScope = ((BaseUnityPlugin)this).Config.Bind<PiggyBankScopes>("General", "Piggy Bank scope", PiggyBankScopes.GLOBAL, "The scope of stored items.\r\nYou can use this config to have different stored items per profile or keep it globally available.");
_itemScope.SettingChanged += delegate
{
_isDirty = true;
};
BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "piggybank.peakbundle", (Action<PeakBundle>)delegate(PeakBundle bundle)
{
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_0321: Unknown result type (might be due to invalid IL or missing references)
//IL_0332: Unknown result type (might be due to invalid IL or missing references)
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_0340: Unknown result type (might be due to invalid IL or missing references)
//IL_0347: Unknown result type (might be due to invalid IL or missing references)
//IL_034e: Unknown result type (might be due to invalid IL or missing references)
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Unknown result type (might be due to invalid IL or missing references)
//IL_0367: Unknown result type (might be due to invalid IL or missing references)
//IL_036e: Unknown result type (might be due to invalid IL or missing references)
//IL_0375: Unknown result type (might be due to invalid IL or missing references)
//IL_037c: Unknown result type (might be due to invalid IL or missing references)
//IL_0383: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0398: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
//IL_03c7: Expected O, but got Unknown
GameObject val = bundle.LoadAsset<GameObject>("PiggyScreen.prefab");
PiggyBankScreen piggyBankScreen = val.AddComponent<PiggyBankScreen>();
((UIWheel)piggyBankScreen).maxCursorDistance = 190f;
piggyBankScreen.chosenItemText = ((Component)val.transform.Find("SelectedItemName")).GetComponent<TextMeshProUGUI>();
piggyBankScreen.currentlyHeldItem = ((Component)val.transform.Find("HeldItem")).GetComponent<RawImage>();
piggyBankScreen.invalidItemIndicator = ((Component)val.transform.Find("InvalidItemIndicator")).GetComponent<Image>();
ReplaceShaders(new List<string>(2) { "Scouts/UI", "TextMeshPro/Distance Field" }, val);
PiggyBankZone orAddComponent = ExtGameObject.GetOrAddComponent<PiggyBankZone>(((Component)val.transform.Find("PiggyZone")).gameObject);
orAddComponent.image = ((Component)((Component)orAddComponent).transform.Find("Segment")).GetComponentInChildren<RawImage>();
((UIWheelSlice)orAddComponent).button = ((Component)orAddComponent).GetComponent<Button>();
PiggyBankZone orAddComponent2 = ExtGameObject.GetOrAddComponent<PiggyBankZone>(((Component)val.transform.Find("PickUpZone")).gameObject);
((UIWheelSlice)orAddComponent2).button = ((Component)orAddComponent2).GetComponent<Button>();
piggyBankScreen.piggyZone = orAddComponent;
piggyBankScreen.pickupZone = orAddComponent2;
PiggyScreenPrefab = ((Component)piggyBankScreen).gameObject;
GameObject val2 = bundle.LoadAsset<GameObject>("Piggybank.prefab");
GameObject val3 = bundle.LoadAsset<GameObject>("VFX_PiggyShards.prefab");
PiggyBankController orAddComponent3 = ExtGameObject.GetOrAddComponent<PiggyBankController>(val2);
PiggyBankBreakable orAddComponent4 = ExtGameObject.GetOrAddComponent<PiggyBankBreakable>(val2);
PiggyBankImpactSFX orAddComponent5 = ExtGameObject.GetOrAddComponent<PiggyBankImpactSFX>(val2);
ItemImpactSFX orAddComponent6 = ExtGameObject.GetOrAddComponent<ItemImpactSFX>(val2);
ItemCooking orAddComponent7 = ExtGameObject.GetOrAddComponent<ItemCooking>(val2);
((Breakable)orAddComponent4).breakOnCollision = true;
((Breakable)orAddComponent4).minBreakVelocity = 15f;
((Breakable)orAddComponent4).ragdollCharacterOnBreak = true;
((Breakable)orAddComponent4).pushForce = 2f;
((Breakable)orAddComponent4).wholeBodyPushForce = 1f;
((Breakable)orAddComponent4).instantiateNonItemOnBreak = new List<GameObject>(1) { val3 };
orAddComponent5.impact = orAddComponent6.impact;
orAddComponent5.disallowInHands = orAddComponent6.disallowInHands;
orAddComponent5.vel = orAddComponent6.vel;
orAddComponent5.velMult = orAddComponent6.velMult;
orAddComponent7.additionalCookingBehaviors = CollectionExtensions.AddToArray<AdditionalCookingBehavior>(orAddComponent7.additionalCookingBehaviors, (AdditionalCookingBehavior)(object)new CookingBehaviourPiggyBankRelease
{
cookedAmountToTrigger = 1
});
orAddComponent5.impact_empty = (SFX_Instance[])(object)new SFX_Instance[1] { bundle.LoadAsset<SFX_Instance>("SFXI Piggy Bank Hold Empty.asset") };
orAddComponent5.impact_full = (SFX_Instance[])(object)new SFX_Instance[1] { bundle.LoadAsset<SFX_Instance>("SFXI Piggy Bank Hold Full.asset") };
Object.Destroy((Object)(object)orAddComponent6);
((Item)orAddComponent3).defaultPos = new Vector3(0f, -0.3f, 1.25f);
((Item)orAddComponent3).defaultForward = new Vector3(0f, 0f, 1f);
((Item)orAddComponent3).mainRenderer = ((Component)val2.transform.Find("Piggybank/Piggybank")).GetComponent<Renderer>();
((Item)orAddComponent3).addtlRenderers = (Renderer[])(object)new Renderer[1] { ((Component)val2.transform.Find("Piggybank/Piggybank_eyes")).GetComponent<Renderer>() };
((Item)orAddComponent3).offsetLuggageSpawn = true;
((Item)orAddComponent3).offsetLuggageRotation = new Vector3(281.467f, 0f, -180f);
((Item)orAddComponent3).offsetLuggagePosition = new Vector3(0f, -0.47f, 0.666f);
orAddComponent3.openRadialMenuTime = 0f;
((Item)orAddComponent3).carryWeight = 1;
((Item)orAddComponent3).mass = 50f;
((Item)orAddComponent3).UIData = new ItemUIData
{
itemName = "Piggy Bank",
icon = bundle.LoadAsset<Texture2D>("piggybank.png"),
hasAltIcon = false,
hasColorBlindIcon = false,
altIcon = null,
hasMainInteract = false,
mainInteractPrompt = "INSPECT",
hasSecondInteract = false,
secondaryInteractPrompt = null,
hasScrollingInteract = false,
scrollInteractPrompt = null,
canDrop = true,
canPocket = true,
canBackpack = true,
canThrow = true,
isShootable = false,
hideFuel = true,
iconPositionOffset = default(Vector3),
iconRotationOffset = default(Vector3),
iconScaleOffset = 0f
};
((Item)orAddComponent3).showUseProgress = true;
ReplaceShaders(new List<string>(1) { "GD/Face Cards" }, val2);
ReplaceShaders(new List<string>(2) { "W/Peak_Standard", "SmokeParticle" }, val3);
bundle.Mod.RegisterContent();
Log.LogInfo((object)"Piggy bank is loaded!");
});
IsBankFree = !File.Exists(Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank"));
AddLocalizedTextCsv();
new Harmony("com.github.MiiMii1205.PiggyBank").PatchAll(typeof(PiggyBankPatcher));
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
}
private void ReplaceShaders(List<string> shaderNames, GameObject go)
{
Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>();
foreach (Renderer ren in componentsInChildren)
{
ReplaceAllShaderInRenderer(shaderNames, ren);
}
}
private void ReplaceAllShaderInRenderer(List<string> shaderNames, Renderer ren)
{
foreach (string shaderName in shaderNames)
{
Shader val = Shader.Find(shaderName);
if ((Object)(object)val == (Object)null)
{
Log.LogWarning((object)(": Shader " + shaderName + " was not found."));
continue;
}
Material[] sharedMaterials = ren.sharedMaterials;
foreach (Material mat in sharedMaterials)
{
ReplaceShader(val, mat);
}
Material[] materials = ren.materials;
foreach (Material mat2 in materials)
{
ReplaceShader(val, mat2);
}
}
}
private static void ReplaceShader(Shader shader, Material mat)
{
if (!(((Object)mat.shader).name != ((Object)shader).name))
{
mat.shader = shader;
}
}
private void OnDestroy()
{
Harmony.UnpatchID("com.github.MiiMii1205.PiggyBank");
Log.LogInfo((object)("Plugin " + Name + " unloaded!"));
}
private void AddLocalizedTextCsv()
{
using StreamReader streamReader = new StreamReader(Path.Join((ReadOnlySpan<char>)Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (ReadOnlySpan<char>)"PiggyBankLocalizedText.csv"));
int num = 0;
while (!streamReader.EndOfStream)
{
string text = streamReader.ReadLine();
if (text == null)
{
break;
}
num++;
List<string> list = new List<string>(CSVReader.SplitCsvLine(text, true));
string text2 = ExtCollections.Deque<string>(list);
string text3 = ExtCollections.Pop<string>(list);
if (text3 != "ENDLINE")
{
Log.LogError((object)$"Invalid localization at line {num}");
}
if (text2 != "CURRENT_LANGUAGE")
{
LocalizedText.mainTable[text2.ToUpper()] = list;
Log.LogDebug((object)("Added localization of " + text2.ToUpper()));
}
}
Log.LogDebug((object)$"Added {num - 1} localizations");
}
private static Item FindItemPrefab(string itemName, ushort itemId)
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
string itemName2 = itemName;
Item val = null;
List<Item> source = SingletonAsset<ItemDatabase>.Instance.itemLookup.Values.Where((Item t) => t.UIData.itemName == itemName2).ToList();
int num = source.Count();
Item val2 = ((num > 1) ? source.First((Item t) => t.itemID == itemId) : ((num != 1) ? val : source.First()));
val = val2;
if ((Object)(object)val == (Object)null)
{
Log.LogWarning((object)("No item named " + itemName2 + " were found. Defaulting to a Red Crispberry..."));
_bankedItemValid = false;
if (!ItemDatabase.TryGetItem((ushort)4, ref val))
{
throw new DeserializationException("No valid item were found while fetching the piggybank");
}
}
else
{
_bankedItemValid = true;
}
return val;
}
private static Item FetchBankedItemPrefab()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
BinaryDeserializer val = new BinaryDeserializer(File.ReadAllBytes(Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank")), (Allocator)2);
string itemName = val.ReadString(Encoding.Unicode);
ushort itemId = val.ReadUShort();
Item val2 = FindItemPrefab(itemName, itemId);
_bankedItemCarryWeight = val2.carryWeight;
return val2;
}
private static ItemInstanceData FetchBankedItemData()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
BinaryDeserializer val = new BinaryDeserializer(File.ReadAllBytes(Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank")), (Allocator)2);
val.ReadString(Encoding.Unicode);
val.ReadUShort();
ItemInstanceData val2 = new ItemInstanceData();
val2.Deserialize(val);
return val2;
}
public static bool WithdrawFromBank(out Item? item, bool giveToLocalPlayer = true, Vector3 spawnPosition = default(Vector3))
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
string text = Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank");
BinaryDeserializer val = new BinaryDeserializer(File.ReadAllBytes(text), (Allocator)2);
try
{
string itemName = val.ReadString(Encoding.Unicode);
ushort itemId = val.ReadUShort();
Item val2 = FindItemPrefab(itemName, itemId);
GameObject val3 = PhotonNetwork.Instantiate("0_Items/" + ((Object)val2).name, spawnPosition, Quaternion.identity, (byte)0, (object[])null);
Item component = val3.GetComponent<Item>();
ItemInstanceData val4 = new ItemInstanceData();
if (_bankedItemValid)
{
val4.Deserialize(val);
val4.data[(DataEntryKey)6] = DataEntryValue.GetNewFromValue((byte)1);
}
component.SetItemInstanceDataRPC(val4);
if (giveToLocalPlayer)
{
val3.GetComponent<Item>().RequestPickup(((Component)Character.localCharacter).GetComponent<PhotonView>());
}
Log.LogInfo((object)("Retreived item " + component.GetName() + " from " + text + "."));
_isDirty = false;
item = component;
IsBankFree = true;
return true;
}
catch (Exception ex)
{
Log.LogError((object)ex);
item = null;
return false;
}
finally
{
((IDisposable)val)?.Dispose();
}
}
public static void ClearBank()
{
File.Delete(Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank"));
}
private static void RefreshBankedItemData(Item storedItemInstante, ItemInstanceData data)
{
Item val = (_bankedItem = FindItemPrefab(storedItemInstante.UIData.itemName, storedItemInstante.itemID));
_bankedItemData = data;
_bankedItemCarryWeight = val.carryWeight;
_isDirty = false;
}
public static bool DepositItemToBank(Item item, ItemInstanceData data)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
BinarySerializer val = new BinarySerializer();
try
{
string text = Path.Join((ReadOnlySpan<char>)PiggyBankPath, (ReadOnlySpan<char>)".peakpiggybank");
try
{
val.WriteString(item.UIData.itemName, Encoding.Unicode);
val.WriteUshort(item.itemID);
data.Serialize(val);
File.WriteAllBytes(text, val.buffer.ToArray());
Log.LogInfo((object)("Serialized item " + item.GetName() + " @ " + text + "."));
_isDirty = true;
IsBankFree = false;
RefreshBankedItemData(item, data);
return true;
}
catch (Exception ex)
{
Log.LogError((object)ex);
return false;
}
}
finally
{
((IDisposable)val)?.Dispose();
}
}
}
}
namespace PiggyBank.Patchers
{
public static class PiggyBankPatcher
{
[HarmonyPatch(typeof(GUIManager), "Awake")]
[HarmonyPostfix]
public static void GUIAwakePostfix(GUIManager __instance)
{
PiggyBankUIManager orAddComponent = ExtensionMethods.GetOrAddComponent<PiggyBankUIManager>(((Component)__instance).gameObject);
if ((Object)(object)orAddComponent == (Object)null)
{
Plugin.Log.LogError((object)("Can't add PiggyBankUIManager to " + __instance.character.characterName + "'s GUI"));
return;
}
GameObject val = Object.Instantiate<GameObject>(Plugin.PiggyScreenPrefab, ((Component)__instance.hudCanvas).transform);
orAddComponent.piggyBankScreen = val.GetComponent<PiggyBankScreen>();
val.SetActive(false);
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
public static void GUIWheelActivePost(GUIManager __instance, ref bool __result)
{
__result = PiggyBankUIManager.instance.piggyBankActive | __result;
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
public static void CarryWeightPost(Item __instance, ref int __result)
{
if (__instance is PiggyBankController && !Plugin.IsBankFree)
{
__result = __instance.carryWeight + Plugin.BankedItemCarryWeight + Ascents.itemWeightModifier;
}
}
[HarmonyPatch(typeof(Item), "GetItemName")]
[HarmonyPostfix]
public static void ItemNamePost(Item __instance, ref string __result)
{
if (__instance is PiggyBankController && !Plugin.IsBankFree)
{
(Item, ItemInstanceData) bankedItemData = Plugin.BankedItemData;
Item val = bankedItemData.Item1 ?? throw new NullReferenceException("prefab");
__result = __result + " (" + val.GetItemName(bankedItemData.Item2) + ")";
}
}
}
}
namespace PiggyBank.Data
{
public enum PiggyBankScopes
{
GLOBAL,
PER_PROFILE
}
}
namespace PiggyBank.Behaviours
{
public class CookingBehaviourPiggyBankRelease : AdditionalCookingBehavior
{
public override void TriggerBehaviour(int cookedAmount)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)((ItemComponent)base.itemCooking).item.holderCharacter) && ((ItemComponent)base.itemCooking).item.holderCharacter.IsLocal && !Plugin.IsBankFree && Plugin.WithdrawFromBank(out Item item))
{
item = item ?? throw new NullReferenceException("i");
item.Interact(Character.localCharacter);
Plugin.ClearBank();
}
}
}
[RequireComponent(typeof(PhotonView))]
public class PiggyBankBreakable : Breakable
{
private bool m_justThrown;
public void Awake()
{
((Breakable)this).Awake();
GlobalEvents.OnItemThrown = (Action<Item>)Delegate.Combine(GlobalEvents.OnItemThrown, new Action<Item>(OnItemThrown));
}
private void OnItemThrown(Item obj)
{
if ((Object)(object)obj == (Object)(object)base.item)
{
m_justThrown = true;
}
}
public void OnCollisionEnter(Collision collision)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: 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)
if (((MonoBehaviourPun)base.item).photonView.IsMine && (int)base.item.itemState == 0 && base.breakOnCollision && Object.op_Implicit((Object)(object)base.item.rig))
{
Vector3 relativeVelocity = collision.relativeVelocity;
if (!(((Vector3)(ref relativeVelocity)).magnitude <= base.minBreakVelocity))
{
goto IL_0056;
}
}
m_justThrown = false;
goto IL_0056;
IL_0056:
((Breakable)this).OnCollisionEnter(collision);
}
public override void Break(Collision coll)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
if (base.item is PiggyBankController && m_justThrown && base.item.lastThrownCharacter.IsLocal && !base.item.lastThrownCharacter.data.dead && !base.item.lastThrownCharacter.data.fullyPassedOut && !Plugin.IsBankFree && Plugin.WithdrawFromBank(out Item item, giveToLocalPlayer: false, ((Component)this).transform.position + ((ContactPoint)(ref coll.contacts[0])).normal))
{
item = item ?? throw new NullReferenceException("i");
item.rig.linearVelocity = base.item.rig.linearVelocity;
item.rig.angularVelocity = base.item.rig.linearVelocity;
((Component)item).transform.up = ((ContactPoint)(ref coll.contacts[0])).normal;
Plugin.ClearBank();
}
((Breakable)this).Break(coll);
}
[PunRPC]
public void RPC_NonItemBreak()
{
((Breakable)this).RPC_NonItemBreak();
}
}
public class PiggyBankController : Item
{
public float openRadialMenuTime = 0.25f;
public bool holdOnFinish => false;
public override void AddPhysics()
{
((Item)this).AddPhysics();
base.rig.sleepThreshold = 0f;
}
public override void Interact(Character interactor)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)((Item)this).itemState == 2)
{
((Item)this).Interact(interactor);
}
else
{
PiggyBankUIManager.instance.OpenPîggyBankScreen(PiggyBankReference.GetFromBackpackItem((Item)(object)this));
}
}
public void ReleaseInteract(Character interactor)
{
}
public void PickUpPiggyBank(Character interactor)
{
((Item)this).Interact(interactor);
}
private void DisableVisuals()
{
base.mainRenderer.shadowCastingMode = (ShadowCastingMode)3;
}
private void EnableVisuals()
{
base.mainRenderer.shadowCastingMode = (ShadowCastingMode)1;
}
private static bool HasSpace()
{
return Plugin.IsBankFree;
}
public override string GetInteractionText()
{
return LocalizedText.GetText("INSPECT", true);
}
[ConsoleCommand]
public static void PrintBankedItems()
{
(Item, ItemInstanceData) bankedItemData = Plugin.BankedItemData;
Plugin.Log.LogInfo((object)$"Slot: {((Object)((Component)bankedItemData.Item1).gameObject).name}, data entries: {bankedItemData.Item2.data.Count}");
}
public bool IsConstantlyInteractable(Character interactor)
{
return false;
}
public float GetInteractTime(Character interactor)
{
return openRadialMenuTime;
}
public void Interact_CastFinished(Character interactor)
{
}
public void CancelCast(Character interactor)
{
}
public void Deposit(Character interactor)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: 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)
if (!Object.op_Implicit((Object)(object)interactor.data.currentItem) || !HasSpace())
{
return;
}
CharacterItems items = interactor.refs.items;
if (items.currentSelectedSlot.IsNone)
{
Plugin.Log.LogError((object)"Need item slot selected to stash item in piggy bank!");
return;
}
ItemSlot itemSlot = interactor.player.GetItemSlot(items.currentSelectedSlot.Value);
if (itemSlot.IsEmpty())
{
Plugin.Log.LogError((object)$"Item slot {itemSlot.itemSlotID} is empty!");
}
else if (Plugin.DepositItemToBank(itemSlot.prefab, itemSlot.data))
{
interactor.player.EmptySlot(items.currentSelectedSlot);
Optionable<byte> currentSelectedSlot = items.currentSelectedSlot;
if (currentSelectedSlot.IsSome && currentSelectedSlot.Value == 250)
{
((MonoBehaviourPun)interactor).photonView.RPC("DestroyHeldItemRpc", (RpcTarget)0, Array.Empty<object>());
}
else
{
items.EquipSlot(Optionable<byte>.None);
}
}
}
}
public class PiggyBankImpactSFX : MonoBehaviour
{
public float vel;
private Rigidbody rig;
private Item item;
public float velMult = 1f;
public bool disallowInHands;
public SFX_Instance[] impact;
public SFX_Instance[] impact_empty;
public SFX_Instance[] impact_full;
private void Start()
{
rig = ((Component)this).GetComponent<Rigidbody>();
item = ((Component)this).GetComponent<Item>();
}
private void Update()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)rig) && !rig.isKinematic)
{
vel = Mathf.Lerp(vel, Vector3.SqrMagnitude(rig.linearVelocity) * velMult, 10f * Time.deltaTime);
}
}
private void playEmptySFX()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < impact_empty.Length; i++)
{
impact_empty[i].Play(((Component)this).transform.position);
}
}
private void playFullSFX()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < impact_full.Length; i++)
{
impact_full[i].Play(((Component)this).transform.position);
}
}
private void PlayAdditionalSfx()
{
if (Plugin.IsBankFree)
{
playEmptySFX();
}
else
{
playFullSFX();
}
}
private void PlayImpactSFX()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
SFX_Instance[] array = impact;
foreach (SFX_Instance val in array)
{
val.Play(((Component)this).transform.position);
}
PlayAdditionalSfx();
}
private void OnCollisionEnter(Collision collision)
{
if (!Object.op_Implicit((Object)(object)rig))
{
return;
}
if (Object.op_Implicit((Object)(object)item))
{
if (!Object.op_Implicit((Object)(object)item.holderCharacter))
{
if (vel > 4f)
{
PlayImpactSFX();
}
}
else if (vel > 36f && !disallowInHands)
{
PlayImpactSFX();
}
}
if (!Object.op_Implicit((Object)(object)item) && !Object.op_Implicit((Object)(object)collision.rigidbody) && vel > 64f)
{
PlayImpactSFX();
}
vel = 0f;
}
}
public struct PiggyBankReference : IBinarySerializable
{
public Transform locationTransform;
public PhotonView view;
public void Serialize(BinarySerializer serializer)
{
serializer.WriteInt(view.ViewID);
}
public void Deserialize(BinaryDeserializer deserializer)
{
view = PhotonView.Find(deserializer.ReadInt());
}
public static PiggyBankReference GetFromBackpackItem(Item item)
{
PiggyBankReference result = default(PiggyBankReference);
result.view = ((Component)item).GetComponent<PhotonView>();
result.locationTransform = ((Component)item).transform;
return result;
}
public bool TryGetPiggyBankItem(out PiggyBankController piggyBank)
{
piggyBank = ((Component)view).GetComponent<PiggyBankController>();
return true;
}
}
public class PiggyBankUIManager : MonoBehaviour
{
public PiggyBankScreen piggyBankScreen;
public static PiggyBankUIManager instance;
public bool piggyBankActive => ((Component)piggyBankScreen).gameObject.activeSelf;
private void Awake()
{
instance = this;
}
public void ClosePîggyBankScreen()
{
Plugin.Log.LogDebug((object)"Close piggy screen");
Character.localCharacter.data.usingBackpackWheel = false;
((Component)piggyBankScreen).gameObject.SetActive(false);
}
public void OpenPîggyBankScreen(PiggyBankReference backpackReference)
{
if (!GUIManager.instance.wheelActive && !GUIManager.instance.windowBlockingInput)
{
Character.localCharacter.data.usingBackpackWheel = true;
piggyBankScreen.InitWheel(backpackReference);
}
}
}
}
namespace PiggyBank.Behaviours.GUI
{
public class PiggyBankScreen : UIWheel
{
public PiggyBankZone piggyZone;
public PiggyBankZone pickupZone;
public TextMeshProUGUI chosenItemText;
public Optionable<PiggyBankZone.ZoneData> chosenZone;
public PiggyBankReference piggyBank;
public RawImage currentlyHeldItem;
public Image invalidItemIndicator;
private int currentlyHeldItemCookedAmount;
private void Awake()
{
((TMP_Text)chosenItemText).font = Plugin.DarumaDropOne;
((TMP_Text)chosenItemText).lineSpacing = -50f;
TextMeshProUGUI obj = chosenItemText;
TextMeshProUGUI obj2 = chosenItemText;
Material val = (((Graphic)chosenItemText).material = Plugin.DarumaDropOneShadowMaterial);
Material fontSharedMaterial = (((TMP_Text)obj2).fontMaterial = val);
((TMP_Text)obj).fontSharedMaterial = fontSharedMaterial;
}
public void InitWheel(PiggyBankReference pg)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
piggyBank = pg;
chosenZone = Optionable<PiggyBankZone.ZoneData>.None;
((TMP_Text)chosenItemText).text = "";
piggyZone.InitItemSlot(pg, this);
((Component)this).gameObject.SetActive(true);
pickupZone.InitPickupPiggyBank(pg, this);
if ((Object)(object)Character.localCharacter.data.currentItem != (Object)null && !(Character.localCharacter.data.currentItem is PiggyBankController) && Character.localCharacter.data.currentItem.UIData.canBackpack)
{
currentlyHeldItem.texture = (Texture)(object)Character.localCharacter.data.currentItem.UIData.GetIcon();
UpdateCookedAmount(Character.localCharacter.data.currentItem);
((Behaviour)currentlyHeldItem).enabled = true;
}
else
{
UpdateCookedAmount(null);
((Behaviour)currentlyHeldItem).enabled = false;
}
((Behaviour)invalidItemIndicator).enabled = !Plugin.IsBankItemValid;
}
private void UpdateCookedAmount(Item item)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
IntItemData val = default(IntItemData);
if ((Object)(object)item == (Object)null || item.data == null)
{
currentlyHeldItemCookedAmount = 0;
((Graphic)currentlyHeldItem).color = Color.white;
}
else if (item.data.TryGetDataEntry<IntItemData>((DataEntryKey)1, ref val) && currentlyHeldItemCookedAmount != val.Value)
{
((Graphic)currentlyHeldItem).color = Color.white;
((Graphic)currentlyHeldItem).color = ItemCooking.GetCookColor(val.Value);
currentlyHeldItemCookedAmount = val.Value;
}
}
public override void Update()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
if (!Character.localCharacter.input.interactIsPressed)
{
Choose();
PiggyBankUIManager.instance.ClosePîggyBankScreen();
return;
}
if ((Object)(object)piggyBank.locationTransform != (Object)null && Vector3.Distance(piggyBank.locationTransform.position, Character.localCharacter.Center) > 6f)
{
PiggyBankUIManager.instance.ClosePîggyBankScreen();
return;
}
if (chosenZone.IsSome && !chosenZone.Value.isPiggyBankPickup && !((Behaviour)piggyZone.image).enabled)
{
((Component)currentlyHeldItem).transform.position = Vector3.Lerp(((Component)currentlyHeldItem).transform.position, ((Component)piggyZone).transform.GetChild(0).GetChild(0).position, Time.deltaTime * 20f);
}
else
{
((Component)currentlyHeldItem).transform.localPosition = Vector3.Lerp(((Component)currentlyHeldItem).transform.localPosition, Vector3.zero, Time.deltaTime * 20f);
}
((UIWheel)this).Update();
}
public void Choose()
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Invalid comparison between Unknown and I4
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
if (!chosenZone.IsSome)
{
return;
}
Plugin.Log.LogDebug((object)$"Chose zone {chosenZone.Value.slotID}");
Item item = null;
if (chosenZone.Value.isPiggyBankPickup)
{
if (chosenZone.Value.piggyBankReference.TryGetPiggyBankItem(out PiggyBankController piggyBankController) && (int)((Item)piggyBankController).itemState != 1)
{
piggyBankController.PickUpPiggyBank(Character.localCharacter);
}
}
else if (chosenZone.Value.isDepositZone)
{
TryDeposit();
}
else if (!Plugin.IsBankFree && Plugin.WithdrawFromBank(out item))
{
item = item ?? throw new NullReferenceException("item");
item.Interact(Character.localCharacter);
Plugin.ClearBank();
}
else if (Object.op_Implicit((Object)(object)Character.localCharacter.data.currentItem))
{
TryDeposit();
}
}
private void TryDeposit()
{
if (piggyBank.TryGetPiggyBankItem(out PiggyBankController piggyBankController))
{
piggyBankController.Deposit(Character.localCharacter);
}
}
public void Hover(PiggyBankZone.ZoneData zoneData)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_00d7: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
if (zoneData.isPiggyBankPickup)
{
if (zoneData.piggyBankReference.TryGetPiggyBankItem(out PiggyBankController piggyBankController) && (int)((Item)piggyBankController).itemState != 1)
{
((TMP_Text)chosenItemText).text = LocalizedText.GetText("CARRY", true).Replace("#", ((Item)piggyBankController).GetItemName((ItemInstanceData)null));
chosenZone = Optionable<PiggyBankZone.ZoneData>.Some(zoneData);
}
else
{
((TMP_Text)chosenItemText).text = "";
chosenZone = Optionable<PiggyBankZone.ZoneData>.None;
}
return;
}
if (zoneData.isDepositZone)
{
Item currentItem = Character.localCharacter.data.currentItem;
if ((Object)(object)currentItem != (Object)null)
{
((TMP_Text)chosenItemText).text = LocalizedText.GetText("DEPOSITITEM", true).Replace("#", currentItem.GetItemName((ItemInstanceData)null));
chosenZone = Optionable<PiggyBankZone.ZoneData>.Some(zoneData);
}
else
{
((TMP_Text)chosenItemText).text = "";
chosenZone = Optionable<PiggyBankZone.ZoneData>.None;
}
return;
}
bool flag = false;
if (Plugin.IsBankFree && Object.op_Implicit((Object)(object)Character.localCharacter.data.currentItem))
{
if (Object.op_Implicit((Object)(object)Character.localCharacter.data.currentItem))
{
((TMP_Text)chosenItemText).text = LocalizedText.GetText("DEPOSITITEM", true).Replace("#", Character.localCharacter.data.currentItem.GetItemName((ItemInstanceData)null));
flag = true;
}
}
else
{
(Item, ItemInstanceData) bankedItemData = Plugin.BankedItemData;
var (val, _) = bankedItemData;
if ((Object)(object)val != (Object)null)
{
((TMP_Text)chosenItemText).text = LocalizedText.GetText("WITHDRAWITEM", true).Replace("#", val.GetItemName(bankedItemData.Item2));
flag = true;
}
}
if (flag)
{
chosenZone = Optionable<PiggyBankZone.ZoneData>.Some(zoneData);
}
}
public void Dehover(PiggyBankZone.ZoneData zoneData)
{
//IL_0034: 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)
if (chosenZone.IsSome && chosenZone.Value.Equals(zoneData))
{
((TMP_Text)chosenItemText).text = "";
chosenZone = Optionable<PiggyBankZone.ZoneData>.None;
}
}
public override void TestSelectSliceGamepad(Vector2 gamepadVector)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
float num = 0f;
PiggyBankZone piggyBankZone = null;
if (!(((Vector2)(ref gamepadVector)).sqrMagnitude < 0.5f))
{
float num2 = Vector3.Angle(Vector2.op_Implicit(gamepadVector), ((UIWheelSlice)pickupZone).GetUpVector());
if ((Object)(object)piggyBankZone == (Object)null || num2 < num)
{
piggyBankZone = pickupZone;
num = num2;
}
num2 = Vector3.Angle(Vector2.op_Implicit(gamepadVector), ((UIWheelSlice)piggyZone).GetUpVector());
if ((Object)(object)piggyBankZone == (Object)null || num2 < num)
{
piggyBankZone = piggyZone;
num = num2;
}
}
if ((Object)(object)piggyBankZone != (Object)null)
{
EventSystem.current.SetSelectedGameObject(((Component)((UIWheelSlice)piggyBankZone).button).gameObject);
piggyBankZone.Hover();
}
else
{
EventSystem.current.SetSelectedGameObject((GameObject)null);
Dehover(chosenZone.Value);
}
}
}
public class PiggyBankZone : UIWheelSlice, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
public struct ZoneData : IEquatable<ZoneData>
{
public bool isDepositZone;
public bool isPiggyBankPickup;
public PiggyBankReference piggyBankReference;
public byte slotID;
public bool Equals(ZoneData other)
{
if (isPiggyBankPickup == other.isPiggyBankPickup)
{
return slotID == other.slotID;
}
return false;
}
public override bool Equals(object obj)
{
if (obj is ZoneData other)
{
return Equals(other);
}
return false;
}
public override int GetHashCode()
{
return HashCode.Combine(isPiggyBankPickup, piggyBankReference, slotID);
}
}
public RawImage image;
private int cookedAmount;
private bool hasItem;
private bool isDepositZone;
private ItemSlot itemSlot;
private PiggyBankReference piggyBank;
private PiggyBankScreen piggyBankScreen;
public byte piggyBankSlot { get; private set; }
private bool canInteract
{
get
{
if (isPiggyBankPickup)
{
return true;
}
if (isDepositZone)
{
return true;
}
if (!hasItem)
{
if ((Object)(object)Character.localCharacter.data.currentItem != (Object)null)
{
if (Character.localCharacter.data.currentItem.UIData.canBackpack)
{
return !(Character.localCharacter.data.currentItem is PiggyBankController);
}
return false;
}
return false;
}
return true;
}
}
public bool isPiggyBankPickup => piggyBankSlot == byte.MaxValue;
public void OnPointerEnter(PointerEventData eventData)
{
Hover();
}
public void OnPointerExit(PointerEventData eventData)
{
Dehover();
}
private void UpdateInteractable()
{
((Selectable)base.button).interactable = canInteract;
}
public void InitItemSlot(PiggyBankReference pg, PiggyBankScreen pbs)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
SharedInit(pg, pbs);
piggyBankSlot = 0;
Item iconHolder = null;
if (itemSlot == null)
{
itemSlot = new ItemSlot(piggyBankSlot);
}
if (!Plugin.IsBankFree)
{
(Item, ItemInstanceData) bankedItemData = Plugin.BankedItemData;
itemSlot.SetItem(bankedItemData.Item1, bankedItemData.Item2);
iconHolder = itemSlot.prefab;
}
SetItemIcon(iconHolder, itemSlot.data);
UpdateInteractable();
}
private void SharedInit(PiggyBankReference pgRef, PiggyBankScreen screen)
{
piggyBank = pgRef;
piggyBankScreen = screen;
if (piggyBankSlot == byte.MaxValue)
{
((Component)this).gameObject.SetActive(true);
}
SetItemIcon(null, null);
}
private void SetItemIcon(Item iconHolder, ItemInstanceData itemInstanceData)
{
if ((Object)(object)iconHolder == (Object)null)
{
if ((Object)(object)image != (Object)null)
{
((Behaviour)image).enabled = false;
}
hasItem = false;
}
else
{
if ((Object)(object)image != (Object)null)
{
((Behaviour)image).enabled = true;
image.texture = (Texture)(object)iconHolder.UIData.GetIcon();
}
hasItem = true;
}
UpdateCookedAmount(iconHolder, itemInstanceData);
}
private void UpdateCookedAmount(Item? item, ItemInstanceData? itemInstanceData)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
IntItemData val = default(IntItemData);
if ((Object)(object)item == (Object)null || itemInstanceData == null)
{
cookedAmount = 0;
if ((Object)(object)image != (Object)null)
{
((Graphic)image).color = Color.white;
}
}
else if (itemInstanceData.TryGetDataEntry<IntItemData>((DataEntryKey)1, ref val) && cookedAmount != val.Value)
{
if ((Object)(object)image != (Object)null)
{
((Graphic)image).color = Color.white;
((Graphic)image).color = ItemCooking.GetCookColor(val.Value);
}
cookedAmount = val.Value;
}
}
public void Hover()
{
if (canInteract)
{
ZoneData zoneData = default(ZoneData);
zoneData.isDepositZone = isDepositZone;
zoneData.isPiggyBankPickup = isPiggyBankPickup;
zoneData.piggyBankReference = piggyBank;
zoneData.slotID = piggyBankSlot;
ZoneData zoneData2 = zoneData;
piggyBankScreen.Hover(zoneData2);
}
}
public void Dehover()
{
ZoneData zoneData = default(ZoneData);
zoneData.isDepositZone = isDepositZone;
zoneData.isPiggyBankPickup = piggyBankSlot == byte.MaxValue;
zoneData.piggyBankReference = piggyBank;
zoneData.slotID = piggyBankSlot;
ZoneData zoneData2 = zoneData;
piggyBankScreen.Dehover(zoneData2);
}
public void InitPickupPiggyBank(PiggyBankReference pg, PiggyBankScreen pbs)
{
piggyBankSlot = byte.MaxValue;
SharedInit(pg, pbs);
UpdateInteractable();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}