fix: fix item creation

This commit is contained in:
k0t9i
2023-02-01 22:29:36 +04:00
parent 546b371dd6
commit 6cbf61d67f
6 changed files with 39 additions and 5 deletions

View File

@@ -0,0 +1,17 @@
#pragma once
#include "Event.h"
class OnEndItemListEvent : public Event
{
public:
static constexpr const char* name = "onEndItemList";
const std::string GetName() const
{
return std::string(name);
}
OnEndItemListEvent() = default;
virtual ~OnEndItemListEvent() = default;
};

View File

@@ -177,6 +177,7 @@
<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" />
<ClInclude Include="Events\OnEndItemListEvent.h" />
<ClInclude Include="Events\SkillCancelledEvent.h" /> <ClInclude Include="Events\SkillCancelledEvent.h" />
<ClInclude Include="Events\SkillCreatedEvent.h" /> <ClInclude Include="Events\SkillCreatedEvent.h" />
<ClInclude Include="Events\AbnormalEffectChangedEvent.h" /> <ClInclude Include="Events\AbnormalEffectChangedEvent.h" />

View File

@@ -198,6 +198,9 @@
<ClInclude Include="Versions\Interlude\Repositories\ChatMessageRepository.h"> <ClInclude Include="Versions\Interlude\Repositories\ChatMessageRepository.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Events\OnEndItemListEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="dllmain.cpp"> <ClCompile Include="dllmain.cpp">

View File

@@ -14,6 +14,7 @@
#include "../../../Events/ItemAutousedEvent.h" #include "../../../Events/ItemAutousedEvent.h"
#include "../../../Events/GameEngineTickedEvent.h" #include "../../../Events/GameEngineTickedEvent.h"
#include "../../../Events/ChatMessageCreatedEvent.h" #include "../../../Events/ChatMessageCreatedEvent.h"
#include "../../../Events/OnEndItemListEvent.h"
#include "../../../DTO/ItemData.h" #include "../../../DTO/ItemData.h"
#include "FName.h" #include "FName.h"
@@ -30,6 +31,7 @@ namespace Interlude
void(__thiscall* GameEngineWrapper::__OnExAutoSoulShot)(GameEngine*, L2ParamStack&) = 0; void(__thiscall* GameEngineWrapper::__OnExAutoSoulShot)(GameEngine*, L2ParamStack&) = 0;
void(__thiscall* GameEngineWrapper::__Tick)(GameEngine*, float_t) = 0; void(__thiscall* GameEngineWrapper::__Tick)(GameEngine*, float_t) = 0;
void(__thiscall* GameEngineWrapper::__OnSay2)(GameEngine*, L2ParamStack&) = 0; void(__thiscall* GameEngineWrapper::__OnSay2)(GameEngine*, L2ParamStack&) = 0;
void(__thiscall* GameEngineWrapper::__OnEndItemList)(GameEngine*) = 0;
void GameEngineWrapper::Init(HMODULE hModule) void GameEngineWrapper::Init(HMODULE hModule)
@@ -61,6 +63,9 @@ namespace Interlude
(FARPROC&)__OnSay2 = (FARPROC)splice( (FARPROC&)__OnSay2 = (FARPROC)splice(
GetProcAddress(hModule, "?OnSay2@UGameEngine@@UAEXAAVL2ParamStack@@@Z"), __OnSay2_hook GetProcAddress(hModule, "?OnSay2@UGameEngine@@UAEXAAVL2ParamStack@@@Z"), __OnSay2_hook
); );
(FARPROC&)__OnEndItemList = (FARPROC)splice(
GetProcAddress(hModule, "?OnEndItemList@UGameEngine@@UAEXXZ"), __OnEndItemList_hook
);
} }
void GameEngineWrapper::Restore() void GameEngineWrapper::Restore()
@@ -73,6 +78,7 @@ namespace Interlude
restore((void*&)__OnReceiveUpdateItemList); restore((void*&)__OnReceiveUpdateItemList);
restore((void*&)__OnExAutoSoulShot); restore((void*&)__OnExAutoSoulShot);
restore((void*&)__OnSay2); restore((void*&)__OnSay2);
restore((void*&)__OnEndItemList);
} }
void __fastcall GameEngineWrapper::__OnSkillListPacket_hook(GameEngine* This, uint32_t, L2ParamStack& stack) void __fastcall GameEngineWrapper::__OnSkillListPacket_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
@@ -185,4 +191,9 @@ namespace Interlude
(*__OnSay2)(This, stack); (*__OnSay2)(This, stack);
} }
void __fastcall GameEngineWrapper::__OnEndItemList_hook(GameEngine* This, uint32_t)
{
EventDispatcher::GetInstance().Dispatch(OnEndItemListEvent());
(*__OnEndItemList)(This);
}
} }

