using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.GUI;
using Jotunn.Managers;
using Jotunn.Utils;
using SimpleJson;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using ValheimResourceInventoryMod;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("StorehouseCharacter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StorehouseCharacter")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7ebb018e-7e1a-4bf1-a422-e17e94e9900e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(Inventory), "CountItems", new Type[]
{
typeof(string),
typeof(int),
typeof(bool)
})]
internal static class Inventory_CountItems_CustomResourcesPatch
{
private static void Postfix(Inventory __instance, string name, int quality, bool matchWorldLevel, ref int __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null || string.IsNullOrEmpty(name))
{
return;
}
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer == (Object)null || __instance != ((Humanoid)localPlayer).GetInventory())
{
return;
}
int num = 0;
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (!(inventorySlot.SharedName == name))
{
continue;
}
if (quality >= 0)
{
if (inventorySlot.Quality == quality)
{
num += inventorySlot.Stack;
}
}
else
{
num += inventorySlot.Stack;
}
}
if (num > 0)
{
__result += num;
}
}
}
namespace ValheimResourceInventoryMod;
[HarmonyPatch(typeof(Player), "AutoPickup", new Type[] { typeof(float) })]
internal static class AutoPickUpPatch
{
[CompilerGenerated]
private sealed class <Transpiler>d__2 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
{
private int <>1__state;
private CodeInstruction <>2__current;
private int <>l__initialThreadId;
private IEnumerable<CodeInstruction> instructions;
public IEnumerable<CodeInstruction> <>3__instructions;
private MethodInfo <forceCanAdd>5__1;
private MethodInfo <forceMax>5__2;
private IEnumerator<CodeInstruction> <>s__3;
private CodeInstruction <ci>5__4;
private MethodInfo <mi>5__5;
private Type <p0>5__6;
private Type <p1>5__7;
CodeInstruction IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Transpiler>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<forceCanAdd>5__1 = null;
<forceMax>5__2 = null;
<>s__3 = null;
<ci>5__4 = null;
<mi>5__5 = null;
<p0>5__6 = null;
<p1>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<forceCanAdd>5__1 = AccessTools.Method(typeof(AutoPickUpPatch), "ForceCanAddItem", (Type[])null, (Type[])null);
<forceMax>5__2 = AccessTools.Method(typeof(AutoPickUpPatch), "ForceGetMaxCarryWeight", (Type[])null, (Type[])null);
<>s__3 = instructions.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
<mi>5__5 = null;
<ci>5__4 = null;
break;
}
if (<>s__3.MoveNext())
{
<ci>5__4 = <>s__3.Current;
object operand = <ci>5__4.operand;
<mi>5__5 = operand as MethodInfo;
if ((object)<mi>5__5 != null)
{
if (<mi>5__5.Name == "CanAddItem" && <mi>5__5.ReturnType == typeof(bool) && <mi>5__5.GetParameters().Length == 2)
{
<p0>5__6 = <mi>5__5.GetParameters()[0].ParameterType;
<p1>5__7 = <mi>5__5.GetParameters()[1].ParameterType;
if (<p0>5__6 == typeof(ItemData) && <p1>5__7 == typeof(int))
{
<ci>5__4.opcode = OpCodes.Call;
<ci>5__4.operand = <forceCanAdd>5__1;
}
<p0>5__6 = null;
<p1>5__7 = null;
}
else if (<mi>5__5.Name == "GetMaxCarryWeight" && <mi>5__5.ReturnType == typeof(float) && <mi>5__5.GetParameters().Length == 0)
{
<ci>5__4.opcode = OpCodes.Call;
<ci>5__4.operand = <forceMax>5__2;
}
}
<>2__current = <ci>5__4;
<>1__state = 1;
return true;
}
<>m__Finally1();
<>s__3 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>s__3 != null)
{
<>s__3.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
{
<Transpiler>d__2 <Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Transpiler>d__ = this;
}
else
{
<Transpiler>d__ = new <Transpiler>d__2(0);
}
<Transpiler>d__.instructions = <>3__instructions;
return <Transpiler>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
private static bool ForceCanAddItem(Inventory inv, ItemData item, int stack)
{
return true;
}
private static float ForceGetMaxCarryWeight(Player p)
{
return 999999f;
}
[IteratorStateMachine(typeof(<Transpiler>d__2))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Transpiler>d__2(-2)
{
<>3__instructions = instructions
};
}
}
[Serializable]
public class CustomInventorySlot
{
public string PrefabName;
public string SharedName;
public int Stack = 1;
public int Quality = 1;
public float Durability = 100f;
public int Variant;
public int WorldLevel;
public long CrafterID;
public string CrafterName = "";
public int MaxStackSize = 1;
public Dictionary<string, string> CustomData = new Dictionary<string, string>();
public string Rarity = "";
private ItemType? _cachedItemType;
private Color? _cachedRarityColor;
private static readonly HashSet<ItemType> UniqueItemTypes = new HashSet<ItemType>
{
(ItemType)3,
(ItemType)4,
(ItemType)5,
(ItemType)6,
(ItemType)7,
(ItemType)10,
(ItemType)11,
(ItemType)12,
(ItemType)14,
(ItemType)15,
(ItemType)19,
(ItemType)22,
(ItemType)24,
(ItemType)17,
(ItemType)18,
(ItemType)20
};
public bool IsUnique
{
get
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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)
ItemType itemType = GetItemType();
return UniqueItemTypes.Contains(itemType);
}
}
public bool CanDoStackOperations()
{
return !IsUnique;
}
public bool CanStackWith(CustomInventorySlot other)
{
if (other == null)
{
return false;
}
if (SharedName != other.SharedName)
{
return false;
}
if (IsUnique || other.IsUnique)
{
return false;
}
return true;
}
public Color GetRarityColor()
{
//IL_0016: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
if (_cachedRarityColor.HasValue)
{
return _cachedRarityColor.Value;
}
if (string.IsNullOrEmpty(Rarity))
{
_cachedRarityColor = Color.white;
return Color.white;
}
Color white = Color.white;
string text = Rarity.ToLower();
if (text == "magic" || text.Contains("magic"))
{
((Color)(ref white))..ctor(0.2f, 0.5f, 1f, 0.08f);
}
else if (text == "rare" || text.Contains("rare"))
{
((Color)(ref white))..ctor(1f, 1f, 0.2f, 0.08f);
}
else if (text == "epic" || text.Contains("epic"))
{
((Color)(ref white))..ctor(0.7f, 0.2f, 1f, 0.08f);
}
else if (text == "legendary" || text.Contains("legendary"))
{
((Color)(ref white))..ctor(0f, 0.7f, 0.7f, 0.08f);
}
else if (text == "mythic" || text.Contains("mythic"))
{
((Color)(ref white))..ctor(1f, 0.5f, 0f, 0.08f);
}
_cachedRarityColor = white;
return white;
}
private ItemType GetItemType()
{
//IL_0016: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
if (_cachedItemType.HasValue)
{
return _cachedItemType.Value;
}
if ((Object)(object)ObjectDB.instance == (Object)null)
{
return (ItemType)0;
}
if (!string.IsNullOrEmpty(PrefabName))
{
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(PrefabName);
if ((Object)(object)itemPrefab != (Object)null)
{
ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
if (component?.m_itemData?.m_shared != null)
{
_cachedItemType = component.m_itemData.m_shared.m_itemType;
return _cachedItemType.Value;
}
}
}
if (!string.IsNullOrEmpty(SharedName))
{
foreach (GameObject item in ObjectDB.instance.m_items)
{
ItemDrop component2 = item.GetComponent<ItemDrop>();
if (component2?.m_itemData?.m_shared?.m_name == SharedName)
{
_cachedItemType = component2.m_itemData.m_shared.m_itemType;
PrefabName = ((Object)item).name;
return _cachedItemType.Value;
}
}
}
return (ItemType)0;
}
public CustomInventorySlot Clone()
{
return new CustomInventorySlot
{
PrefabName = PrefabName,
SharedName = SharedName,
Stack = Stack,
Quality = Quality,
Durability = Durability,
Variant = Variant,
WorldLevel = WorldLevel,
CrafterID = CrafterID,
CrafterName = CrafterName,
MaxStackSize = MaxStackSize,
CustomData = new Dictionary<string, string>(CustomData),
_cachedItemType = _cachedItemType,
Rarity = Rarity,
_cachedRarityColor = _cachedRarityColor
};
}
public static CustomInventorySlot FromItemData(ItemData item)
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
if (item == null)
{
return null;
}
CustomInventorySlot customInventorySlot = new CustomInventorySlot();
GameObject dropPrefab = item.m_dropPrefab;
customInventorySlot.PrefabName = ((dropPrefab != null) ? ((Object)dropPrefab).name : null) ?? "";
customInventorySlot.SharedName = item.m_shared?.m_name ?? "";
customInventorySlot.Stack = item.m_stack;
customInventorySlot.Quality = item.m_quality;
customInventorySlot.Durability = item.m_durability;
customInventorySlot.Variant = item.m_variant;
customInventorySlot.WorldLevel = item.m_worldLevel;
customInventorySlot.CrafterID = item.m_crafterID;
customInventorySlot.CrafterName = item.m_crafterName;
customInventorySlot.MaxStackSize = item.m_shared?.m_maxStackSize ?? 1;
customInventorySlot._cachedItemType = item.m_shared?.m_itemType;
CustomInventorySlot customInventorySlot2 = customInventorySlot;
if (item.m_customData != null)
{
foreach (KeyValuePair<string, string> customDatum in item.m_customData)
{
customInventorySlot2.CustomData[customDatum.Key] = customDatum.Value;
}
string key = "randyknapp.mods.epicloot#EpicLoot.MagicItemComponent";
if (item.m_customData.TryGetValue(key, out var value))
{
if (value.Contains("\"Rarity\": 0") || value.Contains("\"Rarity\":0"))
{
customInventorySlot2.Rarity = "Magic";
}
else if (value.Contains("\"Rarity\": 1") || value.Contains("\"Rarity\":1"))
{
customInventorySlot2.Rarity = "Rare";
}
else if (value.Contains("\"Rarity\": 2") || value.Contains("\"Rarity\":2"))
{
customInventorySlot2.Rarity = "Epic";
}
else if (value.Contains("\"Rarity\": 3") || value.Contains("\"Rarity\":3"))
{
customInventorySlot2.Rarity = "Legendary";
}
else if (value.Contains("\"Rarity\": 4") || value.Contains("\"Rarity\":4"))
{
customInventorySlot2.Rarity = "Mythic";
}
}
}
return customInventorySlot2;
}
public ItemData ToItemData()
{
if ((Object)(object)ObjectDB.instance == (Object)null)
{
return null;
}
GameObject val = null;
if (!string.IsNullOrEmpty(PrefabName))
{
val = ObjectDB.instance.GetItemPrefab(PrefabName);
}
if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(SharedName))
{
foreach (GameObject item in ObjectDB.instance.m_items)
{
if (item.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_name == SharedName)
{
val = item;
break;
}
}
}
if ((Object)(object)val == (Object)null)
{
return null;
}
ItemDrop component = val.GetComponent<ItemDrop>();
if (component?.m_itemData == null)
{
return null;
}
ItemData val2 = component.m_itemData.Clone();
val2.m_stack = Stack;
val2.m_quality = Quality;
val2.m_durability = Durability;
val2.m_variant = Variant;
val2.m_worldLevel = WorldLevel;
val2.m_crafterID = CrafterID;
val2.m_crafterName = CrafterName;
val2.m_dropPrefab = val;
val2.m_customData.Clear();
foreach (KeyValuePair<string, string> customDatum in CustomData)
{
val2.m_customData[customDatum.Key] = customDatum.Value;
}
return val2;
}
}
[HarmonyPatch(typeof(CookingStation), "OnAddFoodSwitch")]
internal static class CookingStation_OnAddFoodSwitch_Patch
{
private static bool Prefix(CookingStation __instance, Switch caller, Humanoid user, ItemData item, ref bool __result)
{
if ((Object)(object)__instance.m_addFoodSwitch == (Object)null)
{
return true;
}
if (item != null)
{
return true;
}
if (Traverse.Create((object)__instance).Method("HaveDoneItem", Array.Empty<object>()).GetValue<bool>())
{
return true;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
string text = ResourceUI.PrioritizedItemForCooking;
bool flag = false;
if (!string.IsNullOrEmpty(text))
{
flag = resourceUI.IsItemValidForStation(text, __instance);
}
if (!flag)
{
string text2 = (ResourceUI.PrioritizedItemForCooking = resourceUI.FindFirstValidItemForStation(__instance));
text = text2;
if (!string.IsNullOrEmpty(text2))
{
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).Message((MessageType)1, "Auto-prioritized: " + resourceUI.GetLocalizedName(text2), 0, (Sprite)null);
}
resourceUI.OnResourcesChanged();
}
}
if (!string.IsNullOrEmpty(text))
{
CustomInventorySlot slotByName = GetSlotByName(resourceUI, text);
if (slotByName != null && slotByName.Stack > 0)
{
return UsePriorityItem(__instance, user, slotByName, ref __result);
}
string text3 = (ResourceUI.PrioritizedItemForCooking = resourceUI.FindFirstValidItemForStation(__instance));
if (!string.IsNullOrEmpty(text3))
{
Player localPlayer2 = Player.m_localPlayer;
if (localPlayer2 != null)
{
((Character)localPlayer2).Message((MessageType)1, "Switched to: " + resourceUI.GetLocalizedName(text3), 0, (Sprite)null);
}
resourceUI.OnResourcesChanged();
slotByName = GetSlotByName(resourceUI, text3);
if (slotByName != null && slotByName.Stack > 0)
{
return UsePriorityItem(__instance, user, slotByName, ref __result);
}
}
}
return true;
}
private static CustomInventorySlot GetSlotByName(ResourceUI ui, string sharedName)
{
foreach (CustomInventorySlot inventorySlot in ui.inventorySlots)
{
if (inventorySlot.SharedName == sharedName)
{
return inventorySlot;
}
}
return null;
}
private static bool UsePriorityItem(CookingStation __instance, Humanoid user, CustomInventorySlot slot, ref bool __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null)
{
return true;
}
if (__instance.m_requireFire && !Traverse.Create((object)__instance).Method("IsFireLit", Array.Empty<object>()).GetValue<bool>())
{
((Character)user).Message((MessageType)2, "$msg_needfire", 0, (Sprite)null);
__result = false;
return false;
}
int value = Traverse.Create((object)__instance).Method("GetFreeSlot", Array.Empty<object>()).GetValue<int>();
if (value == -1)
{
((Character)user).Message((MessageType)2, "$msg_nocookroom", 0, (Sprite)null);
__result = false;
return false;
}
slot.Stack--;
if (slot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(slot);
}
string text = slot.PrefabName;
if (string.IsNullOrEmpty(text))
{
GameObject prefabBySharedNamePublic = resourceUI.GetPrefabBySharedNamePublic(slot.SharedName);
if ((Object)(object)prefabBySharedNamePublic != (Object)null)
{
text = ((Object)prefabBySharedNamePublic).name;
}
}
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
if (!value2.HasOwner())
{
value2.ClaimOwnership();
}
value2.InvokeRPC("RPC_AddItem", new object[1] { text });
}
resourceUI.OnResourcesChanged();
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).RaiseSkill((SkillType)105, 0.4f);
}
__result = true;
return false;
}
}
[HarmonyPatch(typeof(CookingStation), "Interact")]
internal static class CookingStation_Interact_AutoPriority_Patch
{
private static bool Prefix(CookingStation __instance, Humanoid user, bool hold, bool alt, ref bool __result)
{
if ((Object)(object)__instance.m_addFoodSwitch != (Object)null)
{
return true;
}
if (hold || alt)
{
return true;
}
if (Traverse.Create((object)__instance).Method("HaveDoneItem", Array.Empty<object>()).GetValue<bool>())
{
return true;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
string text = ResourceUI.PrioritizedItemForCooking;
bool flag = false;
if (!string.IsNullOrEmpty(text))
{
flag = resourceUI.IsItemValidForStation(text, __instance);
}
if (!flag)
{
string text2 = (ResourceUI.PrioritizedItemForCooking = resourceUI.FindFirstValidItemForStation(__instance));
text = text2;
if (!string.IsNullOrEmpty(text2))
{
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).Message((MessageType)1, "Auto-prioritized: " + resourceUI.GetLocalizedName(text2), 0, (Sprite)null);
}
resourceUI.OnResourcesChanged();
}
}
if (!string.IsNullOrEmpty(text))
{
CustomInventorySlot slotByName = GetSlotByName(resourceUI, text);
if (slotByName != null && slotByName.Stack > 0)
{
return UsePriorityItem(__instance, user, slotByName, ref __result);
}
string text3 = (ResourceUI.PrioritizedItemForCooking = resourceUI.FindFirstValidItemForStation(__instance));
if (!string.IsNullOrEmpty(text3))
{
Player localPlayer2 = Player.m_localPlayer;
if (localPlayer2 != null)
{
((Character)localPlayer2).Message((MessageType)1, "Switched to: " + resourceUI.GetLocalizedName(text3), 0, (Sprite)null);
}
resourceUI.OnResourcesChanged();
slotByName = GetSlotByName(resourceUI, text3);
if (slotByName != null && slotByName.Stack > 0)
{
return UsePriorityItem(__instance, user, slotByName, ref __result);
}
}
}
return true;
}
private static CustomInventorySlot GetSlotByName(ResourceUI ui, string sharedName)
{
foreach (CustomInventorySlot inventorySlot in ui.inventorySlots)
{
if (inventorySlot.SharedName == sharedName)
{
return inventorySlot;
}
}
return null;
}
private static bool UsePriorityItem(CookingStation __instance, Humanoid user, CustomInventorySlot slot, ref bool __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null)
{
return true;
}
if (__instance.m_requireFire && !Traverse.Create((object)__instance).Method("IsFireLit", Array.Empty<object>()).GetValue<bool>())
{
((Character)user).Message((MessageType)2, "$msg_needfire", 0, (Sprite)null);
__result = false;
return false;
}
int value = Traverse.Create((object)__instance).Method("GetFreeSlot", Array.Empty<object>()).GetValue<int>();
if (value == -1)
{
((Character)user).Message((MessageType)2, "$msg_nocookroom", 0, (Sprite)null);
__result = false;
return false;
}
slot.Stack--;
if (slot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(slot);
}
string text = slot.PrefabName;
if (string.IsNullOrEmpty(text))
{
GameObject prefabBySharedNamePublic = resourceUI.GetPrefabBySharedNamePublic(slot.SharedName);
if ((Object)(object)prefabBySharedNamePublic != (Object)null)
{
text = ((Object)prefabBySharedNamePublic).name;
}
}
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
if (!value2.HasOwner())
{
value2.ClaimOwnership();
}
value2.InvokeRPC("RPC_AddItem", new object[1] { text });
}
resourceUI.OnResourcesChanged();
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).RaiseSkill((SkillType)105, 0.4f);
}
__result = true;
return false;
}
}
[HarmonyPatch(typeof(CookingStation), "OnInteract")]
internal static class CookingStation_OnInteract_Priority_Patch
{
private static bool Prefix(CookingStation __instance, Humanoid user, ref bool __result)
{
if (!Input.GetKey((KeyCode)114))
{
return true;
}
ItemData hoveredItem = GetHoveredItem();
if (hoveredItem != null && IsItemAllowed(__instance, hoveredItem))
{
if (__instance.m_requireFire && !Traverse.Create((object)__instance).Method("IsFireLit", Array.Empty<object>()).GetValue<bool>())
{
((Character)user).Message((MessageType)2, "$msg_needfire", 0, (Sprite)null);
__result = false;
return false;
}
int value = Traverse.Create((object)__instance).Method("GetFreeSlot", Array.Empty<object>()).GetValue<int>();
if (value == -1)
{
((Character)user).Message((MessageType)2, "$msg_nocookroom", 0, (Sprite)null);
__result = false;
return false;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (user.GetInventory().HaveItem(hoveredItem.m_shared.m_name, true))
{
return true;
}
if (resourceUI != null && resourceUI.inventorySlots != null)
{
CustomInventorySlot customInventorySlot = CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, hoveredItem.m_shared.m_name);
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
string name = ((Object)hoveredItem.m_dropPrefab).name;
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
if (!value2.HasOwner())
{
value2.ClaimOwnership();
}
value2.InvokeRPC("RPC_AddItem", new object[1] { name });
}
resourceUI.OnResourcesChanged();
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).RaiseSkill((SkillType)105, 0.4f);
}
__result = true;
return false;
}
}
}
return true;
}
private static ItemData GetHoveredItem()
{
if ((Object)(object)InventoryGui.instance == (Object)null)
{
return null;
}
InventoryGrid playerGrid = InventoryGui.instance.m_playerGrid;
if ((Object)(object)playerGrid != (Object)null)
{
ItemData hoveredItemFromGrid = GetHoveredItemFromGrid(playerGrid);
if (hoveredItemFromGrid != null)
{
return hoveredItemFromGrid;
}
}
return null;
}
private static ItemData GetHoveredItemFromGrid(InventoryGrid grid)
{
//IL_005f: 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_0069: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
IList value = Traverse.Create((object)grid).Field("m_elements").GetValue<IList>();
if (value != null)
{
foreach (object item in value)
{
GameObject value2 = Traverse.Create(item).Field("m_go").GetValue<GameObject>();
Transform transform = value2.transform;
RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
Vector2 val2 = Vector2.op_Implicit(((Transform)val).InverseTransformPoint(Input.mousePosition));
Rect rect = val.rect;
if (((Rect)(ref rect)).Contains(val2))
{
Vector2i value3 = Traverse.Create((object)grid).Method("GetButtonPos", new Type[1] { typeof(GameObject) }, (object[])null).GetValue<Vector2i>(new object[1] { value2 });
Inventory inventory = grid.GetInventory();
return (inventory != null) ? inventory.GetItemAt(value3.x, value3.y) : null;
}
}
}
return null;
}
private static bool IsItemAllowed(CookingStation station, ItemData item)
{
string name = ((Object)item.m_dropPrefab).name;
return Traverse.Create((object)station).Method("IsItemAllowed", new Type[1] { typeof(string) }, (object[])null).GetValue<bool>(new object[1] { name });
}
}
[HarmonyPatch(typeof(CookingStation), "OnAddFuelSwitch")]
internal static class CookingStation_OnAddFuelSwitch_Patch
{
private static bool Prefix(CookingStation __instance, Switch sw, Humanoid user, ItemData item, ref bool __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
if (item != null && item.m_shared.m_name != name)
{
((Character)user).Message((MessageType)2, "$msg_wrongitem", 0, (Sprite)null);
__result = false;
return false;
}
float value = Traverse.Create((object)__instance).Method("GetFuel", Array.Empty<object>()).GetValue<float>();
if (value > (float)(__instance.m_maxFuel - 1))
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
__result = false;
return false;
}
if (user.GetInventory().HaveItem(name, true))
{
return true;
}
CustomInventorySlot customInventorySlot = CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, name);
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
((Character)user).Message((MessageType)2, "$msg_added " + name, 0, (Sprite)null);
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
value2.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
((Character)user).Message((MessageType)2, "$msg_donthaveany " + name, 0, (Sprite)null);
__result = false;
return false;
}
}
[HarmonyPatch(typeof(CookingStation), "TryGetItems")]
internal static class CookingStation_TryGetItems_Patch
{
private static void Postfix(CookingStation __instance, Player player, Switch switchRef, ref List<string> items)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return;
}
if ((Object)(object)switchRef == (Object)null || (Object)(object)switchRef == (Object)(object)__instance.m_addFoodSwitch)
{
foreach (ItemConversion item in __instance.m_conversion)
{
if (!((Object)(object)item.m_from == (Object)null))
{
string name = item.m_from.m_itemData.m_shared.m_name;
if (CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, name) != null && !items.Contains(name))
{
items.Add(name);
}
}
}
return;
}
if ((Object)(object)switchRef == (Object)(object)__instance.m_addFuelSwitch)
{
string name2 = __instance.m_fuelItem.m_itemData.m_shared.m_name;
if (CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, name2) != null && !items.Contains(name2))
{
items.Add(name2);
}
}
}
}
[HarmonyPatch(typeof(CookingStation), "CanUseItems")]
internal static class CookingStation_CanUseItems_Patch
{
private static void Postfix(CookingStation __instance, Player player, Switch switchRef, bool sendErrorMessage, ref bool __result)
{
if (__result)
{
return;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return;
}
if ((Object)(object)switchRef == (Object)null || (Object)(object)switchRef == (Object)(object)__instance.m_addFoodSwitch)
{
if (__instance.m_requireFire && !Traverse.Create((object)__instance).Method("IsFireLit", Array.Empty<object>()).GetValue<bool>())
{
__result = false;
return;
}
int value = Traverse.Create((object)__instance).Method("GetFreeSlot", Array.Empty<object>()).GetValue<int>();
if (value != -1)
{
foreach (ItemConversion item in __instance.m_conversion)
{
if (!((Object)(object)item.m_from == (Object)null) && CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, item.m_from.m_itemData.m_shared.m_name) != null)
{
__result = true;
break;
}
}
return;
}
__result = false;
}
else if ((Object)(object)switchRef == (Object)(object)__instance.m_addFuelSwitch)
{
float value2 = Traverse.Create((object)__instance).Method("GetFuel", Array.Empty<object>()).GetValue<float>();
if (value2 > (float)(__instance.m_maxFuel - 1))
{
__result = false;
}
else if (CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, __instance.m_fuelItem.m_itemData.m_shared.m_name) != null)
{
__result = true;
}
}
}
}
[HarmonyPatch(typeof(CookingStation), "RPC_RemoveDoneItem")]
internal static class CookingStation_RPC_RemoveDoneItem_Patch
{
private static bool Prefix(CookingStation __instance, long sender, Vector3 userPoint, int amount)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || !resourceUI.IsInitialized)
{
return true;
}
ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
Transform[] value2 = Traverse.Create((object)__instance).Field("m_slots").GetValue<Transform[]>();
if ((Object)(object)value == (Object)null || value2 == null)
{
return true;
}
for (int i = 0; i < value2.Length; i++)
{
string @string = value.GetZDO().GetString("slot" + i, "");
if (string.IsNullOrEmpty(@string) || !IsItemDone(__instance, @string))
{
continue;
}
ItemConversion itemConversion = GetItemConversion(__instance, @string);
if (itemConversion == null || !((Object)(object)itemConversion.m_to != (Object)null))
{
break;
}
ItemData val = itemConversion.m_to.m_itemData.Clone();
val.m_stack = amount;
resourceUI.AddItemFromPickup(val);
try
{
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
Player.m_localPlayer.AddKnownItem(val);
}
}
catch (Exception ex)
{
Debug.LogWarning((object)("[CookingStation] AddKnownItem failed: " + ex.Message));
}
value.GetZDO().Set("slot" + i, "");
value.GetZDO().Set("slot" + i, 0f);
value.GetZDO().Set("slotstatus" + i, 0);
value.InvokeRPC(ZNetView.Everybody, "RPC_SetSlotVisual", new object[2] { i, "" });
resourceUI.OnResourcesChanged();
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).Message((MessageType)1, $"Picked up: {val.m_shared.m_name} x{amount}", 0, (Sprite)null);
}
return false;
}
return true;
}
private static bool IsItemDone(CookingStation station, string itemName)
{
ItemDrop overCookedItem = station.m_overCookedItem;
string text = ((overCookedItem != null) ? ((Object)overCookedItem).name : null);
if (itemName == text)
{
return true;
}
ItemConversion itemConversion = GetItemConversion(station, itemName);
if (itemConversion == null)
{
return false;
}
return itemName == ((Object)itemConversion.m_to).name;
}
private static ItemConversion GetItemConversion(CookingStation station, string itemName)
{
foreach (ItemConversion item in station.m_conversion)
{
ItemDrop from = item.m_from;
object obj;
if (from == null)
{
obj = null;
}
else
{
GameObject gameObject = ((Component)from).gameObject;
obj = ((gameObject != null) ? ((Object)gameObject).name : null);
}
if (!((string?)obj == itemName))
{
ItemDrop to = item.m_to;
object obj2;
if (to == null)
{
obj2 = null;
}
else
{
GameObject gameObject2 = ((Component)to).gameObject;
obj2 = ((gameObject2 != null) ? ((Object)gameObject2).name : null);
}
if (!((string?)obj2 == itemName))
{
continue;
}
}
return item;
}
return null;
}
}
internal static class CookingStationPatchesHelper
{
public static CustomInventorySlot FindSlotBySharedName(ResourceUI ui, string sharedName)
{
foreach (CustomInventorySlot inventorySlot in ui.inventorySlots)
{
if (inventorySlot.SharedName == sharedName && inventorySlot.Quality <= 1 && inventorySlot.Stack > 0)
{
return inventorySlot;
}
}
return null;
}
}
[HarmonyPatch(typeof(Fermenter), "Interact")]
internal static class Fermenter_Interact_Patch
{
private static bool Prefix(Fermenter __instance, Humanoid user, bool hold, bool alt, ref bool __result)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
if (hold)
{
return true;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
Traverse.Create((object)__instance).Method("UpdateCover", new Type[2]
{
typeof(float),
typeof(bool)
}, (object[])null).GetValue(new object[2] { 0f, true });
if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
{
__result = true;
return false;
}
switch (Traverse.Create((object)__instance).Method("GetStatus", Array.Empty<object>()).GetValue<int>())
{
case 0:
{
bool value = Traverse.Create((object)__instance).Field("m_hasRoof").GetValue<bool>();
bool value2 = Traverse.Create((object)__instance).Field("m_exposed").GetValue<bool>();
if (!value)
{
((Character)user).Message((MessageType)2, "$piece_fermenter_needroof", 0, (Sprite)null);
__result = false;
return false;
}
if (value2)
{
((Character)user).Message((MessageType)2, "$piece_fermenter_exposed", 0, (Sprite)null);
__result = false;
return false;
}
Inventory inventory = user.GetInventory();
ItemData value3 = Traverse.Create((object)__instance).Method("FindCookableItem", new Type[1] { typeof(Inventory) }, (object[])null).GetValue<ItemData>(new object[1] { inventory });
if (value3 != null)
{
return true;
}
foreach (ItemConversion item in __instance.m_conversion)
{
if ((Object)(object)item.m_from == (Object)null)
{
continue;
}
string name = item.m_from.m_itemData.m_shared.m_name;
CustomInventorySlot customInventorySlot = FermenterStationPatchesHelper.FindSlotBySharedName(resourceUI, name);
if (customInventorySlot == null || customInventorySlot.Stack <= 0)
{
continue;
}
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
string name2 = ((Object)((Component)item.m_from).gameObject).name;
ZNetView value4 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value4 != (Object)null)
{
value4.InvokeRPC("RPC_AddItem", new object[1] { name2 });
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
((Character)user).Message((MessageType)2, "$msg_noprocessableitems", 0, (Sprite)null);
__result = false;
return false;
}
case 3:
return true;
default:
return true;
}
}
}
[HarmonyPatch(typeof(Fermenter), "UseItem")]
internal static class Fermenter_UseItem_Patch
{
private static bool Prefix(Fermenter __instance, Humanoid user, ItemData item, ref bool __result)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
{
__result = false;
return false;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
if (Traverse.Create((object)__instance).Method("GetStatus", Array.Empty<object>()).GetValue<int>() != 0)
{
__result = false;
return false;
}
string name = ((Object)item.m_dropPrefab).name;
if (!Traverse.Create((object)__instance).Method("IsItemAllowed", new Type[1] { typeof(string) }, (object[])null).GetValue<bool>(new object[1] { name }))
{
__result = false;
return false;
}
if (user.GetInventory().HaveItem(item.m_shared.m_name, true))
{
return true;
}
CustomInventorySlot customInventorySlot = CookingStationPatchesHelper.FindSlotBySharedName(resourceUI, item.m_shared.m_name);
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value != (Object)null)
{
value.InvokeRPC("RPC_AddItem", new object[1] { name });
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
__result = false;
return false;
}
}
internal static class FermenterStationPatchesHelper
{
public static CustomInventorySlot FindSlotBySharedName(ResourceUI ui, string sharedName)
{
foreach (CustomInventorySlot inventorySlot in ui.inventorySlots)
{
if (inventorySlot.SharedName == sharedName && inventorySlot.Quality <= 1 && inventorySlot.Stack > 0)
{
return inventorySlot;
}
}
return null;
}
}
[HarmonyPatch(typeof(Fireplace), "Interact")]
internal static class Fireplace_Interact_Patch
{
private static bool Prefix(Fireplace __instance, Humanoid user, bool hold, bool alt)
{
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
if (hold || alt)
{
return true;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
if (!__instance.m_canRefill)
{
return true;
}
ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value == (Object)null)
{
return true;
}
float @float = value.GetZDO().GetFloat(ZDOVars.s_fuel, 0f);
if ((float)Mathf.CeilToInt(@float) >= __instance.m_maxFuel)
{
return true;
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
Inventory inventory = user.GetInventory();
if (inventory.HaveItem(name, true))
{
return true;
}
CustomInventorySlot customInventorySlot = null;
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (inventorySlot.SharedName == name && inventorySlot.Quality <= 1)
{
customInventorySlot = inventorySlot;
break;
}
}
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
value.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
__instance.m_fuelAddedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1);
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_fireadding", new string[1] { __instance.m_fuelItem.m_itemData.m_shared.m_name }), 0, (Sprite)null);
resourceUI.OnResourcesChanged();
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Fireplace), "UseItem")]
internal static class Fireplace_UseItem_Patch
{
private static bool Prefix(Fireplace __instance, Humanoid user, ItemData item, ref bool __result)
{
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_045f: Unknown result type (might be due to invalid IL or missing references)
//IL_0464: Unknown result type (might be due to invalid IL or missing references)
//IL_0466: Unknown result type (might be due to invalid IL or missing references)
//IL_0473: Unknown result type (might be due to invalid IL or missing references)
//IL_0478: Unknown result type (might be due to invalid IL or missing references)
//IL_0493: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: Unknown result type (might be due to invalid IL or missing references)
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (item.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name && !__instance.m_infiniteFuel)
{
ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value == (Object)null)
{
return true;
}
if ((float)Mathf.CeilToInt(value.GetZDO().GetFloat(ZDOVars.s_fuel, 0f)) >= __instance.m_maxFuel)
{
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_cantaddmore", new string[1] { item.m_shared.m_name }), 0, (Sprite)null);
__result = true;
return false;
}
if (user.GetInventory().HaveItem(item.m_shared.m_name, true))
{
return true;
}
if (resourceUI != null && resourceUI.inventorySlots != null)
{
CustomInventorySlot customInventorySlot = null;
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (inventorySlot.SharedName == item.m_shared.m_name && inventorySlot.Quality <= 1)
{
customInventorySlot = inventorySlot;
break;
}
}
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
value.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_fireadding", new string[1] { item.m_shared.m_name }), 0, (Sprite)null);
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
}
}
for (int i = 0; i < __instance.m_fireworkItemList.Length; i++)
{
FireworkItem val = __instance.m_fireworkItemList[i];
if (!(item.m_shared.m_name == val.m_fireworkItem.m_itemData.m_shared.m_name))
{
continue;
}
if (!__instance.IsBurning())
{
((Character)user).Message((MessageType)2, "$msg_firenotburning", 0, (Sprite)null);
__result = true;
return false;
}
string name = val.m_fireworkItem.m_itemData.m_shared.m_name;
int num = user.GetInventory().CountItems(name, -1, true);
int num2 = 0;
CustomInventorySlot customInventorySlot2 = null;
if (resourceUI != null && resourceUI.inventorySlots != null)
{
foreach (CustomInventorySlot inventorySlot2 in resourceUI.inventorySlots)
{
if (inventorySlot2.SharedName == name)
{
customInventorySlot2 = inventorySlot2;
num2 = inventorySlot2.Stack;
break;
}
}
}
int num3 = num + num2;
if (num3 < val.m_fireworkItemCount)
{
((Character)user).Message((MessageType)2, "$msg_toofew " + name, 0, (Sprite)null);
__result = true;
return false;
}
int num4 = val.m_fireworkItemCount;
if (num > 0)
{
int num5 = Mathf.Min(num, num4);
user.GetInventory().RemoveItem(item.m_shared.m_name, num5, -1, true);
num4 -= num5;
}
if (num4 > 0 && customInventorySlot2 != null)
{
customInventorySlot2.Stack -= num4;
if (customInventorySlot2.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot2);
}
resourceUI.OnResourcesChanged();
}
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_throwinfire", new string[1] { item.m_shared.m_name }), 0, (Sprite)null);
float num6 = Random.Range(0f - __instance.m_fireworksMaxRandomAngle, __instance.m_fireworksMaxRandomAngle);
float num7 = Random.Range(0f - __instance.m_fireworksMaxRandomAngle, __instance.m_fireworksMaxRandomAngle);
Quaternion val2 = Quaternion.Euler(num6, 0f, num7);
val.m_fireworksEffects.Create(((Component)__instance).transform.position, val2, (Transform)null, 1f, -1);
__instance.m_fuelAddedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1);
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Fireplace), "TryGetItems")]
internal static class Fireplace_TryGetItems_Patch
{
private static void Postfix(Fireplace __instance, Player player, ref List<string> items)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null || __instance.m_infiniteFuel)
{
return;
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (inventorySlot.SharedName == name && inventorySlot.Stack > 0)
{
if (!items.Contains(name))
{
items.Add(name);
}
break;
}
}
}
}
[HarmonyPatch(typeof(Fireplace), "CanUseItems")]
internal static class Fireplace_CanUseItems_Patch
{
private static void Postfix(Fireplace __instance, Player player, bool sendErrorMessage, ref bool __result)
{
if (__result)
{
return;
}
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return;
}
if (__instance.m_infiniteFuel)
{
__result = false;
return;
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (!(inventorySlot.SharedName == name) || inventorySlot.Stack <= 0)
{
continue;
}
ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value == (Object)null)
{
break;
}
if ((float)Mathf.CeilToInt(value.GetZDO().GetFloat(ZDOVars.s_fuel, 0f)) >= __instance.m_maxFuel)
{
if (sendErrorMessage)
{
((Character)player).Message((MessageType)2, Localization.instance.Localize("$msg_cantaddmore", new string[1] { __instance.m_fuelItem.m_itemData.m_shared.m_name }), 0, (Sprite)null);
}
__result = false;
}
else
{
__result = true;
}
break;
}
}
}
[HarmonyPatch(typeof(Smelter), "OnAddOre")]
internal static class Smelter_OnAddOre_Patch
{
private static bool Prefix(Smelter __instance, Switch sw, Humanoid user, ItemData item, ref bool __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
int value = Traverse.Create((object)__instance).Method("GetQueueSize", Array.Empty<object>()).GetValue<int>();
if (value >= __instance.m_maxOre)
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
__result = false;
return false;
}
if (item != null)
{
string name = ((Object)item.m_dropPrefab).name;
if (!Traverse.Create((object)__instance).Method("IsItemAllowed", new Type[1] { typeof(string) }, (object[])null).GetValue<bool>(new object[1] { name }))
{
((Character)user).Message((MessageType)2, "$msg_wontwork", 0, (Sprite)null);
__result = false;
return false;
}
if (user.GetInventory().HaveItem(item.m_shared.m_name, true))
{
return true;
}
CustomInventorySlot customInventorySlot = SmelterStationPatchesHelper.FindSlotBySharedName(resourceUI, item.m_shared.m_name);
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
((Character)user).Message((MessageType)2, "$msg_added " + item.m_shared.m_name, 0, (Sprite)null);
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
if (!value2.IsOwner())
{
value2.ClaimOwnership();
}
value2.InvokeRPC("RPC_AddOre", new object[1] { name });
}
Traverse.Create((object)__instance).Field("m_addedOreTime").SetValue((object)Time.time);
if (__instance.m_addOreAnimationDuration > 0f)
{
SetAnimation(__instance, active: true);
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
((Character)user).Message((MessageType)2, "$msg_donthaveany " + item.m_shared.m_name, 0, (Sprite)null);
__result = false;
return false;
}
Inventory inventory = user.GetInventory();
foreach (ItemConversion item2 in __instance.m_conversion)
{
if (!((Object)(object)item2.m_from == (Object)null))
{
string name2 = item2.m_from.m_itemData.m_shared.m_name;
if (inventory.HaveItem(name2, true))
{
return true;
}
}
}
foreach (ItemConversion item3 in __instance.m_conversion)
{
if ((Object)(object)item3.m_from == (Object)null)
{
continue;
}
string name3 = item3.m_from.m_itemData.m_shared.m_name;
string name4 = ((Object)((Component)item3.m_from).gameObject).name;
CustomInventorySlot customInventorySlot2 = SmelterStationPatchesHelper.FindSlotBySharedName(resourceUI, name3);
if (customInventorySlot2 == null || customInventorySlot2.Stack <= 0)
{
continue;
}
customInventorySlot2.Stack--;
if (customInventorySlot2.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot2);
}
((Character)user).Message((MessageType)2, "$msg_added " + name3, 0, (Sprite)null);
ZNetView value3 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value3 != (Object)null)
{
if (!value3.IsOwner())
{
value3.ClaimOwnership();
}
value3.InvokeRPC("RPC_AddOre", new object[1] { name4 });
}
Traverse.Create((object)__instance).Field("m_addedOreTime").SetValue((object)Time.time);
if (__instance.m_addOreAnimationDuration > 0f)
{
SetAnimation(__instance, active: true);
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
((Character)user).Message((MessageType)2, "$msg_noprocessableitems", 0, (Sprite)null);
__result = false;
return false;
}
private static void SetAnimation(Smelter smelter, bool active)
{
Animator[] animators = smelter.m_animators;
foreach (Animator val in animators)
{
if (((Component)val).gameObject.activeInHierarchy)
{
val.SetBool("active", active);
val.SetFloat("activef", active ? 1f : 0f);
}
}
}
}
[HarmonyPatch(typeof(Smelter), "OnAddFuel")]
internal static class Smelter_OnAddFuel_Patch
{
private static bool Prefix(Smelter __instance, Switch sw, Humanoid user, ItemData item, ref bool __result)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null)
{
return true;
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
if (item != null && item.m_shared.m_name != name)
{
((Character)user).Message((MessageType)2, "$msg_wrongitem", 0, (Sprite)null);
__result = false;
return false;
}
float value = Traverse.Create((object)__instance).Method("GetFuel", Array.Empty<object>()).GetValue<float>();
if (value > (float)(__instance.m_maxFuel - 1))
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
__result = false;
return false;
}
if (user.GetInventory().HaveItem(name, true))
{
return true;
}
CustomInventorySlot customInventorySlot = SmelterStationPatchesHelper.FindSlotBySharedName(resourceUI, name);
if (customInventorySlot != null && customInventorySlot.Stack > 0)
{
customInventorySlot.Stack--;
if (customInventorySlot.Stack <= 0)
{
resourceUI.inventorySlots.Remove(customInventorySlot);
}
((Character)user).Message((MessageType)2, "$msg_added " + name, 0, (Sprite)null);
ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value2 != (Object)null)
{
if (!value2.IsOwner())
{
value2.ClaimOwnership();
}
value2.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
}
resourceUI.OnResourcesChanged();
__result = true;
return false;
}
((Character)user).Message((MessageType)2, "$msg_donthaveany " + name, 0, (Sprite)null);
__result = false;
return false;
}
}
[HarmonyPatch(typeof(Smelter), "RPC_AddOre")]
internal static class Smelter_RPC_AddOre_Patch
{
private static void Prefix(Smelter __instance, long sender, string name)
{
}
private static void Postfix(Smelter __instance, long sender, string name)
{
int value = Traverse.Create((object)__instance).Method("GetQueueSize", Array.Empty<object>()).GetValue<int>();
}
}
internal static class SmelterStationPatchesHelper
{
public static CustomInventorySlot FindSlotBySharedName(ResourceUI ui, string sharedName)
{
foreach (CustomInventorySlot inventorySlot in ui.inventorySlots)
{
if (inventorySlot.SharedName == sharedName && inventorySlot.Quality <= 1 && inventorySlot.Stack > 0)
{
return inventorySlot;
}
}
return null;
}
}
[HarmonyPatch(typeof(InventoryGui))]
public class InventoryGuiPatch
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static UnityAction <>9__2_0;
internal void <CreateResourceButton>b__2_0()
{
ResourceInventoryMod.ResourceUI?.Toggle();
}
}
private static GameObject resourceButton;
[HarmonyPatch("Awake")]
[HarmonyPostfix]
public static void PostfixAwake(InventoryGui __instance)
{
CreateResourceButton(__instance);
}
private static void CreateResourceButton(InventoryGui inventoryGui)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: 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_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: 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_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Expected O, but got Unknown
Transform val = ((Component)inventoryGui).transform.Find("root");
if ((Object)(object)val == (Object)null)
{
return;
}
Transform val2 = val.Find("Player");
if ((Object)(object)val2 == (Object)null)
{
return;
}
resourceButton = new GameObject("ResourceButton", new Type[1] { typeof(RectTransform) });
resourceButton.transform.SetParent(val2, false);
RectTransform component = resourceButton.GetComponent<RectTransform>();
Image val3 = resourceButton.AddComponent<Image>();
Button val4 = resourceButton.AddComponent<Button>();
component.anchorMin = new Vector2(0.5f, 0f);
component.anchorMax = new Vector2(0.5f, 0f);
component.pivot = new Vector2(2f, 1.5f);
component.sizeDelta = new Vector2(120f, 35f);
component.anchoredPosition = new Vector2(0f, 0f);
val3.sprite = GUIManager.Instance.GetSprite("button");
val3.type = (Type)1;
((Graphic)val3).color = Color.white;
((Selectable)val4).transition = (Transition)1;
ColorBlock colors = ((Selectable)val4).colors;
((ColorBlock)(ref colors)).normalColor = Color.white;
((ColorBlock)(ref colors)).highlightedColor = new Color(0.95f, 0.95f, 0.95f, 1f);
((ColorBlock)(ref colors)).pressedColor = new Color(0.85f, 0.85f, 0.85f, 1f);
((ColorBlock)(ref colors)).selectedColor = GUIManager.Instance.ValheimOrange;
((Selectable)val4).colors = colors;
TextMeshProUGUI val5 = ResourceTMPHelper.CreateText("Text", resourceButton.transform);
RectTransform rectTransform = ((TMP_Text)val5).rectTransform;
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
((TMP_Text)val5).text = "Items";
((TMP_Text)val5).fontSize = 16f;
((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
((Graphic)val5).color = Color.white;
((TMP_Text)val5).enableWordWrapping = false;
((Graphic)val5).raycastTarget = false;
resourceButton.AddComponent<DragWindowCntrl>();
ButtonClickedEvent onClick = val4.onClick;
object obj = <>c.<>9__2_0;
if (obj == null)
{
UnityAction val6 = delegate
{
ResourceInventoryMod.ResourceUI?.Toggle();
};
<>c.<>9__2_0 = val6;
obj = (object)val6;
}
((UnityEvent)onClick).AddListener((UnityAction)obj);
resourceButton.SetActive(false);
}
[HarmonyPatch("Show")]
[HarmonyPostfix]
public static void PostfixShow(InventoryGui __instance, Container container, int activeGroup)
{
if ((Object)(object)resourceButton != (Object)null)
{
resourceButton.SetActive(true);
resourceButton.transform.SetAsLastSibling();
}
if (ResourceInventoryMod.AutoShowWithInventory.Value)
{
ResourceInventoryMod.ResourceUI?.Show();
}
}
[HarmonyPatch("Hide")]
[HarmonyPostfix]
public static void PostfixHide()
{
if ((Object)(object)resourceButton != (Object)null)
{
resourceButton.SetActive(false);
}
ResourceInventoryMod.ResourceUI?.Hide();
}
}
[HarmonyPatch(typeof(InventoryGui), "Hide")]
internal static class InventoryGui_Hide_Patch
{
private static bool Prefix(InventoryGui __instance)
{
if (ResourceUI.Instance != null && ResourceUI.Instance.IsVisible() && ResourceUI.Instance.IsSearchFieldFocused())
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
internal static class InventoryGui_Update_Patch
{
private static void Postfix(InventoryGui __instance)
{
if (ResourceUI.Instance != null && ResourceUI.Instance.IsVisible() && ResourceUI.Instance.IsSearchFieldFocused() && !Input.GetKeyDown((KeyCode)101))
{
}
}
}
[HarmonyPatch(typeof(TMP_InputField), "KeyPressed")]
internal static class TMP_InputField_KeyPressed_Patch
{
private static bool Prefix(TMP_InputField __instance, Event evt)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Invalid comparison between Unknown and I4
if (ResourceUI.Instance != null && ResourceUI.Instance.IsSearchFieldFocused() && (Object)(object)__instance == (Object)(object)ResourceUI.Instance.GetSearchInputField() && (int)evt.keyCode == 101)
{
return true;
}
return true;
}
}
[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[]
{
typeof(string),
typeof(int),
typeof(int),
typeof(bool)
})]
internal static class Inventory_RemoveItem_CustomResourcesPatch
{
private static void Prefix(Inventory __instance, string name, ref int amount, int itemQuality, bool worldLevelBased)
{
ResourceUI resourceUI = ResourceInventoryMod.ResourceUI;
if (resourceUI == null || resourceUI.inventorySlots == null || string.IsNullOrEmpty(name))
{
return;
}
int num = 0;
List<CustomInventorySlot> list = new List<CustomInventorySlot>();
foreach (CustomInventorySlot inventorySlot in resourceUI.inventorySlots)
{
if (inventorySlot.SharedName == name && inventorySlot.Quality <= 1 && !inventorySlot.IsUnique)
{
num += inventorySlot.Stack;
list.Add(inventorySlot);
}
}
if (num <= 0)
{
return;
}
int num2 = __instance.CountItems(name, itemQuality, worldLevelBased);
num2 -= num;
if (num2 < 0)
{
num2 = 0;
}
if (amount <= num2)
{
return;
}
int num3 = amount - num2;
amount = num2;
int num4 = num3;
int num5 = list.Count - 1;
while (num5 >= 0 && num4 > 0)
{
CustomInventorySlot customInventorySlot = list[num5];
if (customInventorySlot.Stack <= num4)
{
num4 -= customInventorySlot.Stack;
resourceUI.inventorySlots.Remove(customInventorySlot);
}
else
{
customInventorySlot.Stack -= num4;
num4 = 0;
}
num5--;
}
resourceUI.OnResourcesChanged();
}
}
[HarmonyPatch(typeof(Humanoid), "Pickup", new Type[]
{
typeof(GameObject),
typeof(bool),
typeof(bool)
})]
public static class ItemPickupPatch
{
[HarmonyPrefix]
private static bool PrefixPickup(Humanoid __instance, GameObject go, bool autoequip, bool autoPickupDelay, ref bool __result)
{
try
{
Player val = (Player)(object)((__instance is Player) ? __instance : null);
if (val == null)
{
return true;
}
if ((Object)(object)go == (Object)null)
{
return true;
}
ItemDrop component = go.GetComponent<ItemDrop>();
if (component?.m_itemData == null)
{
return true;
}
if ((Object)(object)Player.m_localPlayer == (Object)null)
{
Debug.LogWarning((object)"[ItemPickupPatch] Player.m_localPlayer is null, using vanilla pickup");
return true;
}
if ((Object)(object)ObjectDB.instance == (Object)null)
{
Debug.LogWarning((object)"[ItemPickupPatch] ObjectDB not ready, using vanilla pickup");
return true;
}
if (ResourceInventoryMod.ResourceUI == null)
{
ResourceInventoryMod.ResourceUI = new ResourceUI();
}
ResourceInventoryMod.ResourceUI.EnsureCreated();
if (!ResourceInventoryMod.ResourceUI.IsInitialized)
{
Debug.LogWarning((object)"[ItemPickupPatch] UI not ready, using vanilla pickup");
return true;
}
ResourceInventoryMod.ResourceUI.AddItemFromPickup(component.m_itemData);
try
{
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
Player.m_localPlayer.AddKnownItem(component.m_itemData);
}
}
catch (Exception ex)
{
Debug.LogWarning((object)("[ItemPickupPatch] AddKnownItem failed: " + ex.Message));
}
DestroyGroundItemSafely(go);
try
{
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
string name = component.m_itemData.m_shared.m_name;
int quality = component.m_itemData.m_quality;
int stack = component.m_itemData.m_stack;
string text = "Picked up: " + name;
if (quality > 1)
{
text += $" [{quality}★]";
}
if (stack > 1)
{
text += $" x{stack}";
}
((Character)Player.m_localPlayer).Message((MessageType)1, text, 0, (Sprite)null);
}
}
catch
{
}
__result = true;
return false;
}
catch (Exception arg)
{
Debug.LogError((object)$"[ItemPickupPatch] Error: {arg}");
return true;
}
}
private static void DestroyGroundItemSafely(GameObject go)
{
if ((Object)(object)go == (Object)null)
{
return;
}
try
{
ZNetView component = go.GetComponent<ZNetView>();
if ((Object)(object)component != (Object)null && component.IsValid())
{
component.ClaimOwnership();
ZNetScene instance = ZNetScene.instance;
if (instance != null)
{
instance.Destroy(go);
}
}
else
{
Object.Destroy((Object)(object)go);
}
}
catch (Exception ex)
{
Debug.LogWarning((object)("[ItemPickupPatch] Failed to destroy item: " + ex.Message));
Object.Destroy((Object)(object)go);
}
}
}
public class MoveAmountDialog : MonoBehaviour
{
private RectTransform root;
private RectTransform panelRect;
private Slider amountSlider;
private TextMeshProUGUI amountValueText;
private TextMeshProUGUI maxText;
private Button confirmButton;
private Button cancelButton;
private CustomInventorySlot slot;
private string itemName;
private int maxAmount;
private ResourceUI resourceUI;
private bool isClosing;
private bool useLegacyMode = false;
public static MoveAmountDialog Current { get; private set; }
public static MoveAmountDialog Create(Transform parent, string itemName, int maxAmount, ResourceUI ui)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
if ((Object)(object)Current != (Object)null)
{
Current.Close();
}
object obj = parent;
if (obj == null)
{
GameObject customGUIFront = GUIManager.CustomGUIFront;
obj = ((customGUIFront != null) ? customGUIFront.transform : null);
}
Transform val = (Transform)obj;
if ((Object)(object)val == (Object)null)
{
return null;
}
GameObject val2 = new GameObject("MoveAmountDialog", new Type[2]
{
typeof(RectTransform),
typeof(CanvasGroup)
});
val2.transform.SetParent(val, false);
val2.transform.SetAsLastSibling();
MoveAmountDialog moveAmountDialog = val2.AddComponent<MoveAmountDialog>();
moveAmountDialog.useLegacyMode = true;
moveAmountDialog.BuildLegacy(itemName, maxAmount, ui);
Current = moveAmountDialog;
return moveAmountDialog;
}
public static MoveAmountDialog CreateForSlot(Transform parent, CustomInventorySlot slot, int maxAmount, ResourceUI ui)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
if ((Object)(object)Current != (Object)null)
{
Current.Close();
}
object obj = parent;
if (obj == null)
{
GameObject customGUIFront = GUIManager.CustomGUIFront;
obj = ((customGUIFront != null) ? customGUIFront.transform : null);
}
Transform val = (Transform)obj;
if ((Object)(object)val == (Object)null)
{
return null;
}
GameObject val2 = new GameObject("MoveAmountDialog", new Type[2]
{
typeof(RectTransform),
typeof(CanvasGroup)
});
val2.transform.SetParent(val, false);
val2.transform.SetAsLastSibling();
MoveAmountDialog moveAmountDialog = val2.AddComponent<MoveAmountDialog>();
moveAmountDialog.useLegacyMode = false;
moveAmountDialog.BuildForSlot(slot, maxAmount, ui);
Current = moveAmountDialog;
return moveAmountDialog;
}
private void BuildLegacy(string name, int max, ResourceUI ui)
{
itemName = name;
maxAmount = Mathf.Max(1, max);
resourceUI = ui;
BuildUI();
}
private void BuildForSlot(CustomInventorySlot itemSlot, int max, ResourceUI ui)
{
slot = itemSlot;
itemName = slot.SharedName;
maxAmount = Mathf.Max(1, max);
resourceUI = ui;
BuildUI();
}
private void BuildUI()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_0069: 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)
CanvasGroup component = ((Component)this).GetComponent<CanvasGroup>();
component.alpha = 1f;
component.interactable = true;
component.blocksRaycasts = true;
root = ((Component)this).GetComponent<RectTransform>();
root.anchorMin = Vector2.zero;
root.anchorMax = Vector2.one;
root.offsetMin = Vector2.zero;
root.offsetMax = Vector2.zero;
root.pivot = new Vector2(0.5f, 0.5f);
CreateOverlay();
CreateDialogPanel();
GUIManager.BlockInput(true);
}
private void CreateOverlay()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0054: 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)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
GameObject val = new GameObject("Overlay", new Type[3]
{
typeof(RectTransform),
typeof(Image),
typeof(Button)
});
val.transform.SetParent(((Component)this).transform, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
Image component2 = val.GetComponent<Image>();
((Graphic)component2).color = new Color(0f, 0f, 0f, 0.65f);
((Graphic)component2).raycastTarget = true;
Button component3 = val.GetComponent<Button>();
((Selectable)component3).transition = (Transition)0;
((UnityEvent)component3.onClick).AddListener(new UnityAction(Close));
}
private void CreateDialogPanel()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0067: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Panel", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val.transform.SetParent(((Component)this).transform, false);
val.transform.SetAsLastSibling();
panelRect = val.GetComponent<RectTransform>();
panelRect.anchorMin = new Vector2(0.5f, 0.5f);
panelRect.anchorMax = new Vector2(0.5f, 0.5f);
panelRect.pivot = new Vector2(0.5f, 0.5f);
panelRect.sizeDelta = new Vector2(520f, 250f);
panelRect.anchoredPosition = Vector2.zero;
Image component = val.GetComponent<Image>();
component.sprite = GUIManager.Instance.GetSprite("woodpanel_trophys");
component.type = (Type)1;
((Graphic)component).color = Color.gray;
((Graphic)component).raycastTarget = true;
Outline val2 = val.AddComponent<Outline>();
val.AddComponent<DragWindowCntrl>();
CreateTitle(val.transform);
CreateSlider(val.transform);
CreateButtons(val.transform);
}
private void CreateTitle(Transform parent)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_003f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_011e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Title", new Type[1] { typeof(RectTransform) });
val.transform.SetParent(parent, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 1f);
component.anchorMax = new Vector2(0.5f, 1f);
component.pivot = new Vector2(0.5f, 1f);
component.sizeDelta = new Vector2(300f, 40f);
component.anchoredPosition = new Vector2(0f, -20f);
TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
string text = "Quantity";
if (!useLegacyMode && slot != null && slot.Quality > 1)
{
text = $"Quantity [{slot.Quality}★]";
}
((TMP_Text)val2).text = text;
((TMP_Text)val2).font = GUIManager.Instance.TMP_AveriaSansLibre;
((TMP_Text)val2).fontSize = 26f;
((Graphic)val2).color = GUIManager.Instance.ValheimOrange;
((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
((Graphic)val2).raycastTarget = false;
}
private void CreateSlider(Transform parent)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_003f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Expected O, but got Unknown
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0322: 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: Expected O, but got Unknown
//IL_03a0: 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_03ce: Unknown result type (might be due to invalid IL or missing references)
//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0421: Unknown result type (might be due to invalid IL or missing references)
//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
//IL_04b9: Expected O, but got Unknown
//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0500: Unknown result type (might be due to invalid IL or missing references)
//IL_0530: Unknown result type (might be due to invalid IL or missing references)
//IL_0537: Expected O, but got Unknown
//IL_0557: Unknown result type (might be due to invalid IL or missing references)
//IL_0564: Unknown result type (might be due to invalid IL or missing references)
//IL_0571: Unknown result type (might be due to invalid IL or missing references)
//IL_057e: Unknown result type (might be due to invalid IL or missing references)
//IL_0599: Unknown result type (might be due to invalid IL or missing references)
//IL_05ca: Unknown result type (might be due to invalid IL or missing references)
//IL_05d1: Expected O, but got Unknown
//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
//IL_060b: Unknown result type (might be due to invalid IL or missing references)
//IL_0618: Unknown result type (might be due to invalid IL or missing references)
//IL_0648: Unknown result type (might be due to invalid IL or missing references)
//IL_064f: Expected O, but got Unknown
//IL_0679: Unknown result type (might be due to invalid IL or missing references)
//IL_0690: Unknown result type (might be due to invalid IL or missing references)
//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
//IL_06be: Unknown result type (might be due to invalid IL or missing references)
//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("ValueText", new Type[1] { typeof(RectTransform) });
val.transform.SetParent(parent, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 1f);
component.anchorMax = new Vector2(0.5f, 1f);
component.pivot = new Vector2(0.5f, 1f);
component.sizeDelta = new Vector2(100f, 40f);
component.anchoredPosition = new Vector2(0f, -120f);
amountValueText = val.AddComponent<TextMeshProUGUI>();
((TMP_Text)amountValueText).text = maxAmount.ToString();
((TMP_Text)amountValueText).font = GUIManager.Instance.TMP_AveriaSansLibre;
((TMP_Text)amountValueText).fontSize = 24f;
((Graphic)amountValueText).color = Color.white;
((TMP_Text)amountValueText).alignment = (TextAlignmentOptions)514;
((Graphic)amountValueText).raycastTarget = false;
GameObject val2 = new GameObject("MaxValueText", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(parent, false);
RectTransform component2 = val2.GetComponent<RectTransform>();
component2.anchorMin = new Vector2(1f, 1f);
component2.anchorMax = new Vector2(1f, 1f);
component2.pivot = new Vector2(1f, 1f);
component2.sizeDelta = new Vector2(60f, 30f);
component2.anchoredPosition = new Vector2(-30f, -70f);
TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)val3).text = maxAmount.ToString();
((TMP_Text)val3).font = GUIManager.Instance.TMP_AveriaSansLibre;
((TMP_Text)val3).fontSize = 20f;
((Graphic)val3).color = new Color(0.8f, 0.8f, 0.8f, 0.8f);
((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
((Graphic)val3).raycastTarget = false;
GameObject val4 = new GameObject("MinValueText", new Type[1] { typeof(RectTransform) });
val4.transform.SetParent(parent, false);
RectTransform component3 = val4.GetComponent<RectTransform>();
component3.anchorMin = new Vector2(0f, 1f);
component3.anchorMax = new Vector2(0f, 1f);
component3.pivot = new Vector2(0f, 1f);
component3.sizeDelta = new Vector2(60f, 30f);
component3.anchoredPosition = new Vector2(30f, -70f);
TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>();
((TMP_Text)val5).text = "1";
((TMP_Text)val5).font = GUIManager.Instance.TMP_AveriaSansLibre;
((TMP_Text)val5).fontSize = 20f;
((Graphic)val5).color = new Color(0.8f, 0.8f, 0.8f, 0.8f);
((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
((Graphic)val5).raycastTarget = false;
GameObject val6 = new GameObject("Slider", new Type[3]
{
typeof(RectTransform),
typeof(Slider),
typeof(Image)
});
val6.transform.SetParent(parent, false);
RectTransform component4 = val6.GetComponent<RectTransform>();
component4.anchorMin = new Vector2(0.5f, 1f);
component4.anchorMax = new Vector2(0.5f, 1f);
component4.pivot = new Vector2(0.5f, 1f);
component4.sizeDelta = new Vector2(280f, 20f);
component4.anchoredPosition = new Vector2(0f, -85f);
Image component5 = val6.GetComponent<Image>();
((Graphic)component5).color = new Color(0.2f, 0.2f, 0.25f);
amountSlider = val6.GetComponent<Slider>();
amountSlider.minValue = 1f;
amountSlider.maxValue = maxAmount;
amountSlider.wholeNumbers = true;
amountSlider.value = maxAmount;
((UnityEvent<float>)(object)amountSlider.onValueChanged).AddListener((UnityAction<float>)OnSliderValueChanged);
GameObject val7 = new GameObject("FillArea", new Type[1] { typeof(RectTransform) });
val7.transform.SetParent(val6.transform, false);
RectTransform component6 = val7.GetComponent<RectTransform>();
component6.anchorMin = Vector2.zero;
component6.anchorMax = Vector2.one;
component6.offsetMin = Vector2.zero;
component6.offsetMax = Vector2.zero;
GameObject val8 = new GameObject("Fill", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val8.transform.SetParent(val7.transform, false);
RectTransform component7 = val8.GetComponent<RectTransform>();
component7.anchorMin = Vector2.zero;
component7.anchorMax = Vector2.one;
component7.offsetMin = Vector2.zero;
component7.offsetMax = Vector2.zero;
Image component8 = val8.GetComponent<Image>();
((Graphic)component8).color = GUIManager.Instance.ValheimOrange;
amountSlider.fillRect = component7;
GameObject val9 = new GameObject("HandleArea", new Type[1] { typeof(RectTransform) });
val9.transform.SetParent(val6.transform, false);
RectTransform component9 = val9.GetComponent<RectTransform>();
component9.anchorMin = Vector2.zero;
component9.anchorMax = Vector2.one;
component9.offsetMin = Vector2.zero;
component9.offsetMax = Vector2.zero;
GameObject val10 = new GameObject("Handle", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val10.transform.SetParent(val9.transform, false);
RectTransform component10 = val10.GetComponent<RectTransform>();
component10.sizeDelta = new Vector2(20f, 30f);
component10.anchorMin = new Vector2(0.5f, 0.5f);
component10.anchorMax = new Vector2(0.5f, 0.5f);
component10.pivot = new Vector2(0.5f, 0.5f);
component10.anchoredPosition = Vector2.zero;
Image component11 = val10.GetComponent<Image>();
component11.sprite = GUIManager.Instance.GetSprite("UISprite");
((Graphic)component11).color = Color.white;
amountSlider.handleRect = component10;
}
private void OnSliderValueChanged(float value)
{
if ((Object)(object)amountValueText != (Object)null)
{
((TMP_Text)amountValueText).text = ((int)value).ToString();
}
}
private void CreateButtons(Transform parent)
{
//IL_0013: 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_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
confirmButton = CreateButton(parent, "OK", new Vector2(-70f, -85f), new Vector2(110f, 40f), new UnityAction(OnConfirm));
cancelButton = CreateButton(parent, "Cancel", new Vector2(70f, -85f), new Vector2(110f, 40f), new UnityAction(Close));
}
private Button CreateButton(Transform parent, string text, Vector2 position, Vector2 size, UnityAction action)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//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)
//IL_008b: 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_00a0: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(text + "Button", new Type[3]
{
typeof(RectTransform),
typeof(Image),
typeof(Button)
});
val.transform.SetParent(parent, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.5f);
component.anchorMax = new Vector2(0.5f, 0.5f);
component.pivot = new Vector2(0.5f, 0.5f);
component.sizeDelta = size;
component.anchoredPosition = position;
Image component2 = val.GetComponent<Image>();
component2.sprite = GUIManager.Instance.GetSprite("button");
component2.type = (Type)1;
((Graphic)component2).color = Color.white;
((Graphic)component2).raycastTarget = true;
Button component3 = val.GetComponent<Button>();
((Selectable)component3).targetGraphic = (Graphic)(object)component2;
((Selectable)component3).colors = GUIManager.Instance.ValheimButtonColorBlock;
((UnityEvent)component3.onClick).AddListener(action);
GameObject val2 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(val.transform, false);
RectTransform component4 = val2.GetComponent<RectTransform>();
component4.anchorMin = Vector2.zero;
component4.anchorMax = Vector2.one;
component4.offsetMin = Vector2.zero;
component4.offsetMax = Vector2.zero;
TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)val3).text = text;
((TMP_Text)val3).font = GUIManager.Instance.TMP_AveriaSansLibre;
((TMP_Text)val3).fontSize = 18f;
((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
((Graphic)val3).color = GUIManager.Instance.ValheimOrange;
((Graphic)val3).raycastTarget = false;
return component3;
}
private void OnConfirm()
{
if (resourceUI == null)
{
Close();
return;
}
int num = (int)amountSlider.value;
num = Mathf.Clamp(num, 1, maxAmount);
if (num > 0)
{
if (useLegacyMode)
{
resourceUI.MoveItemToInventory(itemName, num);
}
else if (slot != null)
{
resourceUI.MoveItemToInventory(slot, num);
}
}
Close();
}
public void Close()
{
if (!isClosing)
{
isClosing = true;
GUIManager.BlockInput(false);
if ((Object)(object)Current == (Object)(object)this)
{
Current = null;
}
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
private void Update()
{
if (!((Object)(object)Current != (Object)(object)this))
{
if (Input.GetKeyDown((KeyCode)27))
{
Close();
}
else if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
{
OnConfirm();
}
}
}
private void OnDestroy()
{
GUIManager.BlockInput(false);
if ((Object)(object)Current == (Object)(object)this)
{
Current = null;
}
}
}
public class MoveAmountToCustomDialog : MonoBehaviour
{
private RectTransform root;
private Slider amountSlider;
private TextMeshProUGUI amountValueText;
private Button confirmButton;
private Button cancelButton;
private ItemData targetItemData;
private int maxAmount;
private ResourceUI resourceUI;
private bool isClosing;
private Vector2 targetScreenPosition;
public static MoveAmountToCustomDialog Current { get; private set; }
public static MoveAmountToCustomDialog CreateForItemData(Transform parent, ItemData item, int maxAmount, ResourceUI ui, Vector2 screenPosition)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Current != (Object)null)
{
Current.Close();
}
object obj = parent;
if (obj == null)
{
GameObject customGUIFront = GUIManager.CustomGUIFront;
obj = ((customGUIFront != null) ? customGUIFront.transform : null);
}
Transform val = (Transform)obj;
if ((Object)(object)val == (Object)null)
{
return null;
}
GameObject val2 = new GameObject("MoveAmountToCustomDialog", new Type[2]
{
typeof(RectTransform),
typeof(CanvasGroup)
});
val2.transform.SetParent(val, false);
val2.transform.SetAsLastSibling();
MoveAmountToCustomDialog moveAmountToCustomDialog = val2.AddComponent<MoveAmountToCustomDialog>();
moveAmountToCustomDialog.Build(item, maxAmount, ui, screenPosition);
Current = moveAmountToCustomDialog;
return moveAmountToCustomDialog;
}
private void Build(ItemData item, int max, ResourceUI ui, Vector2 screenPosition)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
targetItemData = item;
maxAmount = Mathf.Max(1, max);
resourceUI = ui;
targetScreenPosition = screenPosition;
BuildUI();
}
private void BuildUI()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_0069: 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)
CanvasGroup component = ((Component)this).GetComponent<CanvasGroup>();
component.alpha = 1f;
component.interactable = true;
component.blocksRaycasts = true;
root = ((Component)this).GetComponent<RectTransform>();
root.anchorMin = Vector2.zero;
root.anchorMax = Vector2.one;
root.offsetMin = Vector2.zero;
root.offsetMax = Vector2.zero;
root.pivot = new Vector2(0.5f, 0.5f);
CreateOverlay();
CreateDialogPanel();
GUIManager.BlockInput(true);
}
private void CreateOverlay()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0054: 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)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
GameObject val = new GameObject("Overlay", new Type[3]
{
typeof(RectTransform),
typeof(Image),
typeof(Button)
});
val.transform.SetParent(((Component)this).transform, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
Image component2 = val.GetComponent<Image>();
((Graphic)component2).color = new Color(0f, 0f, 0f, 0.65f);
((Graphic)component2).raycastTarget = true;
Button component3 = val.GetComponent<Button>();
((Selectable)component3).transition = (Transition)0;
((UnityEvent)component3.onClick).AddListener(new UnityAction(Close));
}
private void CreateDialogPanel()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Panel", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val.transform.SetParent(((Component)this).transform, false);
val.transform.SetAsLastSibling();
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.5f);
component.anchorMax = new Vector2(0.5f, 0.5f);
component.pivot = new Vector2(0.5f, 0.5f);
component.sizeDelta = new Vector2(520f, 250f);
component.anchoredPosition = CalculateDialogPosition(targetScreenPosition);
Image component2 = val.GetComponent<Image>();
component2.sprite = GUIManager.Instance.GetSprite("woodpanel_trophys");
component2.type = (Type)1;
((Graphic)component2).color = Color.gray;
((Graphic)component2).raycastTarget = true;
val.AddComponent<Outline>();
val.AddComponent<DragWindowCntrl>();
CreateTitle(val.transform);
CreateSlider(val.transform);
CreateButtons(val.transform);
}
private Vector2 CalculateDialogPosition(Vector2 screenPosition)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: 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)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//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_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: 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_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
if ((Object)(object)componentInParent == (Object)null)
{
return Vector2.zero;
}
Transform transform = ((Component)componentInParent).transform;
RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
Vector2 sizeDelta = val.sizeDelta;
Vector2 val2 = default(Vector2);
RectTransformUtility.ScreenPointToLocalPointInRectangle(val, screenPosition, componentInParent.worldCamera, ref val2);
float num = 520f;
float num2 = 250f;
float num3 = ((val2.x > 0f) ? ((0f - num) / 2f - 50f) : (num / 2f + 50f));
float num4 = 0f;
float num5 = (0f - sizeDelta.x) / 2f + num / 2f + 20f;
float num6 = sizeDelta.x / 2f - num / 2f - 20f;
float num7 = (0f - sizeDelta.y) / 2f + num2 / 2f + 20f;
float num8 = sizeDelta.y / 2f - num2 / 2f - 20f;
Vector2 val3 = val2 + new Vector2(num3, num4);
val3.x = Mathf.Clamp(val3.x, num5, num6);
val3.y = Mathf.Clamp(val3.y, num7, num8);
return val3;
}
private void CreateTitle(Transform parent)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_003f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_011a: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Title", new Type[1] { typeof(RectTransform) });