Decompiled source of RomanianCompany v1.1.1

plugins/RomanianCompany.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using RomanianCompany.Patches;
using RomanianCompany.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RomanianCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RomanianCompany")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("671be1f6-28b7-44c5-9707-904de701dd9b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RomanianCompany
{
	[BepInPlugin("RomanianCompany", "Romanian Company", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "RomanianCompany";

		public const string modFilePath = "RedaOps-RomanianCompany";

		private readonly Harmony harmony = new Harmony("RomanianCompany");

		public static Plugin Instance;

		internal ManualLogSource log;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			log = Logger.CreateLogSource("RomanianCompany");
			log.LogInfo((object)"Mod loaded");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(TerminalPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(FlowermanAIPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(PosterPatch));
			harmony.PatchAll(typeof(SandSpiderAIPatch));
		}

		public static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message);
		}

		public static void LogWarning(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message);
		}

		public static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message);
		}

		public static void LogError(Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex);
		}
	}
}
namespace RomanianCompany.Utils
{
	internal class SoundLoader
	{
		public static bool hasLoaded = false;

		public static List<AudioClip> BrakenHatz = new List<AudioClip>();

		public static AudioClip BrakenKill = null;

		public static List<AudioClip> coildheadSounds = new List<AudioClip>();

		public static List<AudioClip> valiSounds = new List<AudioClip>();

