Decompiled source of ItemsAPI v0.2.0

ItemsAPI.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Bifrost.ConstEnum;
using Bifrost.Cooked;
using Bifrost.ItemConsumable;
using Bifrost.ItemMiscellany;
using Bifrost.LocalizationData;
using HarmonyLib;
using ItemsAPI;
using ItemsAPI.Builders;
using ItemsAPI.Descriptors;
using ItemsAPI.Enums;
using ItemsAPI.Helpers;
using MelonLoader;
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: MelonInfo(typeof(global::ItemsAPI.ItemsAPI), "ItemsAPI", "0.2.0", "Shlygly", null)]
[assembly: MelonGame("ReLUGames", "MIMESIS")]
[assembly: MelonColor(255, 0, 128, 0)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Shlygly")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4b21c11dc439d6b22cfffb290027f60e44aa513d")]
[assembly: AssemblyProduct("ItemsAPI")]
[assembly: AssemblyTitle("ItemsAPI")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ItemsAPI
{
	public class ItemsAPI : MelonMod
	{
		public static ItemsAPI Instance { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			((MelonBase)this).LoggerInstance.Msg("API Ready to use !");
		}

		public static void Log(object msg)
		{
			if (msg is Exception)
			{
				((MelonBase)Instance).LoggerInstance.Error(msg);
			}
			else
			{
				((MelonBase)Instance).LoggerInstance.Msg(msg);
			}
		}
	}
}
namespace ItemsAPI.Patches
{
	[HarmonyPatch(typeof(Hub), "Start")]
	internal static class Hub_Start
	{
		private static void Postfix()
		{
			try
			{
				ItemsAPI.Log("Initializing item builder...");
				ItemBuilder.Initialize();
				int num = ItemBuilder.Items.Length;
				ItemsAPI.Log($"Adding {num} item(s)...");
				int num2 = ItemBuilder.Build().Length;
				ItemsAPI.Log($"{num2} of {num} item(s) added to the game !");
			}
			catch (Exception msg)
			{
				ItemsAPI.Log(msg);
			}
		}
	}
}
namespace ItemsAPI.Pachtes
{
	[HarmonyPatch(typeof(ExcelDataManager), "GetShopGroupPriceList", new Type[] { typeof(int) })]
	internal static class ExcelDataManager_GetShopGroupPriceList
	{
		private static void Postfix(ref List<(int masterid, int price)> __result)
		{
			try
			{
				VendingMachineBuilder.BuildShopPrices(__result);
			}
			catch (Exception msg)
			{
				ItemsAPI.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(MaintenanceScene), "Start")]
	internal static class MaintenanceScene_Start
	{
		private static void Prefix(MaintenanceScene __instance)
		{
			try
			{
				int num = VendingMachineBuilder.VendingMachines.Length;
				ItemsAPI.Log($"Adding {num} vending machine(s)...");
				int num2 = VendingMachineBuilder.BuildMaintenanceScene(__instance).Length;
				ItemsAPI.Log($"{num2} of {num} vending machine(s) added to the game !");
			}
			catch (Exception msg)
			{
				ItemsAPI.Log(msg);
			}
		}
	}
}
namespace ItemsAPI.Helpers
{
	public static class AssetTools
	{
		private static Material cachedMeshSlicerCrossMat;

		private static GameObject cachedMeshSlicerCrashEffect;

		private static GameObject cachedMeshSlicerSpawningEffect;

		private static GameObject cachedMeshSlicerVanishingEffect;

		private static GameObject cachedMeshSlicerFragmentSpawningEffect;

		private static GameObject cachedMeshSlicerFragmentVanishingEffect;

		public static void FixPrefabShaders(GameObject prefab)
		{
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] materials = val.materials;
				Material[] array = materials;
				foreach (Material val2 in array)
				{
					if (!((Object)(object)((val2 != null) ? val2.shader : null) == (Object)null))
					{
						Shader val3 = Shader.Find(((Object)val2.shader).name);
						if ((Object)(object)val3 != (Object)null)
						{
							val2.shader = val3;
						}
					}
				}
				val.materials = materials;
			}
		}

		public static void FixMeshSlicers(MMLootingObjectTable sourceTable, GameObject prefab)
		{
			if ((Object)(object)cachedMeshSlicerCrossMat == (Object)null || (Object)(object)cachedMeshSlicerCrashEffect == (Object)null || (Object)(object)cachedMeshSlicerSpawningEffect == (Object)null || (Object)(object)cachedMeshSlicerVanishingEffect == (Object)null)
			{
				MeshSlicer instance = sourceTable.rows.Where((Row row) => row != null && (Object)(object)row.prefab != (Object)null).SelectMany((Row row) => row.prefab.GetComponentsInChildren<MeshSlicer>(true)).FirstOrDefault((Func<MeshSlicer, bool>)((MeshSlicer meshSlicer) => (Object)(object)meshSlicer != (Object)null && (Object)(object)((Component)meshSlicer).gameObject != (Object)null && !((Component)meshSlicer).transform.IsChildOf(prefab.transform) && ReflectionTools.GetFieldOrProperty(meshSlicer, "crossMat") != null && ReflectionTools.GetFieldOrProperty(meshSlicer, "crashEffect") != null && ReflectionTools.GetFieldOrProperty(meshSlicer, "fragmentSpawningEffect") != null && ReflectionTools.GetFieldOrProperty(meshSlicer, "fragmentVanishingEffect") != null)) ?? throw new Exception("Could not find any MeshSlicer.");
				cachedMeshSlicerCrossMat = ReflectionTools.GetFieldOrProperty<Material>(instance, "crossMat");
				cachedMeshSlicerCrashEffect = ReflectionTools.GetFieldOrProperty<GameObject>(instance, "crashEffect");
				cachedMeshSlicerSpawningEffect = ReflectionTools.GetFieldOrProperty<GameObject>(instance, "fragmentSpawningEffect");
				cachedMeshSlicerVanishingEffect = ReflectionTools.GetFieldOrProperty<GameObject>(instance, "fragmentVanishingEffect");
			}
			if ((Object)(object)cachedMeshSlicerFragmentSpawningEffect != (Object)null && (Object)(object)cachedMeshSlicerFragmentVanishingEffect != (Object)null)
			{
				MeshSlicerFragmentScript val = sourceTable.rows.Where((Row row) => row != null && (Object)(object)row.prefab != (Object)null).SelectMany((Row row) => row.prefab.GetComponentsInChildren<MeshSlicerFragmentScript>(true)).FirstOrDefault((Func<MeshSlicerFragmentScript, bool>)((MeshSlicerFragmentScript meshSlicer) => (Object)(object)meshSlicer != (Object)null && (Object)(object)((Component)meshSlicer).gameObject != (Object)null && !((Component)meshSlicer).transform.IsChildOf(prefab.transform) && (Object)(object)meshSlicer.spawningEffect != (Object)null && (Object)(object)meshSlicer.vanishingEffect != (Object)null)) ?? throw new Exception("Could not find any MeshSlicerFragmentScript.");
				cachedMeshSlicerFragmentSpawningEffect = val.spawningEffect;
				cachedMeshSlicerFragmentVanishingEffect = val.vanishingEffect;
			}
			MeshSlicer[] componentsInChildren = prefab.GetComponentsInChildren<MeshSlicer>(true);
			foreach (MeshSlicer instance2 in componentsInChildren)
			{
				ReflectionTools.SetFieldOrProperty(instance2, "crossMat", cachedMeshSlicerCrossMat);
				ReflectionTools.SetFieldOrProperty(instance2, "crashEffect", cachedMeshSlicerCrashEffect);
				ReflectionTools.SetFieldOrProperty(instance2, "fragmentSpawningEffect", cachedMeshSlicerSpawningEffect);
				ReflectionTools.SetFieldOrProperty(instance2, "fragmentVanishingEffect", cachedMeshSlicerVanishingEffect);
			}
			MeshSlicerFragmentScript[] componentsInChildren2 = prefab.GetComponentsInChildren<MeshSlicerFragmentScript>(true);
			foreach (MeshSlicerFragmentScript val2 in componentsInChildren2)
			{
				val2.spawningEffect = cachedMeshSlicerFragmentSpawningEffect;
				val2.vanishingEffect = cachedMeshSlicerFragmentVanishingEffect;
			}
		}
	}
	public static class ReflectionTools
	{
		public static object GetFieldOrProperty(object instance, string name)
		{
			Type type = instance.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field.GetValue(instance);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null)
			{
				return property.GetValue(instance);
			}
			throw new Exception("Field/property '" + name + "' not found on " + type.FullName);
		}

		public static T GetFieldOrProperty<T>(object instance, string name)
		{
			return (T)GetFieldOrProperty(instance, name);
		}

		public static void SetFieldOrProperty(object instance, string name, object value)
		{
			Type type = instance.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(instance, value);
				return;
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null)
			{
				property.SetValue(instance, value);
				return;
			}
			throw new Exception("Field/property '" + name + "' not found on " + type.FullName);
		}
	}
	public static class LocalizationTools
	{
		public static string[] GetAvailableLocalizationKeys()
		{
			return Enum.GetNames(typeof(Language));
		}
	}
}
namespace ItemsAPI.Enums
{
	public enum KeyGroup
	{
		None,
		Small,
		Medium,
		Large
	}
	public static class KeyGroupExtensions
	{
		public static string ToGameString(this KeyGroup keyGroup)
		{
			if (1 == 0)
			{
			}
			string result = keyGroup switch
			{
				KeyGroup.None => "", 
				KeyGroup.Small => "small", 
				KeyGroup.Medium => "medium", 
				KeyGroup.Large => "large", 
				_ => "", 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
}
namespace ItemsAPI.Descriptors
{
	public class ConsumableItemDescriptor : ItemDescriptor
	{
		public ConsumeItemType ConsumeType { get; set; } = (ConsumeItemType)1;


		public BulletType BulletType { get; set; } = (BulletType)0;


		public int MaxStackCount { get; set; } = 1;


		public int DefaultProvideCount { get; set; } = 1;


		public int UseEffectId { get; set; } = 0;


		public ConsumableItemDescriptor(string lootingObjectId, string prefabAssetName, string defaultItemName)
			: base(lootingObjectId, prefabAssetName, defaultItemName)
		{
		}//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)


		public override ItemMasterInfo GetItemInfo()
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected I4, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected I4, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected I4, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			ItemConsumable_MasterData val = new ItemConsumable_MasterData
			{
				id = base.MasterId,
				looting_object_id = base.LootingObjectId,
				vending_machine_tooltip_string = ((base.DefaultVendingMachineTooltip.Length > 0) ? $"STRING_VENDING_MACHINE_TOOLTIP_{base.MasterId}" : ""),
				name = $"STRING_ITEM_NAME_{base.MasterId}",
				tool_tip_string = new List<string>(1) { $"STRING_ITEM_NAME_{base.MasterId}" },
				price_for_sell_min = base.MinPrice,
				price_for_sell_max = base.MaxPrice,
				weight = base.Weight,
				item_drop_id = 0,
				attach_socket_name = base.AttachSocketName,
				puppet_handheld_state = (int)base.PuppetHandheldState,
				use_vending_machine_exchange = base.IsExchangeableOnVendingMachine,
				is_preserved_on_wipe = base.IsPreservedOnWipe,
				handheld_auraskill_id = 0,
				handheld_abnormal_id = 0,
				spawn_fieldskill_id = 0,
				spawn_fieldskill_env_condition = 0,
				spawn_fieldskill_enclosure_condition = 0,
				spawn_fieldskill_time_min = 0,
				spawn_fieldskill_time_max = 0,
				spawn_fieldskill_wait_time = 0,
				fieldskill_spawn_rate = 0,
				spawn_fieldskill_wait_effect = new List<string>(),
				sound_aggro_per_use = 0,
				sound_aggro_in_hand_per_tick = 0,
				sound_aggro_in_hand_toggle_on_per_tick = 0,
				hide_item_by_emote = base.IsHideWhenEmote,
				is_promotion_item = false,
				is_promotion_item_hidden = false,
				consume_type = (int)ConsumeType,
				bullet_type = (int)BulletType,
				max_stack_count = MaxStackCount,
				default_provide_count = DefaultProvideCount,
				link_skill_target_effect_data_id = UseEffectId
			};
			return (ItemMasterInfo)new ItemConsumableInfo(val);
		}
	}
	public abstract class ItemDescriptor
	{
		public int MasterId { get; set; }

		public string LootingObjectId { get; set; }

		public string PrefabAssetName { get; set; }

		public string IconSpriteAssetId { get; set; }

		public string PosterIconSpriteId { get; set; }

		public string DefaultItemName { get; set; }

		public Dictionary<string, string> LocalizedItemNames { get; }

		public string DefaultVendingMachineTooltip { get; set; }

		public Dictionary<string, string> LocalizedVendingMachineTooltip { get; }

		public int MinPrice { get; set; }

		public int MaxPrice { get; set; }

		public int Weight { get; set; }

		public KeyGroup KeyGroup { get; set; }

		public string AttachSocketName { get; set; }

		public PuppetHandheldState PuppetHandheldState { get; set; }

		public bool IsHideWhenEmote { get; set; }

		public bool ForbidChange { get; set; }

		public bool IsExchangeableOnVendingMachine { get; set; }

		public bool IsPreservedOnWipe { get; set; }

		public int DefaultSpawnRate { get; set; }

		public Dictionary<int, int> SpawnRateByMap { get; set; }

		protected ItemDescriptor(string lootingObjectId, string prefabAssetName, string defaultItemName)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			LootingObjectId = lootingObjectId;
			PrefabAssetName = prefabAssetName;
			IconSpriteAssetId = string.Empty;
			PosterIconSpriteId = string.Empty;
			DefaultItemName = defaultItemName;
			LocalizedItemNames = new Dictionary<string, string>();
			DefaultVendingMachineTooltip = "";
			LocalizedVendingMachineTooltip = new Dictionary<string, string>();
			MinPrice = 5;
			MaxPrice = 10;
			Weight = 4;
			KeyGroup = KeyGroup.None;
			AttachSocketName = string.Empty;
			PuppetHandheldState = (PuppetHandheldState)0;
			IsHideWhenEmote = false;
			ForbidChange = false;
			IsExchangeableOnVendingMachine = false;
			IsPreservedOnWipe = false;
			DefaultSpawnRate = 0;
			SpawnRateByMap = new Dictionary<int, int> { { 999, 0 } };
			base..ctor();
		}

		public ItemDescriptor AddLocalizedItemName(string lang, string name)
		{
			if (!LocalizationTools.GetAvailableLocalizationKeys().Contains(lang))
			{
				throw new ArgumentException("Invalid lang key : \"" + lang + "\" is not accepted by the game.");
			}
			LocalizedItemNames.Add(lang, name);
			return this;
		}

		public ItemDescriptor AddLocalizedItemName(IDictionary<string, string> names)
		{
			foreach (KeyValuePair<string, string> name in names)
			{
				AddLocalizedItemName(name.Key, name.Value);
			}
			return this;
		}

		public LocalizationData_MasterData GetLocalizationItemName()
		{
			//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_0022: Expected O, but got Unknown
			LocalizationData_MasterData val = new LocalizationData_MasterData
			{
				key = $"STRING_ITEM_NAME_{MasterId}"
			};
			string[] availableLocalizationKeys = LocalizationTools.GetAvailableLocalizationKeys();
			foreach (string text in availableLocalizationKeys)
			{
				FieldInfo field = ((object)val).GetType().GetField(text);
				if (LocalizedItemNames.ContainsKey(text))
				{
					field.SetValue(val, LocalizedItemNames[text]);
				}
				else
				{
					field.SetValue(val, DefaultItemName);
				}
			}
			return val;
		}

		public ItemDescriptor AddLocalizedVendingMachineTooltip(string lang, string tooltip)
		{
			if (!LocalizationTools.GetAvailableLocalizationKeys().Contains(lang))
			{
				throw new ArgumentException("Invalid lang key : \"" + lang + "\" is not accepted by the game.");
			}
			LocalizedVendingMachineTooltip.Add(lang, tooltip);
			return this;
		}

		public ItemDescriptor AddLocalizedVendingMachineTooltip(IDictionary<string, string> tooltips)
		{
			foreach (KeyValuePair<string, string> tooltip in tooltips)
			{
				AddLocalizedVendingMachineTooltip(tooltip.Key, tooltip.Value);
			}
			return this;
		}

		public LocalizationData_MasterData GetLocalizationVendingMachineTooltip()
		{
			//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_0022: Expected O, but got Unknown
			LocalizationData_MasterData val = new LocalizationData_MasterData
			{
				key = $"STRING_VENDING_MACHINE_TOOLTIP_{MasterId}"
			};
			string[] availableLocalizationKeys = LocalizationTools.GetAvailableLocalizationKeys();
			foreach (string text in availableLocalizationKeys)
			{
				FieldInfo field = ((object)val).GetType().GetField(text);
				if (LocalizedVendingMachineTooltip.ContainsKey(text))
				{
					field.SetValue(val, LocalizedVendingMachineTooltip[text]);
				}
				else
				{
					field.SetValue(val, DefaultVendingMachineTooltip);
				}
			}
			return val;
		}

		public ItemDescriptor SetMapSpawnRate(int mapId, int spawnRate)
		{
			if (SpawnRateByMap.ContainsKey(mapId))
			{
				SpawnRateByMap[mapId] = spawnRate;
			}
			else
			{
				SpawnRateByMap.Add(mapId, spawnRate);
			}
			return this;
		}

		public int GetMapSpawnRate(int mapId)
		{
			int value;
			return SpawnRateByMap.TryGetValue(mapId, out value) ? value : DefaultSpawnRate;
		}

		public abstract ItemMasterInfo GetItemInfo();
	}
	public class VendingMachineDescriptor
	{
		private int itemMasterID = 0;

		private ItemDescriptor item = null;

		public int Price { get; set; }

		public Vector3 Position { get; set; }

		public Quaternion Rotation { get; set; } = new Quaternion(0f, 1f, 0f, 0f);


		public float ItemYOffset { get; set; } = 0f;


		public float ItemXRotation { get; set; } = 60f;


		public float ItemScale { get; set; } = 1f;


		public float ItemAnimationRotSpeed { get; set; } = 15f;


		public float ItemAnimationOscFreq { get; set; } = 1f;


		public float ItemAnimationOscAmp { get; set; } = 0.1f;


		public VendingMachineDescriptor(int itemMasterID, int price, Vector3 position, Quaternion? rotation = null)
		{
			//IL_0023: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			this.itemMasterID = itemMasterID;
			Price = price;
			Position = position;
			Rotation = (Quaternion)(((??)rotation) ?? new Quaternion(0f, 1f, 0f, 0f));
		}

		public VendingMachineDescriptor(ItemDescriptor item, int price, Vector3 position, Quaternion? rotation = null)
		{
			//IL_0023: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			this.item = item;
			Price = price;
			Position = position;
			Rotation = (Quaternion)(((??)rotation) ?? new Quaternion(0f, 1f, 0f, 0f));
		}

		public int GetItemMasterID()
		{
			if (itemMasterID > 0)
			{
				return itemMasterID;
			}
			if (item != null && item.MasterId > 0)
			{
				return item.MasterId;
			}
			throw new NullReferenceException("Missing vending machine Item or MasterID");
		}

