Decompiled source of Maxim Gun v0.2.0

plugins/MaximGun/MaximGun.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Gunworks;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Blackforge.Maxim
{
	public static class MaximGun
	{
		private const float Scale = 2.16f;

		private static readonly Vector3 Swivel = new Vector3(0f, 0.33f, 0f) * 2.16f;

		private static readonly Vector3 Pin = new Vector3(0f, 0.45f, 0f) * 2.16f;

		private const int Rounds = 250;

		public static MountedGun Define(IModHost host)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00ae: 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_00d0: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Expected O, but got Unknown
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Expected O, but got Unknown
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Expected O, but got Unknown
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_02f2: Expected O, but got Unknown
			Settings settings = new Settings(host);
			return new MountedGun
			{
				Prefab = "bf_maxim",
				Keys = "bf_maxim",
				Name = "Maxim gun",
				Description = "The Soviet Maxim machine gun of 1910/30 on the wheeled mount of Sokolov. Pull it by the trail.",
				Icon = "maxim",
				Station = "forge",
				Cost = settings.GunCost,
				Scale = 2.16f,
				Tints = new Dictionary<string, Color>
				{
					["paint"] = new Color(0.62f, 0.72f, 0.36f),
					["brass"] = new Color(1.6f, 1.25f, 0.55f)
				},
				Build = Build,
				Carriage = new CarriageSpec
				{
					Mass = 66f,
					WheelMass = 4f,
					WheelRadius = 0.3456f,
					Wheel = new Vector3(0.2525f, 0.16f, 0.08f) * 2.16f,
					WheelModel = "maxim_wheel",
					Hitch = new Vector3(0f, 0.05f, -1f) * 2.16f,
					HitchHalf = 0.32400003f,
					Hands = new Vector3(0f, 0.6f, 0f),
					CenterOfMass = new Vector3(0f, -0.06f, -0.2f) * 2.16f
				},
				Traverse = new TraverseSpec
				{
					Up = 20f,
					Down = 15f,
					Side = 180f,
					Speed = 240f
				},
				Fire = new FireSpec
				{
					RoundsPerMinute = settings.RoundsPerMinute,
					InfiniteAmmo = settings.InfiniteAmmo,
					Range = 250f
				},
				Round = new RoundSpec
				{
					Damage = settings.Damage,
					Speed = 300f
				},
				Heat = new HeatSpec(),
				Feed = new FeedSpec
				{
					Item = new AmmoSpec
					{
						Prefab = "bf_maxim_belt",
						Name = "Maxim belt",
						Description = $"A canvas belt of {250} rounds for the Maxim gun. Load it at the slot on the right side of the gun.",
						Look = "BoltIron",
						Model = "maxim_belt",
						Icon = "maxim_belt",
						Weight = 10f,
						MaxStack = 10,
						Cost = settings.BeltCost,
						Station = "forge"
					},
					RoundsPerItem = 250,
					Most = 1000,
					Noun = "belt",
					Nouns = "belts",
					EmptyHint = "No rounds. Load a belt at the slot on the right of the gun"
				}
			};
		}

		private static void Build(GunBuilder b)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_007e: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0198: 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_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			Transform root = b.Root;
			b.Part(root, "maxim", Vector3.zero, Quaternion.identity);
			b.Swivel = b.Part(root, "maxim_swivel", Swivel, Quaternion.identity);
			b.Barrel = b.Part(root, "maxim_gun", Pin, Quaternion.identity);
			foreach (Box box in Files.Mesh(b.Host, "maxim").boxes)
			{
				b.Solid(root, box.center * 2.16f, box.size * 2.16f, box.rotation);
			}
			b.Solid(root, new Vector3(0f, 0.6f, 0.3f) * 2.16f, new Vector3(0.42f, 0.5f, 0.6f) * 2.16f, Quaternion.identity);
			b.Handle(root, new Vector3(0f, 0.16f, -0.72f) * 2.16f, new Vector3(0.42f, 0.32f, 1.04f) * 2.16f);
			b.GripsAt(b.Barrel, new Vector3(0f, 0.05f, -0.42f), new Vector3(0.3f, 0.32f, 0.4f));
			b.SlotAt(b.Barrel, new Vector3(0.16f, 0.1f, -0.07f), new Vector3(0.16f, 0.16f, 0.17f));
			b.Muzzle = b.Point(b.Barrel, "muzzle", new Vector3(0f, 0.07f, 0.565f));
			b.Seat = b.Point(b.Swivel, "stand", new Vector3(0f, (0f - Swivel.y) / 2.16f, -0.7683333f));
			b.Flash = b.Lamp(b.Muzzle, new Color(1f, 0.75f, 0.4f), 6f, 4f);
			b.Glow = b.Lamp(b.Point(b.Barrel, "glow", new Vector3(0f, 0.07f, 0.49f)), new Color(1f, 0.25f, 0.05f), 3f, 0f);
			b.Steam = b.SteamAt(b.Point(b.Barrel, "steam", new Vector3(0f, 0.14f, 0.44f)));
			LoadShow loadShow = ((Component)root).gameObject.AddComponent<LoadShow>();
			loadShow.m_crank = b.Inner(b.Barrel, "maxim_crank", new Vector3(0.085f, 0.07f, -0.39f), Quaternion.identity);
			loadShow.m_strip = b.Inner(b.Barrel, "maxim_strip", LoadShow.StripAt, Quaternion.identity);
			loadShow.m_box = b.Inner(b.Swivel, "maxim_belt", new Vector3(0.24f, (0f - Swivel.y) / 2.16f, -0.07f), Quaternion.Euler(0f, 180f, 0f));
			((Component)loadShow.m_strip).gameObject.SetActive(false);
			((Component)loadShow.m_box).gameObject.SetActive(false);
			loadShow.m_mech = b.Speaker((AudioClip)null, 30f);
			loadShow.m_beltSound = b.Sound("belt");
			loadShow.m_cockSound = b.Sound("cock");
		}
	}
	public class LoadShow : MonoBehaviour, IGunExtra
	{
		public static readonly Vector3 StripAt = new Vector3(0.105f, 0.1f, -0.07f);

		private const float StripTravel = 0.25f;

		private const float SlideSeconds = 0.6f;

		private const float TurnSeconds = 0.4f;

		public Transform m_crank;

		public Transform m_strip;

		public Transform m_box;

		public AudioSource m_mech;

		public AudioClip m_beltSound;

		public AudioClip m_cockSound;

		private float m_start = -1f;

		private int m_cocks;

		public bool Busy => m_start >= 0f;

		public void OnLoadShow()
		{
			m_start = Time.time;
			m_mech.PlayOneShot(m_beltSound);
			m_cocks = 0;
		}

		public void Tick(bool loaded)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (Busy)
			{
				float num = Time.time - m_start;
				float num2 = Mathf.Clamp01(num / 0.6f);
				m_strip.localPosition = StripAt + new Vector3(0.25f * (1f - Mathf.SmoothStep(0f, 1f, num2)), 0f, 0f);
				float num3 = Mathf.Clamp01((num - 0.6f) / 0.8f);
				m_crank.localRotation = Quaternion.Euler(-720f * Mathf.SmoothStep(0f, 1f, num3), 0f, 0f);
				for (int i = m_cocks; i < 2 && num >= 0.6f + (float)i * 0.4f + 0.2f; i++)
				{
					m_mech.PlayOneShot(m_cockSound);
					m_cocks = i + 1;
				}
				if (num >= 1.4000001f)
				{
					m_start = -1f;
					m_crank.localRotation = Quaternion.identity;
				}
			}
			bool flag = loaded || Busy;
			if (((Component)m_strip).gameObject.activeSelf != flag)
			{
				((Component)m_strip).gameObject.SetActive(flag);
				((Component)m_box).gameObject.SetActive(flag);
			}
		}
	}
	public sealed class Settings
	{
		private const string FileName = "vladasz.maxim.cfg";

		public readonly Func<float> RoundsPerMinute;

		public readonly Func<float> Damage;

		public readonly Func<bool> InfiniteAmmo;

		public readonly Func<string> GunCost;

		public readonly Func<string> BeltCost;

		public Settings(IModHost host)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			SyncedConfig val = new SyncedConfig(host, "vladasz.maxim.cfg", "gw_maxim");
			RoundsPerMinute = val.Float("Gun", "RoundsPerMinute", 600f, "How fast the gun fires, from 60 to 1200 rounds a minute. The real gun fired 600.", 60f, 1200f);
			Damage = val.Float("Gun", "Damage", 20f, "The damage of 1 round, from 1 to 200. At 20 a Lox falls in about 5 seconds of fire.", 1f, 200f);
			InfiniteAmmo = val.Bool("Gun", "InfiniteAmmo", false, "true: the gun fires with no belts and spends no rounds.");
			GunCost = val.Text("Costs", "Gun", "BlackMetal:30,Iron:20,FineWood:20,LinenThread:10", "What building the gun at a forge costs: prefab names of items and amounts, with commas between.");
			BeltCost = val.Text("Costs", "Belt", "Iron:2,Coal:2,LinenThread:1", "What crafting 1 belt of 250 rounds at a forge costs: prefab names of items and amounts, with commas between.");
			val.Start();
		}
	}
	[BepInPlugin("vladasz.maxim", "Maxim Gun", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MaximGunPlugin : BaseUnityPlugin
	{
		public const string Id = "vladasz.maxim";

		public const string Number = "0.2.0";

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_002b: Expected O, but got Unknown
			FolderHost val = new FolderHost("maxim", ((BaseUnityPlugin)this).Logger, Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
			Guns.Register((IModHost)val, MaximGun.Define((IModHost)val));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}