using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MyHopefullyKYSRepoMOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("MyHopefullyKYSRepoMOD")]
[assembly: AssemblyCopyright("Copyright © HP 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ef944c74-4cac-48b1-9060-aa93d4c2fe5a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TF2StyleKillFeed;
[BepInPlugin("com.thisismynameyes.TF2StyleKillFeed", "Please work", "1.0.0")]
public class InnerWorksOfTf2Style : BaseUnityPlugin
{
public GameObject killFeedEntryPrefab;
public Canvas killFeedCanvas;
private readonly List<GameObject> killFeedEntries = new List<GameObject>();
public static InnerWorksOfTf2Style Instance { get; private set; }
private void Awake()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Hopefully this works");
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
CreateKillFeedCanvas();
LoadAssetBundle();
Harmony val = new Harmony("com.thisismynameyes.TF2StyleKillFeed");
val.PatchAll();
}
private void CreateKillFeedCanvas()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("KillFeedCanvas");
killFeedCanvas = val.AddComponent<Canvas>();
killFeedCanvas.renderMode = (RenderMode)0;
killFeedCanvas.sortingOrder = 100;
CanvasScaler val2 = val.AddComponent<CanvasScaler>();
val2.uiScaleMode = (ScaleMode)1;
val2.referenceResolution = new Vector2(1920f, 1080f);
val2.screenMatchMode = (ScreenMatchMode)0;
val2.matchWidthOrHeight = 0.5f;
val.AddComponent<GraphicRaycaster>();
Object.DontDestroyOnLoad((Object)(object)val);
}
private void LoadAssetBundle()
{
string text = Path.Combine(Paths.PluginPath, "TF2StyleKillFeed", "final");
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load killfeed asset bundle from path: " + text));
return;
}
killFeedEntryPrefab = val.LoadAsset<GameObject>("assets/killfeedwidgetfinal.prefab");
((BaseUnityPlugin)this).Logger.LogInfo((object)("Asset was loaded at " + text));
if ((Object)(object)killFeedEntryPrefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load the prefab 'KillFeedWidget' from the asset bundle.");
}
}
public void AddKillFeedEntry(string playerName)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)killFeedEntryPrefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Killfeed asset (killFeedEntryPrefab) is null.");
}
if ((Object)(object)killFeedCanvas == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Killfeed canvas (killFeedCanvas) is null, creating one right now");
CreateKillFeedCanvas();
}
if ((Object)(object)killFeedEntryPrefab == (Object)null || (Object)(object)killFeedCanvas == (Object)null)
{
return;
}
GameObject val = Object.Instantiate<GameObject>(killFeedEntryPrefab, ((Component)killFeedCanvas).transform);
val.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>();
if ((Object)(object)componentInChildren != (Object)null)
{
TMP_FontAsset val2 = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
if ((Object)(object)val2 != (Object)null)
{
if ((Object)(object)((TMP_Text)componentInChildren).font == (Object)null || (Object)(object)((TMP_Asset)((TMP_Text)componentInChildren).font).material == (Object)null)
{
((TMP_Text)componentInChildren).font = val2;
((TMP_Text)componentInChildren).fontSharedMaterial = ((TMP_Asset)val2).material;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Fallback TMP font assigned due to null font or material.");
}
else
{
((TMP_Text)componentInChildren).font = val2;
((TMP_Text)componentInChildren).fontSharedMaterial = ((TMP_Asset)val2).material;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Fallback TMP font forcibly assigned from mod Resources.");
}
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load fallback TMP font from mod Resources.");
}
((TMP_Text)componentInChildren).text = playerName;
((TMP_Text)componentInChildren).fontSize = 64f;
((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Set player name on killfeed entry: " + ((TMP_Text)componentInChildren).text));
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"TextMeshProUGUI component not found in the killfeed prefab.");
}
killFeedEntries.Insert(0, val);
RepositionEntries();
Object.Destroy((Object)(object)val, 6f);
}
private void RepositionEntries()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
killFeedEntries.RemoveAll((GameObject item) => (Object)(object)item == (Object)null);
float num = 0f;
float num2 = 50f;
foreach (GameObject killFeedEntry in killFeedEntries)
{
RectTransform component = killFeedEntry.GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
component.anchorMin = new Vector2(1f, 1f);
component.anchorMax = new Vector2(1f, 1f);
component.pivot = new Vector2(1f, 1f);
component.anchoredPosition = new Vector2(-400f, -75f - num);
num += num2;
}
}
}
}
[HarmonyPatch(typeof(PlayerAvatar), "PlayerDeathRPC")]
public class PlayerDeathRPCPatch
{
private static void Postfix(PlayerAvatar __instance, int enemyIndex)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerAvatar), "playerName");
string text = (string)fieldInfo.GetValue(__instance);
Debug.Log((object)$"[HarmonyPatch] PlayerDeathRPC called for player: {text}, enemyIndex: {enemyIndex}");
InnerWorksOfTf2Style.Instance.AddKillFeedEntry(text);
}
}