using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Needleforge;
using Needleforge.Data;
using TeamCherry.Localization;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("silkphial")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("silkphial")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("319e44e5-02f1-45d1-b5d1-bbc42878e380")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.xTruesX.silkphialmod", "Silk Phial Mod", "1.0.0")]
public class main : BaseUnityPlugin
{
[HarmonyPatch(typeof(ToolItemStatesLiquid))]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private class SilkPhial_UsableWhenEmpty_Patch
{
private static void Postfix(ToolItemStatesLiquid __instance, ref bool __result)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!(((ToolItem)__instance).name != "Silk Phial") && ((ToolItem)__instance).SavedData.AmountLeft <= 0)
{
__result = false;
}
}
}
[HarmonyPatch(typeof(ToolItem), "get_IsUnlockedTest")]
internal static class ToolItem_IsUnlockedTest_NullFix
{
private static bool Prefix(ToolItem __instance, ref bool __result)
{
if (AccessTools.Field(typeof(ToolItem), "alternateUnlockedTest")?.GetValue(__instance) == null)
{
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PlayerData), "CountGameCompletion")]
internal static class PlayerData_CountGameCompletionFixForSiPhi
{
private static void Postfix(PlayerData __instance)
{
ToolItem toolByName = ToolItemManager.GetToolByName("Silk Phial");
if ((Object)(object)toolByName != (Object)null && toolByName.IsUnlocked)
{
__instance.completionPercentage -= 1f;
}
}
}
[HarmonyPatch(typeof(LocalisedString))]
[HarmonyPatch("ToString", new Type[] { typeof(bool) })]
internal static class SilkPhial_ForceText_NoSheetKey
{
private static void Postfix(LocalisedString __instance, ref string __result)
{
if (PlayerData.instance == null)
{
return;
}
ToolItem toolByName = ToolItemManager.GetToolByName("Silk Phial");
if ((Object)(object)toolByName == (Object)null || !toolByName.IsUnlocked)
{
return;
}
string text = __result;
if (!text.Contains("SilkPhial") && !text.Contains("silkphial") && !text.Contains("!!"))
{
return;
}
if (text.ToLower().Contains("display") || text.Contains("Name"))
{
__result = "Silk Phial";
}
else if (text.ToLower().Contains("desc"))
{
if (PlayerData.instance.CurrentCrestID == "Toolmaster")
{
__result = "A phial filled to the brim with Silk. Used to inject silk into a bug's shell \n\nGives 1-2 spools of silk when injected.";
}
else
{
__result = "A phial filled to the brim with Silk. Used to inject silk into a bug's shell \n\nGives 3 spools of silk when injected.";
}
}
}
}
[CompilerGenerated]
private sealed class <BenchRefillWatcher>d__2 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public main <>4__this;
private string <toolName>5__2;
private bool <wasAtBench>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <BenchRefillWatcher>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<toolName>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//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_0131: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
main main2 = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
goto IL_0042;
case 1:
<>1__state = -1;
goto IL_0042;
case 2:
{
<>1__state = -1;
break;
}
IL_0042:
if ((Object)(object)HeroController.instance == (Object)null || PlayerData.instance == null)
{
<>2__current = null;
<>1__state = 1;
return true;
}
<toolName>5__2 = "Silk Phial";
<wasAtBench>5__3 = false;
break;
}
bool atBench = PlayerData.instance.atBench;
if (atBench && !<wasAtBench>5__3)
{
ToolItemStatesLiquid val = null;
foreach (ToolItem newTool in NeedleforgePlugin.newTools)
{
if (newTool.name == <toolName>5__2)
{
val = (ToolItemStatesLiquid)(object)((newTool is ToolItemStatesLiquid) ? newTool : null);
break;
}
}
if (!((ToolItem)val).IsUnlocked)
{
((ToolItem)val).Unlock((Action)null, (PopupFlags)3);
}
if ((Object)(object)val != (Object)null)
{
Data data = ((SerializableNamedList<Data, NamedData>)(object)PlayerData.instance.ToolLiquids).GetData(<toolName>5__2);
data.RefillsLeft = val.RefillsMax;
data.UsedExtra = false;
data.SeenEmptyState = true;
((SerializableNamedList<Data, NamedData>)(object)PlayerData.instance.ToolLiquids).SetData(<toolName>5__2, data);
}
else
{
((BaseUnityPlugin)main2).Logger.LogError((object)"Bench refill: Tool N/A");
}
}
<wasAtBench>5__3 = atBench;
<>2__current = null;
<>1__state = 2;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private void Awake()
{
//IL_00c9: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
//IL_00ed: 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_00fa: 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_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Expected O, but got Unknown
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin loaded");
Harmony.CreateAndPatchAll(typeof(main), (string)null);
Harmony.CreateAndPatchAll(typeof(SilkPhial_UsableWhenEmpty_Patch), (string)null);
Harmony.CreateAndPatchAll(typeof(ToolItem_IsUnlockedTest_NullFix), (string)null);
Harmony.CreateAndPatchAll(typeof(PlayerData_CountGameCompletionFixForSiPhi), (string)null);
Harmony.CreateAndPatchAll(typeof(SilkPhial_ForceText_NoSheetKey), (string)null);
AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Paths.PluginPath, "silkphial"));
Sprite inventorySprite = obj.LoadAsset<Sprite>("SilkPhial");
Sprite hudSprite = obj.LoadAsset<Sprite>("SilkPhialHud");
Sprite poisonInventorySprite = obj.LoadAsset<Sprite>("SilkPhial_Poison");
Sprite poisonHudSprite = obj.LoadAsset<Sprite>("SilkPhial_PoisonHud");
Sprite val = obj.LoadAsset<Sprite>("SilkPhial_Empty");
Sprite val2 = obj.LoadAsset<Sprite>("SilkPhial_EmptyHud");
StateSprites val3 = new StateSprites
{
InventorySprite = inventorySprite,
HudSprite = hudSprite,
PoisonInventorySprite = poisonInventorySprite,
PoisonHudSprite = poisonHudSprite
};
StateSprites val4 = new StateSprites
{
InventorySprite = val,
HudSprite = val2,
PoisonInventorySprite = val,
PoisonHudSprite = val2
};
LiquidToolData val5 = NeedleforgePlugin.AddLiquidTool("Silk Phial", 10, 4, "SilkPhial_InfiniteBench", Color.white, (ReplenishResources)1, (ReplenishUsages)0, 1f, val3, val4, "Reserve BindBurst Air");
int CrSilk = 1;
((SerializableNamedList<Data, NamedData>)(object)PlayerData.instance.ToolLiquids).SetData("Silk Phial", new Data
{
RefillsLeft = 10,
UsedExtra = false,
SeenEmptyState = false
});
((ToolData)val5).displayName = new LocalisedString
{
Sheet = "silkphial",
Key = "Display"
};
((ToolData)val5).description = new LocalisedString
{
Key = "desc",
Sheet = "silkphial"
};
LiquidToolData liquidData = val5;
liquidData.beforeAnim = delegate
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
ToolItemStatesLiquid item = liquidData.Item;
if (!((Object)(object)item == (Object)null) && ((ToolItem)item).SavedData.AmountLeft <= 0)
{
AttackToolBinding? attackToolBinding = ToolItemManager.GetAttackToolBinding((ToolItem)(object)item);
if (attackToolBinding.HasValue)
{
ToolItemManager.ReportBoundAttackToolFailed(attackToolBinding.Value);
}
}
};
val5.afterAnim = delegate
{
if (!((Object)(object)HeroController.instance == (Object)null))
{
if (PlayerData.instance.CurrentCrestID == "Toolmaster")
{
PlayerData instance = PlayerData.instance;
instance.silk += CrSilk;
if (CrSilk == 1)
{
CrSilk = 2;
}
else
{
CrSilk = 1;
}
}
else
{
PlayerData instance2 = PlayerData.instance;
instance2.silk += 3;
}
HeroController.instance.AddSilk(0, false);
}
};
((MonoBehaviour)this).StartCoroutine(BenchRefillWatcher());
}
private void Update()
{
}
[IteratorStateMachine(typeof(<BenchRefillWatcher>d__2))]
private IEnumerator BenchRefillWatcher()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <BenchRefillWatcher>d__2(0)
{
<>4__this = this
};
}
private void SetPrivate(object obj, string fieldName, object value)
{
if (obj == null)
{
throw new Exception("SetPrivate: obj is null");
}
Type type = obj.GetType();
while (type != null)
{
FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(obj, value);
return;
}
type = type.BaseType;
}
throw new Exception($"SetPrivate: Field '{fieldName}' not found on {obj.GetType()}");
}
}