From 6af4bf1c99845e4188c275dcf07310f3dc5c5b2e Mon Sep 17 00:00:00 2001 From: Christina <122680126+HayashiUme@users.noreply.github.com> Date: Fri, 10 Jul 2026 15:19:18 +0800 Subject: [PATCH] Fix PrivacyPolicy PopUp (#648) * Fix PrivacyPolicy PopUp * Rename and Adjust text size --- Main.cs | 4 +- Modules/ModConsentPopUp.cs | 133 ++++++++++++++++++++++++++++++++ Patches/ClientPatch.cs | 7 +- Patches/MainMenuManagerPatch.cs | 2 +- Resources/Lang/en_US.json | 4 +- Resources/Lang/zh_CN.json | 4 +- 6 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 Modules/ModConsentPopUp.cs diff --git a/Main.cs b/Main.cs index 361beee9a..e7d6b37d4 100644 --- a/Main.cs +++ b/Main.cs @@ -250,7 +250,7 @@ public class Main : BasePlugin public static ConfigEntry BetaBuildUrl { get; private set; } public static ConfigEntry LastKillCooldown { get; private set; } public static ConfigEntry LastShapeshifterCooldown { get; private set; } - public static ConfigEntry AckdPrivacyPolicy { get; private set; } + public static ConfigEntry AckdConsentPopup { get; private set; } public static PlayerControl[] AllPlayerControlsToArray => CachedAllPlayerControlsList.ToArray(); public static PlayerControl[] AllAlivePlayerControlsToArray => CachedAlivePlayerControlsList.ToArray(); @@ -437,7 +437,7 @@ public class Main : BasePlugin MessageWait = Config.Bind("Other", "MessageWait", 0); LastKillCooldown = Config.Bind("Other", "LastKillCooldown", (float)30); LastShapeshifterCooldown = Config.Bind("Other", "LastShapeshifterCooldown", (float)30); - AckdPrivacyPolicy = Config.Bind("Other", "AckdPrivacyPolicy", false); + AckdConsentPopup = Config.Bind("Other", "AckdConsentPopup", false); HasArgumentException = false; diff --git a/Modules/ModConsentPopUp.cs b/Modules/ModConsentPopUp.cs new file mode 100644 index 000000000..041a45f55 --- /dev/null +++ b/Modules/ModConsentPopUp.cs @@ -0,0 +1,133 @@ +using System; +using AmongUs.Data; +using HarmonyLib; +using TMPro; +using UnityEngine; +using static EHR.Translator; + +namespace EHR.Modules; + +public static class ModConsentPopUp +{ + public static bool IsShowingModPolicy { get; private set; } + private static int OriginalVersion { get; set; } + + public static void SetupCustomPolicy(PrivacyPolicyScreen screen) + { + if (screen == null) return; + + IsShowingModPolicy = true; + OriginalVersion = DataManager.Player.Onboarding.LastAcceptedPrivacyPolicyVersion; + + DestroyTranslator(screen.DefaultHyperlinkText); + DestroyTranslator(screen.PlayStationHyperlinkText); + + screen.DefaultHyperlinkText.Text = GetString("EHRConsentPopUp"); + screen.PlayStationHyperlinkText.Text = screen.DefaultHyperlinkText.Text; + + try + { + screen.OnTextUpdated(); + } + catch (Exception ex) + { + Logger.Warn($"OnTextUpdated() failed: {ex.StackTrace}", "ModPrivacyPolicy"); + } + + DataManager.Player.Onboarding.LastAcceptedPrivacyPolicyVersion = + Math.Max(0, OriginalVersion) == 0 ? -1 : OriginalVersion - 1; + + ConfigureButtons(screen); + + Logger.Info("Custom mod consent popup configured", "ModPrivacyPolicy"); + } + + private static void DestroyTranslator(OpenHyperlinks hyperlink) + { + if (hyperlink == null) return; + var translator = hyperlink.GetComponent(); + if (translator != null) + { + UnityEngine.Object.Destroy(translator); + } + } + + private static void ConfigureButtons(PrivacyPolicyScreen screen) + { + var acceptGO = screen.AcceptButton?.gameObject; + if (acceptGO == null) return; + + var acceptPassive = acceptGO.GetComponentInChildren(); + if (acceptPassive == null) return; + + acceptPassive.OnClick.RemoveAllListeners(); + acceptPassive.OnClick.AddListener((Action)(() => + { + Main.AckdConsentPopup.Value = true; + screen.Close(); + })); + + var acceptTMP = acceptGO.GetComponentInChildren(); + if (acceptTMP != null) + { + acceptTMP.DestroyTranslator(); + acceptTMP.text = GetString("Accept"); + } + + var disagreeGO = UnityEngine.Object.Instantiate(acceptGO, acceptGO.transform.parent); + disagreeGO.name = "DisagreeButton"; + + float z = acceptGO.transform.localPosition.z; + acceptGO.transform.localPosition = new Vector3(1.35f, -1.74f, z); + disagreeGO.transform.localPosition = new Vector3(-1.25f, -1.74f, z); + + var disagreePassive = disagreeGO.GetComponentInChildren(); + if (disagreePassive != null) + { + disagreePassive.OnClick.RemoveAllListeners(); + disagreePassive.OnClick.AddListener((Action)(() => + SplashLogoAnimatorPatch.SceneChanger.ExitGame())); + } + + var disagreeTMP = disagreeGO.GetComponentInChildren(); + if (disagreeTMP != null) + { + disagreeTMP.DestroyTranslator(); + disagreeTMP.text = GetString("Reject"); + } + + if (screen.ManageDataButton != null) + screen.ManageDataButton.gameObject.SetActive(false); + } + + public static void OnPolicyAccepted() + { + if (!IsShowingModPolicy) return; + IsShowingModPolicy = false; + + DataManager.Player.Onboarding.LastAcceptedPrivacyPolicyVersion = OriginalVersion; + DataManager.Player.Save(); + + Logger.Info("Mod consent popup accepted by user", "ModPrivacyPolicy"); + } + +} + +[HarmonyPatch(typeof(PrivacyPolicyScreen), nameof(PrivacyPolicyScreen.Show))] +internal static class PrivacyPolicyScreenShowPatch +{ + public static void Prefix(PrivacyPolicyScreen __instance) + { + if (!Main.AckdConsentPopup.Value) + ModConsentPopUp.SetupCustomPolicy(__instance); + } +} + +[HarmonyPatch(typeof(PrivacyPolicyScreen), nameof(PrivacyPolicyScreen.Close))] +internal static class PrivacyPolicyScreenClosePatch +{ + public static void Postfix() + { + ModConsentPopUp.OnPolicyAccepted(); + } +} diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index 82d538d5a..d1f78a199 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -90,11 +90,10 @@ internal static class RunLoginPatch public static void Prefix(ref bool canOnline) { if (DebugModeManager.AmDebugger) canOnline = true; - - if (!Main.AckdPrivacyPolicy.Value) + + if (!Main.AckdConsentPopup.Value) { - ModUpdater.ShowPopupWithTwoButtons(GetString("PrivacyPolicy"), GetString("Yes"), GetString("MainMenu.ExitGameButton"), () => Main.AckdPrivacyPolicy.Value = true, SplashLogoAnimatorPatch.SceneChanger.ExitGame); - return; + canOnline = true; } try { ModUpdater.ShowAvailableUpdate(); } diff --git a/Patches/MainMenuManagerPatch.cs b/Patches/MainMenuManagerPatch.cs index 2cbad3681..ba53d3f7e 100644 --- a/Patches/MainMenuManagerPatch.cs +++ b/Patches/MainMenuManagerPatch.cs @@ -118,7 +118,7 @@ public static class MainMenuManagerPatch public static void Start_Postfix(MainMenuManager __instance) { Instance = __instance; - + SimpleButton.SetBase(__instance.creditsButton); var logoObject = new GameObject("titleLogo_MG"); Transform logoTransform = logoObject.transform; diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index 966eee371..74debd8bf 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -24,7 +24,9 @@ "Server": "<#00ffa5>Server: ", "VersionMismatch": "{0} has a different version of the mod installed", "ModMismatch": "{0} has a different mod installed that isn't compatible with EHR <#ffff00>⚠", - "PrivacyPolicy": "Have you read and agree to the Privacy Policy and Code Of Conduct available on the mod's official GitHub repository?\\nYou must accept them to continue.", + "EHRConsentPopUp": "Welcome to Endless Host Roles!\\n\\nBy playing online with this mod, you acknowledge that certain technical and gameplay data may be processed in connection with mod services and platform interactions.\\n\\n> Privacy Policy - Covers what information is collected, how it is used, and under what circumstances it may be retained or acted upon.\\n\\n> Code of Conduct - Outlines the standards of behaviour expected of all players and the consequences of violations.\\n\\nPress Accept to confirm you have read and agree to both.", + "Reject": "Reject", + "Accept": "Accept", "Yes": "Yes", "No": "No", "None": "None", diff --git a/Resources/Lang/zh_CN.json b/Resources/Lang/zh_CN.json index 6f7d79ddf..4f7aa4e4f 100644 --- a/Resources/Lang/zh_CN.json +++ b/Resources/Lang/zh_CN.json @@ -24,7 +24,9 @@ "Server": "<#00ffa5>服务器:: ", "VersionMismatch": "{0} 安装了不同版本的模组", "ModMismatch": "{0} 安装了与 EHR 不兼容的模组", - "PrivacyPolicy": "您是否已阅读并同意模组官方 GitHub 仓库上的隐私政策和行为准则?\\n您必须接受它们才能继续。", + "EHRConsentPopUp": "Welcome to Endless Host Roles!\\n\\nBy playing online with this mod, you acknowledge that certain technical and gameplay data may be processed in connection with mod services and platform interactions.\\n\\n> Privacy Policy - Covers what information is collected, how it is used, and under what circumstances it may be retained or acted upon.\\n\\n> Code of Conduct - Outlines the standards of behaviour expected of all players and the consequences of violations.\\n\\nPress Accept to confirm you have read and agree to both.", + "Reject": "Reject", + "Accept": "Accept", "Yes": "是", "No": "否", "None": "空",