Skip to content

Commit

Permalink
Merge pull request #38 from RaidcoreGG/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DeltaGW2 authored Apr 20, 2024
2 parents efb4303 + 93a163f commit f3f2d48
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Consts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const char* EV_WINDOW_RESIZED = "EV_WINDOW_RESIZED";
const char* EV_MUMBLE_IDENTITY_UPDATED = "EV_MUMBLE_IDENTITY_UPDATED";
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";
const char* EV_VOLATILE_ADDON_DISABLED = "EV_VOLATILE_ADDON_DISABLED";

/* DataLink */
const char* DL_MUMBLE_LINK = "DL_MUMBLE_LINK";
Expand Down
2 changes: 1 addition & 1 deletion src/Consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern const char* EV_WINDOW_RESIZED;
extern const char* EV_MUMBLE_IDENTITY_UPDATED;
extern const char* EV_ADDON_LOADED;
extern const char* EV_ADDON_UNLOADED;
extern const char* EV_VOLATILE_ADDONS_DISABLED;
extern const char* EV_VOLATILE_ADDON_DISABLED;

/* DataLink */
extern const char* DL_MUMBLE_LINK;
Expand Down
35 changes: 21 additions & 14 deletions src/GUI/Widgets/Addons/AddonItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "Events/EventHandler.h"

#include "GUI/Widgets/Alerts/Alerts.h"

#include "imgui.h"
#include "imgui_extensions.h"

Expand Down Expand Up @@ -213,7 +215,7 @@ namespace GUI
ImGui::GW2::TooltipGeneric(Language.Translate("((000021))"));
}
}
else if (aAddon->State == EAddonState::LoadedLOCKED && aAddon->IsFlaggedForDisable == false)
else if (aAddon->State == EAddonState::LoadedLOCKED)
{
std::string additionalInfo;

Expand All @@ -223,27 +225,31 @@ namespace GUI
additionalInfo.append(Language.Translate("((000021))"));
}

