Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of DayTimeCountdown v1.2.0
ValheimDayTimeCountdown.dll
Decompiled 7 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Aidin")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Display day count and a how much of the current day or night is left (in minutes/seconds)")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0+079211609539158e7ffe2ce2434e7f7deac76c59")] [assembly: AssemblyProduct("DayTimeCountdown")] [assembly: AssemblyTitle("ValheimDayTimeCountdown")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/aidinabedi/ValheimDayTimeCountdown")] [assembly: AssemblyVersion("1.2.0.0")] internal static class Manifest { public const string ProjectName = "ValheimDayTimeCountdown"; public const string Product = "DayTimeCountdown"; public const string Description = "Display day count and a how much of the current day or night is left (in minutes/seconds)"; public const string Version = "1.2.0"; public const string Authors = "Aidin"; } namespace ValheimDayTimeCountdown { [BepInPlugin("ValheimDayTimeCountdown", "DayTimeCountdown", "1.2.0")] [BepInProcess("valheim.exe")] public class DayTimeCountdownPlugin : BaseUnityPlugin { public const string ID = "ValheimDayTimeCountdown"; private static ConfigEntry<bool> _displayUnderMiniMap; private static ConfigEntry<bool> _displayDay; private static ConfigEntry<bool> _displayTime; private static ConfigEntry<bool> _displayBackground; private static ConfigEntry<int> _fontSize; private static ConfigEntry<string> _fontName; private static ConfigEntry<Color> _fontColor; private static ConfigEntry<bool> _textOutlineEnabled; private static ConfigEntry<Color> _textOutlineColor; private static ConfigEntry<Color> _backgroundColor; private static ConfigEntry<float> _marginBetweenMiniMap; private static ConfigEntry<float> _padding; private static ConfigEntry<bool> _reverseTextPositions; private static ConfigEntry<float> _panelWidth; private static ConfigEntry<float> _panelHeight; private const string DEFAULT_FONT = "AveriaSansLibre-Bold"; private static GameObject _panel; private static Text _dayText; private static Text _timeText; private Harmony _harmony; private void Awake() { //IL_00e9: 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_0165: Unknown result type (might be due to invalid IL or missing references) _displayUnderMiniMap = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display under minimap", false, "Display under minimap"); _displayDay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display day", true, "Display day"); _displayTime = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display time", true, "Display time"); _displayBackground = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display background", true, "Display background"); _fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Font size", 16, "Font size"); _fontName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Font name", "AveriaSansLibre-Bold", "Font name"); _fontColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Font color", new Color(1f, 1f, 1f, 0.791f), "Font color"); _textOutlineEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Text outline enabled", true, "Text outline enabled"); _textOutlineColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Text outline color", Color.black, "Text outline color"); _backgroundColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Background color", new Color(0f, 0f, 0f, 0.3921569f), "Background color"); _marginBetweenMiniMap = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Margin between minimap and this panel", 0f, "Margin between minimap and this panel"); _padding = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Padding left and right", 10f, "Padding left and right from text."); _reverseTextPositions = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Reverse text positions", false, "If set to 'true', time will display to the left and day will display to the right."); _panelWidth = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Panel width", 200f, "Panel width"); _panelHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Panel height", 30f, "Panel height"); _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "ValheimDayTimeCountdown"); } private void OnDestroy() { if (Object.op_Implicit((Object)(object)Hud.instance) && (Object)(object)_panel != (Object)null) { Log("Destroying panel..."); Object.Destroy((Object)(object)_panel); Log("Panel destroyed!"); } Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchAll("ValheimDayTimeCountdown"); } } private void Update() { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)Hud.instance) && Traverse.Create((object)Hud.instance).Method("IsVisible", Array.Empty<object>()).GetValue<bool>()) { if ((Object)(object)_panel == (Object)null) { CreatePanel(Hud.instance); } RectTransform component = _panel.GetComponent<RectTransform>(); component.anchoredPosition = new Vector2(-140f, _displayUnderMiniMap.Value ? (-255f - _marginBetweenMiniMap.Value) : (-25f + _marginBetweenMiniMap.Value)); component.sizeDelta = new Vector2(_panelWidth.Value, _panelHeight.Value); Image component2 = _panel.GetComponent<Image>(); ((Behaviour)component2).enabled = _displayBackground.Value; ((Graphic)component2).color = _backgroundColor.Value; ((Behaviour)_dayText).enabled = _displayDay.Value; ((Behaviour)_timeText).enabled = _displayTime.Value; if (_displayDay.Value) { UpdateDay(); } if (_displayTime.Value) { UpdateTime(); } } } public static void CreatePanel(Hud hudInstance) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) Log("Creating panel..."); _panel = new GameObject("DayTimePanel") { layer = 5 }; _panel.transform.SetParent(hudInstance.m_rootObject.transform); RectTransform obj = _panel.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(1f, 1f); obj.anchorMax = new Vector2(1f, 1f); obj.anchoredPosition = new Vector2(-140f, _displayUnderMiniMap.Value ? (-255f - _marginBetweenMiniMap.Value) : (-25f + _marginBetweenMiniMap.Value)); obj.sizeDelta = new Vector2(_panelWidth.Value, _panelHeight.Value); Sprite sprite = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => ((Object)s).name == "InputFieldBackground")); Image obj2 = _panel.AddComponent<Image>(); ((Behaviour)obj2).enabled = _displayBackground.Value; ((Graphic)obj2).color = _backgroundColor.Value; obj2.sprite = sprite; obj2.type = (Type)1; Log("Panel created!"); CreateDay(); CreateTime(); } private static void CreateDay() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) Log("Creating day text..."); GameObject val = new GameObject("Day") { layer = 5 }; val.transform.SetParent(_panel.transform); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchoredPosition = new Vector2(_reverseTextPositions.Value ? (_panelWidth.Value / 4f - _padding.Value) : (0f - _panelWidth.Value / 4f + _padding.Value), 0f); obj.sizeDelta = new Vector2(_panelWidth.Value / 2f, _panelHeight.Value); _dayText = val.AddComponent<Text>(); ((Graphic)_dayText).color = _fontColor.Value; _dayText.font = GetFont(); _dayText.fontSize = _fontSize.Value; ((Behaviour)_dayText).enabled = _displayDay.Value; _dayText.alignment = (TextAnchor)(_reverseTextPositions.Value ? 5 : 3); Outline obj2 = val.AddComponent<Outline>(); ((Shadow)obj2).effectColor = _textOutlineColor.Value; ((Shadow)obj2).effectDistance = new Vector2(1f, -1f); ((Shadow)obj2).useGraphicAlpha = true; ((MonoBehaviour)obj2).useGUILayout = true; ((Behaviour)obj2).enabled = _textOutlineEnabled.Value; Log("Day created!"); } private static void CreateTime() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) Log("Creating time text..."); GameObject val = new GameObject("Time") { layer = 5 }; val.transform.SetParent(_panel.transform); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchoredPosition = new Vector2(_reverseTextPositions.Value ? (0f - _panelWidth.Value / 4f + _padding.Value) : (_panelWidth.Value / 4f - _padding.Value), 0f); obj.sizeDelta = new Vector2(_panelWidth.Value / 2f, _panelHeight.Value); _timeText = val.AddComponent<Text>(); ((Graphic)_timeText).color = _fontColor.Value; _timeText.font = GetFont(); _timeText.fontSize = _fontSize.Value; ((Behaviour)_timeText).enabled = _displayTime.Value; _timeText.alignment = (TextAnchor)(_reverseTextPositions.Value ? 3 : 5); Outline obj2 = val.AddComponent<Outline>(); ((Shadow)obj2).effectColor = _textOutlineColor.Value; ((Shadow)obj2).effectDistance = new Vector2(1f, -1f); ((Shadow)obj2).useGraphicAlpha = true; ((MonoBehaviour)obj2).useGUILayout = true; ((Behaviour)obj2).enabled = _textOutlineEnabled.Value; Log("Time created!"); } private void UpdateDay() { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) if (((Object)_dayText.font).name != _fontName.Value) { _dayText.font = GetFont(); } RectTransform component = ((Component)_dayText).GetComponent<RectTransform>(); component.anchoredPosition = new Vector2(_reverseTextPositions.Value ? (_panelWidth.Value / 4f - _padding.Value) : (0f - _panelWidth.Value / 4f + _padding.Value), 0f); component.sizeDelta = new Vector2(_panelWidth.Value / 2f, _panelHeight.Value); _dayText.alignment = (TextAnchor)(_reverseTextPositions.Value ? 5 : 3); ((Graphic)_dayText).color = _fontColor.Value; _dayText.fontSize = _fontSize.Value; _dayText.text = GetCurrentDayText(); Outline component2 = ((Component)_dayText).GetComponent<Outline>(); ((Behaviour)component2).enabled = _textOutlineEnabled.Value; ((Shadow)component2).effectColor = _textOutlineColor.Value; } private void UpdateTime() { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) if (((Object)_timeText.font).name != _fontName.Value) { _timeText.font = GetFont(); } RectTransform component = ((Component)_timeText).GetComponent<RectTransform>(); component.anchoredPosition = new Vector2(_reverseTextPositions.Value ? (0f - _panelWidth.Value / 4f + _padding.Value) : (_panelWidth.Value / 4f - _padding.Value), 0f); component.sizeDelta = new Vector2(_panelWidth.Value / 2f, _panelHeight.Value); _timeText.alignment = (TextAnchor)(_reverseTextPositions.Value ? 3 : 5); ((Graphic)_timeText).color = _fontColor.Value; _timeText.fontSize = _fontSize.Value; _timeText.text = GetCurrentTimeText(); Outline component2 = ((Component)_timeText).GetComponent<Outline>(); ((Behaviour)component2).enabled = _textOutlineEnabled.Value; ((Shadow)component2).effectColor = _textOutlineColor.Value; } private string GetCurrentDayText() { if (!Object.op_Implicit((Object)(object)EnvMan.instance) || Localization.instance == null) { return null; } int day = EnvMan.instance.GetDay(); return Localization.instance.Localize("$msg_newday", new string[1] { day.ToString() }); } private string GetCurrentTimeText() { if (!Object.op_Implicit((Object)(object)EnvMan.instance)) { return null; } float dayFraction = EnvMan.instance.GetDayFraction(); long dayLengthSec = EnvMan.instance.m_dayLengthSec; float num = 0.5f - (dayFraction + 0.25f) % 0.5f; int num2 = (int)(num * (float)dayLengthSec) / 60; int num3 = (int)(num * (float)dayLengthSec) % 60; string text = ((num2 > 0) ? $"{num2}m" : $"{num3}s"); return ((0.25f <= dayFraction && dayFraction <= 0.75f) ? "Day " : "Night ") + text; } public static Font GetFont() { Font[] source = Resources.FindObjectsOfTypeAll<Font>(); Font val = ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name == _fontName.Value)); if ((Object)(object)val == (Object)null) { return ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name == "AveriaSansLibre-Bold")); } return val; } public static void Log(string message) { Debug.Log((object)("ValheimDayTimeCountdown: " + message)); } } } namespace ValheimDayTimeCountdown.GamePatches { [HarmonyPatch(typeof(Hud), "Awake")] public static class Hud_Awake_Patch { public static void Postfix(Hud __instance) { DayTimeCountdownPlugin.CreatePanel(__instance); } } }