		public void SetItem(int itemMasterID)
		{
			this.itemMasterID = itemMasterID;
			item = null;
		}

		public void SetItem(ItemDescriptor item)
		{
			if (!(item is ConsumableItemDescriptor))
			{
				throw new ArgumentException("Only Consumable items can be used in vending machine.");
			}
			itemMasterID = 0;
			this.item = item;
		}
	}
	public class MiscItemDescriptor : ItemDescriptor
	{
		public bool IsHidingCamera { get; set; } = false;


		public new bool IsExchangeableOnVendingMachine { get; set; } = true;


		public new int DefaultSpawnRate { get; set; } = 105;


		public MiscItemDescriptor(string lootingObjectId, string prefabAssetName, string defaultItemName)
			: base(lootingObjectId, prefabAssetName, defaultItemName)
		{
		}

		public override ItemMasterInfo GetItemInfo()
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected I4, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Expected O, but got Unknown
			ItemMiscellany_MasterData val = new ItemMiscellany_MasterData
			{
				id = base.MasterId,
				looting_object_id = base.LootingObjectId,
				vending_machine_tooltip_string = ((base.DefaultVendingMachineTooltip.Length > 0) ? $"STRING_VENDING_MACHINE_TOOLTIP_{base.MasterId}" : ""),
				name = $"STRING_ITEM_NAME_{base.MasterId}",
				tool_tip_string = new List<string>(1) { $"STRING_ITEM_NAME_{base.MasterId}" },
				price_for_sell_min = base.MinPrice,
				price_for_sell_max = base.MaxPrice,
				weight = base.Weight,
				item_drop_id = 0,
				attach_socket_name = base.AttachSocketName,
				puppet_handheld_state = (int)base.PuppetHandheldState,
				use_vending_machine_exchange = IsExchangeableOnVendingMachine,
				is_preserved_on_wipe = base.IsPreservedOnWipe,
				handheld_auraskill_id = 0,
				handheld_abnormal_id = 0,
				spawn_fieldskill_id = 0,
				spawn_fieldskill_env_condition = 0,
				spawn_fieldskill_enclosure_condition = 0,
				spawn_fieldskill_time_min = 0,
				spawn_fieldskill_time_max = 0,
				spawn_fieldskill_wait_time = 0,
				fieldskill_spawn_rate = 0,
				spawn_fieldskill_wait_effect = new List<string>(),
				sound_aggro_per_use = 0,
				sound_aggro_in_hand_per_tick = 0,
				sound_aggro_in_hand_toggle_on_per_tick = 0,
				hide_item_by_emote = base.IsHideWhenEmote,
				is_promotion_item = false,
				is_promotion_item_hidden = false,
				accessory_group = 0,
				is_hide_my_camera = IsHidingCamera,
				forbid_change = base.ForbidChange,
				key_group = base.KeyGroup.ToGameString(),
				scrap_animation_state_name = string.Empty,
				is_moving_scrap_animation = false,
				scrap_animation_loop = false,
				use_bonus_item = (base.PosterIconSpriteId.Length > 0)
			};
			return (ItemMasterInfo)new ItemMiscellanyInfo(val);
		}
	}
}
namespace ItemsAPI.Builders
{
	public static class ItemBuilder
	{
		private static MMSpriteTable iconSpriteTable;

