bbepis / XUnity.AutoTranslator

MIT License
1.89k stars 288 forks source link

Can not Open the Control Pan in the Game #443

Open incredibleIdea opened 10 months ago

incredibleIdea commented 10 months ago
image

Error like the pic. XUnity.AutoTranslator Version: 5.3.0
BepInEx version: x64_5.4.22.0
Game's name: Lethal Company
Stream store Link: https://store.steampowered.com/app/1966720/Lethal_Company/

odocha0986 commented 10 months ago

you want to open alt + 0 right?

incredibleIdea commented 10 months ago

Yes, I search the error online. it seems like to say legacy input method is not support.But i can't import InputSystem with UnityEngine.dll And I am not found UnityEngine.InputSystem.dll

lis0 commented 9 months ago

same here

Atamg1994 commented 9 months ago

I partially solved the problem like this buttons work correctly ALT + T: Alternate between translated and untranslated versions of all texts provided by this plugin. ALT + R: Reload translation files. Useful if you change the text and texture files on the fly. Not guaranteed to work for all textures. ALT + U: Manual hooking. The default hooks wont always pick up texts. This will attempt to make lookups manually. Will not hook text components from frameworks not enabled. ALT + F: If OverrideFont is configured, will toggle between overridden and default font. ALT + Q: Reboot the plugin if it was shutdown. This will only work if the plugin was shut down due to consecutive errors towards the translation endpoint. Should only be used if you have reason to believe you have remedied the problem (such as changed VPN endpoint etc.) otherwise it will just shut down again. Debugging-only keys:

CTRL + ALT + NP9: Simulate synchronous errors CTRL + ALT + NP8: Simulate asynchronous errors delayed by one second CTRL + ALT + NP7: Print out loaded scene names and ids to console CTRL + ALT + NP6: Print out entire GameObject hierarchy to file hierarchy.txt

Unfortunately It was not possible to patch the interface; we need to edit the translator library directly

The code below can be inserted into any mod (or create your own mod) I have this library that replaces fonts in the game with "arial unicode ms" for the correct display of Russian there. I also embedded the code below to remove an error that during the game can create a bunch of errors in the log file and the file weighs a lot

The font change mod itself is written for melon loader 0.5.7 but you can also run it on Bepinex via MLLoader but this is not a completely different problem, so I have attached a code that partially solves it if you need a mod let me know

using System;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;

namespace FontOverride.input_path
{
    // Token: 0x0200002F RID: 47
    public static class InputPatch
    {
        // Token: 0x02000030 RID: 48
        [HarmonyPatch(typeof(Input), "GetKey", new Type[]
        {
            typeof(KeyCode)
        })]
        public static class GetKeyPatch
        {
            // Token: 0x06000183 RID: 387 RVA: 0x00002732 File Offset: 0x00000932
            [HarmonyPrefix]
            public static bool PrefixGetKey(KeyCode key, ref bool __result)
            {
                if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate)
                {
                    __result = Keyboard.current[KeyCodeMapper.MapToNewKey(key)].isPressed;
                    return false;
                }
                return true;
            }
        }

