Exemplo n.º 1
0
 public static bool PackagePlayerStats_ProcessPackage_Prefix(NetPackagePlayerStats __instance, World _world)
 {
     if (__instance.Sender != null)
     {
         ClientInfo  _cInfo       = __instance.Sender;
         EntityAlive _entityAlive = _world.GetEntity(_entityId(__instance)) as EntityAlive;
         if (_entityAlive != null)
         {
             if (_cInfo.entityId != _entityAlive.entityId)
             {
                 Log.Out(string.Format("[SERVERTOOLS] Detected erroneous data NetPackagePlayerStats uploaded by steam id {0}, owner id {1}, entity id {2} name {3}. Attempted modifying their entity id to {4}", _cInfo.playerId, _cInfo.ownerId, _cInfo.entityId, _cInfo.playerName, _entityId(__instance)));
                 Packages.Ban(_cInfo.ownerId, _cInfo.playerId, _cInfo.playerName);
                 Packages.Writer(_cInfo.ownerId, _cInfo.playerId, _cInfo.playerName, string.Format("Attempted modifying their entity id to {0}", _entityId(__instance)));
                 return(false);
             }
         }
         else
         {
             Log.Out(string.Format("[SERVERTOOLS] Detected erroneous data NetPackagePlayerStats uploaded by steam id {0}, owner id {1}, entity id {2} name {3}. Attempted modifying their entity id to a non existent entity with id {4}", _cInfo.playerId, _cInfo.ownerId, _cInfo.entityId, _cInfo.playerName, _entityName(__instance)));
             Packages.Ban(_cInfo.ownerId, _cInfo.playerId, _cInfo.playerName);
             Packages.Writer(_cInfo.ownerId, _cInfo.playerId, _cInfo.playerName, string.Format("Attempted modifying their entity id to a non existent entity with id {0}", _entityId(__instance)));
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
 public static bool IsValid(NetPackagePlayerStats __instance)
 {
     try
     {
         if (__instance.Sender.entityId != entityId(__instance))
         {
             ClientInfo cInfo = PersistentOperations.GetClientInfoFromEntityId(entityId(__instance));
             if (cInfo != null)
             {
                 GameUtils.KickPlayerForClientInfo(__instance.Sender, new GameUtils.KickPlayerData(GameUtils.EKickReason.Banned, 0, DateTime.Now.AddDays(1095), "Auto detection has banned you for packet manipulation"));
                 using (StreamWriter sw = new StreamWriter(Filepath, true, Encoding.UTF8))
                 {
                     sw.WriteLine(string.Format("Detected invalid player stat update by '{0}' '{1}' named '{2}' against '{3}' '{4}' named '{5}'", __instance.Sender.PlatformId.CombinedString, __instance.Sender.CrossplatformId.CombinedString, __instance.Sender.playerName, cInfo.PlatformId.CombinedString, cInfo.CrossplatformId.CombinedString, cInfo.playerName));
                     sw.WriteLine();
                     sw.Flush();
                     sw.Close();
                 }
                 Log.Out(string.Format("[SERVERTOOLS] Detected invalid player stat update by '{0}' '{1}' named '{2}' against '{3}' '{4}' named '{5}'. Client has been banned", __instance.Sender.PlatformId.CombinedString, __instance.Sender.CrossplatformId.CombinedString, __instance.Sender.playerName, cInfo.PlatformId.CombinedString, cInfo.CrossplatformId.CombinedString, cInfo.playerName));
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in PlayerStatsPackage.IsValid: {0}", e.Message));
     }
     return(true);
 }
Exemplo n.º 3
0
 public static bool NetPackagePlayerStats_ProcessPackage_Prefix(NetPackagePlayerStats __instance)
 {
     if (PersistentOperations.Net_Package_Detector && __instance.Sender != null)
     {
         if (!PlayerStatsPackage.IsValid(__instance))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 4
0
        public static bool Prefix(NetPackagePlayerStats __instance, ref State __state, [CanBeNull] World _world)
        {
            Log.Debug($"Executing patch prefix {nameof(PlayerStatsChanged)} ...");

            if (_world == null)
            {
                return(true);
            }

            if (_world.GetEntity(__instance.GetEntityId()) is EntityPlayer player)
            {
                // Remember last values for comparison later
                __state = new State()
                {
                    EntityId       = player.entityId,
                    Level          = player.Level,
                    ExpToNextLevel = player.ExpToNextLevel,
                };
            }
            return(true);
        }
Exemplo n.º 5
0
        public static void Postfix(NetPackagePlayerStats __instance, State __state, [CanBeNull] World _world)
        {
            Log.Debug($"Executing patch postfix {nameof(PlayerStatsChanged)} ...");

            if (_world == null || __state == null)
            {
                return;
            }

            if (_world.GetEntity(__state.EntityId) is EntityPlayer player)
            {
                // Track level increase
                if (player.Level > __state.Level)
                {
                    CommandTools.InvokeScriptEvents(ScriptEvent.playerLevelUp, () => new PlayerLevelUpEventArgs()
                    {
                        oldLevel   = __state.Level,
                        newLevel   = player.Level,
                        clientInfo = ConnectionManager.Instance?.GetClientInfoForEntityId(player.entityId),
                    });
                }

                // Track gained xp, including level-up by 1 (can't easily calculate multiple levels into xp)
                if (player.ExpToNextLevel != __state.ExpToNextLevel && (player.Level == __state.Level || player.Level == __state.Level + 1))
                {
                    CommandTools.InvokeScriptEvents(ScriptEvent.playerExpGained, () => new PlayerExpGainedEventArgs()
                    {
                        expGained = player.Level == __state.Level
                                         ? __state.ExpToNextLevel - player.ExpToNextLevel
                                         : __state.ExpToNextLevel + (player.GetExpForNextLevel() - player.ExpToNextLevel),
                        expToNextLevel = player.ExpToNextLevel,
                        levelUp        = player.Level > __state.Level,
                        clientInfo     = ConnectionManager.Instance?.GetClientInfoForEntityId(player.entityId),
                    });
                }
            }
        }
Exemplo n.º 6
0
 public static int GetEntityId(this NetPackagePlayerStats target)
 {
     return((int)fi_NetPackagePlayerStats_entityId.GetValue(target));
 }