2 Commits
1.5.2 ... 1.5.4

Author SHA1 Message Date
mikx
11f6384db6 (1.5.4) KillFeed death icon + Tweaks 2026-02-06 20:36:53 -05:00
mikx
4dcd7504da (1.5.3) Major KillFeed Tweaks/Fix 2026-02-05 22:34:52 -05:00
3 changed files with 107 additions and 73 deletions

View File

@@ -2,8 +2,10 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Threading;
using TMPro;
using UnityEngine;
using UnityEngine.Diagnostics;
using UnityEngine.UI;
@@ -25,6 +27,7 @@ namespace MxValheim.KillFeed
{
ZNet zn = new ZNet();
if (zn.IsDedicated()) return;
if (attacker == "The World") return;
float distance = (encodedType / 1000) / 10.0f;
int remainder = encodedType % 1000;
@@ -42,11 +45,49 @@ namespace MxValheim.KillFeed
if (c != null) localizedVictim = c.m_name;
}
if (attacker == "The World") return;
// Message Format Variables
string type1Separator = " a été tué par ";
string type2Separator = " a tué ";
string finalMsg = "";
string attackerFormat = "";
string victimFormat = "";
string distanceFormat = "";
string starFormat = "";
string crossFormat = "";
// Format Message in Divided Section
starFormat = "<color=#fffb00>★</color>";
crossFormat = "<color=#a0a3a1>✝</color>";
attackerFormat = $"<color=#00ff06>{attacker.ToUpper()}</color>";
if(type == 1)
{
victimFormat = $"{crossFormat} <color=#00ff06>{victim.ToUpper()}</color>";
} else if(type == 2)
{
switch (level)
{
case 1:
victimFormat = $"<color=#00ff06>{victim.ToUpper()}</color>";
break;
case 2:
victimFormat = $"{starFormat} <color=#00ff06>{victim.ToUpper()}</color>";
break;
case 3:
victimFormat = $"{starFormat}{starFormat} <color=#00ff06>{victim.ToUpper()}</color>";
break;
case 4:
victimFormat = $"{starFormat}{starFormat}{starFormat} <color=#00ff06>{victim.ToUpper()}</color>";
break;
case 5:
victimFormat = $"{starFormat}{starFormat}{starFormat}{starFormat} <color=#00ff06>{victim.ToUpper()}</color>";
break;
}
}
distanceFormat = $" à <color=#9402f5>{distance:F1}m</color> de distance.";
string finalMsg = (type == 1) ? $"<color=#FF3333>☠</color> <color=#00ff06>{victim.ToUpper()}</color> a été tué par <color=#ff0000>{attacker.ToUpper()}</color> à <color=#9402f5>{distance:F1}m</color> de distance." :
(type == 2) ? $"<color=#00ff06>{attacker.ToUpper()}</color> a tué <color=#00c0ff>{victim.ToUpper()}</color> à <color=#9402f5>{distance:F1}m</color> de distance." :
$"<color=#00ff06>{attacker.ToUpper()}</color> a tué <color=#00c0ff>{victim.ToUpper()}</color> à <color=#9402f5>{distance:F1}m</color> de distance.";
finalMsg =
(type == 1) ? $"{victimFormat}{type1Separator}{attackerFormat}{distanceFormat}": // Player Death
(type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}": // Player Killed Something
$"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}"; // Failsafe
Sprite weaponIcon = null;
@@ -137,7 +178,8 @@ namespace MxValheim.KillFeed
// List of common trophies that don't follow the exact pattern if needed
// But for most (Boar, Greyling, Neck, Deer), this works:
string trophyName = "Trophy" + cleanName;
string replace = cleanName.Replace("_","");
string trophyName = "Trophy" + replace;
GameObject trophyObj = ObjectDB.instance.GetItemPrefab(trophyName);
if (trophyObj != null)
@@ -349,6 +391,7 @@ namespace MxValheim.KillFeed
_killText.supportRichText = true;
_killText.color = Color.white;
// 4. Victim Portrait Slot
GameObject victimObj = new GameObject("VictimIcon", typeof(RectTransform), typeof(Image));
victimObj.transform.SetParent(panel.transform, false);
@@ -375,72 +418,5 @@ namespace MxValheim.KillFeed
_hudRoot.SetActive(false);
}
/*
public void CreateCustomHud()
{
_hudRoot = new GameObject("MxKillFeed_Root");
UnityEngine.Object.DontDestroyOnLoad(_hudRoot);
Canvas c = _hudRoot.AddComponent<Canvas>();
c.renderMode = RenderMode.ScreenSpaceOverlay;
c.sortingOrder = 10000;
// Add a Scaler to ensure it looks right on all resolutions
CanvasScaler scaler = _hudRoot.AddComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1920, 1080);
_canvasGroup = _hudRoot.AddComponent<CanvasGroup>();
GameObject panel = new GameObject("Background", typeof(RectTransform), typeof(Image));
panel.transform.SetParent(_hudRoot.transform, false);
_panelImage = panel.GetComponent<Image>();
// Fallback: Set a solid color first in case the sprite search fails
_panelImage.color = new Color(0, 0, 0, 0.8f);
foreach (Sprite s in Resources.FindObjectsOfTypeAll<Sprite>())
{
if (s.name == "shout_field")
{
_panelImage.sprite = s;
_panelImage.type = Image.Type.Sliced;
break;
}
}
RectTransform pRect = panel.GetComponent<RectTransform>();
pRect.anchorMin = pRect.anchorMax = pRect.pivot = new Vector2(0.5f, 0.95f);
pRect.anchoredPosition = Vector2.zero; // Center top
pRect.sizeDelta = new Vector2(550, 40);
pRect.localScale = Vector3.one; // FORCE SCALE TO 1
// Icon
GameObject iconObj = new GameObject("Icon", typeof(RectTransform), typeof(Image));
iconObj.transform.SetParent(panel.transform, false);
_weaponIconSlot = iconObj.GetComponent<Image>();
_weaponIconSlot.preserveAspect = true;
RectTransform iRect = iconObj.GetComponent<RectTransform>();
iRect.anchorMin = iRect.anchorMax = iRect.pivot = new Vector2(0, 0.5f);
iRect.anchoredPosition = new Vector2(10, 0);
iRect.sizeDelta = new Vector2(30, 30);
// Text
GameObject textObj = new GameObject("Text", typeof(RectTransform), typeof(Text));
textObj.transform.SetParent(panel.transform, false);
_killText = textObj.GetComponent<Text>();
_killText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
_killText.fontSize = 18;
_killText.alignment = TextAnchor.MiddleLeft;
_killText.supportRichText = true;
textObj.AddComponent<Outline>().effectColor = Color.black;
RectTransform tRect = textObj.GetComponent<RectTransform>();
tRect.anchorMin = Vector2.zero; tRect.anchorMax = Vector2.one;
tRect.offsetMin = new Vector2(50, 0); tRect.offsetMax = new Vector2(-10, 0);
_hudRoot.SetActive(false);
}*/
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MxValheim.Localization
{
internal class KillFeed
{
Dictionary<string, string> killfeedLocales = new Dictionary<string, string>
{
{ " has been killed by ", " a été tué par " },
{ " killed ", " a tué " }
};
}
}

