using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterTruckHeals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterTruckHeals")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("819aea69-b910-4066-83d4-ca334402331c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterTruckHeals;
[BepInPlugin("Lazarus.BetterTruckHeals", "Better Truck Heals", "2.1.4")]
public class BetterTruckHeals : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayerAvatar), "FinalHealRPC")]
public 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);
private static readonly FieldInfo MaxHealthField = typeof(PlayerHealth).GetField("maxHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
[HarmonyPrefix]
private static bool Prefix(PlayerAvatar __instance)
{
if (FinalHealField == null || IsLocalField == null || PlayerNameField == null)
{
ModLogger.LogError((object)"Failed to reflect fields in PlayerAvatar. Check assembly reference.");
return true;
}
if (MaxHealthField == null && UsePercentageHealConfig.Value)
{
ModLogger.LogError((object)"Failed to reflect 'maxHealth' field in PlayerHealth. Skipping custom heal.");
return true;
}
if ((bool)FinalHealField.GetValue(__instance))
{
return true;
}
if ((bool)IsLocalField.GetValue(__instance))
{
string text = (string)PlayerNameField.GetValue(__instance);
int val;
if (UsePercentageHealConfig.Value)
{
int num = (int)MaxHealthField.GetValue(__instance.playerHealth);
if (num <= 0)
{
ModLogger.LogError((object)$"Invalid maxHealth value ({num}) retrieved for player: {text}. Skipping custom heal.");
return true;
}
ModLogger.LogInfo((object)$"Retrieved maxHealth: {num} for player: {text}");
val = (int)((float)num * HealPercentageConfig.Value);
val = Math.Max(1, val);
ModLogger.LogInfo((object)$"Applying percentage heal: {val} ({HealPercentageConfig.Value * 100f}% of max health {num}) for player: {text}");
}
else
{
val = HealAmountConfig.Value;
ModLogger.LogInfo((object)$"Applying fixed heal amount: {val} for player: {text}");
}
__instance.playerHealth.EyeMaterialOverride((EyeOverrideState)2, 2f, 1);
TruckScreenText.instance.MessageSendCustom("", text + " {arrowright}{truck}{check}\n {point}{shades}{pointright}<b><color=#00FF00>+" + val + "</color></b>{heart}", 0);
__instance.playerHealth.Heal(val, true);
FinalHealField.SetValue(__instance, true);
}
return false;
}
[HarmonyPostfix]
private static void Postfix(PlayerAvatar __instance)
{
//IL_001e: 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)
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);
}
}
private const string PluginGUID = "Lazarus.BetterTruckHeals";
private const string PluginName = "Better Truck Heals";
private const string PluginVersion = "2.1.4";
public static ConfigEntry<int> HealAmountConfig;
public static ConfigEntry<bool> UsePercentageHealConfig;
public static ConfigEntry<float> HealPercentageConfig;
internal static ManualLogSource ModLogger;
private void Awake()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"John 11:11!");
((BaseUnityPlugin)this).Logger.LogInfo((object)"WAKEY WAKEY!");
((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterTruckHeals has risen!");
HealAmountConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "HealAmount", 50, new ConfigDescription("The amount of health the truck healer restores to the player when UsePercentageHeal is false.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200), Array.Empty<object>()));
UsePercentageHealConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsePercentageHeal", false, "If true, heals a percentage of the player's max health. If false, heals a fixed amount.");
HealPercentageConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HealPercentage", 0.5f, new ConfigDescription("The percentage of max health to restore when UsePercentageHeal is true (e.g., 0.5 = 50%, 2.0 = 200%).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
ModLogger = ((BaseUnityPlugin)this).Logger;
ModLogger.LogInfo((object)("Better Truck Heals v2.1.4 is loading with heal settings: " + $"Fixed Amount = {HealAmountConfig.Value}, " + $"Use Percentage = {UsePercentageHealConfig.Value}, " + $"Percentage = {HealPercentageConfig.Value * 100f}%"));
Harmony val = new Harmony("Lazarus.BetterTruckHeals");
val.PatchAll();
ModLogger.LogInfo((object)"Harmony patches applied successfully!");
}
}