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."); } } }
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."); } } } }