Decompiled source of LethallyWide v1.1.3

BepInEx/plugins/LethallyWide.dll

Decompiled 6 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
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: AssemblyTitle("LC Ultrawide")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC Ultrawide")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c57c79ae-4ad6-4a9f-a590-27d09b8e6c11")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethallyWideMod;

[BepInPlugin("LethallyWide", "Lethally Wide", "1.1.3")]
public class LethallyWide2 : BaseUnityPlugin
{
	public static ManualLogSource log;

	public static bool ultrawide;

	public static ConfigEntry<bool> useCustomFOV;

	public static ConfigEntry<int> resdiv_cfg;

	public static ConfigEntry<int> targetFOV_cfg;

	public static ConfigEntry<int> terminalFOV_cfg;

	public static ConfigEntry<float> posmod_z_cfg;

	public static ConfigEntry<float> posmod_zt_cfg;

	public static ConfigEntry<float> posmod_y_cfg;

	public static ConfigEntry<bool> useCustomDimensions;

	public static ConfigEntry<int> customW;

	public static ConfigEntry<int> customH;

	public static ConfigEntry<float> uiScale;

	public static ConfigEntry<float> uiAspect;

	public static ConfigEntry<bool> visorEnabled;

	public static Vector3 startGameCamLocalPos;

	public static Vector2 dimensions_mult;

	public static Vector2 dimensions;

	public static float aspect;

