Decompiled source of Tweaks v1.3.0

EasyDeliveryTweaks.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("EasyDeliveryTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyDeliveryTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f84ad313-c1a7-4171-a51b-794f60688197")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EasyDeliveryTweaks;

internal class Config
{
	public static ConfigEntry<bool> fixLowResRender;

	public static ConfigEntry<bool> fixTruckTurn;

	public static ConfigEntry<bool> vertSync;

	public static ConfigEntry<bool> warnings;

	public static ConfigEntry<float> coldModifier;

	public static ConfigEntry<float> energyModifier;

	public static ConfigEntry<float> fuelModifier;

	public static AcceptableValueRange<float> energyModifierRange = new AcceptableValueRange<float>(0f, 2f);

	public static void Bind()
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		fixLowResRender = Main.config.Bind<bool>("", "Render the world in resolution set in options", false, "Restart the game if after toggling this the picture looks too wide");
		fixTruckTurn = Main.config.Bind<bool>("", "Smooth truck turning", false, (ConfigDescription)null);
		warnings = Main.config.Bind<bool>("", "Show warnings", true, (ConfigDescription)null);
		vertSync = Main.config.Bind<bool>("", "Screen vertical synchronization", true, (ConfigDescription)null);
		coldModifier = Main.config.Bind<float>("", "Body temperature loss modifier", 1f, new ConfigDescription("Amount of body temperature you lose when outside will be multiplied by this", (AcceptableValueBase)(object)energyModifierRange, Array.Empty<object>()));
		energyModifier = Main.config.Bind<float>("", "Energy loss modifier", 1f, new ConfigDescription("Energy amount you lose will be multiplied by this", (AcceptableValueBase)(object)energyModifierRange, Array.Empty<object>()));
		fuelModifier = Main.config.Bind<float>("", "Fuel consumption modifier", 1f, new ConfigDescription("Fuel consumed by your truck will be multiplied by this", (AcceptableValueBase)(object)energyModifierRange, Array.Empty<object>()));
		vertSync.SettingChanged += VertSyncChanged;
		fixLowResRender.SettingChanged += FixLowResRenderChanged;
		fixTruckTurn.SettingChanged += FixTruckTurnChanged;
	}

	private static void FixLowResRenderChanged(object sender, EventArgs e)
	{
		LowResRenderFix.FixLowResRender();
	}

	private static void FixTruckTurnChanged(object sender, EventArgs e)
	{
		TruckTurnFix.FixTruckTurning();
	}

	private static void VertSyncChanged(object sender, EventArgs e)
	{
		if (vertSync.Value)
		{
			QualitySettings.vSyncCount = 1;
		}
		else
		{
			QualitySettings.vSyncCount = 0;
		}
	}
}
internal class EnergyModifier
{
	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("LowerEnergy")]
		private static void LowerEnergyPrefix(sHUD __instance, ref float delta)
		{
			delta *= Config.energyModifier.Value;
		}
	}
}
internal class FuelConsumptionModifier
{
	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		private static float fuelBefore;

		[HarmonyPrefix]
		[HarmonyPatch("DoFuelMath")]
		private static void DoFuelMathPrefix(sHUD __instance)
		{
			fuelBefore = __instance.fuel;
		}

		[HarmonyPostfix]
		[HarmonyPatch("DoFuelMath")]
		private static void DoFuelMathPostfix(sHUD __instance)
		{
			if (Config.fuelModifier.Value != 1f)
			{
				if (Config.fuelModifier.Value == 0f)
				{
					__instance.fuel = fuelBefore;
					return;
				}
				float num = __instance.fuel - fuelBefore;
				num *= Config.fuelModifier.Value;
				__instance.fuel = fuelBefore + num;
			}
		}
	}
}
internal class PlayerTemperatureModifier
{
	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPostfix(sHUD __instance)
		{
			if (defaultTemperatureRate == 0f)
			{
				defaultTemperatureRate = __instance.temperatureRate;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("DoTemperature")]
		private static void DoTemperaturePrefix(sHUD __instance)
		{
			__instance.temperatureRate = defaultTemperatureRate * Config.coldModifier.Value;
		}
	}

