Skip to content

Commit

Permalink
remove InstanceTimer plugin, instead create ExamplePlugin that can al…
Browse files Browse the repository at this point in the history
…ways run to check for stability
  • Loading branch information
DubbleClick committed May 20, 2024
1 parent 919a46e commit 301d366
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 360 deletions.
2 changes: 1 addition & 1 deletion Dependencies/GWCA
Submodule GWCA updated from c53ea3 to 3fdd93
16 changes: 1 addition & 15 deletions GWToolboxdll/Windows/FactionLeaderboardWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
#include "stdafx.h"

#include <GWCA/Constants/Constants.h>

#include <GWCA/Packets/StoC.h>

#include <GWCA/GameEntities/Map.h>
#include <GWCA/Context/GuildContext.h>

#include <GWCA/Managers/UIMgr.h>
#include <GWCA/Managers/MapMgr.h>
#include <GWCA/Managers/StoCMgr.h>

#include <Modules/Resources.h>

#include <Utils/GuiUtils.h>

#include <Windows/FactionLeaderboardWindow.h>

void FactionLeaderboardWindow::Draw(IDirect3DDevice9*)
Expand Down Expand Up @@ -44,8 +31,7 @@ void FactionLeaderboardWindow::Draw(IDirect3DDevice9*)
ImGui::Separator();
bool has_entries = false;

const auto g = GW::GetGuildContext();
if (g) {
if (const auto g = GW::GetGuildContext()) {
const auto& leaderboard = g->factions_outpost_guilds;
for (const auto& e : leaderboard) {
has_entries = true;
Expand Down
2 changes: 1 addition & 1 deletion GWToolboxdll/Windows/ObjectiveTimerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void ObjectiveTimerWindow::Initialize()
&PartyDefeated_Entry, [this](GW::HookStatus*, GW::Packet::StoC::PartyDefeated*) { StopObjectives(); });

// NB: Server may not send packets in the order we want them
// e.g. InstanceLoadInfo comes in before InstanceTimer which means the run start is whacked out
// e.g. InstanceLoadInfo comes in before ExamplePlugin which means the run start is whacked out
// keep track of the packets and only trigger relevent events when the needed packets are in.
GW::StoC::RegisterPostPacketCallback<GW::Packet::StoC::InstanceLoadInfo>(&InstanceLoadInfo_Entry,
[this](GW::HookStatus*, const GW::Packet::StoC::InstanceLoadInfo* packet) {
Expand Down
2 changes: 1 addition & 1 deletion cmake/gwtoolboxdll_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ macro(add_tb_plugin PLUGIN)
set_target_properties(${PLUGIN} PROPERTIES FOLDER "plugins/")
endmacro()

add_tb_plugin(InstanceTimer)
add_tb_plugin(ExamplePlugin)
12 changes: 6 additions & 6 deletions plugins/Base/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
#define PLUGIN_ASSERT(expr) ((void)(!!(expr) || (std::cerr << (#expr, __FILE__, (unsigned)__LINE__), 0)))
#endif

#define LOAD_BOOL(var) var = ini->GetBoolValue(Name(), #var, var);
#define SAVE_BOOL(var) ini->SetBoolValue(Name(), #var, var);
#define LOAD_FLOAT(var) var = static_cast<float>(ini->GetDoubleValue(Name(), #var, static_cast<double>(var)));
#define SAVE_FLOAT(var) ini->SetDoubleValue(Name(), #var, static_cast<double>(var));
#define LOAD_UINT(var) var = static_cast<unsigned int>(ini->GetLongValue(Name(), #var, static_cast<long>(var)));
#define SAVE_UINT(var) ini->SetLongValue(Name(), #var, static_cast<long>(var));
#define PLUGIN_LOAD_BOOL(var) var = ini.GetBoolValue(Name(), #var, var);
#define PLUGIN_SAVE_BOOL(var) ini.SetBoolValue(Name(), #var, var);
#define PLUGIN_LOAD_FLOAT(var) var = static_cast<float>(ini.GetDoubleValue(Name(), #var, static_cast<double>(var)));
#define PLUGIN_SAVE_FLOAT(var) ini.SetDoubleValue(Name(), #var, static_cast<double>(var));
#define PLUGIN_LOAD_UINT(var) var = static_cast<unsigned int>(ini.GetLongValue(Name(), #var, static_cast<long>(var)));
#define PLUGIN_SAVE_UINT(var) ini.SetLongValue(Name(), #var, static_cast<long>(var));
76 changes: 76 additions & 0 deletions plugins/ExamplePlugin/ExamplePlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "ExamplePlugin.h"

#include <GWCA/Constants/Constants.h>
#include <GWCA/Managers/MapMgr.h>

#include <Utils/GuiUtils.h>
#include <GWCA/GWCA.h>
#include <GWCA/Utilities/Hooker.h>

#include "GWCA/Managers/ChatMgr.h"
#include "Modules/ChatLog.h"

namespace {
bool redirect_slash_ee_to_eee = false;
}

DLLAPI ToolboxPlugin* ToolboxPluginInstance()
{
static ExamplePlugin instance;
return &instance;
}

void ExamplePlugin::LoadSettings(const wchar_t* folder)
{
ToolboxUIPlugin::LoadSettings(folder);
PLUGIN_LOAD_BOOL(redirect_slash_ee_to_eee);
}

void ExamplePlugin::SaveSettings(const wchar_t* folder)
{
ToolboxUIPlugin::SaveSettings(folder);
PLUGIN_SAVE_BOOL(redirect_slash_ee_to_eee);
PLUGIN_ASSERT(ini.SaveFile(GetSettingFile(folder).c_str()) == SI_OK);
}

void ExamplePlugin::DrawSettings()
{
if (!toolbox_handle) {
return;
}
ImGui::Checkbox("Redirect ee to eee", &redirect_slash_ee_to_eee);
}

void ExamplePlugin::Initialize(ImGuiContext* ctx, const ImGuiAllocFns allocator_fns, const HMODULE toolbox_dll)
{
ToolboxUIPlugin::Initialize(ctx, allocator_fns, toolbox_dll);
GW::Chat::CreateCommand(L"ee", [](const wchar_t*, const int, const LPWSTR*) {
if (redirect_slash_ee_to_eee) {
GW::Chat::SendChat('/', "eee");
}
});
}
void ExamplePlugin::SignalTerminate()
{
ToolboxUIPlugin::SignalTerminate();
GW::Chat::DeleteCommand(L"ee");
GW::DisableHooks();
}

bool ExamplePlugin::CanTerminate() {
return GW::Hook::GetInHookCount() == 0;
}

void ExamplePlugin::Draw(IDirect3DDevice9*)
{
if (GW::Map::GetInstanceType() != GW::Constants::InstanceType::Loading) {
return;
}

ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
if (ImGui::Begin(Name(), GetVisiblePtr(), ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar)) {
ImGui::Text("Example plugin: area loading...");
}
ImGui::End();
ImGui::PopStyleColor();
}
26 changes: 26 additions & 0 deletions plugins/ExamplePlugin/ExamplePlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <ToolboxUIPlugin.h>

class ExamplePlugin : public ToolboxUIPlugin {
public:
ExamplePlugin()
{
can_show_in_main_window = false;
show_title = false;
can_collapse = false;
can_close = false;
}
~ExamplePlugin() override = default;

const char* Name() const override { return "Example Plugin"; }

void LoadSettings(const wchar_t*) override;
void SaveSettings(const wchar_t*) override;
void DrawSettings() override;
void Initialize(ImGuiContext* ctx, ImGuiAllocFns allocator_fns, HMODULE toolbox_dll) override;
void SignalTerminate() override;
bool CanTerminate() override;
// Draw user interface. Will be called every frame if the element is visible
void Draw(IDirect3DDevice9* pDevice) override;
};
Loading

0 comments on commit 301d366

Please sign in to comment.