Decompiled source of Murat 3 v1.1.3

plugins/Karster-Sagolasin/Sagolasin.dll

Decompiled 2 weeks 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.Logging;
using HarmonyLib;
using LethalLib.Extras;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Sagolasin.Components;
using Unity.Netcode.Components;
using UnityEngine;

[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 = "")]
[assembly: AssemblyCompany("Sagolasin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Sagolasin")]
[assembly: AssemblyTitle("Sagolasin")]
[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 Sagolasin
{
	[BepInPlugin("karster.sagolasin", "sagolasin", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGuid = "karster.sagolasin";

		private const string modName = "sagolasin";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("karster.sagolasin");

		private static Plugin instance;

		internal static ManualLogSource mls;

		public static AssetBundle MainAssets;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("karster.sagolasin");
			MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sagomat"));
			Register.RegisterItems();
			Register.RegisterUnlockables();
			harmony.PatchAll(typeof(Plugin));
		}
	}
	internal class Register
	{
		public class CustomItem
		{
			public string name = "";

			public string itemPath = "";

			public string infoPath = "";

			public Action<Item> itemAction = delegate
			{
			};

			public bool enabled = true;

			public CustomItem(string name, string itemPath, string infoPath, Action<Item> action = null)
			{
				this.name = name;
				this.itemPath = itemPath;
				this.infoPath = infoPath;
				if (action != null)
				{
					itemAction = action;
				}
			}

			public static CustomItem Add(string name, string itemPath, string infoPath = null, Action<Item> action = null)
			{
				return new CustomItem(name, itemPath, infoPath, action);
			}
		}

		public class CustomUnlockable
		{
			public string name = "";

			public string unlockablePath = "";

			public string infoPath = "";

			public Action<UnlockableItem> unlockableAction = delegate
			{
			};

			public bool enabled = true;

			public int unlockCost = -1;

			public CustomUnlockable(string name, string unlockablePath, string infoPath, Action<UnlockableItem> action = null, int unlockCost = -1)
			{
				this.name = name;
				this.unlockablePath = unlockablePath;
				this.infoPath = infoPath;
				if (action != null)
				{
					unlockableAction = action;
				}
				this.unlockCost = unlockCost;
			}

			public static CustomUnlockable Add(string name, string unlockablePath, string infoPath = null, Action<UnlockableItem> action = null, int unlockCost = -1, bool enabled = true)
			{
				return new CustomUnlockable(name, unlockablePath, infoPath, action, unlockCost)
				{
					enabled = enabled
				};
			}
		}

		public class CustomShopItem : CustomItem
		{
			public int itemPrice;

			public CustomShopItem(string name, string itemPath, string infoPath = null, int itemPrice = 0, Action<Item> action = null)
				: base(name, itemPath, infoPath, action)
			{
				this.itemPrice = itemPrice;
			}

			public static CustomShopItem Add(string name, string itemPath, string infoPath = null, int itemPrice = 0, Action<Item> action = null, bool enabled = true)
			{
				return new CustomShopItem(name, itemPath, infoPath, itemPrice, action)
				{
					enabled = enabled
				};
			}
		}

		public static List<CustomUnlockable> customUnlockables;

		public static List<CustomItem> customItems;

		public static void RegisterUnlockables()
		{
			customUnlockables = new List<CustomUnlockable> { CustomUnlockable.Add("Sago", "Assets/SagoMat.asset", "Assets/SagoInfo.asset", null, 15) };
			foreach (CustomUnlockable customUnlockable in customUnlockables)
			{
				Plugin.mls.LogInfo((object)customUnlockable.unlockablePath);
				if (customUnlockable.enabled)
				{
					UnlockableItem unlockable = Plugin.MainAssets.LoadAsset<UnlockableItemDef>(customUnlockable.unlockablePath).unlockable;
					if ((Object)(object)unlockable.prefabObject != (Object)null)
					{
						NetworkPrefabs.RegisterNetworkPrefab(unlockable.prefabObject);
					}
					TerminalNode val = null;
					if (customUnlockable.infoPath != null)
					{
						val = Plugin.MainAssets.LoadAsset<TerminalNode>(customUnlockable.infoPath);
					}
					Unlockables.RegisterUnlockable(unlockable, (StoreType)2, (TerminalNode)null, (TerminalNode)null, val, customUnlockable.unlockCost);
				}
			}
		}

		public static void RegisterItems()
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			customItems = new List<CustomItem> { CustomShopItem.Add("SagoBox", "Assets/SagoBox/SagoBox.asset", "Assets/SagoBox/SagoBoxInfo.asset", 1000) };
			foreach (CustomItem customItem in customItems)
			{
				if (customItem.enabled)
				{
					Item val = Plugin.MainAssets.LoadAsset<Item>(customItem.itemPath);
					if ((Object)(object)val.spawnPrefab.GetComponent<NetworkTransform>() == (Object)null)
					{
						NetworkTransform val2 = val.spawnPrefab.AddComponent<NetworkTransform>();
						val2.SlerpPosition = false;
						val2.Interpolate = false;
						val2.SyncPositionX = false;
						val2.SyncPositionY = false;
						val2.SyncPositionZ = false;
						val2.SyncScaleX = false;
						val2.SyncScaleY = false;
						val2.SyncScaleZ = false;
						val2.UseHalfFloatPrecision = true;
					}
					if (((Object)val.spawnPrefab).name == "SagoBox" && (Object)(object)val.spawnPrefab.GetComponent<Sagobox>() == (Object)null)
					{
						Plugin.mls.LogInfo((object)"Test");
						Sagobox sagobox = val.spawnPrefab.AddComponent<Sagobox>();
						Plugin.mls.LogInfo((object)"Test1");
						((GrabbableObject)sagobox).grabbable = true;
						Plugin.mls.LogInfo((object)"Test2");
						((GrabbableObject)sagobox).isInFactory = true;
						Plugin.mls.LogInfo((object)"Test3");
						((GrabbableObject)sagobox).itemProperties = val;
						Plugin.mls.LogInfo((object)"Test4");
						Battery insertedBattery = new Battery(false, 1f);
						((GrabbableObject)sagobox).insertedBattery = insertedBattery;
						Plugin.mls.LogInfo((object)"Test5");
						((GrabbableObject)sagobox).mainObjectRenderer = val.spawnPrefab.GetComponent<MeshRenderer>();
						Plugin.mls.LogInfo((object)"Test6");
						((GrabbableObject)sagobox).grabbableToEnemies = true;
						Plugin.mls.LogInfo((object)"Test7");
						sagobox.boomboxAudio = val.spawnPrefab.GetComponent<AudioSource>();
						Plugin.mls.LogInfo((object)"Test8");
						AudioClip[] musicAudios = (AudioClip[])(object)new AudioClip[2]
						{
							Plugin.MainAssets.LoadAsset<AudioClip>("4.mp3"),
							Plugin.MainAssets.LoadAsset<AudioClip>("8.mp3")
						};
						sagobox.musicAudios = musicAudios;
						AudioClip[] stopAudios = (AudioClip[])(object)new AudioClip[1] { Plugin.MainAssets.LoadAsset<AudioClip>("kafkef.mp3") };
						sagobox.stopAudios = stopAudios;
					}
					NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
					customItem.itemAction(val);
					if (customItem is CustomShopItem)
					{
						TerminalNode val3 = Plugin.MainAssets.LoadAsset<TerminalNode>(customItem.infoPath);
						Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val3, ((CustomShopItem)customItem).itemPrice);
					}
				}
			}
		}
	}
}
namespace Sagolasin.Components
{
	public class kafkef : InteractEvent
	{
		public kafkef(AudioSource source)
		{
			source.Play();
		}
	}
	public class Sagobox : GrabbableObject
	{
		public AudioSource boomboxAudio;

