Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
685
JotunnModStub/RacesOfValheim.cs
Normal file
685
JotunnModStub/RacesOfValheim.cs
Normal file
|
|
@ -0,0 +1,685 @@
|
|||
using System.Collections;
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // Added for UI
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
|
||||
[BepInDependency(Jotunn.Main.ModGuid)]
|
||||
public class RacesOfValheim : BaseUnityPlugin
|
||||
{
|
||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||
public const string PluginName = "Races Of Valheim";
|
||||
public const string PluginVersion = "1.3.2";
|
||||
|
||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||
|
||||
public static RacesOfValheim Instance;
|
||||
private GameObject raceSelectionMenu;
|
||||
|
||||
private void Awake() {
|
||||
Instance = this;
|
||||
harmony.PatchAll();
|
||||
gameObject.AddComponent<FenrirRace>();
|
||||
gameObject.AddComponent<SkadiRace>();
|
||||
gameObject.AddComponent<SkeletonRace>();
|
||||
gameObject.AddComponent<AswidRace>();
|
||||
gameObject.AddComponent<FurlingRace>();
|
||||
gameObject.AddComponent<TrolRace>();
|
||||
PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets;
|
||||
CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new IncreaseProgressionCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
|
||||
}
|
||||
|
||||
private void CreateAllModAssets() {
|
||||
PrefabManager.OnVanillaPrefabsAvailable -= CreateAllModAssets;
|
||||
FenrirRace.Instance.CreateModAssets();
|
||||
SkadiRace.Instance.CreateModAssets();
|
||||
SkeletonRace.Instance.CreateModAssets();
|
||||
AswidRace.Instance.CreateModAssets();
|
||||
FurlingRace.Instance.CreateModAssets();
|
||||
TrolRace.Instance.CreateModAssets();
|
||||
}
|
||||
// --- RACE SELECTION UI ---
|
||||
public void ShowRaceSelectionMenu()
|
||||
{
|
||||
if (raceSelectionMenu != null) return;
|
||||
if (GUIManager.Instance == null || GUIManager.CustomGUIFront == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("GUIManager.CustomGUIFront is null, cannot show race menu.");
|
||||
return;
|
||||
}
|
||||
|
||||
raceSelectionMenu = new GameObject("RaceSelectionMenu");
|
||||
raceSelectionMenu.transform.SetParent(GUIManager.CustomGUIFront.transform, false);
|
||||
|
||||
RectTransform rect = raceSelectionMenu.AddComponent<RectTransform>();
|
||||
rect.anchorMin = new Vector2(0, 0);
|
||||
rect.anchorMax = new Vector2(1, 1);
|
||||
rect.offsetMin = Vector2.zero;
|
||||
rect.offsetMax = Vector2.zero;
|
||||
|
||||
Image bg = raceSelectionMenu.AddComponent<Image>();
|
||||
bg.color = new Color(0, 0, 0, 0.9f);
|
||||
|
||||
GameObject selectionPanel = new GameObject("SelectionPanel");
|
||||
selectionPanel.transform.SetParent(raceSelectionMenu.transform, false);
|
||||
RectTransform spRect = selectionPanel.AddComponent<RectTransform>();
|
||||
spRect.anchorMin = Vector2.zero; spRect.anchorMax = Vector2.one;
|
||||
spRect.offsetMin = Vector2.zero; spRect.offsetMax = Vector2.zero;
|
||||
|
||||
GameObject confirmationPanel = new GameObject("ConfirmationPanel");
|
||||
confirmationPanel.transform.SetParent(raceSelectionMenu.transform, false);
|
||||
RectTransform cpRect = confirmationPanel.AddComponent<RectTransform>();
|
||||
cpRect.anchorMin = Vector2.zero; cpRect.anchorMax = Vector2.one;
|
||||
cpRect.offsetMin = Vector2.zero; cpRect.offsetMax = Vector2.zero;
|
||||
confirmationPanel.SetActive(false);
|
||||
|
||||
GameObject titleObj = new GameObject("Title");
|
||||
titleObj.transform.SetParent(selectionPanel.transform, false);
|
||||
Text titleText = titleObj.AddComponent<Text>();
|
||||
titleText.font = GUIManager.Instance.AveriaSerifBold;
|
||||
titleText.text = "Choose your Race";
|
||||
titleText.fontSize = 50;
|
||||
titleText.alignment = TextAnchor.MiddleCenter;
|
||||
titleText.color = Color.white;
|
||||
RectTransform titleRect = titleObj.GetComponent<RectTransform>();
|
||||
titleRect.anchoredPosition = new Vector2(0, 200);
|
||||
titleRect.sizeDelta = new Vector2(600, 100);
|
||||
|
||||
GameObject confTitleObj = new GameObject("ConfTitle");
|
||||
confTitleObj.transform.SetParent(confirmationPanel.transform, false);
|
||||
Text confTitleText = confTitleObj.AddComponent<Text>();
|
||||
confTitleText.font = GUIManager.Instance.AveriaSerifBold;
|
||||
confTitleText.fontSize = 50;
|
||||
confTitleText.alignment = TextAnchor.MiddleCenter;
|
||||
confTitleText.color = Color.white;
|
||||
RectTransform confTitleRect = confTitleObj.GetComponent<RectTransform>();
|
||||
confTitleRect.anchoredPosition = new Vector2(0, 150);
|
||||
confTitleRect.sizeDelta = new Vector2(600, 100);
|
||||
|
||||
GameObject confDescObj = new GameObject("ConfDesc");
|
||||
confDescObj.transform.SetParent(confirmationPanel.transform, false);
|
||||
Text confDescText = confDescObj.AddComponent<Text>();
|
||||
confDescText.font = GUIManager.Instance.AveriaSerifBold;
|
||||
confDescText.fontSize = 24;
|
||||
confDescText.alignment = TextAnchor.MiddleCenter;
|
||||
confDescText.color = Color.white;
|
||||
RectTransform confDescRect = confDescObj.GetComponent<RectTransform>();
|
||||
confDescRect.anchoredPosition = new Vector2(0, 0);
|
||||
confDescRect.sizeDelta = new Vector2(800, 200);
|
||||
|
||||
GameObject btnOkObj = new GameObject("OkButton");
|
||||
btnOkObj.transform.SetParent(confirmationPanel.transform, false);
|
||||
RectTransform btnOkRect = btnOkObj.AddComponent<RectTransform>();
|
||||
btnOkRect.sizeDelta = new Vector2(200, 60);
|
||||
btnOkRect.anchoredPosition = new Vector2(120, -150);
|
||||
Image btnOkImg = btnOkObj.AddComponent<Image>();
|
||||
btnOkImg.color = new Color(0.2f, 0.5f, 0.2f, 1f);
|
||||
Button btnOk = btnOkObj.AddComponent<Button>();
|
||||
|
||||
GameObject btnOkTxtObj = new GameObject("Text");
|
||||
btnOkTxtObj.transform.SetParent(btnOkObj.transform, false);
|
||||
Text btnOkTxt = btnOkTxtObj.AddComponent<Text>();
|
||||
btnOkTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnOkTxt.text = "OK";
|
||||
btnOkTxt.fontSize = 24;
|
||||
btnOkTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnOkTxt.color = Color.white;
|
||||
RectTransform btnOkTxtRect = btnOkTxtObj.GetComponent<RectTransform>();
|
||||
btnOkTxtRect.anchorMin = Vector2.zero; btnOkTxtRect.anchorMax = Vector2.one;
|
||||
btnOkTxtRect.offsetMin = Vector2.zero; btnOkTxtRect.offsetMax = Vector2.zero;
|
||||
|
||||
GameObject btnBackObj = new GameObject("BackButton");
|
||||
btnBackObj.transform.SetParent(confirmationPanel.transform, false);
|
||||
RectTransform btnBackRect = btnBackObj.AddComponent<RectTransform>();
|
||||
btnBackRect.sizeDelta = new Vector2(200, 60);
|
||||
btnBackRect.anchoredPosition = new Vector2(-120, -150);
|
||||
Image btnBackImg = btnBackObj.AddComponent<Image>();
|
||||
btnBackImg.color = new Color(0.5f, 0.2f, 0.2f, 1f);
|
||||
Button btnBack = btnBackObj.AddComponent<Button>();
|
||||
btnBack.onClick.AddListener(() => {
|
||||
confirmationPanel.SetActive(false);
|
||||
selectionPanel.SetActive(true);
|
||||
});
|
||||
|
||||
GameObject btnBackTxtObj = new GameObject("Text");
|
||||
btnBackTxtObj.transform.SetParent(btnBackObj.transform, false);
|
||||
Text btnBackTxt = btnBackTxtObj.AddComponent<Text>();
|
||||
btnBackTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnBackTxt.text = "Back";
|
||||
btnBackTxt.fontSize = 24;
|
||||
btnBackTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnBackTxt.color = Color.white;
|
||||
RectTransform btnBackTxtRect = btnBackTxtObj.GetComponent<RectTransform>();
|
||||
btnBackTxtRect.anchorMin = Vector2.zero; btnBackTxtRect.anchorMax = Vector2.one;
|
||||
btnBackTxtRect.offsetMin = Vector2.zero; btnBackTxtRect.offsetMax = Vector2.zero;
|
||||
|
||||
void CreateRaceButtonWithConfirm(string label, Vector2 position, Sprite iconSprite, string description, UnityEngine.Events.UnityAction onConfirm)
|
||||
{
|
||||
CreateRaceButton(label, position, iconSprite, selectionPanel.transform, () => {
|
||||
selectionPanel.SetActive(false);
|
||||
confirmationPanel.SetActive(true);
|
||||
confTitleText.text = label;
|
||||
confDescText.text = description;
|
||||
btnOk.onClick.RemoveAllListeners();
|
||||
btnOk.onClick.AddListener(onConfirm);
|
||||
});
|
||||
}
|
||||
|
||||
// Row 1 (y = 100)
|
||||
CreateRaceButtonWithConfirm("Human", new Vector2(-300, 100), GetHumanIcon(), "The versatile founders of Midgard. Balanced stats with no specific weaknesses.", SelectHuman);
|
||||
CreateRaceButtonWithConfirm("Fenrir", new Vector2(0, 100), GetFenrirIcon(), "Cursed by the blood of the wolf. Fast and deadly, but vulnerable to silver.", SelectFenrir);
|
||||
CreateRaceButtonWithConfirm("Skadi", new Vector2(300, 100), GetSkadiIcon(), "Children of the mountains. Resistant to frost, at home in the freezing cold.", SelectSkadi);
|
||||
|
||||
// Row 2 (y = 0)
|
||||
CreateRaceButtonWithConfirm("Skeleton", new Vector2(-300, 0), GetSkeletonIcon(), "Undead warriors. Immune to poison, but brittle against blunt trauma.", SelectSkeleton);
|
||||
CreateRaceButtonWithConfirm("Aswid", new Vector2(0, 0), GetAswidIcon(), "Fierce night stalker. Strong and resilient, transforms into a bat.", SelectAswid);
|
||||
CreateRaceButtonWithConfirm("Furling", new Vector2(300, 0), GetFurlingIcon(), "Cunning goblin-like creatures. Agile and resourceful.", SelectFurling);
|
||||
|
||||
// Row 3 (y = -100)
|
||||
CreateRaceButtonWithConfirm("Trol", new Vector2(0, -100), GetTrolIcon(), "Massive brute strength. Towering over others but slow to react.", SelectTrol);
|
||||
|
||||
GUIManager.BlockInput(true);
|
||||
}
|
||||
|
||||
private Sprite GetHumanIcon()
|
||||
{
|
||||
GameObject clubPrefab = PrefabManager.Cache.GetPrefab<ItemDrop>("Club")?.gameObject;
|
||||
if (clubPrefab != null)
|
||||
{
|
||||
ItemDrop clubDrop = clubPrefab.GetComponent<ItemDrop>();
|
||||
if (clubDrop != null && clubDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return clubDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Sprite GetFenrirIcon()
|
||||
{
|
||||
GameObject fenringTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyFenring")?.gameObject;
|
||||
if (fenringTrophy != null)
|
||||
{
|
||||
ItemDrop trophyDrop = fenringTrophy.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Sprite GetSkadiIcon()
|
||||
{
|
||||
GameObject drakeTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyHatchling")?.gameObject;
|
||||
if (drakeTrophy != null)
|
||||
{
|
||||
ItemDrop trophyDrop = drakeTrophy.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Sprite GetSkeletonIcon()
|
||||
{
|
||||
GameObject skelTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySkeleton")?.gameObject;
|
||||
if (skelTrophy != null)
|
||||
{
|
||||
ItemDrop trophyDrop = skelTrophy.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Sprite GetAswidIcon()
|
||||
{
|
||||
GameObject aswidTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith")?.gameObject;
|
||||
if (aswidTrophy != null)
|
||||
{
|
||||
ItemDrop trophyDrop = aswidTrophy.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void CreateRaceButton(string label, Vector2 position, Sprite iconSprite, Transform parentTransform, UnityEngine.Events.UnityAction onClick)
|
||||
{
|
||||
GameObject btnObj = new GameObject(label + "Button");
|
||||
btnObj.transform.SetParent(parentTransform, false);
|
||||
RectTransform btnRect = btnObj.AddComponent<RectTransform>();
|
||||
btnRect.sizeDelta = new Vector2(250, 80);
|
||||
btnRect.anchoredPosition = position;
|
||||
|
||||
Image btnImg = btnObj.AddComponent<Image>();
|
||||
btnImg.color = new Color(0.2f, 0.2f, 0.2f, 1f);
|
||||
|
||||
Button btn = btnObj.AddComponent<Button>();
|
||||
btn.onClick.AddListener(onClick);
|
||||
|
||||
GameObject txtObj = new GameObject("Text");
|
||||
txtObj.transform.SetParent(btnObj.transform, false);
|
||||
Text txt = txtObj.AddComponent<Text>();
|
||||
txt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
txt.text = label;
|
||||
txt.fontSize = 30;
|
||||
txt.alignment = TextAnchor.MiddleCenter;
|
||||
txt.color = Color.white;
|
||||
RectTransform txtRect = txtObj.GetComponent<RectTransform>();
|
||||
txtRect.anchorMin = Vector2.zero;
|
||||
txtRect.anchorMax = Vector2.one;
|
||||
txtRect.offsetMin = Vector2.zero;
|
||||
txtRect.offsetMax = Vector2.zero;
|
||||
|
||||
if (iconSprite != null)
|
||||
{
|
||||
GameObject iconObj = new GameObject("Icon");
|
||||
iconObj.transform.SetParent(btnObj.transform, false);
|
||||
Image iconImg = iconObj.AddComponent<Image>();
|
||||
iconImg.sprite = iconSprite;
|
||||
RectTransform iconRect = iconObj.GetComponent<RectTransform>();
|
||||
iconRect.sizeDelta = new Vector2(60, 60);
|
||||
iconRect.anchoredPosition = new Vector2(-70, 0); // shift left
|
||||
|
||||
txt.alignment = TextAnchor.MiddleRight;
|
||||
txtRect.offsetMax = new Vector2(-30, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectHuman()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Human";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human");
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose to remain Human.");
|
||||
}
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
|
||||
private void SelectFenrir()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Fenrir";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Fenrir");
|
||||
Player.m_localPlayer.m_customData["FenrirCurse_Active"] = "true";
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_FenrirCurse".GetStableHashCode(), true);
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Fenrir.");
|
||||
}
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
|
||||
private void SelectSkadi()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Skadi";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Skadi");
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of Skadi.");
|
||||
|
||||
// Force update skin colors
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
}
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
|
||||
private void SelectSkeleton()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Skeleton";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Skeleton");
|
||||
|
||||
// Add the stats SE for Skeleton
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkeletonStats".GetStableHashCode(), true);
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Skeleton.");
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectAswid()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Aswid";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Aswid");
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
// Save original skin color
|
||||
if (!Player.m_localPlayer.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
Vector3 currentSkinColor = Traverse.Create(visEq).Field("m_skinColor").GetValue<Vector3>();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_X"] = currentSkinColor.x.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Y"] = currentSkinColor.y.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Z"] = currentSkinColor.z.ToString();
|
||||
}
|
||||
|
||||
// Force max white
|
||||
Traverse.Create(visEq).Method("SetSkinColor", new Vector3(1f, 1f, 1f)).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Aswid.");
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectFurling()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Furling";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Furling");
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
if (!Player.m_localPlayer.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
Vector3 currentSkinColor = Traverse.Create(visEq).Field("m_skinColor").GetValue<Vector3>();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_X"] = currentSkinColor.x.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Y"] = currentSkinColor.y.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Z"] = currentSkinColor.z.ToString();
|
||||
}
|
||||
|
||||
Traverse.Create(visEq).Method("SetSkinColor", new Vector3(0.3f, 0.8f, 0.3f)).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Furling.");
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite GetFurlingIcon()
|
||||
{
|
||||
GameObject trophyPrefab = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyGoblin")?.gameObject;
|
||||
if (trophyPrefab != null)
|
||||
{
|
||||
ItemDrop trophyDrop = trophyPrefab.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SelectTrol()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData["Race"] = "Trol";
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Trol");
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
if (!Player.m_localPlayer.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
Vector3 currentSkinColor = Traverse.Create(visEq).Field("m_skinColor").GetValue<Vector3>();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_X"] = currentSkinColor.x.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Y"] = currentSkinColor.y.ToString();
|
||||
Player.m_localPlayer.m_customData["OriginalSkinColor_Z"] = currentSkinColor.z.ToString();
|
||||
}
|
||||
|
||||
Traverse.Create(visEq).Method("SetSkinColor", new Vector3(0.1f, 0.6f, 0.7f)).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Trol.");
|
||||
CloseRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite GetTrolIcon()
|
||||
{
|
||||
GameObject trophyPrefab = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyFrostTroll")?.gameObject;
|
||||
if (trophyPrefab == null) trophyPrefab = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyTroll")?.gameObject;
|
||||
if (trophyPrefab != null)
|
||||
{
|
||||
ItemDrop trophyDrop = trophyPrefab.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
return trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void CloseRaceSelectionMenu()
|
||||
{
|
||||
if (raceSelectionMenu != null)
|
||||
{
|
||||
Destroy(raceSelectionMenu);
|
||||
raceSelectionMenu = null;
|
||||
}
|
||||
GUIManager.BlockInput(false);
|
||||
}
|
||||
}
|
||||
|
||||
// --- MAIN MENU CHARACTER PREVIEW SKIN PATCH ---
|
||||
// Forces skin color/visuals refresh on the FejdStartup character preview
|
||||
// so Aswid/Furling skins are visible before loading into a world.
|
||||
[HarmonyPatch(typeof(FejdStartup), "SetupCharacterPreview")]
|
||||
public static class FejdStartup_SetupCharacterPreview_Patch
|
||||
{
|
||||
public static void Postfix(FejdStartup __instance) => ForcePreviewRefresh(__instance);
|
||||
|
||||
internal static void ForcePreviewRefresh(FejdStartup instance)
|
||||
{
|
||||
// GetPreviewPlayer returns the preview Player instance (has m_customData but no ZNetView)
|
||||
Player preview = instance.GetType()
|
||||
.GetMethod("GetPreviewPlayer",
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Public)
|
||||
?.Invoke(instance, null) as Player;
|
||||
if (preview == null) return;
|
||||
|
||||
VisEquipment visEq = preview.GetComponent<VisEquipment>();
|
||||
if (visEq == null) return;
|
||||
|
||||
// Fire UpdateVisuals first (goblin head, hair/beard hide), then UpdateColors (skin tint)
|
||||
var flags = System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Public;
|
||||
visEq.GetType().GetMethod("UpdateVisuals", flags)?.Invoke(visEq, null);
|
||||
visEq.GetType().GetMethod("UpdateColors", flags)?.Invoke(visEq, null);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(FejdStartup), "SetSelectedProfile")]
|
||||
public static class FejdStartup_SetSelectedProfile_Patch
|
||||
{
|
||||
public static void Postfix(FejdStartup __instance) =>
|
||||
FejdStartup_SetupCharacterPreview_Patch.ForcePreviewRefresh(__instance);
|
||||
}
|
||||
|
||||
// --- PLAYER SPAWN PATCH (RACE CHECK) ---
|
||||
[HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||
public static class PlayerSpawnPatch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (__instance.m_customData.ContainsKey("FenrirCurse_Active") && __instance.m_customData["FenrirCurse_Active"] == "true")
|
||||
{
|
||||
__instance.GetSEMan().AddStatusEffect("SE_FenrirCurse".GetStableHashCode(), true);
|
||||
}
|
||||
|
||||
// If Skadi, Aswid, Furling or Trol, re-trigger visual update to set skin color
|
||||
if (__instance.m_customData.ContainsKey("Race") && (__instance.m_customData["Race"] == "Skadi" || __instance.m_customData["Race"] == "Aswid" || __instance.m_customData["Race"] == "Furling" || __instance.m_customData["Race"] == "Trol"))
|
||||
{
|
||||
VisEquipment visEq = __instance.GetComponent<VisEquipment>();
|
||||
if (visEq != null) visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
// Check for Race Selection
|
||||
if (!__instance.m_customData.ContainsKey("Race"))
|
||||
{
|
||||
if (RacesOfValheim.Instance != null)
|
||||
{
|
||||
RacesOfValheim.Instance.ShowRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- CONSOLE COMMANDS ---
|
||||
public class ResetRaceCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "resetrace";
|
||||
public override string Help => "Resets the player's race and reopens the race selection menu for debugging";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData.Remove("Race");
|
||||
Player.m_localPlayer.m_customData.Remove("FenrirCurse_Active");
|
||||
|
||||
// Restore original skin color if it exists
|
||||
if (Player.m_localPlayer.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
float x = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_X"]);
|
||||
float y = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_Y"]);
|
||||
float z = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_Z"]);
|
||||
Vector3 origColor = new Vector3(x, y, z);
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
Traverse.Create(visEq).Method("SetSkinColor", origColor).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
}
|
||||
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode());
|
||||
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human");
|
||||
|
||||
if (RacesOfValheim.Instance != null)
|
||||
{
|
||||
if (FenrirRace.Instance != null) FenrirRace.Instance.ForceRevert();
|
||||
RacesOfValheim.Instance.ShowRaceSelectionMenu();
|
||||
}
|
||||
|
||||
Console.instance.Print("Race has been reset. The selection menu should now appear.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.instance.Print("You must be in-game to reset your race.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckProgressionCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "checkprogression";
|
||||
public override string Help => "Checks the current boss progression state (1-8)";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
Console.instance.Print($"Current World Boss Progression State: {state}");
|
||||
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"World Progression State: {state}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IncreaseProgressionCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "increaseprogression";
|
||||
public override string Help => "[DEBUG] Increases the current boss progression state by 1 (max 8)";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
if (BossProgressionManager.DebugState == -1)
|
||||
{
|
||||
BossProgressionManager.DebugState = BossProgressionManager.GetCurrentProgressionState();
|
||||
}
|
||||
|
||||
if (BossProgressionManager.DebugState < 8)
|
||||
{
|
||||
BossProgressionManager.DebugState++;
|
||||
Console.instance.Print($"[DEBUG] Progression state increased to: {BossProgressionManager.DebugState}");
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Progression State: {BossProgressionManager.DebugState}");
|
||||
Traverse.Create(Player.m_localPlayer).Method("SetupEquipment").GetValue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.instance.Print("[DEBUG] Progression state is already at maximum (8).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ResetProgressionCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "resetprogression";
|
||||
public override string Help => "[DEBUG] Resets the progression state to natural world state";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
BossProgressionManager.DebugState = -1;
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
Console.instance.Print($"[DEBUG] Progression state reset to natural world state: {state}");
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Progression reset to: {state}");
|
||||
Traverse.Create(Player.m_localPlayer).Method("SetupEquipment").GetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue