mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-15 04:38:21 +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
87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#include "InterruptBehavior.h"
|
|
#include "BehaviorBranchContext.h"
|
|
#include "BehaviorContext.h"
|
|
#include "Game.h"
|
|
#include "dLogger.h"
|
|
#include "EntityManager.h"
|
|
#include "SkillComponent.h"
|
|
|
|
|
|
void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
if (branch.target != context->originator) {
|
|
bool unknown = false;
|
|
|
|
if (!bitStream->Read(unknown)) {
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown1 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
|
|
if (unknown) return;
|
|
}
|
|
|
|
if (!this->m_interruptBlock) {
|
|
bool unknown = false;
|
|
|
|
if (!bitStream->Read(unknown)) {
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown2 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
|
|
if (unknown) return;
|
|
}
|
|
|
|
if (this->m_target) // Guess...
|
|
{
|
|
bool unknown = false;
|
|
|
|
if (!bitStream->Read(unknown)) {
|
|
Game::logger->Log("InterruptBehavior", "Unable to read unknown3 from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
|
|
return;
|
|
};
|
|
}
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (target == nullptr) return;
|
|
|
|
auto* skillComponent = target->GetComponent<SkillComponent>();
|
|
|
|
if (skillComponent == nullptr) return;
|
|
|
|
skillComponent->Interrupt();
|
|
}
|
|
|
|
|
|
void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
if (branch.target != context->originator) {
|
|
bitStream->Write(false);
|
|
}
|
|
|
|
if (!this->m_interruptBlock) {
|
|
bitStream->Write(false);
|
|
}
|
|
|
|
bitStream->Write(false);
|
|
|
|
if (branch.target == context->originator) return;
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (target == nullptr) return;
|
|
|
|
auto* skillComponent = target->GetComponent<SkillComponent>();
|
|
|
|
if (skillComponent == nullptr) return;
|
|
|
|
skillComponent->Interrupt();
|
|
}
|
|
|
|
|
|
void InterruptBehavior::Load() {
|
|
this->m_target = GetBoolean("target");
|
|
|
|
this->m_interruptBlock = GetBoolean("interrupt_block");
|
|
}
|