Decompiled source of AmmoCost Capacity v1.0.0

AmmoCostCapacity.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AmmoCostCapacity;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.ItemFramework;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::AmmoCostCapacity.AmmoCostCapacity), "AmmoCost & Capacity", "1.0", "Jumble", null)]
[assembly: MelonColor]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AmmoCostCapacity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AmmoCostCapacity")]
[assembly: AssemblyTitle("AmmoCostCapacity")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AmmoCostCapacity;

public static class BuildInfo
{
	public const string Name = "AmmoCost & Capacity";

	public const string Description = "Lets you configure ammo cost & magazine/cylinder capacity.";

	public const string Author = "Jumble";

	public const string Company = null;

	public const string Version = "1.0";

	public const string DownloadLink = null;
}
public static class Config
{
	public static int m1911Size = 7;

	public static int revolverSize = 6;

	public static int m1911Price = 20;

	public static int revolverPrice = 10;

	private static string modsFolderPath = Path.Combine(Application.dataPath, "../Mods");

	private static string automatic1911FolderPath = Path.Combine(modsFolderPath, "AmmoCostCapacity");

	private static string configPath = Path.Combine(automatic1911FolderPath, "AmmoCostCapacityConfig.ini");

	public static void Load()
	{
		if (!Directory.Exists(automatic1911FolderPath))
		{
			Directory.CreateDirectory(automatic1911FolderPath);
			MelonLogger.Msg("Created 'Automatic1911' folder in Mods directory.");
		}
		if (!File.Exists(configPath))
		{
			File.WriteAllText(configPath, "M1911 Ammo Capacity = 7\r\nRevolver Ammo Capacity = 6\r\nM1911 Ammo Price = 20\r\nRevolver Ammo Price = 10");
			MelonLogger.Msg("AmmoCostCapacityConfig.ini created with default values.");
		}
		string[] array = File.ReadAllLines(configPath);
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (text.StartsWith(";") || text.StartsWith("#") || string.IsNullOrWhiteSpace(text))
			{
				continue;
			}
			string[] array2 = text.Split('=');
			if (array2.Length != 2)
			{
				continue;
			}
			string text2 = array2[0].Trim();
			string s = array2[1].Trim();
			switch (text2.ToLowerInvariant())
			{
			case "m1911 ammo capacity":
			{
				if (int.TryParse(s, out var result4))
				{
					m1911Size = result4;
				}
				break;
			}
			case "revolver ammo capacity":
			{
				if (int.TryParse(s, out var result2))
				{
					revolverSize = result2;
				}
				break;
			}
			case "m1911 ammo price":
			{
				if (int.TryParse(s, out var result3))
				{
					m1911Price = result3;
				}
				break;
			}
			case "revolver ammo price":
			{
				if (int.TryParse(s, out var result))
				{
					revolverPrice = result;
				}
				break;
			}
			}
		}
		MelonLogger.Msg("AmmoCostCapacityConfig.ini loaded.");
	}
}
public class AmmoCostCapacity : MelonMod
{
	[CompilerGenerated]
	private sealed class <HandleGunChanges>d__2 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HandleGunChanges>d__2(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
			{
				<>1__state = -1;
				GameObject val = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject obj) => ((Object)obj).name == "M1911_Equippable" && (Object)(object)obj.transform.parent == (Object)null));
				if ((Object)(object)val != (Object)null)
				{
					Equippable_RangedWeapon component = val.GetComponent<Equippable_RangedWeapon>();
					StorableItemDefinition magazine = component.Magazine;
					IntegerItemDefinition val2 = ((Il2CppObjectBase)component.Magazine).Cast<IntegerItemDefinition>();
					if ((Object)(object)component != (Object)null)
					{
						component.MagazineSize = Config.m1911Size;
					}
					if ((Object)(object)magazine != (Object)null)
					{
						magazine.BasePurchasePrice = Config.m1911Price;
					}
					if ((Object)(object)val2 != (Object)null)
					{
						val2.DefaultValue = Config.m1911Size;
					}
					else
					{
						MelonLogger.Msg("M1911Magazineint is NULL!!");
					}
				}
				else
				{
					MelonLogger.Msg("M1911Object is NULL!!");
				}
				GameObject val3 = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject obj) => ((Object)obj).name == "Revolver_Equippable" && (Object)(object)obj.transform.parent == (Object)null));
				if ((Object)(object)val3 != (Object)null)
				{
					Equippable_RangedWeapon component2 = val3.GetComponent<Equippable_RangedWeapon>();
					StorableItemDefinition magazine2 = component2.Magazine;
					IntegerItemDefinition val4 = ((Il2CppObjectBase)component2.Magazine).Cast<IntegerItemDefinition>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.MagazineSize = Config.revolverSize;
					}
					if ((Object)(object)val4 != (Object)null)
					{
						val4.DefaultValue = Config.revolverSize;
					}
					else
					{
						MelonLogger.Msg("RevolverCylinderint is NULL!!");
					}
					if ((Object)(object)magazine2 != (Object)null)
					{
						magazine2.BasePurchasePrice = Config.revolverPrice;
					}
				}
				else
				{
					MelonLogger.Msg("RevolverObject is NULL!!");
				}
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			case 1:
				<>1__state = -1;
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <HandleStanChanges>d__3 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HandleStanChanges>d__3(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(7f);
				<>1__state = 1;
				return true;
			case 1:
			{
				<>1__state = -1;
				GameObject obj = GameObject.Find("Stan");
				DialogueController_ArmsDealer val = ((obj != null) ? obj.GetComponentInChildren<DialogueController_ArmsDealer>() : null);
				if ((Object)(object)val != (Object)null)
				{
					Enumerator<WeaponOption> enumerator = val.allWeapons.GetEnumerator();
					while (enumerator.MoveNext())
					{
						WeaponOption current = enumerator.Current;
						if (current.Name == "M1911 Magazine")
						{
							current.Price = Config.m1911Price;
						}
						else if (current.Name == "Revolver Ammo")
						{
							current.Price = Config.revolverPrice;
						}
					}
				}
				<>2__current = null;
				<>1__state = 2;
				return true;
			}
			case 2:
				<>1__state = -1;
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public override void OnInitializeMelon()
	{
		Config.Load();
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
		MelonCoroutines.Start(HandleGunChanges());
		MelonCoroutines.Start(HandleStanChanges());
	}

	[IteratorStateMachine(typeof(<HandleGunChanges>d__2))]
	private static IEnumerator HandleGunChanges()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HandleGunChanges>d__2(0);
	}

	[IteratorStateMachine(typeof(<HandleStanChanges>d__3))]
	private static IEnumerator HandleStanChanges()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HandleStanChanges>d__3(0);
	}
}