feat(Protections): Reenabled CanApplyData (#740)

* fix(CanApplyData): correct crash_blocked msg
This commit is contained in:
Yimura 2022-12-30 11:48:59 +01:00 committed by GitHub
parent 055bb3e939
commit 5909af7fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 130 additions and 12 deletions

View File

@ -28,5 +28,23 @@ namespace rage
static_assert(consteval_joaat("test") == 0x3f75ccc1);
}
inline consteval rage::joaat_t operator""_j(const char* s, std::size_t n)
{
rage::joaat_t result = 0;
for (std::size_t i = 0; i < n; i++)
{
result += rage::joaat_to_lower(s[i]);
result += (result << 10);
result ^= (result >> 6);
}
result += (result << 3);
result ^= (result >> 11);
result += (result << 15);
return result;
}
#define RAGE_JOAAT_IMPL(str) (::rage::consteval_joaat(str))
#define RAGE_JOAAT(str) (std::integral_constant<rage::joaat_t, RAGE_JOAAT_IMPL(str)>::value)

View File

@ -56,7 +56,7 @@ namespace big
detour_hook_helper::add<hooks::received_clone_create>("RCC", g_pointers->m_received_clone_create);
detour_hook_helper::add<hooks::received_clone_sync>("RCS", g_pointers->m_received_clone_sync);
// detour_hook_helper::add<hooks::can_apply_data>("CAD", g_pointers->m_can_apply_data);
detour_hook_helper::add<hooks::can_apply_data>("CAD", g_pointers->m_can_apply_data);
detour_hook_helper::add<hooks::get_network_event_data>("GNED", g_pointers->m_get_network_event_data);
detour_hook_helper::add<hooks::write_player_gamer_data_node>("WPGDN", g_pointers->m_write_player_gamer_data_node);

View File