		private static MMLootingObjectTable lootingObjectTable;

		private static DataManager dataManager;

		private static readonly Dictionary<string, AssetBundle> assets = new Dictionary<string, AssetBundle>();

		private static readonly List<ItemDescriptor> items = new List<ItemDescriptor>();

		public static ItemDescriptor[] Items => items.ToArray();

		private static int GetNewItemMasterId()
		{
			if ((Object)(object)dataManager == (Object)null || dataManager.ExcelDataManager == null)
			{
				throw new NullReferenceException("DataManager / ExcelDataManager not ready.");
			}
			return dataManager.ExcelDataManager.ItemInfoDict.Keys.Max() + 1;
		}

		public static void Initialize()
		{
			object instance = ReflectionTools.GetFieldOrProperty(Hub.s, "<tableman>k__BackingField") ?? throw new NullReferenceException("TableManager not ready.");
			iconSpriteTable = ReflectionTools.GetFieldOrProperty<MMSpriteTable>(instance, "iconSprite") ?? throw new NullReferenceException("Icon Sprite Table not ready.");
			lootingObjectTable = ReflectionTools.GetFieldOrProperty<MMLootingObjectTable>(instance, "lootingObject") ?? throw new NullReferenceException("Looting Object Table not ready.");
			dataManager = ReflectionTools.GetFieldOrProperty<DataManager>(Hub.s, "<dataman>k__BackingField") ?? throw new NullReferenceException("DataManager not ready.");
			if (dataManager.ExcelDataManager == null)
			{
				throw new NullReferenceException("ExcelDataManager not ready.");
			}
		}

