Skip to content

Commit

Permalink
Merge pull request #10 from RaidcoreGG/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DeltaGW2 authored Nov 14, 2023
2 parents b812591 + 253629f commit abadd0d
Show file tree
Hide file tree
Showing 32 changed files with 315 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Debug
BUILD_CONFIGURATION: Release

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion GW2-AddonHost.sln → Nexus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32126.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Raidcore-AddonHost", "src\Raidcore-AddonHost.vcxproj", "{70B0E807-04CF-46A6-B838-7904E154581E}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nexus", "src\Nexus.vcxproj", "{70B0E807-04CF-46A6-B838-7904E154581E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 1 addition & 0 deletions src/Consts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const char* CH_LOADER = "Loader";
const char* CH_DATALINK = "DataLink";
const char* CH_KEYBINDS = "Keybinds";
const char* CH_GUI = "GUI";
const char* CH_UPDATER = "Updater";

/* Keybinds */
const char* KB_MENU = "KB_MENU";
Expand Down
1 change: 1 addition & 0 deletions src/Consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern const char* CH_LOADER;
extern const char* CH_DATALINK;
extern const char* CH_KEYBINDS;
extern const char* CH_GUI;
extern const char* CH_UPDATER;

/* Keybinds */
extern const char* KB_MENU;
Expand Down
15 changes: 14 additions & 1 deletion src/GUI/Widgets/About/AboutBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ namespace GUI
ImGui::TextDisabled("Renderer:");
ImGui::Text(""); ImGui::SameLine(); ImGui::Text("DirectX 11"); ImGui::SameLine(); ImGui::TextDisabled("Method %d %s", State::EntryMethod, State::IsChainloading ? "Chainloading" : "");

if (State::MultiboxState == EMultiboxState::READY) { ImGui::TextDisabled("Multibox ready."); }
if (State::MultiboxState == EMultiboxState::READY)
{
ImGui::TextDisabled("Multibox ready.");
}
else
{
if (State::MultiboxState != EMultiboxState::NONE)
{
ImGui::TextDisabled("Multibox State:");
if ((bool)(State::MultiboxState & EMultiboxState::ARCHIVE_SHARED)) { ImGui::Text(""); ImGui::SameLine(); ImGui::Text("Archive shared."); }
if ((bool)(State::MultiboxState & EMultiboxState::LOCAL_SHARED)) { ImGui::Text(""); ImGui::SameLine(); ImGui::Text("Local shared."); }
if ((bool)(State::MultiboxState & EMultiboxState::MUTEX_CLOSED)) { ImGui::Text(""); ImGui::SameLine(); ImGui::Text("Mutex closed."); }
}
}

ImGui::Separator();

Expand Down
1 change: 0 additions & 1 deletion src/GUI/Widgets/Debug/DebugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ namespace GUI
}
ImGui::TreePop();
}
ImGui::TooltipGeneric("These files will not be checked during the next wave of addon loading.");
}
Loader::Mutex.unlock();

Expand Down
15 changes: 10 additions & 5 deletions src/GUI/Widgets/Log/LogWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace GUI
bool SelectedOnly = false;
std::string ChannelFilter;

float off1 = 0.0f;
float off2 = 0.0f;
const char* filterLevels[] = { "Critical", "Warning", "Info", "Debug", "Trace", "All" };
size_t amtShown = 0;

