Decompiled source of VanillaContentExpansion v0.1.8

plugins/VanillaContentExpansion/VanillaContentExpansion.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Unity.Netcode;
using UnityEngine;
using VanillaContentExpansion;
using VanillaContentPlus;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VanillaContentExpansion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VanillaContentExpansion")]
[assembly: AssemblyTitle("VanillaContentExpansion")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace VanillaContentPlus
{
	[BepInPlugin("bigmcnugget.vanillaContentExpansion", "Vanilla Content Expansion", "0.1.7")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "bigmcnugget.vanillaContentExpansion";

		private const string NAME = "Vanilla Content Expansion";

		private const string VERSION = "0.1.7";

		public static Plugin instance;

		public ConfigEntry<bool> AllowDebugLogs;

		public static AssetBundle scrapAssetBundle;

		public static string scrapListJson;

		public static AssetBundle monsterAssetBundle;

		public static ConfigFile mainConfig { get; internal set; }

		public static ConfigFile scrapConfig { get; internal set; }

		public static ConfigFile monsterConfig { get; internal set; }

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			instance = this;
			mainConfig = new ConfigFile(Utility.CombinePaths(new string[2]
			{
				Paths.ConfigPath,
				"bigmcnugget.vanillaContentExpansion-main.cfg"
			}), true);
			AllowDebugLogs = mainConfig.Bind<bool>("Main", "Allow Debug Logs", true, "Allow printing logs to the console, really only needed for debug");
			PrepareForPatching();
			scrapAssetBundle = LoadAssetBundle("Scrap", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "customscrap"));
			scrapListJson = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScrapList.json");
			scrapConfig = new ConfigFile(Utility.CombinePaths(new string[2]
			{
				Paths.ConfigPath,
				"bigmcnugget.vanillaContentExpansion-scrap.cfg"
			}), false);
			CustomScrap.Init();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bigmcnugget.vanillaContentExpansion");
		}

		private static void PrepareForPatching()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private static AssetBundle LoadAssetBundle(string debugName, string path)
		{
			AssetBundle result = AssetBundle.LoadFromFile(path);
			instance.LogInfo("Loaded " + debugName + " Asset bundle from " + path);
			return result;
		}

		public void LogInfo(string message)
		{
			if (AllowDebugLogs.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)message);
			}
		}

		public void LogWarning(string message)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)message);
		}
	}
}
namespace VanillaContentPlus.CustomBehaviour
{
	public class FlipPhone : GrabbableObject
	{
		public AudioSource src;

		public AudioClip[] ringtones;

		public bool isPlaying;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (((NetworkBehaviour)this).IsOwner && isPlaying)
			{
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayServerRpc()
		{
			int i = Random.Range(0, ringtones.Length);
			PlayClientRpc(i);
		}

		[ClientRpc]
		public void PlayClientRpc(int i)
		{
			((MonoBehaviour)this).StartCoroutine(PlayOneShotIEnum(i));
		}

		public IEnumerator PlayOneShotIEnum(int i)
		{
			isPlaying = true;
			AudioClip clip = ringtones[i];
			Debug.Log((object)("Phone item: Playing clip " + ((Object)clip).name));
			src.PlayOneShot(clip);
			yield return (object)new WaitForSeconds(clip.length + 0.2f);
			isPlaying = false;
		}
	}
}
namespace VanillaContentExpansion
{
	public class ChatterboxAI : EnemyAI
	{
	}
	public class CustomEnemy
	{
		public class CustomEnemyData
		{
			public string name;

			public string enemyPath;

			public int rarity;

			public LevelTypes levelFlags;

			public SpawnType spawnType;

			public string infoKeyword;

			public string infoNode;

			public bool enabled = true;

			private CustomEnemyConfig config;

