Decompiled source of Gunsmith v0.1.0

plugins/Gunsmith/Gunsmith.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("Gunsmith")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Gunsmith")]
[assembly: AssemblyTitle("Gunsmith")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Gunsmith;

[BepInPlugin("local.gunsmith", "Gunsmith", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	private readonly Dictionary<string, Mesh> meshCache = new Dictionary<string, Mesh>();

	private static readonly MethodInfo LoadImage = typeof(ImageConversion).GetMethod("LoadImage", new Type[2]
	{
		typeof(Texture2D),
		typeof(byte[])
	});

	private const string Guid = "local.gunsmith";

	private ConfigEntry<string> language;

	private static readonly Quaternion MeshToAttach = Quaternion.LookRotation(Vector3.forward, Vector3.up) * Quaternion.Inverse(Quaternion.LookRotation(Vector3.up, Vector3.forward));

	private const float GunScale = 1.12f;

	private static readonly Vector3 GripInAttach = new Vector3(0f, 0.01f, -0.12f) - MeshToAttach * (new Vector3(0f, 0.06f, 0.04f) * 1.725f * 0.75f);

	private static ConfigEntry<string> muzzleFx;

	private static ConfigEntry<float> muzzleScale;

	private readonly Dictionary<string, GameObject> shrunk = new Dictionary<string, GameObject>();

	private string MeshDir => Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "meshes");

	private Mesh BundleMesh(string name)
	{
		//IL_00a3: 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_00c1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: 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_0104: Expected O, but got Unknown
		if (meshCache.TryGetValue(name, out var value))
		{
			return value;
		}
		string path = Path.Combine(MeshDir, name + ".gsm");
		if (!File.Exists(path))
		{
			return meshCache[name] = null;
		}
		string[] array = File.ReadAllLines(path);
		Vector3[] array2 = (Vector3[])(object)new Vector3[array.Length];
		Vector2[] array3 = (Vector2[])(object)new Vector2[array.Length];
		int[] array4 = new int[array.Length];
		for (int i = 0; i < array.Length; i++)
		{
			string[] p = array[i].Split(new char[1] { ' ' });
			array2[i] = new Vector3(F(0), F(1), F(2));
			array3[i] = new Vector2(F(3), F(4));
			array4[i] = i;
			float F(int k)
			{
				return float.Parse(p[k], CultureInfo.InvariantCulture);
			}
		}
		Mesh val2 = new Mesh
		{
			name = name,
			vertices = array2,
			uv = array3,
			triangles = array4
		};
		val2.RecalculateNormals();
		val2.RecalculateBounds();
		return meshCache[name] = val2;
	}

	private Sprite LoadIcon(string id)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = LoadTexture(id + "_icon");
		if (!Object.op_Implicit((Object)(object)val))
		{
			return null;
		}
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
	}

	private Texture2D LoadTexture(string name)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		string path = Path.Combine(MeshDir, name + ".png");
		if (!File.Exists(path))
		{
			return null;
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
		{
			name = name
		};
		LoadImage.Invoke(null, new object[2]
		{
			val,
			File.ReadAllBytes(path)
		});
		return val;
	}

	private void Awake()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		language = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "Auto", new ConfigDescription("Item names when the game runs in English. Auto = Korean if a Korean patch mod is installed.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "Korean", "English" }), Array.Empty<object>()));
		BindVisualConfig();
		PrefabManager.OnVanillaPrefabsAvailable += Register;
	}

	private void Register()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= Register;
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
		AmmoDef[] ammo = Data.Ammo;
		foreach (AmmoDef d in ammo)
		{
			AddAmmo(d, dictionary, dictionary2);
		}
		WeaponDef[] weapons = Data.Weapons;
		foreach (WeaponDef w in weapons)
		{
			AddWeapon(w, dictionary, dictionary2);
		}
		CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
		string text = "Korean";
		localization.AddTranslation(ref text, dictionary2);
		text = "English";
		localization.AddTranslation(ref text, UseKoreanInEnglish() ? dictionary2 : dictionary);
	}

	private bool UseKoreanInEnglish()
	{
		if (language.Value == "Korean")
		{
			return true;
		}
		if (language.Value == "English")
		{
			return false;
		}
		return Chainloader.PluginInfos.Keys.Any((string g) => g.IndexOf("korean", StringComparison.OrdinalIgnoreCase) >= 0);
	}

	private void AddWeapon(WeaponDef w, Dictionary<string, string> en, Dictionary<string, string> ko)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		string text = w.Id.ToLowerInvariant();
		CustomItem val = new CustomItem(w.Id, "CrossbowArbalest", new ItemConfig
		{
			Name = "$" + text,
			Description = "$" + text + "_desc",
			Icon = LoadIcon(w.Mesh),
			CraftingStation = w.Station,
			MinStationLevel = w.Level,
			Requirements = w.Recipe
		});
		en[text] = w.En;
		ko[text] = w.Ko;
		en[text + "_desc"] = "Fires like a crossbow, hits like a gun.";
		ko[text + "_desc"] = "석궁처럼 쏘고 총처럼 맞힌다.";
		SharedData shared = val.ItemDrop.m_itemData.m_shared;
		shared.m_ammoType = w.Ammo;
		shared.m_skillType = (SkillType)14;
		shared.m_damages = new DamageTypes
		{
			m_blunt = w.Blunt,
			m_pierce = w.Pierce
		};
		shared.m_damagesPerLevel = default(DamageTypes);
		shared.m_maxQuality = 1;
		Attack attack = shared.m_attack;
		attack.m_reloadTime = w.Reload;
		attack.m_projectiles = w.Projectiles;
		attack.m_projectileBursts = w.Bursts;
		if (w.Bursts > 1)
		{
			attack.m_burstInterval = 0.1f;
		}
		if (w.Projectiles > 1)
		{
			attack.m_projectileAccuracy = 6f;
			attack.m_projectileAccuracyMin = 3f;
		}
		attack.m_recoilPushback = ((w.Projectiles > 1) ? 1.5f : 0.8f);
		attack.m_raiseSkillAmount /= (float)(w.Projectiles * w.Bursts);
		Mesh val2 = BundleMesh(w.Mesh);
		if (Object.op_Implicit((Object)(object)val2))
		{
			ReplaceVisual(val.ItemPrefab, val2, LoadTexture(w.Mesh + "_albedo"), w.Prop);
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[GS] mesh " + w.Mesh + " missing; " + w.Id + " keeps the arbalest look"));
		}
		if (w.Gunpowder)
		{
			AddMuzzleEffects(shared);
		}
		ItemManager.Instance.AddItem(val);
	}

	private void ReplaceVisual(GameObject prefab, Mesh mesh, Texture2D tex, string prop)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_0075: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_00a5: 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)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		Transform val = prefab.transform.Find("attach");
		Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
		Material val2 = new Material(((Renderer)((Component)val.Find("Unloaded")).GetComponent<MeshRenderer>()).sharedMaterial)
		{
			name = ((Object)mesh).name + "_mat",
			mainTexture = (Texture)(object)tex
		};
		Renderer[] array = componentsInChildren;
		for (int i = 0; i < array.Length; i++)
		{
			array[i].enabled = false;
		}
		GameObject val3 = new GameObject("GS_visual");
		val3.transform.SetParent(val, false);
		val3.AddComponent<MeshFilter>().sharedMesh = mesh;
		((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = val2;
		val3.transform.localRotation = MeshToAttach;
		val3.transform.localScale = Vector3.one * 1.12f;
		val3.transform.localPosition = GripInAttach;
		GunPoseDriver gunPoseDriver = val3.AddComponent<GunPoseDriver>();
		Mesh val4 = ((prop != null) ? BundleMesh(prop) : null);
		if (Object.op_Implicit((Object)(object)val4))
		{
			gunPoseDriver.propMesh = val4;
			gunPoseDriver.propMat = new Material(val2)
			{
				name = prop + "_mat",
				mainTexture = (Texture)(object)LoadTexture(prop + "_albedo")
			};
		}
	}

	private void BindVisualConfig()
	{
		muzzleFx = ((BaseUnityPlugin)this).Config.Bind<string>("Visual", "MuzzleEffects", "fx_turret_fire,sfx_bombdynamite_explosion", "Vanilla effect prefabs spawned at the muzzle on each shot (comma separated)");
		muzzleScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "MuzzleEffectScale", 0.3f, "Scale applied to the visual muzzle effects");
	}

	private void AddMuzzleEffects(SharedData shared)
	{
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		Attack attack = shared.m_attack;
		List<EffectData> list = ((IEnumerable<EffectData>)(((object)attack.m_burstEffect.m_effectPrefabs) ?? ((object)new EffectData[0]))).ToList();
		foreach (string item in from n in muzzleFx.Value.Split(new char[1] { ',' })
			select n.Trim() into n
			where n.Length > 0
			select n)
		{
			GameObject val = Cache.GetPrefab<GameObject>(item);
			if (Object.op_Implicit((Object)(object)val) && !item.StartsWith("sfx"))
			{
				if (!shrunk.TryGetValue(item, out var value))
				{
					value = (shrunk[item] = Shrunk(val, muzzleScale.Value));
				}
				val = value;
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				list.Add(new EffectData
				{
					m_prefab = val,
					m_enabled = true
				});
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[GS] effect prefab not found: " + item));
			}
		}
		attack.m_burstEffect = new EffectList
		{
			m_effectPrefabs = list.ToArray()
		};
	}

	private static GameObject Shrunk(GameObject src, float k)
	{
		//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = PrefabManager.Instance.CreateClonedPrefab("GS_" + ((Object)src).name, src);
		Transform transform = val.transform;
		transform.localScale *= k;
		ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			MainModule main = componentsInChildren[i].main;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
		}
		Light[] componentsInChildren2 = val.GetComponentsInChildren<Light>(true);
		foreach (Light obj in componentsInChildren2)
		{
			obj.range *= k;
		}
		PrefabManager.Instance.AddPrefab(val);
		return val;
	}

	private void AddAmmo(AmmoDef d, Dictionary<string, string> en, Dictionary<string, string> ko)
	{
		//IL_0026: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_0070: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Expected O, but got Unknown
		string text = d.Id.ToLowerInvariant();
		CustomItem val = new CustomItem(d.Id, d.IsPowder ? "Coal" : "BoltBone", new ItemConfig
		{
			Name = "$" + text,
			Description = "$" + text + "_desc",
			Icon = LoadIcon(d.Id),
			CraftingStation = d.Station,
			MinStationLevel = d.Level,
			Amount = d.Amount,
			Requirements = d.Recipe
		});
		en[text] = d.En;
		ko[text] = d.Ko;
		en[text + "_desc"] = (d.IsPowder ? "Gunpowder for crafting ammunition." : "Gun ammunition.");
		ko[text + "_desc"] = (d.IsPowder ? "탄을 만드는 화약." : "총에 쓰는 탄.");
		if (d.IsPowder)
		{
			ItemManager.Instance.AddItem(val);
			return;
		}
		SharedData shared = val.ItemDrop.m_itemData.m_shared;
		shared.m_ammoType = d.Key;
		shared.m_damages = new DamageTypes
		{
			m_blunt = d.Blunt,
			m_pierce = d.Pierce,
			m_spirit = d.Spirit,
			m_frost = d.Frost,
			m_lightning = d.Lightning,
			m_fire = d.Fire
		};
		Mesh val2 = BundleMesh("T2_shot");
		Material mat = new Material(((Renderer)val.ItemPrefab.GetComponentInChildren<MeshRenderer>(true)).sharedMaterial)
		{
			mainTexture = (Texture)(object)LoadTexture("T2_handcannon_albedo")
		};
		if (Object.op_Implicit((Object)(object)val2))
		{
			Reskin(val.ItemPrefab.transform, val2, mat, 2.5f);
		}
		GameObject val3 = PrefabManager.Instance.CreateClonedPrefab(d.Id + "_projectile", shared.m_attack.m_attackProjectile);
		if (Object.op_Implicit((Object)(object)val2))
		{
			Reskin(val3.transform, val2, mat, 1.5f);
		}
		Projectile component = val3.GetComponent<Projectile>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.m_respawnItemOnHit = false;
		}
		PrefabManager.Instance.AddPrefab(val3);
		shared.m_attack.m_attackProjectile = val3;
		ItemManager.Instance.AddItem(val);
	}

	private static void Reskin(Transform root, Mesh mesh, Material mat, float scale)
	{
		//IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		MeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshRenderer>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Renderer)componentsInChildren[i]).enabled = false;
		}
		GameObject val = new GameObject("GS_ball");
		val.transform.SetParent(root, false);
		val.transform.localScale = Vector3.one * scale;
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = mat;
	}
}
internal class GunPoseDriver : MonoBehaviour
{
	private static readonly Func<Player, bool> IsReloading = AccessTools.MethodDelegate<Func<Player, bool>>(AccessTools.Method(typeof(Player), "IsReloadActionQueued", (Type[])null, (Type[])null), (object)null, true);

