Skip to content

Commit

Permalink
feature: checking for latest ue4ss version
Browse files Browse the repository at this point in the history
if not latest ue4ss version from github, add to crash dumper messagebox

add setting for check

chore: changelog
  • Loading branch information
Buckminsterfullerene02 committed Dec 7, 2024
1 parent 16ad32e commit c29b584
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 2 deletions.
1 change: 1 addition & 0 deletions UE4SS/include/SettingsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace RC
bool EnableDebugKeyBindings{false};
int64_t SecondsToScanBeforeGivingUp{30};
bool UseUObjectArrayCache{true};
bool LatestVersionCheck{true};
} General;

struct SectionEngineVersionOverride
Expand Down
3 changes: 3 additions & 0 deletions UE4SS/include/UE4SSProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ namespace RC
RC_UE4SS_API auto generate_uht_compatible_headers() -> void;
RC_UE4SS_API auto generate_cxx_headers(const std::filesystem::path& output_dir) -> void;
RC_UE4SS_API auto generate_lua_types(const std::filesystem::path& output_dir) -> void;
RC_UE4SS_API auto get_latest_version_check_setting() -> bool;
RC_UE4SS_API auto get_latest_ue4ss_version() -> StringType;
RC_UE4SS_API auto is_latest_ue4ss_version(StringType latest_ver) -> bool;
auto get_debugging_ui() -> GUI::DebuggingGUI&
{
return m_debugging_gui;
Expand Down
14 changes: 12 additions & 2 deletions UE4SS/src/CrashDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ namespace RC
return EXCEPTION_CONTINUE_SEARCH;
}

const StringType message = fmt::format(STR("Crashdump written to: {}"), dump_path);
MessageBoxW(NULL, FromCharTypePtr<wchar_t>(message.c_str()), L"Fatal Error!", MB_OK);
StringType version_message = L"";
if (UE4SSProgram::get_program().get_latest_version_check_setting())
{
StringType latest_version = UE4SSProgram::get_program().get_latest_ue4ss_version();
if (!UE4SSProgram::get_program().is_latest_ue4ss_version(latest_version))
{
version_message = fmt::format(L"\n\nA newer version ({}) is available. Updating may solve your issue.", latest_version);
}
}

const StringType message = fmt::format(L"Crashdump written to: {}{}", dump_path, version_message);
MessageBoxW(NULL, message.c_str(), L"Fatal Error!", MB_OK);

return EXCEPTION_EXECUTE_HANDLER;
}
Expand Down
1 change: 1 addition & 0 deletions UE4SS/src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace RC
REGISTER_BOOL_SETTING(General.EnableDebugKeyBindings, section_general, EnableDebugKeyBindings)
REGISTER_INT64_SETTING(General.SecondsToScanBeforeGivingUp, section_general, SecondsToScanBeforeGivingUp)
REGISTER_BOOL_SETTING(General.UseUObjectArrayCache, section_general, bUseUObjectArrayCache)
REGISTER_BOOL_SETTING(General.LatestVersionCheck, section_general, bLatestVersionCheck)

constexpr static File::CharType section_engine_version_override[] = STR("EngineVersionOverride");
REGISTER_INT64_SETTING(EngineVersionOverride.MajorVersion, section_engine_version_override, MajorVersion)
Expand Down
123 changes: 123 additions & 0 deletions UE4SS/src/UE4SSProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include <UnrealDef.hpp>

#include <polyhook2/PE/IatHook.hpp>
#include <curl/curl.h>
#include <glaze/glaze.hpp>

namespace RC
{
Expand Down Expand Up @@ -1461,6 +1463,127 @@ namespace RC
Output::send(STR("SDK generated in {} seconds.\n"), generator_duration);
}

auto UE4SSProgram::get_latest_version_check_setting() -> bool
{
return settings_manager.General.LatestVersionCheck;
}

static auto write_callback(void* contents, size_t size, size_t nmemb, void* userp) -> size_t
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}

auto UE4SSProgram::get_latest_ue4ss_version() -> StringType
{
CURL* curl;
CURLcode response;
std::string finalUrl;
std::string tag;

curl = curl_easy_init();
if (curl)
{
// This is a redirect hack to avoid having to use github api,
// which would require a user agent such as a github app to be made in UE4SS org,
// and is not a good idea to use in a public project
// CI version: curl -L -s -o /dev/null -w "%{url_effective}" "https://github.com/UE4SS-RE/RE-UE4SS/releases/latest"
curl_easy_setopt(curl, CURLOPT_URL, "https://github.com/UE4SS-RE/RE-UE4SS/releases/latest");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &finalUrl);

response = curl_easy_perform(curl);

if (response != CURLE_OK)
{
curl_easy_cleanup(curl);
return L"";
}
else
{
char* effectiveUrl = nullptr;
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
if (effectiveUrl)
{
finalUrl = std::string(effectiveUrl);
}

std::size_t lastSlashPos = finalUrl.find_last_of('/');
if (lastSlashPos != std::string::npos)
{
tag = finalUrl.substr(lastSlashPos + 1);
}
}

curl_easy_cleanup(curl);
}