	private void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		log = Logger.CreateLogSource("Lethally Wide Mod");
		Harmony val = new Harmony("com.n8bits.lethallywide");
		resdiv_cfg = ((BaseUnityPlugin)this).Config.Bind<int>("RESOLUTION", "resdiv", 1, "Divides resolution by this number. Higher values make pixelation effect stronger.");
		useCustomDimensions = ((BaseUnityPlugin)this).Config.Bind<bool>("RESOLUTION", "use_custom_dimensions", false, "True = Mod sets game dimensions to values in this file. Fale = Mod auto-detects resolution.");
		customW = ((BaseUnityPlugin)this).Config.Bind<int>("RESOLUTION", "Width", 3440, "Only used if use_custom_dimensions = true. Otherwise this value is detected automatically.");
		customH = ((BaseUnityPlugin)this).Config.Bind<int>("RESOLUTION", "Height", 1440, "Only used if use_custom_dimensions = true. Otherwise this value is detected automatically.");
		visorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "visor", true, "Whether the visor overlay is visible");
		uiScale = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "UI_scale", 3.2f, "Scales the games first person UI.");
		uiAspect = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "UI_aspect", 1.77f, "Scales the games first person UI. 16:9 = 1.77 | 21:9 = 2.33 | 32:9 = 3.55");
		useCustomFOV = ((BaseUnityPlugin)this).Config.Bind<bool>("FOV", "use_custom_FOV", false, "Whether to use the values here for FOV or just use vanilla.");
		targetFOV_cfg = ((BaseUnityPlugin)this).Config.Bind<int>("FOV", "targetFOV", 66, "Sets the default field of view (FOV). On a 21:9, 3440x1440 monitor, a maximum FOV of 103 is recommended to avoid gameplay issues due to pop-in effects.");
		terminalFOV_cfg = ((BaseUnityPlugin)this).Config.Bind<int>("FOV", "terminalFOV", 66, "Adjusts the FOV for terminal use. An FOV of 80 is optimal for 21:9, 3440x1440 monitors, balancing text distortion and camera zoom.");
		posmod_zt_cfg = ((BaseUnityPlugin)this).Config.Bind<float>("OFFSET", "cam_offset_z_terminal", 0f, "When using the terminal, jimmys the camera forward/backward by that many meters. ");
		posmod_z_cfg = ((BaseUnityPlugin)this).Config.Bind<float>("OFFSET", "cam_offset_z", 0f, "Alters the camera's forward/backward offset. You may want to toy with this if using higher FOV to prevent clipping.");
		posmod_y_cfg = ((BaseUnityPlugin)this).Config.Bind<float>("OFFSET", "cam_offset_y", 0f, "Adjusts the camera's vertical position. You may want to toy with this about -0.1 if using high FOV and you see your head while sprinting.");
		val.PatchAll(typeof(PlayerControllerBPatches));
		val.PatchAll(typeof(HUDManagerPatches));
	}
}
public static class PlayerControllerBPatches
{
	[HarmonyPatch(typeof(PlayerControllerB), "Start")]
	[HarmonyPrefix]
	private static void PlayerControllerInit(PlayerControllerB __instance)
	{
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		if (LethallyWide2.useCustomDimensions.Value)
		{
			LethallyWide2.dimensions = new Vector2((float)Mathf.RoundToInt((float)(LethallyWide2.customW.Value / LethallyWide2.resdiv_cfg.Value)), (float)Mathf.RoundToInt((float)(LethallyWide2.customH.Value / LethallyWide2.resdiv_cfg.Value)));
			LethallyWide2.log.LogInfo((object)("Using cfg dimensions. " + LethallyWide2.dimensions.x + "/" + LethallyWide2.dimensions.y));
		}
		else
		{
			LethallyWide2.dimensions = new Vector2((float)(Screen.width / LethallyWide2.resdiv_cfg.Value), (float)(Screen.height / LethallyWide2.resdiv_cfg.Value));
			LethallyWide2.log.LogInfo((object)("Using auto detected dimensions. " + LethallyWide2.dimensions.x + "/" + LethallyWide2.dimensions.y));
		}
		LethallyWide2.aspect = LethallyWide2.dimensions.x / LethallyWide2.dimensions.y;
		LethallyWide2.log.LogInfo((object)("Using game aspect " + LethallyWide2.aspect));
		LethallyWide2.log.LogInfo((object)"Finished initializing dimensions.");
		__instance.gameplayCamera.aspect = LethallyWide2.aspect;
		LethallyWide2.log.LogInfo((object)("Set gameplay camera aspect to = " + LethallyWide2.aspect));
		RenderTexture targetTexture = __instance.gameplayCamera.targetTexture;
		LethallyWide2.log.LogInfo((object)"Found gameplayCamera targetTexture");
		GameObject val = GameObject.Find("Systems/UI/Canvas/Panel");
		GameObject val2 = GameObject.Find("Systems/UI/Canvas");
		GameObject val3 = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD");
		GameObject val4 = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/Inventory");
		LethallyWide2.log.LogInfo((object)"Found all game objects.");
		((Texture)targetTexture).width = (int)LethallyWide2.dimensions.x;
		((Texture)targetTexture).height = (int)LethallyWide2.dimensions.y;
		LethallyWide2.log.LogInfo((object)"Set target texture dimensions.");
		AspectRatioFitter val5 = default(AspectRatioFitter);
		if ((Object)(object)val != (Object)null && val.TryGetComponent<AspectRatioFitter>(ref val5))
		{
			val5.aspectRatio = LethallyWide2.aspect;
			LethallyWide2.log.LogInfo((object)"Set UI panel fitter.");
		}
		Canvas val6 = default(Canvas);
		if (val2.TryGetComponent<Canvas>(ref val6))
		{
			val6.scaleFactor = LethallyWide2.uiScale.Value;
			LethallyWide2.log.LogInfo((object)"Set system UI canvas scale factor.");
		}
		AspectRatioFitter val7 = default(AspectRatioFitter);
		if ((Object)(object)val3 != (Object)null && val3.TryGetComponent<AspectRatioFitter>(ref val7))
		{
			val7.aspectRatio = LethallyWide2.uiAspect.Value;
			LethallyWide2.log.LogInfo((object)"Set in game player HUD fitter.");
		}
		RectTransform val8 = default(RectTransform);
		if ((Object)(object)val4 != (Object)null && val4.TryGetComponent<RectTransform>(ref val8))
		{
			val8.anchoredPosition = Vector2.zero;
			val8.anchorMax = new Vector2(0.5f, 0f);
			val8.anchorMin = new Vector2(0.5f, 0.5f);
			val8.pivot = new Vector2(0.5f, 0f);
			LethallyWide2.log.LogInfo((object)"Anchored inventory HUD rect.");
		}
		if (!LethallyWide2.visorEnabled.Value)
		{
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(0f, 0f, 0f);
			__instance.localVisor.localScale = localScale;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	[HarmonyPostfix]
	private static void Update_Postfix(PlayerControllerB __instance)
	{
		//IL_0139: 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_0150: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.inTerminalMenu)
		{
			if (LethallyWide2.useCustomFOV.Value && __instance.gameplayCamera.fieldOfView != (float)LethallyWide2.terminalFOV_cfg.Value)
			{
				__instance.gameplayCamera.fieldOfView = Mathf.Lerp(__instance.gameplayCamera.fieldOfView, (float)LethallyWide2.terminalFOV_cfg.Value, 3f * Time.deltaTime);
			}
			((Component)__instance.gameplayCamera).transform.localPosition = new Vector3(LethallyWide2.startGameCamLocalPos.x, LethallyWide2.startGameCamLocalPos.y, LethallyWide2.startGameCamLocalPos.z + LethallyWide2.posmod_zt_cfg.Value);
		}
		else
		{
			if (LethallyWide2.useCustomFOV.Value && __instance.gameplayCamera.fieldOfView != (float)LethallyWide2.targetFOV_cfg.Value)
			{
				__instance.gameplayCamera.fieldOfView = LethallyWide2.targetFOV_cfg.Value;
			}
			((Component)__instance.gameplayCamera).transform.localPosition = new Vector3(LethallyWide2.startGameCamLocalPos.x, LethallyWide2.startGameCamLocalPos.y + LethallyWide2.posmod_y_cfg.Value, LethallyWide2.startGameCamLocalPos.z + LethallyWide2.posmod_z_cfg.Value);
		}
		Vector3 localPosition = ((Component)__instance.gameplayCamera).transform.localPosition;
		if (localPosition.z != LethallyWide2.startGameCamLocalPos.z + LethallyWide2.posmod_z_cfg.Value && !__instance.inTerminalMenu)
		{
			Vector3 localPosition2 = default(Vector3);
			((Vector3)(ref localPosition2))..ctor(LethallyWide2.startGameCamLocalPos.x, LethallyWide2.startGameCamLocalPos.y, LethallyWide2.startGameCamLocalPos.z + LethallyWide2.posmod_z_cfg.Value);
			((Component)__instance.gameplayCamera).transform.localPosition = localPosition2;
		}
	}
}
public class TerminalPatches
{
	[HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")]
	[HarmonyPrefix]
	private static void ResizeHDTex(Terminal __instance)
	{
		__instance.playerScreenTexHighRes.Release();
		((Texture)__instance.playerScreenTexHighRes).width = (int)LethallyWide2.dimensions.x;
		((Texture)__instance.playerScreenTexHighRes).height = (int)LethallyWide2.dimensions.y;
		__instance.playerScreenTexHighRes.Create();
		LethallyWide2.log.LogInfo((object)"Resized the HD texture used in Terminal.Update()");
	}
}
public class HUDManagerPatches
{
	[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
	[HarmonyPostfix]
	private static void HUDManagerUpdateScanNodes(PlayerControllerB playerScript, HUDManager __instance)
	{
		//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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		RectTransform[] scanElements = __instance.scanElements;
		Dictionary<RectTransform, ScanNodeProperties> dictionary = Traverse.Create((object)__instance).Field("scanNodes").GetValue() as Dictionary<RectTransform, ScanNodeProperties>;
		RectTransform val = default(RectTransform);
		if (!GameObject.Find("Systems/UI/Canvas/Panel/GameObject/PlayerScreen").TryGetComponent<RectTransform>(ref val))
		{
			return;
		}
		Rect rect = val.rect;
		for (int i = 0; i < scanElements.Length; i++)
		{
			if (dictionary.TryGetValue(scanElements[i], out var value))
			{
				Vector3 val2 = playerScript.gameplayCamera.WorldToViewportPoint(((Component)value).transform.position);
				scanElements[i].anchoredPosition = new Vector2(((Rect)(ref rect)).xMin + ((Rect)(ref rect)).width * val2.x, ((Rect)(ref rect)).yMin + ((Rect)(ref rect)).height * val2.y);
			}
		}
	}
}