feat: add autouse of items

This commit is contained in:
k0t9i
2023-01-25 00:17:35 +04:00
parent 4cfb986ce0
commit a2bcb25f0e
8 changed files with 100 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
#include "../../../Events/ItemCreatedEvent.h"
#include "../../../Events/ItemUpdatedEvent.h"
#include "../../../Events/ItemDeletedEvent.h"
#include "../../../Events/ItemAutousedEvent.h"
#include "../../../DTO/ItemData.h"
namespace Interlude
@@ -24,6 +25,7 @@ namespace Interlude
void(__thiscall* GameEngineWrapper::__AddAbnormalStatus)(GameEngine*, L2ParamStack&) = 0;
void(__thiscall* GameEngineWrapper::__AddInventoryItem)(GameEngine*, ItemInfo&) = 0;
void(__thiscall* GameEngineWrapper::__OnReceiveUpdateItemList)(GameEngine*, UpdateItemListActionType, ItemInfo&) = 0;
void(__thiscall* GameEngineWrapper::__OnExAutoSoulShot)(GameEngine*, L2ParamStack&) = 0;
void GameEngineWrapper::Init(HMODULE hModule)
@@ -50,6 +52,9 @@ namespace Interlude
(FARPROC&)__OnReceiveUpdateItemList = (FARPROC)splice(
GetProcAddress(hModule, "?OnReceiveUpdateItemList@UGameEngine@@UAEXHAAUItemInfo@@@Z"), __OnReceiveUpdateItemList_hook
);
(FARPROC&)__OnExAutoSoulShot = (FARPROC)splice(
GetProcAddress(hModule, "?OnExAutoSoulShot@UGameEngine@@UAEXAAVL2ParamStack@@@Z"), __OnExAutoSoulShot_hook
);
}
void GameEngineWrapper::Restore()
@@ -61,6 +66,7 @@ namespace Interlude
restore((void*&)__AddAbnormalStatus);
restore((void*&)__AddInventoryItem);
restore((void*&)__OnReceiveUpdateItemList);
restore((void*&)__OnExAutoSoulShot);
}
void __fastcall GameEngineWrapper::__Init_hook(GameEngine* This, uint32_t /*edx*/, float_t unk)
@@ -147,4 +153,10 @@ namespace Interlude
}
(*__OnReceiveUpdateItemList)(This, actionType, itemInfo);
}
void __fastcall GameEngineWrapper::__OnExAutoSoulShot_hook(GameEngine* This, int, L2ParamStack& stack)
{
EventDispatcher::GetInstance().Dispatch(ItemAutousedEvent{ stack.GetBufferAsVector<uint32_t>() });
(*__OnExAutoSoulShot)(This, stack);
}
}

View File

@@ -26,6 +26,7 @@ namespace Interlude
static void(__thiscall* __AddAbnormalStatus)(GameEngine*, L2ParamStack&);
static void(__thiscall* __AddInventoryItem)(GameEngine*, ItemInfo&);
static void(__thiscall* __OnReceiveUpdateItemList)(GameEngine*, UpdateItemListActionType, ItemInfo&);
static void(__thiscall* __OnExAutoSoulShot)(GameEngine*, L2ParamStack&);
static void __fastcall __Init_hook(GameEngine* This, uint32_t /*edx*/, float_t unk);
static void __fastcall __OnSkillListPacket_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
@@ -34,6 +35,7 @@ namespace Interlude
static void __fastcall __AddAbnormalStatus_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
static void __fastcall __AddInventoryItem_hook(GameEngine* This, int /*edx*/, ItemInfo& itemInfo);
static void __fastcall __OnReceiveUpdateItemList_hook(GameEngine* This, int /*edx*/, UpdateItemListActionType actionType, ItemInfo& itemInfo);
static void __fastcall __OnExAutoSoulShot_hook(GameEngine* This, int /*edx*/, L2ParamStack& stack);
private:
static void* originalInitAddress;

View File

@@ -11,6 +11,7 @@
#include "../../../Events/ItemUpdatedEvent.h"
#include "../../../Events/ItemDeletedEvent.h"
#include "../../../Events/HeroDeletedEvent.h"
#include "../../../Events/ItemAutousedEvent.h"
#include "../../../Events/EventDispatcher.h"
using namespace L2Bot::Domain;
@@ -61,6 +62,9 @@ namespace Interlude
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
OnHeroDeleted(evt);
});
EventDispatcher::GetInstance().Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
OnItemAutoused(evt);
});
}
void OnHeroDeleted(const Event& evt)
@@ -71,6 +75,31 @@ namespace Interlude
Reset();
}
}
void OnItemAutoused(const Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ItemAutousedEvent::name)
{
const auto casted = static_cast<const ItemAutousedEvent&>(evt);
const auto& data = casted.GetAutouseInfo();
const auto itemId = data[0];
const bool isEnabled = data[1] > 0;
for (const auto& item : m_Items)
{
if (item.second->GetItemId() == itemId)
{
auto ptr = dynamic_cast<Entities::EtcItem*>(item.second.get());
if (ptr)
{
ptr->Autouse(isEnabled);
}
}
}
}
}
//todo need to delete items if they are not exists in create "queue"
void OnItemCreated(const Event& evt)