        // Token: 0x02000031 RID: 49
        [HarmonyPatch(typeof(Input), "GetKeyUp", new Type[]
        {
            typeof(KeyCode)
        })]
        public static class GetKeyUpPatch
        {
            // Token: 0x06000184 RID: 388 RVA: 0x0000275B File Offset: 0x0000095B
            [HarmonyPrefix]
            public static bool PrefixGetKeyUp(KeyCode key, ref bool __result)
            {
                if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate)
                {
                    __result = Keyboard.current[KeyCodeMapper.MapToNewKey(key)].wasReleasedThisFrame;
                    return false;
                }
                return true;
            }
        }

        // Token: 0x02000032 RID: 50
        [HarmonyPatch(typeof(Input), "GetKey", new Type[]
        {
            typeof(string)
        })]
        public static class GetKeyStringPatch
        {
            // Token: 0x06000185 RID: 389 RVA: 0x00002784 File Offset: 0x00000984
            [HarmonyPrefix]
            public static bool PrefixGetKeyString(string name, ref bool __result)
            {
                if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate)
                {
                    __result = Keyboard.current[Keyboard.current.FindKeyOnCurrentKeyboardLayout(name).keyCode].isPressed;
                    return false;
                }
                return true;
            }
        }

        // Token: 0x02000033 RID: 51
        [HarmonyPatch(typeof(Input), "GetKeyDown", new Type[]
        {
            typeof(KeyCode)
        })]
        public static class GetKeyDownPatch
        {
            // Token: 0x06000186 RID: 390 RVA: 0x000027B7 File Offset: 0x000009B7
            [HarmonyPrefix]
            public static bool PrefixGetKeyDown(KeyCode key, ref bool __result)
            {
                if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate)
                {
                    __result = Keyboard.current[KeyCodeMapper.MapToNewKey(key)].wasPressedThisFrame;
                    return false;
                }
                return true;
            }
        }

        // Token: 0x02000034 RID: 52
        [HarmonyPatch(typeof(Input), "GetKeyDown", new Type[]
        {
            typeof(string)
        })]
        public static class GetKeyDownStringPatch
        {
            // Token: 0x06000187 RID: 391 RVA: 0x000027E0 File Offset: 0x000009E0
            [HarmonyPrefix]
            public static bool PrefixGetKeyDownString(string name, ref bool __result)
            {
                if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate)
                {
                    __result = Keyboard.current[Keyboard.current.FindKeyOnCurrentKeyboardLayout(name).keyCode].wasPressedThisFrame;
                    return false;
                }
                return true;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

namespace FontOverride.input_path
{
    // Token: 0x02000035 RID: 53
    public static class KeyCodeMapper
    {
        // Token: 0x06000188 RID: 392 RVA: 0x00007D28 File Offset: 0x00005F28
        private static void Initialize()
        {
            if (KeyCodeMapper.initialized)
            {
                return;
            }
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary["LeftCtrl"] = "LeftControl";
            dictionary["RightCtrl"] = "RightControl";
            dictionary["LeftMeta"] = "LeftApple";
            dictionary["RightMeta"] = "RightApple";
            dictionary["ContextMenu"] = "Menu";
            dictionary["PrintScreen"] = "Print";
            dictionary["Enter"] = "Return";
            foreach (object obj in Enum.GetValues(typeof(Key)))
            {
                string text = obj.ToString();
                int value = (int)obj;
                string text2;
                if (text.StartsWith("Numpad"))
                {
                    text = text.Replace("Numpad", "Keypad");
                }
                else if (text.StartsWith("Digit"))
                {
                    text = text.Replace("Digit", "Alpha");
                }
                else if (dictionary.TryGetValue(text, out text2))
                {
                    text = text2;
                }
                KeyCode key;
                if (KeyCodeMapper.TryEnumParse<KeyCode>(text, out key))
                {
                    KeyCodeMapper.keyCodeToIndex[key] = value;
                }
            }
            foreach (object obj2 in Enum.GetValues(typeof(KeyCode)))
            {
                KeyCode keyCode = (KeyCode)obj2;
                Key key2;
                if (Enum.TryParse<Key>(Enum.GetName(typeof(KeyCode), keyCode), out key2))
                {
                    KeyCodeMapper.keyMappings[(int)keyCode] = key2;
                }
            }
            KeyCodeMapper.initialized = true;
        }

        // Token: 0x06000189 RID: 393 RVA: 0x00007EF0 File Offset: 0x000060F0
        public static Key MapToNewKey(KeyCode oldKeyCode)
        {
            KeyCodeMapper.Initialize();
            int result;
            if (KeyCodeMapper.keyCodeToIndex.TryGetValue(oldKeyCode, out result))
            {
                return (Key)result;
            }
            if (oldKeyCode >= KeyCode.None && oldKeyCode < (KeyCode)KeyCodeMapper.keyMappings.Length)
            {
                return KeyCodeMapper.keyMappings[(int)oldKeyCode];
            }
            return Key.None;
        }

        // Token: 0x0600018A RID: 394 RVA: 0x00002813 File Offset: 0x00000A13
        static KeyCodeMapper()
        {
            KeyCodeMapper.keyMappings = new Key[Enum.GetValues(typeof(KeyCode)).Length];
        }

        // Token: 0x0600018B RID: 395 RVA: 0x00007F2C File Offset: 0x0000612C
        private static bool TryEnumParse<T>(string name, out T val)
        {
            bool result;
            try
            {
                val = (T)((object)Enum.Parse(typeof(T), name, true));
                result = true;
            }
            catch (Exception)
            {
                val = default(T);
                result = false;
            }
            return result;
        }

        // Token: 0x04000093 RID: 147
        private static bool initialized = false;

        // Token: 0x04000094 RID: 148
        private static readonly Key[] keyMappings;

        // Token: 0x04000095 RID: 149
        private static readonly Dictionary<KeyCode, int> keyCodeToIndex = new Dictionary<KeyCode, int>();
    }
}
Atamg1994 commented 9 months ago

UnityEngine.dll And I am not found UnityEngine.InputSystem.dll

And about the library where the new input method, the library (file) itself is called "Unity.InputSystem.dll"

image

omaryomario commented 9 months ago

@Atamg1994 How can i use this or install it??

Atamg1994 commented 9 months ago

@Atamg1994 How can i use this or install it??

use the code above to create a mod for bepinex loader, or melon loader. if you don’t know how - take any mod that you have and edit it using “DNSPY” - software for debugging and editing C# libraries and install the mod as you usually install mods!