using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.Logging;
using CombatHUD;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[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 CombatHUDPatch;
[BepInPlugin("Tchernobill.CombatHUDPatch", "CombatHUDPatch", "1.0.0")]
public class CombatHUDPatch : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayersManager), "UpdatePlayerStatuses")]
public class PlayersManager_UpdatePlayerStatuses
{
private static bool Prefix(PlayersManager __instance, int splitID)
{
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: 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)
//IL_013a: Expected O, but got Unknown
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_0334: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_0358: Invalid comparison between Unknown and I4
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_0370: Unknown result type (might be due to invalid IL or missing references)
//IL_0372: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0482: Unknown result type (might be due to invalid IL or missing references)
//IL_046f: Unknown result type (might be due to invalid IL or missing references)
//IL_0616: Unknown result type (might be due to invalid IL or missing references)
//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
//IL_05de: Unknown result type (might be due to invalid IL or missing references)
//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
//IL_05af: Unknown result type (might be due to invalid IL or missing references)
//IL_0584: Unknown result type (might be due to invalid IL or missing references)
//IL_057d: Unknown result type (might be due to invalid IL or missing references)
//IL_0589: Unknown result type (might be due to invalid IL or missing references)
//IL_053e: Unknown result type (might be due to invalid IL or missing references)
//IL_0543: Unknown result type (might be due to invalid IL or missing references)
//IL_055e: Unknown result type (might be due to invalid IL or missing references)
//IL_0563: Unknown result type (might be due to invalid IL or missing references)
//IL_0555: Unknown result type (might be due to invalid IL or missing references)
//IL_055a: Unknown result type (might be due to invalid IL or missing references)
Character val = null;
bool flag = true;
if (SplitScreenManager.Instance.LocalPlayerCount > splitID)
{
val = SplitScreenManager.Instance.LocalPlayers[splitID].AssignedCharacter;
if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.CharacterUI))
{
flag = CombatHUD.IsHudHidden(splitID);
}
}
Dictionary<int, List<StatusTimerView>> @private = getPrivate<PlayersManager, Dictionary<int, List<StatusTimerView>>>(__instance, "statusTimerViews");
if (flag)
{
if (@private[splitID].Any() && @private[splitID].First().activeSelf)
{
foreach (StatusTimerView item in @private[splitID])
{
item.SetActive(false);
}
}
}
else if (Object.op_Implicit((Object)(object)val))
{
StatusEffectPanel obj = getPrivate<PlayersManager, Dictionary<string, StatusEffectPanel>>(__instance, "statusPanels")[UID.op_Implicit(val.UID)];
List<CachedStatusIcons> list = new List<CachedStatusIcons>();
foreach (KeyValuePair<string, StatusEffectIcon> statusIcon in obj.m_statusIcons)
{
if (((Component)statusIcon.Value).gameObject.activeSelf)
{
list.Add(new CachedStatusIcons
{
icon = statusIcon.Value,
iconIdentifier = statusIcon.Key
});
}
}
List<StatusTimerView> list2 = @private[splitID];
for (int i = 0; i < list2.Count || i < list.Count; i++)
{
if (i >= list.Count || !HUDConfig.Player_StatusTimers.Value)
{
list2[i].SetActive(false);
continue;
}
if (i >= list2.Count)
{
typeof(PlayersManager).GetType().GetMethod("AddNewView", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { splitID });
}
StatusTimerView val2 = list2[i];
CachedStatusIcons data = list[i];
((Transform)val2.rectTransform).position = ((Transform)((Graphic)data.icon.m_icon).rectTransform).position + Vector3.up * CombatHUD.Rel(25f, true);
StatusEffect val3 = ((IEnumerable<StatusEffect>)val.StatusEffectMngr.Statuses).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect it) => it.StatusIconIdentifier == data.iconIdentifier));
float num;
if (Object.op_Implicit((Object)(object)val3))
{
num = val3.RemainingLifespan;
}
else
{
try
{
num = data.iconIdentifier switch
{
"SummonGhost" => val.CurrentSummon.RemainingLifespan,
"ImbueOffWeapon" => val.LeftHandWeapon.FirstImbue.RemainingLifespan,
"ImbueMainWeapon" => val.CurrentWeapon.FirstImbue.RemainingLifespan,
"SummonWeapon" => ((Equipment)val.CurrentWeapon).SummonedEquipment.RemainingLifespan,
_ => throw new NotImplementedException("TODO: Unsupported status icon key '" + data.iconIdentifier + "'"),
};
}
catch
{
continue;
}
}
Color color = Color.white;
Color color2 = Color.red;
Disease val4 = (Disease)(object)((val3 is Disease) ? val3 : null);
if ((Object)(object)val4 != (Object)null && (int)((StatusEffect)val4).LengthType == 1)
{
if (val4.IsReceding)
{
color = Color.green;
color2 = Color.green;
float num2 = DiseaseLibrary.Instance.GetRecedingTime(val4.m_diseasesType);
float num3 = EnvironmentConditions.GameTimeF - val4.m_healedGameTime;
num = (num2 - num3) * 60f * 60f / 24f;
}
else if (val4.m_canDegenerate)
{
color = Color.yellow;
color2 = Color.yellow;
num = (val4.m_degenerateTime - ((StatusEffect)val4).Age) * 60f * 60f / 24f;
}
}
if (num > 0f)
{
TimeSpan timeSpan = TimeSpan.FromSeconds(num);
string text = $"{timeSpan.Minutes}:{timeSpan.Seconds:00}";
if (timeSpan.Hours > 0)
{
text = $"{timeSpan.Hours}:{text}";
}
val2.text.text = text;
if (num < 15f)
{
((Graphic)val2.text).color = color2;
}
else
{
((Graphic)val2.text).color = color;
}
}
else
{
HashSet<string> private2 = getPrivate<PlayersManager, HashSet<string>>(__instance, "needsStatuses");
if (Object.op_Implicit((Object)(object)val3) && private2.Contains(val3.IdentifierName))
{
float num4;
switch (val3.IdentifierName)
{
default:
num4 = val.PlayerStats.CorruptionRatio;
color = ((!(num4 < 0.5f)) ? ((!(num4 < 0.75f)) ? Color.red : Color.yellow) : Color.white);
break;
case "Tired":
case "Drowsy":
num4 = val.PlayerStats.SleepRatio;
color = ((num4 < 0.25f) ? Color.red : Color.yellow);
break;
case "Thirsty":
case "Parched":
num4 = val.PlayerStats.DrinkRatio;
color = ((num4 < 0.5f) ? Color.red : Color.yellow);
break;
case "Hungry":
case "Starving":
num4 = val.PlayerStats.FoodRatio;
color = ((num4 < 0.5f) ? Color.red : Color.yellow);
break;
}
((Graphic)val2.text).color = color;
val2.text.text = $"{Mathf.Round(num4 * 100f)}%";
}
else
{
((Graphic)val2.text).color = color;
val2.text.text = "∞";
}
}
if (!val2.activeSelf)
{
val2.SetActive(true);
}
}
}
return false;
}
private static void Postfix(PlayersManager __instance)
{
}
}
public const string GUID = "Tchernobill.CombatHUDPatch";
public const string NAME = "CombatHUDPatch";
public const string VERSION = "1.0.0";
internal static ManualLogSource Log;
internal void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("Tchernobill.CombatHUDPatch").PatchAll();
}
private static Tp getPrivate<To, Tp>(To OInstance, string OFieldName)
{
return (Tp)typeof(To).GetField(OFieldName, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(OInstance);
}
}