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 SakeysCalender v1.0.2
BepInEx/plugins/Sakey's Calender/SakeysCalendar.dll
Decompiled 3 days agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("SakeysCalendar")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SakeysCalendar")] [assembly: AssemblyTitle("SakeysCalendar")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SakeysCalendar { [BepInPlugin("com.sakey.calendar", "Sakey's Calendar", "1.0.2")] public sealed class SakeysCalendarPlugin : BaseUnityPlugin { private sealed class ConfigurationManagerAttributes { public string DispName; public string Description; public int? Order; public bool? IsAdvanced; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? ReadOnly; public Action<ConfigEntryBase> CustomDrawer; } private sealed class DisplaySegment { public string Text; public int FontSize; public DisplaySegment(string text, int fontSize) { Text = text; FontSize = fontSize; } } private sealed class DisplayLine { public readonly List<DisplaySegment> Segments = new List<DisplaySegment>(); public DisplayLine(params DisplaySegment[] segments) { if (segments != null) { Segments.AddRange(segments); } } } public const string PluginGuid = "com.sakey.calendar"; public const string PluginName = "Sakey's Calendar"; public const string PluginVersion = "1.0.2"; private ConfigEntry<bool> showDay; private ConfigEntry<bool> showTime; private ConfigEntry<bool> showWeather; private ConfigEntry<bool> showForecast; private ConfigEntry<bool> showDeaths; private ConfigEntry<bool> use24Hour; private ConfigEntry<int> dayFontSize; private ConfigEntry<int> timeFontSize; private ConfigEntry<int> weatherFontSize; private ConfigEntry<int> forecastFontSize; private ConfigEntry<int> deathsFontSize; private ConfigEntry<Color> fontColor; private ConfigEntry<Color> outlineColor; private ConfigEntry<bool> showOutline; private ConfigEntry<bool> boldText; private ConfigEntry<bool> showBackground; private ConfigEntry<Color> backgroundColor; private ConfigEntry<float> posX; private ConfigEntry<float> posY; private ConfigEntry<bool> draggable; private bool applyingPositionInternally; private bool positionFileLoaded; private string positionFilePath; private float savedNormalizedX = 0.7f; private float savedNormalizedY = 0.02f; private ConfigEntry<string> uiLanguage; private ConfigEntry<string> textLayout; private ConfigEntry<string> textAlignment; private ConfigEntry<string> singleLineVerticalAlignment; private readonly Rect defaultRect = new Rect(0f, 0f, 160f, 40f); private bool defaultPositionInitialized; private float lastObservedPosX; private float lastObservedPosY; private bool dragging; private Vector2 dragOffset; private GUIStyle labelStyle; private GUIStyle backgroundStyle; private GUIStyle outlineStyle; private float refreshTimer; private string cachedText = string.Empty; private float cachedHeight = 40f; private string cachedForecast = string.Empty; private List<DisplayLine> cachedLines = new List<DisplayLine>(); private int cachedWidth = 160; private int cachedPanelHeight = 40; private Texture2D backgroundTexture; private Color cachedBackgroundColor; private bool backgroundTextureReady; private bool japaneseFontSearchAttempted; private float japaneseFontRetryTimer; private void Awake() { //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Expected O, but got Unknown //IL_0449: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Expected O, but got Unknown //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04dd: Expected O, but got Unknown //IL_055d: Unknown result type (might be due to invalid IL or missing references) //IL_0567: Expected O, but got Unknown showDay = BindBool("Display", "Show Day", defaultValue: true, "日数を表示", "現在のValheimの日数を表示します。", "Show the current Valheim day."); showTime = BindBool("Display", "Show Time", defaultValue: true, "時刻を表示", "現在のValheimの時刻を表示します。", "Show the current Valheim time."); showWeather = BindBool("Display", "Show Weather", defaultValue: true, "天気を表示", "現在の天気を表示します。", "Show the current weather."); showForecast = BindBool("Display", "Show Weather Forecast", defaultValue: true, "天気予報を表示", "次に変わる天気と残り時間を表示します。", "Show the next weather change and remaining time."); showDeaths = BindBool("Display", "Show Deaths", defaultValue: true, "死亡回数を表示", "キャラクターの死亡回数を表示します。", "Show the character death count."); use24Hour = BindBool("Display", "24 Hour Clock", defaultValue: true, "24時間表示", "時刻を24時間制で表示します。", "Use a 24-hour clock."); dayFontSize = BindDirectInt("Appearance", "Day Font Size", 17, "日数の文字サイズ", "日数の文字サイズです。", "Day font size."); timeFontSize = BindDirectInt("Appearance", "Time Font Size", 17, "時刻の文字サイズ", "時刻の文字サイズです。", "Time font size."); weatherFontSize = BindDirectInt("Appearance", "Weather Font Size", 17, "天気の文字サイズ", "天気の文字サイズです。", "Weather font size."); forecastFontSize = BindDirectInt("Appearance", "Forecast Font Size", 14, "予報の文字サイズ", "天気予報の文字サイズです。", "Forecast font size."); deathsFontSize = BindDirectInt("Appearance", "Deaths Font Size", 17, "死亡数の文字サイズ", "死亡回数の文字サイズです。", "Deaths font size."); fontColor = BindColor("Appearance", "Font Color", Color.white, "文字色", "カレンダーの文字色です。", "Calendar text color."); outlineColor = BindColor("Appearance", "Outline Color", Color.black, "縁取り色", "カレンダー文字の縁取り色です。", "Calendar outline color."); showOutline = BindBool("Appearance", "Show Outline", defaultValue: true, "縁取りを表示", "文字の縁取りを表示します。", "Show a text outline."); boldText = BindBool("Appearance", "Bold Text", defaultValue: false, "太字にする", "文字を太字で表示します。", "Use bold text."); showBackground = BindBool("Appearance", "Show Background", defaultValue: true, "背景を表示", "カレンダーの背景を表示します。", "Show the background panel."); backgroundColor = BindColor("Appearance", "Background Color", new Color(0f, 0f, 0f, 0.4f), "背景色", "カレンダーの背景色です。", "Calendar background color."); Rect val = defaultRect; posX = BindFloat("Position", "Position X", ((Rect)(ref val)).x, "X座標", "内部保存用です。", "Internal position value."); val = defaultRect; posY = BindFloat("Position", "Position Y", ((Rect)(ref val)).y, "Y座標", "内部保存用です。", "Internal position value."); positionFilePath = Path.Combine(Paths.ConfigPath, "com.sakey.calendar.position.v3.cfg"); draggable = BindBool("Position", "Mouse Drag", defaultValue: true, "マウスで移動", "マウスでカレンダーをドラッグして移動できるようにします。", "Allow the calendar to be dragged."); uiLanguage = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "UI Language", "Auto", new ConfigDescription("Calendar UI language. Auto follows the game language.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "Japanese", "English" }), new object[1] { MakeAttributes("UIの言語", "UI Language", "カレンダー本体の表示言語です。自動はゲーム言語に合わせます。", "Calendar UI language. Auto follows the game language.", DrawLocalizedDropdown) })); textLayout = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Text Layout", "Single Line", new ConfigDescription("Choose stacked lines or a single horizontal line.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Stacked", "Single Line" }), new object[1] { MakeAttributes("文字レイアウト", "Text Layout", "文字を縦に並べるか、横一列に並べるかを選びます。", "Choose stacked lines or a single horizontal line.", DrawLocalizedDropdown) })); textAlignment = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Text Alignment", "Right", new ConfigDescription("Choose left, center, or right alignment.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Left", "Center", "Right" }), new object[1] { MakeAttributes("横方向の文字揃え", "Horizontal Text Alignment", "文字を左寄せ・中央寄せ・右寄せにします。", "Choose left, center, or right alignment.", DrawLocalizedDropdown) })); singleLineVerticalAlignment = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Single Line Vertical Alignment", "Center", new ConfigDescription("Choose top, center, or bottom alignment for differently sized text in Single Line mode.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Top", "Center", "Bottom" }), new object[1] { MakeAttributes("縦方向の文字揃え", "Vertical Text Alignment", "横一列表示で、サイズの違う文字を上・中央・下のどこに揃えるかを選びます。", "Choose top, center, or bottom alignment for differently sized text in Single Line mode.", DrawLocalizedDropdown) })); refreshTimer = 0f; defaultPositionInitialized = false; lastObservedPosX = posX.Value; lastObservedPosY = posY.Value; positionFileLoaded = false; } private ConfigEntry<bool> BindBool(string category, string key, bool defaultValue, string japaneseName, string japaneseDescription, string englishDescription) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<bool>(category, key, defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)null, new object[1] { MakeAttributes(japaneseName, key, japaneseDescription, englishDescription, DrawLocalizedBool) })); } private ConfigEntry<int> BindInt(string category, string key, int defaultValue, string japaneseName, string japaneseDescription, string englishDescription) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<int>(category, key, defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 48), new object[1] { MakeAttributes(japaneseName, key, japaneseDescription, englishDescription) })); } private ConfigEntry<int> BindDirectInt(string category, string key, int defaultValue, string japaneseName, string japaneseDescription, string englishDescription) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<int>(category, key, defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 48), new object[1] { MakeAttributes(japaneseName, key, japaneseDescription, englishDescription) })); } private ConfigEntry<float> BindFloat(string category, string key, float defaultValue, string japaneseName, string japaneseDescription, string englishDescription) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown ConfigurationManagerAttributes configurationManagerAttributes = MakeAttributes(japaneseName, key, japaneseDescription, englishDescription); if (string.Equals(category, "Position", StringComparison.OrdinalIgnoreCase)) { configurationManagerAttributes.Browsable = false; } return ((BaseUnityPlugin)this).Config.Bind<float>(category, key, defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes })); } private ConfigEntry<Color> BindColor(string category, string key, Color defaultValue, string japaneseName, string japaneseDescription, string englishDescription) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<Color>(category, key, defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)null, new object[1] { MakeAttributes(japaneseName, key, japaneseDescription, englishDescription) })); } private static ConfigurationManagerAttributes MakeAttributes(string japaneseName, string englishName, string japaneseDescription, string englishDescription, Action<ConfigEntryBase> customDrawer = null) { bool flag = IsGameLanguageJapanese(); return new ConfigurationManagerAttributes { DispName = (flag ? japaneseName : englishName), Description = (flag ? japaneseDescription : englishDescription), CustomDrawer = customDrawer }; } private static void DrawLocalizedBool(ConfigEntryBase entry) { if (entry != null) { bool flag = false; try { flag = Convert.ToBoolean(entry.BoxedValue); } catch { return; } string text = ((!IsGameLanguageJapanese()) ? (flag ? "Enabled" : "Disabled") : (flag ? "有効" : "無効")); bool flag2 = GUILayout.Toggle(flag, text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }); if (flag2 != flag) { entry.BoxedValue = flag2; } } } private static void DrawLocalizedDropdown(ConfigEntryBase entry) { if (entry == null) { return; } string text = (entry.BoxedValue as string) ?? string.Empty; bool japanese = IsGameLanguageJapanese(); if (!GUILayout.Button(GetLocalizedOptionLabel(entry.Definition.Key, text, japanese), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { return; } string[] dropdownValues = GetDropdownValues(entry.Definition.Key); if (dropdownValues.Length == 0) { return; } int num = 0; for (int i = 0; i < dropdownValues.Length; i++) { if (string.Equals(text, dropdownValues[i], StringComparison.OrdinalIgnoreCase)) { num = i; break; } } int num2 = (num + 1) % dropdownValues.Length; entry.BoxedValue = dropdownValues[num2]; } private static string[] GetDropdownValues(string key) { return key switch { "UI Language" => new string[3] { "Auto", "Japanese", "English" }, "Text Layout" => new string[2] { "Stacked", "Single Line" }, "Text Alignment" => new string[3] { "Left", "Center", "Right" }, "Single Line Vertical Alignment" => new string[3] { "Top", "Center", "Bottom" }, _ => new string[1] { "" }, }; } private static string GetLocalizedOptionLabel(string key, string value, bool japanese) { if (!japanese) { return value; } switch (key) { case "UI Language": if (string.Equals(value, "Auto", StringComparison.OrdinalIgnoreCase)) { return "自動"; } if (string.Equals(value, "Japanese", StringComparison.OrdinalIgnoreCase)) { return "日本語"; } if (string.Equals(value, "English", StringComparison.OrdinalIgnoreCase)) { return "英語"; } break; case "Text Layout": if (string.Equals(value, "Stacked", StringComparison.OrdinalIgnoreCase)) { return "縦表示"; } if (string.Equals(value, "Single Line", StringComparison.OrdinalIgnoreCase)) { return "横一列"; } break; case "Text Alignment": if (string.Equals(value, "Left", StringComparison.OrdinalIgnoreCase)) { return "左寄せ"; } if (string.Equals(value, "Center", StringComparison.OrdinalIgnoreCase)) { return "中央寄せ"; } if (string.Equals(value, "Right", StringComparison.OrdinalIgnoreCase)) { return "右寄せ"; } break; case "Single Line Vertical Alignment": if (string.Equals(value, "Top", StringComparison.OrdinalIgnoreCase)) { return "上揃え"; } if (string.Equals(value, "Center", StringComparison.OrdinalIgnoreCase)) { return "中央揃え"; } if (string.Equals(value, "Bottom", StringComparison.OrdinalIgnoreCase)) { return "下揃え"; } break; } return value; } private void Update() { refreshTimer -= Time.unscaledDeltaTime; japaneseFontRetryTimer -= Time.unscaledDeltaTime; if (refreshTimer <= 0f) { refreshTimer = 0.25f; RefreshText(); ApplyDefaultPosition(); } } private void ApplyDefaultPosition() { if (dragging) { return; } applyingPositionInternally = true; try { if (cachedWidth <= 0 || Screen.width <= 0 || Screen.height <= 0) { return; } if (!positionFileLoaded) { positionFileLoaded = LoadSavedPosition(); if (!positionFileLoaded) { savedNormalizedX = 0.7f; savedNormalizedY = 0.02f; SavePosition(); positionFileLoaded = true; } } float num = (float)Screen.width * Mathf.Clamp01(savedNormalizedX); float num2 = (float)Screen.height * Mathf.Clamp01(savedNormalizedY); posX.Value = Mathf.Clamp(num - (float)cachedWidth * 0.5f, 0f, Mathf.Max(0f, (float)(Screen.width - cachedWidth))); posY.Value = Mathf.Clamp(num2 - (float)cachedPanelHeight * 0.5f, 0f, Mathf.Max(0f, (float)(Screen.height - cachedPanelHeight))); lastObservedPosX = posX.Value; lastObservedPosY = posY.Value; defaultPositionInitialized = true; } finally { applyingPositionInternally = false; } } private bool LoadSavedPosition() { try { if (string.IsNullOrEmpty(positionFilePath) || !File.Exists(positionFilePath)) { return false; } string[] array = File.ReadAllText(positionFilePath).Trim().Split(new char[1] { ',' }); if (array.Length != 2) { return false; } if (!float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { return false; } if (float.IsNaN(result) || float.IsNaN(result2) || float.IsInfinity(result) || float.IsInfinity(result2)) { return false; } savedNormalizedX = Mathf.Clamp01(result); savedNormalizedY = Mathf.Clamp01(result2); return true; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to load saved calendar position: " + ex.Message)); return false; } } private void SavePosition() { try { if (!string.IsNullOrEmpty(positionFilePath) && Screen.width > 0 && Screen.height > 0) { string directoryName = Path.GetDirectoryName(positionFilePath); if (!string.IsNullOrEmpty(directoryName)) { Directory.CreateDirectory(directoryName); } float num = posX.Value + (float)cachedWidth * 0.5f; float num2 = posY.Value + (float)cachedPanelHeight * 0.5f; savedNormalizedX = Mathf.Clamp01(num / (float)Screen.width); savedNormalizedY = Mathf.Clamp01(num2 / (float)Screen.height); File.WriteAllText(positionFilePath, savedNormalizedX.ToString("R", CultureInfo.InvariantCulture) + "," + savedNormalizedY.ToString("R", CultureInfo.InvariantCulture)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to save calendar position: " + ex.Message)); } } private void OnPositionSettingChanged(object sender, EventArgs e) { if (!applyingPositionInternally) { SavePosition(); } } private void OnGUI() { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Invalid comparison between Unknown and I4 //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Invalid comparison between Unknown and I4 //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) if (!ShouldDisplay()) { return; } EnsureStyles(); List<DisplayLine> list = cachedLines; if (list == null || list.Count == 0) { return; } int num = cachedWidth; int num2 = cachedPanelHeight; posX.Value = Mathf.Clamp(posX.Value, 0f, Mathf.Max(0f, (float)(Screen.width - num))); posY.Value = Mathf.Clamp(posY.Value, 0f, Mathf.Max(0f, (float)(Screen.height - num2))); Rect val = default(Rect); ((Rect)(ref val))..ctor(posX.Value, posY.Value, (float)num, (float)num2); Event current = Event.current; if (draggable.Value) { if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition)) { dragging = true; dragOffset = current.mousePosition - ((Rect)(ref val)).position; current.Use(); } else if ((int)current.type == 3 && current.button == 0 && dragging) { Vector2 val2 = current.mousePosition - dragOffset; val2.x = Mathf.Clamp(val2.x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref val)).width)); val2.y = Mathf.Clamp(val2.y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref val)).height)); posX.Value = val2.x; posY.Value = val2.y; current.Use(); } else if ((int)current.type == 1 && current.button == 0 && dragging) { dragging = false; SavePosition(); ((BaseUnityPlugin)this).Config.Save(); current.Use(); } } ((Rect)(ref val))..ctor(posX.Value, posY.Value, (float)num, (float)num2); if (showBackground.Value) { EnsureBackgroundTexture(); backgroundStyle.normal.background = backgroundTexture; GUI.Box(val, GUIContent.none, backgroundStyle); } float num3 = ((Rect)(ref val)).y + 2f; if (string.Equals(textLayout.Value, "Single Line", StringComparison.OrdinalIgnoreCase)) { DrawSingleLine(list, val, num3); return; } for (int i = 0; i < list.Count; i++) { float lineHeight = GetLineHeight(list[i]); DrawCalendarLine(list[i], val, num3, lineHeight); num3 += lineHeight; } } private List<DisplayLine> GetDisplayLines() { bool flag = IsJapaneseUI(); List<DisplayLine> list = new List<DisplayLine>(); string text = ((!showDay.Value) ? string.Empty : (flag ? (EnvMan.instance.GetDay() + "日目") : ("Day " + EnvMan.instance.GetDay()))); string text2 = (showTime.Value ? FormatTime(EnvMan.instance.GetDayFraction()) : string.Empty); if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2)) { list.Add(new DisplayLine(new DisplaySegment(text, ResolveFontSize(dayFontSize)), new DisplaySegment(" ", Mathf.Max(8, Mathf.Max(ResolveFontSize(dayFontSize), ResolveFontSize(timeFontSize)))), new DisplaySegment(text2, ResolveFontSize(timeFontSize)))); } else if (!string.IsNullOrEmpty(text)) { list.Add(new DisplayLine(new DisplaySegment(text, ResolveFontSize(dayFontSize)))); } else if (!string.IsNullOrEmpty(text2)) { list.Add(new DisplayLine(new DisplaySegment(text2, ResolveFontSize(timeFontSize)))); } if (showWeather.Value) { string currentWeather = GetCurrentWeather(); if (!string.IsNullOrEmpty(currentWeather)) { list.Add(new DisplayLine(new DisplaySegment(currentWeather, ResolveFontSize(weatherFontSize)))); } } if (showForecast.Value && !string.IsNullOrEmpty(cachedForecast)) { list.Add(new DisplayLine(new DisplaySegment(cachedForecast, ResolveFontSize(forecastFontSize)))); } if (showDeaths.Value) { list.Add(new DisplayLine(new DisplaySegment((flag ? "死亡: " : "Deaths: ") + GetDeathCount(), ResolveFontSize(deathsFontSize)))); } return list; } private int ResolveFontSize(ConfigEntry<int> specific) { return Mathf.Clamp(specific?.Value ?? 17, 6, 48); } private void DrawCalendarLine(DisplayLine line, Rect panelRect, float y, float lineHeight) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) float contentWidth = CalculateLineWidth(line); float x = GetAlignedX(panelRect, contentWidth); for (int i = 0; i < line.Segments.Count; i++) { DrawSegment(line.Segments[i], ref x, y, lineHeight, verticalAlign: false); } } private void DrawSingleLine(List<DisplayLine> lines, Rect panelRect, float y) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) List<DisplaySegment> list = new List<DisplaySegment>(); for (int i = 0; i < lines.Count; i++) { if (i > 0) { list.Add(new DisplaySegment(" ", 8)); } list.AddRange(lines[i].Segments); } float contentWidth = CalculateSegmentsWidth(list); float x = GetAlignedX(panelRect, contentWidth); float segmentsLineHeight = GetSegmentsLineHeight(list); for (int j = 0; j < list.Count; j++) { DrawSegment(list[j], ref x, y, segmentsLineHeight, verticalAlign: true); } } private void DrawSegment(DisplaySegment segment, ref float x, float y, float lineHeight, bool verticalAlign) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Expected O, but got Unknown //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) int fontSize = Mathf.Max(8, segment.FontSize); GUIContent val = new GUIContent(boldText.Value ? ("<b>" + segment.Text + "</b>") : segment.Text); labelStyle.fontSize = fontSize; labelStyle.wordWrap = false; labelStyle.richText = true; labelStyle.normal.textColor = fontColor.Value; labelStyle.padding = new RectOffset(0, 0, 0, 0); float x2 = labelStyle.CalcSize(val).x; float num = Mathf.Max(1f, labelStyle.CalcHeight(val, Mathf.Max(1f, x2))); float num2 = Mathf.Max(0f, lineHeight - num); float num3 = 0f; if (verticalAlign) { if (string.Equals(singleLineVerticalAlignment.Value, "Center", StringComparison.OrdinalIgnoreCase)) { num3 = num2 * 0.5f; } else if (string.Equals(singleLineVerticalAlignment.Value, "Bottom", StringComparison.OrdinalIgnoreCase)) { num3 = num2; } } int num4 = Mathf.Max(0, Mathf.RoundToInt(num3)); int num5 = Mathf.Max(0, Mathf.RoundToInt(num2 - num3)); labelStyle.padding = new RectOffset(0, 0, num4, num5); outlineStyle.fontSize = fontSize; outlineStyle.wordWrap = false; outlineStyle.richText = true; outlineStyle.normal.textColor = outlineColor.Value; outlineStyle.padding = new RectOffset(0, 0, num4, num5); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(x, y, x2 + 4f, lineHeight); if (showOutline.Value && outlineColor.Value.a > 0f) { GUI.Label(Offset(val2, -1f, 0f), val, outlineStyle); GUI.Label(Offset(val2, 1f, 0f), val, outlineStyle); GUI.Label(Offset(val2, 0f, -1f), val, outlineStyle); GUI.Label(Offset(val2, 0f, 1f), val, outlineStyle); } GUI.Label(val2, val, labelStyle); x += x2; } private float GetAlignedX(Rect panelRect, float contentWidth) { if (string.Equals(textAlignment.Value, "Center", StringComparison.OrdinalIgnoreCase)) { return ((Rect)(ref panelRect)).x + (((Rect)(ref panelRect)).width - contentWidth) * 0.5f; } if (string.Equals(textAlignment.Value, "Right", StringComparison.OrdinalIgnoreCase)) { return ((Rect)(ref panelRect)).xMax - 2f - contentWidth; } return ((Rect)(ref panelRect)).x + 2f; } private float CalculateLineWidth(DisplayLine line) { return CalculateSegmentsWidth(line.Segments); } private float CalculateSegmentsWidth(List<DisplaySegment> segments) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) float num = 0f; for (int i = 0; i < segments.Count; i++) { int fontSize = Mathf.Max(8, segments[i].FontSize); labelStyle.fontSize = fontSize; labelStyle.wordWrap = false; labelStyle.richText = true; string text = (boldText.Value ? ("<b>" + segments[i].Text + "</b>") : segments[i].Text); num += labelStyle.CalcSize(new GUIContent(text)).x; } return num; } private float GetLineHeight(DisplayLine line) { float num = 8f; for (int i = 0; i < line.Segments.Count; i++) { num = Mathf.Max(num, (float)line.Segments[i].FontSize); } return num + 16f; } private float GetSegmentsLineHeight(List<DisplaySegment> segments) { float num = 8f; for (int i = 0; i < segments.Count; i++) { num = Mathf.Max(num, (float)segments[i].FontSize); } return num + 16f; } private int CalculatePanelWidth(List<DisplayLine> lines) { if (labelStyle == null) { return 160; } float num = 0f; if (string.Equals(textLayout.Value, "Single Line", StringComparison.OrdinalIgnoreCase)) { List<DisplaySegment> list = new List<DisplaySegment>(); for (int i = 0; i < lines.Count; i++) { if (i > 0) { list.Add(new DisplaySegment(" ", 8)); } list.AddRange(lines[i].Segments); } num = CalculateSegmentsWidth(list); } else { for (int j = 0; j < lines.Count; j++) { num = Mathf.Max(num, CalculateLineWidth(lines[j])); } } return Mathf.Clamp(Mathf.CeilToInt(num + 4f), 90, Mathf.Max(90, Screen.width)); } private int CalculatePanelHeight(List<DisplayLine> lines) { if (string.Equals(textLayout.Value, "Single Line", StringComparison.OrdinalIgnoreCase)) { return Mathf.Max(24, Mathf.CeilToInt(4f + GetSegmentsLineHeight(GetAllSegments(lines)))); } float num = 4f; for (int i = 0; i < lines.Count; i++) { num += GetLineHeight(lines[i]); } return Mathf.Max(20, Mathf.CeilToInt(num)); } private List<DisplaySegment> GetAllSegments(List<DisplayLine> lines) { List<DisplaySegment> list = new List<DisplaySegment>(); for (int i = 0; i < lines.Count; i++) { if (i > 0) { list.Add(new DisplaySegment(" ", 8)); } list.AddRange(lines[i].Segments); } return list; } private static Rect Offset(Rect rect, float x, float y) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) ((Rect)(ref rect)).x = ((Rect)(ref rect)).x + x; ((Rect)(ref rect)).y = ((Rect)(ref rect)).y + y; return rect; } private static Texture2D MakeTexture(Color color) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false) { hideFlags = (HideFlags)61 }; val.SetPixel(0, 0, color); val.Apply(); return val; } private void EnsureStyles() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown if (labelStyle == null) { labelStyle = new GUIStyle(GUI.skin.label); } if (outlineStyle == null) { outlineStyle = new GUIStyle(GUI.skin.label); } if (backgroundStyle == null) { backgroundStyle = new GUIStyle(GUI.skin.box); } labelStyle.padding = new RectOffset(0, 0, 0, 0); labelStyle.margin = new RectOffset(0, 0, 0, 0); outlineStyle.padding = new RectOffset(0, 0, 0, 0); outlineStyle.margin = new RectOffset(0, 0, 0, 0); if (IsJapaneseUI() && japaneseFontRetryTimer <= 0f && !japaneseFontSearchAttempted) { japaneseFontRetryTimer = 2f; japaneseFontSearchAttempted = true; TryApplyJapaneseFont(labelStyle, outlineStyle); } } private void EnsureBackgroundTexture() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) Color value = backgroundColor.Value; if (!backgroundTextureReady || !((Object)(object)backgroundTexture != (Object)null) || !(cachedBackgroundColor == value)) { if ((Object)(object)backgroundTexture != (Object)null) { Object.Destroy((Object)(object)backgroundTexture); } backgroundTexture = MakeTexture(value); cachedBackgroundColor = value; backgroundTextureReady = true; } } private void TryApplyJapaneseFont(GUIStyle primary, GUIStyle outline) { try { PropertyInfo property = typeof(GUIStyle).GetProperty("font", BindingFlags.Instance | BindingFlags.Public); if (!(property == null) && property.CanWrite) { object obj = FindJapaneseFontObject(); if (obj == null) { japaneseFontSearchAttempted = false; return; } property.SetValue(primary, obj, null); property.SetValue(outline, obj, null); } } catch { japaneseFontSearchAttempted = false; } } private static object FindJapaneseFontObject() { try { Object[] array = Resources.FindObjectsOfTypeAll<Object>(); object obj = null; foreach (Object val in array) { if (!(val == (Object)null) && !(((object)val).GetType().Name != "Font")) { string text = val.name ?? string.Empty; if (text.IndexOf("NotoSans", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Noto Sans", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("NotoSerif", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Noto Serif", StringComparison.OrdinalIgnoreCase) >= 0) { return val; } if (obj == null && (text.IndexOf("Japanese", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("JP", StringComparison.OrdinalIgnoreCase) >= 0)) { obj = val; } } } return obj; } catch { return null; } } private void OnDestroy() { if (posX != null) { posX.SettingChanged -= OnPositionSettingChanged; } if (posY != null) { posY.SettingChanged -= OnPositionSettingChanged; } if ((Object)(object)backgroundTexture != (Object)null) { Object.Destroy((Object)(object)backgroundTexture); } } private bool ShouldDisplay() { if ((Object)(object)EnvMan.instance != (Object)null) { return (Object)(object)Player.m_localPlayer != (Object)null; } return false; } private void RefreshText() { if (ShouldDisplay()) { float num = cachedWidth; float num2 = posX.Value + num; bool num3 = num > 0f && string.Equals(textAlignment.Value, "Right", StringComparison.OrdinalIgnoreCase) && defaultPositionInitialized; bool japanese = IsJapaneseUI(); cachedForecast = (showForecast.Value ? GetForecastText(japanese) : string.Empty); cachedText = string.Empty; cachedLines = GetDisplayLines(); cachedWidth = CalculatePanelWidth(cachedLines); cachedPanelHeight = CalculatePanelHeight(cachedLines); if (num3) { posX.Value = Mathf.Clamp(num2 - (float)cachedWidth, 0f, Mathf.Max(0f, (float)(Screen.width - cachedWidth))); } } } private bool IsJapaneseUI() { if (uiLanguage != null) { if (string.Equals(uiLanguage.Value, "Japanese", StringComparison.OrdinalIgnoreCase)) { return true; } if (string.Equals(uiLanguage.Value, "English", StringComparison.OrdinalIgnoreCase)) { return false; } } return IsGameLanguageJapanese(); } private static bool IsGameLanguageJapanese() { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Invalid comparison between Unknown and I4 try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { Type type = assemblies[i].GetType("Localization"); if (type == null) { continue; } PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public); object obj = ((property != null) ? property.GetValue(null, null) : null); if (obj == null) { continue; } MethodInfo method = type.GetMethod("GetSelectedLanguage", BindingFlags.Instance | BindingFlags.Public); if (!(method == null)) { string text = method.Invoke(obj, null) as string; if (!string.IsNullOrEmpty(text)) { return text.IndexOf("Japanese", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("日本", StringComparison.OrdinalIgnoreCase) >= 0; } } } } catch { } if ((int)Application.systemLanguage != 22) { return string.Equals(PlayerPrefs.GetString("language", "English"), "Japanese", StringComparison.OrdinalIgnoreCase); } return true; } private string FormatTime(float dayFraction) { int num = Mathf.FloorToInt(Mathf.Repeat(dayFraction, 1f) * 1440f); int num2 = num / 60; int num3 = num % 60; if (use24Hour.Value) { return $"{num2:00}:{num3:00}"; } int num4 = num2 % 12; if (num4 == 0) { num4 = 12; } string text = ((num2 < 12) ? "AM" : "PM"); if (IsJapaneseUI()) { return $"{text}{num4}:{num3:00}"; } return $"{num4}:{num3:00} {text}"; } private string GetCurrentWeather() { try { EnvSetup currentEnvironment = EnvMan.instance.GetCurrentEnvironment(); return (currentEnvironment == null) ? string.Empty : (currentEnvironment.m_name ?? string.Empty); } catch { return string.Empty; } } private string GetForecastText(bool japanese) { try { EnvMan instance = EnvMan.instance; if ((Object)(object)instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null) { return string.Empty; } EnvSetup currentEnvironment = instance.GetCurrentEnvironment(); if (currentEnvironment == null) { return string.Empty; } float floatField = GetFloatField(instance, "m_dayLengthSec"); float floatField2 = GetFloatField(instance, "m_environmentDuration"); if (floatField <= 0f || floatField2 <= 0f) { return string.Empty; } double num = (double)instance.GetDay() * (double)floatField + (double)(instance.GetDayFraction() * floatField); long num2 = (long)Math.Floor(num / (double)floatField2); double num3 = (float)(num2 + 1) * floatField2; string b = currentEnvironment.m_name ?? string.Empty; EnvSetup val = null; double num4 = num3; for (int i = 1; i <= 12; i++) { long num5 = num2 + i; EnvSetup val2 = SelectEnvironmentForPeriod(instance, num5); if (val2 != null && !string.Equals(val2.m_name, b, StringComparison.Ordinal)) { val = val2; num4 = (double)num5 * (double)floatField2; break; } } if (val == null || string.IsNullOrEmpty(val.m_name)) { return string.Empty; } double num6 = Math.Max(0.0, num4 - num); return "→ " + val.m_name + " " + FormatDuration((float)(num6 / (double)floatField)); } catch (Exception ex) { if (Time.frameCount % 300 == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Weather forecast unavailable: " + ex.Message)); } return string.Empty; } } private static float GetFloatField(object instance, string fieldName) { if (instance == null) { return 0f; } FieldInfo field = instance.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return 0f; } object value = field.GetValue(instance); if (value != null) { return Convert.ToSingle(value); } return 0f; } private static EnvSetup SelectEnvironmentForPeriod(EnvMan envMan, long period) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) try { Biome currentBiome = Player.m_localPlayer.GetCurrentBiome(); FieldInfo field = typeof(EnvMan).GetField("m_biomes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return null; } if (!(field.GetValue(envMan) is IEnumerable enumerable)) { return null; } object obj = null; foreach (object item in enumerable) { if (item == null) { continue; } FieldInfo field2 = item.GetType().GetField("m_biome", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field2 == null)) { object value = field2.GetValue(item); if (value != null && value.Equals(currentBiome)) { obj = item; break; } } } if (obj == null) { return null; } FieldInfo field3 = obj.GetType().GetField("m_environments", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field3 == null) { return null; } if (!(field3.GetValue(obj) is IEnumerable enumerable2)) { return null; } List<EnvSetup> list = new List<EnvSetup>(); List<float> list2 = new List<float>(); foreach (object item2 in enumerable2) { if (item2 == null) { continue; } Type type = item2.GetType(); FieldInfo field4 = type.GetField("m_env", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo field5 = type.GetField("m_weight", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field4 == null || field5 == null) { continue; } object? value2 = field4.GetValue(item2); EnvSetup val = (EnvSetup)((value2 is EnvSetup) ? value2 : null); if (val != null) { float num = Convert.ToSingle(field5.GetValue(item2)); if (!(num <= 0f)) { list.Add(val); list2.Add(num); } } } if (list.Count == 0) { return null; } State state = Random.state; try { Random.InitState((int)period); float num2 = 0f; for (int i = 0; i < list2.Count; i++) { num2 += list2[i]; } float num3 = Random.Range(0f, num2); float num4 = 0f; for (int j = 0; j < list.Count; j++) { num4 += list2[j]; if (num3 <= num4) { return list[j]; } } return list[list.Count - 1]; } finally { Random.state = state; } } catch { return null; } } private string FormatDuration(float dayFraction) { int num = Mathf.Max(1, Mathf.RoundToInt(dayFraction * 1440f)); int num2 = num / 60; int num3 = num % 60; if (num2 > 0) { return $"{num2:00}:{num3:00}"; } return $"00:{num3:00}"; } private int GetDeathCount() { try { if ((Object)(object)Game.instance == (Object)null) { return 0; } PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); if (playerProfile == null) { return 0; } FieldInfo field = typeof(PlayerProfile).GetField("m_playerStats", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return 0; } object value = field.GetValue(playerProfile); if (value == null) { return 0; } if (value is Array array) { if (array.Length == 0) { return 0; } value = array.GetValue(0); if (value == null) { return 0; } } FieldInfo field2 = value.GetType().GetField("m_stats", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 == null) { return 0; } if (field2.GetValue(value) is IDictionary dictionary) { foreach (DictionaryEntry item in dictionary) { if (item.Key != null && string.Equals(item.Key.ToString(), "Deaths", StringComparison.OrdinalIgnoreCase)) { return Mathf.RoundToInt(Convert.ToSingle(item.Value)); } } } } catch (Exception ex) { if (Time.frameCount % 300 == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not read death count: " + ex.Message)); } } return 0; } } }