	private const float ForwardTilt = 0.3f;

	private const float GripLift = 0.08f;

	private const float TwoHanded = 0.4f;

	public Mesh propMesh;

	public Material propMat;

	private const float PropScale = 1.8f;

	private static readonly Vector3 PropPos = new Vector3(0f, 0.06f, 0.03f);

	private static readonly Vector3 PropEuler = new Vector3(0f, 0f, 90f);

	private Player owner;

	private Transform rightHand;

	private Transform forearm;

	private GameObject prop;

	private float reloadStart = -1f;

	private Quaternion baseRot;

	private Vector3 basePos;

	private void Start()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: 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)
		owner = ((Component)this).GetComponentInParent<Player>();
		rightHand = (Object.op_Implicit((Object)(object)owner) ? ((Component)owner).GetComponent<VisEquipment>().m_rightHand : null);
		Transform parent = ((Component)this).transform.parent;
		while (Object.op_Implicit((Object)(object)parent) && !Object.op_Implicit((Object)(object)forearm))
		{
			if (((Object)parent).name.Contains("ForeArm"))
			{
				forearm = parent;
			}
			parent = parent.parent;
		}
		baseRot = ((Component)this).transform.localRotation;
		basePos = ((Component)this).transform.localPosition;
		if (Object.op_Implicit((Object)(object)rightHand) && Object.op_Implicit((Object)(object)propMesh))
		{
			prop = new GameObject("GS_handprop");
			prop.transform.SetParent(rightHand, false);
			prop.transform.localPosition = PropPos;
			prop.transform.localEulerAngles = PropEuler;
			prop.transform.localScale = Vector3.one * 1.8f;
			prop.AddComponent<MeshFilter>().sharedMesh = propMesh;
			((Renderer)prop.AddComponent<MeshRenderer>()).sharedMaterial = propMat;
			prop.SetActive(false);
		}
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)prop))
		{
			Object.Destroy((Object)(object)prop);
		}
	}

	private void HideForeignRenderers()
	{
		Renderer[] componentsInChildren = ((Component)((Component)this).transform.parent).GetComponentsInChildren<Renderer>();
		foreach (Renderer val in componentsInChildren)
		{
			if (val.enabled && !((Component)val).transform.IsChildOf(((Component)this).transform))
			{
				val.enabled = false;
			}
		}
	}

	private void LateUpdate()
	{
		//IL_0007: 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_00d5: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: 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_013a: 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_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: 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_019b: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.localRotation = baseRot;
		((Component)this).transform.localPosition = basePos;
		HideForeignRenderers();
		bool flag = Object.op_Implicit((Object)(object)owner) && IsReloading(owner);
		if (!flag)
		{
			reloadStart = -1f;
		}
		else if (reloadStart < 0f)
		{
			reloadStart = Time.time;
		}
		if (Object.op_Implicit((Object)(object)prop))
		{
			prop.SetActive(flag && Time.time - reloadStart > 0.3f);
		}
		if (!(!Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)rightHand) || ((Character)owner).InAttack() || flag) && !(Vector3.Distance(rightHand.position, ((Component)this).transform.position) < 0.4f))
		{
			Vector3 val = ((Component)this).transform.TransformDirection(Vector3.up);
			Vector3 val2;
			Vector3 val3;
			if (!Object.op_Implicit((Object)(object)forearm))
			{
				val2 = Vector3.down;
			}
			else
			{
				val3 = ((Component)this).transform.parent.position - forearm.position;
				val2 = ((Vector3)(ref val3)).normalized;
			}
			Vector3 val4 = val2;
			val3 = Vector3.ProjectOnPlane(((Component)owner).transform.forward, Vector3.up);
			val3 = Vector3.Slerp(val4, ((Vector3)(ref val3)).normalized, 0.3f);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			Quaternion val5 = Quaternion.FromToRotation(val, normalized);
			((Component)this).transform.SetPositionAndRotation(((Component)this).transform.parent.position - val4 * 0.08f, val5 * ((Component)this).transform.rotation);
		}
	}
}
internal class WeaponDef
{
	public string Id;

	public string Mesh;

	public string En;

	public string Ko;

	public string Station;

	public string Ammo;

	public int Level;

	public int Projectiles = 1;

	public int Bursts = 1;

	public float Blunt;

	public float Pierce;

	public float Reload;

	public string Prop = "GS_cartridge";

	public bool Gunpowder = true;

	public RequirementConfig[] Recipe;
}
internal class AmmoDef
{
	public string Id;

	public string Key;

	public string En;

	public string Ko;

	public string Station;

	public int Level = 1;

	public int Amount = 10;

	public float Blunt;

	public float Pierce;

	public float Spirit;

	public float Frost;

	public float Lightning;

	public float Fire;

	public RequirementConfig[] Recipe;

	public bool IsPowder => Key == null;
}
internal static class Data
{
	public const string Stone = "$ammo_gs_stone";

	public const string Shot = "$ammo_gs_shot";

	public const string Ball = "$ammo_gs_ball";

	public static readonly WeaponDef[] Weapons = new WeaponDef[8]
	{
		new WeaponDef
		{
			Id = "GS_T1_StoneSling",
			Mesh = "T1_stonesling",
			En = "Stone-sling Crossbow",
			Ko = "돌팔매 석궁",
			Station = "piece_workbench",
			Level = 1,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("Wood", 10),
				R("Stone", 6),
				R("LeatherScraps", 4)
			},
			Blunt = 36.35f,
			Reload = 2.5f,
			Ammo = "$ammo_gs_stone",
			Prop = null,
			Gunpowder = false
		},
		new WeaponDef
		{
			Id = "GS_T2_HandCannon",
			Mesh = "T2_handcannon",
			En = "Bronze Hand Cannon",
			Ko = "청동 화통",
			Station = "forge",
			Level = 1,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				R("Bronze", 8),
				R("FineWood", 4),
				R("Wood", 6),
				R("DeerHide", 2)
			},
			Blunt = 10f,
			Projectiles = 5,
			Reload = 4.5f,
			Ammo = "$ammo_gs_shot"
		},
		new WeaponDef
		{
			Id = "GS_T3_Matchlock",
			Mesh = "T3_matchlock",
			En = "Iron Matchlock",
			Ko = "철 화승총",
			Station = "forge",
			Level = 2,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				R("Iron", 12),
				R("ElderBark", 10),
				R("Guck", 4),
				R("LeatherScraps", 4)
			},
			Pierce = 71.6f,
			Reload = 4.5f,
			Ammo = "$ammo_gs_ball"
		},
		new WeaponDef
		{
			Id = "GS_T4_Flintlock",
			Mesh = "T4_flintlock",
			En = "Silver Flintlock",
			Ko = "은장 부싯돌총",
			Station = "forge",
			Level = 3,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				R("Silver", 10),
				R("Iron", 4),
				R("Flint", 8),
				R("WolfPelt", 2)
			},
			Pierce = 112.6f,
			Reload = 4f,
			Ammo = "$ammo_gs_ball"
		},
		new WeaponDef
		{
			Id = "GS_T5_RifledMusket",
			Mesh = "T5_rifledmusket",
			En = "Black-metal Rifled Musket",
			Ko = "흑철 강선 머스킷",
			Station = "forge",
			Level = 4,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("BlackMetal", 15),
				R("FineWood", 8),
				R("LinenThread", 6)
			},
			Pierce = 96.1f,
			Reload = 4f,
			Ammo = "$ammo_gs_ball"
		},
		new WeaponDef
		{
			Id = "GS_T5b_Blunderbuss",
			Mesh = "T5b_blunderbuss",
			En = "Black-metal Blunderbuss",
			Ko = "흑철 블런더버스",
			Station = "forge",
			Level = 4,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("BlackMetal", 12),
				R("Wood", 10),
				R("LinenThread", 4)
			},
			Pierce = 14.36f,
			Projectiles = 7,
			Reload = 4.5f,
			Ammo = "$ammo_gs_shot"
		},
		new WeaponDef
		{
			Id = "GS_T6_RuneRifle",
			Mesh = "T6_runerifle",
			En = "Dvergr Rune Rifle",
			Ko = "드베르그 룬 소총",
			Station = "blackforge",
			Level = 1,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				R("YggdrasilWood", 10),
				R("Carapace", 12),
				R("Eitr", 6),
				R("BlackCore", 1)
			},
			Pierce = 272.8f,
			Reload = 4f,
			Ammo = "$ammo_gs_ball",
			Prop = "GS_eitrcell"
		},
		new WeaponDef
		{
			Id = "GS_T7_FlametalRepeater",
			Mesh = "T7_flametalrepeater",
			En = "Flametal Repeater",
			Ko = "플라메탈 연발총",
			Station = "blackforge",
			Level = 3,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				R("FlametalNew", 12),
				R("Blackwood", 10),
				R("CeramicPlate", 4),
				R("AskHide", 2)
			},
			Pierce = 79.77f,
			Bursts = 3,
			Reload = 4.5f,
			Ammo = "$ammo_gs_ball",
			Prop = "GS_flameclip"
		}
	};

	public const string BlackPowder = "GS_BlackPowder";

	public const string RefinedPowder = "GS_RefinedPowder";

	public static readonly AmmoDef[] Ammo = new AmmoDef[12]
	{
		new AmmoDef
		{
			Id = "GS_BlackPowder",
			En = "Black Powder",
			Ko = "흑색화약",
			Station = "forge",
			Amount = 5,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("Coal", 3),
				R("Resin", 1),
				R("BoneFragments", 1)
			}
		},
		new AmmoDef
		{
			Id = "GS_RefinedPowder",
			En = "Refined Powder",
			Ko = "정제 화약",
			Station = "blackforge",
			Amount = 5,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("SulfurStone", 2),
				R("Coal", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_AmmoStone",
			Key = "$ammo_gs_stone",
			En = "Sling Stones",
			Ko = "돌탄",
			Station = "piece_workbench",
			Blunt = 20f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[1] { R("Stone", 2) }
		},
		new AmmoDef
		{
			Id = "GS_AmmoFlint",
			Key = "$ammo_gs_stone",
			En = "Flint Shot",
			Ko = "부싯돌탄",
			Station = "piece_workbench",
			Pierce = 24f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("Flint", 1),
				R("Wood", 1)
			}
		},
		new AmmoDef
		{
			Id = "GS_ShotBronze",
			Key = "$ammo_gs_shot",
			En = "Bronze Shot",
			Ko = "청동 산탄",
			Station = "forge",
			Blunt = 6f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("Bronze", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallIron",
			Key = "$ammo_gs_ball",
			En = "Iron Ball",
			Ko = "철탄",
			Station = "forge",
			Level = 2,
			Pierce = 25f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("Iron", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallSilver",
			Key = "$ammo_gs_ball",
			En = "Silver Ball",
			Ko = "은탄",
			Station = "forge",
			Level = 3,
			Pierce = 20f,
			Spirit = 10f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("Silver", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallFrost",
			Key = "$ammo_gs_ball",
			En = "Frost Ball",
			Ko = "서리탄",
			Station = "forge",
			Level = 3,
			Pierce = 18f,
			Frost = 12f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("Iron", 1),
				R("FreezeGland", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallBlackmetal",
			Key = "$ammo_gs_ball",
			En = "Black-metal Ball",
			Ko = "흑철탄",
			Station = "forge",
			Level = 4,
			Pierce = 35f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("BlackMetal", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_ShotBlackmetal",
			Key = "$ammo_gs_shot",
			En = "Black-metal Shot",
			Ko = "흑철 산탄",
			Station = "forge",
			Level = 4,
			Pierce = 6f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("BlackMetal", 1),
				R("GS_BlackPowder", 3)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallEitr",
			Key = "$ammo_gs_ball",
			En = "Eitr Ball",
			Ko = "에이트르 탄",
			Station = "piece_magetable",
			Pierce = 28f,
			Lightning = 12f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				R("Carapace", 1),
				R("Eitr", 1),
				R("GS_BlackPowder", 2)
			}
		},
		new AmmoDef
		{
			Id = "GS_BallFlametal",
			Key = "$ammo_gs_ball",
			En = "Flametal Ball",
			Ko = "플라메탈 탄",
			Station = "blackforge",
			Pierce = 22f,
			Fire = 14f,
			Recipe = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				R("FlametalNew", 1),
				R("GS_RefinedPowder", 2)
			}
		}
	};

	private static RequirementConfig R(string item, int n)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		return new RequirementConfig(item, n, 0, true);
	}
}