Created
October 23, 2020 23:55
-
-
Save Aviator-Coding/e428f8a9fff68b017ff8cedad0fc1830 to your computer and use it in GitHub Desktop.
7dtd Netpackage Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using HarmonyLib; | |
| namespace _7dtd_inject | |
| { | |
| /// <summary> | |
| /// This is an Example howto patch Netpackages in 7dtd | |
| /// this will help prevent people from cheating | |
| /// Research done by Aviator#1024 - https://github.com/Aviator-Coding | |
| /// </summary> | |
| class Patch | |
| { | |
| public static bool Debug = true; | |
| //Patches the Game wwith Custom Hooks | |
| public static void Game() | |
| { | |
| Harmony harmony = new Harmony("com.aviator.patch"); | |
| harmony.PatchAll(); | |
| } | |
| } | |
| /// <summary> | |
| /// NetPackageChat: Prevent an Attacker to Spoof the Name in the Chat and his EntityID | |
| /// </summary> | |
| [HarmonyPatch(typeof(NetPackageChat))] | |
| class NetPackageChat_Patch | |
| { | |
| static AccessTools.FieldRef<NetPackageChat, EChatType> h_chatType = AccessTools.FieldRefAccess<NetPackageChat, EChatType>("chatType"); | |
| static AccessTools.FieldRef<NetPackageChat, int> h_senderEntityId = AccessTools.FieldRefAccess<NetPackageChat, int>("senderEntityId"); | |
| static AccessTools.FieldRef<NetPackageChat, string> h_msg = AccessTools.FieldRefAccess<NetPackageChat, string>("msg"); | |
| static AccessTools.FieldRef<NetPackageChat, string> h_mainName = AccessTools.FieldRefAccess<NetPackageChat, string>("mainName"); | |
| static AccessTools.FieldRef<NetPackageChat, bool> h_localizeMain = AccessTools.FieldRefAccess<NetPackageChat, bool>("localizeMain"); | |
| [HarmonyPostfix] | |
| [HarmonyPatch("ProcessPackage")] | |
| static void ProcessPacketPrefix(NetPackageChat __instance, World _world, INetConnectionCallbacks _netConnectionCallback) | |
| { | |
| //Lets check the Name and if it does not match we will set it correct and flag the log | |
| if(__instance.Sender.playerName != h_mainName(__instance)) | |
| { | |
| Log.Warning("NetPacketChat Claimed Name {0} is not the Same as Connection Name {1}", h_mainName(__instance), __instance.Sender.playerName); | |
| h_mainName(__instance) = __instance.Sender.playerName; | |
| } | |
| if(__instance.Sender.entityId != h_senderEntityId(__instance)) | |
| { | |
| Log.Warning("NetPacketChat Claimed Entity ID {0} is not the Same as Connection EntityID {1}", h_senderEntityId(__instance), __instance.Sender.entityId); | |
| h_senderEntityId(__instance) = __instance.Sender.entityId; | |
| } | |
| if (Patch.Debug) | |
| { | |
| Log.Out("NetPacketChat Prefix: Sender IP: {0} EntityID: {1} Name {2}", __instance.Sender.ip, __instance.Sender.entityId, __instance.Sender.playerName); | |
| Log.Out("NetPacketChat Prefix: Chattype: {0}, Message: {1}, MainName:{2}, localizeMain: {3}", h_chatType(__instance), h_msg(__instance), h_mainName(__instance), h_localizeMain(__instance)); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment