Skip to content

Commit

Permalink
Added effect durations for exhaustion, depletion and scorpion for eff…
Browse files Browse the repository at this point in the history
…ect monitor
  • Loading branch information
3vcloud committed Jan 5, 2025
1 parent 787fb9d commit ae05bed
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
Binary file modified Dependencies/GWCA/bin/gwca.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Dependencies/GWCA/include/GWCA/Managers/MemoryMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GW {

GWCA_API uint32_t GetGWVersion();

DWORD GetSkillTimer();
GWCA_API DWORD GetSkillTimer();

GWCA_API bool GetPersonalDir(size_t buf_len, wchar_t* buf);

Expand Down
Binary file modified Dependencies/GWCA/lib/gwca.lib
Binary file not shown.
65 changes: 65 additions & 0 deletions GWToolboxdll/Widgets/EffectsMonitorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <GWCA/Managers/MapMgr.h>
#include <GWCA/Managers/UIMgr.h>
#include <GWCA/Managers/GameThreadMgr.h>
#include <GWCA/Managers/MemoryMgr.h>

#include <Utils/GuiUtils.h>
#include <Color.h>
Expand All @@ -19,6 +20,7 @@
#include "Utils/FontLoader.h"



namespace {
auto font_effects = 18.f;
Color color_text_effects = Colors::White();
Expand Down Expand Up @@ -69,6 +71,25 @@ namespace {
}
draw_list->AddText(label_pos, color_text_effects, text);
}

std::unordered_map<uint32_t, clock_t> effect_timestamps;

GW::HookEntry OnPreUIMessage_HookEntry;
void OnPreUIMessage(GW::HookStatus*, GW::UI::UIMessage message_id, void* wparam, void*) {
switch (message_id) {
case GW::UI::UIMessage::kEffectAdd: {
const auto packet = (GW::UI::UIPacket::kEffectAdd*)wparam;
switch (packet->effect->skill_id) {
case GW::Constants::SkillID::Aspect_of_Exhaustion:
case GW::Constants::SkillID::Aspect_of_Depletion_energy_loss:
case GW::Constants::SkillID::Scorpion_Aspect:
if (!effect_timestamps.contains((uint32_t)packet->effect->skill_id))
effect_timestamps[(uint32_t)packet->effect->skill_id] = GW::MemoryMgr::GetSkillTimer();
break;
}
} break;
}
}
}

void EffectsMonitorWidget::Draw(IDirect3DDevice9*)
Expand Down Expand Up @@ -125,6 +146,50 @@ void EffectsMonitorWidget::Draw(IDirect3DDevice9*)
ImGui::PopFont(draw_list);
}

void EffectsMonitorWidget::Initialize()
{
ToolboxWidget::Initialize();
GW::UI::UIMessage message_ids[] = {
GW::UI::UIMessage::kEffectAdd
};
for (auto message_id : message_ids) {
GW::UI::RegisterUIMessageCallback(&OnPreUIMessage_HookEntry, message_id, OnPreUIMessage, -0x6000);
}
}
void EffectsMonitorWidget::Terminate()
{
ToolboxWidget::Terminate();
GW::UI::RemoveUIMessageCallback(&OnPreUIMessage_HookEntry);
}
void EffectsMonitorWidget::Update(float)
{
for (auto [skill_id, timestamp] : effect_timestamps) {
auto effect = GW::Effects::GetPlayerEffectBySkillId((GW::Constants::SkillID)skill_id);
if (!effect) {
effect_timestamps.erase(skill_id);
break;
}
const auto elapsed = effect->GetTimeElapsed();
if (!effect->duration || (elapsed / 1000.f) > effect->duration) {
const auto now = GW::MemoryMgr::GetSkillTimer();
const clock_t diff = (now - timestamp) / 1000;

// a 30s timer starts when you enter the aspect
// a 30s timer starts 100s after you enter the aspect
// a 30s timer starts 200s after you enter the aspect
long duration = 30 - diff % 30;
if (diff > 100) {
duration = std::min(duration, 30 - (diff - 100) % 30);
}
if (diff > 200) {
duration = std::min(duration, 30 - (diff - 200) % 30);
}
effect->timestamp = now;
effect->duration = (float)duration;
}
}
}

void EffectsMonitorWidget::LoadSettings(ToolboxIni* ini)
{
ToolboxWidget::LoadSettings(ini);
Expand Down
4 changes: 4 additions & 0 deletions GWToolboxdll/Widgets/EffectsMonitorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class EffectsMonitorWidget : public ToolboxWidget {

[[nodiscard]] const char* Icon() const override { return ICON_FA_HISTORY; }

void Initialize() override;
void Terminate() override;
void Update(float) override;

void LoadSettings(ToolboxIni* ini) override;
void SaveSettings(ToolboxIni* ini) override;
void DrawSettingsInternal() override;
Expand Down

0 comments on commit ae05bed

Please sign in to comment.