Decompiled source of proflupins Amazing Weapons v1.4.1

plugins/proflupins_Amazing_Weapons.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("proflupins_Amazing_Weapons")]
[assembly: AssemblyDescription("Fire, Lightning, Poison...control all these--and the power of the gods!")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("proflupin")]
[assembly: AssemblyProduct("proflupins_Amazing_Weapons")]
[assembly: AssemblyCopyright("Copyright © proflupin 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7e61f470-fb41-4c6b-a654-4e199ea7d009")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
namespace proflupins_Amazing_Weapons;

[BepInPlugin("org.proflupins.amazingweapons", "proflupins_Amazing_Weapons", "1.2.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class JotunnModStub : BaseUnityPlugin
{
	private readonly ManualLogSource _logger;

	private static readonly string[] WeaponTypes = new string[8] { "EssenceoftheGods", "SledgeCheaty", "SwordCheaty", "Flametongue", "Frostbite", "PickStone", "SwordIronLightning", "SwordIronPoison" };

	private static readonly string[] DamageTypes = new string[9] { "blunt", "slash", "pierce", "chop", "fire", "frost", "lightning", "poison", "spirit" };

	private readonly Dictionary<string, ConfigEntry<string>> _nameConfigs = new Dictionary<string, ConfigEntry<string>>();

	private readonly Dictionary<string, Dictionary<string, ConfigEntry<float>>> _damageConfigs = new Dictionary<string, Dictionary<string, ConfigEntry<float>>>();

	private readonly Dictionary<string, ConfigEntry<string>> _recipeConfigs = new Dictionary<string, ConfigEntry<string>>();

	private ConfigEntry<float> _cheatyAttackForceConfig;

	private ConfigEntry<float> _cheatyAttackHeightConfig;

	private ConfigEntry<float> _cheatyAttackRadiusConfig;

	public JotunnModStub()
	{
		_logger = ((BaseUnityPlugin)this).Logger;
	}

	private void Awake()
	{
		try
		{
			_logger.LogInfo((object)"Initializing proflupins_Amazing_Weapons...");
			InitializeConfig();
			_logger.LogInfo((object)"Config initialized.");
			PrefabManager.OnVanillaPrefabsAvailable += AddCustomItems;
			LocalizationManager.OnLocalizationAdded += AddLocalization;
		}
		catch (Exception arg)
		{
			_logger.LogError((object)$"Awake failed: {arg}");
		}
	}

	private void InitializeConfig()
	{
		string[] weaponTypes = WeaponTypes;
		foreach (string text in weaponTypes)
		{
			_nameConfigs[text] = ((BaseUnityPlugin)this).Config.Bind<string>("Names", text, "$item_" + text.ToLower(), "Display name token for " + text);
			if (text != "EssenceoftheGods")
			{
				_damageConfigs[text] = new Dictionary<string, ConfigEntry<float>>();
				string[] damageTypes = DamageTypes;
				foreach (string text2 in damageTypes)
				{
					_damageConfigs[text][text2] = ((BaseUnityPlugin)this).Config.Bind<float>("Damage." + text, text2, GetDefaultDamage(text, text2), text2 + " damage for " + text);
					_logger.LogInfo((object)$"Bound {text} {text2} = {_damageConfigs[text][text2].Value}");
				}
			}
			_recipeConfigs[text] = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", text, GetDefaultRecipe(text), "Recipe JSON for " + text);
		}
		_cheatyAttackForceConfig = ((BaseUnityPlugin)this).Config.Bind<float>("CheatySledge.Special", "AttackForce", 10000f, "Force multiplier");
		_cheatyAttackHeightConfig = ((BaseUnityPlugin)this).Config.Bind<float>("CheatySledge.Special", "AttackHeight", 200f, "Attack height");
		_cheatyAttackRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<float>("CheatySledge.Special", "AttackRadius", 100f, "Attack radius");
		((BaseUnityPlugin)this).Config.Save();
	}

	private float GetDefaultDamage(string weapon, string damageType)
	{
		if (1 == 0)
		{
		}
		float result;
		switch (weapon)
		{
		case "Flametongue":
			if (!(damageType == "slash"))
			{
				if (!(damageType == "fire"))
				{
					goto default;
				}
				result = 60f;
				break;
			}
			result = 100f;
			break;
		case "Frostbite":
			if (!(damageType == "slash"))
			{
				if (!(damageType == "frost"))
				{
					goto default;
				}
				result = 60f;
				break;
			}
			result = 100f;
			break;
		case "SledgeCheaty":
			if (!(damageType == "blunt"))
			{
				goto default;
			}
			result = 999f;
			break;
		case "SwordCheaty":
			if (!(damageType == "slash"))
			{
				if (!(damageType == "pierce"))
				{
					goto default;
				}
				result = 500f;
				break;
			}
			result = 999f;
			break;
		case "SwordIronLightning":
			if (!(damageType == "slash"))
			{
				if (!(damageType == "lightning"))
				{
					goto default;
				}
				result = 60f;
				break;
			}
			result = 100f;
			break;
		case "SwordIronPoison":
			if (!(damageType == "slash"))
			{
				if (!(damageType == "poison"))
				{
					goto default;
				}
				result = 60f;
				break;
			}
			result = 100f;
			break;
		case "PickStone":
			if (!(damageType == "pierce"))
			{
				goto default;
			}
			result = 25f;
			break;
		default:
			result = 0f;
			break;
		}
		if (1 == 0)
		{
		}
		return result;
	}

	private string GetDefaultRecipe(string weapon)
	{
		if (1 == 0)
		{
		}
		string result = weapon switch
		{
			"EssenceoftheGods" => "{\"station\":\"piece_artisanstation\",\"minLevel\":1,\"amount\":1,\"requirements\":[{\"item\":\"TrophyEikthyr\",\"amount\":1},{\"item\":\"TrophyTheElder\",\"amount\":1},{\"item\":\"TrophyBonemass\",\"amount\":1},{\"item\":\"TrophyDragonQueen\",\"amount\":1},{\"item\":\"TrophyGoblinKing\",\"amount\":1},{\"item\":\"TrophyQueen\",\"amount\":1},{\"item\":\"TrophyFader\",\"amount\":1}]}", 
			"Flametongue" => "{\"station\":\"forge\",\"minLevel\":3,\"amount\":1,\"requirements\":[{\"item\":\"Iron\",\"amount\":30},{\"item\":\"SurtlingCore\",\"amount\":5}]}", 
			"Frostbite" => "{\"station\":\"forge\",\"minLevel\":3,\"amount\":1,\"requirements\":[{\"item\":\"Iron\",\"amount\":30},{\"item\":\"FreezeGland\",\"amount\":5}]}", 
			"PickStone" => "{\"station\":\"piece_workbench\",\"minLevel\":1,\"amount\":1,\"requirements\":[{\"item\":\"Stone\",\"amount\":10},{\"item\":\"Wood\",\"amount\":5}]}", 
			"SwordIronLightning" => "{\"station\":\"forge\",\"minLevel\":3,\"amount\":1,\"requirements\":[{\"item\":\"Iron\",\"amount\":30},{\"item\":\"Thunderstone\",\"amount\":5}]}", 
			"SwordIronPoison" => "{\"station\":\"forge\",\"minLevel\":3,\"amount\":1,\"requirements\":[{\"item\":\"Iron\",\"amount\":30},{\"item\":\"Ooze\",\"amount\":10},{\"item\":\"Wood\",\"amount\":8},{\"item\":\"Guck\",\"amount\":10}]}", 
			"SledgeCheaty" => "{\"station\":\"blackforge\",\"minLevel\":7,\"amount\":1,\"requirements\":[{\"item\":\"FlametalNew\",\"amount\":40},{\"item\":\"Finewood\",\"amount\":20},{\"item\":\"EssenceoftheGods\",\"amount\":1}]}", 
			"SwordCheaty" => "{\"station\":\"blackforge\",\"minLevel\":7,\"amount\":1,\"requirements\":[{\"item\":\"FlametalNew\",\"amount\":40},{\"item\":\"Finewood\",\"amount\":20},{\"item\":\"EssenceoftheGods\",\"amount\":1}]}", 
			_ => "{}", 
		};
		if (1 == 0)
		{
		}
		return result;
	}

	private void AddLocalization()
	{
		try
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_essenceofthegods", "Gods' Essence" },
				{ "item_sledgecheaty", "CheatySledge" },
				{ "item_swordcheaty", "CheatSword" },
				{ "item_flametongue", "Flametongue" },
				{ "item_frostbite", "Frostbite" },
				{ "item_pickstone", "Stone Pick" },
				{ "item_swordironlightning", "Crackle" },
				{ "item_swordironpoison", "Venomfang" }
			});
			_logger.LogInfo((object)"Localization added.");
		}
		catch (Exception arg)
		{
			_logger.LogError((object)$"AddLocalization failed: {arg}");
		}
	}

	private void AddCustomItems()
	{
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Expected O, but got Unknown
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05db: Expected O, but got Unknown
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0603: Unknown result type (might be due to invalid IL or missing references)
		//IL_0608: Unknown result type (might be due to invalid IL or missing references)
		//IL_061a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0622: Unknown result type (might be due to invalid IL or missing references)
		//IL_062b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0650: Expected O, but got Unknown
		//IL_064b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0655: Expected O, but got Unknown
		try
		{
			string[] weaponTypes = WeaponTypes;
			foreach (string text in weaponTypes)
			{
				if (1 == 0)
				{
				}
				string text2 = text switch
				{
					"EssenceoftheGods" => "Eitr", 
					"SledgeCheaty" => "SledgeIron", 
					"SwordCheaty" => "SwordIron", 
					"Flametongue" => "SwordIron", 
					"Frostbite" => "SwordIron", 
					"PickStone" => "PickaxeStone", 
					"SwordIronLightning" => "SwordIron", 
					"SwordIronPoison" => "SwordIron", 
					_ => null, 
				};
				if (1 == 0)
				{
				}
				string text3 = text2;
				if (text3 == null)
				{
					continue;
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab(text, text3);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				component.m_itemData.m_shared.m_name = _nameConfigs[text].Value;
				if (text == "EssenceoftheGods")
				{
					component.m_itemData.m_shared.m_maxStackSize = 50;
					component.m_itemData.m_shared.m_weight = 0.1f;
					component.m_itemData.m_shared.m_maxQuality = 1;
				}
				else
				{
					component.m_itemData.m_shared.m_maxStackSize = 1;
					SharedData shared = component.m_itemData.m_shared;
					if (1 == 0)
					{
					}
					SkillType skillType = ((text == "SledgeCheaty") ? ((SkillType)3) : ((!(text == "PickStone")) ? ((SkillType)1) : ((SkillType)12)));
					if (1 == 0)
					{
					}
					shared.m_skillType = skillType;
					component.m_itemData.m_shared.m_toolTier = ((text == "PickStone") ? 1 : 4);
					component.m_itemData.m_shared.m_weight = ((text == "SledgeCheaty") ? 5f : 2.5f);
					if (_damageConfigs.ContainsKey(text))
					{
						DamageTypes damages = component.m_itemData.m_shared.m_damages;
						damages.m_blunt = _damageConfigs[text]["blunt"].Value;
						damages.m_slash = _damageConfigs[text]["slash"].Value;
						damages.m_pierce = _damageConfigs[text]["pierce"].Value;
						damages.m_chop = _damageConfigs[text]["chop"].Value;
						damages.m_fire = _damageConfigs[text]["fire"].Value;
						damages.m_frost = _damageConfigs[text]["frost"].Value;
						damages.m_lightning = _damageConfigs[text]["lightning"].Value;
						damages.m_poison = _damageConfigs[text]["poison"].Value;
						damages.m_spirit = _damageConfigs[text]["spirit"].Value;
					}
					if (text == "SledgeCheaty")
					{
						component.m_itemData.m_shared.m_attackForce = _cheatyAttackForceConfig.Value;
						Attack componentInChildren = val.GetComponentInChildren<Attack>();
						if (componentInChildren != null)
						{
							componentInChildren.m_attackHeight = _cheatyAttackHeightConfig.Value;
							componentInChildren.m_attackRange = _cheatyAttackRadiusConfig.Value;
						}
					}
				}
				ItemManager.Instance.AddItem(new CustomItem(val, true));
				string value = _recipeConfigs[text].Value;
				if (string.IsNullOrEmpty(value) || !(value != "{}"))
				{
					continue;
				}
				try
				{
					string input = value.Replace("\\\"", "\"");
					string value2 = Regex.Match(input, "\"station\":\"([^\"]+)\"").Groups[1].Value;
					int minStationLevel = int.Parse(Regex.Match(input, "\"minLevel\":(\\d+)").Groups[1].Value);
					int amount = int.Parse(Regex.Match(input, "\"amount\":(\\d+)").Groups[1].Value);
					List<RequirementConfig> list = new List<RequirementConfig>();
					foreach (Match item in Regex.Matches(input, "\"item\":\"([^\"]+)\",\"amount\":(\\d+)"))
					{
						list.Add(new RequirementConfig(item.Groups[1].Value, int.Parse(item.Groups[2].Value), 0, true));
					}
					ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
					{
						Name = "Recipe_" + text,
						Item = text,
						CraftingStation = value2,
						MinStationLevel = minStationLevel,
						Amount = amount,
						Requirements = list.ToArray()
					}));
				}
				catch (Exception arg)
				{
					_logger.LogError((object)$"Failed to parse recipe for {text}: {arg}");
				}
			}
		}
		catch (Exception arg2)
		{
			_logger.LogError((object)$"AddCustomItems failed: {arg2}");
		}
	}
}