	private static float defaultTemperatureRate;
}
internal class Warnings
{
	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AddWarning")]
		private static bool AddWarningPrefix(sHUD __instance)
		{
			return Config.warnings.Value;
		}
	}
}
internal class TruckTurnFix
{
	[HarmonyPatch(typeof(sCarController))]
	public class sCarControllerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void UpdatePostfix(sCarController __instance)
		{
			Transform val = ((Component)__instance).transform.Find("Model");
			if ((Object)(object)val != (Object)null)
			{
				truckRR = ((Component)val).GetComponent<RotationRounding>();
			}
			FixTruckTurning();
		}
	}

	private static RotationRounding truckRR;

	public static void FixTruckTurning()
	{
		if (Object.op_Implicit((Object)(object)truckRR))
		{
			((Behaviour)truckRR).enabled = !Config.fixTruckTurn.Value;
		}
	}
}
[BepInPlugin("qqqbbb.EasyDelivery.tweaks", "Tweaks", "1.3.0")]
public class Main : BaseUnityPlugin
{
	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPostfix(sHUD __instance)
		{
			hud = __instance;
		}
	}

	public const string PLUGIN_GUID = "qqqbbb.EasyDelivery.tweaks";

	public const string PLUGIN_NAME = "Tweaks";

	public const string PLUGIN_VERSION = "1.3.0";

	public static ConfigFile config;

	public static ManualLogSource logger;

	public static sHUD hud;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("qqqbbb.EasyDelivery.tweaks").PatchAll();
		config = ((BaseUnityPlugin)this).Config;
		Config.Bind();
		logger = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Tweaks 1.3.0 is loaded");
	}
}
internal class LowResRenderFix
{
	[HarmonyPatch(typeof(sCameraController))]
	public class CameraPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(sCameraController __instance)
		{
			mainCamera = __instance.cam;
		}
	}

	[HarmonyPatch(typeof(ScreenSystem))]
	public class ScreenSystemPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(ScreenSystem __instance)
		{
			Transform val = ((Component)__instance).transform.Find("Camera Persp/ScreenPivot/Screen");
			if ((Object)(object)val != (Object)null)
			{
				screenMR = ((Component)val).GetComponent<MeshRenderer>();
			}
		}
	}

	[HarmonyPatch(typeof(sCarController))]
	public class sCarControllerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(sCarController __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			currentRes = default(Resolution);
			if (!Object.op_Implicit((Object)(object)rearVeiwMR))
			{
				Transform val = ((Component)__instance).transform.Find("carInt/RearViewMirror");
				if (Object.op_Implicit((Object)(object)val))
				{
					rearVeiwMR = ((Component)val).GetComponent<MeshRenderer>();
				}
				val = ((Component)__instance).transform.Find("RearViewCam");
				if (Object.op_Implicit((Object)(object)val))
				{
					rearVeiwCamera = ((Component)val).GetComponent<Camera>();
				}
			}
		}
	}

	[HarmonyPatch(typeof(sHUD))]
	public class sHUDPatch
	{
		private static void StartPostfix(sHUD __instance)
		{
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdatePostfix(sHUD __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (!((object)(Resolution)(ref currentRes)).Equals((object?)Screen.currentResolution))
			{
				FixLowResRender();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("WorldToHUDPoint")]
		private static void WorldToHUDPointPostfix(sHUD __instance, ref Vector2 __result, Vector3 worldPoint)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (Config.fixLowResRender.Value && resWidthRatio != 0f && __result.x != -100f)
			{
				__result = Vector2.op_Implicit(__instance.navigation.car.carCamera.WorldToScreenPoint(worldPoint));
				__result = new Vector2(__result.x / resWidthRatio, __result.y / resHeightRatio);
				__result.y = (float)__instance.R.height - __result.y;
			}
		}
	}

	public class MainMenuHUDPatch
	{
		private static void UpdatePostfix(MainMenuHUD __instance)
		{
			if (Input.GetKey((KeyCode)118))
			{
				Main.logger.LogDebug((object)"MainMenuHUD FrameUpdate");
			}
		}
	}

	public class PauseSystemPatch
	{
		private static void UpdatePostfix(PauseSystem __instance)
		{
			if (!Input.GetKeyDown((KeyCode)118))
			{
				return;
			}
			Main.logger.LogDebug((object)" InterSceneData  ");
			foreach (KeyValuePair<string, string> item in (Dictionary<string, string>)(object)InterSceneData.instance.data)
			{
				Main.logger.LogDebug((object)(item.Key + " ,value: " + item.Value + " "));
			}
		}

		private static void GotoMainMenuPostfix(PauseSystem __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			currentRes = default(Resolution);
			Main.logger.LogDebug((object)"PauseSystem GotoMainMenu ");
		}
	}

	private const float defaultRenderWidth = 456f;

	private const float defaultRenderHeight = 256f;

	private static RenderTexture newRT;

	private static RenderTexture defaultRT;

	private static RenderTexture newRearVeiwRT;

	private static RenderTexture defaultRearVeiwRT;

	private static MeshRenderer screenMR;

	private static MeshRenderer rearVeiwMR;

	private static Camera mainCamera;

	private static Camera rearVeiwCamera;

	private static float resWidthRatio;

	private static float resHeightRatio;

	private static Resolution currentRes;

	private static void CreateNewRenderTexture(Camera cam)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_007b: 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)
		if (!((Object)(object)cam.targetTexture == (Object)null))
		{
			defaultRT = cam.targetTexture;
			Resolution currentResolution = Screen.currentResolution;
			int width = ((Resolution)(ref currentResolution)).width;
			currentResolution = Screen.currentResolution;
			int height = ((Resolution)(ref currentResolution)).height;
			if (((Texture)defaultRT).width == width && ((Texture)defaultRT).height == height)
			{
				newRT = defaultRT;
				return;
			}
			newRT = new RenderTexture(width, height, defaultRT.depth);
			newRT.format = defaultRT.format;
			newRT.antiAliasing = defaultRT.antiAliasing;
			((Texture)newRT).filterMode = ((Texture)defaultRT).filterMode;
			newRT.Create();
		}
	}

	public static void FixLowResRender()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		currentRes = Screen.currentResolution;
		resWidthRatio = (float)((Resolution)(ref currentRes)).width / 456f;
		resHeightRatio = (float)((Resolution)(ref currentRes)).height / 256f;
		CreateNewRenderTexture(mainCamera);
		CreateNewRearViewRenderTexture(rearVeiwCamera);
		if (Config.fixLowResRender.Value)
		{
			((Renderer)screenMR).material.mainTexture = (Texture)(object)newRT;
			mainCamera.targetTexture = newRT;
			rearVeiwCamera.targetTexture = newRearVeiwRT;
			((Renderer)rearVeiwMR).material.mainTexture = (Texture)(object)newRearVeiwRT;
		}
		else
		{
			((Renderer)screenMR).material.mainTexture = (Texture)(object)defaultRT;
			mainCamera.targetTexture = defaultRT;
			rearVeiwCamera.targetTexture = defaultRearVeiwRT;
			((Renderer)rearVeiwMR).material.mainTexture = (Texture)(object)defaultRearVeiwRT;
		}
	}

	private static void CreateNewRearViewRenderTexture(Camera cam)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)cam.targetTexture == (Object)null))
		{
			defaultRearVeiwRT = cam.targetTexture;
			Resolution currentResolution = Screen.currentResolution;
			int num = (int)((float)((Resolution)(ref currentResolution)).width / 4.5f);
			currentResolution = Screen.currentResolution;
			int num2 = (int)((float)((Resolution)(ref currentResolution)).height / 8f);
			if (((Texture)defaultRearVeiwRT).width == num && ((Texture)defaultRearVeiwRT).height == num2)
			{
				newRearVeiwRT = defaultRearVeiwRT;
				return;
			}
			newRearVeiwRT = new RenderTexture(num, num2, defaultRearVeiwRT.depth);
			newRearVeiwRT.format = defaultRearVeiwRT.format;
			newRearVeiwRT.antiAliasing = defaultRearVeiwRT.antiAliasing;
			((Texture)newRearVeiwRT).filterMode = ((Texture)defaultRearVeiwRT).filterMode;
			newRearVeiwRT.Create();
		}
	}
}
internal class Util
{
	public static void DisplayText(string text, float displayTime = 1f)
	{
		if ((Object)(object)Main.hud == (Object)null)
		{
			Main.logger.LogError((object)"Main.hud == null");
		}
		else
		{
			Main.hud.DisplayText(text, displayTime);
		}
	}

	public static bool IsInMainMenu()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		return ((Scene)(ref activeScene)).name == "TitleScreen";
	}

	public static bool IsLoadingScene()
	{
		return SceneTransition.loadingScene;
	}
}