using System; using System.Collections; 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 HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Omniscye")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RespawnInTruck")] [assembly: AssemblyTitle("RespawnInTruck")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 RespawnInTruck { public class RespawnInTruck : BaseUnityPlugin { internal static RespawnInTruck Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { } internal void Patch() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { } } } namespace Empress.Repo.RespawnInTruck { [BepInPlugin("com.truckalwaysspawn.repo", "TruckAlwaysSpawn", "1.0.0")] public class RespawnInTruckPlugin : BaseUnityPlugin { public const string GUID = "com.truckalwaysspawn.repo"; public const string Name = "TruckAlwaysSpawn"; public const string Version = "1.0.0"; internal static RespawnInTruckPlugin Instance; internal static Harmony Harmony; internal static ManualLogSource Log; private ConfigEntry _enabled; private ConfigEntry _respawnDelay; internal static readonly HashSet Scheduled = new HashSet(); private void Awake() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; _enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "If true, dead players are revived in the truck (master-controlled)."); _respawnDelay = ((BaseUnityPlugin)this).Config.Bind("General", "RespawnDelay", 3f, "Real-time delay after death before reviving (seconds)."); Harmony = new Harmony("com.truckalwaysspawn.repo"); Harmony.PatchAll(); Log.LogInfo((object)string.Format("[{0}] v{1} loaded. Enabled={2}, Delay={3:F2}s", "RespawnInTruck", "2.0.0", _enabled.Value, _respawnDelay.Value)); } private void OnDestroy() { Harmony harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Scheduled.Clear(); } internal bool FeatureEnabledForThisClient() { return _enabled.Value; } internal IEnumerator ReviveAfterDelay(PlayerAvatar avatar, int actorNr) { float wait = Mathf.Max(0f, _respawnDelay.Value); if (wait > 0f) { yield return (object)new WaitForSecondsRealtime(wait); } float t = 0f; while ((Object)(object)avatar != (Object)null && (Object)(object)avatar.playerDeathHead == (Object)null && t < 2f) { t += Time.unscaledDeltaTime; yield return null; } if ((Object)(object)avatar == (Object)null) { Scheduled.Remove(actorNr); yield break; } if ((Object)(object)avatar.playerDeathHead == (Object)null) { Log.LogWarning((object)string.Format("[{0}] Death head missing for actor {1}; postponing revive by 0.25s", "RespawnInTruck", actorNr)); yield return (object)new WaitForSecondsRealtime(0.25f); } try { avatar.Revive(true); Log.LogDebug((object)string.Format("[{0}] Revive(true) sent for actor {1} after {2:F2}s", "RespawnInTruck", actorNr, wait)); } catch (Exception ex) { Exception ex2 = ex; Log.LogError((object)string.Format("[{0}] Revive call failed for actor {1}: {2}", "RespawnInTruck", actorNr, ex2)); } finally { Scheduled.Remove(actorNr); } } internal static bool TryGetTruckSpawn(out Vector3 pos, out Quaternion rot) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //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_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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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) //IL_011d: 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) pos = Vector3.zero; rot = Quaternion.identity; if ((Object)(object)TruckSafetySpawnPoint.instance != (Object)null) { Transform transform = ((Component)TruckSafetySpawnPoint.instance).transform; SpawnPoint[] componentsInChildren = ((Component)transform).GetComponentsInChildren(false); if (componentsInChildren != null && componentsInChildren.Length != 0) { pos = ((Component)componentsInChildren[0]).transform.position; rot = ((Component)componentsInChildren[0]).transform.rotation; return true; } pos = transform.position; rot = transform.rotation; return true; } if ((Object)(object)LevelGenerator.Instance != (Object)null && (Object)(object)LevelGenerator.Instance.LevelPathTruck != (Object)null) { Transform transform2 = ((Component)LevelGenerator.Instance.LevelPathTruck).transform; pos = transform2.position; rot = transform2.rotation; return true; } if ((Object)(object)TruckHealer.instance != (Object)null) { Transform transform3 = ((Component)TruckHealer.instance).transform; pos = transform3.position; rot = transform3.rotation; return true; } return false; } internal static bool GetTruckSpawnFor(PlayerAvatar avatar, out Vector3 pos, out Quaternion rot) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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) pos = Vector3.zero; rot = Quaternion.identity; if ((Object)(object)TruckSafetySpawnPoint.instance != (Object)null) { Transform transform = ((Component)TruckSafetySpawnPoint.instance).transform; List list = new List(); try { SpawnPoint[] componentsInChildren = ((Component)transform).GetComponentsInChildren(false); if (componentsInChildren != null && componentsInChildren.Length != 0) { SpawnPoint[] array = componentsInChildren; foreach (SpawnPoint val in array) { if (Object.op_Implicit((Object)(object)val)) { list.Add(((Component)val).transform); } } } } catch { } if (list.Count == 0) { list.Add(transform); } int num = 0; try { num = (((Object)(object)avatar?.photonView != (Object)null) ? avatar.photonView.OwnerActorNr : ((Object)avatar).GetInstanceID()); } catch { num = (((Object)(object)avatar != (Object)null) ? ((Object)avatar).GetInstanceID() : 0); } int index = ((list.Count > 0) ? (Mathf.Abs(num) % list.Count) : 0); Transform val2 = list[index]; if (Object.op_Implicit((Object)(object)val2)) { pos = val2.position; rot = val2.rotation; return true; } } return TryGetTruckSpawn(out pos, out rot); } internal static Vector3 SpreadOffsetFor(PlayerAvatar avatar) { //IL_006d: 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_0075: Unknown result type (might be due to invalid IL or missing references) int num = 0; try { num = (((Object)(object)avatar?.photonView != (Object)null) ? avatar.photonView.OwnerActorNr : ((Object)avatar).GetInstanceID()); } catch { num = (((Object)(object)avatar != (Object)null) ? ((Object)avatar).GetInstanceID() : 0); } float num2 = 0.6f; float num3 = (float)(num % 8) * (MathF.PI / 4f); return new Vector3(Mathf.Cos(num3) * num2, 0f, Mathf.Sin(num3) * num2); } } [HarmonyPatch(typeof(PlayerAvatar))] internal static class PlayerAvatar_TruckRespawn_Patches { [HarmonyPostfix] [HarmonyPatch("PlayerDeathRPC")] private static void Post_PlayerDeathRPC(PlayerAvatar __instance, int enemyIndex, PhotonMessageInfo _info) { RespawnInTruckPlugin instance = RespawnInTruckPlugin.Instance; if ((Object)(object)instance == (Object)null || !instance.FeatureEnabledForThisClient()) { /*Error near IL_0020: Invalid branch target*/; } bool num = PhotonNetwork.IsMasterClient; if (!num) { num = !PhotonNetwork.InRoom; } if (num && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.photonView == (Object)null)) { int num2 = __instance.photonView.OwnerActorNr; if (num2 <= 0) { num2 = 1; } if (num2 > 0 && RespawnInTruckPlugin.Scheduled.Add(num2)) { ((MonoBehaviour)instance).StartCoroutine(instance.ReviveAfterDelay(__instance, num2)); } } } [HarmonyPostfix] [HarmonyPatch("ReviveRPC")] private static void Post_ReviveRPC(PlayerAvatar __instance, bool _revivedByTruck, PhotonMessageInfo _info) { RespawnInTruckPlugin instance = RespawnInTruckPlugin.Instance; if ((Object)(object)instance == (Object)null || !instance.FeatureEnabledForThisClient() || !_revivedByTruck) { return; } try { if ((Object)(object)__instance.photonView != (Object)null && PhotonNetwork.InRoom && !__instance.photonView.IsMine) { return; } } catch { } ((MonoBehaviour)instance).StartCoroutine(OwnerMoveAfterRevive(__instance)); } private static IEnumerator OwnerMoveAfterRevive(PlayerAvatar avatar) { yield return null; yield return (object)new WaitForSeconds(0.05f); if (!RespawnInTruckPlugin.TryGetTruckSpawn(out var basePos, out var baseRot)) { yield break; } if (!RespawnInTruckPlugin.GetTruckSpawnFor(avatar, out var finalPos, out var finalRot)) { finalPos = basePos + RespawnInTruckPlugin.SpreadOffsetFor(avatar); finalRot = baseRot; } Vector3 probe = finalPos + Vector3.up * 2f; RaycastHit hit = default(RaycastHit); finalPos = ((!Physics.Raycast(probe, Vector3.down, ref hit, 5f)) ? (finalPos + Vector3.up * 0.1f) : (((RaycastHit)(ref hit)).point + Vector3.up * 0.05f)); try { ((Component)avatar).transform.SetPositionAndRotation(finalPos, finalRot); if ((Object)(object)avatar.playerTransform != (Object)null) { avatar.playerTransform.position = finalPos; } if ((Object)(object)avatar.playerAvatarVisuals != (Object)null) { ((Component)avatar.playerAvatarVisuals).transform.position = finalPos; } try { avatar.FallDamageResetSet(2f); } catch { } } catch (Exception arg) { RespawnInTruckPlugin.Log.LogError((object)string.Format("[{0}] Owner teleport failed: {1}", "RespawnInTruck", arg)); } } } }