Decompiled source of FuelMod v1.1.0

FuelMod.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using FuelMod;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Vehicles;
using MelonLoader;
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: MelonInfo(typeof(Plugin), "Fuel Mod", "0.1.0", "Fuel Mod", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FuelMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FuelMod")]
[assembly: AssemblyTitle("FuelMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 FuelMod
{
	public sealed class Plugin : MelonMod
	{
		private sealed class FuelState
		{
			public float Fuel { get; set; }

			public AnimationCurve OriginalTorque { get; }

			public bool IsStalled { get; set; }

			public FuelState(float fuel, AnimationCurve originalTorque)
			{
				Fuel = fuel;
				OriginalTorque = originalTorque;
			}
		}

		private const float TankCapacity = 100f;

		private const float FuelPerSecondAt50Kmh = 0.12f;

		private readonly Dictionary<int, FuelState> _fuelByVehicle = new Dictionary<int, FuelState>();

		private AnimationCurve? _emptyTorqueCurve;

		public override void OnInitializeMelon()
		{
			_emptyTorqueCurve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
			((MelonBase)this).LoggerInstance.Msg("Fuel Mod loaded. Press R while stopped in a car to refuel.");
		}

		public override void OnUpdate()
		{
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null || (Object)(object)local.CurrentVehicle == (Object)null)
			{
				return;
			}
			LandVehicle component = ((Component)local.CurrentVehicle).GetComponent<LandVehicle>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)component).GetInstanceID();
			if (!_fuelByVehicle.TryGetValue(instanceID, out FuelState value))
			{
				value = new FuelState(100f, component.motorTorque);
				_fuelByVehicle.Add(instanceID, value);
			}
			if (Input.GetKeyDown((KeyCode)114))
			{
				if (Mathf.Abs(component.Speed_Kmh) < 1f)
				{
					value.Fuel = 100f;
					value.IsStalled = false;
					component.motorTorque = value.OriginalTorque;
					((MelonBase)this).LoggerInstance.Msg("Vehicle refueled.");
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Stop the vehicle before refueling.");
				}
			}
			if (!value.IsStalled && Mathf.Abs(component.Speed_Kmh) > 2f)
			{
				float num = Mathf.Abs(component.Speed_Kmh) / 50f;
				value.Fuel = Mathf.Max(0f, value.Fuel - 0.12f * num * Time.deltaTime);
			}
			if (value.Fuel <= 0f && !value.IsStalled)
			{
				value.IsStalled = true;
				component.motorTorque = _emptyTorqueCurve;
				((MelonBase)this).LoggerInstance.Warning("This vehicle is out of fuel. Stop and press R to refuel.");
			}
		}

		public override void OnGUI()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Player local = Player.Local;
			if (!((Object)(object)local == (Object)null) && !((Object)(object)local.CurrentVehicle == (Object)null))
			{
				LandVehicle component = ((Component)local.CurrentVehicle).GetComponent<LandVehicle>();
				if (!((Object)(object)component == (Object)null) && _fuelByVehicle.TryGetValue(((Object)component).GetInstanceID(), out FuelState value))
				{
					GUI.Label(new Rect(24f, 24f, 220f, 32f), $"Fuel: {Mathf.CeilToInt(value.Fuel)}%");
				}
			}
		}
	}
}