@ -23,10 +23,95 @@
#include "util/model_info.hpp"
#include "network/CNetGamePlayer.hpp"
#include "util/notify.hpp"
// TODO: remove as it's unused
#define CLASS_TO_MANGLED_NAME(c) "?AV"#c"@@"
namespace big
{
constexpr auto nodes = std::to_array<std::pair<Hash, uint64_t>>({
{RAGE_JOAAT("CAutomobileCreationDataNode"), 0x1b088e0},
{RAGE_JOAAT("CBikeGameStateDataNode"), 0x1b08a40},
{RAGE_JOAAT("CBoatGameStateDataNode"), 0x1b08a80},
{RAGE_JOAAT("CDoorCreationDataNode"), 0x1b08be0},
{RAGE_JOAAT("CDoorMovementDataNode"), 0x1b09000},
{RAGE_JOAAT("CDoorScriptGameStateDataNode"), 0x1b08ea0},
{RAGE_JOAAT("CDoorScriptInfoDataNode"), 0x1b08d40},
{RAGE_JOAAT("CDynamicEntityGameStateDataNode"), 0x1b06450},
{RAGE_JOAAT("CEntityOrientationDataNode"), 0x1b05df0},
{RAGE_JOAAT("CEntityScriptGameStateDataNode"), 0x1b05c90},
{RAGE_JOAAT("CEntityScriptInfoDataNode"), 0x1b05b30},
{RAGE_JOAAT("CGlobalFlagsDataNode"), 0x1b057f0},
{RAGE_JOAAT("CHeliControlDataNode"), 0x1b08180},
{RAGE_JOAAT("CHeliHealthDataNode"), 0x1b06f60},
{RAGE_JOAAT("CMigrationDataNode"), 0x1b05af0},
{RAGE_JOAAT("CObjectCreationDataNode"), 0x1b096e0},
{RAGE_JOAAT("CObjectGameStateDataNode"), 0x1b09840},
{RAGE_JOAAT("CObjectOrientationNode"), 0x1b09c60},
{RAGE_JOAAT("CObjectScriptGameStateDataNode"), 0x1b099a0},
{RAGE_JOAAT("CObjectSectorPosNode"), 0x1b09b00},
{RAGE_JOAAT("CPedAIDataNode"), 0x1b0ae80},
{RAGE_JOAAT("CPedAppearanceDataNode"), 0x1b0ad20},
{RAGE_JOAAT("CPedAttachDataNode"), 0x1b0a900},
{RAGE_JOAAT("CPedComponentReservationDataNode"), 0x1b0a380},
{RAGE_JOAAT("CPedCreationDataNode"), 0x1b09ca0},
{RAGE_JOAAT("CPedGameStateDataNode"), 0x1b09f60},
{RAGE_JOAAT("CPedHealthDataNode"), 0x1b0a7a0},
{RAGE_JOAAT("CPedInventoryDataNode"), 0x1b0b2a0},
{RAGE_JOAAT("CPedMovementDataNode"), 0x1b0abc0},
{RAGE_JOAAT("CPedMovementGroupDataNode"), 0x1b0aa60},
{RAGE_JOAAT("CPedOrientationDataNode"), 0x1b0a640},
{RAGE_JOAAT("CPedScriptCreationDataNode"), 0x1b09e00},
{RAGE_JOAAT("CPedScriptGameStateDataNode"), 0x1b0a4e0},
{RAGE_JOAAT("CPedSectorPosMapNode"), 0x1b05ab0},
{RAGE_JOAAT("CPedSectorPosNavMeshNode"), 0x1b0a220},
{RAGE_JOAAT("CPedTaskSequenceDataNode"), 0x1b0b400},
{RAGE_JOAAT("CPedTaskSpecificDataNode"), 0x1b0b140},
{RAGE_JOAAT("CPedTaskTreeDataNode"), 0x1b0afe0},
{RAGE_JOAAT("CPhysicalAngVelocityDataNode"), 0x1b06f20},
{RAGE_JOAAT("CPhysicalAttachDataNode"), 0x1b06fa0},
{RAGE_JOAAT("CPhysicalGameStateDataNode"), 0x1b06b00},
{RAGE_JOAAT("CPhysicalHealthDataNode"), 0x1b06f60},
{RAGE_JOAAT("CPhysicalMigrationDataNode"), 0x1b07100},
{RAGE_JOAAT("CPhysicalScriptGameStateDataNode"), 0x1b06c60},
{RAGE_JOAAT("CPhysicalScriptMigrationDataNode"), 0x1b07140},
{RAGE_JOAAT("CPhysicalVelocityDataNode"), 0x1b06dc0},
{RAGE_JOAAT("CPickupCreationDataNode"), 0x1b0b560},
{RAGE_JOAAT("CPickupPlacementCreationDataNode"), 0x1b0b860},
{RAGE_JOAAT("CPickupPlacementStateDataNode"), 0x1b0b9c0},
{RAGE_JOAAT("CPickupScriptGameStateNode"), 0x1b0b820},
{RAGE_JOAAT("CPickupSectorPosNode"), 0x1b0b6c0},
{RAGE_JOAAT("CPlaneControlDataNode"), 0x1b08180},
{RAGE_JOAAT("CPlaneGameStateDataNode"), 0x1b0c380},
{RAGE_JOAAT("CPlayerAmbientModelStreamingNode"), 0x1b0c040},
{RAGE_JOAAT("CPlayerAppearanceDataNode"), 0x1b0bc20},
{RAGE_JOAAT("CPlayerCameraDataNode"), 0x1b0bba0},
{RAGE_JOAAT("CPlayerCreationDataNode"), 0x1b0ba00},
{RAGE_JOAAT("CPlayerExtendedGameStateNode"), 0x1b0c300},
{RAGE_JOAAT("CPlayerGameStateDataNode"), 0x1b0bbe0},
{RAGE_JOAAT("CPlayerGamerDataNode"), 0x1b0c1a0},
{RAGE_JOAAT("CPlayerPedGroupDataNode"), 0x1b0bd80},
{RAGE_JOAAT("CPlayerSectorPosNode"), 0x1b0bb60},
{RAGE_JOAAT("CPlayerWantedAndLOSDataNode"), 0x1b0bee0},
{RAGE_JOAAT("CSectorDataNode"), 0x1b05950},
{RAGE_JOAAT("CSectorPositionDataNode"), 0x1b05ab0},
{RAGE_JOAAT("CSubmarineControlDataNode"), 0x1b08180},
{RAGE_JOAAT("CSubmarineGameStateDataNode"), 0x1b092c0},
{RAGE_JOAAT("CTrainGameStateDataNode"), 0x1b0c340},
{RAGE_JOAAT("CVehicleAngVelocityDataNode"), 0x1b06f20},
{RAGE_JOAAT("CVehicleAppearanceDataNode"), 0x1b082e0},
{RAGE_JOAAT("CVehicleComponentReservationDataNode"), 0x1b085e0},
{RAGE_JOAAT("CVehicleControlDataNode"), 0x1b08180},
{RAGE_JOAAT("CVehicleCreationDataNode"), 0x1b07940},
{RAGE_JOAAT("CVehicleDamageStatusDataNode"), 0x1b08440},
{RAGE_JOAAT("CVehicleGadgetDataNode"), 0x1b08780},
{RAGE_JOAAT("CVehicleGameStateDataNode"), 0x1b07c00},
{RAGE_JOAAT("CVehicleHealthDataNode"), 0x1b07ec0},
{RAGE_JOAAT("CVehicleProximityMigrationDataNode"), 0x1b08740},
{RAGE_JOAAT("CVehicleScriptGameStateDataNode"), 0x1b07d60},
{RAGE_JOAAT("CVehicleSteeringDataNode"), 0x1b08020},
{RAGE_JOAAT("CVehicleTaskDataNode"), 0x1b085a0}});
// TODO: remove as it's unused
constexpr uint64_t operator ""_fnv1a(char const* str, std::size_t len)
{
auto const fnv_offset_basis = 14695981039346656037ULL;
@ -95,9 +180,24 @@ namespace big
}
else if (node->IsDataNode())
{
switch (typeid(*node).hash_code())
auto offset_to_address = [](uint64_t off)
{
case "?AVCDoorCreationDataNode@@"_fnv1a:
static auto base_addr = reinterpret_cast<uint64_t>(GetModuleHandle(nullptr));
return base_addr + off;
};
auto vtable = *(void**)node;
Hash node_hash;
for (const auto& n : nodes)
{
if ((void*)offset_to_address(n.second) == vtable)
{
node_hash = n.first;
}
}
switch (node_hash)
{
case "CDoorCreationDataNode"_j:
{
const auto creation_node = dynamic_cast<CDoorCreationDataNode*>(node);
if (is_crash_object(creation_node->m_model))
@ -107,17 +207,17 @@ namespace big
}
break;
}
case "?AVCPickupCreationDataNode@@"_fnv1a:
case "CPickupCreationDataNode"_j:
{
const auto creation_node = dynamic_cast<CPickupCreationDataNode*>(node);
if (is_crash_object(creation_node->m_custom_model))
{
notify::crash_blocked(sender, "invalid door model");
notify::crash_blocked(sender, "invalid pickup model");
return true;
}
break;
}
case "?AVCPhysicalAttachDataNode@@"_fnv1a:
case "CPhysicalAttachDataNode"_j:
{
const auto attach_node = dynamic_cast<CPhysicalAttachDataNode*>(node);
@ -130,7 +230,7 @@ namespace big
}
break;
}
case "?AVCPedCreationDataNode@@"_fnv1a:
case "CPedCreationDataNode"_j:
{
const auto creation_node = dynamic_cast<CPedCreationDataNode*>(node);
if (is_crash_ped(creation_node->m_model))
@ -145,7 +245,7 @@ namespace big
}
break;
}
case "?AVCPedAttachDataNode@@"_fnv1a:
case "CPedAttachDataNode"_j:
{
const auto attach_node = dynamic_cast<CPedAttachDataNode*>(node);
if (attach_node->m_attached && attach_node->m_attached_to == object->m_object_id)
@ -155,7 +255,7 @@ namespace big
}
break;
}
case "?AVCVehicleCreationDataNode@@"_fnv1a:
case "CVehicleCreationDataNode"_j:
{
const auto vehicle_creation_node = dynamic_cast<CVehicleCreationDataNode*>(node);
if (is_crash_vehicle(vehicle_creation_node->m_model))
@ -165,7 +265,7 @@ namespace big
}
break;
}
case "?AVCObjectCreationDataNode@@"_fnv1a:
case "CObjectCreationDataNode"_j:
{
const auto creation_node = dynamic_cast<CObjectCreationDataNode*>(node);
if (is_crash_object(creation_node->m_model))
@ -175,7 +275,7 @@ namespace big
}
break;
}
case "?AVCPlayerAppearanceDataNode@@"_fnv1a:
case "CPlayerAppearanceDataNode"_j:
{
const auto player_appearance_node = dynamic_cast<CPlayerAppearanceDataNode*>(node);
if (is_crash_ped(player_appearance_node->m_model_hash))
@ -185,7 +285,7 @@ namespace big
}
break;
}
case "?AVCSectorDataNode@@"_fnv1a:
case "CSectorDataNode"_j:
{
const auto sector_node = dynamic_cast<CSectorDataNode*>(node);
if (sector_node->m_pos_x == 712 || sector_node->m_pos_y == 712 || sector_node->m_pos_z == 712)