Decompiled source of BetterBread v0.0.1

PapiMod.dll

Decompiled 11 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using LC_API.ServerAPI;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("PapiMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("First Mod Attempt")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PapiMod")]
[assembly: AssemblyTitle("PapiMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 PapiMod
{
	public static class Config
	{
		public static ConfigEntry<int> papiSpawnWeight;

		public static ConfigEntry<int> papiValue;

		public static ConfigEntry<int> whenuSpawnWeight;

		public static ConfigEntry<int> whenuValue;

		public static void Load()
		{
			papiSpawnWeight = Plugin.config.Bind<int>("Scrap", "PapiWeight", 100, "How much does Papi spawn, higher = more common");
			papiValue = Plugin.config.Bind<int>("Scrap", "PapiValue", 9491, "Papi's value");
			whenuSpawnWeight = Plugin.config.Bind<int>("Scrap", "WhenuSpawnWeight", 100, "How much does whenu spawn, higher = more common");
			whenuValue = Plugin.config.Bind<int>("Scrap", "WhenuValue", 9491, "Whenu's value");
		}
	}
	public class LineRendererFadeOut : MonoBehaviour
	{
		public LineRenderer lineRenderer;

		public float fadeDuration = 1f;

		public float destroyDelay = 0.5f;

		private float elapsed;

		private bool isFading = true;

		private void Start()
		{
			lineRenderer = ((Component)this).GetComponent<LineRenderer>();
		}

		private void Update()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (isFading)
			{
				if (elapsed < fadeDuration)
				{
					float num = Mathf.Lerp(1f, 0f, elapsed / fadeDuration);
					((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, num);
					elapsed += Time.deltaTime;
				}
				else
				{
					((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, 0f);
					isFading = false;
					Object.Destroy((Object)(object)((Component)this).gameObject, destroyDelay);
				}
			}
		}
	}
	public class PapiObject : GrabbableObject
	{
		public void Awake()
		{
			base.grabbable = true;
			base.grabbableToEnemies = true;
			base.mainObjectRenderer = ((Component)this).GetComponentInChildren<MeshRenderer>(false);
			base.fallTime = 1f;
			base.scrapValue = 9491;
		}
	}
	[BepInPlugin("PapiMod", "PapiMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "locrien.papimod";

		public const string ModName = "PapiMod";

		public const string ModVersion = "1.0.0";

		public static ManualLogSource logger;

		public static ConfigFile config;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PapiMod is loaded!");
			config = ((BaseUnityPlugin)this).Config;
			Config.Load();
			Object[] assetsinBundle = AssetBundle.LoadFromMemory(Resource1.modassets).LoadAllAssets();
			Item itemWithName = GetItemWithName("PapiItem", assetsinBundle);
			if ((Object)(object)itemWithName != (Object)null)
			{
				((GrabbableObject)itemWithName.spawnPrefab.AddComponent<PapiObject>()).itemProperties = itemWithName;
				itemWithName.minValue = Config.papiValue.Value;
				itemWithName.maxValue = Config.papiValue.Value;
				itemWithName.spawnPrefab.GetComponentInChildren<ScanNodeProperties>().scrapValue = Config.papiValue.Value;
				Items.RegisterScrap(itemWithName, Config.papiSpawnWeight.Value, (LevelTypes)510);
				NetworkPrefabs.RegisterNetworkPrefab(itemWithName.spawnPrefab);
			}
			else
			{
				Debug.LogError((object)"Couldnt find item PapiItem");
			}
			itemWithName = GetItemWithName("WhenUScrap", assetsinBundle);
			if ((Object)(object)itemWithName != (Object)null)
			{
				((GrabbableObject)itemWithName.spawnPrefab.AddComponent<WhenUBox>()).itemProperties = itemWithName;
				itemWithName.minValue = Config.whenuValue.Value;
				itemWithName.maxValue = Config.whenuValue.Value;
				itemWithName.spawnPrefab.GetComponentInChildren<ScanNodeProperties>().scrapValue = Config.whenuValue.Value;
				Items.RegisterScrap(itemWithName, Config.whenuSpawnWeight.Value, (LevelTypes)510);
				NetworkPrefabs.RegisterNetworkPrefab(itemWithName.spawnPrefab);
			}
			else
			{
				Debug.LogError((object)"Couldnt find item WhenUScrap");
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private Item GetItemWithName(string itemName, Object[] assetsinBundle)
		{
			Item result = null;
			foreach (Object val in assetsinBundle)
			{
				Debug.LogWarning((object)("thing in bundle : " + val.name + ((object)val).GetType().ToString()));
				if (val.name == itemName)
				{
					result = (Item)(object)((val is Item) ? val : null);
				}
			}
			return result;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (Utils.Main.IsIngame())
			{
				ModdedServer.SetServerModdedOnly();
			}
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resource1
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("PapiMod.Resource1", typeof(Resource1).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] modassets => (byte[])ResourceManager.GetObject("modassets", resourceCulture);

		internal Resource1()
		{
		}
	}
	public class Shotgun : GrabbableObject
	{
		private ParticleSystem particleSystem;

		private AudioSource audioSource;

		public AudioClip shootSound;

		public AudioClip noammoSound;

		public GameObject BulletTrail;

		private Transform BulletSpawnPoint;

		public float spread = 7f;

		public float range = 35f;

		private RoundManager roundManager;

		public void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			particleSystem = ((Component)this).GetComponentInChildren<ParticleSystem>();
			audioSource = ((Component)this).GetComponent<AudioSource>();
			roundManager = Object.FindObjectOfType<RoundManager>();
			BulletSpawnPoint = ((Component)this).transform.GetChild(0);
			base.grabbable = true;
			base.grabbableToEnemies = true;
			base.mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
			base.useCooldown = 2f;
			base.insertedBattery = new Battery(false, 1f);
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_00b1: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (base.insertedBattery.charge >= 0.16f)
			{
				Battery insertedBattery = base.insertedBattery;
				insertedBattery.charge -= 0.16f;
				if (base.insertedBattery.charge < 0.16f)
				{
					base.insertedBattery.charge = 0f;
				}
				audioSource.PlayOneShot(shootSound);
				particleSystem.Play();
				RaycastHit val3 = default(RaycastHit);
				IHittable val4 = default(IHittable);
				EnemyAI val5 = default(EnemyAI);
				for (int i = 0; i < 5; i++)
				{
					float num = Random.Range(0f - spread - 3f, spread + 3f);
					float num2 = Random.Range(0f - spread, spread);
					Vector3 val = ((Component)this).transform.position + ((Component)this).transform.forward * range;
					((Vector3)(ref val))..ctor(val.x + num, val.y + num2, val.z + num);
					Vector3 val2 = val - ((Component)this).transform.position;
					LineRenderer component = Object.Instantiate<GameObject>(BulletTrail, BulletSpawnPoint).GetComponent<LineRenderer>();
					if (Physics.Raycast(((Component)this).transform.position, ((Vector3)(ref val2)).normalized, ref val3, range))
					{
						SpawnTrail(component, ((RaycastHit)(ref val3)).point);
						if (((Component)((RaycastHit)(ref val3)).collider).TryGetComponent<IHittable>(ref val4))
						{
							if (val4 == null)
							{
								return;
							}
							val4.Hit(1, ((Component)base.playerHeldBy.gameplayCamera).transform.forward, base.playerHeldBy, false);
						}
						else
						{
							if (!((Component)((RaycastHit)(ref val3)).collider).TryGetComponent<EnemyAI>(ref val5))
							{
								continue;
							}
							if ((Object)(object)val5 == (Object)null || ((Object)val5).name.ToLower().Contains("ghost") || ((Object)val5).name.ToLower().Contains("spring") || !val5.enemyType.canDie)
							{
								return;
							}
							if (val5.enemyHP <= 0)
							{
								continue;
							}
							EnemyAI obj = val5;
							obj.enemyHP--;
							if (val5.enemyHP == 0)
							{
								switch (val5.enemyType.enemyName)
								{
								case "HoarderBug":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 50);
									break;
								case "Centipede":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 50);
									break;
								case "SandSpider":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
									break;
								case "MouthDog":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
									break;
								case "Flowerman":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 200);
									break;
								case "Jester":
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 500);
									break;
								default:
									SpawnScrap(roundManager.currentLevel.spawnableScrap[2], ((Component)val5).transform.position, 100);
									break;
								}
							}
						}
					}
					else
					{
						SpawnTrail(component, ((Component)this).transform.position + val2 * 100f);
					}
				}
				((MonoBehaviour)this).StartCoroutine(ShakeCamera());
			}
			else
			{
				audioSource.PlayOneShot(noammoSound);
			}
		}

		private void SpawnTrail(LineRenderer Trail, Vector3 HitPoint)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Trail.SetPositions((Vector3[])(object)new Vector3[2] { BulletSpawnPoint.position, HitPoint });
			((Component)Trail).gameObject.AddComponent<LineRendererFadeOut>();
		}

		public void SpawnScrap(SpawnableItemWithRarity scrapItem, Vector3 enemyPos, int customWorth = 0)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_004b: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = new List<int>();
			List<NetworkObjectReference> list2 = new List<NetworkObjectReference>();
			List<Item> list3 = new List<Item>();
			GameObject obj = Object.Instantiate<GameObject>(scrapItem.spawnableItem.spawnPrefab, enemyPos, default(Quaternion), roundManager.spawnedScrapContainer);
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			list3.Add(scrapItem.spawnableItem);
			list.Add((int)((float)roundManager.AnomalyRandom.Next(list3[0].minValue, list3[0].maxValue) * roundManager.scrapValueMultiplier));
			component.scrapValue = list[list.Count - 1];
			NetworkObject component2 = obj.GetComponent<NetworkObject>();
			component2.Spawn(false);
			list2.Add(NetworkObjectReference.op_Implicit(component2));
			if (customWorth != 0)
			{
				component.SetScrapValue(customWorth);
			}
			((MonoBehaviour)this).StartCoroutine(WaitForScrapToSpawnToSync(list2.ToArray(), list.ToArray()));
		}

		private IEnumerator WaitForScrapToSpawnToSync(NetworkObjectReference[] spawnedScrap, int[] allScrapValue)
		{
			yield return (object)new WaitForSeconds(11f);
			roundManager.SyncScrapValuesClientRpc(spawnedScrap, allScrapValue);
		}

		private IEnumerator ShakeCamera()
		{
			Vector3 originalPosition = ((Component)base.playerHeldBy.gameplayCamera).transform.localPosition;
			float elapsed = 0f;
			while (elapsed < 0.4f)
			{
				float num = Random.Range(-1f, 1f) * 0.3f;
				float num2 = Random.Range(-1f, 1f) * 0.3f;
				((Component)base.playerHeldBy.gameplayCamera).transform.localPosition = new Vector3(num, num2, originalPosition.z);
				elapsed += Time.deltaTime;
				yield return null;
			}
			((Component)base.playerHeldBy.gameplayCamera).transform.localPosition = originalPosition;
		}
	}
	public class Utils
	{
		public class Main
		{
			public static bool IsIngame()
			{
				if ((Object)(object)GameObject.Find("Environment") != (Object)null)
				{
					return true;
				}
				return false;
			}
		}
	}
	public class WhenUBox : GrabbableObject
	{
		public void Awake()
		{
			base.grabbable = true;
			base.grabbableToEnemies = true;
			base.mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
			base.fallTime = 1f;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PapiMod";

		public const string PLUGIN_NAME = "PapiMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}