if (tag.empty())
{
return L"";
}

return to_generic_string(tag);
}

static auto split_version(const std::string& version) -> std::vector<int>
{
std::vector<int> parts;
std::stringstream ss(version);
std::string item;

while (std::getline(ss, item, '.'))
{
parts.push_back(std::stoi(item));
}

return parts;
}

auto UE4SSProgram::is_latest_ue4ss_version(StringType latest_ver) -> bool
{
std::string current_version = fmt::format("{}.{}.{}", UE4SS_LIB_VERSION_MAJOR, UE4SS_LIB_VERSION_MINOR, UE4SS_LIB_VERSION_HOTFIX);
std::string latest_version = to_string(latest_ver);
if (latest_version.empty())
{
// If we can't get the latest version (due to no internet connection or otherwise), assume it is
return true;
}
if (latest_version[0] == 'v')
{
latest_version = latest_version.substr(1);
}

std::vector<int> current = split_version(current_version);
std::vector<int> latest = split_version(latest_version);

while (current.size() < latest.size())
{
current.push_back(0);
}

while (latest.size() < current.size())
{
latest.push_back(0);
}

for (size_t i = 0; i < current.size(); ++i)
{
if (latest[i] > current[i])
{
return false;
}
else if (latest[i] < current[i])
{
return true;
}
}

// If both equal
return true;
}

auto UE4SSProgram::stop_render_thread() -> void
{
if (m_render_thread.joinable())
Expand Down
3 changes: 3 additions & 0 deletions UE4SS/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_requires("glfw 3.3.9", { debug = is_mode_debug() , configs = {runtimes = get
add_requires("opengl", { debug = is_mode_debug(), configs = {runtimes = get_mode_runtimes()} })
add_requires("glaze v2.9.5", { debug = is_mode_debug(), configs = {runtimes = get_mode_runtimes()} })
add_requires("fmt 10.2.1", { debug = is_mode_debug(), configs = {runtimes = get_mode_runtimes()} })
add_requires("libcurl 8.7.1", { debug = is_mode_debug(), configs = {runtimes = get_mode_runtimes()} })

option("ue4ssBetaIsStarted")
set_default(true)
Expand Down Expand Up @@ -75,6 +76,8 @@ target(projectName)

add_packages("fmt", { public = true })

add_packages("libcurl", { public = true })

add_packages("imgui", "ImGuiTextEdit", "IconFontCppHeaders", "glfw", "opengl", { public = true })

add_packages("glaze", "polyhook_2", { public = true })
Expand Down
5 changes: 5 additions & 0 deletions assets/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Added new installation method by allowing overriding of the location of the `UE4

Add Github alerts pre-processor support to the documentation system ([UE4SS #611](https://github.com/UE4SS-RE/RE-UE4SS/pull/611)) - Buckminsterfullerene

Add opt-out checking for the latest version of UE4SS during load or when a crash dump is created. ([UE4SS #617](https://github.com/UE4SS-RE/RE-UE4SS/pull/617)) - Buckminsterfullerene

### Live View
Added search filter: `IncludeClassNames`. ([UE4SS #472](https://github.com/UE4SS-RE/RE-UE4SS/pull/472)) - Buckminsterfullerene

Expand Down Expand Up @@ -180,6 +182,9 @@ Fixes mods not loading when UE4SS initializes too late ([UE4SS #454](https://git
; Default: false
DebugBuild =

[General]
bLatestVersionCheck = 1

[Hooks]
HookLoadMap = 1
HookAActorTick = 1
Expand Down
5 changes: 5 additions & 0 deletions assets/UE4SS-settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ SecondsToScanBeforeGivingUp = 30
; Default: true
bUseUObjectArrayCache = true

; Whether to check if the user is running the latest stable version of UE4SS
; If enabled, and user is not running latest stable version, a warning will be displayed in console and crash popup box
; Default: 1
bLatestVersionCheck = 1

[EngineVersionOverride]
MajorVersion =
MinorVersion =
Expand Down

0 comments on commit c29b584

Please sign in to comment.