Skip to content

Commit

Permalink
addon disabler
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaGW2 committed Mar 5, 2024
1 parent 050b4d0 commit 7b8ffc2
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 182 deletions.
3 changes: 1 addition & 2 deletions src/Consts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const char* QA_MENU = "0_QA_MENU";
/* Events */
const char* EV_WINDOW_RESIZED = "EV_WINDOW_RESIZED";
const char* EV_MUMBLE_IDENTITY_UPDATED = "EV_MUMBLE_IDENTITY_UPDATED";
const char* EV_OPTIONS_CALLED = "EV_OPTIONS_CALLED";
const char* EV_EULA_ACCEPTED = "EV_EULA_ACCEPTED";
const char* EV_ADDON_LOADED = "EV_ADDON_LOADED";
const char* EV_ADDON_UNLOADED = "EV_ADDON_UNLOADED";
const char* EV_VOLATILE_ADDONS_DISABLED = "EV_VOLATILE_ADDONS_DISABLED";

/* DataLink */
const char* DL_MUMBLE_LINK = "DL_MUMBLE_LINK";
Expand Down
3 changes: 1 addition & 2 deletions src/Consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ extern const char* QA_MENU;
/* Events */
extern const char* EV_WINDOW_RESIZED;
extern const char* EV_MUMBLE_IDENTITY_UPDATED;
extern const char* EV_OPTIONS_CALLED;
extern const char* EV_EULA_ACCEPTED;
extern const char* EV_ADDON_LOADED;
extern const char* EV_ADDON_UNLOADED;
extern const char* EV_VOLATILE_ADDONS_DISABLED;

/* DataLink */
extern const char* DL_MUMBLE_LINK;
Expand Down
58 changes: 58 additions & 0 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,63 @@ namespace GUI
}
}

/* FIXME: quick and dirty hack for now */
class CVolatileAddonsDisabledNotification : public IWindow
{
public:
float Opacity = 1.0f;

CVolatileAddonsDisabledNotification()
{
Name = "CVolatileAddonsDisabledNotification";
}
void Render()
{
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, Opacity);

ImVec2 center(Renderer::Width * 0.5f, Renderer::Height * 0.5f);
ImGui::SetNextWindowPos(center, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
if (ImGui::Begin("##CVolatileAddonsDisabledNotification", (bool*)0, (ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar)))
{
ImGui::PushFont(FontBig);
ImGui::TextColoredOutlined(ImVec4(1, 0, 0, 1), "Some addons were disabled due to a game update.");
ImGui::TextColoredOutlined(ImVec4(1, 0, 0, 1), "Manually re-enable them or wait for them to update.");
ImGui::PopFont();

ImGui::End();
}

ImGui::PopStyleVar();
}
};

void OnVolatileAddonsDisabled(void* aEventArgs)
{
CVolatileAddonsDisabledNotification* notif = new CVolatileAddonsDisabledNotification();
AddWindow(notif);
std::thread([notif]()
{
Sleep(10000);
while (notif->Opacity > 0)
{
notif->Opacity -= 0.1f;
Sleep(35);
}

GUI::Mutex.lock();
auto it = std::find(GUI::Windows.begin(), GUI::Windows.end(), notif);

if (it != GUI::Windows.end())
{
delete (*it);
GUI::Windows.erase(it);
}
GUI::Mutex.unlock();
})
.detach();
}
/* FIXME: end */