Expand All @@ -17,6 +19,12 @@ namespace GUI
{
if (!Visible) { return; }

if (!(off1 && off2))
{
off1 = ImGui::CalcTextSize("XXXXXXXXX").x;
off2 = ImGui::CalcTextSize("XXXXXXXXXXX").x;
}

ImGui::SetNextWindowSize(ImVec2(600.0f, 380.0f));
if (ImGui::Begin("Log", &Visible, WindowFlags_Default))
{
Expand Down Expand Up @@ -76,7 +84,7 @@ namespace GUI
{
ImGui::BeginChild("logmessages", ImVec2(windowWidthQuarter * 3 - 1, 0.0f));

MessageMutex.lock();
LogHandler::Mutex.lock();
{
/* Show last 400 log messages */
size_t start = 0;
Expand Down Expand Up @@ -104,9 +112,6 @@ namespace GUI
default: level = "[TRACE]"; ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(220, 220, 220, 255)); break;
}

float off1 = ImGui::CalcTextSize("XXXXXXXXX").x;
float off2 = ImGui::CalcTextSize("XXXXXXXXXXX").x;

/* time */
ImGui::Text(entry.TimestampString(false).c_str()); ImGui::SameLine(off1);

Expand All @@ -120,7 +125,7 @@ namespace GUI
}
}
}
MessageMutex.unlock();
LogHandler::Mutex.unlock();

if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
{
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Widgets/Options/OptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace GUI
{
GeneralTab();
AddonsTab();
StyleTab();
//StyleTab();
KeybindsTab();
APITab();
//APITab();

ImGui::EndTabBar();
}
Expand Down
59 changes: 2 additions & 57 deletions src/Keybinds/Keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@
#include "KeybindHandler.h"
#include "../core.h"

const char* ConvertToUTF8(const char* multibyteStr)
{
char* utf8Str = nullptr;

int wideCharCount = MultiByteToWideChar(CP_ACP, 0, multibyteStr, -1, NULL, 0);
if (wideCharCount > 0)
{
wchar_t* wideCharBuff = new wchar_t[wideCharCount];
MultiByteToWideChar(CP_ACP, 0, multibyteStr, -1, wideCharBuff, wideCharCount);

int utf8Count = WideCharToMultiByte(CP_UTF8, 0, wideCharBuff, -1, NULL, 0, NULL, NULL);
if (utf8Count > 0)
{
utf8Str = new char[utf8Count];
WideCharToMultiByte(CP_UTF8, 0, wideCharBuff, -1, utf8Str, utf8Count, NULL, NULL);
}

delete[] wideCharBuff;
}

return utf8Str;
}


std::string Keybind::ToString(bool padded)
{
if (!Key) { return "(null)"; }
Expand Down Expand Up @@ -60,53 +36,22 @@ std::string Keybind::ToString(bool padded)

if (vk >= 65 && vk <= 90 || vk >= 48 && vk <= 57)
{
//UINT keyExW = MapVirtualKeyExW(Key, MAPVK_VSC_TO_VK_EX, hkl);
//str.append(std::to_string(keyExW));
GetKeyNameTextA(Key << 16, buff, 100);
str.append(buff);
}
else
{
// TODO:
// this does not work for special utf8 characters
// basically ImGui::Text(u8"somestring") -> handles utf8 properly
// since this is a std::string, there is no prefixing, meaning it has to be converted somehow, no idea how
// characters like Ü or ß don't work. I give up
auto it = Keybinds::ScancodeLookupTable.find(Key);
if (it != Keybinds::ScancodeLookupTable.end())
{
str.append(it->second);
}

/*// get vkey from keycode based on the current keyboardlayout
UINT keyExW = MapVirtualKeyExW(Key, MAPVK_VSC_TO_VK_EX, hkl);
wchar_t shortCutRealNameWstr[32];
constexpr BYTE keyState[256]{};
// say windows to get the translation of the key (e.g. ä, ö, #)
int toUnicodeCount = ToUnicodeEx(keyExW, Key, keyState, shortCutRealNameWstr, 32, 1 << 2, hkl);
// some keys set two utf16 chars, i only care about the first one, so i set the second one to 0
if (toUnicodeCount == 2) {
shortCutRealNameWstr[2] = '\0';
}
int count = WideCharToMultiByte(CP_UTF8, 0, shortCutRealNameWstr, sizeof(shortCutRealNameWstr), NULL, 0, NULL, NULL);
std::string str2(count, 0);
WideCharToMultiByte(CP_UTF8, 0, shortCutRealNameWstr, -1, &str2[0], count, NULL, NULL);
std::transform(str2.begin(), str2.end(), str2.begin(), ::toupper);
str.append(std::to_string(toUnicodeCount));
if (toUnicodeCount == 0)
{
str.append("nt");
}
else if (toUnicodeCount < 0)
{
str.append("dk");
}
str.append(str2);*/
}

delete[] buff;

std::transform(str.begin(), str.end(), str.begin(), ::toupper);

// Convert Multibyte encoding to UFT-8 bytes
const char* multibyte_pointer = str.c_str();
const char* utf8_bytes = ConvertToUTF8(multibyte_pointer);
Expand Down
2 changes: 0 additions & 2 deletions src/Loader/AddonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ struct AddonAPI1 : AddonAPI

/* Logging */
LOGGER_LOGA Log;
LOGGER_ADDREM RegisterLogger;
LOGGER_ADDREM UnregisterLogger;

/* Events */
EVENTS_RAISE RaiseEvent;
Expand Down
19 changes: 18 additions & 1 deletion src/Loader/AddonDefinition.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#include "AddonDefinition.h"

bool operator>(AddonVersion lhs, AddonVersion rhs)
{
if ((lhs.Major > rhs.Major) ||
(lhs.Major == rhs.Major && lhs.Minor > rhs.Minor) ||
(lhs.Major == rhs.Major && lhs.Minor == rhs.Minor && lhs.Build > rhs.Build) ||
(lhs.Major == rhs.Major && lhs.Minor == rhs.Minor && lhs.Build == rhs.Build && lhs.Revision > rhs.Revision))
{
return true;
}

return false;
}
bool operator<(AddonVersion lhs, AddonVersion rhs)
{
return !(lhs > rhs);
}

bool AddonDefinition::HasMinimumRequirements()
{
if (Signature != 0 &&
Name &&
Author &&
Description &&
Load &&
Unload)
(HasFlag(EAddonFlags::DisableHotloading) || Unload))
{
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Loader/AddonDefinition.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef ADDONDEF_H
#define ADDONDEF_H

#include <iomanip>
#include <sstream>

#include "AddonAPI.h"
#include "EAddonFlags.h"
#include "EUpdateProvider.h"
Expand All @@ -26,6 +29,9 @@ struct AddonVersion
}
};

bool operator>(AddonVersion lhs, AddonVersion rhs);
bool operator<(AddonVersion lhs, AddonVersion rhs);

struct AddonDefinition
{
/* required */
Expand All @@ -36,7 +42,7 @@ struct AddonDefinition
const char* Author; /* Author of the addon */
const char* Description; /* Short description */
ADDON_LOAD Load; /* Pointer to Load Function of the addon */
ADDON_UNLOAD Unload; /* Pointer to Unload Function of the addon */
ADDON_UNLOAD Unload; /* Pointer to Unload Function of the addon. Not required if EAddonFlags::DisableHotloading is set. */
EAddonFlags Flags; /* Information about the addon */

/* update fallback */
Expand Down
10 changes: 0 additions & 10 deletions src/Loader/EAddonFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,4 @@ EAddonFlags operator&(EAddonFlags lhs, EAddonFlags rhs)
static_cast<int>(lhs) &
static_cast<int>(rhs)
);
}

bool operator==(EAddonFlags lhs, EAddonFlags rhs)
{
return static_cast<int>(lhs) == static_cast<int>(rhs);
}

bool operator!=(EAddonFlags lhs, EAddonFlags rhs)
{
return static_cast<int>(lhs) != static_cast<int>(rhs);
}
8 changes: 2 additions & 6 deletions src/Loader/EAddonFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
enum class EAddonFlags
{
None = 0,
IsVolatile = 1 /* is hooking functions or doing anything else that's volatile and game build dependant */
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. */
};

