Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ShowMeTheGoods v0.3.2
ShowMeTheGoods.dll
Decompiled 3 weeks agousing 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 System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Configs; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Extensions; using Jotunn.Managers; using Jotunn.Utils; using Logging; using Microsoft.CodeAnalysis; using ShowMeTheGoods.Core; using ShowMeTheGoods.Helpers; using SoftReferenceableAssets; using Splatform; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ShowMeTheGoods")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ShowMeTheGoods")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("08a6f7d7-cf93-4931-aecd-abf2ce6ed34c")] [assembly: AssemblyFileVersion("0.3.2")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.3.2.0")] [module: UnverifiableCode] [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 Logging { internal static class Log { internal enum InfoLevel { Low, Medium, High } private static ManualLogSource logSource; internal static ConfigEntry<InfoLevel> Verbosity { get; set; } internal static InfoLevel VerbosityLevel => Verbosity.Value; internal static bool IsVerbosityLow => Verbosity.Value >= InfoLevel.Low; internal static bool IsVerbosityMedium => Verbosity.Value >= InfoLevel.Medium; internal static bool IsVerbosityHigh => Verbosity.Value >= InfoLevel.High; internal static void Init(ManualLogSource logSource) { Log.logSource = logSource; } internal static void LogDebug(object data) { logSource.LogDebug(data); } internal static void LogError(object data) { logSource.LogError(data); } internal static void LogFatal(object data) { logSource.LogFatal(data); } internal static void LogMessage(object data) { logSource.LogMessage(data); } internal static void LogWarning(object data) { logSource.LogWarning(data); } internal static void LogInfo(object data, InfoLevel level = InfoLevel.Low) { if (Verbosity == null || VerbosityLevel >= level) { logSource.LogInfo(data); } } internal static void LogGameObject(GameObject prefab, bool includeChildren = false) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown LogInfo("***** " + ((Object)prefab).name + " *****"); Component[] components = prefab.GetComponents<Component>(); for (int i = 0; i < components.Length; i++) { LogComponent(components[i]); } if (!includeChildren) { return; } LogInfo("***** " + ((Object)prefab).name + " (children) *****"); foreach (Transform item in prefab.transform) { Transform val = item; if (Object.op_Implicit((Object)(object)val)) { LogInfo(" - " + ((Object)val).name); components = ((Component)val).GetComponents<Component>(); for (int i = 0; i < components.Length; i++) { LogComponent(components[i]); } } } } internal static void LogComponent(Component compo) { if (!Object.op_Implicit((Object)(object)compo)) { return; } try { LogInfo("--- " + ((object)compo).GetType().Name + ": " + ((Object)compo).name + " ---"); } catch (Exception ex) { LogError(ex.ToString()); LogWarning("Could not get type name for component!"); return; } try { foreach (PropertyInfo declaredProperty in AccessTools.GetDeclaredProperties(((object)compo).GetType())) { try { LogInfo($" - {declaredProperty.Name} = {declaredProperty.GetValue(compo)}"); } catch (Exception ex2) { LogError(ex2.ToString()); LogWarning("Could not get property: " + declaredProperty.Name + " for component!"); } } } catch (Exception ex3) { LogError(ex3.ToString()); LogWarning("Could not get properties for component!"); } try { foreach (FieldInfo declaredField in AccessTools.GetDeclaredFields(((object)compo).GetType())) { try { LogInfo($" - {declaredField.Name} = {declaredField.GetValue(compo)}"); } catch (Exception ex4) { LogError(ex4.ToString()); LogWarning("Could not get field: " + declaredField.Name + " for component!"); } } } catch (Exception ex5) { LogError(ex5.ToString()); LogWarning("Could not get fields for component!"); } } } } namespace ShowMeTheGoods { [BepInPlugin("Searica.Valheim.ShowMeTheGoods", "ShowMeTheGoods", "0.3.2")] [BepInDependency("com.jotunn.jotunn", "2.30.2")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [SynchronizationMode(/*Could not decode attribute arguments.*/)] internal sealed class ShowMeTheGoods : BaseUnityPlugin { public const string PluginName = "ShowMeTheGoods"; internal const string Author = "Searica"; public const string PluginGUID = "Searica.Valheim.ShowMeTheGoods"; public const string PluginVersion = "0.3.2"; internal static ShowMeTheGoods Instance; internal static ConfigFile ConfigFile; internal static ConfigFileWatcher ConfigFileWatcher; internal const string MainConfigSection = "ShowMeTheGoods"; internal ConfigEntry<int> MapCost; private bool AddedCustomItems; public void Awake() { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown Instance = this; ConfigFile = ((BaseUnityPlugin)this).Config; Log.Init(((BaseUnityPlugin)this).Logger); ((BaseUnityPlugin)this).Config.DisableSaveOnConfigSet(); SetUpConfigEntries(); ((BaseUnityPlugin)this).Config.Save(); ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Searica.Valheim.ShowMeTheGoods"); Game.isModded = true; ConfigFileWatcher = new ConfigFileWatcher(((BaseUnityPlugin)this).Config, 1000L); PrefabManager.OnVanillaPrefabsAvailable += AddCustomItems; } internal void SetUpConfigEntries() { Log.Verbosity = ConfigFileExtensions.BindConfigInOrder<Log.InfoLevel>(((BaseUnityPlugin)this).Config, "ShowMeTheGoods", "Verbosity", Log.InfoLevel.Low, "Low will log basic information about the mod. Medium will log information that is useful for troubleshooting. High will log a lot of information, do not set it to this without good reason as it will slow Down your game.", false, false, true, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); MapCost = ConfigFileExtensions.BindConfigInOrder<int>(((BaseUnityPlugin)this).Config, "ShowMeTheGoods", "Map Cost", 2000, "Cost of the map in coins.", true, false, true, (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10000), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null); MapCost.SettingChanged += delegate { if (AddedCustomItems) { TradeRouteMapManager.UpdateTradeItemCost(); } }; } private void AddCustomItems() { Log.LogInfo("Adding TradeRouteMap", Log.InfoLevel.Medium); ItemManager.Instance.AddItem(TradeRouteMapManager.GetTradeRouteMapCustomItem()); PrefabManager.OnVanillaPrefabsAvailable -= AddCustomItems; AddedCustomItems = true; } public void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } } } namespace ShowMeTheGoods.Helpers { internal class IconManager : MonoBehaviour { private static GameObject _gameObject; private static IconManager _instance; internal static IconManager Instance => CreateInstance(); private static IconManager CreateInstance() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)_gameObject)) { _gameObject = new GameObject(); Object.DontDestroyOnLoad((Object)(object)_gameObject); } if (!Object.op_Implicit((Object)(object)_instance)) { _instance = _gameObject.AddComponent<IconManager>(); } return _instance; } private IconManager() { } public void GeneratePrefabItemDropIcons(IEnumerable<GameObject> prefabs) { ((MonoBehaviour)this).StartCoroutine(RenderCoroutine(prefabs)); } private IEnumerator RenderCoroutine(IEnumerable<GameObject> gameObjects) { ItemDrop itemDrop = default(ItemDrop); foreach (GameObject gameObject in gameObjects) { if (!Object.op_Implicit((Object)(object)gameObject)) { Log.LogWarning("Null prefab, cannot render icon"); continue; } if (!gameObject.TryGetComponent<ItemDrop>(ref itemDrop)) { Log.LogWarning("Missing ItemDrop, cannot render icon"); continue; } Sprite result = GenerateObjectIcon(gameObject); yield return (object)new WaitForEndOfFrame(); if (result == null) { Log.LogWarning("Failed to generate icon for " + ((Object)gameObject).name + "!"); continue; } itemDrop.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { result }; itemDrop = null; } } private static Sprite GenerateObjectIcon(GameObject obj) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown RenderRequest val = new RenderRequest(obj) { Rotation = RenderManager.IsometricRotation, UseCache = true }; return RenderManager.Instance.Render(val); } } } namespace ShowMeTheGoods.Extensions { internal static class AssetBundleLoaderExtensions { private static readonly Dictionary<BundleLoader, HashSet<AssetID>> _bundleLoaderToAssetIDsMap = new Dictionary<BundleLoader, HashSet<AssetID>>(); private static Dictionary<BundleLoader, HashSet<AssetID>> GetBundleLoaderToAssetIDDependeciesMap() { //IL_001d: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) if (_bundleLoaderToAssetIDsMap.Count == 0) { AssetLoader[] assetLoaders = AssetBundleLoader.Instance.m_assetLoaders; foreach (AssetLoader val in assetLoaders) { BundleLoader bundleLoaderFromAssetID = AssetBundleLoader.Instance.GetBundleLoaderFromAssetID(val.m_assetID); if (!_bundleLoaderToAssetIDsMap.TryGetValue(bundleLoaderFromAssetID, out var value)) { value = new HashSet<AssetID>(); _bundleLoaderToAssetIDsMap[bundleLoaderFromAssetID] = value; } value.Add(val.m_assetID); } } return _bundleLoaderToAssetIDsMap; } internal static BundleLoader GetBundleLoaderFromAssetID(this AssetBundleLoader assetBundleLoader, AssetID assetID) { //IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) AssetLoader loader = assetBundleLoader.GetLoader(assetID); return assetBundleLoader.m_bundleLoaders[loader.m_bundleLoaderIndex]; } internal static HashSet<AssetID> GetDependenciesFromAssetID(this AssetBundleLoader assetBundleLoader, AssetID assetID) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) BundleLoader bundleLoaderFromAssetID = assetBundleLoader.GetBundleLoaderFromAssetID(assetID); List<AssetID> list = new List<AssetID>(); Dictionary<BundleLoader, HashSet<AssetID>> bundleLoaderToAssetIDDependeciesMap = GetBundleLoaderToAssetIDDependeciesMap(); int[] bundleLoaderIndicesOfThisAndDependencies = bundleLoaderFromAssetID.m_bundleLoaderIndicesOfThisAndDependencies; foreach (int num in bundleLoaderIndicesOfThisAndDependencies) { if (bundleLoaderToAssetIDDependeciesMap.TryGetValue(assetBundleLoader.m_bundleLoaders[num], out var value)) { list.AddRange(value); } } return list.ToHashSet(); } } internal static class GameObjectExtensions { public static bool IsRootPrefab(this GameObject go) { return !Object.op_Implicit((Object)(object)go.transform.parent); } } } namespace ShowMeTheGoods.Core { internal static class ModCompat { public const string MWLGUID = "warpalicious.More_World_Locations_AIO"; private static bool? _MWLInstalled; internal static bool IsMWLInstalled() { bool valueOrDefault = _MWLInstalled == true; if (!_MWLInstalled.HasValue) { valueOrDefault = Chainloader.PluginInfos.ContainsKey("warpalicious.More_World_Locations_AIO"); _MWLInstalled = valueOrDefault; } return _MWLInstalled.Value; } } [HarmonyPatch] internal sealed class TraderLocationManager { internal class LocationTraderInfo { public bool IsUnique; public bool IsTraderLocation; } private static readonly Dictionary<string, LocationTraderInfo> Internal_TraderLocationInfoMap = new Dictionary<string, LocationTraderInfo>(); private static readonly Dictionary<string, LocationTraderInfo> Vanilla_TraderLocationInfoMap = new Dictionary<string, LocationTraderInfo> { { "Vendor_BlackForest", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "Hildir_camp", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "BogWitch_Camp", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } } }; private static readonly Dictionary<string, LocationTraderInfo> MWL_TraderLocationInfoMap = new Dictionary<string, LocationTraderInfo> { { "MWL_PlainsTavern1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_PlainsCamp1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_BlackForestBlacksmith1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_BlackForestBlacksmith2", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_MountainsBlacksmith1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_MistlandsBlacksmith1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_OceanTavern1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_MeadowsTrainer1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_SwampTrainer1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_PlainsTrainer1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } }, { "MWL_MistTrainer1", new LocationTraderInfo { IsUnique = true, IsTraderLocation = true } } }; private GameObject gameObject; private TradeRouteMap TraderRouteMap; public static TraderLocationManager Instance; private static bool HasInit = false; internal Dictionary<string, LocationTraderInfo> TraderLocationInfoMap { get { if (!IsValid() || Internal_TraderLocationInfoMap.Count > 0) { return Internal_TraderLocationInfoMap; } foreach (KeyValuePair<string, LocationTraderInfo> item in Vanilla_TraderLocationInfoMap) { Internal_TraderLocationInfoMap.Add(item.Key, item.Value); } if (!ModCompat.IsMWLInstalled()) { return Internal_TraderLocationInfoMap; } foreach (KeyValuePair<string, LocationTraderInfo> item2 in MWL_TraderLocationInfoMap) { Internal_TraderLocationInfoMap.Add(item2.Key, item2.Value); } return Internal_TraderLocationInfoMap; } } private static bool IsValid() { return HasInit; } [HarmonyPostfix] [HarmonyPatch(typeof(ZoneSystem), "Start")] private static void InitTraderLocationManager(ZoneSystem __instance) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown Scene activeScene = SceneManager.GetActiveScene(); if (!(((Scene)(ref activeScene)).name != "main") && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)ZNetScene.instance)) { if (!IsValid()) { Instance = new TraderLocationManager { gameObject = new GameObject("TraderLocationManager") }; Instance.TraderRouteMap = Instance.gameObject.AddComponent<TradeRouteMap>(); Object.DontDestroyOnLoad((Object)(object)Instance.gameObject); HasInit = true; } if (!ZNet.instance.IsServer()) { ZRoutedRpc.instance.Register<ZPackage>("TraderLocations", (Action<long, ZPackage>)Instance.RPC_TraderLocations); } } } [HarmonyPostfix] [HarmonyPatch(typeof(ZoneSystem), "SendLocationIcons")] private static void SendTraderLocations(ZoneSystem __instance, long peer) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_00a2: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) if (!ZNet.instance.IsServer()) { return; } ZPackage val = new ZPackage(); Dictionary<string, List<LocationInstance>> traderLocationInstances = Instance.GetTraderLocationInstances(); val.Write(traderLocationInstances.Keys.Count); foreach (KeyValuePair<string, List<LocationInstance>> item in traderLocationInstances) { val.Write(item.Key); val.Write(item.Value.Count); foreach (LocationInstance item2 in item.Value) { val.Write(item2.m_location.m_prefabName); val.Write(item2.m_position.x); val.Write(item2.m_position.y); val.Write(item2.m_position.z); val.Write(item2.m_placed); } } ZRoutedRpc.instance.InvokeRoutedRPC(peer, "TraderLocations", new object[1] { val }); } private void RPC_TraderLocations(long sender, ZPackage pkg) { //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_009d: Unknown result type (might be due to invalid IL or missing references) Log.LogInfo("Client received trader locations."); int num = pkg.ReadInt(); for (int i = 0; i < num; i++) { string arg = pkg.ReadString(); int num2 = pkg.ReadInt(); Log.LogInfo($"Parsing {num2} instances of location: {arg}", Log.InfoLevel.Medium); for (int j = 0; j < num2; j++) { string text = pkg.ReadString(); Vector3 zero = Vector3.zero; zero.x = pkg.ReadSingle(); zero.y = pkg.ReadSingle(); zero.z = pkg.ReadSingle(); bool flag = pkg.ReadBool(); ZoneLocation location = ZoneSystem.instance.GetLocation(text); if (location != null) { ZoneSystem.instance.RegisterLocation(location, zero, flag); } else { Log.LogInfo($"Failed to find instance {j + 1} of location {arg}", Log.InfoLevel.Medium); } } } } [HarmonyPostfix] [HarmonyPatch(typeof(Humanoid), "UseItem")] private static void UseTradeRouteMap(Player __instance, ItemData item, bool fromInventoryGui) { if (Object.op_Implicit((Object)(object)__instance) && fromInventoryGui && item != null && item.m_shared != null && Object.op_Implicit((Object)(object)item.m_dropPrefab) && Object.op_Implicit((Object)(object)item.m_dropPrefab.GetComponent<TradeRouteMap>())) { Instance.PinClosestUndiscoveredTrader(); } } private void PinClosestUndiscoveredTrader() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (Instance.TraderRouteMap.CanReadMap()) { if (FindClosestUndiscoveredTraderLocation(out var closest)) { Instance.TraderRouteMap.AddLocationPin(closest); } else if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "You have found all the traders!", 0, (Sprite)null, false); } } } private bool FindClosestUndiscoveredTraderLocation(out LocationInstance closest) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, List<LocationInstance>> traderLocationInstances = Instance.GetTraderLocationInstances(); closest = default(LocationInstance); bool result = false; float num = float.MaxValue; foreach (KeyValuePair<string, List<LocationInstance>> item in traderLocationInstances) { float minDistance; LocationInstance closest2; bool flag = FindClosestUndiscoveredLocationInList(TraderLocationInfoMap[item.Key].IsUnique, item.Value, out minDistance, out closest2); Log.LogInfo($"{item.Key} has undiscovered location: {flag}", Log.InfoLevel.Medium); if (flag && minDistance < num) { num = minDistance; closest = closest2; result = true; } } return result; } private Dictionary<string, List<LocationInstance>> GetTraderLocationInstances() { //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_0067: 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_008c: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, List<LocationInstance>> dictionary = new Dictionary<string, List<LocationInstance>>(); foreach (string key in TraderLocationInfoMap.Keys) { dictionary.Add(key, new List<LocationInstance>()); } foreach (LocationInstance value in ZoneSystem.instance.m_locationInstances.Values) { if (dictionary.ContainsKey(value.m_location.m_prefabName)) { dictionary[value.m_location.m_prefabName].Add(value); } } foreach (string key2 in TraderLocationInfoMap.Keys) { int count = dictionary[key2].Count; Log.LogInfo($"{key2} has {count} Location Instances", Log.InfoLevel.Medium); } return dictionary; } private static bool FindClosestUndiscoveredLocationInList(bool isUniqueLocation, List<LocationInstance> locationInstances, out float minDistance, out LocationInstance closest) { //IL_0001: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0041: Unknown result type (might be due to invalid IL or missing references) closest = default(LocationInstance); minDistance = float.MaxValue; bool result = false; Vector3 position = ((Component)Player.m_localPlayer).transform.position; foreach (LocationInstance locationInstance in locationInstances) { if (HasLocationInstanceBeenDiscovered(locationInstance)) { if (isUniqueLocation) { Log.LogInfo("Location " + locationInstance.m_location.m_prefabName + " is Unique and has already been discovered"); return false; } continue; } float num = Vector3.Distance(locationInstance.m_position, position); if (num < minDistance) { minDistance = num; closest = locationInstance; result = true; } } return result; } private static bool HasLocationInstanceBeenDiscovered(LocationInstance locationInstance) { //IL_0000: 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) if (!locationInstance.m_location.m_iconAlways) { return locationInstance.m_placed; } return true; } } internal class TradeRouteMap : MonoBehaviour { private const float PinDuration = 300f; private const float DefaultRadius = 1500f; private const float RadiusVariance = 300f; private const float RadialVariance = 0.9f; private const string DefaultPinName = "Trader?"; private PinData LocationPinData; public bool CanReadMap() { if (LocationPinData == null && Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.LocationsGenerated) { return true; } if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "Cannot read trade route map again yet.", 0, (Sprite)null, false); } return false; } public void AddLocationPin(LocationInstance locationInstance) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_011b: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)Minimap.instance) && Object.op_Implicit((Object)(object)InventoryGui.instance)) { if (LocationPinData != null) { Minimap.instance.RemovePin(LocationPinData); } float num = 1500f + Random.Range(-300f, 300f); float num2 = Random.Range(0f, num * 0.9f); float num3 = Random.Range(0f, (float)Math.PI * 2f); float num4 = num2 * Mathf.Cos(num3); float num5 = num2 * Mathf.Sin(num3); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(locationInstance.m_position.x + num4, locationInstance.m_position.y, locationInstance.m_position.z + num5); LocationPinData = Minimap.instance.AddPin(val, (PinType)13, "Trader?", false, false, 0L, default(PlatformUserID)); LocationPinData.m_worldSize = num * 2f; InventoryGui.instance.Hide(); Sprite sprite = Minimap.instance.GetSprite((PinType)13); ((Character)Player.m_localPlayer).Message((MessageType)1, "$msg_pin_added: Trader?", 0, sprite, false); Minimap.instance.ShowPointOnMap(val); ((MonoBehaviour)this).StartCoroutine((IEnumerator)RemovePinDataAfter(300f)); } } private IEnumerator<object> RemovePinDataAfter(float seconds) { Log.LogDebug($"Will remove pin in {seconds} seconds"); yield return (object)new WaitForSeconds(seconds); if (LocationPinData != null) { if (Object.op_Implicit((Object)(object)Minimap.instance)) { Minimap.instance.RemovePin(LocationPinData); } LocationPinData = null; } yield return null; } } [HarmonyPatch] internal static class TradeRouteMapManager { private const string TraderMapPrefabName = "ShowMeTheGoods_TradeRouteMap"; private static CustomItem TradeRouteMapCustomItem; private static TradeItem TradeRouteMapTradeItem; public static CustomItem GetTradeRouteMapCustomItem() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0068: 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_015f: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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) if (TradeRouteMapCustomItem != null) { return TradeRouteMapCustomItem; } ItemConfig val = new ItemConfig { Name = "Trade Route Map", Description = "Map that helps to find possible trader locations.", CraftingStation = CraftingStations.None, Enabled = false, StackSize = 1, Weight = 1f }; GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("ShowMeTheGoods_TradeRouteMap", "Iron"); val2.transform.localRotation = Quaternion.identity; val2.AddComponent<TradeRouteMap>(); Transform val3 = val2.transform.Find("model"); if (Object.op_Implicit((Object)(object)val3)) { ((Component)val3).transform.localPosition = Vector3.zero; ((Component)val3).transform.localRotation = Quaternion.identity; ((Component)val3).transform.localScale = new Vector3(1.1f, 0.1f, 0.7f); } try { GameObject prefab = PrefabManager.Instance.GetPrefab("hildir_maptable"); ((Renderer)((Component)val3).GetComponent<MeshRenderer>()).sharedMaterial = ((Renderer)prefab.GetComponentInChildren<MeshRenderer>()).sharedMaterial; } catch { Log.LogWarning("Failed to customize material of ShowMeTheGoods_TradeRouteMap!"); } try { ItemDrop component = val2.GetComponent<ItemDrop>(); component.m_itemData.m_shared.m_itemType = (ItemType)0; component.m_itemData.m_shared.m_teleportable = true; IconManager.Instance.GeneratePrefabItemDropIcons((IEnumerable<GameObject>)(object)new GameObject[1] { val2 }); } catch { Log.LogWarning("Failed to customize item type of ShowMeTheGoods_TradeRouteMap!"); } TradeRouteMapCustomItem = new CustomItem(val2, true, val); return TradeRouteMapCustomItem; } public static TradeItem GetTradeRouteMapTradeItem() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown if (TradeRouteMapTradeItem != null) { return TradeRouteMapTradeItem; } CustomItem tradeRouteMapCustomItem = GetTradeRouteMapCustomItem(); TradeRouteMapTradeItem = new TradeItem { m_prefab = tradeRouteMapCustomItem.ItemDrop, m_stack = 1, m_price = ShowMeTheGoods.Instance.MapCost.Value, m_tooltip = tradeRouteMapCustomItem.ItemDrop.m_itemData.m_shared.m_description }; return TradeRouteMapTradeItem; } public static void UpdateTradeItemCost() { GetTradeRouteMapTradeItem().m_price = ShowMeTheGoods.Instance.MapCost.Value; } [HarmonyPostfix] [HarmonyPatch(typeof(Trader), "Start")] private static void AddTradeRouteMapToTraderItems(Trader __instance) { if (Object.op_Implicit((Object)(object)__instance)) { __instance.m_items.Add(GetTradeRouteMapTradeItem()); } } } } namespace Configs { public static class ConfigFileExtensions { public static bool DisableSaveOnConfigSet(this ConfigFile configFile) { bool saveOnConfigSet = configFile.SaveOnConfigSet; configFile.SaveOnConfigSet = false; return saveOnConfigSet; } } internal static class SafeInvokeEvent { internal static void SafeInvoke(this Action events) { if (events == null) { return; } Delegate[] invocationList = events.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { Action action = (Action)invocationList[i]; try { action(); } catch (Exception arg) { Log.LogWarning("Exception thrown at event " + new StackFrame(1).GetMethod().Name + $" in {action.Method.DeclaringType.Name}.{action.Method.Name}:\n{arg}"); } } } } }