Decompiled source of Translations v1.0.2

WWAG_Translation.dll

Decompiled 7 months ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WWAG_Translation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WWAG_Translation")]
[assembly: AssemblyTitle("WWAG_Translation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace WWAG_Translation;

[BepInPlugin("org.NikoTheFox.Translation", "WWAG Translation", "0.0.3")]
public class GlyphTranslatorMod : BaseUnityPlugin
{
	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin WWAG Translation is loaded!");
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		if (((Scene)(ref scene)).name == "scene-overworld")
		{
			GameObject val = new GameObject("GlyphModController");
			val.AddComponent<TranslationController>().Init(this);
		}
	}

	private void OnEnable()
	{
		Debug.Log((object)"Plugin enabled");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}
}
public class TranslationController : MonoBehaviour
{
	private GlyphTranslatorMod mod;

	private float lastTalkTime = -3000f;

	public void Init(GlyphTranslatorMod mod)
	{
		this.mod = mod;
	}

	private void Start()
	{
		Debug.Log((object)"Starting routine");
		((MonoBehaviour)this).StartCoroutine(ScanAndTranslateTextRoutine());
	}

	private IEnumerator ScanAndTranslateTextRoutine()
	{
		while (true)
		{
			GameObject dialogueTextObj = GameObject.Find("dialogue-text(Clone)");
			if (Object.op_Implicit((Object)(object)dialogueTextObj) && !Object.op_Implicit((Object)(object)dialogueTextObj.GetComponent<ProcessedMarker>()))
			{
				Debug.Log((object)"Found Dialogue to translate");
				if (Time.time - lastTalkTime > 50f)
				{
					lastTalkTime = Time.time;
				}
				Transform canvasTransform = dialogueTextObj.transform.Find("canvas");
				if (Object.op_Implicit((Object)(object)canvasTransform))
				{
					Transform fitterTransform = canvasTransform.Find("fitter");
					if (Object.op_Implicit((Object)(object)fitterTransform))
					{
						Transform textTransform = fitterTransform.Find("text");
						if (Object.op_Implicit((Object)(object)textTransform))
						{
							TextMeshProUGUI textComponent = ((Component)textTransform).GetComponent<TextMeshProUGUI>();
							if (Object.op_Implicit((Object)(object)textComponent))
							{
								((TMP_Text)textComponent).text = TranslateText(((TMP_Text)textComponent).text);
							}
						}
					}
				}
			}
			yield return (object)new WaitForSeconds(1.5f);
		}
	}

	private void Update()
	{
		if (PlayerInteractedWithNPC())
		{
			HandleNPCInteraction();
		}
	}

	private bool PlayerInteractedWithNPC()
	{
		return false;
	}

	private void HandleNPCInteraction()
	{
	}

	public bool ShouldTranslateGlyph()
	{
		return Random.Range(0f, 100f) > 75f;
	}

	public string TranslateText(string input)
	{
		Debug.Log((object)"Translating text");
		StringBuilder stringBuilder = new StringBuilder();
		MatchCollection matchCollection = Regex.Matches(input, "<sprite=\"spell-glyphs\" name=\"glyphs-(?<glyph>\\w+)\" tint=1>|(?<other>[^<]+)");
		foreach (Match item in matchCollection)
		{
			if (item.Groups["glyph"].Success)
			{
				if (ShouldTranslateGlyph())
				{
					stringBuilder.Append(item.Groups["glyph"].Value);
				}
				else
				{
					stringBuilder.Append(item.Value);
				}
			}
			else if (item.Groups["other"].Success)
			{
				stringBuilder.Append(item.Groups["other"].Value);
			}
		}
		return stringBuilder.ToString();
	}
}
public class ProcessedMarker : MonoBehaviour
{
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "WWAG_Translation";

	public const string PLUGIN_NAME = "WWAG_Translation";

	public const string PLUGIN_VERSION = "1.0.0";
}