Decompiled source of OurBuddyRusty v1.0.4

RustyMod.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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RustyMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("I CAN FLYYYYYYYYYYYYYYYYYYYYYY")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RustyMod")]
[assembly: AssemblyTitle("RustyMod")]
[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;
		}
	}
}
internal static class Assets
{
	public static AssetBundle AssetBundle { get; private set; }

	private static Dictionary<string, Object> AssetList { get; set; }

	private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

	public static void PopulateAssets()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		if ((Object)AssetBundle != (Object)null)
		{
			RustyModBase.mls.LogWarning((object)"Attempted to load the asset bundle but the bundle was not null!");
			return;
		}
		AssetBundle = RustyModBase.RustyBundle;
		if ((Object)AssetBundle == (Object)null)
		{
			RustyModBase.mls.LogError((object)("Asset bundle at " + RustyModBase.location + "\rusty failed to load!"));
		}
		AssetList = new Dictionary<string, Object>();
		Object[] array = AssetBundle.LoadAllAssets();
		Object[] array2 = array;
		foreach (Object val in array2)
		{
			AssetList.Add(val.name, val);
		}
	}

	public static T GetAsset<T>(string name) where T : Object
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		if (!AssetList.TryGetValue(name, out var value))
		{
			RustyModBase.mls.LogError((object)("Attempted to load asset of name " + name + " but no asset of that name exists!"));
			return default(T);
		}
		T val = (T)(object)((value is T) ? value : null);
		if ((Object)val == (Object)null)
		{
			RustyModBase.mls.LogError((object)("Attempted to load an asset of type " + typeof(T).Name + " but asset of name " + name + " does not match this type!"));
			return default(T);
		}
		return val;
	}
}
[HarmonyPatch]
internal class EnemyPatches
{
	[HarmonyPatch(typeof(EnemyAI), "Start")]
	[HarmonyPostfix]
	public static void CreateRustyModel(EnemyAI __instance)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (__instance is RadMechAI)
		{
			((Component)__instance).gameObject.AddComponent<RustyController>();
		}
	}
}
public class RustyController : MonoBehaviour
{
	private List<string> baseMatNames = new List<string> { "ArmLeft", "ArmRight", "Booster", "Core", "EyeArmL", "EyeArmR" };

	private Animator vanillaRadMechAnimator;

	private Animator rustyAnimator;

	private AudioSource rustyAudioSource;

	private int loggedMisslesFired = 0;

	private AudioClip audioMainSystem;

	private AudioClip audioAllOrNothing;

	private AudioClip audioBuddy;

	private AudioClip audioDontDie;

	private AudioClip audioHeyBuddy;

	private AudioClip audioHopeOrDispair;

	private AudioClip audioIWontMiss;

	private AudioClip audioImComing1;

	private AudioClip audioImComing2;

	private AudioClip audioKeepYouWaiting;

	private AudioClip audioLockOn;

	private AudioClip audioNoChoice;

	private AudioClip audioNoGraverThreat;

	private AudioClip audioOnlyICanFly;

	private AudioClip audioRubicon;

	private AudioClip audioStayCool;

	private AudioClip audioStepUpMyGame;

	private AudioClip audioUnderPressure;

	private AudioClip audioWatchOut;

	private AudioClip audioWhatDrivesYou;

	private AudioClip audioYouCanDoBetter;

	private AudioClip audioYouThereBuddy;

	private AudioClip audioYoureFast;

	private AudioClip audioYoureGood;

	private List<AudioClip> voiceLines;

	private int voiceCooldown = 0;

	private RadMechAI RadMechAI { get; set; }

	private GameObject BaseRustyObject { get; set; }

	private Material spotlightMat { get; set; }

	private Material defaultMat { get; set; }

	private GameObject SecondaryGokuObject { get; set; }

	private bool takingStep { get; set; }

	private SkinnedMeshRenderer[] skinnedMeshRenderers { get; set; }

	private bool IsAttacking { get; set; }

