diff --git a/src/gta/joaat.hpp b/src/gta/joaat.hpp index 42341fda..de774119 100644 --- a/src/gta/joaat.hpp +++ b/src/gta/joaat.hpp @@ -8,6 +8,25 @@ namespace rage { + template + inline constexpr joaat_t consteval_joaat(char const (&data)[N]) + { + joaat_t hash = 0; + + for (std::size_t i = 0; i < N - 1; ++i) + { + hash += joaat_to_lower(data[i]); + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return hash; + } + inline consteval joaat_t consteval_joaat(const std::span& data) { joaat_t hash = 0; diff --git a/src/hooks/protections/can_apply_data.cpp b/src/hooks/protections/can_apply_data.cpp index f535ecd4..6aeabc01 100644 --- a/src/hooks/protections/can_apply_data.cpp +++ b/src/hooks/protections/can_apply_data.cpp @@ -29,517 +29,519 @@ namespace big { - struct sync_tree_children + struct sync_node_id { - Hash parent; - std::vector children; - }; - static std::vector trees = { - {RAGE_JOAAT("CAutomobileSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CAutomobileCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CBikeSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CBikeGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CBoatSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CBoatGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CDoorSyncTree"), - { - RAGE_JOAAT("CDoorCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDoorScriptInfoDataNode"), - RAGE_JOAAT("CDoorScriptGameStateDataNode"), - RAGE_JOAAT("CDoorMovementDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - }}, - {RAGE_JOAAT("CHeliSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CAutomobileCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CHeliHealthDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CHeliControlDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CObjectSyncTree"), - { - RAGE_JOAAT("CObjectCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CObjectGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CObjectScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CPhysicalHealthDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CObjectSectorPosNode"), - RAGE_JOAAT("CObjectOrientationNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CPhysicalAngVelocityDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - }}, - {RAGE_JOAAT("CPedSyncTree"), - { - RAGE_JOAAT("CPedCreationDataNode"), - RAGE_JOAAT("CPedScriptCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CPedGameStateDataNode"), - RAGE_JOAAT("CPedComponentReservationDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CPedScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPedAttachDataNode"), - RAGE_JOAAT("CPedHealthDataNode"), - RAGE_JOAAT("CPedMovementGroupDataNode"), - RAGE_JOAAT("CPedAIDataNode"), - RAGE_JOAAT("CPedAppearanceDataNode"), - RAGE_JOAAT("CPedOrientationDataNode"), - RAGE_JOAAT("CPedMovementDataNode"), - RAGE_JOAAT("CPedTaskTreeDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CPedSectorPosMapNode"), - RAGE_JOAAT("CPedSectorPosNavMeshNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CPedInventoryDataNode"), - RAGE_JOAAT("CPedTaskSequenceDataNode"), - }}, - {RAGE_JOAAT("CPickupSyncTree"), - { - RAGE_JOAAT("CPickupCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPickupScriptGameStateNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalHealthDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CPickupSectorPosNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CPhysicalAngVelocityDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - }}, - {RAGE_JOAAT("CPickupPlacementSyncTree"), - { - RAGE_JOAAT("CPickupPlacementCreationDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CPickupPlacementStateDataNode"), - }}, - {RAGE_JOAAT("CPlaneSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CPlaneGameStateDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CPlaneControlDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CSubmarineSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CSubmarineGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CSubmarineControlDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CPlayerSyncTree"), - { - RAGE_JOAAT("CPlayerCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CPedGameStateDataNode"), - RAGE_JOAAT("CPedComponentReservationDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPlayerGameStateDataNode"), - RAGE_JOAAT("CPedAttachDataNode"), - RAGE_JOAAT("CPedHealthDataNode"), - RAGE_JOAAT("CPedMovementGroupDataNode"), - RAGE_JOAAT("CPedAIDataNode"), - RAGE_JOAAT("CPlayerAppearanceDataNode"), - RAGE_JOAAT("CPlayerPedGroupDataNode"), - RAGE_JOAAT("CPlayerAmbientModelStreamingNode"), - RAGE_JOAAT("CPlayerGamerDataNode"), - RAGE_JOAAT("CPlayerExtendedGameStateNode"), - RAGE_JOAAT("CPedOrientationDataNode"), - RAGE_JOAAT("CPedMovementDataNode"), - RAGE_JOAAT("CPedTaskTreeDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CPedTaskSpecificDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CPlayerSectorPosNode"), - RAGE_JOAAT("CPlayerCameraDataNode"), - RAGE_JOAAT("CPlayerWantedAndLOSDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - }}, - {RAGE_JOAAT("CAutomobileSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CAutomobileCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - {RAGE_JOAAT("CTrainSyncTree"), - { - RAGE_JOAAT("CVehicleCreationDataNode"), - RAGE_JOAAT("CGlobalFlagsDataNode"), - RAGE_JOAAT("CDynamicEntityGameStateDataNode"), - RAGE_JOAAT("CPhysicalGameStateDataNode"), - RAGE_JOAAT("CVehicleGameStateDataNode"), - RAGE_JOAAT("CTrainGameStateDataNode"), - RAGE_JOAAT("CEntityScriptGameStateDataNode"), - RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), - RAGE_JOAAT("CVehicleScriptGameStateDataNode"), - RAGE_JOAAT("CEntityScriptInfoDataNode"), - RAGE_JOAAT("CPhysicalAttachDataNode"), - RAGE_JOAAT("CVehicleAppearanceDataNode"), - RAGE_JOAAT("CVehicleDamageStatusDataNode"), - RAGE_JOAAT("CVehicleComponentReservationDataNode"), - RAGE_JOAAT("CVehicleHealthDataNode"), - RAGE_JOAAT("CVehicleTaskDataNode"), - RAGE_JOAAT("CSectorDataNode"), - RAGE_JOAAT("CSectorPositionDataNode"), - RAGE_JOAAT("CEntityOrientationDataNode"), - RAGE_JOAAT("CPhysicalVelocityDataNode"), - RAGE_JOAAT("CVehicleAngVelocityDataNode"), - RAGE_JOAAT("CVehicleSteeringDataNode"), - RAGE_JOAAT("CVehicleControlDataNode"), - RAGE_JOAAT("CVehicleGadgetDataNode"), - RAGE_JOAAT("CMigrationDataNode"), - RAGE_JOAAT("CPhysicalMigrationDataNode"), - RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), - RAGE_JOAAT("CVehicleProximityMigrationDataNode"), - }}, - }; + Hash id; - struct sync_node - { - Hash node_hash; - void* vtable_addr; - }; - static auto nodes = std::to_array({ - {RAGE_JOAAT("CAutomobileCreationDataNode"), 0}, - {RAGE_JOAAT("CBikeGameStateDataNode"), 0}, - {RAGE_JOAAT("CBoatGameStateDataNode"), 0}, - {RAGE_JOAAT("CDoorCreationDataNode"), 0}, - {RAGE_JOAAT("CDoorMovementDataNode"), 0}, - {RAGE_JOAAT("CDoorScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CDoorScriptInfoDataNode"), 0}, - {RAGE_JOAAT("CDynamicEntityGameStateDataNode"), 0}, - {RAGE_JOAAT("CEntityOrientationDataNode"), 0}, - {RAGE_JOAAT("CEntityScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CEntityScriptInfoDataNode"), 0}, - {RAGE_JOAAT("CGlobalFlagsDataNode"), 0}, - {RAGE_JOAAT("CHeliControlDataNode"), 0}, - {RAGE_JOAAT("CHeliHealthDataNode"), 0}, - {RAGE_JOAAT("CMigrationDataNode"), 0}, - {RAGE_JOAAT("CObjectCreationDataNode"), 0}, - {RAGE_JOAAT("CObjectGameStateDataNode"), 0}, - {RAGE_JOAAT("CObjectOrientationNode"), 0}, - {RAGE_JOAAT("CObjectScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CObjectSectorPosNode"), 0}, - {RAGE_JOAAT("CPedAIDataNode"), 0}, - {RAGE_JOAAT("CPedAppearanceDataNode"), 0}, - {RAGE_JOAAT("CPedAttachDataNode"), 0}, - {RAGE_JOAAT("CPedComponentReservationDataNode"), 0}, - {RAGE_JOAAT("CPedCreationDataNode"), 0}, - {RAGE_JOAAT("CPedGameStateDataNode"), 0}, - {RAGE_JOAAT("CPedHealthDataNode"), 0}, - {RAGE_JOAAT("CPedInventoryDataNode"), 0}, - {RAGE_JOAAT("CPedMovementDataNode"), 0}, - {RAGE_JOAAT("CPedMovementGroupDataNode"), 0}, - {RAGE_JOAAT("CPedOrientationDataNode"), 0}, - {RAGE_JOAAT("CPedScriptCreationDataNode"), 0}, - {RAGE_JOAAT("CPedScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CPedSectorPosMapNode"), 0}, - {RAGE_JOAAT("CPedSectorPosNavMeshNode"), 0}, - {RAGE_JOAAT("CPedTaskSequenceDataNode"), 0}, - {RAGE_JOAAT("CPedTaskSpecificDataNode"), 0}, - {RAGE_JOAAT("CPedTaskTreeDataNode"), 0}, - {RAGE_JOAAT("CPhysicalAngVelocityDataNode"), 0}, - {RAGE_JOAAT("CPhysicalAttachDataNode"), 0}, - {RAGE_JOAAT("CPhysicalGameStateDataNode"), 0}, - {RAGE_JOAAT("CPhysicalHealthDataNode"), 0}, - {RAGE_JOAAT("CPhysicalMigrationDataNode"), 0}, - {RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), 0}, - {RAGE_JOAAT("CPhysicalVelocityDataNode"), 0}, - {RAGE_JOAAT("CPickupCreationDataNode"), 0}, - {RAGE_JOAAT("CPickupPlacementCreationDataNode"), 0}, - {RAGE_JOAAT("CPickupPlacementStateDataNode"), 0}, - {RAGE_JOAAT("CPickupScriptGameStateNode"), 0}, - {RAGE_JOAAT("CPickupSectorPosNode"), 0}, - {RAGE_JOAAT("CPlaneControlDataNode"), 0}, - {RAGE_JOAAT("CPlaneGameStateDataNode"), 0}, - {RAGE_JOAAT("CPlayerAmbientModelStreamingNode"), 0}, - {RAGE_JOAAT("CPlayerAppearanceDataNode"), 0}, - {RAGE_JOAAT("CPlayerCameraDataNode"), 0}, - {RAGE_JOAAT("CPlayerCreationDataNode"), 0}, - {RAGE_JOAAT("CPlayerExtendedGameStateNode"), 0}, - {RAGE_JOAAT("CPlayerGameStateDataNode"), 0}, - {RAGE_JOAAT("CPlayerGamerDataNode"), 0}, - {RAGE_JOAAT("CPlayerPedGroupDataNode"), 0}, - {RAGE_JOAAT("CPlayerSectorPosNode"), 0}, - {RAGE_JOAAT("CPlayerWantedAndLOSDataNode"), 0}, - {RAGE_JOAAT("CSectorDataNode"), 0}, - {RAGE_JOAAT("CSectorPositionDataNode"), 0}, - {RAGE_JOAAT("CSubmarineControlDataNode"), 0}, - {RAGE_JOAAT("CSubmarineGameStateDataNode"), 0}, - {RAGE_JOAAT("CTrainGameStateDataNode"), 0}, - {RAGE_JOAAT("CVehicleAngVelocityDataNode"), 0}, - {RAGE_JOAAT("CVehicleAppearanceDataNode"), 0}, - {RAGE_JOAAT("CVehicleComponentReservationDataNode"), 0}, - {RAGE_JOAAT("CVehicleControlDataNode"), 0}, - {RAGE_JOAAT("CVehicleCreationDataNode"), 0}, - {RAGE_JOAAT("CVehicleDamageStatusDataNode"), 0}, - {RAGE_JOAAT("CVehicleGadgetDataNode"), 0}, - {RAGE_JOAAT("CVehicleGameStateDataNode"), 0}, - {RAGE_JOAAT("CVehicleHealthDataNode"), 0}, - {RAGE_JOAAT("CVehicleProximityMigrationDataNode"), 0}, - {RAGE_JOAAT("CVehicleScriptGameStateDataNode"), 0}, - {RAGE_JOAAT("CVehicleSteeringDataNode"), 0}, - {RAGE_JOAAT("CVehicleTaskDataNode"), 0}, - }); - - static void cache_nodes() - { - for (int i = (int)eNetObjType::NET_OBJ_TYPE_AUTOMOBILE; i <= (int)eNetObjType::NET_OBJ_TYPE_TRAIN; i++) + constexpr sync_node_id() { - if (i == (int)eNetObjType::NET_OBJ_TYPE_TRAILER) - continue; - rage::netSyncTree* tree = g_pointers->m_gta.m_get_sync_tree_for_type(*g_pointers->m_gta.m_network_object_mgr, i); - if (tree->m_child_node_count > trees[i].children.size()) + id = 0; + } + + template + constexpr sync_node_id(char const (&pp)[N]) + { + id = rage::consteval_joaat(pp); + } + + // implicit conversion + constexpr operator Hash() const + { + return id; + } + }; + + using sync_node_vft = uintptr_t; + + // Sync Node Virtual Function Table address to all sync node identifiers that also have that vft address. + using sync_node_vft_to_ids = std::unordered_map>; + + // Sync Tree node array index to node identifier. + using sync_tree_node_array_index_to_node_id_t = std::vector; + + struct sync_node_finder_t + { + static constexpr size_t sync_tree_count = size_t(eNetObjType::NET_OBJ_TYPE_TRAIN) + 1; + + std::array sync_trees_sync_node_vft_to_ids; + + std::array sync_trees_node_array_index_to_node_id = + { + { + // AUTOMOBILE + { + {"CVehicleCreationDataNode"}, + {"CAutomobileCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // BIKE + { + {"CVehicleCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + {"CBikeGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // BOAT + { + {"CVehicleCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + {"CBoatGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // DOOR + { + {"CDoorCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDoorScriptInfoDataNode"}, + {"CDoorScriptGameStateDataNode"}, + + {"CDoorMovementDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + }, + // HELI + { + {"CVehicleCreationDataNode"}, + {"CAutomobileCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + {"CHeliHealthDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + {"CHeliControlDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // OBJECT + { + {"CObjectCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CObjectGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CObjectScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CPhysicalHealthDataNode"}, + + {"CSectorDataNode"}, + {"CObjectSectorPosNode"}, + {"CObjectOrientationNode"}, + {"CPhysicalVelocityDataNode"}, + {"CPhysicalAngVelocityDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + }, + // PED + { + {"CPedCreationDataNode"}, + {"CPedScriptCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CPedGameStateDataNode"}, + {"CPedComponentReservationDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CPedScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPedAttachDataNode"}, + {"CPedHealthDataNode"}, + {"CPedMovementGroupDataNode"}, + {"CPedAIDataNode"}, + {"CPedAppearanceDataNode"}, + + {"CPedOrientationDataNode"}, + {"CPedMovementDataNode"}, + + {"CPedTaskTreeDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + + {"CSectorDataNode"}, + {"CPedSectorPosMapNode"}, + {"CPedSectorPosNavMeshNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CPedInventoryDataNode"}, + {"CPedTaskSequenceDataNode"}, + }, + // PICKUP + { + {"CPickupCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + + {"CPickupScriptGameStateNode"}, + {"CPhysicalGameStateDataNode"}, + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + {"CPhysicalHealthDataNode"}, + + {"CPhysicalAttachDataNode"}, + + {"CSectorDataNode"}, + {"CPickupSectorPosNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CPhysicalAngVelocityDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + }, + // PICKUP_PLACEMENT + { + {"CPickupPlacementCreationDataNode"}, + {"CMigrationDataNode"}, + {"CGlobalFlagsDataNode"}, + {"CPickupPlacementStateDataNode"}, + }, + // PLANE + { + {"CVehicleCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + {"CPlaneGameStateDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + {"CPlaneControlDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // SUBMARINE + { + {"CVehicleCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + {"CSubmarineGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + {"CSubmarineControlDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + // PLAYER + { + {"CPlayerCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CPedGameStateDataNode"}, + {"CPedComponentReservationDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPlayerGameStateDataNode"}, + + {"CPedAttachDataNode"}, + {"CPedHealthDataNode"}, + {"CPedMovementGroupDataNode"}, + {"CPedAIDataNode"}, + {"CPlayerAppearanceDataNode"}, + {"CPlayerPedGroupDataNode"}, + {"CPlayerAmbientModelStreamingNode"}, + {"CPlayerGamerDataNode"}, + {"CPlayerExtendedGameStateNode"}, + + {"CPedOrientationDataNode"}, + {"CPedMovementDataNode"}, + + {"CPedTaskTreeDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + {"CPedTaskSpecificDataNode"}, + + {"CSectorDataNode"}, + {"CPlayerSectorPosNode"}, + {"CPlayerCameraDataNode"}, + {"CPlayerWantedAndLOSDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + }, + // TRAILER + { + + }, + // TRAIN + { + {"CVehicleCreationDataNode"}, + + {"CGlobalFlagsDataNode"}, + {"CDynamicEntityGameStateDataNode"}, + {"CPhysicalGameStateDataNode"}, + {"CVehicleGameStateDataNode"}, + {"CTrainGameStateDataNode"}, + + {"CEntityScriptGameStateDataNode"}, + {"CPhysicalScriptGameStateDataNode"}, + {"CVehicleScriptGameStateDataNode"}, + {"CEntityScriptInfoDataNode"}, + + {"CPhysicalAttachDataNode"}, + {"CVehicleAppearanceDataNode"}, + {"CVehicleDamageStatusDataNode"}, + {"CVehicleComponentReservationDataNode"}, + {"CVehicleHealthDataNode"}, + {"CVehicleTaskDataNode"}, + + {"CSectorDataNode"}, + {"CSectorPositionDataNode"}, + {"CEntityOrientationDataNode"}, + {"CPhysicalVelocityDataNode"}, + {"CVehicleAngVelocityDataNode"}, + + {"CVehicleSteeringDataNode"}, + {"CVehicleControlDataNode"}, + {"CVehicleGadgetDataNode"}, + + {"CMigrationDataNode"}, + {"CPhysicalMigrationDataNode"}, + {"CPhysicalScriptMigrationDataNode"}, + {"CVehicleProximityMigrationDataNode"}, + }, + }, + }; + }; + + class sync_node_finder + { + private: + + static inline sync_node_finder_t finder; + + public: + static const std::vector& find(eNetObjType obj_type, uintptr_t vft) + { + return finder.sync_trees_sync_node_vft_to_ids[(int)obj_type][vft]; + } + + static void init() + { + for (int i = (int)eNetObjType::NET_OBJ_TYPE_AUTOMOBILE; i <= (int)eNetObjType::NET_OBJ_TYPE_TRAIN; i++) { - LOG(FATAL) << "Cache nodes failed " << i << tree->m_child_node_count << " " << trees[i].children.size(); - throw std::runtime_error("Failed to cache nodes"); - } - for (int j = 0; j < tree->m_child_node_count; j++) - { - PVOID vft = *(PVOID*)tree->m_child_nodes[j]; - for (auto& n : nodes) + if (i == (int)eNetObjType::NET_OBJ_TYPE_TRAILER) + continue; + + rage::netSyncTree* tree = g_pointers->m_gta.m_get_sync_tree_for_type(*g_pointers->m_gta.m_network_object_mgr, i); + + if (tree->m_child_node_count != finder.sync_trees_node_array_index_to_node_id[i].size()) { - if (n.node_hash == trees[i].children[j]) - { - n.vtable_addr = vft; - break; - } + LOG(FATAL) << "Cache nodes failed " << i << " " << tree->m_child_node_count << " " + << finder.sync_trees_node_array_index_to_node_id[i].size(); + + throw std::runtime_error("Failed to cache nodes"); + } + + for (int j = 0; j < tree->m_child_node_count; j++) + { + const uintptr_t vft = *(uintptr_t*)tree->m_child_nodes[j]; + + const sync_node_id node_id = finder.sync_trees_node_array_index_to_node_id[i][j]; + + finder.sync_trees_sync_node_vft_to_ids[i][vft].push_back(node_id); } } } - } + }; constexpr uint32_t crash_peds[] = {RAGE_JOAAT("slod_human"), RAGE_JOAAT("slod_small_quadped"), RAGE_JOAAT("slod_large_quadped")}; @@ -630,183 +632,177 @@ namespace big } else if (node->IsDataNode()) { - auto vtable = *(void**)node; - Hash node_hash = 0; + const auto vft = *(uintptr_t*)node; - for (const auto& n : nodes) + for (const sync_node_id node_id : sync_node_finder::find((eNetObjType)object->m_object_type, vft)) { - if (n.vtable_addr == vtable) + switch (node_id) { - node_hash = n.node_hash; + case sync_node_id("CVehicleCreationDataNode"): + { + const auto creation_node = (CVehicleCreationDataNode*)(node); + if (is_crash_vehicle(creation_node->m_model)) + { + notify::crash_blocked(sender, "invalid vehicle model"); + return true; + } break; } - } - - switch (node_hash) - { - case (RAGE_JOAAT("CVehicleCreationDataNode")): - { - const auto creation_node = (CVehicleCreationDataNode*)(node); - if (is_crash_vehicle(creation_node->m_model)) + case sync_node_id("CDoorCreationDataNode"): { - notify::crash_blocked(sender, "invalid vehicle model"); - return true; - } - break; - } - case RAGE_JOAAT("CDoorCreationDataNode"): - { - const auto creation_node = (CDoorCreationDataNode*)(node); - if (is_crash_object(creation_node->m_model)) - { - notify::crash_blocked(sender, "invalid door model"); - return true; - } - break; - } - case RAGE_JOAAT("CPickupCreationDataNode"): - { - const auto creation_node = (CPickupCreationDataNode*)(node); - if (creation_node->m_custom_model && is_crash_object(creation_node->m_custom_model)) - { - notify::crash_blocked(sender, "invalid pickup model"); - return true; - } - break; - } - case RAGE_JOAAT("CPhysicalAttachDataNode"): - { - const auto attach_node = (CPhysicalAttachDataNode*)(node); - - // TODO: Find a better method to avoid false positives - auto model_hash = get_game_object(object) ? get_game_object(object)->m_model_info->m_hash : 0; - if (attach_node->m_attached && attach_node->m_attached_to == object->m_object_id && (model_hash != RAGE_JOAAT("hauler2") && model_hash != RAGE_JOAAT("phantom3"))) - { - // notify::crash_blocked(sender, "infinite physical attachment"); - return true; - } - else if (attach_node->m_attached - && is_attachment_infinite((rage::CDynamicEntity*)get_game_object(object), attach_node->m_attached_to)) - { - // notify::crash_blocked(sender, "recursive infinite physical attachment"); - return true; - } - - break; - } - case RAGE_JOAAT("CPedCreationDataNode"): - { - const auto creation_node = (CPedCreationDataNode*)(node); - if (is_crash_ped(creation_node->m_model)) - { - notify::crash_blocked(sender, "invalid ped model"); - return true; - } - else if (creation_node->m_has_prop && is_crash_object(creation_node->m_prop_model)) - { - notify::crash_blocked(sender, "invalid ped prop model"); - return true; - } - break; - } - case RAGE_JOAAT("CPedAttachDataNode"): - { - const auto attach_node = (CPedAttachDataNode*)(node); - if (attach_node->m_attached && attach_node->m_attached_to == object->m_object_id) - { - notify::crash_blocked(sender, "infinite ped attachment"); - return true; - } - else if (attach_node->m_attached && is_attachment_infinite(get_game_object(object), attach_node->m_attached_to)) - { - // notify::crash_blocked(sender, "recursive infinite ped attachment"); - return true; - } - - break; - } - case RAGE_JOAAT("CObjectCreationDataNode"): - { - const auto creation_node = (CObjectCreationDataNode*)(node); - if (is_crash_object(creation_node->m_model)) - { - notify::crash_blocked(sender, "invalid object model"); - return true; - } - break; - } - case RAGE_JOAAT("CPlayerAppearanceDataNode"): - { - const auto player_appearance_node = (CPlayerAppearanceDataNode*)(node); - if (is_crash_ped(player_appearance_node->m_model_hash)) - { - notify::crash_blocked(sender, "invalid player model (appearance node)"); - return true; - } - break; - } - case RAGE_JOAAT("CPlayerCreationDataNode"): - { - const auto player_creation_node = (CPlayerCreationDataNode*)(node); - if (is_crash_ped(player_creation_node->m_model)) - { - notify::crash_blocked(sender, "invalid player model (creation node)"); - return true; - } - break; - } - case RAGE_JOAAT("CSectorDataNode"): - { - const auto sector_node = (CSectorDataNode*)(node); - if (sector_node->m_pos_x == 712 || sector_node->m_pos_y == 712 || sector_node->m_pos_z == 712) - { - notify::crash_blocked(sender, "invalid sector position"); - return true; - } - break; - } - case RAGE_JOAAT("CTrainGameStateDataNode"): - { - const auto train_node = (CTrainGameStateDataNode*)(node); - if (train_node->m_track_id < 0 || train_node->m_track_id >= 27) - { - notify::crash_blocked(sender, "out of bound train track index"); - return true; - } - break; - } - case RAGE_JOAAT("CVehicleProximityMigrationDataNode"): - { - if (object && g_local_player && g_local_player->m_net_object) - { - const auto migration_node = (CVehicleProximityMigrationDataNode*)(node); - if (is_in_vehicle(g_local_player, g_local_player->m_vehicle) && g_local_player->m_vehicle->m_net_object - && g_local_player->m_vehicle->m_net_object->m_object_id == object->m_object_id) - return true; // vehicle kick? - - if (!g_local_player->m_vehicle || !g_local_player->m_vehicle->m_net_object - || g_local_player->m_vehicle->m_net_object->m_object_id != object->m_object_id - || !is_in_vehicle(g_local_player, g_local_player->m_vehicle)) + const auto creation_node = (CDoorCreationDataNode*)(node); + if (is_crash_object(creation_node->m_model)) { - for (int i = 0; i < 16; i++) + notify::crash_blocked(sender, "invalid door model"); + return true; + } + break; + } + case sync_node_id("CPickupCreationDataNode"): + { + const auto creation_node = (CPickupCreationDataNode*)(node); + if (creation_node->m_custom_model && is_crash_object(creation_node->m_custom_model)) + { + notify::crash_blocked(sender, "invalid pickup model"); + return true; + } + break; + } + case sync_node_id("CPhysicalAttachDataNode"): + { + const auto attach_node = (CPhysicalAttachDataNode*)(node); + + // TODO: Find a better method to avoid false positives + auto model_hash = get_game_object(object) ? get_game_object(object)->m_model_info->m_hash : 0; + if (attach_node->m_attached && attach_node->m_attached_to == object->m_object_id && (model_hash != RAGE_JOAAT("hauler2") && model_hash != RAGE_JOAAT("phantom3"))) + { + // notify::crash_blocked(sender, "infinite physical attachment"); + return true; + } + else if (attach_node->m_attached + && is_attachment_infinite((rage::CDynamicEntity*)get_game_object(object), attach_node->m_attached_to)) + { + // notify::crash_blocked(sender, "recursive infinite physical attachment"); + return true; + } + + break; + } + case sync_node_id("CPedCreationDataNode"): + { + const auto creation_node = (CPedCreationDataNode*)(node); + if (is_crash_ped(creation_node->m_model)) + { + notify::crash_blocked(sender, "invalid ped model"); + return true; + } + else if (creation_node->m_has_prop && is_crash_object(creation_node->m_prop_model)) + { + notify::crash_blocked(sender, "invalid ped prop model"); + return true; + } + break; + } + case sync_node_id("CPedAttachDataNode"): + { + const auto attach_node = (CPedAttachDataNode*)(node); + if (attach_node->m_attached && attach_node->m_attached_to == object->m_object_id) + { + notify::crash_blocked(sender, "infinite ped attachment"); + return true; + } + else if (attach_node->m_attached && is_attachment_infinite(get_game_object(object), attach_node->m_attached_to)) + { + // notify::crash_blocked(sender, "recursive infinite ped attachment"); + return true; + } + + break; + } + case sync_node_id("CObjectCreationDataNode"): + { + const auto creation_node = (CObjectCreationDataNode*)(node); + if (is_crash_object(creation_node->m_model)) + { + notify::crash_blocked(sender, "invalid object model"); + return true; + } + break; + } + case sync_node_id("CPlayerAppearanceDataNode"): + { + const auto player_appearance_node = (CPlayerAppearanceDataNode*)(node); + if (is_crash_ped(player_appearance_node->m_model_hash)) + { + notify::crash_blocked(sender, "invalid player model (appearance node)"); + return true; + } + break; + } + case sync_node_id("CPlayerCreationDataNode"): + { + const auto player_creation_node = (CPlayerCreationDataNode*)(node); + if (is_crash_ped(player_creation_node->m_model)) + { + notify::crash_blocked(sender, "invalid player model (creation node)"); + return true; + } + break; + } + case sync_node_id("CSectorDataNode"): + { + const auto sector_node = (CSectorDataNode*)(node); + if (sector_node->m_pos_x == 712 || sector_node->m_pos_y == 712 || sector_node->m_pos_z == 712) + { + notify::crash_blocked(sender, "invalid sector position"); + return true; + } + break; + } + case sync_node_id("CTrainGameStateDataNode"): + { + const auto train_node = (CTrainGameStateDataNode*)(node); + if (train_node->m_track_id < 0 || train_node->m_track_id >= 27) + { + notify::crash_blocked(sender, "out of bound train track index"); + return true; + } + break; + } + case sync_node_id("CVehicleProximityMigrationDataNode"): + { + if (object && g_local_player && g_local_player->m_net_object) + { + if (is_in_vehicle(g_local_player, g_local_player->m_vehicle) && g_local_player->m_vehicle->m_net_object + && g_local_player->m_vehicle->m_net_object->m_object_id == object->m_object_id) + return true; // vehicle kick? + + if (!g_local_player->m_vehicle || !g_local_player->m_vehicle->m_net_object + || g_local_player->m_vehicle->m_net_object->m_object_id != object->m_object_id + || !is_in_vehicle(g_local_player, g_local_player->m_vehicle)) { - if (migration_node->m_has_occupants[i] - && migration_node->m_occupants[i] == g_local_player->m_net_object->m_object_id) - return true; // remote teleport + const auto migration_node = (CVehicleProximityMigrationDataNode*)(node); + + for (int i = 0; i < 16; i++) + { + if (migration_node->m_has_occupants[i] + && migration_node->m_occupants[i] == g_local_player->m_net_object->m_object_id) + return true; // remote teleport + } } } - } - break; + break; + } + } } - } - } +} return false; } bool hooks::can_apply_data(rage::netSyncTree* tree, rage::netObject* object) { - static bool init = ([] { cache_nodes(); }(), true); + static bool init = ([] { sync_node_finder::init(); }(), true); if (tree->m_child_node_count && tree->m_next_sync_node && check_node(tree->m_next_sync_node, g.m_syncing_player, object)) {