View File

@@ -6,8 +6,10 @@ using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -19,7 +21,7 @@ public class MxValheimMod : BaseUnityPlugin
private const string ModGUID = "ovh.mxdev.mxvalheim";
private const string ModName = "MxValheim";
private const string ModVersion = "1.5.2";
private const string ModVersion = "1.5.4";
public static ConfigEntry<bool> Config_Locked;
public static ConfigEntry<int> Config_OreMultiplier;
@@ -77,6 +79,45 @@ public class MxValheimMod : BaseUnityPlugin
harmony.PatchAll();
}
// --- TEST COMMAND: Type 'testkill' in F5 console ---
[HarmonyPatch(typeof(Terminal), nameof(Terminal.InputText))]
public static class ConsoleInputPatch
{
static void Postfix(Terminal __instance)
{
string text = __instance.m_input.text;
if (text.ToLower() == "listiconsstore")
{
var spriteAsset = Resources.FindObjectsOfTypeAll<TMP_SpriteAsset>().FirstOrDefault(x => x.name == "store_icons"); ;
if (spriteAsset != null)
{
Debug.Log($"--- Listing all sprites in {spriteAsset.name} ---");
for (int i = 0; i < spriteAsset.spriteCharacterTable.Count; i++)
{
var sprite = spriteAsset.spriteCharacterTable[i];
Debug.Log($"Index: {i} | Name: {sprite.name}");
}
}
}
if (text.ToLower() == "listicons")
{
var spriteAsset = Resources.FindObjectsOfTypeAll<TMP_SpriteAsset>().FirstOrDefault(x => x.name == "icons"); ;
if (spriteAsset != null)
{
Debug.Log($"--- Listing all sprites in {spriteAsset.name} ---");
for (int i = 0; i < spriteAsset.spriteCharacterTable.Count; i++)
{
var sprite = spriteAsset.spriteCharacterTable[i];
Debug.Log($"Index: {i} | Name: {sprite.name}");
}
}
}
}
}
[HarmonyPatch(typeof(Game), nameof(Game.Start))]
public static class GameStartPatch
{