			public CustomEnemyData(string name, string enemyPath, int rarity, LevelTypes levelFlags, SpawnType spawnType, string infoKeyword, string infoNode)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: 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_002f: Unknown result type (might be due to invalid IL or missing references)
				this.name = name;
				this.enemyPath = enemyPath;
				this.rarity = rarity;
				this.levelFlags = levelFlags;
				this.spawnType = spawnType;
				this.infoKeyword = infoKeyword;
				this.infoNode = infoNode;
				config = new CustomEnemyConfig(name, rarity);
				enabled = config.ENABLED.Value;
				this.rarity = config.RARITY.Value;
				allMonsters.Add(this);
			}
		}

		public static List<CustomEnemyData> allMonsters = new List<CustomEnemyData>();

		public static CustomEnemyData chatterbox = new CustomEnemyData("chatterbox", "Assets/content/enemies/chatterbox/data/chatterbox_enemy_type.asset", 1000, (LevelTypes)(-1), (SpawnType)0, null, "");

		public static void Init()
		{
			foreach (CustomEnemyData allMonster in allMonsters)
			{
				RegisterCustomMonster(allMonster);
			}
		}

		private static void RegisterCustomMonster(CustomEnemyData monster)
		{
			//IL_00a8: 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)
			Plugin.instance.LogInfo("Attempting To register Custom Monster: " + monster.name + " at " + monster.enemyPath);
			if (!monster.enabled)
			{
				Plugin.instance.LogInfo("Register Skipped" + monster.name + " Disabled in config");
				return;
			}
			EnemyType val = Plugin.monsterAssetBundle.LoadAsset<EnemyType>(monster.enemyPath);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.instance.LogWarning("!!!!!!!!!!!!!CANNOT FIND!!!!!!!!!!!!!!" + monster.name);
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, monster.rarity, monster.levelFlags, monster.spawnType, (TerminalNode)null, (TerminalKeyword)null);
			Plugin.instance.LogInfo("Registered Custom Monster: " + monster.name);
			Plugin.instance.LogInfo("\n");
		}
	}
	public class CustomEnemyConfig
	{
		public string name;

		public int rarity;

		public ConfigEntry<bool> ENABLED;

		public ConfigEntry<int> RARITY;

		public CustomEnemyConfig(string _name, int _defaultRarity)
		{
			name = _name;
			rarity = _defaultRarity;
			ENABLED = Plugin.monsterConfig.Bind<bool>(name, name + " Enabled", true, (ConfigDescription)null);
			RARITY = Plugin.monsterConfig.Bind<int>(name, name + " Rarity", rarity, "");
			Plugin.instance.LogInfo(name + " Config Loaded: [ENABLED] " + ENABLED.Value + " | [RARITY] " + RARITY.Value);
		}
	}
	public class CustomScrap
	{
		public class CustomScrapItem
		{
			public string scrapName;

			public string path;

			public Dictionary<LevelTypes, int> moonWeights;

			public bool enabled;

			public int minValue;

			public int maxValue;

			public float itemWeight;

			private CustomScrapConfig config;

			public CustomScrapItem(string name, string path, int[] weights, int minValue, int maxValue, float weight)
			{
				scrapName = name;
				this.path = path;
				moonWeights = new Dictionary<LevelTypes, int>
				{
					{
						(LevelTypes)4,
						weights[0]
					},
					{
						(LevelTypes)8,
						weights[1]
					},
					{
						(LevelTypes)16,
						weights[2]
					},
					{
						(LevelTypes)32,
						weights[3]
					},
					{
						(LevelTypes)64,
						weights[4]
					},
					{
						(LevelTypes)128,
						weights[5]
					},
					{
						(LevelTypes)256,
						weights[6]
					},
					{
						(LevelTypes)512,
						weights[7]
					},
					{
						(LevelTypes)1024,
						weights[0]
					}
				};
				this.minValue = minValue;
				this.maxValue = maxValue;
				itemWeight = weight;
				config = new CustomScrapConfig(scrapName, this);
				enabled = config.ENABLED.Value;
				this.minValue = config.valueMin.Value;
				this.maxValue = config.valueMax.Value;
				itemWeight = config.itemWeight.Value;
			}
		}

		public class CustomScrapConfig
		{
			public string name;

			public ConfigEntry<bool> ENABLED;

			public ConfigEntry<int> valueMin;

			public ConfigEntry<int> valueMax;

			public ConfigEntry<float> itemWeight;

			public CustomScrapConfig(string _name, CustomScrapItem item)
			{
				name = _name;
				ENABLED = Plugin.scrapConfig.Bind<bool>("SCRAP " + name, name + " Enabled", true, (ConfigDescription)null);
				valueMin = Plugin.scrapConfig.Bind<int>("SCRAP " + name, name + " Minimum Value", item.minValue, (ConfigDescription)null);
				valueMax = Plugin.scrapConfig.Bind<int>("SCRAP " + name, name + " Maximum Value", item.maxValue, (ConfigDescription)null);
				itemWeight = Plugin.scrapConfig.Bind<float>("SCRAP " + name, name + " Item Weight", item.itemWeight, (ConfigDescription)null);
				Plugin.instance.LogInfo(name + " Config Loaded: [ENABLED] " + ENABLED.Value);
			}
		}

		public class JsonRoot
		{
			[JsonProperty("SCRAP")]
			public JsonData[] scraplist { get; set; }
		}

		public class JsonData
		{
			[JsonProperty("name")]
			public string name;

			[JsonProperty("path")]
			public string path;

			[JsonProperty("weights")]
			public int[] weights;

			[JsonProperty("minValue")]
			public int minValue;

			[JsonProperty("maxValue")]
			public int maxValue;

			[JsonProperty("itemWeight")]
			public float itemWeight;
		}

		public static List<CustomScrapItem> allScrapItems = new List<CustomScrapItem>();

		public static void Init()
		{
			ParseJsonList();
		}

		private static void RegisterCustomScrapItem(CustomScrapItem scrap)
		{
			if (!scrap.enabled)
			{
				Plugin.instance.LogInfo("Register Skipped" + scrap.scrapName + " Disabled in config");
				return;
			}
			Item val = Plugin.scrapAssetBundle.LoadAsset<Item>(scrap.path);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.instance.LogWarning("!!!!!!!!!!!!!CANNOT FIND!!!!!!!!!!!!!!" + scrap.scrapName);
				return;
			}
			val.minValue = (int)((double)scrap.minValue * 2.5);
			val.maxValue = (int)((double)scrap.maxValue * 2.5);
			val.weight = scrap.itemWeight;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, scrap.moonWeights, (Dictionary<string, int>)null);
			Plugin.instance.LogInfo("Succesfully Registered Scrap: " + scrap.scrapName);
		}

		private static void ParseJsonList()
		{
			StreamReader streamReader = new StreamReader(Plugin.scrapListJson);
			string text = streamReader.ReadToEnd();
			JsonRoot jsonRoot = JsonConvert.DeserializeObject<JsonRoot>(text);
			int num = jsonRoot.scraplist.Length;
			for (int i = 0; i < num; i++)
			{
				JsonData jsonData = jsonRoot.scraplist[i];
				CustomScrapItem scrap = new CustomScrapItem(jsonData.name, jsonData.path, jsonData.weights, jsonData.minValue, jsonData.maxValue, jsonData.itemWeight);
				RegisterCustomScrapItem(scrap);
			}
		}
	}
}
namespace VanillaContentExpansion.CustomBehaviour
{
	public class AlarmClock
	{
		public Transform hHand;

