using System;
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 BetterSpec.Patches;
using HarmonyLib;
using TMPro;
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("BetterSpec")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterSpec")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b229aed6-018b-46b3-be64-4b5073c1a1f2")]
[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 BetterSpec
{
[BepInPlugin("zg.BetterSpec", "BetterSpec", "1.1.3")]
public class MainBetterSpec : BaseUnityPlugin
{
private const string modGUID = "zg.BetterSpec";
private const string modName = "BetterSpec";
private const string modVersion = "1.1.3";
private readonly Harmony harmony = new Harmony("zg.BetterSpec");
public static MainBetterSpec instance;
internal ManualLogSource pnt;
public ConfigEntry<bool> seeItemsRemaining;
public ConfigEntry<bool> seeValueRemaining;
public ConfigEntry<bool> seeConfigNotice;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
BindConfiguration();
pnt = Logger.CreateLogSource("zg.BetterSpec");
pnt.LogInfo((object)"BetterSpec Enabled");
pnt.LogInfo((object)"Make sure to review BetterSpec");
harmony.PatchAll(typeof(MainBetterSpec));
harmony.PatchAll(typeof(HUDManagerPatches));
harmony.PatchAll(typeof(SpecInfoHud));
}
private void BindConfiguration()
{
seeValueRemaining = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "See Value Remaining", false, "Show Value Remaining when spectating");
seeItemsRemaining = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "See Items Remaining Inside", false, "Show Items Remaining when spectating");
seeConfigNotice = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Config Notice Display", true, "Shows the messasge informing of new Config");
}
}
}
namespace BetterSpec.Patches
{
internal class HUDManagerPatches
{
[HarmonyPatch(typeof(HUDManager), "Update")]
[HarmonyPrefix]
private static void specClockPatch(HUDManager __instance)
{
if (!GameNetworkManager.Instance.gameHasStarted || CheckNull(__instance))
{
return;
}
if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
if (HUDManager.Instance.Clock != null)
{
HUDManager.Instance.HideHUD(false);
HUDManager.Instance.SetClockVisible(true);
HUDManager.Instance.Clock.targetAlpha = 1f;
HUDManager.Instance.Inventory.targetAlpha = 0f;
HUDManager.Instance.PlayerInfo.targetAlpha = 0f;
}
else
{
Debug.LogError((object)"Clock in HUDManager is null!");
}
}
else
{
HUDManager.Instance.PlayerInfo.targetAlpha = 1f;
HUDManager.Instance.Inventory.targetAlpha = 1f;
}
}
private static bool CheckNull(HUDManager __instance)
{
if ((Object)(object)__instance == (Object)null)
{
Debug.LogError((object)"HUDManagerPatches: __instance is null!");
return true;
}
if ((Object)(object)HUDManager.Instance == (Object)null)
{
Debug.LogError((object)"HUDManagerPatches: HUDManager.Instance is null!");
return true;
}
if (HUDManager.Instance.Clock == null)
{
Debug.LogError((object)"HUDManagerPatches: Clock in HUDManager is null!");
return true;
}
if ((Object)(object)GameNetworkManager.Instance == (Object)null)
{
Debug.LogError((object)"HUDManagerPatches: GameNetworkManager.Instance is null!");
return true;
}
if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
Debug.LogError((object)"HUDManagerPatches: localPlayerController is null!");
return true;
}
return false;
}
}
[HarmonyPatch(typeof(HUDManager))]
internal class SpecInfoHud
{
private static TextMeshProUGUI specInfo;
public static HUDManager hud = HUDManager.Instance;
public int num2 = 0;
private int num4 = 0;
public string itemsInside()
{
Random random = new Random(StartOfRound.Instance.randomMapSeed + 91);
int num = 0;
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
for (int i = 0; i < array.Length; i++)
{
if (array[i].itemProperties.isScrap && array[i].isInFactory && !((Object)array[i]).name.Equals("Key"))
{
num4 += array[i].itemProperties.maxValue - array[i].itemProperties.minValue;
num += Mathf.Clamp(random.Next(array[i].itemProperties.minValue, array[i].itemProperties.maxValue), array[i].scrapValue - 6 * i, array[i].scrapValue + 9 * i);
num2++;
}
}
return num2.ToString();
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void modifyWeightText()
{
if ((Object)(object)specInfo == (Object)null || (Object)(object)MainBetterSpec.instance == (Object)null || (Object)(object)GameNetworkManager.Instance == (Object)null)
{
return;
}
if (!GameNetworkManager.Instance.gameHasStarted)
{
((TMP_Text)specInfo).alpha = 0f;
return;
}
if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
SpecInfoHud specInfoHud = new SpecInfoHud();
specInfoHud.itemsInside();
int numberOfEnemiesInScene = RoundManager.Instance.numberOfEnemiesInScene;
((TMP_Text)specInfo).alpha = 0f;
}
if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
return;
}
SpecInfoHud specInfoHud2 = new SpecInfoHud();
if (MainBetterSpec.instance.seeItemsRemaining.Value)
{
if (MainBetterSpec.instance.seeValueRemaining.Value)
{
((TMP_Text)specInfo).text = "Items Remaining Inside: " + specInfoHud2.num2 + "\nValue Remaining: $" + specInfoHud2.num4;
}
else
{
((TMP_Text)specInfo).text = "Items Remaining Inside: " + specInfoHud2.num2;
}
}
else if (MainBetterSpec.instance.seeValueRemaining.Value)
{
((TMP_Text)specInfo).text = "Value Remaining: $" + specInfoHud2.num4;
}
if (!MainBetterSpec.instance.seeValueRemaining.Value && !MainBetterSpec.instance.seeItemsRemaining.Value)
{
if (MainBetterSpec.instance.seeConfigNotice.Value)
{
((TMP_Text)specInfo).text = "Enable More Data in Config\nRemove this Notice in Config\nCheckout Better Terminal\nAnd ScalingStartCredits";
}
else
{
((TMP_Text)specInfo).text = "";
}
}
((TMP_Text)specInfo).alpha = 1f;
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void createSpecElm(ref HUDManager __instance)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
SpecInfoHud specInfoHud = new SpecInfoHud();
specInfoHud.itemsInside();
GameObject val = new GameObject("SpectatorInfo");
val.AddComponent<RectTransform>();
TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
((Transform)rectTransform).SetParent(((Component)__instance.PTTIcon).transform, false);
rectTransform.anchoredPosition = new Vector2(400f, -90f);
((TMP_Text)val2).font = ((TMP_Text)__instance.controlTipLines[0]).font;
((TMP_Text)val2).fontSize = 9f;
((Behaviour)val2).enabled = true;
((Graphic)val2).color = Color.green;
((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
specInfo = val2;
}
}
}