feat: add autouse of items
This commit is contained in:
@@ -14,6 +14,10 @@ namespace L2Bot::Domain::Entities
|
|||||||
{
|
{
|
||||||
return m_ObjectId;
|
return m_ObjectId;
|
||||||
}
|
}
|
||||||
|
const uint32_t GetItemId() const
|
||||||
|
{
|
||||||
|
return m_ItemId;
|
||||||
|
}
|
||||||
virtual void Update(const EntityInterface* other) override
|
virtual void Update(const EntityInterface* other) override
|
||||||
{
|
{
|
||||||
const BaseItem* casted = static_cast<const BaseItem*>(other);
|
const BaseItem* casted = static_cast<const BaseItem*>(other);
|
||||||
|
@@ -9,6 +9,11 @@ namespace L2Bot::Domain::Entities
|
|||||||
class EtcItem : public BaseItem
|
class EtcItem : public BaseItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
void Autouse(bool enabled)
|
||||||
|
{
|
||||||
|
m_IsAutoused = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void Update(const EntityInterface* other) override
|
void Update(const EntityInterface* other) override
|
||||||
{
|
{
|
||||||
const EtcItem* casted = static_cast<const EtcItem*>(other);
|
const EtcItem* casted = static_cast<const EtcItem*>(other);
|
||||||
@@ -17,6 +22,7 @@ namespace L2Bot::Domain::Entities
|
|||||||
|
|
||||||
m_Amount = casted->m_Amount;
|
m_Amount = casted->m_Amount;
|
||||||
m_IsQuest = casted->m_IsQuest;
|
m_IsQuest = casted->m_IsQuest;
|
||||||
|
m_IsAutoused = casted->m_IsAutoused;
|
||||||
}
|
}
|
||||||
void SaveState() override
|
void SaveState() override
|
||||||
{
|
{
|
||||||
@@ -24,6 +30,7 @@ namespace L2Bot::Domain::Entities
|
|||||||
m_PrevState =
|
m_PrevState =
|
||||||
{
|
{
|
||||||
m_Amount,
|
m_Amount,
|
||||||
|
m_IsAutoused,
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -32,7 +39,8 @@ namespace L2Bot::Domain::Entities
|
|||||||
const EtcItem* casted = static_cast<const EtcItem*>(other);
|
const EtcItem* casted = static_cast<const EtcItem*>(other);
|
||||||
return BaseItem::IsEqual(other) &&
|
return BaseItem::IsEqual(other) &&
|
||||||
m_IsQuest == casted->m_IsQuest &&
|
m_IsQuest == casted->m_IsQuest &&
|
||||||
m_Amount == casted->m_Amount;
|
m_Amount == casted->m_Amount &&
|
||||||
|
m_IsAutoused == casted->m_IsAutoused;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||||
@@ -48,6 +56,10 @@ namespace L2Bot::Domain::Entities
|
|||||||
{
|
{
|
||||||
result.push_back({ "amount", std::to_string(m_Amount) });
|
result.push_back({ "amount", std::to_string(m_Amount) });
|
||||||
}
|
}
|
||||||
|
if (m_PrevState.isNewState || m_IsAutoused != m_PrevState.isAutoused)
|
||||||
|
{
|
||||||
|
result.push_back({ "isAutoused", std::to_string(m_IsAutoused) });
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -82,7 +94,7 @@ namespace L2Bot::Domain::Entities
|
|||||||
EtcItem(const EtcItem* other) :
|
EtcItem(const EtcItem* other) :
|
||||||
BaseItem(other),
|
BaseItem(other),
|
||||||
m_Amount(other->m_Amount),
|
m_Amount(other->m_Amount),
|
||||||
m_IsQuest(other->m_IsQuest)
|
m_IsAutoused(other->m_IsAutoused)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +105,7 @@ namespace L2Bot::Domain::Entities
|
|||||||
struct GetState
|
struct GetState
|
||||||
{
|
{
|
||||||
uint32_t amount = 0;
|
uint32_t amount = 0;
|
||||||
|
bool isAutoused = false;
|
||||||
|
|
||||||
bool isNewState = true;
|
bool isNewState = true;
|
||||||
};
|
};
|
||||||
@@ -100,6 +113,7 @@ namespace L2Bot::Domain::Entities
|
|||||||
private:
|
private:
|
||||||
uint32_t m_Amount = 0;
|
uint32_t m_Amount = 0;
|
||||||
bool m_IsQuest = false;
|
bool m_IsQuest = false;
|
||||||
|
bool m_IsAutoused = false;
|
||||||
GetState m_PrevState = GetState();
|
GetState m_PrevState = GetState();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
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\EventDispatcher.h" />
|
||||||
<ClInclude Include="Events\HeroCreatedEvent.h" />
|
<ClInclude Include="Events\HeroCreatedEvent.h" />
|
||||||
<ClInclude Include="Events\HeroDeletedEvent.h" />
|
<ClInclude Include="Events\HeroDeletedEvent.h" />
|
||||||
|
<ClInclude Include="Events\ItemAutousedEvent.h" />
|
||||||
<ClInclude Include="Events\ItemCreatedEvent.h" />
|
<ClInclude Include="Events\ItemCreatedEvent.h" />
|
||||||
<ClInclude Include="Events\ItemDeletedEvent.h" />
|
<ClInclude Include="Events\ItemDeletedEvent.h" />
|
||||||
<ClInclude Include="Events\ItemUpdatedEvent.h" />
|
<ClInclude Include="Events\ItemUpdatedEvent.h" />
|
||||||
|
@@ -171,6 +171,9 @@
|
|||||||
<ClInclude Include="Events\ItemDeletedEvent.h">
|
<ClInclude Include="Events\ItemDeletedEvent.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Events\ItemAutousedEvent.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "../../../Events/ItemCreatedEvent.h"
|
#include "../../../Events/ItemCreatedEvent.h"
|
||||||
#include "../../../Events/ItemUpdatedEvent.h"
|
#include "../../../Events/ItemUpdatedEvent.h"
|
||||||
#include "../../../Events/ItemDeletedEvent.h"
|
#include "../../../Events/ItemDeletedEvent.h"
|
||||||
|
#include "../../../Events/ItemAutousedEvent.h"
|
||||||
#include "../../../DTO/ItemData.h"
|
#include "../../../DTO/ItemData.h"
|
||||||
|
|
||||||
namespace Interlude
|
namespace Interlude
|
||||||
@@ -24,6 +25,7 @@ namespace Interlude
|
|||||||
void(__thiscall* GameEngineWrapper::__AddAbnormalStatus)(GameEngine*, L2ParamStack&) = 0;
|
void(__thiscall* GameEngineWrapper::__AddAbnormalStatus)(GameEngine*, L2ParamStack&) = 0;
|
||||||
void(__thiscall* GameEngineWrapper::__AddInventoryItem)(GameEngine*, ItemInfo&) = 0;
|
void(__thiscall* GameEngineWrapper::__AddInventoryItem)(GameEngine*, ItemInfo&) = 0;
|
||||||
void(__thiscall* GameEngineWrapper::__OnReceiveUpdateItemList)(GameEngine*, UpdateItemListActionType, ItemInfo&) = 0;
|
void(__thiscall* GameEngineWrapper::__OnReceiveUpdateItemList)(GameEngine*, UpdateItemListActionType, ItemInfo&) = 0;
|
||||||
|
void(__thiscall* GameEngineWrapper::__OnExAutoSoulShot)(GameEngine*, L2ParamStack&) = 0;
|
||||||
|
|
||||||
|
|
||||||
void GameEngineWrapper::Init(HMODULE hModule)
|
void GameEngineWrapper::Init(HMODULE hModule)
|
||||||
@@ -50,6 +52,9 @@ namespace Interlude
|
|||||||
(FARPROC&)__OnReceiveUpdateItemList = (FARPROC)splice(
|
(FARPROC&)__OnReceiveUpdateItemList = (FARPROC)splice(
|
||||||
GetProcAddress(hModule, "?OnReceiveUpdateItemList@UGameEngine@@UAEXHAAUItemInfo@@@Z"), __OnReceiveUpdateItemList_hook
|
GetProcAddress(hModule, "?OnReceiveUpdateItemList@UGameEngine@@UAEXHAAUItemInfo@@@Z"), __OnReceiveUpdateItemList_hook
|
||||||
);
|
);
|
||||||
|
(FARPROC&)__OnExAutoSoulShot = (FARPROC)splice(
|
||||||
|
GetProcAddress(hModule, "?OnExAutoSoulShot@UGameEngine@@UAEXAAVL2ParamStack@@@Z"), __OnExAutoSoulShot_hook
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEngineWrapper::Restore()
|
void GameEngineWrapper::Restore()
|
||||||
@@ -61,6 +66,7 @@ namespace Interlude
|
|||||||
restore((void*&)__AddAbnormalStatus);
|
restore((void*&)__AddAbnormalStatus);
|
||||||
restore((void*&)__AddInventoryItem);
|
restore((void*&)__AddInventoryItem);
|
||||||
restore((void*&)__OnReceiveUpdateItemList);
|
restore((void*&)__OnReceiveUpdateItemList);
|
||||||
|
restore((void*&)__OnExAutoSoulShot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fastcall GameEngineWrapper::__Init_hook(GameEngine* This, uint32_t /*edx*/, float_t unk)
|
void __fastcall GameEngineWrapper::__Init_hook(GameEngine* This, uint32_t /*edx*/, float_t unk)
|
||||||
@@ -147,4 +153,10 @@ namespace Interlude
|
|||||||
}
|
}
|
||||||
(*__OnReceiveUpdateItemList)(This, actionType, itemInfo);
|
(*__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* __AddAbnormalStatus)(GameEngine*, L2ParamStack&);
|
||||||
static void(__thiscall* __AddInventoryItem)(GameEngine*, ItemInfo&);
|
static void(__thiscall* __AddInventoryItem)(GameEngine*, ItemInfo&);
|
||||||
static void(__thiscall* __OnReceiveUpdateItemList)(GameEngine*, UpdateItemListActionType, 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 __Init_hook(GameEngine* This, uint32_t /*edx*/, float_t unk);
|
||||||
static void __fastcall __OnSkillListPacket_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
|
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 __AddAbnormalStatus_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
|
||||||
static void __fastcall __AddInventoryItem_hook(GameEngine* This, int /*edx*/, ItemInfo& itemInfo);
|
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 __OnReceiveUpdateItemList_hook(GameEngine* This, int /*edx*/, UpdateItemListActionType actionType, ItemInfo& itemInfo);
|
||||||
|
static void __fastcall __OnExAutoSoulShot_hook(GameEngine* This, int /*edx*/, L2ParamStack& stack);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void* originalInitAddress;
|
static void* originalInitAddress;
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include "../../../Events/ItemUpdatedEvent.h"
|
#include "../../../Events/ItemUpdatedEvent.h"
|
||||||
#include "../../../Events/ItemDeletedEvent.h"
|
#include "../../../Events/ItemDeletedEvent.h"
|
||||||
#include "../../../Events/HeroDeletedEvent.h"
|
#include "../../../Events/HeroDeletedEvent.h"
|
||||||
|
#include "../../../Events/ItemAutousedEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
#include "../../../Events/EventDispatcher.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
@@ -61,6 +62,9 @@ namespace Interlude
|
|||||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||||
OnHeroDeleted(evt);
|
OnHeroDeleted(evt);
|
||||||
});
|
});
|
||||||
|
EventDispatcher::GetInstance().Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
|
||||||
|
OnItemAutoused(evt);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnHeroDeleted(const Event& evt)
|
void OnHeroDeleted(const Event& evt)
|
||||||
@@ -71,6 +75,31 @@ namespace Interlude
|
|||||||
Reset();
|
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"
|
//todo need to delete items if they are not exists in create "queue"
|
||||||
void OnItemCreated(const Event& evt)
|
void OnItemCreated(const Event& evt)
|
||||||
|
Reference in New Issue
Block a user