		public Transform mHand;

		public Transform sHand;

		public AudioSource src;

		public AudioClip tick;

		public AudioClip alarm;
	}
	public class Lighter : GrabbableObject
	{
		private bool enabled;

		public AudioSource src;

		public AudioClip enabledSfx;

		public AudioClip disabledSfx;

		public Light pointLight;

		private float defaultlightRange = 5f;

		private Vector2 lightRangeRandom = new Vector2(4f, 8f);

		private float currentLightRange;

		private float defaultlightIntensity = 500f;

		private Vector2 lightIntensityRandom = new Vector2(125f, 150f);

		private float currentLightIntensity;

		private Vector2 flickerTimerRandom = new Vector2(0.01f, 0.15f);

		private float flickerTimer = 0.1f;

		public float fuel = 100f;

		private float fuelLeft;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (((NetworkBehaviour)this).IsOwner)
			{
				((Behaviour)pointLight).enabled = false;
			}
		}

		public void Toggle()
		{
			enabled = !enabled;
			if (enabled)
			{
				Debug.Log((object)"Lighter enabled");
				src.PlayOneShot(enabledSfx);
				((Behaviour)pointLight).enabled = true;
			}
			else
			{
				Debug.Log((object)"Lighter disabled");
				src.PlayOneShot(disabledSfx);
				((Behaviour)pointLight).enabled = false;
				pointLight.intensity = defaultlightIntensity;
				pointLight.range = defaultlightRange;
			}
		}

