Merge pull request #17 from D1GQ/dev

v1.0.0
This commit is contained in:
D1GQ authored and GitHub committed 2024-08-08 22:30:10 -05:00
commit bd7326c195
11 files changed
+150 -224

No files matched your search

+3 -6
View File
@@ -25,18 +25,15 @@ class AntiCheat
if (SickoData.ContainsKey(hashPuid))
{
player.RpcSetName($"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known Sicko Menu User<size=0%>");
AmongUsClient.Instance.KickPlayer(player.GetClientId(), true);
player.Kick(true, $"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known Sicko Menu User<size=0%>");
}
else if (AUMData.ContainsKey(hashPuid))
{
player.RpcSetName($"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known AUM User<size=0%>");
AmongUsClient.Instance.KickPlayer(player.GetClientId(), true);
player.Kick(true, $"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known AUM User<size=0%>");
}
else if (PlayerData.ContainsKey(hashPuid))
{
player.RpcSetName($"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known Cheater<size=0%>");
AmongUsClient.Instance.KickPlayer(player.GetClientId(), true);
player.Kick(true, $"<color=#ffea00>{player.Data.PlayerName}</color> Has been banned by <color=#4f92ff>Anti-Cheat</color>, Reason: Known Cheater<size=0%>");
}
}
}
+93 -1
View File
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Collections.Generic;
using System.Text.Json;
namespace BetterAmongUs;
@@ -122,6 +123,97 @@ class BetterDataManager
File.WriteAllText(filePath, json);
}
public static bool RemovePlayer(string identifier)
{
bool successful = false;
string filePath = GetFilePath("BetterData");
string json = File.ReadAllText(filePath);
var jsonData = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(json)
?? new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
if (jsonData != null)
{
if (jsonData.ContainsKey("cheatData"))
{
RemoveIdentifierFromSection(jsonData["cheatData"], identifier, ref successful);
}
if (jsonData.ContainsKey("sickoData"))
{
RemoveIdentifierFromSection(jsonData["sickoData"], identifier, ref successful);
}
if (jsonData.ContainsKey("aumData"))
{
RemoveIdentifierFromSection(jsonData["aumData"], identifier, ref successful);
}
json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(filePath, json);
}
return successful;
}
private static void RemoveIdentifierFromSection(Dictionary<string, Dictionary<string, string>> sectionData, string identifier, ref bool successful)
{
string keyToRemove = null;
foreach (var entry in sectionData)
{
if (entry.Key == identifier || entry.Value.ContainsValue(identifier))
{
keyToRemove = entry.Key;
break;
}
}
if (keyToRemove != null)
{
sectionData.Remove(keyToRemove);
successful = true;
}
if (successful)
{
foreach (var data in AntiCheat.PlayerData)
{
if (data.Value != identifier)
{
AntiCheat.PlayerData.Remove(identifier);
}
else
{
AntiCheat.PlayerData.Remove(data.Key);
}
}
foreach (var data in AntiCheat.SickoData)
{
if (data.Value != identifier)
{
AntiCheat.SickoData.Remove(identifier);
}
else
{
AntiCheat.SickoData.Remove(data.Key);
}
}
foreach (var data in AntiCheat.AUMData)
{
if (data.Value != identifier)
{
AntiCheat.AUMData.Remove(identifier);
}
else
{
AntiCheat.AUMData.Remove(data.Key);
}
}
}
}
public static void ClearCheatData()
{
string filePath = GetFilePath("BetterData");
-200
View File
@@ -1,200 +0,0 @@
using Hazel;
using InnerNet;
using HarmonyLib;
using UnityEngine;
// Code from: https://github.com/0xDrMoe/TownofHost-Enhanced
namespace BetterAmongUs;
[HarmonyPatch(typeof(InnerNetClient))]
public class InnerNetClientPatch
{
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendInitialData))]
[HarmonyPrefix]
public static bool SendInitialDataPrefix(InnerNetClient __instance, int clientId)
{
if (!Constants.IsVersionModded() || __instance.NetworkMode != NetworkModes.OnlineGame) return true;
// We make sure other stuffs like playercontrol and Lobby behavior is spawned properly
// Then we spawn networked data for new clients
MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable);
messageWriter.StartMessage(6);
messageWriter.Write(__instance.GameId);
messageWriter.WritePacked(clientId);
Il2CppSystem.Collections.Generic.List<InnerNetObject> obj = __instance.allObjects;
lock (obj)
{
HashSet<GameObject> hashSet = new HashSet<GameObject>();
for (int i = 0; i < __instance.allObjects.Count; i++)
{
InnerNetObject innerNetObject = __instance.allObjects[i];
if (innerNetObject && (innerNetObject.OwnerId != -4 || __instance.AmModdedHost) && hashSet.Add(innerNetObject.gameObject))
{
GameManager gameManager = innerNetObject as GameManager;
if (gameManager != null)
{
__instance.SendGameManager(clientId, gameManager);
}
else
{
if (innerNetObject is not NetworkedPlayerInfo)
__instance.WriteSpawnMessage(innerNetObject, innerNetObject.OwnerId, innerNetObject.SpawnFlags, messageWriter);
}
}
}
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Recycle();
}
DelaySpawnPlayerInfo(__instance, clientId);
return false;
}
private static void DelaySpawnPlayerInfo(InnerNetClient __instance, int clientId)
{
List<NetworkedPlayerInfo> players = GameData.Instance.AllPlayers.ToArray().ToList();
// We send 5 players at a time to prevent too huge packet
while (players.Count > 0)
{
var batch = players.Take(5).ToList();
MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable);
messageWriter.StartMessage(6);
messageWriter.Write(__instance.GameId);
messageWriter.WritePacked(clientId);
foreach (var player in batch)
{
if (messageWriter.Length > 1600) break;
if (player != null && player.ClientId != clientId && !player.Disconnected)
{
__instance.WriteSpawnMessage(player, player.OwnerId, player.SpawnFlags, messageWriter);
}
players.Remove(player);
}
messageWriter.EndMessage();
// Logger.Info($"send delayed network data to {clientId} , size is {messageWriter.Length}", "SendInitialDataPrefix");
__instance.SendOrDisconnect(messageWriter);
messageWriter.Recycle();
}
}
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendAllStreamedObjects))]
[HarmonyPrefix]
public static bool SendAllStreamedObjectsPrefix(InnerNetClient __instance, ref bool __result)
{
if (!Constants.IsVersionModded() || __instance.NetworkMode != NetworkModes.OnlineGame) return true;
// Bypass all NetworkedData here.
__result = false;
Il2CppSystem.Collections.Generic.List<InnerNetObject> obj = __instance.allObjects;
lock (obj)
{
for (int i = 0; i < __instance.allObjects.Count; i++)
{
InnerNetObject innerNetObject = __instance.allObjects[i];
if (innerNetObject && innerNetObject is not NetworkedPlayerInfo && innerNetObject.IsDirty && (innerNetObject.AmOwner || (innerNetObject.OwnerId == -2 && __instance.AmHost)))
{
MessageWriter messageWriter = __instance.Streams[(int)innerNetObject.sendMode];
messageWriter.StartMessage(1);
messageWriter.WritePacked(innerNetObject.NetId);
try
{
if (innerNetObject.Serialize(messageWriter, false))
{
messageWriter.EndMessage();
}
else
{
messageWriter.CancelMessage();
}
if (innerNetObject.Chunked && innerNetObject.IsDirty)
{
__result = true;
}
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
messageWriter.CancelMessage();
}
}
}
}
for (int j = 0; j < __instance.Streams.Length; j++)
{
MessageWriter messageWriter2 = __instance.Streams[j];
if (messageWriter2.HasBytes(7))
{
messageWriter2.EndMessage();
__instance.SendOrDisconnect(messageWriter2);
messageWriter2.Clear((SendOption)j);
messageWriter2.StartMessage(5);
messageWriter2.Write(__instance.GameId);
}
}
return false;
}
private static byte timer = 0;
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.FixedUpdate))]
[HarmonyPostfix]
public static void FixedUpdatePostfix(InnerNetClient __instance)
{
// Send a networked data pre 2 fixed update should be a good practice?
if (!Constants.IsVersionModded() || __instance.NetworkMode != NetworkModes.OnlineGame) return;
if (!__instance.AmHost || __instance.Streams == null) return;
if (timer == 0)
{
timer = 1;
return;
}
var player = GameData.Instance.AllPlayers.ToArray().FirstOrDefault(x => x.IsDirty);
if (player != null)
{
timer = 0;
MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable);
messageWriter.StartMessage(5);
messageWriter.Write(__instance.GameId);
messageWriter.StartMessage(1);
messageWriter.WritePacked(player.NetId);
try
{
if (player.Serialize(messageWriter, false))
{
messageWriter.EndMessage();
}
else
{
messageWriter.CancelMessage();
player.ClearDirtyBits();
return;
}
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Recycle();
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
messageWriter.CancelMessage();
player.ClearDirtyBits();
}
}
}
}
[HarmonyPatch(typeof(GameData), nameof(GameData.DirtyAllData))]
internal class DirtyAllDataPatch
{
// Currently this function only occurs in CreatePlayer
// It's believed to lag host, delay the playercontrol spawn mesasge & blackout new client
// & send huge packets to all clients & completely no need to run
// Temporarily disable it until Innersloth get a better fix.
public static bool Prefix()
{
return false;
}
}
+16
View File
@@ -88,6 +88,22 @@ static class ExtendedPlayerControl
return true;
}
// Kick player
public static void Kick(this PlayerControl player, bool ban = false, string setReasonInfo = "")
{
if (!GameStates.IsHost || !player.DataIsCollected() || player.IsHost())
{
return;
}
if (setReasonInfo != "")
{
player.RpcSetName(setReasonInfo);
}
AmongUsClient.Instance.KickPlayer(player.GetClientId(), ban);
}
// RPCs
public static void RpcSendHostChat(this PlayerControl player, string text, string title = "<color=#ffffff><b>(<color=#00ff44>System Message</color>)</b>", bool sendToBetterUser = true)
{
+4 -1
View File
@@ -1,10 +1,12 @@
using HarmonyLib;
using InnerNet;
using UnityEngine;
namespace BetterAmongUs.Patches;
public class ClientPatch
{
// Log game exit
[HarmonyPatch(typeof(AmongUsClient))]
public class AmongUsClientPatch
{
@@ -15,6 +17,7 @@ public class ClientPatch
Logger.Log($"Client has left game for: {Enum.GetName(reason)}", "AmongUsClientPatch");
}
}
// Set text color
[HarmonyPatch(typeof(CosmeticsLayer))]
public class CosmeticsLayerPatch
{
@@ -32,7 +35,7 @@ public class ClientPatch
return false;
}
}
// Clean up menu
[HarmonyPatch(typeof(RegionMenu))]
public class RegionMenuPatch
{
+15 -2
View File
@@ -1,6 +1,5 @@
using AmongUs.Data;
using AmongUs.GameOptions;
using BetterAmongUs.Role;
using HarmonyLib;
using Hazel;
using Il2CppSystem.Text;
@@ -32,6 +31,7 @@ class CommandsPatch
"kick {id}---Kick a player from the game - <color=red>Host Only</color>---{player id}",
"ban {id}---Ban a player from the game - <color=red>Host Only</color>---{player id}",
"endgame {reason}---Force end the game - <color=red>Host Only</color>---{player id}",
"removeplayer {identifier}---Remove player from local <color=#4f92ff>Anti-Cheat</color> data---{FriendCode, HashPuid}",
};
public static string[] DebugCommandListHelper =
{
@@ -222,7 +222,7 @@ class CommandsPatch
{
var player = cmdTarget;
var cmdFlag = command[0][1..].ToLower().Trim() != "kick";
AmongUsClient.Instance.KickPlayer(player.GetClientId(), cmdFlag);
player.Kick(cmdFlag);
}
}
break;
@@ -252,6 +252,19 @@ class CommandsPatch
}
}
break;
case "removeplayer":
if (!string.IsNullOrEmpty(subArgs))
{
if (BetterDataManager.RemovePlayer(subArgs) == true)
{
Utils.AddChatPrivate($"{subArgs} successfully removed from local <color=#4f92ff>Anti-Cheat</color> data!");
}
else
{
Utils.AddChatPrivate($"{error}\nCould not find player data from identifier");
}
}
break;
default:
if (GameStates.IsDev)
{
+2 -2
View File
@@ -1,13 +1,11 @@
using AmongUs.Data;
using HarmonyLib;
using Hazel;
using Il2CppSystem.Linq;
using LibCpp2IL;
using System.Text;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
namespace BetterAmongUs.Patches;
@@ -60,6 +58,7 @@ class PlayerControlPatch
BetterHostManager.PlayerUpdate(__instance);
}
// Set text info
infotime -= Time.deltaTime;
if (infotime <= 0)
@@ -68,6 +67,7 @@ class PlayerControlPatch
infotime = 0.4f;
}
// Reset player data in lobby
if (!GameStates.IsInGamePlay)
{
__instance.BetterData().TimesCalledMeeting = 0;
+1 -1
View File
@@ -2,7 +2,7 @@
using HarmonyLib;
using Hazel;
namespace BetterAmongUs.Role;
namespace BetterAmongUs;
[HarmonyPatch(typeof(RoleManager))]
public class RoleManagerPatch
+1 -1
View File
@@ -1,5 +1,5 @@
#Skip
#Number:100000
#Number:110000
#Title:Main Header
#SubTitle:Main Header SubText
#ShortTitle:List Name
+12 -7
View File
@@ -1,5 +1,4 @@
#Skip
#Number:100001
#Number:110001
#Title:Better Among Us v1.0.0
#SubTitle:<color=#4d4d4d>Is it truly better though?</color>
#ShortTitle:BAU v1.0.0
@@ -7,14 +6,20 @@
#-----------------------------
We are thrilled to announce the release of <b>BetterAmongUs</b> v1.0.0
#
<size=150%>Change Log</size>
BetterAmongUs comes packed with a variety of features designed to improve your gameplay experience:
#
- <b>Built-in Client-Sided Anti-Cheat</b>: Enjoy a fair game by preventing cheaters from ruining your fun.
- <b>Host Enhancements</b>: Gain more control as a host with additional options and settings.
- <b>Better Options</b>: Customize your game with a range of new and improved options.
- <b>Commands</b>: Utilize a set of commands to manage and enhance gameplay.
- <b>Client Improvements</b>: Experience smoother gameplay with various client-side improvements.
- <b>And More!</b>: Stay tuned for more exciting features coming your way!
#
#
<size=150%>Known Issues</size>
<size=150%>Issues & Bugs</size>
#
- If you encounter any issues or have feedback, please report them on our <nobr><link="https://github.com/D1GQ/BetterAmongUs-Public/issues">Github Issues Page</nobr></link> or Bug Reports channel in the <nobr><link="https://discord.gg/a3eVJHp9p5">BAU Discord Server</nobr></link>.
#
Thank you for your support, and we hope you enjoy the new features of <b>BetterAmongUs</b>!
#
<size=125%><nobr><link="https://github.com/D1GQ/BetterAmongUs">Github</nobr></link> </size>
<size=150%><nobr><link="https://discord.gg/vjYrXpzNAn">Discord</nobr></link> </size> <size=150%><nobr><link="https://github.com/D1GQ/BetterAmongUs-Public">Github</nobr></link> </size>
+3 -3
View File
@@ -20,14 +20,14 @@ public enum ReleaseTypes : int
[BepInProcess("Among Us.exe")]
public class Main : BasePlugin
{
public const ReleaseTypes ReleaseBuildType = ReleaseTypes.Canary;
public const string CanaryNum = "6";
public const ReleaseTypes ReleaseBuildType = ReleaseTypes.Release;
public const string CanaryNum = "0";
public const string HotfixNum = "0";
public const bool IsHotFix = false;
public const string PluginGuid = "com.d1gq.betteramongus";
public const string PluginVersion = "1.0.0";
public const string ReleaseDate = "08.08.2024"; // mm/dd/yyyy
public const string Github = "https://github.com/D1GQ/BetterAmongUs";
public const string Github = "https://github.com/D1GQ/BetterAmongUs-Public";
public const string Discord = "https://discord.gg/vjYrXpzNAn";
public static string GetVersionText(bool newLine = false)