Decompiled source of GunDealerConsole v1.0.2

GunDealer/GunDealer.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using Receiver2;
using Receiver2ModdingKit;
using TMPro;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GunDealer;

public class GunDealer : MonoBehaviour
{
	private List<string> gunList = new List<string>();

	private int selectedGun;

	public TextMeshPro gunNameText;

	public Transform spawnPoint;

	public Transform magSpawnPoint;

	private LevelObject levelObject;

	private void Awake()
	{
		if ((Object)(object)spawnPoint == (Object)null)
		{
			spawnPoint = ((Component)this).transform.Find("GunSpawnPoint");
		}
		if ((Object)(object)magSpawnPoint == (Object)null)
		{
			magSpawnPoint = ((Component)this).transform.Find("magSpawnPoint");
		}
		if ((Object)(object)gunNameText == (Object)null)
		{
			gunNameText = ((Component)((Component)this).transform.Find("screen/screen_text")).GetComponent<TextMeshPro>();
		}
		levelObject = Object.FindObjectOfType<LevelObject>();
		string[] gunNames = ReceiverCoreScript.Instance().GetGunNames();
		for (int i = 0; i < gunNames.Length; i++)
		{
			if (!gunNames[i].Contains("wolfire"))
			{
				gunList.Add(gunNames[i]);
			}
		}
		selectedGun = Random.Range(0, gunList.Count - 1);
		UpdateGunName();
	}

	public void SpawnGun()
	{
		//IL_0021: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		((InventoryItem)Object.Instantiate<GunScript>(ReceiverCoreScript.Instance().GetGunPrefab(gunList[selectedGun]), spawnPoint.position + Vector3.up * 0.3f, spawnPoint.rotation, levelObject.PlayerRoomTransform)).AddRigidBody();
	}

	private void UpdateGunName()
	{
		((TMP_Text)gunNameText).text = gunList[selectedGun].Split(new char[1] { '.' })[1].Replace('_', ' ').ToUpper();
	}

	public void SpawnMatchingMag()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		string[] magazine_root_types = ReceiverCoreScript.Instance().GetGunPrefab(gunList[selectedGun]).magazine_root_types;
		MagazineScript val = default(MagazineScript);
		for (int i = 0; i < magazine_root_types.Length; i++)
		{
			if (ReceiverCoreScript.Instance().TryGetMagazinePrefabFromRoot(magazine_root_types[i], (MagazineClass)1, ref val))
			{
				((InventoryItem)Object.Instantiate<MagazineScript>(val, magSpawnPoint.position + new Vector3(0.05f * (float)i, 0.05f), magSpawnPoint.rotation, levelObject.PlayerRoomTransform)).AddRigidBody();
			}
		}
	}

	public void SelectNextGun()
	{
		if (selectedGun == 0)
		{
			selectedGun = gunList.Count - 1;
			UpdateGunName();
		}
		else
		{
			selectedGun--;
			UpdateGunName();
		}
	}

	public void SelectPrevGun()
	{
		if (selectedGun == gunList.Count - 1)
		{
			selectedGun = 0;
			UpdateGunName();
		}
		else
		{
			selectedGun++;
			UpdateGunName();
		}
	}
}
[BepInPlugin("CiarenceW-GunDealer", "GunDealer", "1.0.1")]
[BepInProcess("receiver2.exe")]
internal class GunDealerManager : BaseUnityPlugin
{
	private GunDealer gunDealerConsole;

	private void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(((object)this).GetType(), typeof(BepInPlugin));
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"GunDealer {val.GUID} version {val.Version} Awaken wokeism woke");
		ReceiverEvents.StartListening((ReceiverEventTypeVoid)26, (UnityAction<ReceiverEventTypeVoid>)InstantiateConsole);
		ModdingKitEvents.AddTaskAtCoreStartup(new StartupAction(FindGunDealerAssetBundle));
	}

	private void FindGunDealerAssetBundle()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		string directoryName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
		Debug.Log((object)directoryName);
		if (Directory.Exists(directoryName))
		{
			string[] files = Directory.GetFiles(directoryName);
			foreach (string fileName in files)
			{
				string text = fileName;
				OperatingSystemFamily operatingSystemFamily = SystemInfo.operatingSystemFamily;
				if (!text.Contains(((object)(OperatingSystemFamily)(ref operatingSystemFamily)).ToString().ToLower()))
				{
					continue;
				}
				AssetBundle val = AssetBundle.GetAllLoadedAssetBundles().FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle bundle) => ((Object)bundle).name.Contains(Path.GetFileNameWithoutExtension(fileName))));
				if ((Object)(object)val == (Object)null)
				{
					val = AssetBundle.LoadFromFile(fileName);
					if ((Object)(object)val == (Object)null)
					{
						Debug.LogWarning((object)("Failed to load AssetBundle " + fileName));
						return;
					}
				}
				string[] allAssetNames = val.GetAllAssetNames();
				foreach (string text2 in allAssetNames)
				{
					GameObject val2 = val.LoadAsset<GameObject>(text2);
					if ((Object)(object)val2 != (Object)null && val2.TryGetComponent<GunDealer>(ref gunDealerConsole))
					{
						Debug.Log((object)"Found gun dealer bundle");
						return;
					}
				}
			}
			if ((Object)(object)gunDealerConsole == (Object)null)
			{
				Debug.LogError((object)"mdoel replacer is null!!!! SHITTTTTT!!!!!!!!!!!");
			}
		}
		else
		{
			Debug.LogError((object)"direrctort DOESNT FUCKING EDXIST");
		}
	}

	private void InstantiateConsole(ReceiverEventTypeVoid ev)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if ((int)ReceiverCoreScript.Instance().game_mode.GetGameMode() == 3)
		{
			Object.Instantiate<GunDealer>(gunDealerConsole, new Vector3(-0.17f, 1f, 15.1491f), new Quaternion(0f, 1f, 0f, 0f));
			return;
		}
		GunDealerSpawnPoint gunDealerSpawnPoint = Object.FindObjectOfType<GunDealerSpawnPoint>();
		if ((Object)(object)gunDealerSpawnPoint != (Object)null)
		{
			Object.Instantiate<GunDealer>(gunDealerConsole, ((Component)gunDealerSpawnPoint).transform.position, ((Component)gunDealerSpawnPoint).transform.rotation);
		}
	}
}
public class GunDealerSpawnPoint : MonoBehaviour
{
}