Decompiled source of Rains Car Mod v0.0.5

RainsCarMod.dll

Decompiled 2 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 FishNet;
using FishNet.Connection;
using FishNet.Managing.Client;
using FishNet.Object;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RainsCarMod;
using RainsCarMod.Logging;
using S1API.PhoneApp;
using S1API.UI;
using ScheduleOne.UI.Phone;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(CarSpawnerAppLoader), "RainsCarMod", "0.0.1", "RainingDeath", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RainsCarMod")]
[assembly: AssemblyConfiguration("DebugMelon")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RainsCarMod")]
[assembly: AssemblyTitle("RainsCarMod")]
[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 RainsCarMod
{
	public class CarSpawnerAppLoader : MelonMod
	{
		[HarmonyPatch(typeof(HomeScreen), "Start")]
		public class HomeScreenStartPatch
		{
			private static void Postfix(HomeScreen __instance)
			{
				CarSpawnerApp obj = new CarSpawnerApp();
				MethodInfo method = typeof(PhoneApp).GetMethod("SpawnIcon", BindingFlags.Instance | BindingFlags.NonPublic);
				MethodInfo method2 = typeof(PhoneApp).GetMethod("SpawnUI", BindingFlags.Instance | BindingFlags.NonPublic);
				method?.Invoke(obj, new object[1] { __instance });
				method2?.Invoke(obj, new object[1] { __instance });
				MelonLogger.Msg("[CarSpawnerApp] \ud83d\ude97 Phone app UI and icon injected.");
			}
		}

		public static readonly Dictionary<string, GameObject> LoadedPrefabs = new Dictionary<string, GameObject>();

		public override void OnApplicationStart()
		{
			((MelonBase)this).HarmonyInstance.PatchAll();
			LoadEmbeddedBundle();
			new CarSpawnerApp();
		}

		private void LoadEmbeddedBundle()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream("RainsCarMod.Resources.carmod");
			if (stream == null)
			{
				MelonLogger.Error("[CarSpawnerAppLoader] ❌ Embedded AssetBundle not found.");
				return;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			AssetBundle val = AssetBundle.LoadFromMemory(memoryStream.ToArray());
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error("[CarSpawnerAppLoader] ❌ Failed to load embedded AssetBundle.");
				return;
			}
			Object[] array = val.LoadAllAssets();
			foreach (Object val2 in array)
			{
				GameObject val3 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
				if (val3 != null && !LoadedPrefabs.ContainsKey(((Object)val3).name))
				{
					LoadedPrefabs.Add(((Object)val3).name, val3);
					MelonLogger.Msg("[CarSpawnerAppLoader] ✅ Loaded prefab: " + ((Object)val3).name);
				}
			}
		}
	}
	public class CarSpawnerApp : PhoneApp
	{
		protected override string AppName => "CarSpawnerApp";

		protected override string AppTitle => "Car Spawner";

		protected override string IconLabel => "CarSpawner";

		protected override string IconFileName => "Rain'sCarModIcon.png";

		private void SpawnVehicle(string prefabKey, string label)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsServer)
			{
				MelonLogger.Warning("[CarSpawnerApp] ❌ Only the server can spawn networked objects.");
				return;
			}
			ClientManager clientManager = InstanceFinder.ClientManager;
			object obj;
			if (clientManager == null)
			{
				obj = null;
			}
			else
			{
				NetworkConnection connection = clientManager.Connection;
				obj = ((connection != null) ? connection.FirstObject : null);
			}
			NetworkObject val = (NetworkObject)obj;
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("[CarSpawnerApp] ❌ Local FishNet player not found.");
				return;
			}
			Transform transform = ((Component)val).transform;
			Vector3 val2 = transform.position + transform.forward * 5f;
			Quaternion rotation = transform.rotation;
			if (!CarSpawnerAppLoader.LoadedPrefabs.TryGetValue(prefabKey, out var value))
			{
				MelonLogger.Error("[CarSpawnerApp] ❌ '" + prefabKey + "' prefab not found in loaded bundles.");
				return;
			}
			NetworkObject component = value.GetComponent<NetworkObject>();
			if ((Object)(object)component == (Object)null)
			{
				MelonLogger.Warning("[CarSpawnerApp] ❌ " + label + " prefab is missing NetworkObject.");
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(value, val2, rotation);
			InstanceFinder.ServerManager.Spawn(val3, (NetworkConnection)null, default(Scene));
			MelonLogger.Msg("[CarSpawnerApp] ✅ " + label + " spawned and replicated over network.");
		}

		protected override void OnCreatedUI(GameObject container)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			GameObject val = UIFactory.Panel("CarSpawnerPanel", container.transform, new Color(0.5f, 0f, 0.5f), (Vector2?)null, (Vector2?)null, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(1250f, 700f);
			VerticalLayoutGroup val2 = val.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val2).spacing = 10f;
			((LayoutGroup)val2).childAlignment = (TextAnchor)1;
			Button item = UIFactory.RoundedButtonWithLabel("spawnButton", "Spawn GODZILLA", val.transform, new Color(0f, 1f, 0.2f), 100f, 60f, 18, Color.white).Item2;
			((UnityEvent)item.onClick).AddListener((UnityAction)delegate
			{
				SpawnVehicle("GODZILLA", "GODZILLA");
			});
			Button item2 = UIFactory.RoundedButtonWithLabel("hellButton", "Spawn HellStorm", val.transform, new Color(0.3f, 0.5f, 1f), 100f, 60f, 18, Color.white).Item2;
			((UnityEvent)item2.onClick).AddListener((UnityAction)delegate
			{
				SpawnVehicle("HellStorm", "HellStorm");
			});
			Button item3 = UIFactory.RoundedButtonWithLabel("driftButton", "Spawn Driftcar", val.transform, new Color(0.4f, 0f, 1f), 100f, 60f, 18, Color.white).Item2;
			((UnityEvent)item3.onClick).AddListener((UnityAction)delegate
			{
				SpawnVehicle("driftcar", "Driftcar");
			});
			Button item4 = UIFactory.RoundedButtonWithLabel("superButton", "Spawn Supercar", val.transform, new Color(1f, 0f, 0.7f), 100f, 60f, 18, Color.white).Item2;
			((UnityEvent)item4.onClick).AddListener((UnityAction)delegate
			{
				SpawnVehicle("supercar", "Supercar");
			});
			Button item5 = UIFactory.RoundedButtonWithLabel("soupButton", "Spawn Soup Car", val.transform, new Color(1f, 0f, 0.4f), 100f, 60f, 18, Color.white).Item2;
			((UnityEvent)item5.onClick).AddListener((UnityAction)delegate
			{
				SpawnVehicle("canofsoupcar", "Can of Soup Car");
			});
		}
	}
	public class Core : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Log.LogInfo("Initializing RainsCarMod...");
		}
	}
}
namespace RainsCarMod.Logging
{
	public static class Log
	{
		public static void LogInfo(string message)
		{
			Melon<Core>.Logger.Msg(message);
		}

		public static void LogWarning(string message)
		{
			Melon<Core>.Logger.Warning(message);
		}

		public static void LogError(string message)
		{
			Melon<Core>.Logger.Error(message);
		}

		public static void LogFatal(string message)
		{
			Melon<Core>.Logger.BigError(message);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}