Decompiled source of BazaarPrinter v0.3.1

BazaarPrinter.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BazaarPrinter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+db00d670ee92516c59fcaa02a80800b7c9a2867d")]
[assembly: AssemblyProduct("BazaarPrinter")]
[assembly: AssemblyTitle("BazaarPrinter")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BazaarPrinter;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.MagnusMagnuson.BazaarPrinter", "BazaarPrinter", "0.3.1")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class BazaarPrinter : BaseUnityPlugin
{
	private Random r = new Random();

	private Dictionary<int, PrinterInfo> printerPosAndRot = new Dictionary<int, PrinterInfo>();

	private string[] duplicators = new string[4] { "iscDuplicator", "iscDuplicatorLarge", "iscDuplicatorMilitary", "iscDuplicatorWild" };

	public void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		ModConfig.InitConfig(((BaseUnityPlugin)this).Config);
		BazaarController.Awake += new hook_Awake(BazaarController_Start);
	}

	private void BazaarController_Start(orig_Awake orig, BazaarController self)
	{
		orig.Invoke(self);
		if (NetworkServer.active)
		{
			SpawnPrinters();
		}
	}

	private void FillPrinterInfo()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_00bc: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: 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)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		List<int> list = new List<int> { 0, 1, 2, 3 };
		List<int> list2 = new List<int>();
		while (list.Count > 0)
		{
			int index = r.Next(list.Count);
			list2.Add(list[index]);
			list.RemoveAt(index);
		}
		PrinterInfo printerInfo = new PrinterInfo();
		printerInfo.position = new Vector3(-133.3f, -25.7f, -17.9f);
		printerInfo.rotation = new Vector3(0f, 72.6f, 0f);
		printerPosAndRot.Add(list2[0], printerInfo);
		printerInfo = new PrinterInfo();
		printerInfo.position = new Vector3(-71.3f, -24.7f, -29.2f);
		printerInfo.rotation = new Vector3(0f, 291f, 0f);
		printerPosAndRot.Add(list2[1], printerInfo);
		printerInfo = new PrinterInfo();
		printerInfo.position = new Vector3(-143.8f, -24.7f, -23.6f);
		printerInfo.rotation = new Vector3(0f, 61f, 0f);
		printerPosAndRot.Add(list2[2], printerInfo);
		printerInfo = new PrinterInfo();
		printerInfo.position = new Vector3(-110.7f, -26.7f, -46.4f);
		printerInfo.rotation = new Vector3(0f, 32.2f, 0f);
		printerPosAndRot.Add(list2[3], printerInfo);
	}

	private void SpawnPrinters()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_0035: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		printerPosAndRot.Clear();
		FillPrinterInfo();
		for (int i = 0; i < ModConfig.printerCount.Value; i++)
		{
			string randomDuplicator = GetRandomDuplicator();
			SpawnCard val = Resources.Load<SpawnCard>("SpawnCards/InteractableSpawnCard/" + randomDuplicator);
			DirectorPlacementRule val2 = new DirectorPlacementRule();
			val2.placementMode = (PlacementMode)0;
			val.DoSpawn(printerPosAndRot[i].position, Quaternion.identity, new DirectorSpawnRequest(val, val2, Run.instance.runRNG)).spawnedInstance.transform.eulerAngles = printerPosAndRot[i].rotation;
		}
	}

	private string GetRandomDuplicator()
	{
		double num = ModConfig.tier1Chance.Value + ModConfig.tier2Chance.Value + ModConfig.tier3Chance.Value + ModConfig.tierBossChance.Value;
		double num2 = r.NextDouble() * num;
		if (num2 <= (double)ModConfig.tier1Chance.Value)
		{
			return duplicators[0];
		}
		if (num2 <= (double)(ModConfig.tier1Chance.Value + ModConfig.tier2Chance.Value))
		{
			return duplicators[1];
		}
		if (num2 <= (double)(ModConfig.tier1Chance.Value + ModConfig.tier2Chance.Value + ModConfig.tier3Chance.Value))
		{
			return duplicators[2];
		}
		return duplicators[3];
	}
}
internal class PrinterInfo
{
	public Vector3 position;

	public Vector3 rotation;
}
internal class ModConfig
{
	public static ConfigEntry<int> printerCount;

	public static ConfigEntry<float> tier1Chance;

	public static ConfigEntry<float> tier2Chance;

	public static ConfigEntry<float> tier3Chance;

	public static ConfigEntry<float> tierBossChance;

	public static void InitConfig(ConfigFile config)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		printerCount = config.Bind<int>("Config", "printerCount", 1, new ConfigDescription("Set how many 3D Printers should spawn in the bazaar. Maximum is 4", (AcceptableValueBase)null, Array.Empty<object>()));
		printerCount.Value = Math.Abs(printerCount.Value);
		if (printerCount.Value > 4)
		{
			printerCount.Value = 4;
		}
		tier1Chance = config.Bind<float>("Config", "tier1Chance", 0.7f, new ConfigDescription("Set how likely it is for a bazaar 3D Printer to be tier 1", (AcceptableValueBase)null, Array.Empty<object>()));
		tier1Chance.Value = Math.Abs(tier1Chance.Value);
		tier2Chance = config.Bind<float>("Config", "tier2Chance", 0.2f, new ConfigDescription("Set how likely it is for a bazaar 3D Printer to be tier 2", (AcceptableValueBase)null, Array.Empty<object>()));
		tier2Chance.Value = Math.Abs(tier2Chance.Value);
		tier3Chance = config.Bind<float>("Config", "tier3Chance", 0.05f, new ConfigDescription("Set how likely it is for a bazaar 3D Printer to be tier 3", (AcceptableValueBase)null, Array.Empty<object>()));
		tier3Chance.Value = Math.Abs(tier3Chance.Value);
		tierBossChance = config.Bind<float>("Config", "tierBossChance", 0.05f, new ConfigDescription("Set how likely it is for a bazaar 3D Printer to be boss tier", (AcceptableValueBase)null, Array.Empty<object>()));
		tierBossChance.Value = Math.Abs(tierBossChance.Value);
	}
}