EAddonFlags operator|(EAddonFlags lhs, EAddonFlags rhs);

EAddonFlags operator&(EAddonFlags lhs, EAddonFlags rhs);

bool operator==(EAddonFlags lhs, EAddonFlags rhs);

bool operator!=(EAddonFlags lhs, EAddonFlags rhs);

#endif
46 changes: 30 additions & 16 deletions src/Loader/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,36 @@ namespace Loader
MODULEINFO moduleInfo;
GetModuleInformation(GetCurrentProcess(), hMod, &moduleInfo, sizeof(moduleInfo));

AddonAPI* api = GetAddonAPI(defs->APIVersion);
AddonAPI* api = GetAddonAPI(defs->APIVersion); // will be nullptr if doesn't exist or APIVersion = 0

// if no addon api was requested
// else if the requested addon api exists
// if no addon api was requested or if the requested addon api exists
// else invalid addon, don't load
if (defs->APIVersion == 0)
if (defs->APIVersion == 0 || api != nullptr)
{
LogInfo(CH_LOADER, "Loaded addon: %s [%p - %p] (No API was requested.)", path, hMod, ((PBYTE)hMod) + moduleInfo.SizeOfImage);
addon->Module = hMod;
addon->ModuleSize = moduleInfo.SizeOfImage;
addon->Definitions = defs;
addon->Definitions->Load(nullptr);
addon->State = EAddonState::Loaded;
}
else if (api != nullptr)
{
LogInfo(CH_LOADER, "Loaded addon: %s [%p - %p] (API Version %d was requested.)", path, hMod, ((PBYTE)hMod) + moduleInfo.SizeOfImage, defs->APIVersion);
addon->Module = hMod;
addon->ModuleSize = moduleInfo.SizeOfImage;

// free the old stuff
if (addon->Definitions != nullptr)
{
// is this necessary?
delete[] addon->Definitions->Name;
delete[] addon->Definitions->Author;
delete[] addon->Definitions->Description;
delete[] addon->Definitions->UpdateLink;
delete addon->Definitions;
}

addon->Definitions = defs;

if (defs->APIVersion == 0)
{
LogInfo(CH_LOADER, "Loaded addon: %s [%p - %p] (No API was requested.)", path, hMod, ((PBYTE)hMod) + moduleInfo.SizeOfImage);
}
else
{
LogInfo(CH_LOADER, "Loaded addon: %s [%p - %p] (API Version %d was requested.)", path, hMod, ((PBYTE)hMod) + moduleInfo.SizeOfImage, defs->APIVersion);
}
addon->Definitions->Load(api);
addon->State = EAddonState::Loaded;
}
Expand Down Expand Up @@ -230,6 +240,12 @@ namespace Loader
/* cache name for warning message and already release defs */
std::string name = Addons[aPath]->Definitions->Name;

if (!Addons[aPath]->Definitions->Unload ||
Addons[aPath]->Definitions->HasFlag(EAddonFlags::DisableHotloading))
{
LogWarning(CH_LOADER, "Prevented unloading \"%s\" because either no Unload function is defined or Hotloading is explicitly disabled. (%s)", name.c_str(), path);
return;
}
Addons[aPath]->Definitions->Unload();

if (Addons[aPath]->Module)
Expand Down Expand Up @@ -388,8 +404,6 @@ namespace Loader
((AddonAPI1*)api)->DisableHook = MH_DisableHook;

((AddonAPI1*)api)->Log = LogMessageAddon;
((AddonAPI1*)api)->RegisterLogger = RegisterLogger;
((AddonAPI1*)api)->UnregisterLogger = UnregisterLogger;

((AddonAPI1*)api)->RaiseEvent = Events::Raise;
((AddonAPI1*)api)->SubscribeEvent = Events::Subscribe;
Expand Down
Loading

0 comments on commit abadd0d

Please sign in to comment.