Ejemplo n.º 1
0
        public static void BlockIfConfigured(WindowFunction function, int windowId)
        {
            if (Settings.BlacklistedIMGUIPlugins.Count == 0)
            {
                return;
            }

            var method = function.Method;

            if (!HandledMethods.Contains(method))
            {
                HandledMethods.Add(method);

                try
                {
                    if (IsBlackslisted(method))
                    {
                        XuaLogger.AutoTranslator.Info("Attempting to hook " + method.DeclaringType.FullName.ToString() + "." + method.Name + " to disable translation in window.");

                        IMGUIWindow_Function_Hook.Register(method);
                        HookingHelper.PatchType(typeof(IMGUIWindow_Function_Hook), Settings.ForceMonoModHooks);
                        IMGUIWindow_Function_Hook.Clean();
                    }
                }
                catch (Exception e)
                {
                    XuaLogger.AutoTranslator.Error(e, "An error occurred while attempting to hook " + method.DeclaringType.FullName.ToString() + " to disable translation in window.");
                }
            }
        }
Ejemplo n.º 2
0
        public static void HookIfConfigured(MethodInfo method)
        {
            if (!HandledMethods.Contains(method))
            {
                HandledMethods.Add(method);

                if (!HookedMethods.Contains(method))
                {
                    var methodName = method.DeclaringType.FullName.ToString() + "." + method.Name;
                    try
                    {
                        var assembly = method.DeclaringType.Assembly;
                        if (!AutoTranslationPlugin.Current.PluginTextCaches.TryGetValue(assembly.GetName().Name, out var cache))
                        {
                            return;
                        }

                        XuaLogger.AutoTranslator.Info("Attempting to hook " + methodName + " to enable plugin specific translations.");

                        var behaviour = method.DeclaringType.Assembly
                                        .GetTypes()
                                        .FirstOrDefault(x => typeof(MonoBehaviour).IsAssignableFrom(x));

                        if (behaviour == null)
                        {
                            XuaLogger.AutoTranslator.Warn("Could not find any MonoBehaviours in assembly owning method the method: " + methodName);
                            return;
                        }
                        var behaviourType = behaviour.GetType();

                        var translationCache = AutoTranslationPlugin.Current.TextCache.GetOrCreateCompositeCache(cache);

                        var pluginCallbackType = typeof(PluginCallbacks_Function_Hook <>).MakeGenericType(behaviourType);
                        pluginCallbackType
                        .GetMethod("Register", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                        .Invoke(null, new object[] { method });
                        pluginCallbackType
                        .GetMethod("SetTextCache", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                        .Invoke(null, new object[] { translationCache });

                        HookingHelper.PatchType(pluginCallbackType, Settings.ForceMonoModHooks);

                        HookedMethods.Add(method);

                        pluginCallbackType
                        .GetMethod("Clean", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                        .Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        XuaLogger.AutoTranslator.Error(e, "An error occurred while attempting to hook " + methodName + " to disable translation in window.");
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public static void InstallTextAssetHooks()
 {
     try
     {
         HookingHelper.PatchAll(TextAssetHooks.All, Settings.ForceMonoModHooks);
     }
     catch (Exception e)
     {
         XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up text asset hooks.");
     }
 }
Ejemplo n.º 4
0
 public static void InstallTextGetterCompatHooks()
 {
     try
     {
         if (Settings.TextGetterCompatibilityMode)
         {
             HookingHelper.PatchAll(TextGetterCompatHooks.All, Settings.ForceMonoModHooks);
         }
     }
     catch (Exception e)
     {
         XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up text getter compat hooks.");
     }
 }
Ejemplo n.º 5
0
 public static void InstallSpriteRendererHooks()
 {
     try
     {
         if (Settings.EnableSpriteRendererHooking && (Settings.EnableTextureTranslation || Settings.EnableTextureDumping))
         {
             HookingHelper.PatchAll(ImageHooks.SpriteRenderer, Settings.ForceMonoModHooks);
         }
     }
     catch (Exception e)
     {
         XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up image hooks.");
     }
 }
Ejemplo n.º 6
0
        public static void InstallTextGetterCompatHooks()
        {
            try
            {
                if (Settings.TextGetterCompatibilityMode)
                {
#if MANAGED
                    HookingHelper.PatchAll(TextGetterCompatHooks.All, Settings.ForceMonoModHooks);
#else
                    throw new NotImplementedException("TextGetterCompatibilityMode is not supported in IL2CPP.");
#endif
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up text getter compat hooks.");
            }
        }
Ejemplo n.º 7
0
 public static void InstallComponentBasedPluginTranslationHooks()
 {
     if (AutoTranslationPlugin.Current.PluginTextCaches.Count > 0)
     {
         if (!_installedPluginTranslationHooks)
         {
             _installedPluginTranslationHooks = true;
             try
             {
                 HookingHelper.PatchAll(PluginTranslationHooks.All, Settings.ForceMonoModHooks);
             }
             catch (Exception e)
             {
                 XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for Plugin translations.");
             }
         }
     }
 }
Ejemplo n.º 8
0
        public static void InstallComponentBasedPluginTranslationHooks()
        {
            if (AutoTranslationPlugin.Current.PluginTextCaches.Count > 0)
            {
                if (!_installedPluginTranslationHooks)
                {
                    _installedPluginTranslationHooks = true;
                    try
                    {
#if MANAGED
                        HookingHelper.PatchAll(PluginTranslationHooks.All, Settings.ForceMonoModHooks);
#else
                        throw new NotImplementedException("Plugin specific hooks are not supported in IL2CPP.");
#endif
                    }
                    catch (Exception e)
                    {
                        XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for Plugin translations.");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void InstallTextHooks()
        {
            try
            {
                if (Settings.EnableUGUI)
                {
                    HookingHelper.PatchAll(UGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for UGUI.");
            }

            try
            {
                if (Settings.EnableTextMeshPro)
                {
                    HookingHelper.PatchAll(TextMeshProHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for TextMeshPro.");
            }

            try
            {
                if (Settings.EnableNGUI)
                {
                    HookingHelper.PatchAll(NGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for NGUI.");
            }

            try
            {
                if (Settings.EnableIMGUI)
                {
                    HookingHelper.PatchAll(IMGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for IMGUI.");
            }

            try
            {
                HookingHelper.PatchAll(UtageHooks.All, Settings.ForceMonoModHooks);
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for Utage.");
            }

            try
            {
                if (Settings.EnableTextMesh)
                {
                    HookingHelper.PatchAll(TextMeshHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for TextMesh.");
            }
        }
Ejemplo n.º 10
0
        public static void InstallTextHooks()
        {
            try
            {
                if (Settings.EnableUGUI)
                {
                    HookingHelper.PatchAll(UGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for UGUI.");
            }

            try
            {
                if (Settings.EnableTextMeshPro)
                {
                    HookingHelper.PatchAll(TextMeshProHooks.All, Settings.ForceMonoModHooks);

                    if (Settings.DisableTextMeshProScrollInEffects)
                    {
                        HookingHelper.PatchAll(TextMeshProHooks.DisableScrollInTmp, Settings.ForceMonoModHooks);
                    }
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for TextMeshPro.");
            }

            try
            {
                if (Settings.EnableNGUI)
                {
                    HookingHelper.PatchAll(NGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for NGUI.");
            }

            try
            {
                if (Settings.EnableIMGUI)
                {
#if MANAGED
                    HookingHelper.PatchAll(IMGUIHooks.All, Settings.ForceMonoModHooks);
#else
                    throw new NotImplementedException("EnableIMGUI is not supported in IL2CPP.");
#endif
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for IMGUI.");
            }

            try
            {
                HookingHelper.PatchAll(UtageHooks.All, Settings.ForceMonoModHooks);
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for Utage.");
            }

            try
            {
                if (Settings.EnableTextMesh)
                {
                    HookingHelper.PatchAll(TextMeshHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for TextMesh.");
            }

            try
            {
                if (Settings.EnableFairyGUI)
                {
                    HookingHelper.PatchAll(FairyGUIHooks.All, Settings.ForceMonoModHooks);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while setting up hooks for FairyGUI.");
            }
        }