		public static void RegisterAssetBundle(AssetBundle bundle)
		{
			string[] allAssetNames = bundle.GetAllAssetNames();
			foreach (string key in allAssetNames)
			{
				assets.Add(key, bundle);
			}
		}

		public static ItemDescriptor RegisterItem(ItemDescriptor itemDescriptor)
		{
			items.Add(itemDescriptor);
			return itemDescriptor;
		}

		public static int[] Build()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			HashSet<int> hashSet = new HashSet<int>();
			foreach (ItemDescriptor itemDescriptor in items.OrderBy((ItemDescriptor item) => item.LootingObjectId))
			{
				int newItemMasterId = GetNewItemMasterId();
				itemDescriptor.MasterId = newItemMasterId;
				Texture2D val = assets[itemDescriptor.IconSpriteAssetId].LoadAsset<Texture2D>(itemDescriptor.IconSpriteAssetId) ?? throw new KeyNotFoundException("Could not load icon from bundle");
				Sprite sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				Row iconRow = new Row
				{
					id = $"icon_miscellnary_custom_{newItemMasterId}",
					sprite = sprite
				};
				List<Row> list = ReflectionTools.GetFieldOrProperty<Row[]>(iconSpriteTable, "rows").ToList();
				list.RemoveAll((Row row) => row != null && row.id == iconRow.id);
				list.Add(iconRow);
				ReflectionTools.SetFieldOrProperty(iconSpriteTable, "rows", list.ToArray());
				GameObject val2 = assets[itemDescriptor.PrefabAssetName].LoadAsset<GameObject>(itemDescriptor.PrefabAssetName) ?? throw new KeyNotFoundException("Could not load prefab from bundle.");
				LootingLevelObject val3 = val2.GetComponent<LootingLevelObject>() ?? throw new MissingComponentException("Could not find LootingLevelObject component in prefab.");
				val3.itemMasterID = newItemMasterId;
				AssetTools.FixPrefabShaders(val2);
				AssetTools.FixMeshSlicers(lootingObjectTable, val2);
				Row item2 = new Row
				{
					id = itemDescriptor.LootingObjectId,
					prefab = val2,
					iconSpriteId = iconRow.id,
					posterIconSpriteId = itemDescriptor.PosterIconSpriteId
				};
				lootingObjectTable.rows.RemoveAll((Row row) => row != null && row.id == itemDescriptor.LootingObjectId);
				lootingObjectTable.rows.Add(item2);
				lootingObjectTable.ClearSkinnedItemInfos();
				LocalizationData_MasterData localizationItemName = itemDescriptor.GetLocalizationItemName();
				LocalizationData_MasterData localizationVendingMachineTooltip = itemDescriptor.GetLocalizationVendingMachineTooltip();
				ImmutableDictionary<string, LocalizationData_MasterData> immutableDictionary = dataManager.ExcelDataManager.LocalizationDict.Remove(localizationItemName.key).Add(localizationItemName.key, localizationItemName);
				if (itemDescriptor.DefaultVendingMachineTooltip.Length > 0)
				{
					immutableDictionary = immutableDictionary.Remove(localizationVendingMachineTooltip.key).Add(localizationVendingMachineTooltip.key, localizationVendingMachineTooltip);
				}
				PropertyInfo propertyInfo = typeof(ExcelDataManager).GetProperty("LocalizationDict", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("Could not find ExcelDataManager.LocalizationDict property.");
				propertyInfo.SetValue(dataManager.ExcelDataManager, immutableDictionary);
				ItemMasterInfo itemInfo = itemDescriptor.GetItemInfo();
				ImmutableDictionary<int, ItemMasterInfo> value = dataManager.ExcelDataManager.ItemInfoDict.Remove(newItemMasterId).Add(newItemMasterId, itemInfo);
				PropertyInfo propertyInfo2 = typeof(ExcelDataManager).GetProperty("ItemInfoDict", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("Could not find ExcelDataManager.ItemInfoDict property.");
				propertyInfo2.SetValue(dataManager.ExcelDataManager, value);
				if (dataManager.ExcelDataManager.GetItemInfo(newItemMasterId) == null)
				{
					throw new Exception("Injected item could not be read back from ExcelDataManager.");
				}
				hashSet.Add(newItemMasterId);
				foreach (int key in dataManager.ExcelDataManager.SpawnableItemDict.Keys)
				{
					SpawnableItemInfo val4 = dataManager.ExcelDataManager.SpawnableItemDict[key];
					int mapSpawnRate = itemDescriptor.GetMapSpawnRate(key);
					val4.MiscRateDict = val4.MiscRateDict.Add(newItemMasterId, mapSpawnRate);
				}
			}
			return hashSet.ToArray();
		}
	}
	public static class VendingMachineBuilder
	{
		private static readonly List<VendingMachineDescriptor> vendingMachines = new List<VendingMachineDescriptor>();

