From 2f340e6a320a93d683f9bf8c5562e034d308ac74 Mon Sep 17 00:00:00 2001 From: Jerome Montino Date: Wed, 31 Aug 2022 01:21:53 +0800 Subject: [PATCH] RF alt, hooked to FireBeingHit instead of DoHitEntity. --- .../src/user/cheat/player/RapidFire.cpp | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/cheat-library/src/user/cheat/player/RapidFire.cpp b/cheat-library/src/user/cheat/player/RapidFire.cpp index 4a2c9cc..04706bd 100644 --- a/cheat-library/src/user/cheat/player/RapidFire.cpp +++ b/cheat-library/src/user/cheat/player/RapidFire.cpp @@ -13,6 +13,7 @@ namespace cheat::feature static void VCAnimatorEvent_HandleProcessItem_Hook(app::MoleMole_VCAnimatorEvent* __this, app::MoleMole_VCAnimatorEvent_MoleMole_VCAnimatorEvent_AnimatorEventPatternProcessItem* processItem, app::AnimatorStateInfo processStateInfo, app::MoleMole_VCAnimatorEvent_MoleMole_VCAnimatorEvent_TriggerMode__Enum mode, MethodInfo* method); + static void LCBaseCombat_FireBeingHitEvent_Hook(app::LCBaseCombat* __this, uint32_t attackeeRuntimeID, app::AttackResult* attackResult, MethodInfo* method); RapidFire::RapidFire() : Feature(), NF(f_Enabled, "Attack Multiplier", "RapidFire", false), @@ -26,8 +27,9 @@ namespace cheat::feature NF(f_MultiTargetRadius, "Multi-target Radius", "RapidFire", 20.0f), NF(f_MultiAnimation, "Multi-animation", "RapidFire", false) { - HookManager::install(app::MoleMole_LCBaseCombat_DoHitEntity, LCBaseCombat_DoHitEntity_Hook); + // HookManager::install(app::MoleMole_LCBaseCombat_DoHitEntity, LCBaseCombat_DoHitEntity_Hook); -- Looks like FireBeingHitEvent is superior to this. HookManager::install(app::MoleMole_VCAnimatorEvent_HandleProcessItem, VCAnimatorEvent_HandleProcessItem_Hook); + HookManager::install(app::MoleMole_LCBaseCombat_FireBeingHitEvent, LCBaseCombat_FireBeingHitEvent_Hook); } const FeatureGUIInfo& RapidFire::GetGUIInfo() const @@ -275,6 +277,51 @@ namespace cheat::feature CALL_ORIGIN(LCBaseCombat_DoHitEntity_Hook, __this, targetID, attackResult, ignoreCheckCanBeHitInMP, method); } + static void LCBaseCombat_FireBeingHitEvent_Hook(app::LCBaseCombat* __this, uint32_t attackeeRuntimeID, app::AttackResult* attackResult, MethodInfo* method) + { + auto attacker = game::Entity(__this->fields._._._entity); + RapidFire& rapidFire = RapidFire::GetInstance(); + if (!IsConfigByAvatar(attacker) || !IsAttackByAvatar(attacker) || !rapidFire.f_Enabled) + return CALL_ORIGIN(LCBaseCombat_FireBeingHitEvent_Hook, __this, attackeeRuntimeID, attackResult, method); + + auto& manager = game::EntityManager::instance(); + auto originalTarget = manager.entity(attackeeRuntimeID); + + if (!IsValidByFilter(originalTarget)) + return CALL_ORIGIN(LCBaseCombat_FireBeingHitEvent_Hook, __this, attackeeRuntimeID, attackResult, method); + + std::vector validEntities; + validEntities.push_back(originalTarget); + + if (rapidFire.f_MultiTarget) + { + auto filteredEntities = manager.entities(); + for (const auto& entity : filteredEntities) { + auto distance = originalTarget->distance(entity); + + if (entity->runtimeID() == manager.avatar()->runtimeID()) + continue; + + if (entity->runtimeID() == attackeeRuntimeID) + continue; + + if (distance > rapidFire.f_MultiTargetRadius) + continue; + + if (!IsValidByFilter(entity)) + continue; + + validEntities.push_back(entity); + } + } + + for (const auto& entity : validEntities) { + int attackCount = rapidFire.f_MultiHit ? rapidFire.GetAttackCount(__this, entity->runtimeID(), attackResult) : 1; + for (int i = 0; i < attackCount; i++) + CALL_ORIGIN(LCBaseCombat_FireBeingHitEvent_Hook, __this, entity->runtimeID(), attackResult, method); + } + } + static void VCAnimatorEvent_HandleProcessItem_Hook(app::MoleMole_VCAnimatorEvent* __this, app::MoleMole_VCAnimatorEvent_MoleMole_VCAnimatorEvent_AnimatorEventPatternProcessItem* processItem, app::AnimatorStateInfo processStateInfo, app::MoleMole_VCAnimatorEvent_MoleMole_VCAnimatorEvent_TriggerMode__Enum mode, MethodInfo* method)