mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-14 04:08: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
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
#include "SwitchBehavior.h"
|
|
#include "BehaviorBranchContext.h"
|
|
#include "EntityManager.h"
|
|
#include "dLogger.h"
|
|
#include "DestroyableComponent.h"
|
|
#include "BehaviorContext.h"
|
|
#include "BuffComponent.h"
|
|
|
|
void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
|
auto state = true;
|
|
|
|
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
|
if (!bitStream->Read(state)) {
|
|
Game::logger->Log("SwitchBehavior", "Unable to read state from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
}
|
|
|
|
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
|
|
|
if (entity == nullptr) {
|
|
return;
|
|
}
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
|
|
|
if (destroyableComponent == nullptr) {
|
|
return;
|
|
}
|
|
|
|
Game::logger->Log("SwitchBehavior", "[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
|
|
|
if (state || (entity->GetLOT() == 8092 && destroyableComponent->GetImagination() >= m_imagination)) {
|
|
this->m_actionTrue->Handle(context, bitStream, branch);
|
|
} else {
|
|
this->m_actionFalse->Handle(context, bitStream, branch);
|
|
}
|
|
}
|
|
|
|
void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
auto state = true;
|
|
|
|
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
|
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
state = entity != nullptr;
|
|
|
|
if (state && m_targetHasBuff != 0) {
|
|
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
|
|
|
if (buffComponent != nullptr && !buffComponent->HasBuff(m_targetHasBuff)) {
|
|
state = false;
|
|
}
|
|
}
|
|
|
|
bitStream->Write(state);
|
|
}
|
|
|
|
if (state) {
|
|
this->m_actionTrue->Calculate(context, bitStream, branch);
|
|
} else {
|
|
this->m_actionFalse->Calculate(context, bitStream, branch);
|
|
}
|
|
}
|
|
|
|
void SwitchBehavior::Load() {
|
|
this->m_actionTrue = GetAction("action_true");
|
|
|
|
this->m_actionFalse = GetAction("action_false");
|
|
|
|
this->m_imagination = GetInt("imagination");
|
|
|
|
this->m_isEnemyFaction = GetBoolean("isEnemyFaction");
|
|
|
|
this->m_targetHasBuff = GetInt("target_has_buff");
|
|
}
|