My mod’s entry point

Home   »   My mod’s entry point

using System.Runtime.CompilerServices;

using BepInEx;
using BepInEx.Logging;

using HarmonyLib;

using SCMultiMod.Cheats;
using SCMultiMod.Tools;

namespace SCMultiMod
{
	[BepInPlugin(Utilities.PLUGIN_BEPINEX_GUID, "Storm Chasers Multi-Mod", "1.0.0.0")]
	[BepInProcess("Storm Chasers.exe")]
	public sealed class PluginEntry : BaseUnityPlugin
	{
		public static PluginEntry INSTANCE { [MethodImpl(MethodImplOptions.NoInlining)] get; private set; }

		public readonly PhotonObjects localObjects;

		internal new PluginConfig Config { get; }
		internal new ManualLogSource Logger => base.Logger;

		public PluginEntry() : base()
		{
			INSTANCE = this;

			this.localObjects = new PhotonObjects();
			this.Config = new PluginConfig(base.Config);

			new Harmony(Utilities.PLUGIN_BEPINEX_GUID).PatchAll(this.GetType().Assembly);
			this.Logger.LogInfo("Storm Chasers Multi-Mod has finished patching the game");
		}

		public void Start()
		{
			var keyCepter = this.gameObject.AddComponent();
			keyCepter[this.Config.ExplodeTruckKey] = this.ExplodeTruck;
			keyCepter[this.Config.SuicideKey] = this.CommitSuicide;
			keyCepter[this.Config.RemoteStarterKey] = this.ToggleTruckEngine;
			keyCepter[this.Config.RemoteLightsKey] = this.ToggleTruckLights;
			keyCepter[this.Config.RemoteSirensKey] = this.ToggleTruckSiren;
			keyCepter[this.Config.RemoteHornKey] = this.HonkTheHorn;
		}

		private void ExplodeTruck(GlobalValues.GameType gameType)
		{
			if (this.localObjects.LocalTruck != null)
			{
				CarTools.Explode(this.localObjects.LocalTruck);
				this.localObjects.LocalTruck = null; // We destroyed our truck!

				if (gameType == GlobalValues.GameType.ONLINE_FREE_ROAMING || gameType == GlobalValues.GameType.ONLINE_VERSUS)
					GameController.Instance.photonView.RPC("receiveChat", PhotonTargets.All, new object[3] { PhotonNetwork.player, "Oh dear, I decimated my truck", true });
			}
		}

		private void CommitSuicide(GlobalValues.GameType gameType)
		{
			var playerIsDead = this.localObjects.PlayerTraverse.Field("isDead");
			if (!playerIsDead.Value)
			{
				PlayerTools.Die(); // We use this to bypass our godmode (if enabled)
				if (gameType == GlobalValues.GameType.ONLINE_FREE_ROAMING || gameType == GlobalValues.GameType.ONLINE_VERSUS)
					GameController.Instance.sendChatInfoText("A player has bid the cruel world farewell!");
			}
		}

		private void ToggleTruckEngine(GlobalValues.GameType gameType)
		{
			var localTruck = this.localObjects.LocalTruck;
			CarTools.ToggleEngine(localTruck, !localTruck.isEngineStarted);
		}

		private void ToggleTruckLights(GlobalValues.GameType gameType) => CarTools.ToggleLights(this.localObjects.LocalTruck);

		private void ToggleTruckSiren(GlobalValues.GameType gameType) => CarTools.ToggleSirens(this.localObjects.LocalTruck);

		private void HonkTheHorn(GlobalValues.GameType gameType) => CarTools.UseHorn(this.localObjects.LocalTruck);

		public void SCStartGame(GameController gc)
		{
			this.Logger.LogInfo("We are now in a game session!");

			var keyCepter = this.GetComponent();
			if (this.Config.playerCheats.AddScore)
				keyCepter[this.Config.playerCheats.AddScoreKey] = this.Config.playerCheats.AddScoreGlobally;
			keyCepter.enabled = true;

			if (GlobalValues.Instance.gameType == GlobalValues.GameType.ONLINE_FREE_ROAMING)
			{
				if (PlayerCheats.CONFIG.GovernmentStimulus)
					gc.sendChatInfoText($"ATTENTION EVERYONE! THE GOVERNMENT HAS PROVIDED YOU ALL WITH ${PlayerCheats.CONFIG.StartingMoneyAmount}!");
			}
		}

		public void SCEndGame()
		{
			this.Logger.LogInfo("We are now out of a game session!");
			this.GetComponent().enabled = false;
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *