using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InsanityDisplay.Config;
using InsanityDisplay.ModCompatibility;
using InsanityDisplay.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Adds an insanity meter above the stamina meter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InsanityDisplay")]
[assembly: AssemblyCopyright("Confusified © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3df3c939-915d-40af-83e9-b834f47be026")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace InsanityDisplay
{
[BepInPlugin("com.Confusified.InsanityDisplay", "InsanityDisplay", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Initialise : BaseUnityPlugin
{
private const string modGUID = "com.Confusified.InsanityDisplay";
private const string modName = "InsanityDisplay";
private const string modVersion = "1.1.0";
private static readonly string configLocation = Utility.CombinePaths(new string[1] { Paths.ConfigPath + "\\" + "com.Confusified.InsanityDisplay".Substring(4).Replace(".", "\\") });
public static ConfigFile modConfig = new ConfigFile(configLocation + ".cfg", false);
private readonly Harmony _Harmony = new Harmony("com.Confusified.InsanityDisplay");
public static ManualLogSource modLogger;
public void Awake()
{
modLogger = Logger.CreateLogSource("com.Confusified.InsanityDisplay");
modLogger = ((BaseUnityPlugin)this).Logger;
ConfigHandler.InitialiseConfig();
CheckForModCompatibility();
_Harmony.PatchAll(Assembly.GetExecutingAssembly());
modLogger.LogInfo((object)"InsanityDisplay 1.1.0 loaded");
}
private static void CheckForModCompatibility()
{
if (Chainloader.PluginInfos.ContainsKey("LCCrouchHUD"))
{
CompatibilityList.LCCrouch_Installed = true;
modLogger.LogInfo((object)"Enabling LCCrouchHUD compatibility");
}
if (Chainloader.PluginInfos.ContainsKey("me.eladnlg.customhud"))
{
CompatibilityList.EladsHUD_Installed = true;
modLogger.LogInfo((object)"Enabling Elad's HUD compatibility");
}
if (Chainloader.PluginInfos.ContainsKey("com.an0n.patch"))
{
CompatibilityList.An0nPatches_Installed = true;
modLogger.LogInfo((object)"Enabling An0n Patches compatibility");
}
}
}
}
namespace InsanityDisplay.UI
{
public class UIHandler
{
private static Vector3 localPositionOffset = new Vector3(-3.4f, 3.7f, 0f);
private static Vector3 localScale = new Vector3(1.4f, 1.4f, 1.4f);
private static Vector3 selfLocalPositionOffset = new Vector3(-6.8f, 4f, 0f);
private static Color meterColor = ConfigSettings.MeterColor.Value;
private const float accurate_MinValue = 0.2978f;
private const float accurate_MaxValue = 0.9101f;
public static GameObject Memory_InsanityMeter;
public static GameObject InsanityMeter;
public static Image InsanityImage;
private static PlayerControllerB localPlayer;
public static void CreateInMemory()
{
if ((Object)(object)Memory_InsanityMeter != (Object)null)
{
CreateInScene();
return;
}
if (CompatibilityList.EladsHUD_Installed)
{
EnableCompatibilities();
return;
}
Memory_InsanityMeter = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/SprintMeter").gameObject;
Memory_InsanityMeter = Object.Instantiate<GameObject>(Memory_InsanityMeter);
Object.DontDestroyOnLoad((Object)(object)Memory_InsanityMeter);
CreateInScene();
}
private static void CreateInScene()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Memory_InsanityMeter == (Object)null)
{
CreateInMemory();
}
else if (!((Object)(object)InsanityMeter != (Object)null))
{
InsanityMeter = Object.Instantiate<GameObject>(Memory_InsanityMeter);
((Object)InsanityMeter).name = "InsanityMeter";
GameObject gameObject = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner").gameObject;
Transform transform = InsanityMeter.transform;
transform.SetParent(gameObject.transform);
transform.SetAsFirstSibling();
transform.localPosition = ((Component)gameObject.transform.Find("SprintMeter")).gameObject.transform.localPosition + localPositionOffset;
transform.localScale = localScale;
InsanityImage = InsanityMeter.GetComponent<Image>();
((Graphic)InsanityImage).color = meterColor + new Color(0f, 0f, 0f, 1f);
InsanityImage.fillAmount = GetFillAmount();
InsanityMeter.SetActive(ConfigSettings.ModEnabled.Value);
GameObject gameObject2 = ((Component)gameObject.transform.Find("Self")).gameObject;
Transform transform2 = gameObject2.transform;
transform2.localPosition += selfLocalPositionOffset;
GameObject gameObject3 = ((Component)gameObject.transform.Find("SelfRed")).gameObject;
gameObject3.transform.localPosition = gameObject2.transform.localPosition;
Initialise.modLogger.LogInfo((object)"Created insanity meter succesfully");
EnableCompatibilities();
}
}
private static void EnableCompatibilities()
{
Initialise.modLogger.LogInfo((object)"Enabling allowed compatibilities");
if (CompatibilityList.LCCrouch_Installed && ConfigSettings.LCCrouchHUDCompat.Value)
{
LCCrouchHUDCompatibility.MoveCrouchHUD();
}
if (CompatibilityList.EladsHUD_Installed && ConfigSettings.EladsHUDCompat.Value)
{
Object.Destroy((Object)(object)Memory_InsanityMeter);
Object.Destroy((Object)(object)InsanityMeter);
Memory_InsanityMeter = null;
InsanityMeter = null;
EladsHUDCompatibility.EditEladsHUD();
}
if (CompatibilityList.An0nPatches_Installed && ConfigSettings.An0nPatchesCompat.Value)
{
An0nPatchesCompatibility.MoveTextHUD();
}
}
public static float GetFillAmount()
{
if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
return 0f;
}
localPlayer = GameNetworkManager.Instance.localPlayerController;
if (ConfigSettings.alwaysFull.Value)
{
return 1f;
}
if (ConfigSettings.useAccurateDisplay.Value && (!CompatibilityList.EladsHUD_Installed || (CompatibilityList.EladsHUD_Installed && !ConfigSettings.EladsHUDCompat.Value)))
{
if (ConfigSettings.enableReverse.Value)
{
return 0.9101f - localPlayer.insanityLevel / localPlayer.maxInsanityLevel * 0.9101f;
}
return 0.2978f + localPlayer.insanityLevel / localPlayer.maxInsanityLevel * 0.9101f;
}
if (ConfigSettings.enableReverse.Value)
{
return 1f - localPlayer.insanityLevel / localPlayer.maxInsanityLevel;
}
return localPlayer.insanityLevel / localPlayer.maxInsanityLevel;
}
}
}
namespace InsanityDisplay.Patches
{
[HarmonyPatch(typeof(HUDManager))]
public class HUDManageratch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void CreateMeter()
{
UIHandler.CreateInMemory();
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void SetMeterValues()
{
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)UIHandler.InsanityImage == (Object)null || (Object)(object)UIHandler.InsanityMeter == (Object)null)
{
return;
}
UIHandler.InsanityMeter.SetActive(ConfigSettings.ModEnabled.Value);
if (CompatibilityList.EladsHUD_Installed && ConfigSettings.EladsHUDCompat.Value)
{
if ((Object)(object)EladsHUDCompatibility.InsanityInfo == (Object)null)
{
return;
}
((Graphic)EladsHUDCompatibility.InsanityInfo).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
((TMP_Text)EladsHUDCompatibility.InsanityInfo).text = $"{Math.Floor(UIHandler.GetFillAmount() * 100f)}%";
}
UIHandler.InsanityImage.fillAmount = UIHandler.GetFillAmount();
((Graphic)UIHandler.InsanityImage).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
}
}
}
namespace InsanityDisplay.ModCompatibility
{
public class CompatibilityList
{
public const string LCCrouch_GUID = "LCCrouchHUD";
public static bool LCCrouch_Installed;
public const string EladsHUD_GUID = "me.eladnlg.customhud";
public static bool EladsHUD_Installed;
public const string An0nPatches_GUID = "com.an0n.patch";
public static bool An0nPatches_Installed;
}
public class EladsHUDCompatibility
{
private static Vector3 localPositionOffset = new Vector3(0f, 10f, 0f);
private static Vector3 Percentage_localPositionOffset = new Vector3(0f, 28.4f, 0f);
private static GameObject PercentageInsanityText;
public static TextMeshProUGUI InsanityInfo;
public static void EditEladsHUD()
{
CreateCustomInsanityBar();
MoveWithOffset();
}
private static void CreateCustomInsanityBar()
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)UIHandler.Memory_InsanityMeter == (Object)null)
{
CreateInsanityBarInMemory();
}
UIHandler.InsanityMeter = Object.Instantiate<GameObject>(UIHandler.Memory_InsanityMeter);
((Object)UIHandler.InsanityMeter).name = "Insanity";
Transform transform = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/PlayerInfo(Clone)").gameObject.transform;
Transform transform2 = ((Component)transform.Find("Stamina")).gameObject.transform;
Transform transform3 = UIHandler.InsanityMeter.transform;
transform3.SetParent(transform);
transform3.localPosition = transform2.localPosition;
transform3.localScale = transform2.localScale;
transform3.rotation = transform2.rotation;
PercentageInsanityText = ((Component)transform3.Find("StaminaInfo")).gameObject;
InsanityInfo = PercentageInsanityText.GetComponent<TextMeshProUGUI>();
((Graphic)InsanityInfo).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
((TMP_Text)InsanityInfo).horizontalAlignment = (HorizontalAlignmentOptions)4;
((TMP_Text)InsanityInfo).text = $"{Math.Floor(UIHandler.GetFillAmount() * 100f)}%";
UIHandler.InsanityImage = ((Component)transform3.Find("Bar/StaminaBar")).gameObject.GetComponent<Image>();
((Graphic)UIHandler.InsanityImage).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
UIHandler.InsanityImage.fillAmount = UIHandler.GetFillAmount();
}
private static void CreateInsanityBarInMemory()
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)UIHandler.Memory_InsanityMeter != (Object)null))
{
GameObject gameObject = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/PlayerInfo(Clone)/Stamina").gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Initialise.modLogger.LogError((object)"EladsHUD Stamina bar wasn't found");
return;
}
UIHandler.Memory_InsanityMeter = Object.Instantiate<GameObject>(gameObject);
Object.DestroyImmediate((Object)(object)((Component)UIHandler.Memory_InsanityMeter.transform.Find("CarryInfo")).gameObject);
Object.DestroyImmediate((Object)(object)((Component)UIHandler.Memory_InsanityMeter.transform.Find("Bar/Stamina Change FG")).gameObject);
PercentageInsanityText = ((Component)UIHandler.Memory_InsanityMeter.transform.Find("StaminaInfo")).gameObject;
InsanityInfo = PercentageInsanityText.GetComponent<TextMeshProUGUI>();
((Graphic)InsanityInfo).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
UIHandler.InsanityImage = ((Component)UIHandler.Memory_InsanityMeter.transform.Find("Bar/StaminaBar")).gameObject.GetComponent<Image>();
((Graphic)UIHandler.InsanityImage).color = ConfigSettings.MeterColor.Value + new Color(0f, 0f, 0f, 1f);
Object.DontDestroyOnLoad((Object)(object)UIHandler.Memory_InsanityMeter);
}
}
private static void MoveWithOffset()
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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)
//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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
GameObject gameObject = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/PlayerInfo(Clone)").gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Initialise.modLogger.LogError((object)"EladsHUD UI wasn't found");
return;
}
Transform transform = gameObject.transform;
Transform transform2 = ((Component)transform.Find("BatteryLayout")).gameObject.transform;
transform2.localPosition += localPositionOffset;
Transform transform3 = UIHandler.InsanityMeter.transform;
transform3.localPosition += localPositionOffset;
Transform transform4 = PercentageInsanityText.transform;
transform4.localPosition += Percentage_localPositionOffset;
}
}
public class An0nPatchesCompatibility
{
private static Vector3 localPositionOffset = new Vector3(3f, 15f, 0f);
public static void MoveTextHUD()
{
//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_003a: Unknown result type (might be due to invalid IL or missing references)
GameObject gameObject = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/HPSP").gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Initialise.modLogger.LogError((object)"An0nTextHUD's HUD wasn't found");
return;
}
Transform transform = gameObject.transform;
transform.localPosition += localPositionOffset;
}
}
public class LCCrouchHUDCompatibility
{
private static Vector3 positionToLocal = new Vector3(-16.2386f, -20.2468f, -12.0928f);
private static Vector3 localPositionOffset = new Vector3(0f, 4f, 0f);
public static void MoveCrouchHUD()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
GameObject gameObject = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/Self/CrouchIcon").gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Initialise.modLogger.LogError((object)"LCCrouchHud's icon wasn't found");
}
else
{
gameObject.transform.localPosition = positionToLocal + localPositionOffset;
}
}
}
}
namespace InsanityDisplay.Config
{
public class ConfigHandler
{
public static void InitialiseConfig()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
ConfigSettings.ModEnabled = Initialise.modConfig.Bind<bool>("Display Settings", "Meter enabled", true, "Add a bar above the stamina bar which display your insanity");
ConfigSettings.MeterColor = Initialise.modConfig.Bind<Color>("Display Settings", "Color of the meter", new Color(0.45f, 0f, 0.65f, 1f), "The colour that the insanity meter will have\n The colour value must be in HEX\nExample: FFFFFF(FF) (White)");
ConfigSettings.useAccurateDisplay = Initialise.modConfig.Bind<bool>("Display Settings", "Accurate meter", false, "Show your insanity value more accurately, instead of showing it in the vanilla way");
ConfigSettings.enableReverse = Initialise.modConfig.Bind<bool>("Display Settings", "Sanity Meter", false, "Turn the insanity meter into a sanity meter");
ConfigSettings.alwaysFull = Initialise.modConfig.Bind<bool>("Display Settings", "Always Show", false, "Always show the insanity meter, for aesthetic purposes");
ConfigSettings.LCCrouchHUDCompat = Initialise.modConfig.Bind<bool>("Compatibility Settings", "Enable LCCrouchHUD compatibility", true, "Enabling this will move the Crouch HUD slightly up to avoid overlapping");
ConfigSettings.An0nPatchesCompat = Initialise.modConfig.Bind<bool>("Compatibility Settings", "Enable An0n Patches compatibility", true, "Enabling this will move the An0n Patches HUD slightly up to avoid overlapping");
ConfigSettings.EladsHUDCompat = Initialise.modConfig.Bind<bool>("Compatibility Settings", "Enable Elads HUD compatibility", true, "Enabling this will add another bar above the stamina bar displaying your insanity level");
}
}
public class ConfigSettings
{
public static ConfigEntry<bool> ModEnabled;
public static ConfigEntry<Color> MeterColor;
public static ConfigEntry<bool> useAccurateDisplay;
public static ConfigEntry<bool> enableReverse;
public static ConfigEntry<bool> alwaysFull;
public static ConfigEntry<bool> LCCrouchHUDCompat;
public static ConfigEntry<bool> An0nPatchesCompat;
public static ConfigEntry<bool> EladsHUDCompat;
}
}