using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Eremite.Buildings.UI.Trade;
using Eremite.Model.Trade;
using Eremite.Trade.View;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("SaveTradeState")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Mod for Against The Storm")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")]
[assembly: AssemblyProduct("SaveTradeState")]
[assembly: AssemblyTitle("SaveTradeState")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace SaveTradeState
{
[BepInPlugin("savetradestate.plugin", "SaveTradeState", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static Harmony Harmony;
internal static readonly Dictionary<string, (int storage, int offered)> TraderCache = new Dictionary<string, (int, int)>();
internal static bool PanelOpen = false;
internal static bool FirstOffer = false;
internal static bool TradeJustCompleted = false;
internal static bool HasTradedThisVisit = false;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Harmony = new Harmony("savetradestate.harmony");
Harmony.PatchAll();
}
}
[HarmonyPatch(typeof(TraderPanel), "Show")]
public static class Patch_PanelOpened
{
private static void Postfix(TraderPanel __instance)
{
Plugin.PanelOpen = true;
Plugin.FirstOffer = true;
Plugin.TradeJustCompleted = false;
if (!Plugin.HasTradedThisVisit || Plugin.TraderCache.Count <= 0)
{
return;
}
TradingOffer offer = __instance.traderPanel.Offer;
if (offer == null || offer.goods == null)
{
return;
}
foreach (KeyValuePair<string, (int, int)> item in Plugin.TraderCache)
{
if (offer.goods.TryGetValue(item.Key, out var value))
{
value.storageAmount = item.Value.Item1;
value.offeredAmount = item.Value.Item2;
}
}
__instance.traderPanel.Refresh();
}
}
[HarmonyPatch(typeof(TraderPanel), "Hide")]
public static class Patch_PanelClosed
{
private static void Postfix()
{
Plugin.PanelOpen = false;
}
}
[HarmonyPatch(typeof(TraderIndicator), "Hide")]
public static class Patch_TraderDeparted
{
private static void Postfix()
{
Plugin.TraderCache.Clear();
Plugin.TradeJustCompleted = false;
Plugin.FirstOffer = false;
Plugin.HasTradedThisVisit = false;
}
}
[HarmonyPatch(typeof(TradingGoodsPanel), "SetNewOffer")]
public static class Patch_CaptureOffer
{
private static void Postfix(TradingGoodsPanel __instance, TradingGood tradingGood)
{
if (tradingGood != null && ((Object)__instance).name.Contains("Trader"))
{
int storageAmount = tradingGood.storageAmount;
int offeredAmount = tradingGood.offeredAmount;
if (storageAmount == 0 && offeredAmount == 0)
{
Plugin.TraderCache.Remove(tradingGood.goodName);
}
else
{
Plugin.TraderCache[tradingGood.goodName] = (storageAmount, offeredAmount);
}
}
}
}
[HarmonyPatch(typeof(TraderPanel), "CreateTraderOffer")]
public static class Patch_RestoreOrClear
{
private static void Prefix()
{
if (Plugin.PanelOpen && Plugin.TraderCache.Count > 0 && !Plugin.TradeJustCompleted)
{
Plugin.TraderCache.Clear();
Plugin.TradeJustCompleted = true;
Plugin.HasTradedThisVisit = true;
Plugin.FirstOffer = false;
}
}
private static void Postfix(ref TradingOffer __result)
{
if (__result == null || __result.goods == null)
{
return;
}
if (Plugin.TradeJustCompleted)
{
Plugin.TradeJustCompleted = false;
}
else
{
if (!Plugin.FirstOffer || Plugin.TraderCache.Count <= 0)
{
return;
}
Plugin.FirstOffer = false;
foreach (KeyValuePair<string, (int, int)> item in Plugin.TraderCache)
{
if (__result.goods.TryGetValue(item.Key, out var value))
{
value.storageAmount = item.Value.Item1;
value.offeredAmount = item.Value.Item2;
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "SaveTradeState";
public const string PLUGIN_NAME = "SaveTradeState";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}