using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using DeathCam.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
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("DeathCam")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DeathCam")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bbe100ba-3b8f-45a3-bb52-617d99b9e63c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DeathCam
{
[BepInPlugin("rogan.DeathCam", "Death Cam", "1.0.0")]
public class DeathCamBase : BaseUnityPlugin
{
private const string modGUID = "rogan.DeathCam";
private const string modName = "Death Cam";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("rogan.DeathCam");
private static DeathCamBase Instance;
internal static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("rogan.DeathCam");
mls.LogInfo((object)"DeathCam Started!");
harmony.PatchAll(typeof(DeathCamBase));
harmony.PatchAll(typeof(HudPatch));
}
}
}
namespace DeathCam.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class HudPatch
{
public static GameObject MeshModel;
public static GameObject CameraContainer;
public static GameObject MainCamera;
public static GameObject PivotCamera;
public static GameObject SpectateCamera;
public static string PlayerUsername;
public static GameObject CameraHolder;
public static DeadBodyInfo[] DeadMesh;
public static Rigidbody[] bodyParts;
public static int ClientId;
public static bool UpdatedPosition;
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void CameraParentPatch()
{
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null) || !((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null))
{
return;
}
MainCamera = ((Component)StartOfRound.Instance.localPlayerController.gameplayCamera).gameObject;
PivotCamera = ((Component)StartOfRound.Instance.localPlayerController.spectateCameraPivot).gameObject;
SpectateCamera = ((Component)StartOfRound.Instance.spectateCamera).gameObject;
PlayerUsername = GameNetworkManager.Instance.localPlayerController.playerUsername;
MeshModel = ((Component)GameNetworkManager.Instance.localPlayerController.thisPlayerModel).gameObject;
ClientId = (int)GameNetworkManager.Instance.localPlayerController.playerClientId;
if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
return;
}
DeadMesh = Object.FindObjectsOfType<DeadBodyInfo>();
DeadBodyInfo[] deadMesh = DeadMesh;
foreach (DeadBodyInfo val in deadMesh)
{
if (val.playerObjectId != ClientId)
{
continue;
}
bodyParts = val.bodyParts;
Rigidbody[] array = bodyParts;
foreach (Rigidbody val2 in array)
{
if (((Object)val2).name == "spine.004")
{
CameraHolder = ((Component)val2).gameObject;
}
}
if (StartOfRound.Instance.shipIsLeaving)
{
StartOfRound.Instance.overrideSpectateCamera = false;
if (!val.isInShip)
{
SpectateCamera.transform.parent = PivotCamera.transform;
SpectateCamera.transform.position = PivotCamera.transform.position;
}
}
else
{
((TMP_Text)HUDManager.Instance.spectatingPlayerText).text = "";
StartOfRound.Instance.overrideSpectateCamera = true;
}
}
if (!StartOfRound.Instance.shipIsLeaving)
{
SpectateCamera.transform.position = CameraHolder.transform.position;
SpectateCamera.transform.parent = CameraHolder.transform;
SpectateCamera.transform.localPosition = new Vector3(0f, 0f, 0.2f);
SpectateCamera.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
}
}
[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> setAnimationPatch(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && list[i].operand.ToString() == "1.5")
{
list[i].operand = 0f;
}
}
return list;
}
}
}