using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; 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: AssemblyCompany("RepoDefibroMod")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RepoDefibroMod")] [assembly: AssemblyTitle("RepoDefibroMod")] [assembly: AssemblyVersion("1.0.0.0")] 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; } } } namespace RepoDefibroMod { [BepInPlugin("com.oliver.repodefibromod", "Defibro Battery Mod", "1.9.0")] public class DefibroPlugin : BaseUnityPlugin { private readonly Harmony harmony = new Harmony("com.oliver.repodefibromod"); private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Defibro Battery Mod loaded - Truck Charging Crash Fixed!"); harmony.PatchAll(); } } internal static class Ref { public static void Invoke(object instance, string methodName, params object[] providedArgs) { if (instance == null) { return; } MethodInfo methodInfo = AccessTools.Method(instance.GetType(), methodName, (Type[])null, (Type[])null); if (methodInfo == null) { return; } ParameterInfo[] parameters = methodInfo.GetParameters(); object[] array = new object[parameters.Length]; if (providedArgs == null) { providedArgs = new object[1]; } for (int i = 0; i < parameters.Length; i++) { if (i < providedArgs.Length) { array[i] = providedArgs[i]; } else if (parameters[i].HasDefaultValue) { array[i] = parameters[i].DefaultValue; } else { array[i] = Type.Missing; } } methodInfo.Invoke(instance, array); } } public class DefibroStabilizer : MonoBehaviour { private Rigidbody rb; private float timer = 0.5f; private void Start() { rb = ((Component)this).GetComponent(); if ((Object)(object)rb != (Object)null) { rb.isKinematic = true; } } private void Update() { timer -= Time.deltaTime; if (timer <= 0f) { if ((Object)(object)rb != (Object)null) { rb.isKinematic = false; } Object.Destroy((Object)(object)this); } } } [HarmonyPatch(typeof(ItemReviveItem), "Start")] public class DefibroStartPatch { [HarmonyPostfix] public static void Postfix(ItemReviveItem __instance) { ItemBattery val = ((Component)__instance).gameObject.GetComponent(); if ((Object)(object)val == (Object)null) { val = ((Component)__instance).gameObject.AddComponent(); } val.batteryBars = 2; val.hasBatteryVisuals = false; val.isUnchargable = false; val.autoDrain = false; } } [HarmonyPatch(typeof(ItemReviveItem), "UpdatePlayerTarget")] public class PreventTargetingIfEmptyPatch { [HarmonyPrefix] public static bool Prefix(ItemReviveItem __instance, PlayerAvatar _player) { if ((Object)(object)_player != (Object)null) { ItemBattery component = ((Component)__instance).GetComponent(); if ((Object)(object)component != (Object)null) { FieldInfo fieldInfo = AccessTools.Field(typeof(ItemBattery), "batteryLife"); if (fieldInfo != null && (float)fieldInfo.GetValue(component) <= 0f) { return false; } } } return true; } } [HarmonyPatch(typeof(ItemReviveItem), "ReviveAndDestroy")] public class DefibroRevivePatch { [HarmonyPrefix] public static bool Prefix(ItemReviveItem __instance, bool _failSafe) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Expected O, but got Unknown //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.IsMasterClientOrSingleplayer()) { FieldInfo fieldInfo = AccessTools.Field(typeof(ItemReviveItem), "playerTarget"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(ItemReviveItem), "hasTarget"); if (fieldInfo == null || fieldInfo2 == null) { return false; } PlayerAvatar val = (PlayerAvatar)fieldInfo.GetValue(__instance); if ((bool)fieldInfo2.GetValue(__instance) && (Object)(object)val != (Object)null) { if ((Object)(object)((Component)__instance).gameObject.GetComponent() == (Object)null) { ((Component)__instance).gameObject.AddComponent(); } Ref.Invoke(__instance, "ReviveParticles"); Ref.Invoke(__instance, "ReviveScreenEffectSpawn"); Ref.Invoke(val, "Revive"); FieldInfo fieldInfo3 = AccessTools.Field(((object)val).GetType(), "playerHealth"); if (fieldInfo3 != null) { object value = fieldInfo3.GetValue(val); if (value != null) { Ref.Invoke(value, "HealOther", 49, true); } } ItemBattery component = ((Component)__instance).GetComponent(); if ((Object)(object)component != (Object)null) { FieldInfo fieldInfo4 = AccessTools.Field(typeof(ItemBattery), "batteryLife"); FieldInfo fieldInfo5 = AccessTools.Field(typeof(ItemBattery), "batteryLifeInt"); if (fieldInfo4 != null && fieldInfo5 != null) { float num = (float)fieldInfo4.GetValue(component); int num2 = (int)fieldInfo5.GetValue(component); fieldInfo4.SetValue(component, Mathf.Max(0f, num - 50f)); Ref.Invoke(component, "BatteryFullPercentChange", num2 - 1, false); } } if (_failSafe && (Object)(object)TruckSafetySpawnPoint.instance != (Object)null) { FieldInfo fieldInfo6 = AccessTools.Field(((object)val).GetType(), "tumble"); if (fieldInfo6 != null) { object value2 = fieldInfo6.GetValue(val); if (value2 != null) { Ref.Invoke(value2, "TumbleSet", true, false); FieldInfo fieldInfo7 = AccessTools.Field(value2.GetType(), "physGrabObject"); if (fieldInfo7 != null) { PhysGrabObject val2 = (PhysGrabObject)fieldInfo7.GetValue(value2); if ((Object)(object)val2 != (Object)null) { val2.Teleport(((Component)TruckSafetySpawnPoint.instance).transform.position, ((Component)TruckSafetySpawnPoint.instance).transform.rotation); if (!val2.rb.isKinematic) { val2.rb.velocity = Vector3.zero; val2.rb.angularVelocity = Vector3.zero; } } } } } } Ref.Invoke(__instance, "UpdatePlayerTarget", new object[1]); } } return false; } } [HarmonyPatch(typeof(ItemReviveItem), "Update")] public class DefibroUpdateSafeguardPatch { [HarmonyPrefix] public static void Prefix(ItemReviveItem __instance) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown FieldInfo fieldInfo = AccessTools.Field(typeof(ItemReviveItem), "playerTarget"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(ItemReviveItem), "hasTarget"); if (fieldInfo == null || fieldInfo2 == null) { return; } bool num = (bool)fieldInfo2.GetValue(__instance); PlayerAvatar val = (PlayerAvatar)fieldInfo.GetValue(__instance); ItemBattery component = ((Component)__instance).GetComponent(); if (!num) { return; } if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null) { fieldInfo2.SetValue(__instance, false); fieldInfo.SetValue(__instance, null); } else if ((Object)(object)component != (Object)null) { FieldInfo fieldInfo3 = AccessTools.Field(typeof(ItemBattery), "batteryLife"); if (fieldInfo3 != null && (float)fieldInfo3.GetValue(component) <= 0f) { Ref.Invoke(__instance, "UpdatePlayerTarget", new object[1]); } } } } [HarmonyPatch(typeof(ItemBattery), "Update")] public class SuppressBatteryUpdateCrashPatch { [HarmonyFinalizer] public static Exception Finalizer(Exception __exception, ItemBattery __instance) { if (__exception != null && (Object)(object)((Component)__instance).gameObject.GetComponent() != (Object)null) { return null; } return __exception; } } }