		public void Tick()
		{
			flickerTimer -= Time.deltaTime;
			if (flickerTimer <= 0f)
			{
				currentLightIntensity = Random.Range(lightIntensityRandom.x, lightIntensityRandom.y);
				currentLightRange = Random.Range(lightRangeRandom.x, lightRangeRandom.y);
				pointLight.intensity = currentLightIntensity;
				pointLight.range = currentLightRange;
				flickerTimer = Random.Range(flickerTimerRandom.x, flickerTimerRandom.y);
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			Tick();
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if (enabled)
			{
				Toggle();
			}
		}
	}
	public class Missile : GrabbableObject
	{
	}
	public class PolaroidCamera : GrabbableObject
	{
		private bool canUse;

		public Light light;

		private float flashTimer;

		public AudioSource src;

		public AudioClip flashSFX;

		public AudioClip primedSFX;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			((Behaviour)light).enabled = false;
			canUse = true;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!((NetworkBehaviour)this).IsOwner)
			{
			}
		}

		public IEnumerator Flash()
		{
			canUse = false;
			src.PlayOneShot(flashSFX);
			((Behaviour)light).enabled = true;
			light.intensity = 10f;
			Light obj = light;
			obj.intensity += Time.deltaTime * 50000f;
			yield return (object)new WaitForSeconds(0.3f);
			((Behaviour)light).enabled = false;
			light.intensity = 0f;
			yield return (object)new WaitForSeconds(3f);
			src.PlayOneShot(primedSFX);
			canUse = true;
		}
	}
	public class TrafficLight : GrabbableObject
	{
		private bool enabled = false;

		private bool switching;

		public Light[] lights;

		public AudioSource src;

		public AudioClip changeClickClip;

		private Vector2 timerRandom = new Vector2(5f, 20f);

		private float currentTimer = 0f;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			Light[] array = lights;
			foreach (Light val in array)
			{
				((Behaviour)val).enabled = false;
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (!enabled)
			{
				return;
			}
			currentTimer -= Time.deltaTime;
			if (currentTimer <= 0f && !switching)
			{
				Light[] array = lights;
				foreach (Light val in array)
				{
					((Behaviour)val).enabled = false;
				}
				((MonoBehaviour)this).StartCoroutine(ToggleLights());
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			enabled = false;
			Light[] array = lights;
			foreach (Light val in array)
			{
				((Behaviour)val).enabled = false;
			}
		}

		public override void EquipItem()
		{
			enabled = true;
		}

		private IEnumerator ToggleLights()
		{
			switching = true;
			yield return (object)new WaitForSeconds(0.75f);
			src.PlayOneShot(changeClickClip);
			int i = Random.Range(0, lights.Length);
			((Behaviour)lights[i]).enabled = true;
			currentTimer = Random.Range(timerRandom.x, timerRandom.y);
			switching = false;
		}
	}
}