void Setup()
{
ImGuiIO& io = ImGui::GetIO();
Expand Down Expand Up @@ -630,6 +687,7 @@ namespace GUI
io.Fonts->Build();

Events::Subscribe(EV_MUMBLE_IDENTITY_UPDATED, OnMumbleIdentityChanged);
Events::Subscribe(EV_VOLATILE_ADDONS_DISABLED, OnVolatileAddonsDisabled);
OnMumbleIdentityChanged(nullptr);

/* set up and add windows */
Expand Down
52 changes: 25 additions & 27 deletions src/GUI/Widgets/Addons/AddonItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace GUI
Texture* CtxMenuBullet = nullptr;
Texture* CtxMenuHighlight = nullptr;

void AddonItem(Addon* aAddon)
void AddonItem(std::filesystem::path aPath, Addon* aAddon)
{
if (aAddon == nullptr ||
aAddon->Definitions == nullptr ||
Expand Down Expand Up @@ -156,19 +156,30 @@ namespace GUI

ImGui::Separator();

if (ImGui::GW2::ContextMenuItem(("Uninstall##" + sig).c_str(), "Uninstall", CtxMenuBullet->Resource, CtxMenuHighlight->Resource, ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
if (ImGui::GW2::ContextMenuItem(("ToggleDUU##" + sig).c_str(), aAddon->IsDisabledUntilUpdate ? "Re-Enable" : "Disable until Update", CtxMenuBullet->Resource, CtxMenuHighlight->Resource, ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
for (auto& it : Loader::Addons)
//LogDebug(CH_GUI, "ToggleDUU called: %s", it.second->Definitions->Name);
aAddon->IsDisabledUntilUpdate = !aAddon->IsDisabledUntilUpdate;
Loader::SaveAddonConfig();

if (aAddon->State == EAddonState::Loaded)
{
if (it.second->Definitions == aAddon->Definitions)
{
//LogDebug(CH_GUI, "Uninstall called: %s", it.second->Definitions->Name);
Loader::QueueAddon(ELoaderAction::Uninstall, it.first);
break;
}
Loader::QueueAddon(ELoaderAction::Unload, aPath);
}
}
if (aAddon->State == EAddonState::LoadedLOCKED)
{
ImGui::GW2::TooltipGeneric("This addon is currently locked disabling won't take effect until next game start.");
}

ImGui::Separator();

if (ImGui::GW2::ContextMenuItem(("Uninstall##" + sig).c_str(), "Uninstall", CtxMenuBullet->Resource, CtxMenuHighlight->Resource, ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
//LogDebug(CH_GUI, "Uninstall called: %s", it.second->Definitions->Name);
Loader::QueueAddon(ELoaderAction::Uninstall, aPath);
}
if (aAddon->State == EAddonState::LoadedLOCKED)
{
ImGui::GW2::TooltipGeneric("This addon is currently locked and requires a restart to be removed.");
}
Expand All @@ -186,15 +197,8 @@ namespace GUI
{
if (ImGui::GW2::Button(("Disable##" + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
for (auto& it : Loader::Addons)
{
if (it.second->Definitions == aAddon->Definitions)
{
//LogDebug(CH_GUI, "Unload called: %s", it.second->Definitions->Name);
Loader::QueueAddon(ELoaderAction::Unload, it.first);
break;
}
}
//LogDebug(CH_GUI, "Unload called: %s", it.second->Definitions->Name);
Loader::QueueAddon(ELoaderAction::Unload, aPath);
}
if (RequestedAddons.size() > 0)
{
Expand Down Expand Up @@ -235,15 +239,9 @@ namespace GUI
{
if (ImGui::GW2::Button(("Load##" + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
for (auto& it : Loader::Addons)
{
if (it.second->Definitions == aAddon->Definitions)
{
//LogDebug(CH_GUI, "Load called: %s", it.second->Definitions->Name);
Loader::QueueAddon(ELoaderAction::Load, it.first);
break;
}
}
//LogDebug(CH_GUI, "Load called: %s", it.second->Definitions->Name);
aAddon->IsDisabledUntilUpdate = false; // explicitly loaded
Loader::QueueAddon(ELoaderAction::Load, aPath);
}
if (RequestedAddons.size() > 0)
{
Expand Down
4 changes: 3 additions & 1 deletion src/GUI/Widgets/Addons/AddonItem.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#ifndef GUI_ADDONITEM_H
#define GUI_ADDONITEM_H

#include <filesystem>

#include "Loader/Addon.h"
#include "Loader/LibraryAddon.h"

namespace GUI
{
void AddonItem(Addon* aAddon);
void AddonItem(std::filesystem::path aPath, Addon* aAddon);
void AddonItem(LibraryAddon* aAddon, bool aInstalled = false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Widgets/Addons/CAddonsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace GUI
for (auto& [path, addon] : Loader::Addons)
{
if (path.filename() == "arcdps_integration64.dll") { continue; }
AddonItem(addon);
AddonItem(path, addon);
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/GUI/Widgets/Debug/CDebugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ namespace GUI
std::string state = "State: ";
switch (addon->State)
{
case EAddonState::None: state.append("None"); break;
case EAddonState::Loaded: state.append("Loaded"); break;
case EAddonState::LoadedLOCKED: state.append("LoadedLOCKED"); break;
case EAddonState::NotLoaded: state.append("NotLoaded"); break;
case EAddonState::NotLoadedDuplicate: state.append("NotLoadedDuplicate"); break;
case EAddonState::NotLoadedIncompatible: state.append("NotLoadedIncompatible"); break;
case EAddonState::None: state.append("None"); break;
case EAddonState::Loaded: state.append("Loaded"); break;
case EAddonState::LoadedLOCKED: state.append("LoadedLOCKED"); break;
case EAddonState::NotLoaded: state.append("NotLoaded"); break;
case EAddonState::NotLoadedDuplicate: state.append("NotLoadedDuplicate"); break;
case EAddonState::NotLoadedIncompatible: state.append("NotLoadedIncompatible"); break;
case EAddonState::NotLoadedIncompatibleAPI: state.append("NotLoadedIncompatibleAPI"); break;
}

Expand All @@ -281,6 +281,11 @@ namespace GUI
ImGui::TextDisabled("Module Size: %u", addon->ModuleSize);
ImGui::TextDisabled("MD5: %s", MD5ToString(addon->MD5).c_str());
ImGui::TextDisabled("Definitions: %p", addon->Definitions);
ImGui::Separator();
ImGui::TextDisabled("ShouldDisableNextLaunch: %s", addon->ShouldDisableNextLaunch ? "true" : "false");
ImGui::TextDisabled("IsPausingUpdates: %s", addon->IsPausingUpdates ? "true" : "false");
ImGui::TextDisabled("WillBeUninstalled: %s", addon->WillBeUninstalled ? "true" : "false");
ImGui::TextDisabled("IsDisabledUntilUpdate: %s", addon->IsDisabledUntilUpdate ? "true" : "false");

if (addon->Definitions != nullptr)
{
Expand Down
1 change: 1 addition & 0 deletions src/Loader/Addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Addon
bool ShouldDisableNextLaunch;
bool IsPausingUpdates;
bool WillBeUninstalled;
bool IsDisabledUntilUpdate;
};

#endif
Loading

0 comments on commit 7b8ffc2

Please sign in to comment.