using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BoneLib.BoneMenu;
using Hl2Hud;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Data;
using LabFusion.Entities;
using LabFusion.Player;
using LabFusion.Voice;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "HL2 HUD", "1.0.0", "Kyler", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "BoneLib", "LabFusion" })]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Hl2Hud
{
internal static class Settings
{
public static MelonPreferences_Entry<bool> Enabled;
public static MelonPreferences_Entry<bool> AlwaysAmmo;
public static MelonPreferences_Entry<bool> DeathScreen;
public static MelonPreferences_Entry<bool> RemoveVignette;
public static MelonPreferences_Entry<bool> DeathHeadLocked;
public static MelonPreferences_Entry<bool> VoiceIndicator;
public static MelonPreferences_Entry<bool> VoiceShowSelf;
public static MelonPreferences_Entry<bool> VoiceHeadIcon;
public static MelonPreferences_Entry<float> Distance;
public static MelonPreferences_Entry<float> Scale;
public static MelonPreferences_Entry<float> NumW;
public static MelonPreferences_Entry<float> NumH;
public static MelonPreferences_Entry<float> HealthX;
public static MelonPreferences_Entry<float> HealthY;
public static MelonPreferences_Entry<float> AmmoX;
public static MelonPreferences_Entry<float> AmmoY;
public static MelonPreferences_Entry<float> HealthMax;
public static MelonPreferences_Entry<float> Scanlines;
public static MelonPreferences_Entry<float> DeathVolume;
public static MelonPreferences_Entry<float> DeathCamDistance;
public static MelonPreferences_Entry<float> DeathDelay;
public static MelonPreferences_Entry<float> VoiceGain;
public static MelonPreferences_Entry<float> VoiceX;
public static MelonPreferences_Entry<float> VoiceY;
public static MelonPreferences_Entry<float> VoiceScale;
public static MelonPreferences_Entry<float> VoiceOpacity;
public static MelonPreferences_Entry<float> VoiceSpacing;
public static MelonPreferences_Entry<float> VoiceIconSize;
public static MelonPreferences_Entry<float> VoiceIconHeight;
public static MelonPreferences_Entry<string> NumberFont;
private static float _dirtyAt = -1f;
public static void Init()
{
MelonPreferences_Category obj = MelonPreferences.CreateCategory("Hl2Hud");
Enabled = obj.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AlwaysAmmo = obj.CreateEntry<bool>("AlwaysShowAmmo", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
Distance = obj.CreateEntry<float>("Distance", 1.2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
Scale = obj.CreateEntry<float>("Scale", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
NumW = obj.CreateEntry<float>("NumberWidth", 0.75f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
NumH = obj.CreateEntry<float>("NumberHeight", 1.15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
HealthX = obj.CreateEntry<float>("HealthOffsetX", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
HealthY = obj.CreateEntry<float>("HealthOffsetY", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AmmoX = obj.CreateEntry<float>("AmmoOffsetX", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AmmoY = obj.CreateEntry<float>("AmmoOffsetY", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
HealthMax = obj.CreateEntry<float>("HealthMaxOverride", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
Scanlines = obj.CreateEntry<float>("ScanlineStrength", 0.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathScreen = obj.CreateEntry<bool>("DeathScreen", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
RemoveVignette = obj.CreateEntry<bool>("RemoveVignette", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathHeadLocked = obj.CreateEntry<bool>("DeathScreenHeadLocked", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathVolume = obj.CreateEntry<float>("DeathVolume", 0.8f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathCamDistance = obj.CreateEntry<float>("DeathCamDistance", 2.4f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathDelay = obj.CreateEntry<float>("DeathScreenDelay", 0.6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceIndicator = obj.CreateEntry<bool>("VoiceIndicator", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceShowSelf = obj.CreateEntry<bool>("VoiceShowSelf", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceGain = obj.CreateEntry<float>("VoiceFlashGain", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceX = obj.CreateEntry<float>("VoiceOffsetX", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceY = obj.CreateEntry<float>("VoiceOffsetY", 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceScale = obj.CreateEntry<float>("VoiceScale", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceOpacity = obj.CreateEntry<float>("VoiceOpacity", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceSpacing = obj.CreateEntry<float>("VoiceSpacing", 6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceHeadIcon = obj.CreateEntry<bool>("VoiceHeadIcon", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceIconSize = obj.CreateEntry<float>("VoiceIconSize", 0.22f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VoiceIconHeight = obj.CreateEntry<float>("VoiceIconHeight", 0.6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
NumberFont = obj.CreateEntry<string>("NumberFont", "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public static void MarkDirty()
{
_dirtyAt = Time.time;
}
public static void FlushIfDue()
{
if (_dirtyAt >= 0f && Time.time - _dirtyAt > 1.5f)
{
MelonPreferences.Save();
_dirtyAt = -1f;
}
}
}
public class Core : MelonMod
{
private Hud _hud;
private DeathScreen _death;
private VoiceOverlay _voice;
private VoiceHeadIcons _icons;
private Hud _voiceHud;
private bool _loggedHealth;
private float _deadSince = -1f;
private int _lastRigId;
private float _readyAt = float.MaxValue;
private float _loadCheckAt;
private bool _loading;
public override void OnInitializeMelon()
{
Settings.Init();
}
public override void OnLateInitializeMelon()
{
try
{
HudMenu.Build();
}
catch (Exception ex)
{
((MelonBase)this).LoggerInstance.Msg("BoneMenu not available (" + ex.GetType().Name + "); edit the .cfg to adjust.");
}
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
GameBridge.Invalidate();
}
public override void OnUpdate()
{
Settings.FlushIfDue();
}
private bool InLevel()
{
float time = Time.time;
if (time >= _loadCheckAt)
{
_loadCheckAt = time + 1f;
_loading = GameBridge.IsLoadingScene();
}
if (_loading)
{
_lastRigId = 0;
_readyAt = float.MaxValue;
return false;
}
int num = GameBridge.RigId();
if (num == 0)
{
_lastRigId = 0;
_readyAt = float.MaxValue;
return false;
}
if (num != _lastRigId)
{
_lastRigId = num;
_readyAt = time + 1f;
}
return time >= _readyAt;
}
private void HideAll()
{
if (_hud != null && _hud.Alive)
{
_hud.SetActive(a: false);
}
if (_death != null)
{
_death.End();
}
if (_icons != null)
{
_icons.HideAll();
}
_deadSince = -1f;
}
public override void OnLateUpdate()
{
//IL_025d: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
if (!Settings.Enabled.Value)
{
HideAll();
return;
}
if (!InLevel())
{
HideAll();
return;
}
if (Settings.RemoveVignette.Value)
{
GameBridge.SuppressVignette();
}
Transform head = GameBridge.Head;
if ((Object)(object)head == (Object)null)
{
HideAll();
return;
}
if (Settings.DeathScreen.Value && GameBridge.IsDead())
{
if (_hud != null && _hud.Alive)
{
_hud.SetActive(a: false);
}
if (_deadSince < 0f)
{
_deadSince = Time.time;
GameBridge.RagdollPlayer();
}
if (!(Time.time - _deadSince >= Settings.DeathDelay.Value))
{
return;
}
if (_death == null)
{
_death = new DeathScreen(delegate(string msg)
{
((MelonBase)this).LoggerInstance.Msg(msg);
});
}
_death.Tick(head, GameBridge.BodyTransform(), Time.deltaTime, Settings.DeathVolume.Value, Settings.DeathCamDistance.Value);
return;
}
if (_deadSince >= 0f)
{
_deadSince = -1f;
GameBridge.RecoverPlayer();
}
if (_death != null)
{
_death.End();
}
if (_hud == null || !_hud.Alive)
{
_hud = new Hud(Settings.NumberFont.Value, delegate(string msg)
{
((MelonBase)this).LoggerInstance.Msg(msg);
});
}
_hud.SetActive(a: true);
_hud.Follow(head, Settings.Distance.Value, Settings.Scale.Value);
int health = 100;
if (GameBridge.TryGetHealth(out var cur, out var max))
{
float num = ((Settings.HealthMax.Value > 0f) ? Settings.HealthMax.Value : max);
if (!_loggedHealth)
{
_loggedHealth = true;
((MelonBase)this).LoggerInstance.Msg("Health raw: " + cur + " / max " + max);
}
health = Mathf.Clamp(Mathf.CeilToInt(cur / num * 100f), 0, 100);
}
int mag;
int reserve;
bool flag = GameBridge.TryGetAmmo(out mag, out reserve);
if (!flag && Settings.AlwaysAmmo.Value)
{
mag = 0;
reserve = GameBridge.TryGetLightReserve();
flag = true;
}
_hud.Tick(new Hud.State
{
NumberScale = new Vector2(Settings.NumW.Value, Settings.NumH.Value),
HealthOffset = new Vector2(Settings.HealthX.Value, Settings.HealthY.Value),
AmmoOffset = new Vector2(Settings.AmmoX.Value, Settings.AmmoY.Value),
Scan = Settings.Scanlines.Value,
Health = health,
ShowAmmo = flag,
Mag = Mathf.Clamp(mag, 0, 99999),
Reserve = Mathf.Clamp(reserve, 0, 9999)
});
if (Settings.VoiceIndicator.Value && LabFusionBridge.Present)
{
if (_voice == null || _voiceHud != _hud)
{
_voice = new VoiceOverlay(_hud.CanvasRt, _hud.LabelFont, _hud.OverlayMaterial);
_voiceHud = _hud;
}
_voice.Tick(Time.deltaTime, new VoiceOverlay.Style
{
IncludeSelf = Settings.VoiceShowSelf.Value,
Gain = Settings.VoiceGain.Value,
Scale = Settings.VoiceScale.Value,
Opacity = Settings.VoiceOpacity.Value,
Spacing = Settings.VoiceSpacing.Value,
Offset = new Vector2(Settings.VoiceX.Value, Settings.VoiceY.Value)
}, delegate(string msg)
{
((MelonBase)this).LoggerInstance.Msg(msg);
});
if (_icons == null)
{
_icons = new VoiceHeadIcons();
}
if (Settings.VoiceHeadIcon.Value)
{
_icons.Tick(_voice.Speaking, head, Time.deltaTime, Settings.VoiceIconSize.Value, Settings.VoiceIconHeight.Value, delegate(string msg)
{
((MelonBase)this).LoggerInstance.Msg(msg);
});
}
else
{
_icons.HideAll();
}
}
else
{
if (_voice != null)
{
_voice.HideAll();
}
if (_icons != null)
{
_icons.HideAll();
}
}
}
}
internal static class HudMenu
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Build()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0307: Unknown result type (might be due to invalid IL or missing references)
//IL_034c: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_040c: Unknown result type (might be due to invalid IL or missing references)
//IL_0442: Unknown result type (might be due to invalid IL or missing references)
//IL_0487: Unknown result type (might be due to invalid IL or missing references)
//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0511: Unknown result type (might be due to invalid IL or missing references)
//IL_0556: Unknown result type (might be due to invalid IL or missing references)
//IL_058c: Unknown result type (might be due to invalid IL or missing references)
//IL_05d1: 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_065b: Unknown result type (might be due to invalid IL or missing references)
//IL_069f: Unknown result type (might be due to invalid IL or missing references)
Color val = default(Color);
((Color)(ref val))..ctor(1f, 0.905f, 0.11f);
Page obj = Page.Root.CreatePage("HL2 HUD", val, 0, true);
obj.CreateFloat("Distance", val, Settings.Distance.Value, 0.05f, 0.3f, 3f, (Action<float>)delegate(float v)
{
Settings.Distance.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Scale", val, Settings.Scale.Value, 0.05f, 0.3f, 3f, (Action<float>)delegate(float v)
{
Settings.Scale.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Health X", val, Settings.HealthX.Value, 5f, -400f, 400f, (Action<float>)delegate(float v)
{
Settings.HealthX.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Health Y", val, Settings.HealthY.Value, 5f, -300f, 300f, (Action<float>)delegate(float v)
{
Settings.HealthY.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Ammo X", val, Settings.AmmoX.Value, 5f, -400f, 400f, (Action<float>)delegate(float v)
{
Settings.AmmoX.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Ammo Y", val, Settings.AmmoY.Value, 5f, -300f, 300f, (Action<float>)delegate(float v)
{
Settings.AmmoY.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Number Width", val, Settings.NumW.Value, 0.05f, 0.4f, 1.5f, (Action<float>)delegate(float v)
{
Settings.NumW.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Number Height", val, Settings.NumH.Value, 0.05f, 0.6f, 2f, (Action<float>)delegate(float v)
{
Settings.NumH.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Scanlines", val, Settings.Scanlines.Value, 0.05f, 0f, 0.8f, (Action<float>)delegate(float v)
{
Settings.Scanlines.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Death Screen", val, Settings.DeathScreen.Value, (Action<bool>)delegate(bool v)
{
Settings.DeathScreen.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Remove Vignette", val, Settings.RemoveVignette.Value, (Action<bool>)delegate(bool v)
{
Settings.RemoveVignette.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Death Volume", val, Settings.DeathVolume.Value, 0.1f, 0f, 1f, (Action<float>)delegate(float v)
{
Settings.DeathVolume.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Death Cam Delay", val, Settings.DeathDelay.Value, 0.1f, 0f, 3f, (Action<float>)delegate(float v)
{
Settings.DeathDelay.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Death Cam Distance", val, Settings.DeathCamDistance.Value, 0.25f, 1f, 6f, (Action<float>)delegate(float v)
{
Settings.DeathCamDistance.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Voice Indicator", val, Settings.VoiceIndicator.Value, (Action<bool>)delegate(bool v)
{
Settings.VoiceIndicator.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Voice Show Self", val, Settings.VoiceShowSelf.Value, (Action<bool>)delegate(bool v)
{
Settings.VoiceShowSelf.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Flash Gain", val, Settings.VoiceGain.Value, 0.2f, 0.2f, 4f, (Action<float>)delegate(float v)
{
Settings.VoiceGain.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Size", val, Settings.VoiceScale.Value, 0.1f, 0.5f, 2.5f, (Action<float>)delegate(float v)
{
Settings.VoiceScale.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Opacity", val, Settings.VoiceOpacity.Value, 0.05f, 0f, 1f, (Action<float>)delegate(float v)
{
Settings.VoiceOpacity.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Spacing", val, Settings.VoiceSpacing.Value, 2f, 0f, 40f, (Action<float>)delegate(float v)
{
Settings.VoiceSpacing.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Voice Head Icon", val, Settings.VoiceHeadIcon.Value, (Action<bool>)delegate(bool v)
{
Settings.VoiceHeadIcon.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Icon Size", val, Settings.VoiceIconSize.Value, 0.02f, 0.08f, 0.6f, (Action<float>)delegate(float v)
{
Settings.VoiceIconSize.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Icon Height", val, Settings.VoiceIconHeight.Value, 0.05f, 0.1f, 1.5f, (Action<float>)delegate(float v)
{
Settings.VoiceIconHeight.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice X", val, Settings.VoiceX.Value, 5f, -400f, 400f, (Action<float>)delegate(float v)
{
Settings.VoiceX.Value = v;
Settings.MarkDirty();
});
obj.CreateFloat("Voice Y", val, Settings.VoiceY.Value, 5f, -300f, 300f, (Action<float>)delegate(float v)
{
Settings.VoiceY.Value = v;
Settings.MarkDirty();
});
obj.CreateBool("Always Show Ammo", val, Settings.AlwaysAmmo.Value, (Action<bool>)delegate(bool v)
{
Settings.AlwaysAmmo.Value = v;
Settings.MarkDirty();
});
}
}
public class Hud
{
public struct State
{
public Vector2 NumberScale;
public Vector2 HealthOffset;
public Vector2 AmmoOffset;
public float Scan;
public int Health;
public int Mag;
public int Reserve;
public bool ShowAmmo;
}
private const float CanvasW = 1000f;
private const float CanvasH = 560f;
private const float PanelH = 84f;
private const float HealthW = 240f;
private const float Margin = 40f;
private static readonly Color Yellow = new Color(1f, 0.905f, 0.11f, 1f);
private static readonly Color Red = new Color(1f, 0.2f, 0.15f, 1f);
private GameObject _root;
private RectTransform _canvasRt;
private RectTransform _ammoPanel;
private RectTransform _healthPanel;
private Text _healthNum;
private Text _ammoMag;
private Text _ammoReserve;
private Text _healthLabel;
private Text _ammoLabel;
private RectTransform _ammoMagRt;
private RectTransform _ammoResRt;
private Image _healthScan;
private Image _ammoScan;
private Font _labelFont;
private Font _numFont;
private Material _mat;
public bool Alive => (Object)(object)_root != (Object)null;
internal RectTransform CanvasRt => _canvasRt;
internal Font LabelFont => _labelFont;
internal Material OverlayMaterial => _mat;
public void SetActive(bool a)
{
if ((Object)(object)_root != (Object)null && _root.activeSelf != a)
{
_root.SetActive(a);
}
}
public Hud(string numberFontOverride, Action<string> log)
{
_labelFont = LoadLabelFont();
_numFont = LoadNumberFont(numberFontOverride, log) ?? _labelFont;
_mat = MakeOverlayMaterial();
Build();
}
private static Font LoadLabelFont()
{
Font val = null;
try
{
val = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
catch
{
}
if ((Object)(object)val == (Object)null)
{
try
{
val = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
}
catch
{
}
}
if ((Object)(object)val == (Object)null)
{
try
{
val = Font.CreateDynamicFontFromOSFont("Roboto", 32);
}
catch
{
}
}
return val;
}
private static Font LoadNumberFont(string overrideName, Action<string> log)
{
List<string> list = new List<string>();
if (!string.IsNullOrEmpty(overrideName))
{
list.Add(overrideName);
}
list.AddRange(new string[6] { "sans-serif-thin", "Roboto-Thin", "Roboto Thin", "sans-serif-light", "Roboto-Light", "Roboto Light" });
foreach (string item in list)
{
try
{
Font val = Font.CreateDynamicFontFromOSFont(item, 64);
if ((Object)(object)val != (Object)null && val.HasCharacter('0'))
{
log?.Invoke("Number font: " + item);
return val;
}
}
catch
{
}
}
log?.Invoke("No thin OS font found; numbers use the default font. Set NumberFont in the config.");
return null;
}
internal static Material MakeOverlayMaterial()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_0034: Expected O, but got Unknown
Shader val = Shader.Find("UI/Default");
if ((Object)(object)val == (Object)null)
{
return null;
}
Material val2 = new Material(val);
val2.SetInt("unity_GUIZTestMode", 8);
val2.renderQueue = 4000;
return val2;
}
private void Build()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_032e: Unknown result type (might be due to invalid IL or missing references)
//IL_033d: Unknown result type (might be due to invalid IL or missing references)
//IL_034c: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Unknown result type (might be due to invalid IL or missing references)
//IL_039d: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
//IL_042c: Unknown result type (might be due to invalid IL or missing references)
_root = new GameObject("Hl2Hud_Root");
Object.DontDestroyOnLoad((Object)(object)_root);
((Object)_root).hideFlags = (HideFlags)32;
Canvas obj = _root.AddComponent<Canvas>();
obj.renderMode = (RenderMode)2;
obj.sortingOrder = 100;
_canvasRt = _root.GetComponent<RectTransform>();
_canvasRt.sizeDelta = new Vector2(1000f, 560f);
((Transform)_canvasRt).localScale = Vector3.one * 0.001f;
RectTransform val = (_healthPanel = Rt("HealthPanel", (Transform)(object)_canvasRt, V(0f, 0f), V(0f, 0f), V(40f, 40f), V(240f, 84f)));
ImgSliced(val, Sprites.Panel(84f, 10f, scan: false), new Color(0f, 0f, 0f, 0.5f));
_healthLabel = Label(Rt("Label", (Transform)(object)val, V(0f, 0f), V(0f, 0f), V(18f, 14f), V(110f, 24f)), _labelFont, 17, (TextAnchor)6, (FontStyle)1);
_healthLabel.text = "HEALTH";
_healthNum = Label(Rt("Number", (Transform)(object)val, V(1f, 0.5f), V(1f, 0.5f), V(-16f, 0f), V(110f, 90f)), _numFont, 62, (TextAnchor)5, (FontStyle)0);
_healthScan = ImgSliced(Stretch("Scan", (Transform)(object)val), Sprites.Panel(84f, 10f, scan: true), new Color(0f, 0f, 0f, 0.3f));
_ammoPanel = Rt("AmmoPanel", (Transform)(object)_canvasRt, V(1f, 0f), V(1f, 0f), V(-40f, 40f), V(220f, 84f));
ImgSliced(_ammoPanel, Sprites.Panel(84f, 10f, scan: false), new Color(0f, 0f, 0f, 0.5f));
_ammoLabel = Label(Rt("Label", (Transform)(object)_ammoPanel, V(0f, 0f), V(0f, 0f), V(18f, 14f), V(90f, 24f)), _labelFont, 17, (TextAnchor)6, (FontStyle)1);
_ammoLabel.text = "AMMO";
_ammoMagRt = Rt("Mag", (Transform)(object)_ammoPanel, V(1f, 0.5f), V(1f, 0.5f), V(-70f, 0f), V(60f, 90f));
_ammoMag = Label(_ammoMagRt, _numFont, 62, (TextAnchor)5, (FontStyle)0);
_ammoResRt = Rt("Reserve", (Transform)(object)_ammoPanel, V(1f, 0f), V(1f, 0f), V(-14f, 12f), V(50f, 44f));
_ammoReserve = Label(_ammoResRt, _numFont, 31, (TextAnchor)8, (FontStyle)0);
_ammoScan = ImgSliced(Stretch("Scan", (Transform)(object)_ammoPanel), Sprites.Panel(84f, 10f, scan: true), new Color(0f, 0f, 0f, 0.3f));
}
public void Follow(Transform head, float distance, float scale)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: 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)
if (!((Object)(object)_root == (Object)null))
{
Transform transform = _root.transform;
Transform parent = transform.parent;
if ((Object)(object)parent == (Object)null || ((Object)parent).GetInstanceID() != ((Object)head).GetInstanceID())
{
transform.SetParent(head, false);
}
transform.localPosition = new Vector3(0f, 0f, distance);
transform.localRotation = Quaternion.identity;
float num = Mathf.Max(0.0001f, head.lossyScale.x);
transform.localScale = Vector3.one * (0.001f * scale / num);
}
}
public void Tick(State s)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: 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_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: 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_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_root == (Object)null))
{
_healthPanel.anchoredPosition = new Vector2(40f + s.HealthOffset.x, 40f + s.HealthOffset.y);
_ammoPanel.anchoredPosition = new Vector2(-40f + s.AmmoOffset.x, 40f + s.AmmoOffset.y);
Vector3 localScale = default(Vector3);
((Vector3)(ref localScale))..ctor(s.NumberScale.x, s.NumberScale.y, 1f);
((Transform)((Graphic)_healthNum).rectTransform).localScale = localScale;
((Transform)((Graphic)_ammoMag).rectTransform).localScale = localScale;
((Transform)((Graphic)_ammoReserve).rectTransform).localScale = localScale;
Color color = ((s.Health <= 25) ? Color.Lerp(Red, Yellow, 0.5f + 0.5f * Mathf.Sin(Time.time * 7f)) : Yellow);
_healthNum.text = s.Health.ToString();
((Graphic)_healthNum).color = color;
((Graphic)_healthLabel).color = color;
if (((Component)_ammoPanel).gameObject.activeSelf != s.ShowAmmo)
{
((Component)_ammoPanel).gameObject.SetActive(s.ShowAmmo);
}
if (s.ShowAmmo)
{
Color color2 = ((s.Mag <= 0) ? Red : Yellow);
_ammoMag.text = s.Mag.ToString();
((Graphic)_ammoMag).color = color2;
((Graphic)_ammoLabel).color = color2;
_ammoReserve.text = s.Reserve.ToString();
((Graphic)_ammoReserve).color = Yellow;
float x = s.NumberScale.x;
float num = Mathf.Max(12f, _ammoReserve.preferredWidth * x);
float num2 = Mathf.Max(18f, _ammoMag.preferredWidth * x);
float preferredWidth = _ammoLabel.preferredWidth;
_ammoResRt.sizeDelta = new Vector2(num + 4f, 44f);
_ammoMagRt.sizeDelta = new Vector2(num2 + 4f, 90f);
_ammoMagRt.anchoredPosition = new Vector2(0f - (14f + num + 6f), 0f);
_ammoPanel.sizeDelta = new Vector2(18f + preferredWidth + 10f + num2 + 6f + num + 14f, 84f);
}
Color color3 = default(Color);
((Color)(ref color3))..ctor(0f, 0f, 0f, Mathf.Clamp01(s.Scan));
bool enabled = s.Scan > 0.001f;
((Graphic)_healthScan).color = color3;
((Behaviour)_healthScan).enabled = enabled;
((Graphic)_ammoScan).color = color3;
((Behaviour)_ammoScan).enabled = enabled;
}
}
private static Vector2 V(float x, float y)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return new Vector2(x, y);
}
private RectTransform Rt(string name, Transform parent, Vector2 anchor, Vector2 pivot, Vector2 pos, Vector2 size)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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)
RectTransform obj = new GameObject(name).AddComponent<RectTransform>();
((Transform)obj).SetParent(parent, false);
Vector2 anchorMin = (obj.anchorMax = anchor);
obj.anchorMin = anchorMin;
obj.pivot = pivot;
obj.anchoredPosition = pos;
obj.sizeDelta = size;
return obj;
}
private RectTransform Stretch(string name, Transform parent)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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)
RectTransform obj = new GameObject(name).AddComponent<RectTransform>();
((Transform)obj).SetParent(parent, false);
obj.anchorMin = V(0f, 0f);
obj.anchorMax = V(1f, 1f);
Vector2 offsetMin = (obj.offsetMax = Vector2.zero);
obj.offsetMin = offsetMin;
return obj;
}
private Image ImgSliced(RectTransform rt, Sprite sprite, Color c)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
Image obj = Img(rt, sprite, c);
obj.type = (Type)1;
return obj;
}
private Image Img(RectTransform rt, Sprite sprite, Color c)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
Image val = ((Component)rt).gameObject.AddComponent<Image>();
val.sprite = sprite;
((Graphic)val).color = c;
((Graphic)val).raycastTarget = false;
if ((Object)(object)_mat != (Object)null)
{
((Graphic)val).material = _mat;
}
return val;
}
private Text Label(RectTransform rt, Font font, int size, TextAnchor anchor, FontStyle style)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
Text val = ((Component)rt).gameObject.AddComponent<Text>();
val.font = font;
val.fontSize = size;
val.fontStyle = style;
val.alignment = anchor;
((Graphic)val).color = Yellow;
val.horizontalOverflow = (HorizontalWrapMode)1;
val.verticalOverflow = (VerticalWrapMode)1;
((Graphic)val).raycastTarget = false;
if ((Object)(object)_mat != (Object)null)
{
((Graphic)val).material = _mat;
}
return val;
}
}
internal class DeathScreen
{
private const int PcmChannels = 2;
private const int PcmFreq = 48000;
private readonly Action<string> _log;
private GameObject _root;
private GameObject _camGo;
private Camera _cam;
private RenderTexture _rt;
private Canvas _canvas;
private RectTransform _canvasRt;
private RawImage _view;
private Image _red;
private AudioSource _src;
private AudioClip _clip;
private bool _clipTried;
private bool _active;
private float _t;
private float _yaw;
private Vector3 _target;
public bool Active
{
get
{
if (_active)
{
return (Object)(object)_root != (Object)null;
}
return false;
}
}
public DeathScreen(Action<string> log)
{
_log = log;
}
private void EnsureBuilt()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Expected O, but got Unknown
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Expected O, but got Unknown
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_rt == (Object)null)
{
_rt = new RenderTexture(768, 832, 24);
((Object)_rt).name = "Hl2DeathRT";
_rt.antiAliasing = 1;
_rt.Create();
((Object)_rt).hideFlags = (HideFlags)32;
}
if ((Object)(object)_camGo == (Object)null)
{
_camGo = new GameObject("Hl2DeathCam");
Object.DontDestroyOnLoad((Object)(object)_camGo);
_cam = _camGo.AddComponent<Camera>();
Camera main = Camera.main;
if ((Object)(object)main != (Object)null)
{
_cam.CopyFrom(main);
}
_cam.stereoTargetEye = (StereoTargetEyeMask)0;
_cam.targetTexture = _rt;
_cam.fieldOfView = 85f;
_cam.nearClipPlane = 0.05f;
_cam.depth = -50f;
_cam.allowHDR = false;
_cam.allowMSAA = false;
_camGo.SetActive(false);
}
if ((Object)(object)_root == (Object)null)
{
_root = new GameObject("Hl2DeathScreen");
Object.DontDestroyOnLoad((Object)(object)_root);
_canvas = _root.AddComponent<Canvas>();
_canvas.renderMode = (RenderMode)1;
_canvas.sortingOrder = 200;
RectTransform val = (_canvasRt = _root.GetComponent<RectTransform>());
Material val2 = Hud.MakeOverlayMaterial();
GameObject val3 = new GameObject("View");
RectTransform obj = val3.AddComponent<RectTransform>();
((Transform)obj).SetParent((Transform)(object)val, false);
obj.anchorMin = new Vector2(0f, 0f);
obj.anchorMax = new Vector2(1f, 1f);
Vector2 offsetMin = (obj.offsetMax = Vector2.zero);
obj.offsetMin = offsetMin;
_view = val3.AddComponent<RawImage>();
_view.texture = (Texture)(object)_rt;
((Graphic)_view).raycastTarget = false;
if ((Object)(object)val2 != (Object)null)
{
((Graphic)_view).material = val2;
}
GameObject val4 = new GameObject("Red");
RectTransform obj2 = val4.AddComponent<RectTransform>();
((Transform)obj2).SetParent((Transform)(object)val, false);
obj2.anchorMin = new Vector2(0f, 0f);
obj2.anchorMax = new Vector2(1f, 1f);
offsetMin = (obj2.offsetMax = Vector2.zero);
obj2.offsetMin = offsetMin;
_red = val4.AddComponent<Image>();
((Graphic)_red).raycastTarget = false;
if ((Object)(object)val2 != (Object)null)
{
((Graphic)_red).material = val2;
}
_src = _root.AddComponent<AudioSource>();
_src.spatialBlend = 0f;
_src.loop = false;
_root.SetActive(false);
}
}
private AudioClip LoadClip()
{
if (_clipTried)
{
return _clip;
}
_clipTried = true;
try
{
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Hl2Hud.death.pcm");
if (stream == null)
{
_log("death.pcm resource missing");
return null;
}
byte[] array = new byte[stream.Length];
int num;
for (int i = 0; i < array.Length; i += num)
{
num = stream.Read(array, i, array.Length - i);
if (num <= 0)
{
break;
}
}
int num2 = array.Length / 2;
float[] array2 = new float[num2];
for (int j = 0; j < num2; j++)
{
array2[j] = (float)(short)(array[2 * j] | (array[2 * j + 1] << 8)) / 32768f;
}
AudioClip val = AudioClip.Create("Hl2Death", num2 / 2, 2, 48000, false);
val.SetData(Il2CppStructArray<float>.op_Implicit(array2), 0);
((Object)val).hideFlags = (HideFlags)32;
_clip = val;
}
catch (Exception ex)
{
_log("Death sound failed to load: " + ex.GetType().Name + ": " + ex.Message);
}
return _clip;
}
private void Begin(Transform head, Transform body, float volume)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
_active = true;
_t = 0f;
_yaw = head.eulerAngles.y + 180f;
_target = (((Object)(object)body != (Object)null) ? body.position : head.position);
int num = (((Object)(object)Camera.main != (Object)null) ? Camera.main.cullingMask : (-1));
num |= GameBridge.AvatarLayerMask();
_cam.cullingMask = num;
_camGo.SetActive(true);
((Behaviour)_cam).enabled = true;
_root.SetActive(true);
AudioClip val = LoadClip();
if ((Object)(object)val != (Object)null && (Object)(object)_src != (Object)null)
{
try
{
_src.volume = Mathf.Clamp01(volume);
_src.PlayOneShot(val, 1f);
}
catch (Exception ex)
{
_log("Death sound failed to play: " + ex.GetType().Name);
}
}
}
public void Tick(Transform head, Transform body, float dt, float volume, float distance)
{
//IL_0038: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Invalid comparison between Unknown and I4
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Invalid comparison between Unknown and I4
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
EnsureBuilt();
if (!Active)
{
Begin(head, body, volume);
}
_t += dt;
Vector3 val = (((Object)(object)body != (Object)null) ? body.position : head.position);
_target = Vector3.Lerp(_target, val, 1f - Mathf.Exp(-8f * dt));
_yaw += 10f * dt;
float num = _yaw * (MathF.PI / 180f);
Vector3 val2 = _target + new Vector3(Mathf.Sin(num), 0f, Mathf.Cos(num)) * distance + Vector3.up * 1.1f;
Transform transform = _camGo.transform;
transform.position = val2;
transform.rotation = Quaternion.LookRotation(_target + Vector3.up * 0.2f - val2, Vector3.up);
Transform transform2 = _root.transform;
Camera headCam = GameBridge.HeadCam;
if (Settings.DeathHeadLocked.Value)
{
if ((int)_canvas.renderMode != 2)
{
_canvas.renderMode = (RenderMode)2;
}
_canvasRt.sizeDelta = new Vector2(1600f, 900f);
Transform parent = transform2.parent;
if ((Object)(object)parent == (Object)null || ((Object)parent).GetInstanceID() != ((Object)head).GetInstanceID())
{
transform2.SetParent(head, false);
}
transform2.localPosition = new Vector3(0f, 0f, 0.9f);
transform2.localRotation = Quaternion.identity;
float num2 = Mathf.Max(0.0001f, head.lossyScale.x);
transform2.localScale = Vector3.one * (0.0022f / num2);
}
else if ((Object)(object)headCam != (Object)null)
{
if ((Object)(object)transform2.parent != (Object)null)
{
transform2.SetParent((Transform)null, false);
}
if ((int)_canvas.renderMode != 1)
{
_canvas.renderMode = (RenderMode)1;
}
Camera worldCamera = _canvas.worldCamera;
if ((Object)(object)worldCamera == (Object)null || ((Object)worldCamera).GetInstanceID() != ((Object)headCam).GetInstanceID())
{
_canvas.worldCamera = headCam;
}
_canvas.planeDistance = Mathf.Max(0.3f, headCam.nearClipPlane * 3f);
}
float num3 = Mathf.Clamp01(_t / 0.4f);
((Graphic)_view).color = new Color(1f, 1f, 1f, num3);
((Graphic)_red).color = new Color(0.78f, 0.04f, 0.04f, 0.42f * num3);
}
public void End()
{
if (!_active)
{
return;
}
_active = false;
try
{
if ((Object)(object)_src != (Object)null)
{
_src.Stop();
}
}
catch
{
}
if ((Object)(object)_cam != (Object)null)
{
((Behaviour)_cam).enabled = false;
}
if ((Object)(object)_camGo != (Object)null)
{
_camGo.SetActive(false);
}
if ((Object)(object)_root != (Object)null)
{
_root.SetActive(false);
}
}
}
internal static class Sprites
{
private static readonly Dictionary<string, Sprite> _cache = new Dictionary<string, Sprite>();
public static Sprite Panel(float h, float radius, bool scan)
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
string key = "panel" + h + "r" + radius + (scan ? "s" : "");
if (_cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
int num = Mathf.RoundToInt((radius * 2f + 8f) * 1.5f);
int num2 = Mathf.RoundToInt(h * 1.5f);
float num3 = radius * 1.5f;
Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
((Texture)val).filterMode = (FilterMode)1;
((Texture)val).wrapMode = (TextureWrapMode)1;
for (int i = 0; i < num2; i++)
{
for (int j = 0; j < num; j++)
{
float num4 = Mathf.Abs((float)j + 0.5f - (float)num * 0.5f) - ((float)num * 0.5f - num3);
float num5 = Mathf.Abs((float)i + 0.5f - (float)num2 * 0.5f) - ((float)num2 * 0.5f - num3);
float num6 = Mathf.Max(num4, 0f);
float num7 = Mathf.Max(num5, 0f);
float num8 = Mathf.Sqrt(num6 * num6 + num7 * num7) - num3;
float num9 = Mathf.Clamp01(0.5f - num8);
if (scan)
{
float num10 = Mathf.Repeat(((float)i + 0.5f) / 1.5f, 4f) / 4f;
float num11 = ((num10 < 0.5f) ? Mathf.Clamp01(Mathf.Min(num10, 0.5f - num10) / 0.1f) : 0f);
num9 *= num11;
}
val.SetPixel(j, i, new Color(1f, 1f, 1f, num9));
}
}
val.Apply();
((Object)val).hideFlags = (HideFlags)32;
Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f), 150f, 0u, (SpriteMeshType)0, new Vector4(num3, 0f, num3, 0f));
((Object)val2).hideFlags = (HideFlags)32;
_cache[key] = val2;
return val2;
}
}
internal static class GameBridge
{
private class HandCache
{
public int Id;
public Gun Gun;
}
private static RigManager _rm;
private static Camera _cam;
private static float _rigSearchAt;
private static Player_Health _ph;
private static Renderer _vig;
private static bool _ragdolled;
private static readonly HandCache _right = new HandCache();
private static readonly HandCache _left = new HandCache();
private static bool _warned;
private static int _noGunLogs;
private static RigManager Rig
{
get
{
if ((Object)(object)_rm == (Object)null && Time.time >= _rigSearchAt)
{
_rigSearchAt = Time.time + 0.5f;
_rm = Object.FindObjectOfType<RigManager>();
}
return _rm;
}
}
public static Camera HeadCam
{
get
{
if ((Object)(object)_cam == (Object)null)
{
_cam = Camera.main;
}
return _cam;
}
}
public static Transform Head
{
get
{
Camera headCam = HeadCam;
if (!((Object)(object)headCam != (Object)null))
{
return null;
}
return ((Component)headCam).transform;
}
}
public static void Invalidate()
{
_rm = null;
_cam = null;
_ph = null;
_vig = null;
_rigSearchAt = 0f;
_ragdolled = false;
_right.Id = (_left.Id = 0);
_right.Gun = (_left.Gun = null);
}
public static int RigId()
{
try
{
RigManager rig = Rig;
return ((Object)(object)rig != (Object)null) ? ((Object)rig).GetInstanceID() : 0;
}
catch
{
return 0;
}
}
public static bool IsLoadingScene()
{
try
{
return (Object)(object)Object.FindObjectOfType<LoadingScene>() != (Object)null;
}
catch
{
return false;
}
}
public static bool IsDead()
{
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return false;
}
Health health = rig.health;
if ((Object)(object)health == (Object)null)
{
return false;
}
return !health.alive || health.deathIsImminent || (health.max_Health > 0f && health.curr_Health <= 0f);
}
catch (Exception e)
{
Warn("death check", e);
return false;
}
}
public static void RagdollPlayer()
{
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return;
}
PhysicsRig physicsRig = rig.physicsRig;
if (!((Object)(object)physicsRig == (Object)null))
{
if (!physicsRig.shutdown)
{
physicsRig.ShutdownRig();
}
physicsRig.RagdollRig();
_ragdolled = true;
}
}
catch (Exception e)
{
Warn("ragdoll", e);
}
}
public static void RecoverPlayer()
{
if (!_ragdolled)
{
return;
}
_ragdolled = false;
try
{
RigManager rm = _rm;
if ((Object)(object)rm == (Object)null)
{
return;
}
Health health = rm.health;
if (!((Object)(object)health == (Object)null) && health.alive && !(health.curr_Health <= 0f))
{
PhysicsRig physicsRig = rm.physicsRig;
if (!((Object)(object)physicsRig == (Object)null))
{
physicsRig.UnRagdollRig();
physicsRig.TurnOnRig();
}
}
}
catch (Exception e)
{
Warn("un-ragdoll", e);
}
}
public static void SuppressVignette()
{
try
{
if ((Object)(object)_ph == (Object)null || (Object)(object)_vig == (Object)null)
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return;
}
Health health = rig.health;
if ((Object)(object)health == (Object)null)
{
return;
}
_ph = ((Il2CppObjectBase)health).TryCast<Player_Health>();
if ((Object)(object)_ph == (Object)null)
{
return;
}
_vig = (Renderer)(object)_ph.vigRend;
if ((Object)(object)_vig == (Object)null)
{
return;
}
}
if (_vig.enabled)
{
_vig.enabled = false;
}
}
catch (Exception e)
{
Warn("vignette", e);
_ph = null;
_vig = null;
}
}
public static Transform BodyTransform()
{
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return null;
}
PhysicsRig physicsRig = rig.physicsRig;
if ((Object)(object)physicsRig == (Object)null)
{
return null;
}
PhysTorso torso = physicsRig.torso;
if ((Object)(object)torso != (Object)null)
{
Grip gPelvis = torso.gPelvis;
if ((Object)(object)gPelvis != (Object)null)
{
return ((Component)gPelvis).transform;
}
}
GameObject knee = physicsRig.knee;
return ((Object)(object)knee != (Object)null) ? knee.transform : null;
}
catch (Exception e)
{
Warn("body lookup", e);
return null;
}
}
public static int AvatarLayerMask()
{
int num = 0;
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return 0;
}
foreach (SkinnedMeshRenderer componentsInChild in ((Component)rig).GetComponentsInChildren<SkinnedMeshRenderer>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
num |= 1 << ((Component)componentsInChild).gameObject.layer;
}
}
}
catch (Exception e)
{
Warn("avatar layers", e);
}
return num;
}
public static bool TryGetHealth(out float cur, out float max)
{
cur = (max = 0f);
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return false;
}
Health health = rig.health;
if ((Object)(object)health == (Object)null)
{
return false;
}
cur = health.curr_Health;
max = health.max_Health;
return max > 0f;
}
catch (Exception e)
{
Warn("health read", e);
return false;
}
}
private static void Warn(string what, Exception e)
{
if (!_warned)
{
_warned = true;
MelonLogger.Warning("HL2 HUD: " + what + " failed (" + e.GetType().Name + ": " + e.Message + "); will keep retrying quietly.");
}
}
private static Gun HeldGun(Hand hand, HandCache c)
{
if ((Object)(object)hand == (Object)null)
{
c.Id = 0;
c.Gun = null;
return null;
}
GameObject val = null;
try
{
HandReciever attachedReceiver = hand.AttachedReceiver;
if ((Object)(object)attachedReceiver != (Object)null)
{
val = ((Component)attachedReceiver).gameObject;
}
}
catch
{
}
if ((Object)(object)val == (Object)null)
{
val = hand.m_CurrentAttachedGO;
}
if ((Object)(object)val == (Object)null)
{
c.Id = 0;
c.Gun = null;
return null;
}
int instanceID = ((Object)val).GetInstanceID();
if (instanceID != c.Id)
{
c.Id = instanceID;
c.Gun = LocateGun(val);
}
if ((Object)(object)c.Gun == (Object)null)
{
return null;
}
return c.Gun;
}
private static Gun LocateGun(GameObject go)
{
Gun val = go.GetComponentInParent<Gun>();
if ((Object)(object)val == (Object)null)
{
Transform root = go.transform.root;
if ((Object)(object)root != (Object)null)
{
val = ((Component)root).GetComponentInChildren<Gun>(true);
}
}
if ((Object)(object)val == (Object)null && _noGunLogs < 3)
{
_noGunLogs++;
MelonLogger.Msg("HL2 HUD: holding '" + ((Object)go).name + "' but found no Gun on it (ammo panel stays hidden).");
}
return val;
}
public static bool TryGetAmmo(out int mag, out int reserve)
{
mag = (reserve = 0);
try
{
RigManager rig = Rig;
if ((Object)(object)rig == (Object)null)
{
return false;
}
PhysicsRig physicsRig = rig.physicsRig;
if ((Object)(object)physicsRig == (Object)null)
{
return false;
}
Gun val = HeldGun(physicsRig.rightHand, _right);
if ((Object)(object)val == (Object)null)
{
val = HeldGun(physicsRig.leftHand, _left);
}
if ((Object)(object)val == (Object)null)
{
return false;
}
mag = val.AmmoCount();
CartridgeData val2 = null;
MagazineState magazineState = val.MagazineState;
if (magazineState != null)
{
val2 = magazineState.cartridgeData;
}
if ((Object)(object)val2 == (Object)null)
{
val2 = val.defaultCartridge;
}
AmmoInventory instance = AmmoInventory.Instance;
if ((Object)(object)instance != (Object)null && (Object)(object)val2 != (Object)null)
{
reserve = instance.GetCartridgeCount(val2);
}
return true;
}
catch (Exception e)
{
Warn("ammo read", e);
mag = (reserve = 0);
return false;
}
}
public static int TryGetLightReserve()
{
try
{
return LightReserveUnsafe();
}
catch (Exception e)
{
Warn("pouch read", e);
return 0;
}
}
private static int LightReserveUnsafe()
{
AmmoInventory instance = AmmoInventory.Instance;
if ((Object)(object)instance == (Object)null || (Object)(object)instance.lightAmmoGroup == (Object)null)
{
return 0;
}
int num = 0;
Il2CppReferenceArray<CartridgeData> cartridges = instance.lightAmmoGroup.cartridges;
if (cartridges == null)
{
return 0;
}
foreach (CartridgeData item in (Il2CppArrayBase<CartridgeData>)(object)cartridges)
{
if ((Object)(object)item != (Object)null)
{
num += instance.GetCartridgeCount(item);
}
}
return num;
}
}
public class Speaker
{
public int Id;
public string Name;
public Texture Icon;
public bool Local;
public float Level;
public readonly float[] Bands = new float[6];
public float NameAt;
public bool HasHead;
public Vector3 HeadPos;
}
internal static class LabFusionBridge
{
private static bool? _present;
private static readonly Dictionary<int, Speaker> _cache = new Dictionary<int, Speaker>();
private static Il2CppStructArray<float> _spec;
private static readonly int[] Edges = new int[7] { 1, 2, 4, 8, 14, 24, 40 };
public static bool Present
{
get
{
if (!_present.HasValue)
{
_present = false;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
if (assemblies[i].GetName().Name == "LabFusion")
{
_present = true;
break;
}
}
}
return _present.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Poll(List<Speaker> output, bool includeSelf, float gain)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
output.Clear();
if (_spec == null)
{
_spec = new Il2CppStructArray<float>(256L);
}
HashSet<NetworkPlayer> players = NetworkPlayer.Players;
if (players == null)
{
return;
}
foreach (NetworkPlayer item in players)
{
try
{
if (item == null)
{
continue;
}
PlayerID playerID = item.PlayerID;
if (playerID == null || !playerID.IsValid)
{
continue;
}
bool isMe = playerID.IsMe;
if (isMe && !includeSelf)
{
continue;
}
bool flag = false;
bool flag2 = false;
Vector3 headPos = default(Vector3);
float amp = 0f;
AudioSource src = null;
if (isMe)
{
flag = VoiceInfo.HasVoiceActivity && !VoiceInfo.IsMuted;
amp = VoiceInfo.VoiceAmplitude;
}
else
{
RigVoiceSource voiceSource = item.VoiceSource;
VoiceSource val = ((voiceSource != null) ? voiceSource.VoiceSource : null);
if ((Object)(object)val != (Object)null && val.ReceivingInput && !val.Muted)
{
flag = true;
amp = val.Amplitude;
src = val.AudioSource;
}
Transform val2 = ((voiceSource != null) ? voiceSource.Mouth : null);
flag2 = (Object)(object)val2 != (Object)null;
if (flag2)
{
headPos = val2.position;
}
}
if (flag)
{
int smallID = playerID.SmallID;
if (!_cache.TryGetValue(smallID, out var value))
{
value = new Speaker();
_cache[smallID] = value;
}
value.Id = smallID;
value.Local = isMe;
value.HasHead = flag2;
value.HeadPos = headPos;
float time = Time.time;
if (value.Name == null || time >= value.NameAt)
{
value.Name = DisplayName(item, playerID);
value.NameAt = time + 2f;
}
RigIcon icon = item.Icon;
value.Icon = ((icon != null) ? icon.Texture : null);
FillBands(value, src, amp, gain);
output.Add(value);
}
}
catch
{
}
}
}
private static string DisplayName(NetworkPlayer np, PlayerID pid)
{
string text = null;
try
{
text = pid.Metadata.Nickname.GetValue();
}
catch
{
}
if (!string.IsNullOrEmpty(text))
{
return text;
}
if (!string.IsNullOrEmpty(np.Username))
{
return np.Username;
}
return "Player " + pid.SmallID;
}
private static void FillBands(Speaker sp, AudioSource src, float amp, float gain)
{
bool flag = false;
if ((Object)(object)src != (Object)null)
{
try
{
src.GetSpectrumData(_spec, 0, (FFTWindow)2);
float num = 0f;
int num2 = Edges.Length - 1;
for (int i = 0; i < num2; i++)
{
float num3 = 0f;
int num4 = Edges[i];
int num5 = Edges[i + 1];
for (int j = num4; j < num5; j++)
{
num3 += ((Il2CppArrayBase<float>)(object)_spec)[j];
}
float num6 = num3 / (float)(num5 - num4);
num += num6;
sp.Bands[num2 - 1 - i] = Mathf.Clamp01(Mathf.Pow(num6 * 25f * gain, 0.6f));
}
flag = num > 0.0004f;
}
catch
{
flag = false;
}
}
if (!flag)
{
float num7 = Mathf.Clamp01(amp * gain * 2.5f);
for (int k = 0; k < sp.Bands.Length; k++)
{
float num8 = Mathf.PerlinNoise(Time.time * 9f + (float)k * 3.1f, 0.37f);
sp.Bands[k] = Mathf.Clamp01(num7 * (0.45f + 0.55f * num8) * (1.25f - (float)k * 0.12f));
}
}
float num9 = 0f;
float num10 = 0f;
for (int l = 0; l < sp.Bands.Length; l++)
{
num9 = Mathf.Max(num9, sp.Bands[l]);
num10 += sp.Bands[l];
}
sp.Level = Mathf.Clamp01(Mathf.Max(num10 / (float)sp.Bands.Length * 1.6f, num9 * 0.7f));
}
}
internal class VoiceOverlay
{
private class Entry
{
public int Id;
public RectTransform Rt;
public CanvasGroup Group;
public Image Bg;
public Image FallbackBg;
public RawImage Avatar;
public Text Letter;
public Text Name;
public float Alpha;
public float Level;
public float Talk;
public float StartTime;
public float LastSpoke;
public bool Active;
public bool Placed;
public string LastName;
}
public struct Style
{
public bool IncludeSelf;
public float Gain;
public float Scale;
public float Opacity;
public float Spacing;
public Vector2 Offset;
}
public const int BandCount = 6;
private const float RowH = 44f;
private const float AvatarSize = 34f;
private const float MaxNameW = 260f;
private const float BaseX = 60f;
private const float MarginY = 40f;
private const float HoldTime = 0.35f;
private const int MaxRows = 5;
private static readonly Color Green = new Color(0.12f, 0.8f, 0.3f, 1f);
private static readonly Color White = new Color(1f, 1f, 1f, 1f);
private readonly RectTransform _parent;
private readonly Font _font;
private readonly Material _mat;
private readonly Dictionary<int, Entry> _entries = new Dictionary<int, Entry>();
private readonly List<Entry> _active = new List<Entry>();
private readonly List<Speaker> _speaking = new List<Speaker>();
private readonly HashSet<int> _speakingIds = new HashSet<int>();
private float _retryAt;
private bool _logged;
public IList<Speaker> Speaking => _speaking;
public VoiceOverlay(RectTransform canvasRt, Font font, Material mat)
{
_parent = canvasRt;
_font = font;
_mat = mat;
}
public void HideAll()
{
foreach (Entry value in _entries.Values)
{
if (value.Active || ((Component)value.Rt).gameObject.activeSelf)
{
value.Active = false;
value.Alpha = 0f;
((Component)value.Rt).gameObject.SetActive(false);
}
}
}
public void Tick(float dt, Style st, Action<string> log)
{
if (Time.time < _retryAt)
{
return;
}
try
{
LabFusionBridge.Poll(_speaking, st.IncludeSelf, st.Gain);
}
catch (Exception ex)
{
_retryAt = Time.time + 5f;
if (!_logged)
{
_logged = true;
log("Voice indicator error (retrying): " + ex.GetType().Name + ": " + ex.Message);
}
HideAll();
return;
}
float time = Time.time;
_speakingIds.Clear();
foreach (Speaker item in _speaking)
{
if (_entries.Count < 16 || _entries.ContainsKey(item.Id))
{
Entry entry = GetEntry(item.Id);
_speakingIds.Add(item.Id);
if (!entry.Active)
{
entry.Active = true;
entry.StartTime = time;
entry.Placed = false;
((Component)entry.Rt).gameObject.SetActive(true);
}
entry.LastSpoke = time;
string text = item.Name ?? "Player";
if (text.Length > 18)
{
text = text.Substring(0, 17) + "…";
}
if (entry.LastName != text)
{
entry.LastName = text;
entry.Name.text = text;
entry.Letter.text = ((text.Length > 0) ? text.Substring(0, 1).ToUpperInvariant() : "?");
}
bool flag = (Object)(object)item.Icon != (Object)null;
if (((Behaviour)entry.Avatar).enabled != flag)
{
((Behaviour)entry.Avatar).enabled = flag;
}
if (flag && (Object)(object)entry.Avatar.texture != (Object)(object)item.Icon)
{
entry.Avatar.texture = item.Icon;
}
((Behaviour)entry.FallbackBg).enabled = !flag;
((Behaviour)entry.Letter).enabled = !flag;
float level = item.Level;
float num = Mathf.Min(1f, dt * ((level > entry.Level) ? 35f : 10f));
entry.Level += (level - entry.Level) * num;
entry.Talk += (1f - entry.Talk) * Mathf.Min(1f, dt * 25f);
}
}
_active.Clear();
foreach (Entry value in _entries.Values)
{
if (!_speakingIds.Contains(value.Id))
{
value.Level -= value.Level * Mathf.Min(1f, dt * 10f);
value.Talk -= value.Talk * Mathf.Min(1f, dt * 7f);
}
bool flag2 = time - value.LastSpoke < 0.35f;
value.Alpha = Mathf.MoveTowards(value.Alpha, flag2 ? 1f : 0f, dt * 8f);
if (value.Active && !flag2 && value.Alpha <= 0.001f)
{
value.Active = false;
((Component)value.Rt).gameObject.SetActive(false);
}
else if (value.Active)
{
_active.Add(value);
}
}
_active.Sort((Entry a, Entry b) => a.StartTime.CompareTo(b.StartTime));
float follow = 1f - Mathf.Exp(-18f * dt);
int num2 = Mathf.Min(_active.Count, 5);
for (int num3 = 0; num3 < num2; num3++)
{
Entry e = _active[num3];
Layout(e, num3, num2, follow, st);
Visuals(e, st);
}
for (int num4 = 5; num4 < _active.Count; num4++)
{
((Component)_active[num4].Rt).gameObject.SetActive(false);
}
}
private void Layout(Entry e, int row, int count, float follow, Style st)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: 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)
//IL_008e: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
if (!((Component)e.Rt).gameObject.activeSelf)
{
((Component)e.Rt).gameObject.SetActive(true);
}
float num = Mathf.Min(260f, e.Name.preferredWidth);
((Graphic)e.Name).rectTransform.sizeDelta = new Vector2(num + 4f, 30f);
e.Rt.sizeDelta = new Vector2(54f + num + 14f, 44f);
((Transform)e.Rt).localScale = Vector3.one * st.Scale;
float num2 = 44f * st.Scale + st.Spacing;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(60f + st.Offset.x, 40f + st.Offset.y + (float)(count - 1 - row) * num2);
e.Rt.anchoredPosition = (e.Placed ? Vector2.Lerp(e.Rt.anchoredPosition, val, follow) : val);
e.Placed = true;
}
private void Visuals(Entry e, Style st)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
e.Group.alpha = e.Alpha;
float num = Mathf.Clamp01(e.Level);
float num2 = Mathf.Clamp01(e.Talk) * Mathf.Lerp(0.7f, 1f, num);
Color val = default(Color);
((Color)(ref val))..ctor(0f, 0f, 0f, Mathf.Clamp01(st.Opacity));
Color val2 = default(Color);
((Color)(ref val2))..ctor(Green.r, Green.g, Green.b, Mathf.Max(0.9f, st.Opacity));
((Graphic)e.Bg).color = Color.Lerp(val, val2, num2);
}
private Entry GetEntry(int id)
{
if (_entries.TryGetValue(id, out var value) && (Object)(object)value.Rt != (Object)null)
{
return value;
}
value = Build(id);
_entries[id] = value;
return value;
}
private Entry Build(int id)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: 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_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
Entry entry = new Entry
{
Id = id
};
entry.Rt = Rt("Speaker" + id, (Transform)(object)_parent, V(0.5f, 0f), V(0f, 0f), V(60f, 40f), V(240f, 44f));
entry.Group = ((Component)entry.Rt).gameObject.AddComponent<CanvasGroup>();
entry.Group.interactable = false;
entry.Group.blocksRaycasts = false;
entry.Bg = Img(((Component)entry.Rt).gameObject, null, new Color(0f, 0f, 0f, 0.5f));
RectTransform val = Rt("Avatar", (Transform)(object)entry.Rt, V(0f, 0.5f), V(0f, 0.5f), V(10f, 0f), V(34f, 34f));
entry.FallbackBg = Img(((Component)val).gameObject, null, new Color(0.22f, 0.22f, 0.22f, 1f));
RectTransform val2 = Rt("Pic", (Transform)(object)val, V(0.5f, 0.5f), V(0.5f, 0.5f), V(0f, 0f), V(34f, 34f));
entry.Avatar = ((Component)val2).gameObject.AddComponent<RawImage>();
((Graphic)entry.Avatar).raycastTarget = false;
if ((Object)(object)_mat != (Object)null)
{
((Graphic)entry.Avatar).material = _mat;
}
((Behaviour)entry.Avatar).enabled = false;
RectTransform rt = Rt("Letter", (Transform)(object)val, V(0.5f, 0.5f), V(0.5f, 0.5f), V(0f, 0f), V(34f, 34f));
entry.Letter = Label(rt, 22, (TextAnchor)4, (FontStyle)1);
RectTransform rt2 = Rt("Name", (Transform)(object)entry.Rt, V(0f, 0.5f), V(0f, 0.5f), V(54f, 0f), V(200f, 30f));
entry.Name = Label(rt2, 20, (TextAnchor)3, (FontStyle)0);
((Component)entry.Rt).gameObject.SetActive(false);
return entry;
}
private static Vector2 V(float x, float y)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return new Vector2(x, y);
}
private RectTransform Rt(string name, Transform parent, Vector2 anchor, Vector2 pivot, Vector2 pos, Vector2 size)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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)
RectTransform obj = new GameObject(name).AddComponent<RectTransform>();
((Transform)obj).SetParent(parent, false);
Vector2 anchorMin = (obj.anchorMax = anchor);
obj.anchorMin = anchorMin;
obj.pivot = pivot;
obj.anchoredPosition = pos;
obj.sizeDelta = size;
return obj;
}
private Image Img(GameObject go, Sprite sprite, Color c)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
Image val = go.AddComponent<Image>();
val.sprite = sprite;
((Graphic)val).color = c;
((Graphic)val).raycastTarget = false;
if ((Object)(object)_mat != (Object)null)
{
((Graphic)val).material = _mat;
}
return val;
}
private Text Label(RectTransform rt, int size, TextAnchor anchor, FontStyle style)
{
//IL_0020: 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_002f: Unknown result type (might be due to invalid IL or missing references)
Text val = ((Component)rt).gameObject.AddComponent<Text>();
val.font = _font;
val.fontSize = size;
val.fontStyle = style;
val.alignment = anchor;
((Graphic)val).color = White;
val.horizontalOverflow = (HorizontalWrapMode)1;
val.verticalOverflow = (VerticalWrapMode)1;
((Graphic)val).raycastTarget = false;
if ((Object)(object)_mat != (Object)null)
{
((Graphic)val).material = _mat;
}
return val;
}
}
internal class VoiceHeadIcons
{
private class Icon
{
public GameObject Go;
public Transform T;
public RawImage Img;
public float Alpha;
public float LastSpoke;
public float Level;
public bool Active;
}
private const int TexSize = 128;
private const float HoldTime = 0.35f;
private readonly Dictionary<int, Icon> _icons = new Dictionary<int, Icon>();
private readonly HashSet<int> _ids = new HashSet<int>();
private Texture2D _tex;
private bool _texTried;
private Texture2D LoadTexture(Action<string> log)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
if ((Object)(object)_tex != (Object)null)
{
return _tex;
}
if (_texTried)
{
return null;
}
_texTried = true;
try
{
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Hl2Hud.speaker.rgba");
if (stream == null)
{
log("speaker.rgba resource missing");
return null;
}
byte[] array = new byte[stream.Length];
int num;
for (int i = 0; i < array.Length; i += num)
{
num = stream.Read(array, i, array.Length - i);
if (num <= 0)
{
break;
}
}
Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
((Texture)val).filterMode = (FilterMode)1;
((Texture)val).wrapMode = (TextureWrapMode)1;
val.LoadRawTextureData(Il2CppStructArray<byte>.op_Implicit(array));
val.Apply();
((Object)val).hideFlags = (HideFlags)32;
_tex = val;
}
catch (Exception ex)
{
log("Speaker icon failed to load: " + ex.GetType().Name + ": " + ex.Message);
}
return _tex;
}
public void HideAll()
{
foreach (Icon value in _icons.Values)
{
if (value.Active && (Object)(object)value.Go != (Object)null)
{
value.Active = false;
value.Alpha = 0f;
value.Go.SetActive(false);
}
}
}
public void Tick(IList<Speaker> speaking, Transform head, float dt, float size, float height, Action<string> log)
{
//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_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_0249: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = LoadTexture(log);
if ((Object)(object)val == (Object)null || (Object)(object)head == (Object)null)
{
return;
}
float time = Time.time;
_ids.Clear();
for (int i = 0; i < speaking.Count; i++)
{
Speaker speaker = speaking[i];
if (!speaker.Local && speaker.HasHead)
{
if (!_icons.TryGetValue(speaker.Id, out var value) || (Object)(object)value.Go == (Object)null)
{
value = Build(val);
_icons[speaker.Id] = value;
}
_ids.Add(speaker.Id);
if (!value.Active)
{
value.Active = true;
value.Go.SetActive(true);
}
value.LastSpoke = time;
float num = Mathf.Min(1f, dt * ((speaker.Level > value.Level) ? 30f : 10f));
value.Level += (speaker.Level - value.Level) * num;
Place(value, speaker.HeadPos + Vector3.up * height, head, size);
}
}
foreach (KeyValuePair<int, Icon> icon in _icons)
{
Icon value2 = icon.Value;
if (!((Object)(object)value2.Go == (Object)null))
{
if (!_ids.Contains(icon.Key))
{
value2.Level -= value2.Level * Mathf.Min(1f, dt * 10f);
}
bool flag = time - value2.LastSpoke < 0.35f;
value2.Alpha = Mathf.MoveTowards(value2.Alpha, flag ? 1f : 0f, dt * 8f);
if (value2.Active && !flag && value2.Alpha <= 0.001f)
{
value2.Active = false;
value2.Go.SetActive(false);
}
else if (value2.Active)
{
((Graphic)value2.Img).color = new Color(1f, 1f, 1f, value2.Alpha);
}
}
}
}
private void Place(Icon ic, Vector3 pos, Transform head, float size)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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)
Transform t = ic.T;
t.position = pos;
Vector3 val = pos - head.position;
if (((Vector3)(ref val)).sqrMagnitude > 0.0001f)
{
t.rotation = Quaternion.LookRotation(val, Vector3.up);
}
float magnitude = ((Vector3)(ref val)).magnitude;
float num = size * Mathf.Clamp(magnitude / 2.5f, 1f, 4f) * (1f + 0.15f * ic.Level);
t.localScale = Vector3.one * (num / 128f);
}
private Icon Build(Texture2D tex)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: 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)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
Icon icon = new Icon();
icon.Go = new GameObject("Hl2VoiceIcon");
icon.T = icon.Go.transform;
Canvas obj = icon.Go.AddComponent<Canvas>();
obj.renderMode = (RenderMode)2;
obj.sortingOrder = 50;
icon.Go.GetComponent<RectTransform>().sizeDelta = new Vector2(128f, 128f);
GameObject val = new GameObject("Icon");
RectTransform obj2 = val.AddComponent<RectTransform>();
((Transform)obj2).SetParent(icon.T, false);
obj2.anchorMin = new Vector2(0f, 0f);
obj2.anchorMax = new Vector2(1f, 1f);
Vector2 offsetMin = (obj2.offsetMax = Vector2.zero);
obj2.offsetMin = offsetMin;
icon.Img = val.AddComponent<RawImage>();
icon.Img.texture = (Texture)(object)tex;
((Graphic)icon.Img).raycastTarget = false;
icon.Go.SetActive(false);
return icon;
}
}
}