	private bool IsDead { get; set; }

	private void Start()
	{
		RadMechAI = ((Component)this).GetComponent<RadMechAI>();
		UpdateScanNodeData();
		try
		{
		}
		catch (Exception ex)
		{
			RustyModBase.mls.LogError((object)("RustyMod ARM ERROR: " + ex));
		}
		HideRadMechModel();
		CreateRustyModels();
		LoadSounds();
		rustyAudioSource.loop = true;
		rustyAudioSource.PlayOneShot(audioMainSystem);
	}

	private void Update()
	{
		try
		{
			bool flag = ((EnemyAI)RadMechAI).currentBehaviourState.name == "Fly";
			if (RadMechAI.spotlight.activeSelf)
			{
				RadMechAI.spotlight.SetActive(false);
			}
			try
			{
				if (flag && !rustyAudioSource.isPlaying)
				{
					rustyAudioSource.Play();
				}
				if (!flag && rustyAudioSource.isPlaying)
				{
					rustyAudioSource.Pause();
				}
				if (flag)
				{
					if (voiceCooldown > 0)
					{
						voiceCooldown--;
					}
					else if (new Random().Next(1, 21) == 1)
					{
						int index = new Random().Next(1, voiceLines.Count);
						rustyAudioSource.PlayOneShot(voiceLines[index]);
						voiceCooldown = 30;
					}
				}
				if (rustyAnimator.GetInteger("currentAnim") == 7 || (!RadMechAI.attemptingGrab && rustyAnimator.GetInteger("currentnim") == 3))
				{
					rustyAnimator.SetInteger("currentAnim", 0);
				}
				if (!RadMechAI.chargingForward)
				{
					rustyAnimator.SetInteger("currentAnim", 7);
				}
				if (vanillaRadMechAnimator.GetInteger("currentAnim") < 3)
				{
					if (vanillaRadMechAnimator.GetBool("leftFootForward"))
					{
						rustyAnimator.SetInteger("currentAnim", 2);
					}
					else
					{
						rustyAnimator.SetInteger("currentAnim", 1);
					}
				}
				if (RadMechAI.aimingGun && RadMechAI.missilesFired != loggedMisslesFired)
				{
					rustyAnimator.SetInteger("currentAnim", 5);
				}
				if (RadMechAI.chargingForward)
				{
					rustyAnimator.SetInteger("currentAnim", 6);
				}
				if (RadMechAI.attemptingGrab)
				{
					rustyAnimator.SetInteger("currentAnim", 3);
				}
			}
			catch (Exception ex)
			{
				RustyModBase.mls.LogError((object)("Step tracker error: " + ex));
			}
		}
		catch (Exception ex2)
		{
			RustyModBase.mls.LogError((object)("CANNOT CHANGE MATERIAL: " + ex2));
		}
	}

