using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TruckHealPercent.Config;
using TruckHealPercent.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Ezentere")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d08d8c41f6a4f87248b599da5064df0908544002")]
[assembly: AssemblyProduct("TruckHealPercent")]
[assembly: AssemblyTitle("TruckHealPercent")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 TruckHealPercent
{
[BepInPlugin("Ezentere.TruckHealPercent", "Truck Heal Percent", "2.0.0")]
public class TruckHealPercent : BaseUnityPlugin
{
public static ConfigManager configManager;
public static ConfigEntry<int> ConfigHealPercent;
public static int? HealPercent;
internal static TruckHealPercent Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
ConfigHealPercent = ((BaseUnityPlugin)this).Config.Bind<int>("General", "PercentAmount", 25, new ConfigDescription("The percentage of health the truck healer restores to the player.", (AcceptableValueBase)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
HealPercent = ConfigHealPercent.Value;
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.Name} v{((BaseUnityPlugin)this).Info.Metadata.Version} is loading with percent amount: {HealPercent}!");
}
internal void Patch()
{
//IL_0019: 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_0020: Expected O, but got Unknown
//IL_0025: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
Harmony.PatchAll(typeof(PlayerAvatarPatch));
Harmony.PatchAll(typeof(NetworkConnectPatch));
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void Update()
{
}
}
}
namespace TruckHealPercent.Patches
{
[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
internal class NetworkConnectPatch
{
private static void Prefix()
{
PhotonNetwork.AddCallbackTarget((object)TruckHealPercent.configManager);
}
}
[HarmonyPatch(typeof(PlayerAvatar), "FinalHealRPC")]
internal class PlayerAvatarPatch
{
private static readonly FieldInfo FinalHealField = typeof(PlayerAvatar).GetField("finalHeal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static readonly FieldInfo IsLocalField = typeof(PlayerAvatar).GetField("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static readonly FieldInfo PlayerNameField = typeof(PlayerAvatar).GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
[HarmonyPrefix]
private static bool Prefix(PlayerAvatar __instance)
{
if (FinalHealField == null || IsLocalField == null || PlayerNameField == null)
{
TruckHealPercent.Logger.LogError((object)"Failed to reflect fields in PlayerAvatar. Check assembly reference.");
return true;
}
if ((bool)FinalHealField.GetValue(__instance))
{
return true;
}
if ((bool)IsLocalField.GetValue(__instance))
{
if (!TruckHealPercent.HealPercent.HasValue)
{
return true;
}
int value = TruckHealPercent.HealPercent.Value;
object value2 = PlayerNameField.GetValue(__instance);
int num = Mathf.RoundToInt((float)__instance.playerHealth.maxHealth * ((float)value / 100f));
TruckHealPercent.Logger.LogInfo((object)$"Applying custom heal amount: {num} for player: {value2}");
__instance.playerHealth.EyeMaterialOverride((EyeOverrideState)2, 2f, 1);
TruckScreenText.instance.MessageSendCustom("", value2?.ToString() + " {arrowright}{truck}{check}\n {point}{shades}{pointright}<b><color=#00FF00>+" + num + "</color></b>{heart}", 0);
__instance.playerHealth.Heal(num, true);
FinalHealField.SetValue(__instance, true);
}
return false;
}
[HarmonyPostfix]
private static void Postfix(PlayerAvatar __instance)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
TruckHealer.instance.Heal(__instance);
__instance.truckReturn.Play(__instance.PlayerVisionTarget.VisionTransform.position, 1f, 1f, 1f, 1f);
__instance.truckReturnGlobal.Play(__instance.PlayerVisionTarget.VisionTransform.position, 1f, 1f, 1f, 1f);
((Component)__instance.playerAvatarVisuals.effectGetIntoTruck).gameObject.SetActive(true);
}
}
}
namespace TruckHealPercent.Config
{
public class ConfigManager : MonoBehaviourPunCallbacks
{
public override void OnCreatedRoom()
{
if (PhotonNetwork.IsMasterClient)
{
Hashtable customProperties = ((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties;
customProperties[(object)"HealPercent"] = TruckHealPercent.HealPercent;
PhotonNetwork.CurrentRoom.SetCustomProperties(customProperties, (Hashtable)null, (WebFlags)null);
TruckHealPercent.Logger.LogDebug((object)"I'm the host. Add room mod properties.");
}
}
public override void OnJoinedRoom()
{
TruckHealPercent.Logger.LogDebug((object)"Room joined");
if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"HealPercent", out object value))
{
TruckHealPercent.HealPercent = (int)value;
TruckHealPercent.Logger.LogInfo((object)$"Host heal value: {TruckHealPercent.HealPercent}%");
}
else
{
TruckHealPercent.HealPercent = null;
TruckHealPercent.Logger.LogWarning((object)"The host did not send settings for the mod. The healing will work in vanilla mode.");
}
}
public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
{
TruckHealPercent.Logger.LogDebug((object)"Room properties updated");
if (((Dictionary<object, object>)(object)propertiesThatChanged).TryGetValue((object)"HealPercent", out object value))
{
TruckHealPercent.HealPercent = (int)value;
TruckHealPercent.Logger.LogInfo((object)$"Host heal value: {TruckHealPercent.HealPercent}%");
}
else
{
TruckHealPercent.Logger.LogDebug((object)"The host did not send settings for the mod. Just ignore.");
}
}
public override void OnLeftRoom()
{
TruckHealPercent.HealPercent = TruckHealPercent.ConfigHealPercent.Value;
}
public void OnConfigUpdate(object sender, EventArgs e)
{
TruckHealPercent.Logger.LogDebug((object)$"Config updated: {TruckHealPercent.ConfigHealPercent.Value}%");
if (PhotonNetwork.IsMasterClient)
{
Hashtable customProperties = ((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties;
customProperties[(object)"HealPercent"] = TruckHealPercent.ConfigHealPercent.Value;
PhotonNetwork.CurrentRoom.SetCustomProperties(customProperties, (Hashtable)null, (WebFlags)null);
}
}
}
}