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 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 Harmony Harmony; internal static readonly Dictionary TraderCache = new Dictionary(); internal static bool PanelOpen = false; internal static bool FirstOffer = false; internal static bool TradeJustCompleted = false; internal static bool HasTradedThisVisit = false; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown Harmony = new Harmony("savetradestate.harmony"); Harmony.PatchAll(); } internal static bool IsGladeTrader(string traderId) { return !string.IsNullOrEmpty(traderId) && traderId.StartsWith("Trader - Glade"); } } [HarmonyPatch(typeof(TraderPanel), "Show")] public static class Patch_PanelOpened { private static void Postfix(TraderPanel __instance) { string traderId = __instance.traderPanel?.visit?.trader ?? "NULL"; Plugin.PanelOpen = true; Plugin.FirstOffer = true; Plugin.TradeJustCompleted = false; if (Plugin.IsGladeTrader(traderId) || Plugin.TraderCache.Count == 0 || Plugin.TradeJustCompleted) { return; } TradingOffer offer = __instance.traderPanel.Offer; if (offer == null || offer.goods == null) { return; } foreach (KeyValuePair 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(); Plugin.FirstOffer = false; } } [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")) { return; } string traderId = __instance.visit?.trader ?? "NULL"; if (!Plugin.IsGladeTrader(traderId)) { 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(TraderPanel __instance) { string traderId = __instance.traderPanel?.visit?.trader ?? "NULL"; if (!Plugin.IsGladeTrader(traderId) && Plugin.PanelOpen && Plugin.TraderCache.Count > 0 && !Plugin.TradeJustCompleted) { Plugin.TraderCache.Clear(); Plugin.TradeJustCompleted = true; Plugin.HasTradedThisVisit = true; Plugin.FirstOffer = false; } } private static void Postfix() { } } 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) { } } }