	private void HideRadMechModel()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Renderer[] componentsInChildren = ((Component)((Component)RadMechAI).transform.Find("MeshContainer")).GetComponentsInChildren<Renderer>();
			componentsInChildren[0].enabled = false;
		}
		catch (Exception ex)
		{
			RustyModBase.mls.LogError((object)("RUSTY MOD HIDE RADMECH ERROR: " + ex.Message));
		}
	}

	private void CreateRustyModels()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject asset = Assets.GetAsset<GameObject>("rustyPrefab");
			BaseRustyObject = Object.Instantiate<GameObject>(asset, ((Component)this).gameObject.transform);
			((Object)BaseRustyObject).name = "RustyModel";
			try
			{
				rustyAudioSource = BaseRustyObject.GetComponentInChildren<AudioSource>();
			}
			catch (Exception ex)
			{
				RustyModBase.mls.LogError((object)("Audio source errer: " + ex));
			}
			try
			{
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(((Component)this).gameObject.transform.position.x, ((Component)this).gameObject.transform.position.y, ((Component)this).gameObject.transform.position.z);
				Animator[] componentsInChildren = ((Component)((Component)RadMechAI).transform).GetComponentsInChildren<Animator>();
				foreach (Animator val2 in componentsInChildren)
				{
					if (((Object)val2).name == "AnimContainer")
					{
						vanillaRadMechAnimator = val2;
					}
				}
				BaseRustyObject.transform.SetPositionAndRotation(val, ((Component)this).gameObject.transform.rotation);
				BaseRustyObject.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
			}
			catch (Exception ex2)
			{
				RustyModBase.mls.LogError((object)("Positioning error: " + ex2));
			}
			try
			{
				rustyAnimator = BaseRustyObject.GetComponentInChildren<Animator>();
			}
			catch (Exception ex3)
			{
				RustyModBase.mls.LogError((object)("Animator errer: " + ex3));
			}
			try
			{
				rustyAnimator.SetInteger("currentAnim", 0);
			}
			catch (Exception ex4)
			{
				RustyModBase.mls.LogError((object)("ANIMATOR ERROR: " + ex4));
			}
		}
		catch (Exception ex5)
		{
			RustyModBase.mls.LogError((object)("RUSTY MODEL ERROR: " + ex5));
		}
	}

	private void LoadSounds()
	{
		string soundFolder = RustyModBase.soundFolder;
		voiceLines = new List<AudioClip>();
		audioMainSystem = SoundTool.GetAudioClip(RustyModBase.soundFolder, "mainSystem.mp3");
		audioAllOrNothing = SoundTool.GetAudioClip(soundFolder, "allOrNothing.mp3");
		voiceLines.Add(audioAllOrNothing);
		audioBuddy = SoundTool.GetAudioClip(soundFolder, "buddy.mp3");
		voiceLines.Add(audioBuddy);
		audioDontDie = SoundTool.GetAudioClip(soundFolder, "dontDie.mp3");
		voiceLines.Add(audioDontDie);
		audioHeyBuddy = SoundTool.GetAudioClip(soundFolder, "heyBuddy.mp3");
		voiceLines.Add(audioHeyBuddy);
		audioHopeOrDispair = SoundTool.GetAudioClip(soundFolder, "hopeOrDispair.mp3");
		voiceLines.Add(audioHopeOrDispair);
		audioIWontMiss = SoundTool.GetAudioClip(soundFolder, "iWontMiss.mp3");
		voiceLines.Add(audioIWontMiss);
		audioImComing1 = SoundTool.GetAudioClip(soundFolder, "imComing1.mp3");
		voiceLines.Add(audioImComing1);
		audioImComing2 = SoundTool.GetAudioClip(soundFolder, "imComing2.mp3");
		voiceLines.Add(audioImComing2);
		audioKeepYouWaiting = SoundTool.GetAudioClip(soundFolder, "keepYouWaiting.mp3");
		voiceLines.Add(audioKeepYouWaiting);
		audioLockOn = SoundTool.GetAudioClip(soundFolder, "lockOn.mp3");
		voiceLines.Add(audioLockOn);
		audioNoChoice = SoundTool.GetAudioClip(soundFolder, "noChoice.mp3");
		voiceLines.Add(audioNoChoice);
		audioNoGraverThreat = SoundTool.GetAudioClip(soundFolder, "noGraverThreat.mp3");
		voiceLines.Add(audioNoGraverThreat);
		audioOnlyICanFly = SoundTool.GetAudioClip(soundFolder, "onlyICanFly.mp3");
		voiceLines.Add(audioOnlyICanFly);
		audioRubicon = SoundTool.GetAudioClip(soundFolder, "rubicon.mp3");
		voiceLines.Add(audioRubicon);
		audioStayCool = SoundTool.GetAudioClip(soundFolder, "stayCool.mp3");
		voiceLines.Add(audioStayCool);
		audioStepUpMyGame = SoundTool.GetAudioClip(soundFolder, "stepUpMyGame.mp3");
		voiceLines.Add(audioStepUpMyGame);
		audioUnderPressure = SoundTool.GetAudioClip(soundFolder, "underPressure.mp3");
		voiceLines.Add(audioUnderPressure);
		audioWatchOut = SoundTool.GetAudioClip(soundFolder, "watchOut.mp3");
		voiceLines.Add(audioWatchOut);
		audioWhatDrivesYou = SoundTool.GetAudioClip(soundFolder, "whatDrivesYou.mp3");
		voiceLines.Add(audioWhatDrivesYou);
		audioYouCanDoBetter = SoundTool.GetAudioClip(soundFolder, "youCanDoBetter.mp3");
		voiceLines.Add(audioYouCanDoBetter);
		audioYouThereBuddy = SoundTool.GetAudioClip(soundFolder, "youThereBuddy.mp3");
		voiceLines.Add(audioYouThereBuddy);
		audioYoureFast = SoundTool.GetAudioClip(soundFolder, "youreFast.mp3");
		voiceLines.Add(audioYoureFast);
		audioYoureGood = SoundTool.GetAudioClip(soundFolder, "youreGood.mp3");
		voiceLines.Add(audioYoureGood);
	}

	public void TakeStep1()
	{
		rustyAnimator.SetBool("step2", false);
		rustyAnimator.SetBool("step1", true);
	}

	public void TakeStep2()
	{
		rustyAnimator.SetBool("step1", false);
		rustyAnimator.SetBool("step2", true);
	}

	private void UpdateScanNodeData()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		((Component)RadMechAI).GetComponentInChildren<ScanNodeProperties>().headerText = "STEEL HAZE /\nV.IV Rusty";
	}
}
internal static class SoundPatches
{
	public static void Patch()
	{
		try
		{
			RustyModBase.mls.LogInfo((object)("Sound Folder: " + RustyModBase.soundFolder));
			AudioClip audioClip = SoundTool.GetAudioClip(RustyModBase.soundFolder, "none.mp3");
			AudioClip audioClip2 = SoundTool.GetAudioClip(RustyModBase.soundFolder, "mainSystem.mp3");
			SoundTool.ReplaceAudioClip("robotTune", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("RadMechAmbientSFX", audioClip, "EngineSFX");
			SoundTool.ReplaceAudioClip("NeonLightFlicker", audioClip, "VoiceSFX");
			SoundTool.ReplaceAudioClip("LRADAlarm3", audioClip, "3DLradAudio");
			SoundTool.ReplaceAudioClip("ToWar", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("LradBrainwashingSignal1", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("LradBrainwashingSignal4", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("LradBrainwashingSignal6", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("LradBrainwashingSignal7", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("LradBrainwashingSignal8", audioClip, "3DLradAudio2");
			SoundTool.ReplaceAudioClip("RadMechWake", audioClip2, "CreatureSFX");
			RustyModBase.mls.LogInfo((object)"AAAAAAAAAS");
		}
		catch (Exception ex)
		{
			RustyModBase.mls.LogError((object)("SOUND ERROR: " + ex));
		}
	}
}
[HarmonyPatch]
internal class SpawnObjectPatch
{
	[HarmonyPatch(typeof(RoundManager), "SyncNestSpawnPositionsClientRpc")]
	[HarmonyPostfix]
	public static void GetMapObject(RoundManager __instance)
	{
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			RustyModBase.mls.LogInfo((object)"Patching RadMech spawn");
			List<EnemyAINestSpawnObject> enemyNestSpawnObjects = __instance.enemyNestSpawnObjects;
			foreach (EnemyAINestSpawnObject item in enemyNestSpawnObjects)
			{
				if (!(item.enemyType.enemyName != "RadMech"))
				{
					EnemyAINestSpawnObject val = item;
					try
					{
						Renderer[] componentsInChildren = ((Component)((Component)item).transform.Find("MeshContainer")).GetComponentsInChildren<Renderer>();
						componentsInChildren[0].enabled = false;
						((Component)item).GetComponentInChildren<ScanNodeProperties>().headerText = "STEEL HAZE /\nV.IV Rusty";
					}
					catch (Exception ex)
					{
						RustyModBase.mls.LogError((object)("Hide RadMech Error: " + ex.Message));
					}
					GameObject asset = Assets.GetAsset<GameObject>("rustyPrefab");
					GameObject val2 = Object.Instantiate<GameObject>(asset, ((Component)val).transform);
					((Object)val2).name = "RustyModel";
					val2.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
				}
			}
		}
		catch (Exception ex2)
		{
			RustyModBase.mls.LogError((object)("Spawn Object Error: " + ex2));
		}
		RustyModBase.mls.LogInfo((object)"RadMech spawn patched");
	}
}
[BepInPlugin("Eyasu.OurBuddyRusty", "Our Buddy Rusty", "1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class RustyModBase : BaseUnityPlugin
{
	private const string modGUID = "Eyasu.OurBuddyRusty";

	private const string modName = "Our Buddy Rusty";

	private const string modVersion = "1.0";

	private readonly Harmony Harmony = new Harmony("Eyasu.OurBuddyRusty");

	public static ManualLogSource mls;

	public static AssetBundle RustyBundle;

	public static Mesh shovelMesh;

	public static Material shovelMat;

	public static string location;

	public static string soundFolder;

	private static RustyModBase Instance;

	private void Awake()
	{
		mls = Logger.CreateLogSource("Eyasu.OurBuddyRusty");
		mls.LogInfo((object)"AMOGUS SUS");
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		location = Path.Join((ReadOnlySpan<char>)Paths.PluginPath, (ReadOnlySpan<char>)"Eyasu-OurBuddyRusty");
		soundFolder = location;
		string text = Path.Join((ReadOnlySpan<char>)location, (ReadOnlySpan<char>)"rusty");
		RustyBundle = AssetBundle.LoadFromFile(text);
		mls.LogInfo((object)"Loading asset bundle...");
		Assets.PopulateAssets();
		if ((Object)(object)RustyBundle == (Object)null)
		{
			mls.LogError((object)"RUSTY BUNDLE FAILED TO LOAD");
		}
		Mesh[] array = RustyBundle.LoadAllAssets<Mesh>();
		foreach (Mesh val in array)
		{
			mls.LogMessage((object)((Object)val).name);
		}
		Harmony.PatchAll(typeof(RustyModBase));
		Harmony.PatchAll(typeof(EnemyPatches));
		SoundPatches.Patch();
		try
		{
			Harmony.PatchAll(typeof(SpawnObjectPatch));
		}
		catch (Exception ex)
		{
			mls.LogError((object)("Spawn Object Patching Error: " + ex));
		}
		AudioClip audioClip = SoundTool.GetAudioClip(soundFolder, "none.mp3");
		AudioClip audioClip2 = SoundTool.GetAudioClip(soundFolder, "mainSystem.mp3");
	}
}
namespace RustyMod
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RustyMod";

		public const string PLUGIN_NAME = "RustyMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RustyModUtils
{
	internal static class Assets
	{
		public static AssetBundle AssetBundle { get; private set; }

		private static Dictionary<string, Object> AssetList { get; set; }

		private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

		public static void PopulateAssets()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			if ((Object)AssetBundle != (Object)null)
			{
				RustyModBase.mls.LogWarning((object)"Attempted to load the asset bundle but the bundle was not null!");
				return;
			}
			string name = AssemblyName + ".Bundle.gokubracken";
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
			{
				AssetBundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)AssetBundle == (Object)null)
			{
				RustyModBase.mls.LogError((object)("Asset bundle at " + AssemblyName + ".gokubracken failed to load!"));
			}
			AssetList = new Dictionary<string, Object>();
			Object[] array = AssetBundle.LoadAllAssets();
			Object[] array2 = array;
			foreach (Object val in array2)
			{
				AssetList.Add(val.name, val);
			}
		}
	}
}