Decompiled source of RouterLoot v0.1.6

RouterLoot.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using REPOLib;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using RouterLoot.Helpers;
using UnityEngine;

[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("RouterLoot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.6.0")]
[assembly: AssemblyInformationalVersion("0.1.6+320453e0b84e0f3399c71a01c858bf75f559965c")]
[assembly: AssemblyProduct("RouterLoot")]
[assembly: AssemblyTitle("RouterLoot")]
[assembly: AssemblyVersion("0.1.6.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 RouterLoot
{
	[BepInPlugin("romanvht.RouterLoot", "Router Loot", "0.1.6")]
	[BepInDependency("REPOLib", "4.2.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "romanvht.RouterLoot";

		private readonly List<PrefabRef> registered = new List<PrefabRef>();

		private ConfigEntry<bool> debugSpawn;

		private void Awake()
		{
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			debugSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableSpawnKey", false, "Host only: press F8 during a level to spawn the router set for testing.");
			BundleLoader.OnAllBundlesLoaded += Initialize;
		}

		private void OnDestroy()
		{
			BundleLoader.OnAllBundlesLoaded -= Initialize;
		}

		private void Initialize()
		{
			BundleLoader.OnAllBundlesLoaded -= Initialize;
			try
			{
				foreach (ValuableContent item in from item in AssetBundle.GetAllLoadedAssetBundles().Single((AssetBundle item) => ((Object)item).name == "routerloot.repobundle").LoadAllAssets<ValuableContent>()
					orderby ((Object)item).name
					select item)
				{
					ValuableObject val = item.Prefab ?? throw new InvalidOperationException("Missing prefab: " + ((Object)item).name);
					Settings.Apply(((BaseUnityPlugin)this).Config, ((Object)item).name, val);
					registered.Add(NetworkPrefabs.PrefabRefs["Valuables/" + ((Object)val).name]);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Router Loot ready: {registered.Count} valuables.");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Cannot initialize Router Loot: {arg}");
			}
		}

		private void Update()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			//IL_0078: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (DebugSpawn.TryGetCamera(debugSpawn.Value, (KeyCode)289, registered.Count, out Camera camera))
			{
				for (int i = 0; i < registered.Count; i++)
				{
					float num = ((float)i - (float)(registered.Count - 1) / 2f) * 0.65f;
					Vector3 val = ((Component)camera).transform.position + ((Component)camera).transform.forward * 2f + ((Component)camera).transform.right * num;
					Valuables.SpawnValuable(registered[i], val, Quaternion.identity);
				}
			}
		}
	}
	internal static class Settings
	{
		public static void Apply(ConfigFile config, string id, ValuableObject prefab)
		{
			Value val = Object.Instantiate<Value>(prefab.valuePreset);
			PhysAttribute val2 = Object.Instantiate<PhysAttribute>(prefab.physAttributePreset);
			Durability val3 = Object.Instantiate<Durability>(prefab.durabilityPreset);
			val.valueMin = ConfigValues.Bind(config, id, "ValueMin", val.valueMin, 1f, 100000f, "Minimum base value. Host determines value; game multipliers apply.").Value;
			val.valueMax = Mathf.Max(val.valueMin, ConfigValues.Bind(config, id, "ValueMax", val.valueMax, 1f, 100000f, "Maximum base value. Restart after changes.").Value);
			val2.mass = ConfigValues.Bind(config, id, "Mass", val2.mass, 0.1f, 30f, "Mass. Use the same settings on all clients.").Value;
			val3.fragility = ConfigValues.Bind(config, id, "Fragility", val3.fragility, 0f, 100f, "Impact fragility, 0–100. Use the same settings on all clients.").Value;
			prefab.valuePreset = val;
			prefab.physAttributePreset = val2;
			prefab.durabilityPreset = val3;
			((Component)prefab).GetComponent<Rigidbody>().mass = val2.mass;
			((Component)prefab).GetComponent<PhysGrabObject>().massOriginal = val2.mass;
		}
	}
}
namespace RouterLoot.Helpers
{
	internal static class ConfigValues
	{
		public static ConfigEntry<float> Bind(ConfigFile config, string section, string key, float value, float low, float high, string description)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			return config.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(low, high), Array.Empty<object>()));
		}
	}
	internal static class DebugSpawn
	{
		public static bool TryGetCamera(bool enabled, KeyCode key, int count, out Camera camera)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			camera = null;
			if (!enabled || count == 0 || !Input.GetKeyDown(key))
			{
				return false;
			}
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated || !Object.op_Implicit((Object)(object)ValuableDirector.instance) || !SemiFunc.RunIsLevel())
			{
				return false;
			}
			camera = Camera.main;
			return Object.op_Implicit((Object)(object)camera);
		}
	}
}