View File

@@ -28,6 +28,7 @@ namespace Interlude
static void(__thiscall* __OnExAutoSoulShot)(GameEngine*, L2ParamStack&); static void(__thiscall* __OnExAutoSoulShot)(GameEngine*, L2ParamStack&);
static void(__thiscall* __Tick)(GameEngine*, float_t); static void(__thiscall* __Tick)(GameEngine*, float_t);
static void(__thiscall* __OnSay2)(GameEngine*, L2ParamStack&); static void(__thiscall* __OnSay2)(GameEngine*, L2ParamStack&);
static void(__thiscall* __OnEndItemList)(GameEngine*);
static void __fastcall __OnSkillListPacket_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack); static void __fastcall __OnSkillListPacket_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
static int __fastcall __OnReceiveMagicSkillUse_hook(GameEngine* This, uint32_t /*edx*/, User* u1, User* u2, L2ParamStack& stack); static int __fastcall __OnReceiveMagicSkillUse_hook(GameEngine* This, uint32_t /*edx*/, User* u1, User* u2, L2ParamStack& stack);
@@ -38,6 +39,7 @@ namespace Interlude
static void __fastcall __OnExAutoSoulShot_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack); static void __fastcall __OnExAutoSoulShot_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
static void __fastcall __Tick_hook(GameEngine* This, uint32_t /*edx*/, float_t unk); static void __fastcall __Tick_hook(GameEngine* This, uint32_t /*edx*/, float_t unk);
static void __fastcall __OnSay2_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack); static void __fastcall __OnSay2_hook(GameEngine* This, uint32_t /*edx*/, L2ParamStack& stack);
static void __fastcall __OnEndItemList_hook(GameEngine* This, uint32_t /*edx*/);
private: private:
static GameEngine* _target; static GameEngine* _target;

View File

@@ -12,7 +12,7 @@
#include "../../../Events/ItemDeletedEvent.h" #include "../../../Events/ItemDeletedEvent.h"
#include "../../../Events/HeroDeletedEvent.h" #include "../../../Events/HeroDeletedEvent.h"
#include "../../../Events/ItemAutousedEvent.h" #include "../../../Events/ItemAutousedEvent.h"
#include "../../../Events/GameEngineTickedEvent.h" #include "../../../Events/OnEndItemListEvent.h"
#include "../../../Events/EventDispatcher.h" #include "../../../Events/EventDispatcher.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -66,15 +66,15 @@ namespace Interlude
EventDispatcher::GetInstance().Subscribe(ItemAutousedEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
OnItemAutoused(evt); OnItemAutoused(evt);
}); });
EventDispatcher::GetInstance().Subscribe(GameEngineTickedEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(OnEndItemListEvent::name, [this](const Event& evt) {
OnGameEngineTicked(evt); OnEndItemList(evt);
}); });
} }
void OnGameEngineTicked(const Event& evt) void OnEndItemList(const Event& evt)
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex); std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == GameEngineTickedEvent::name) if (evt.GetName() == OnEndItemListEvent::name)
{ {
for (auto it = m_Items.begin(); it != m_Items.end();) for (auto it = m_Items.begin(); it != m_Items.end();)
{ {