Better Host & Modded Server Fix

This commit is contained in:
D1GQ committed 2024-08-19 03:14:49 -05:00
1 parent 664f64f390
commit 285823d6fb
8 files changed
+67 -54

No files matched your search

+1 -1
View File
@@ -51,7 +51,7 @@ class BetterNotificationManager
player.Kick(true, $"<color=#ffea00>{player.Data.PlayerName}</color> banned by <color=#4f92ff>Anti-Cheat</color>!\n Reason: <color=#fc0000>{reason}</color>");
}
Logger.LogCheat(Utils.GetRawText(text));
Logger.LogCheat(Utils.RemoveHtmlText(text));
}
public static void Update()
+6 -2
View File
@@ -7,14 +7,18 @@ class Logger
{
string mark = $"{DateTime.Now:HH:mm} [BetterLog][{tag}]";
string logFilePath = Path.Combine(BetterDataManager.filePathFolder, "better-log.txt");
string newLine = $"{mark}: {info}";
string newLine = $"{mark}: {Utils.RemoveHtmlText(info)}";
File.AppendAllText(logFilePath, newLine + Environment.NewLine);
Main.Logger.LogInfo($"[{tag}] {info}");
}
public static void LogHeader(string info, string tag = "Log") => Log($" <-------------- {info} -------------->", tag);
public static void LogCheat(string info, string tag = "AntiCheat") => Log(info, tag);
public static void Error(string info, string tag = "Error") => Log(info, tag);
public static void Test() => Log("------------------> TEST <------------------", "TEST");
public static void Test()
{
Log("------------------> TEST <------------------", "TEST");
InGame("TEST");
}
// Log in game join msg
public static void InGame(string info)
{
+7 -9
View File
@@ -54,7 +54,7 @@ static class ExtendedPlayerControl
infoType = "InfoText_Info_TMP";
var topText = player.gameObject.transform.Find("Names/NameText_TMP/InfoText_T_TMP")?.GetComponent<TextMeshPro>();
if (topText != null && string.IsNullOrEmpty(Utils.GetRawText(topText.text)))
if (topText != null && string.IsNullOrEmpty(Utils.RemoveHtmlText(topText.text)))
{
text = "<voffset=-2.25em>" + text + "</voffset>";
}
@@ -115,18 +115,16 @@ static class ExtendedPlayerControl
if (setReasonInfo != "")
{
player.RpcSetName(setReasonInfo + "<size=0%>");
playerInfo.PlayerName = setReasonInfo + "<size=0%>";
player.SetName(setReasonInfo + "<size=0%>");
}
AmongUsClient.Instance.KickPlayer(player.GetClientId(), ban);
_ = new LateTask(() =>
{
AmongUsClient.Instance.KickPlayer(player.GetClientId(), ban);
_ = new LateTask(() =>
{
playerInfo.PlayerName = saveName;
}, 0.15f, shoudLog: false);
}, 0.25f, shoudLog: false);
playerInfo.PlayerName = saveName;
}, 0.15f, shoudLog: false);
}
// RPCs
+10 -2
View File
@@ -89,7 +89,12 @@ internal static class RPC
}
public static void SetNamePrivate(PlayerControl player, string name, PlayerControl target)
{
{
if (!GameStates.IsHost || !GameStates.IsVanillaServer)
{
return;
}
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SetName, SendOption.Reliable, target.GetClientId());
writer.Write(player.Data.NetId);
writer.Write(name);
@@ -98,7 +103,10 @@ internal static class RPC
public static void SyncAllNames(bool isForMeeting = false, bool force = false, bool isBetterHost = true)
{
if (!GameStates.IsHost) return;
if (!GameStates.IsHost || !GameStates.IsVanillaServer)
{
return;
}
foreach (PlayerControl player in Main.AllPlayerControls)
BetterHostManager.SetPlayersInfoAsHost(player, isForMeeting, force, isBetterHost);
+25 -1
View File
@@ -100,12 +100,36 @@ public static class Utils
// Remove Html Tags Template
public static string RemoveHtmlTagsTemplate(string str) => Regex.Replace(str, "", "");
// Get raw text
public static string GetRawText(string text)
public static string RemoveHtmlText(string text)
{
text = Regex.Replace(text, "<[^>]*>", "");
text = Regex.Replace(text, "{[^}]*}", "");
text = text.Replace("\n", " ").Replace("\r", " ");
text = text.Trim();
return text;
}
public static bool IsHtmlText(string text)
{
if (Regex.IsMatch(text, "<[^>]*>"))
{
return true;
}
if (Regex.IsMatch(text, "{[^}]*}"))
{
return true;
}
if (text.Contains("\n") || text.Contains("\r"))
{
return true;
}
return false;
}
// Get name for role
public static string GetRoleName(RoleTypes role) => Main.GetRoleName[(int)role];
// Get hex color for team
+6
View File
@@ -1,5 +1,6 @@
using HarmonyLib;
using UnityEngine;
using static Rewired.Data.UserDataStore_PlayerPrefs.ControllerAssignmentSaveInfo;
namespace BetterAmongUs.Patches;
@@ -54,6 +55,11 @@ public static class OptionsMenuBehaviourPatch
{
RPC.SendBetterCheck();
foreach (var kvp in PlayerControlDataExtension.playerInfo)
{
PlayerControlDataExtension.playerInfo[kvp.Key].LastNameSetFor.Clear();
}
RPC.SyncAllNames(force: true);
}
}
+12 -1
View File
@@ -195,7 +195,7 @@ class PlayerControlPatch
string[] parts = text.Split("+++");
for (int i = 0; i < parts.Length; i++)
{
if (!string.IsNullOrEmpty(Utils.GetRawText(parts[i])))
if (!string.IsNullOrEmpty(Utils.RemoveHtmlText(parts[i])))
{
destination.Append(parts[i]);
if (i != parts.Length - 2)
@@ -221,6 +221,17 @@ class PlayerControlPatch
}
}
[HarmonyPatch(nameof(PlayerControl.RpcSetName))]
[HarmonyPrefix]
public static bool RpcSetName_Prefix([HarmonyArgument(0)] string name)
{
if (!GameStates.IsVanillaServer && Utils.IsHtmlText(name))
{
return false;
}
return true;
}
[HarmonyPatch(nameof(PlayerControl.SetColor))]
[HarmonyPostfix]
-38
View File
@@ -1,38 +0,0 @@
using HarmonyLib;
namespace BetterAmongUs.Patches;
[HarmonyPatch(typeof(Constants), nameof(Constants.GetBroadcastVersion))]
class ServerUpdatePatch
{
static void Postfix(ref int __result)
{
var region = ServerManager.Instance.CurrentRegion.Name;
if (GameStates.IsLocalGame)
{
}
if (GameStates.IsOnlineGame)
{
if (region.Contains("MNA") || region.Contains("MEU") || region.Contains("MAS"))
{
__result += 25;
}
}
}
}
[HarmonyPatch(typeof(Constants), nameof(Constants.IsVersionModded))]
public static class IsVersionModdedPatch
{
public static bool Prefix(ref bool __result)
{
var region = ServerManager.Instance.CurrentRegion.Name;
if (region.Contains("MNA") || region.Contains("MEU") || region.Contains("MAS"))
{
__result = true;
return false;
}
return true;
}
}