using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("TraderBrothers")] [assembly: AssemblyDescription("Adds three placeable traders for materials, supplies, meads, and potions.")] [assembly: AssemblyCompany("LEGIOmods")] [assembly: AssemblyProduct("TraderBrothers")] [assembly: AssemblyCopyright("Copyright 2026 LEGIOmods")] [assembly: ComVisible(false)] [assembly: Guid("99c4e7f2-f33a-4b8e-be32-83619c66d3cc")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI for code, localization, documentation, and package preparation.")] [assembly: AssemblyMetadata("AI_Model_Vendor", "OpenAI")] [assembly: AssemblyMetadata("AI_Agent", "OpenAI Codex")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 TraderBrothers { [BepInPlugin("domen.valheim.traderbrothers", "TraderBrothers", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] internal sealed class TraderBrothersPlugin : BaseUnityPlugin { private sealed class TraderBrothersIdleAnimation : MonoBehaviour { private static readonly int[] IdleHashes = new int[5] { Animator.StringToHash("Idle"), Animator.StringToHash("idle"), Animator.StringToHash("Idle1"), Animator.StringToHash("Base Layer.Idle"), Animator.StringToHash("Base Layer.idle") }; public Animator Animator; private void Awake() { if ((Object)(object)Animator == (Object)null) { Animator = ((Component)this).GetComponentInChildren(true); } } private void Start() { if ((Object)(object)Animator != (Object)null) { ((Behaviour)Animator).enabled = true; Animator.speed = 1f; Animator.cullingMode = (AnimatorCullingMode)0; } ((MonoBehaviour)this).InvokeRepeating("RefreshIdle", 0.5f, 3f); } private void Update() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Animator == (Object)null) { return; } ((Behaviour)Animator).enabled = true; Animator.speed = 1f; Animator.cullingMode = (AnimatorCullingMode)0; if (!Animator.IsInTransition(0)) { AnimatorStateInfo currentAnimatorStateInfo = Animator.GetCurrentAnimatorStateInfo(0); if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).length > 0f && ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime >= 0.98f) { Animator.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, 0, 0f); } } } private void RefreshIdle() { if ((Object)(object)Animator == (Object)null) { return; } ((Behaviour)Animator).enabled = true; Animator.speed = 1f; int[] idleHashes = IdleHashes; foreach (int num in idleHashes) { if (Animator.HasState(0, num)) { Animator.CrossFade(num, 0.25f, 0); break; } } } } private sealed class TraderBrothersIdleSound : MonoBehaviour { public EffectList IdleSound; public float Interval = 8f; public float Chance = 0.45f; private void Start() { ((MonoBehaviour)this).InvokeRepeating("TryPlaySound", Random.Range(2f, Interval), Mathf.Max(1f, Interval)); } private void TryPlaySound() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (IdleSound != null && IdleSound.HasEffects() && Random.value <= Chance) { IdleSound.Create(((Component)this).transform.position, ((Component)this).transform.rotation, ((Component)this).transform, 1f, -1); } } } private sealed class TraderBrothersInteractable : MonoBehaviour, Interactable { public Trader Trader; public string DisplayName; public string GetHoverText() { return L(DisplayName) + "\n[$KEY_Use] " + L("$traderbrothers_trade"); } public string GetHoverName() { return L(DisplayName); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)Trader == (Object)null) { return false; } EnsureTrades(Trader); StoreGui.instance.Show(Trader); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } } [HarmonyPatch(typeof(StoreGui), "OnBuyItem")] private static class StoreGuiOnBuyItemPatch { private static bool Prefix(StoreGui __instance) { return !TrySellScrap(__instance); } } [HarmonyPatch(typeof(StoreGui), "UpdateBuyButton")] private static class StoreGuiUpdateBuyButtonPatch { private static void Postfix(StoreGui __instance) { Trader value = Traverse.Create((object)__instance).Field("m_trader").GetValue(); bool flag = IsScrapDealer(value); bool flag2 = IsKnownOnlyTrader(value); if (flag || flag2) { Button value2 = Traverse.Create((object)__instance).Field("m_buyButton").GetValue