		public AudioClip[] musicAudios;

		public AudioClip[] stopAudios;

		public Random musicRandomizer;

		private StartOfRound playersManager;

		private RoundManager roundManager;

		public bool isPlayingMusic;

		private float noiseInterval;

		private int timesPlayedWithoutTurningOff;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			playersManager = Object.FindObjectOfType<StartOfRound>();
			roundManager = Object.FindObjectOfType<RoundManager>();
			musicRandomizer = new Random(playersManager.randomMapSeed - 10);
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			StartMusic(used);
		}

		private void StartMusic(bool startMusic, bool pitchDown = false)
		{
			if (startMusic)
			{
				boomboxAudio.clip = musicAudios[musicRandomizer.Next(0, musicAudios.Length)];
				boomboxAudio.pitch = 1f;
				boomboxAudio.Play();
			}
			else if (isPlayingMusic)
			{
				if (pitchDown)
				{
					((MonoBehaviour)this).StartCoroutine(musicPitchDown());
				}
				else
				{
					boomboxAudio.Stop();
					boomboxAudio.PlayOneShot(stopAudios[Random.Range(0, stopAudios.Length)]);
				}
				timesPlayedWithoutTurningOff = 0;
			}
			base.isBeingUsed = startMusic;
			isPlayingMusic = startMusic;
		}

		private IEnumerator musicPitchDown()
		{
			for (int i = 0; i < 30; i++)
			{
				yield return null;
				AudioSource obj = boomboxAudio;
				obj.pitch -= 0.033f;
				if (boomboxAudio.pitch <= 0f)
				{
					break;
				}
			}
			boomboxAudio.Stop();
			boomboxAudio.PlayOneShot(stopAudios[Random.Range(0, stopAudios.Length)]);
		}

		public override void UseUpBatteries()
		{
			((GrabbableObject)this).UseUpBatteries();
			StartMusic(startMusic: false, pitchDown: true);
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			StartMusic(startMusic: false);
		}

		public override void Update()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if (isPlayingMusic)
			{
				if (noiseInterval <= 0f)
				{
					noiseInterval = 1f;
					timesPlayedWithoutTurningOff++;
					roundManager.PlayAudibleNoise(((Component)this).transform.position, 16f, 0.9f, timesPlayedWithoutTurningOff, false, 5);
				}
				else
				{
					noiseInterval -= Time.deltaTime;
				}
				if (base.insertedBattery.charge < 0.05f)
				{
					boomboxAudio.pitch = 1f - (0.05f - base.insertedBattery.charge) * 4f;
				}
			}
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected override string __getTypeName()
		{
			return "SagoboxItem";
		}
	}
}