mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
More text able to be loaded and translated
This commit is contained in:
1 parent
3292e5b713
commit
a810d4ab7a
3 files changed
+33
-10
No files matched your search
@@ -61,6 +61,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DynamicTranslator.cs" />
|
||||
<Compile Include="Hooks.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -38,11 +38,18 @@ namespace DynamicTranslationLoader
|
||||
|
||||
var harmony = HarmonyInstance.Create("com.bepis.bepinex.dynamictranslationloader");
|
||||
|
||||
|
||||
MethodInfo original = AccessTools.Property(typeof(TMP_Text), "text").GetSetMethod();
|
||||
|
||||
HarmonyMethod prefix = new HarmonyMethod(typeof(DynamicTranslator).GetMethod("LabelTextHook"));
|
||||
HarmonyMethod prefix = new HarmonyMethod(typeof(Hooks).GetMethod("LabelTextHook"));
|
||||
|
||||
harmony.Patch(original, prefix, null);
|
||||
|
||||
|
||||
original = AccessTools.Method(typeof(TMP_Text), "SetText", new[] { typeof(string) });
|
||||
|
||||
prefix = new HarmonyMethod(typeof(Hooks).GetMethod("SetTextHook"));
|
||||
|
||||
harmony.Patch(original, prefix, null);
|
||||
}
|
||||
|
||||
@@ -51,9 +58,9 @@ namespace DynamicTranslationLoader
|
||||
TranslateAll();
|
||||
}
|
||||
|
||||
void OnUpdate()
|
||||
void Update()
|
||||
{
|
||||
if (UnityEngine.Event.current.Equals(Event.KeyboardEvent("f10")))
|
||||
if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.F10))
|
||||
{
|
||||
Dump();
|
||||
Console.WriteLine($"Text dumped to \"{Path.GetFullPath("dumped-tl.txt")}\"");
|
||||
@@ -62,7 +69,7 @@ namespace DynamicTranslationLoader
|
||||
|
||||
void TranslateAll()
|
||||
{
|
||||
foreach (TextMeshProUGUI gameObject in GameObject.FindObjectsOfType<TextMeshProUGUI>())
|
||||
foreach (TextMeshProUGUI gameObject in Resources.FindObjectsOfTypeAll<TextMeshProUGUI>())
|
||||
{
|
||||
//gameObject.text = "Harsh is shit";
|
||||
|
||||
@@ -91,7 +98,7 @@ namespace DynamicTranslationLoader
|
||||
File.WriteAllText("dumped-tl.txt", output);
|
||||
}
|
||||
|
||||
static string Translate(string input)
|
||||
public static string Translate(string input)
|
||||
{
|
||||
if (translations.ContainsKey(input))
|
||||
return translations[input];
|
||||
@@ -101,10 +108,5 @@ namespace DynamicTranslationLoader
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static void LabelTextHook(ref string value)
|
||||
{
|
||||
value = Translate(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DynamicTranslationLoader
|
||||
{
|
||||
public static class Hooks
|
||||
{
|
||||
public static void LabelTextHook(ref string value)
|
||||
{
|
||||
value = DynamicTranslator.Translate(value);
|
||||
}
|
||||
|
||||
public static void SetTextHook(ref string text)
|
||||
{
|
||||
text = DynamicTranslator.Translate(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user