using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Hamunii")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Lethal Company Mod that adds a visual and audio indicator for when your jetpack is about to explode.")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyInformationalVersion("2.2.0")]
[assembly: AssemblyProduct("JetpackWarning")]
[assembly: AssemblyTitle("JetpackWarning")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 JetpackWarning
{
public static class Assets
{
public static string mainAssetBundleName = "jetpackAssets";
public static AssetBundle MainAssetBundle = null;
private static string GetAssemblyName()
{
return Assembly.GetExecutingAssembly().FullName.Split(',')[0];
}
public static void PopulateAssets()
{
if ((Object)(object)MainAssetBundle == (Object)null)
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName))
{
MainAssetBundle = AssetBundle.LoadFromStream(stream);
}
}
}
}
[BepInPlugin("JetpackWarning", "JetpackWarning", "2.2.0")]
public class JetpackWarningPlugin : BaseUnityPlugin
{
public static Harmony _harmony;
public static AudioClip jetpackCriticalBeep;
public static GameObject meterContainer;
public static GameObject meter;
public static GameObject frame;
public static GameObject warning;
private void Awake()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin JetpackWarning is loaded!");
Assets.PopulateAssets();
_harmony = new Harmony("JetpackWarning");
_harmony.PatchAll(typeof(Patches));
SceneManager.sceneLoaded += OnSceneRelayLoaded;
jetpackCriticalBeep = Assets.MainAssetBundle.LoadAsset<AudioClip>("JetpackCriticalBeep");
}
private void OnSceneRelayLoaded(Scene scene, LoadSceneMode loadMode)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0052: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: 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_0103: 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_0151: 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)
if (((Scene)(ref scene)).name == "SampleSceneRelay")
{
GameObject val = GameObject.Find("IngamePlayerHUD");
meterContainer = new GameObject("jetpackMeterContainer");
meterContainer.AddComponent<CanvasGroup>();
RectTransform obj = meterContainer.AddComponent<RectTransform>();
((Transform)obj).parent = val.transform;
((Transform)obj).localScale = Vector3.one;
obj.anchoredPosition = Vector2.zero;
((Transform)obj).localPosition = Vector2.op_Implicit(new Vector2(50f, 0f));
obj.sizeDelta = Vector2.one;
meter = AddImageToHUD("jetpackMeter", scene);
frame = AddImageToHUD("jetpackMeterFrame", scene);
warning = AddImageToHUD("jetpackMeterWarning", scene);
GameObject[] array = (GameObject[])(object)new GameObject[3] { meter, frame, warning };
foreach (GameObject obj2 in array)
{
obj2.transform.parent = meterContainer.transform;
obj2.transform.localPosition = Vector2.op_Implicit(Vector2.zero);
}
meter.GetComponent<Image>().type = (Type)3;
meter.GetComponent<Image>().fillMethod = (FillMethod)1;
Transform transform = warning.transform;
transform.localPosition += new Vector3(30f, 0f);
}
}
private GameObject AddImageToHUD(string imageName, Scene scene)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0024: 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: 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_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Expected O, but got Unknown
Sprite val = Assets.MainAssetBundle.LoadAsset<Sprite>(imageName);
GameObject val2 = new GameObject(imageName);
SceneManager.MoveGameObjectToScene(val2, scene);
GameObject val3 = GameObject.Find("IngamePlayerHUD");
RectTransform obj = val2.AddComponent<RectTransform>();
((Transform)obj).parent = val3.transform;
((Transform)obj).localScale = Vector2.op_Implicit(Vector2.one);
obj.anchoredPosition = Vector2.zero;
((Transform)obj).localPosition = Vector2.op_Implicit(Vector2.zero);
Rect rect = val.rect;
float num = ((Rect)(ref rect)).width / 2f;
rect = val.rect;
obj.sizeDelta = new Vector2(num, ((Rect)(ref rect)).height / 2f);
val2.AddComponent<Image>().sprite = val;
val2.AddComponent<CanvasRenderer>();
return val2;
}
}
internal class Patches
{
private static bool playJetpackCritical = false;
private static bool playingJetpackCritical = false;
private static float criticalFill = 0.75f;
[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
[HarmonyPostfix]
private static void PlayerControllerB_LateUpdate_Postfix(ref PlayerControllerB __instance)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: 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_0240: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)__instance).IsOwner || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject) || !__instance.isPlayerControlled || __instance.isPlayerDead)
{
return;
}
if (__instance.isHoldingObject && __instance.currentlyHeldObjectServer is JetpackItem)
{
JetpackItem val = (JetpackItem)__instance.currentlyHeldObjectServer;
JetpackWarningPlugin.meterContainer.SetActive(true);
Vector3 val2 = (Vector3)typeof(JetpackItem).GetField("forces", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val);
float num = (float)typeof(JetpackItem).GetField("jetpackPower", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val);
float num2 = ((!(num < 80f)) ? (0.5f - Mathf.Clamp(num / 20f - 4f, 0f, 1f) / 2f) : (Mathf.Clamp(num / 25f - 2.2f, 0f, 1f) / 2f));
if (((Vector3)(ref val2)).magnitude > 47f)
{
num2 = Mathf.Clamp(((Vector3)(ref val2)).magnitude / 3f - 15.6666f, 0f, 1f);
}
float num3 = ((((Vector3)(ref val2)).magnitude >= 0f) ? (((Vector3)(ref val2)).magnitude / 50f) : 0f);
float num4 = Mathf.Lerp((((Vector3)(ref val2)).magnitude / 2f + num / 2.25f >= 0f) ? ((((Vector3)(ref val2)).magnitude / 2f + num / 2.25f) / 50f) : 0f, num3, num2);
JetpackWarningPlugin.meter.GetComponent<Image>().fillAmount = num4;
JetpackWarningPlugin.warning.SetActive(num4 > criticalFill);
playJetpackCritical = num4 > criticalFill;
Color color = Color.Lerp(new Color(1f, 0.82f, 0.405f, 1f), new Color(0.769f, 0.243f, 0.243f, 1f), num4);
((Graphic)JetpackWarningPlugin.meter.GetComponent<Image>()).color = color;
((Graphic)JetpackWarningPlugin.frame.GetComponent<Image>()).color = color;
((Graphic)JetpackWarningPlugin.warning.GetComponent<Image>()).color = color;
if (playJetpackCritical)
{
if (!playingJetpackCritical)
{
playingJetpackCritical = true;
val.jetpackBeepsAudio.clip = JetpackWarningPlugin.jetpackCriticalBeep;
val.jetpackBeepsAudio.Play();
}
}
else
{
playingJetpackCritical = false;
}
}
else
{
JetpackWarningPlugin.meterContainer.SetActive(false);
}
}
[HarmonyPatch(typeof(JetpackItem), "SetJetpackAudios")]
[HarmonyPrefix]
private static bool JetpackItem_SetJetpackAudios_Prefix(ref bool ___jetpackActivated, ref AudioSource ___jetpackBeepsAudio)
{
return !playingJetpackCritical;
}
[HarmonyPatch(typeof(JetpackItem), "JetpackEffect")]
[HarmonyPostfix]
private static void JetpackItem_JetpackEffect_Postfix(ref bool __0, JetpackItem __instance)
{
if (__0 && playJetpackCritical)
{
playingJetpackCritical = true;
__instance.jetpackBeepsAudio.clip = JetpackWarningPlugin.jetpackCriticalBeep;
__instance.jetpackBeepsAudio.Play();
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "JetpackWarning";
public const string PLUGIN_NAME = "JetpackWarning";
public const string PLUGIN_VERSION = "2.2.0";
}
}