mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-23 14:07:20 +00:00
a2ca273370
* Add failArmor server side Address out of bounds reading in behavior Address the basicAttackBehavior reading out of bounds memory and reading bits that didnt exist, which occasionally caused crashes and also caused the behavior to do undefined behavior due to the bad reads. Tested that attacking a wall anywhere with a projectile now does not crash the game. Tested with logs that the behavior correctly returned when there were no allocated bits or returned when other states were met. Add back logs and add fail handle Remove comment block Revert "Add back logs and add fail handle" This reverts commit db19be0906fc8bf35bf89037e2bfba39f5ef9c0c. Split out checks * Cleanup Behavior streams
105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
#include "StunBehavior.h"
|
|
|
|
#include "BaseCombatAIComponent.h"
|
|
#include "BehaviorBranchContext.h"
|
|
#include "BehaviorContext.h"
|
|
#include "EntityManager.h"
|
|
#include "Game.h"
|
|
#include "dLogger.h"
|
|
#include "DestroyableComponent.h"
|
|
|
|
|
|
void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
return;
|
|
}
|
|
|
|
bool blocked{};
|
|
if (!bitStream->Read(blocked)) {
|
|
Game::logger->Log("StunBehavior", "Unable to read blocked from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (target == nullptr) {
|
|
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
}
|
|
|
|
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
if (this->m_stunCaster || branch.target == context->originator) {
|
|
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
|
|
|
if (self == nullptr) {
|
|
Game::logger->Log("StunBehavior", "Invalid self entity (%llu)!", context->originator);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* See if we can stun ourselves
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(self->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
|
|
return;
|
|
}
|
|
|
|
bool blocked = false;
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (target != nullptr) {
|
|
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
|
|
|
if (destroyableComponent != nullptr) {
|
|
blocked = destroyableComponent->IsKnockbackImmune();
|
|
}
|
|
}
|
|
|
|
bitStream->Write(blocked);
|
|
|
|
if (target == nullptr) {
|
|
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* If our target is an enemy we can go ahead and stun it.
|
|
*/
|
|
|
|
auto* combatAiComponent = static_cast<BaseCombatAIComponent*>(target->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
|
|
|
|
if (combatAiComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
combatAiComponent->Stun(branch.duration);
|
|
}
|
|
|
|
void StunBehavior::Load() {
|
|
this->m_stunCaster = GetBoolean("stun_caster");
|
|
}
|