Decompiled source of MissingDialogueFix v1.1.0

SoDDialogueFix.dll

Decompiled 2 weeks ago
using System;
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 BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Globalization;
using Il2CppSystem.Threading;
using Microsoft.CodeAnalysis;
using TMPro;
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("SoDDialogueFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("SoDDialogueFix")]
[assembly: AssemblyTitle("SoDDialogueFix")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 SoDDialogueFix
{
	internal static class ConfigWatch
	{
		private static ConfigFile? file;

		private static ManualLogSource? log;

		private static DateTime seen;

		private static DateTime pending;

		private static float next;

		private static bool reading;

		private static readonly List<string> changed = new List<string>();

		internal static void Start(BasePlugin plugin)
		{
			if (file != null)
			{
				return;
			}
			try
			{
				file = plugin.Config;
				log = plugin.Log;
				seen = Stamp();
				file.SettingChanged += delegate(object _, SettingChangedEventArgs e)
				{
					if (reading)
					{
						changed.Add(e.ChangedSetting.Definition.Section + "/" + e.ChangedSetting.Definition.Key);
					}
				};
				plugin.AddComponent<ConfigWatchPump>();
			}
			catch (Exception ex)
			{
				plugin.Log.LogWarning((object)("[CONFIG] live settings off: " + ex.Message));
			}
		}

		private static DateTime Stamp()
		{
			try
			{
				if (file == null)
				{
					return default(DateTime);
				}
				DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(file.ConfigFilePath);
				return (lastWriteTimeUtc.Year < 1700) ? default(DateTime) : lastWriteTimeUtc;
			}
			catch
			{
				return default(DateTime);
			}
		}

		internal static void Tick()
		{
			if (file == null)
			{
				return;
			}
			if (next == 0f)
			{
				next = Time.unscaledTime + 1f + (float)(file.ConfigFilePath.GetHashCode() & 0xFF) / 256f;
			}
			if (Time.unscaledTime < next)
			{
				return;
			}
			next = Time.unscaledTime + 1f;
			DateTime dateTime = Stamp();
			if (dateTime == default(DateTime) || dateTime == seen)
			{
				pending = default(DateTime);
				return;
			}
			if (dateTime != pending)
			{
				pending = dateTime;
				return;
			}
			pending = default(DateTime);
			bool saveOnConfigSet = file.SaveOnConfigSet;
			reading = true;
			changed.Clear();
			try
			{
				file.SaveOnConfigSet = false;
				file.Reload();
				seen = dateTime;
			}
			catch (Exception ex)
			{
				ManualLogSource? obj = log;
				if (obj != null)
				{
					obj.LogWarning((object)("[CONFIG] could not read the settings: " + ex.Message));
				}
			}
			finally
			{
				reading = false;
				file.SaveOnConfigSet = saveOnConfigSet;
			}
			if (changed.Count > 0)
			{
				ManualLogSource? obj2 = log;
				if (obj2 != null)
				{
					obj2.LogInfo((object)("[CONFIG] settings changed while playing: " + string.Join(", ", changed)));
				}
			}
		}
	}
	public sealed class ConfigWatchPump : MonoBehaviour
	{
		public ConfigWatchPump(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			try
			{
				ConfigWatch.Tick();
			}
			catch
			{
			}
		}
	}
	[BepInPlugin("sm3gm.sod.dialoguefix", "Missing Dialogue Fix", "1.1.0")]
	public sealed class Plugin : BasePlugin
	{
		public const string VER = "1.1.0";

		internal static ManualLogSource L;

		internal static ConfigEntry<bool> Mornings;

		internal static ConfigEntry<bool> FixBlank;

		public override void Load()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			ConfigWatch.Start((BasePlugin)(object)this);
			L = ((BasePlugin)this).Log;
			Turkish.Apply((BasePlugin)(object)this);
			Mornings = ((BasePlugin)this).Config.Bind<bool>("Dialogue", "GoodMorning", true, "People say \"Good morning\" in the morning. The game only knew afternoon and evening, so from 3 until 12 it said \"Good evening\".");
			FixBlank = ((BasePlugin)this).Config.Bind<bool>("Dialogue", "ShowInvisibleText", true, "Shows the words in speech bubbles that would otherwise be an empty box.");
			new Harmony("sm3gm.sod.dialoguefix").PatchAll(typeof(Patches));
			ManualLogSource l = L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Missing Dialogue Fix ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
			}
			l.LogInfo(val);
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		private static int fixedCount;

		private static int told;

		private static int colours;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Strings), "GetContainedValue")]
		private static void TimeOfDay(string newValue, ref string __result)
		{
			try
			{
				if (!Plugin.Mornings.Value || __result == null || newValue == null || !newValue.Equals("timeofday", StringComparison.OrdinalIgnoreCase))
				{
					return;
				}
				SessionData instance = SessionData.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				float decimalClock = instance.decimalClock;
				if (decimalClock < 3f || decimalClock >= 12f)
				{
					return;
				}
				string b = Strings.Get("misc", "evening", (Casing)0, false, false, false, (Human)null);
				if (string.Equals(__result, b, StringComparison.OrdinalIgnoreCase))
				{
					string text = Strings.Get("misc", "morning", (Casing)0, false, false, false, (Human)null);
					if (!string.IsNullOrEmpty(text))
					{
						__result = (char.IsUpper(__result[0]) ? (char.ToUpper(text[0]) + text.Substring(1)) : text);
					}
				}
			}
			catch
			{
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SpeechBubbleController), "Update")]
		private static void Update(SpeechBubbleController __instance)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.FixBlank.Value)
				{
					return;
				}
				TextMeshProUGUI text = __instance.text;
				Image backgroundImg = __instance.backgroundImg;
				if ((Object)(object)text == (Object)null || (Object)(object)backgroundImg == (Object)null)
				{
					return;
				}
				Color color = ((Graphic)text).color;
				if (color.a >= 0.05f)
				{
					return;
				}
				float a = ((((Graphic)backgroundImg).color.a >= 0.05f) ? ((Graphic)backgroundImg).color.a : 1f);
				if (color.r < 0.01f && color.g < 0.01f && color.b < 0.01f)
				{
					color.r = 1f;
					color.g = 1f;
					color.b = 1f;
				}
				color.a = a;
				((Graphic)text).color = color;
				fixedCount++;
				if (told >= 20)
				{
					return;
				}
				told++;
				string text2 = "-";
				try
				{
					SpeechController speechController = __instance.speechController;
					object obj;
					if (speechController == null)
					{
						obj = null;
					}
					else
					{
						Actor actor = speechController.actor;
						obj = ((actor != null) ? ((Object)actor).name : null);
					}
					if (obj == null)
					{
						obj = "-";
					}
					text2 = (string)obj;
				}
				catch
				{
				}
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(49, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[DIALOGUE] text made visible (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(fixedCount);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" so far) for '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(__instance.actualString);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
				}
				l.LogInfo(val);
			}
			catch
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SpeechController), "Speak", new Type[]
		{
			typeof(string),
			typeof(string),
			typeof(bool),
			typeof(bool),
			typeof(bool),
			typeof(float),
			typeof(bool),
			typeof(Color),
			typeof(Human),
			typeof(bool),
			typeof(bool),
			typeof(SideJob),
			typeof(DialogPreset),
			typeof(AISpeechPreset),
			typeof(Interactable),
			typeof(InteractionDialogInstance)
		})]
		private static void Speak(string dictionary, string speechEntryRef, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(color.a >= 0.05f) && colours < 15)
				{
					colours++;
					ManualLogSource l = Plugin.L;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(53, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[DIALOGUE] line asked for with see-through colour ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Color>(color);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(dictionary);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(speechEntryRef);
					}
					l.LogInfo(val);
				}
			}
			catch
			{
			}
		}
	}
	internal static class Turkish
	{
		internal static void Apply(BasePlugin plugin)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			ConfigEntry<bool> val = plugin.Config.Bind<bool>("Turkish", "FixCapitalI", true, "Texts with a capital I (Install, Inspect and many more) show up on a PC set to Turkish or Azerbaijani. Does nothing on any other language.");
			if (plugin.Config.Bind<bool>("Turkish", "SimulateTurkish", false, "For testing on any PC: the game uses Turkish letter rules from the start, so the missing texts can be seen. With FixCapitalI on as well, the fix then repairs them. Leave off for normal play.").Value)
			{
				Set(new CultureInfo("tr-TR"), "simulating a Turkish PC");
			}
			string text = "?";
			try
			{
				CultureInfo currentCulture = CultureInfo.CurrentCulture;
				text = ((currentCulture != null) ? currentCulture.Name : null) ?? "?";
			}
			catch
			{
			}
			string name = CultureInfo.CurrentCulture.Name;
			bool flag = default(bool);
			if (!val.Value)
			{
				ManualLogSource l = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(50, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[TURKISH] switched off in the config (language '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("')");
				}
				l.LogInfo(val2);
			}
			else if (!Affected(text) && !Affected(name))
			{
				ManualLogSource l2 = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(52, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[TURKISH] language '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' is not affected, nothing to do");
				}
				l2.LogInfo(val2);
			}
			else
			{
				Neutral("at start");
				plugin.AddComponent<TurkishAgain>();
			}
		}

		private static bool Affected(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return false;
			}
			string text = ((name.Length >= 2) ? name.Substring(0, 2).ToLowerInvariant() : name);
			if (!(text == "tr"))
			{
				return text == "az";
			}
			return true;
		}

		private static void Set(CultureInfo c, string why)
		{
			try
			{
				CultureInfo.s_DefaultThreadCurrentCulture = c;
				CultureInfo.s_DefaultThreadCurrentUICulture = c;
				CultureInfo.default_current_culture = c;
				Thread.m_CurrentCulture = c;
				Thread.m_CurrentUICulture = c;
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("[TURKISH] " + why + ": " + ex.GetType().Name + " " + ex.Message));
			}
		}

		internal static void Neutral(string when)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			string text = "?";
			try
			{
				CultureInfo currentCulture = CultureInfo.CurrentCulture;
				text = ((currentCulture != null) ? currentCulture.Name : null) ?? "?";
			}
			catch
			{
			}
			if (text.Length == 0)
			{
				text = "neutral";
			}
			Set(CultureInfo.InvariantCulture, "game side");
			try
			{
				CultureInfo.CurrentUICulture = (CultureInfo.CurrentCulture = (CultureInfo.DefaultThreadCurrentUICulture = (CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture)));
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("[TURKISH] mod side: " + ex.GetType().Name + " " + ex.Message));
			}
			string text2 = "?";
			try
			{
				text2 = String.op_Implicit("INSTALL").ToLower();
			}
			catch (Exception ex2)
			{
				text2 = ex2.GetType().Name;
			}
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(62, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TURKISH] ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(when);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": language was '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', now neutral; test 'INSTALL' -> '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
			}
			l.LogInfo(val);
		}
	}
	public class TurkishAgain : MonoBehaviour
	{
		private int frames;

		public TurkishAgain(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			if (++frames >= 2)
			{
				Turkish.Neutral("on the main thread");
				Object.Destroy((Object)(object)this);
			}
		}
	}
}