		private static void LoadCoilhead()
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Paths.PluginPath, "RedaOps-RomanianCompany", "coilhead"));
			FileInfo[] files = directoryInfo.GetFiles("*.wav");
			FileInfo[] array = files;
			foreach (FileInfo fileInfo in array)
			{
				coildheadSounds.Add(SoundTool.GetAudioClip("RedaOps-RomanianCompany", "coilhead", fileInfo.Name));
			}
			Plugin.LogInfo($"Loaded {coildheadSounds.Count} coilhead sounds: {(Object)(object)coildheadSounds[0] != (Object)null}");
		}

		private static void LoadVali()
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Paths.PluginPath, "RedaOps-RomanianCompany", "vali"));
			FileInfo[] files = directoryInfo.GetFiles("*.wav");
			FileInfo[] array = files;
			foreach (FileInfo fileInfo in array)
			{
				valiSounds.Add(SoundTool.GetAudioClip("RedaOps-RomanianCompany", "vali", fileInfo.Name));
			}
			Plugin.LogInfo($"Loaded {valiSounds.Count} spyder sounds: {(Object)(object)valiSounds[0] != (Object)null}");
		}

		public static void LoadCustomSounds()
		{
			if (!hasLoaded)
			{
				hasLoaded = true;
				BrakenHatz.Add(SoundTool.GetAudioClip("RedaOps-RomanianCompany", "RomanianSounds", "hatz1.wav"));
				BrakenHatz.Add(SoundTool.GetAudioClip("RedaOps-RomanianCompany", "RomanianSounds", "hatz2.wav"));
				BrakenKill = SoundTool.GetAudioClip("RedaOps-RomanianCompany", "RomanianSounds", "dorian_kill.wav");
				Plugin.LogInfo($"Loaded all custom sounds: {(Object)(object)BrakenHatz[0] != (Object)null}");
				LoadCoilhead();
				LoadVali();
			}
		}
	}
}
namespace RomanianCompany.Patches
{
	internal class DebugPatch
	{
		[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
		private static void Prefix(ref SelectableLevel newLevel)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			foreach (SpawnableEnemyWithRarity enemy in newLevel.Enemies)
			{
				enemy.rarity = 0;
				if ((Object)enemy.enemyType.enemyPrefab.GetComponent<SandSpiderAI>() != (Object)null)
				{
					enemy.rarity = 999;
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		private static void Postfix(ref float ___sprintMeter)
		{
			___sprintMeter = 1f;
		}

		[HarmonyPatch(typeof(GrabbableObject), "Update")]
		private static void Postfix(ref Battery ___insertedBattery, ref Item ___itemProperties)
		{
			if (___itemProperties.requiresBattery)
			{
				___insertedBattery.charge = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class FlowermanAIPatch
	{
		private static bool playedHatz;

		private static int hatzIndex;

		[HarmonyPatch("LookAtFlowermanTrigger")]
		private static void Postfix(ref AudioSource ___creatureAngerVoice)
		{
			if (!playedHatz)
			{
				playedHatz = true;
				___creatureAngerVoice.pitch = 1f;
				___creatureAngerVoice.volume = 1f;
				___creatureAngerVoice.PlayOneShot(SoundLoader.BrakenHatz[hatzIndex], 40f);
				hatzIndex++;
				if (hatzIndex >= SoundLoader.BrakenHatz.Count)
				{
					hatzIndex = 0;
				}
			}
		}

		[HarmonyPatch("Update")]
		private static void Postfix(ref int ___currentBehaviourStateIndex)
		{
			if (___currentBehaviourStateIndex != 1)
			{
				playedHatz = false;
			}
		}

		[HarmonyPatch("killAnimation")]
		private static void Prefix(ref AudioSource ___crackNeckAudio)
		{
			WalkieTalkie.TransmitOneShotAudio(___crackNeckAudio, SoundLoader.BrakenKill, 1f);
			___crackNeckAudio.PlayOneShot(SoundLoader.BrakenKill);
		}
	}
	internal class PosterPatch
	{
		private static string postersPath = Path.Combine(Paths.PluginPath, "RedaOps-RomanianCompany", "posters");

		private static void UpdateMaterials(bool angryAndra)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Plugin.LogInfo($"Updating poster textures: {angryAndra}");
			Material[] materials = ((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials;
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(postersPath, "ro1.png")));
			materials[0].mainTexture = (Texture)(object)val;
			Texture2D val2 = new Texture2D(2, 2);
			if (angryAndra)
			{
				ImageConversion.LoadImage(val2, File.ReadAllBytes(Path.Combine(postersPath, "andra_evil.png")));
			}
			else
			{
				ImageConversion.LoadImage(val2, File.ReadAllBytes(Path.Combine(postersPath, "andra.png")));
			}
			materials[1].mainTexture = (Texture)(object)val2;
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		public static void DefaultPosters()
		{
			UpdateMaterials(angryAndra: false);
		}

		[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
		private static void Prefix(ref SelectableLevel newLevel)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			bool angryAndra = false;
			foreach (SpawnableEnemyWithRarity enemy in newLevel.Enemies)
			{
				if ((Object)enemy.enemyType.enemyPrefab.GetComponent<DressGirlAI>() != (Object)null && enemy.rarity > 0)
				{
					angryAndra = true;
				}
			}
			UpdateMaterials(angryAndra);
		}

		[HarmonyPatch(typeof(StartOfRound), "EndGameClientRpc")]
		private static void Postfix()
		{
			UpdateMaterials(angryAndra: false);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		public const long pauseBetweenCoilhead = 6L;

		public const int chanceToPlay = 450;

		public static long lastPlayed;

		private static void TriggerCoilheadSound(AudioSource audioSource)
		{
			if (Random.Range(0, 1000) <= 450)
			{
				int num = Random.Range(0, SoundLoader.coildheadSounds.Count);
				audioSource.PlayOneShot(SoundLoader.coildheadSounds[num], 20f);
				WalkieTalkie.TransmitOneShotAudio(audioSource, SoundLoader.coildheadSounds[num], 0.85f);
				Plugin.LogInfo($"Played coilhead sound #{num}");
			}
		}

		[HarmonyPatch("PlayRandomClip")]
		private static void Prefix(AudioSource audioSource)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			if ((Object)((Component)audioSource).GetComponentInParent<SpringManAI>() != (Object)null)
			{
				long num = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
				if (num > lastPlayed + 6)
				{
					lastPlayed = num;
					TriggerCoilheadSound(audioSource);
				}
			}
		}
	}
	[HarmonyPatch(typeof(SandSpiderAI))]
	internal class SandSpiderAIPatch
	{
		public const int chanceToPlay = 40;

		public const int chanceToPlayStare = 4000;

		private static long lastPlayed;

		public const int timePassedThreshold = 5;

		private static void TriggerSandspiderSound(AudioSource audioSource, int chance)
		{
			if (Random.Range(0, 10000) <= chance)
			{
				int num = Random.Range(0, SoundLoader.valiSounds.Count);
				if (chance == 4000)
				{
					audioSource.pitch = 1f;
					audioSource.volume = 0.5f;
				}
				Plugin.LogInfo($"Triggered spider sound {num}");
				audioSource.PlayOneShot(SoundLoader.valiSounds[num], 20f);
				WalkieTalkie.TransmitOneShotAudio(audioSource, SoundLoader.valiSounds[num], Mathf.Clamp(Random.Range(-0.4f, 0.8f), 0f, 1f));
				Plugin.LogInfo($"Played vali spider sound #{num} and chance: {chance}");
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void WatchingPlayerSounds(ref bool ___watchFromDistance, ref AudioSource ___footstepAudio)
		{
			if (___watchFromDistance)
			{
				long num = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
				if (num > lastPlayed + 5)
				{
					Plugin.LogInfo("State 2 triggered: playing because watching");
					lastPlayed = num;
					TriggerSandspiderSound(___footstepAudio, 4000);
				}
			}
		}

		[HarmonyPatch("MoveLegsProcedurally")]
		[HarmonyPrefix]
		private static void MoveLegsRandomAudio(ref Vector3[] ___legPositions, ref Transform[] ___legDefaultPositions, ref float[] ___legDistances, ref AudioSource ___footstepAudio)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			for (int i = 0; i < ___legPositions.Length; i++)
			{
				Vector3 val = ___legPositions[i] - ___legDefaultPositions[i].position;
				if (((Vector3)(ref val)).sqrMagnitude > ___legDistances[i] * 1.4f)
				{
					TriggerSandspiderSound(___footstepAudio, 40);
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		private static void Prefix()
		{
			SoundLoader.LoadCustomSounds();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		private static TerminalNode EditCreatureData(TerminalNode node)
		{
			switch (node.creatureFileID)
			{
			case 3:
				node.creatureName = "Chelutzu";
				node.displayText = "Chelutzu\n\nNume Stiintific: Canis Ludiculus Popus\nCanis Decibelus Furiosus, poreclit cu afecțiune 'Chelutu Surdul și Furiosul', este o forță de neoprit în lumea canină. Cu o talie impresionantă și o înfățișare amenințătoare, acest patruped este o adevărată mașinărie de sunete și furie.\n\n Cu o voce care ar face invidios orice vocalist de operă, Chelutu Surdul și Furiosul este în topul preferințelor pentru concerte caninofonice. Cu toate acestea, în ciuda aparențelor sale intimidante, acest patruped are și o latură amuzantă, adorând să-și petreacă serile în compania jucăriilor sonore și să joace poker cu celelalte animale de companie care au norocul să îi fie prietene.";
				return node;
			case 1:
				node.creatureName = "Dorian";
				node.displayText = "Dorian\n\nNume Stiintific: Dorianus Poppicus Grotescus\n\nDupa ce a plecat din Bucuresti pentru ca i au luat carnetul cand conducea spart mort, acum Dorian e atat de distrus pe boabe incat zboara prin cosmos si cauta gunoi.\n\nDaca te intalnesti cu Dorian, FUGI! Acesta o sa vrea sa faca o poza cu tine dar e cam agresiv.";
				return node;
			case 12:
				node.creatureName = "Vali Spyder";
				node.displayText = "Vali Spaider\n\nNume Stiintific: Coxatus Maximus\nVali Spyder";
				return node;
			default:
				return node;
			}
		}

		private static TerminalKeyword EditTerminalKeyword(int keyword_id, TerminalKeyword keyword)
		{
			switch (keyword_id)
			{
			case 42:
				((Object)keyword).name = "Chelutzu";
				keyword.word = "chelutzu";
				return keyword;
			case 36:
				((Object)keyword).name = "Dorian";
				keyword.word = "dorian";
				return keyword;
			case 44:
				((Object)keyword).name = "Vali Spyder";
				keyword.word = "vali spyder";
				return keyword;
			default:
				return keyword;
			}
		}

		[HarmonyPatch("Start")]
		private static void Postfix(ref List<TerminalNode> ___enemyFiles, ref TerminalNodesList ___terminalNodes, ref List<int> ___scannedEnemyIDs)
		{
			for (int i = 0; i < ___enemyFiles.Count; i++)
			{
				TerminalNode node = ___enemyFiles[i];
				___enemyFiles[i] = EditCreatureData(node);
			}
			TerminalKeyword[] allKeywords = ___terminalNodes.allKeywords;
			for (int j = 0; j < allKeywords.Length; j++)
			{
				___terminalNodes.allKeywords[j] = EditTerminalKeyword(j, ___terminalNodes.allKeywords[j]);
			}
			for (int k = 0; k < ___enemyFiles.Count; k++)
			{
				TerminalNode val = ___enemyFiles[k];
				___scannedEnemyIDs.Add(val.creatureFileID);
				Plugin.LogInfo("Loaded all creatures into beastiary");
			}
		}
	}
}