From f38161f57397262c9ccd8eea82de1d4e8ed3b4cc Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 4 Aug 2020 12:22:05 +0200 Subject: [PATCH] Fixed issue where hitdata read wrong memory. --- src/Battling/EventHooks/EventHook.hpp | 2 +- src/Battling/Models/ExecutingAttack.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Battling/EventHooks/EventHook.hpp b/src/Battling/EventHooks/EventHook.hpp index 7e41b8c..1c644ed 100644 --- a/src/Battling/EventHooks/EventHook.hpp +++ b/src/Battling/EventHooks/EventHook.hpp @@ -24,7 +24,7 @@ namespace CreatureLib::Battling { public: EventHook() : _offset(0), _capacity(defaultSize) { - auto ptr = calloc(defaultSize, 1); + auto ptr = malloc(_capacity); if (ptr == nullptr) { THROW_CREATURE("Out of memory."); } diff --git a/src/Battling/Models/ExecutingAttack.hpp b/src/Battling/Models/ExecutingAttack.hpp index d2b6678..0ece7cd 100644 --- a/src/Battling/Models/ExecutingAttack.hpp +++ b/src/Battling/Models/ExecutingAttack.hpp @@ -63,7 +63,7 @@ namespace CreatureLib::Battling { HitData& GetHitData(Creature* creature, uint8_t hit) { for (uint8_t i = 0; i < _targetCount; i++) { if (_targets[i] == creature) { - return _hits[i * _numberHits + hit]; + return _hits[(i * _numberHits + hit) * sizeof(HitData)]; } } THROW_CREATURE("Invalid target requested.");