		public static VendingMachineDescriptor[] VendingMachines => vendingMachines.ToArray();

		public static VendingMachineDescriptor RegisterVendingMachine(VendingMachineDescriptor vendingMachineDescriptor)
		{
			vendingMachines.Add(vendingMachineDescriptor);
			return vendingMachineDescriptor;
		}

		public static string[] BuildMaintenanceScene(MaintenanceScene scene)
		{
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			Transform fieldOrProperty = ReflectionTools.GetFieldOrProperty<Transform>(scene, "maintenanceRoomRoot");
			Transform val = ((Component)fieldOrProperty).transform.Find("VendingMachine");
			GameObject gameObject = ((Component)val.GetChild(0)).gameObject;
			for (int i = 0; i < vendingMachines.Count; i++)
			{
				try
				{
					VendingMachineDescriptor vendingMachineDescriptor = vendingMachines[i];
					int itemMasterID = vendingMachineDescriptor.GetItemMasterID();
					string text = $"Vending machine_{i}_{itemMasterID}";
					if (!((Object)(object)val.Find(text) != (Object)null))
					{
						GameObject val2 = Object.Instantiate<GameObject>(gameObject, val);
						((Object)val2).name = text;
						Transform val3 = val2.transform.Find("FeedbackBound").Find("IconContainer");
						HashSet<string> iconContainerChildNames = new HashSet<string> { "Icon", "ItemRoot" };
						CollectionExtensions.Do<Transform>(from Transform child in (IEnumerable)val3
							where !iconContainerChildNames.Contains(((Object)child).name)
							select child, (Action<Transform>)delegate(Transform child)
						{
							Object.Destroy((Object)(object)((Component)child).gameObject);
						});
						val2.transform.position = vendingMachineDescriptor.Position;
						val2.transform.rotation = vendingMachineDescriptor.Rotation;
						VendingMachineLevelObject component = val2.GetComponent<VendingMachineLevelObject>();
						component.itemMasterID = itemMasterID;
						Transform fieldOrProperty2 = ReflectionTools.GetFieldOrProperty<Transform>(component, "vendingMachineItemRoot");
						fieldOrProperty2.localPosition += Vector3.up * vendingMachineDescriptor.ItemYOffset;
						fieldOrProperty2.eulerAngles = new Vector3(vendingMachineDescriptor.ItemXRotation, 0f, 0f);
						fieldOrProperty2.localScale = new Vector3(vendingMachineDescriptor.ItemScale, vendingMachineDescriptor.ItemScale, vendingMachineDescriptor.ItemScale);
						SimpleTransformAnimation component2 = ((Component)val3).GetComponent<SimpleTransformAnimation>();
						ReflectionTools.SetFieldOrProperty(component2, "rotY", vendingMachineDescriptor.ItemAnimationRotSpeed);
						ReflectionTools.SetFieldOrProperty(component2, "sinMoveYFreq", vendingMachineDescriptor.ItemAnimationOscFreq);
						ReflectionTools.SetFieldOrProperty(component2, "sinMoveYAmp", vendingMachineDescriptor.ItemAnimationOscAmp);
						hashSet.Add(text);
					}
				}
				catch (Exception msg)
				{
					ItemsAPI.Log(msg);
				}
			}
			return hashSet.ToArray();
		}

		public static int[] BuildShopPrices(List<(int masterid, int price)> shopPrices)
		{
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < vendingMachines.Count; i++)
			{
				try
				{
					int itemMasterID = vendingMachines[i].GetItemMasterID();
					shopPrices.RemoveAll(((int masterid, int price) item) => item.masterid == itemMasterID);
					shopPrices.Add((itemMasterID, vendingMachines[i].Price));
					hashSet.Add(itemMasterID);
				}
				catch (Exception msg)
				{
					ItemsAPI.Log(msg);
				}
			}
			return hashSet.ToArray();
		}
	}
}