feat: add autouse of items
This commit is contained in:
33
L2BotDll/Events/ItemAutousedEvent.h
Normal file
33
L2BotDll/Events/ItemAutousedEvent.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "Event.h"
|
||||
|
||||
class ItemAutousedEvent : public Event
|
||||
{
|
||||
public:
|
||||
static constexpr const char* name = "itemAutoused";
|
||||
|
||||
const std::string GetName() const
|
||||
{
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& GetAutouseInfo() const
|
||||
{
|
||||
return m_AutouseInfo;
|
||||
}
|
||||
|
||||
ItemAutousedEvent(const std::vector<uint32_t> autouseInfo) :
|
||||
m_AutouseInfo(autouseInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ItemAutousedEvent() = delete;
|
||||
virtual ~ItemAutousedEvent() = default;
|
||||
|
||||
private:
|
||||
const std::vector<uint32_t> m_AutouseInfo;
|
||||
};
|
@@ -170,6 +170,7 @@
|
||||
<ClInclude Include="Events\EventDispatcher.h" />
|
||||
<ClInclude Include="Events\HeroCreatedEvent.h" />
|
||||
<ClInclude Include="Events\HeroDeletedEvent.h" />
|
||||
<ClInclude Include="Events\ItemAutousedEvent.h" />
|
||||
<ClInclude Include="Events\ItemCreatedEvent.h" />
|
||||
<ClInclude Include="Events\ItemDeletedEvent.h" />
|
||||
<ClInclude Include="Events\ItemUpdatedEvent.h" />
|
||||
|
@@ -171,6 +171,9 @@
|
||||
<ClInclude Include="Events\ItemDeletedEvent.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Events\ItemAutousedEvent.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user