if (ImGui::GW2::Button((Language.Translate("((000022))") + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
if (ImGui::GW2::Button((Language.Translate(aAddon->IsFlaggedForDisable ? "((000024))" : "((000022))") + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
aAddon->IsFlaggedForDisable = true;
aAddon->IsFlaggedForDisable = !aAddon->IsFlaggedForDisable;
Loader::SaveAddonConfig();
}
ImGui::GW2::TooltipGeneric(Language.Translate("((000023))"), additionalInfo.c_str());
ImGui::GW2::TooltipGeneric(Language.Translate(aAddon->IsFlaggedForDisable ? "((000025))" : "((000023))"), additionalInfo.c_str());
}
else if (aAddon->State == EAddonState::LoadedLOCKED && aAddon->IsFlaggedForDisable == true)
else if (aAddon->State == EAddonState::NotLoaded && (aAddon->Definitions->HasFlag(EAddonFlags::OnlyLoadDuringGameLaunchSequence) || aAddon->Definitions->Signature == 0xFFF694D1) && !IsGameLaunchSequence)
{
std::string additionalInfo;

if (RequestedAddons.size() > 0)
/* if it's too late to load this addon */
if (ImGui::GW2::Button((Language.Translate(aAddon->IsFlaggedForEnable ? "((000020))" : "((000024))") + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
{
additionalInfo.append("\n");
additionalInfo.append(Language.Translate("((000021))"));
aAddon->IsFlaggedForEnable = !aAddon->IsFlaggedForEnable;
if (aAddon->IsFlaggedForEnable)
{
std::string msg = aAddon->Definitions->Name;
msg.append(" ");
msg.append(Language.Translate("((000080))"));
GUI::Alerts::Notify(msg.c_str());
}
}

if (ImGui::GW2::Button((Language.Translate("((000024))") + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
if (aAddon->IsFlaggedForEnable)
{
aAddon->IsFlaggedForDisable = false;
ImGui::GW2::TooltipGeneric(Language.Translate("((000025))"), "");
}
ImGui::GW2::TooltipGeneric(Language.Translate("((000025))"), additionalInfo.c_str());
}
else if (aAddon->State == EAddonState::NotLoaded)
{
Expand All @@ -258,6 +264,7 @@ namespace GUI
ImGui::GW2::TooltipGeneric(Language.Translate("((000021))"));
}
}

if (aAddon->Definitions->Provider == EUpdateProvider::GitHub && aAddon->Definitions->UpdateLink)
{
if (ImGui::GW2::Button((Language.Translate("((000030))") + sig).c_str(), ImVec2(btnWidth * ImGui::GetFontSize(), btnHeight)))
Expand Down
1 change: 1 addition & 0 deletions src/Loader/Addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Addon
bool IsWaitingForUnload;
bool IsFlaggedForUninstall;
bool IsFlaggedForDisable;
bool IsFlaggedForEnable;
};

#endif
7 changes: 4 additions & 3 deletions src/Loader/EAddonFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

enum class EAddonFlags
{
None = 0,
IsVolatile = 1, /* is hooking functions or doing anything else that's volatile and game build dependant */
DisableHotloading = 2 /* prevents unloading at runtime, aka. will require a restart if updated, etc. */
None = 0,
IsVolatile = 1 << 0, /* is hooking functions or doing anything else that's volatile and game build dependant */
DisableHotloading = 1 << 1, /* prevents unloading at runtime, aka. will require a restart if updated, etc. */
OnlyLoadDuringGameLaunchSequence = 1 << 2 /* prevents loading later than character select, aka will require restart to get loaded */
};

EAddonFlags operator|(EAddonFlags lhs, EAddonFlags rhs);
Expand Down
95 changes: 78 additions & 17 deletions src/Loader/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace Loader

std::vector<signed int> WhitelistedAddons; /* List of addons that should be loaded on initial startup. */

bool DisableVolatileUntilUpdate = false;
bool DisableVolatileUntilUpdate = false;

void Initialize()
{
Expand Down Expand Up @@ -112,6 +112,25 @@ namespace Loader
std::thread arclib(ArcDPS::GetPluginLibrary);
arclib.detach();

std::thread checkLaunchSequence([]()
{
Sleep(5000);
int nothingCounter = 0;
while (!IsGameplay)
{
/* do nothing */
Sleep(1);
nothingCounter++;

if (nothingCounter > 10000)
{
break;
}
}
IsGameLaunchSequence = false;
});
checkLaunchSequence.detach();

LoaderThread = std::thread(ProcessChanges);
LoaderThread.detach();
}
Expand Down Expand Up @@ -232,13 +251,13 @@ namespace Loader
json addonInfo =
{
{"Signature", addon->Definitions ? addon->Definitions->Signature : addon->MatchSignature},
{"IsLoaded", addon->State == EAddonState::Loaded || addon->State == EAddonState::LoadedLOCKED ? true : false},
{"IsLoaded", addon->State == EAddonState::Loaded || addon->State == EAddonState::LoadedLOCKED || addon->IsFlaggedForEnable},
{"IsPausingUpdates", addon->IsPausingUpdates},
{"IsDisabledUntilUpdate", addon->IsDisabledUntilUpdate}
};

/* override loaded state, if it's supposed to disable next launch */
if (addon->State == EAddonState::LoadedLOCKED && addon->IsFlaggedForDisable)
if (addon->IsFlaggedForDisable)
{
addonInfo["IsLoaded"] = false;
}
Expand Down Expand Up @@ -387,7 +406,6 @@ namespace Loader
DisableVolatileUntilUpdate = true;
LogWarning(CH_LOADER, "Game updated. Current Build %d. Old Build: %d. Disabling volatile addons until they update.", gameBuild, lastGameBuild);

Events::Raise(EV_VOLATILE_ADDONS_DISABLED);
std::string msg = Language.Translate("((000001))");
msg.append("\n");
msg.append(Language.Translate("((000002))"));
Expand Down Expand Up @@ -435,7 +453,12 @@ namespace Loader
if ((addon->MD5.empty() || addon->MD5 != md5) || std::filesystem::exists(updatePath))
{
UpdateSwapAddon(addon->Path);
QueueAddon(ELoaderAction::Reload, addon->Path);

// only reload if it already is loadedw
if (addon->State == EAddonState::Loaded)
{
QueueAddon(ELoaderAction::Reload, addon->Path);
}
}
}

Expand Down Expand Up @@ -671,13 +694,22 @@ namespace Loader

/* predeclare locked helper for later */
bool locked = addon->Definitions->Unload == nullptr || addon->Definitions->HasFlag(EAddonFlags::DisableHotloading);
bool onlyInitialLaunch = addon->Definitions->HasFlag(EAddonFlags::OnlyLoadDuringGameLaunchSequence) || addon->Definitions->Signature == 0xFFF694D1;
// FIXME: remove the arcdps check as soon as it adds the flag

/* override shoudLoad */
if (!IsGameLaunchSequence && onlyInitialLaunch)
{
shouldLoad = false;
}

/* don't update when reloading; check when: it's waiting to re-enable but wasn't manually invoked, it's not pausing updates atm */
if (!aIsReload && ((addon->IsDisabledUntilUpdate && isInitialLoad) || !addon->IsPausingUpdates))
{
std::filesystem::path tmpPath = aPath.string();
std::thread([tmpPath, addon, locked, shouldLoad]()
std::thread([tmpPath, addon, locked, shouldLoad, onlyInitialLaunch]()
{
bool lShouldLoad = shouldLoad;
if (UpdateAddon(tmpPath, addon->Definitions->Signature, addon->Definitions->Name,
addon->Definitions->Version, addon->Definitions->Provider,
addon->Definitions->UpdateLink != nullptr ? addon->Definitions->UpdateLink : ""))
Expand All @@ -687,33 +719,55 @@ namespace Loader
{
// reset state, because it updated
addon->IsDisabledUntilUpdate = false;
lShouldLoad = true;

// mutex because we're async/threading
{
const std::lock_guard<std::mutex> lock(Mutex);
SaveAddonConfig(); // save the DUU state
}
}
QueueAddon(ELoaderAction::Reload, tmpPath);

/* only call reload if it wasn't unloaded */
if (lShouldLoad)
{
if (!onlyInitialLaunch)
{
QueueAddon(ELoaderAction::Reload, tmpPath);
}
else
{
std::string msg = addon->Definitions->Name;
msg.append(" ");
msg.append(Language.Translate("((000079))"));
GUI::Alerts::Notify(msg.c_str());
}
}
}
else if (locked && shouldLoad && !addon->IsDisabledUntilUpdate) // if addon is locked and not DUU
else if (locked && lShouldLoad && !addon->IsDisabledUntilUpdate) // if addon is locked and not DUU
{
// the lock state is checked because if it will be locked it means it was unloaded, prior to checking for an update
QueueAddon(ELoaderAction::Reload, tmpPath);

/* only call reload if it wasn't unloaded */
if (!onlyInitialLaunch)
{
QueueAddon(ELoaderAction::Reload, tmpPath);
}
}
else if (addon->IsDisabledUntilUpdate && DisableVolatileUntilUpdate) // if addon is DUP and the global state is too
{
// show message that addon was disabled due to game update
std::string msg = addon->Definitions->Name;
msg.append(" ");
msg.append(Language.Translate("((000073))"));
Events::Raise(EV_VOLATILE_ADDON_DISABLED, &addon->Definitions->Signature);
GUI::Alerts::Notify(msg.c_str());
}
})
.detach();

/* if will be locked, explicitly unload so the update can invoke a reload */
if (locked)
if (locked && !onlyInitialLaunch)
{
FreeLibrary(addon->Module);
addon->State = EAddonState::NotLoaded;
Expand Down Expand Up @@ -836,6 +890,16 @@ namespace Loader
addon->IsWaitingForUnload = true;
std::thread unloadTask([addon, aPath, isShutdown, aDoReload]()
{
if (!isShutdown)
{
/* cache the flag, save that the addon will disable, then restore it */
bool flagDisable = addon->IsFlaggedForDisable;
addon->IsFlaggedForDisable = true;
const std::lock_guard<std::mutex> lock(Mutex);
SaveAddonConfig();
addon->IsFlaggedForDisable = flagDisable;
}

std::chrono::steady_clock::time_point start_time = std::chrono::high_resolution_clock::now();
if (addon->Definitions->Unload)
{
Expand Down Expand Up @@ -884,11 +948,6 @@ namespace Loader
unloadTask.detach();
}
}

if (!isShutdown)
{
SaveAddonConfig();
}
}

void FreeAddon(const std::filesystem::path& aPath)
Expand Down Expand Up @@ -927,6 +986,8 @@ namespace Loader

addon->State = EAddonState::NotLoaded;

SaveAddonConfig();

if (!std::filesystem::exists(aPath))
{
auto it = std::find(Addons.begin(), Addons.end(), addon);
Expand Down Expand Up @@ -1259,7 +1320,7 @@ namespace Loader
return false;
}

auto lmHeader = resultMd5Req->headers.find("Last-Modified");
/*auto lmHeader = resultMd5Req->headers.find("Last-Modified");
if (lmHeader != resultMd5Req->headers.end())
{
Expand All @@ -1278,7 +1339,7 @@ namespace Loader
{
return false;
}
}
}*/

size_t bytesWritten = 0;
std::ofstream fileUpdate(pathUpdate, std::ofstream::binary);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales
Submodule Locales updated 2 files
+3 −2 de_Main.json
+3 −1 en_Main.json
2 changes: 2 additions & 0 deletions src/Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ CAPIClient* GitHubAPI = nullptr;

std::string ChangelogText;
bool IsUpdateAvailable = false;

bool IsGameLaunchSequence = true;
2 changes: 2 additions & 0 deletions src/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ extern CAPIClient* GitHubAPI;
extern std::string ChangelogText;
extern bool IsUpdateAvailable;

extern bool IsGameLaunchSequence;

#endif
16 changes: 16 additions & 0 deletions src/imgui/imgui_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ namespace ImGui
return ret;
}

static bool ButtonDisabled(const char* label, const ImVec2& size_arg = ImVec2(0, 0))
{
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 0, 0, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 1.0f));
ImGui::PushStyleColor(ImGuiCol_BorderShadow, ImVec4(0, 0, 0, 0));
bool ret = ButtonEx(label, size_arg, ImGuiButtonFlags_None);
ImGui::PopStyleColor(6);
ImGui::PopStyleVar(1);

return ret;
}

static bool ContextMenuItem(const char* id, const char* label, ImTextureID bullet_texture_id, ImTextureID highlight_texture_id, const ImVec2& size_arg = ImVec2(0, 0))
{
float itemWidth = ImGui::GetWindowContentRegionWidth();
Expand Down

0 comments on commit f3f2d48

Please sign in to comment.