Skip to content

Commit

Permalink
Merge pull request #62 from PenguLoader/dev
Browse files Browse the repository at this point in the history
Bump v1.0.5
  • Loading branch information
nomi-san committed May 22, 2023
2 parents 4916bbe + a332ae0 commit 65592f5
Show file tree
Hide file tree
Showing 16 changed files with 424 additions and 130 deletions.
29 changes: 26 additions & 3 deletions core/src/browser/assets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,30 @@ class AssetsResourceHandler : public CefRefCount<cef_resource_handler_t>
}
};

cef_resource_handler_t *CreateAssetsResourceHandler(const wstring &path, bool plugin)
void RegisterAssetsSchemeHandlerFactory()
{
return new AssetsResourceHandler(path, plugin);
}
struct AssetsSchemeHandlerFactory : CefRefCount<cef_scheme_handler_factory_t>
{
AssetsSchemeHandlerFactory() : CefRefCount(this)
{
cef_scheme_handler_factory_t::create = create;
}

static cef_resource_handler_t* CEF_CALLBACK create(
struct _cef_scheme_handler_factory_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
const cef_string_t* scheme_name,
struct _cef_request_t* request)
{
CefScopedStr url{ request->get_url(request) };
bool is_assets = wcsncmp(url.str, L"https://assets/", 15) == 0;
auto path = url.str + (is_assets ? 14 : 15);

return new AssetsResourceHandler(path, !is_assets);
}
};

CefRegisterSchemeHandlerFactory(&"https"_s, &CefStr("assets"), new AssetsSchemeHandlerFactory());
CefRegisterSchemeHandlerFactory(&"https"_s, &CefStr("plugins"), new AssetsSchemeHandlerFactory());
}
114 changes: 59 additions & 55 deletions core/src/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void PrepareDevTools();
void OpenDevTools_Internal(bool remote);
void SetUpBrowserWindow(cef_browser_t *browser, cef_frame_t *frame);

cef_resource_handler_t *CreateAssetsResourceHandler(const wstring &path, bool isPlugins);
cef_resource_handler_t *CreateRiotClientResourceHandler(cef_frame_t *frame, wstring path);
void RegisterAssetsSchemeHandlerFactory();
void RegisterRiotClientSchemeHandlerFactory();
void SetRiotClientCredentials(const wstring &appPort, const wstring &authToken);

void OpenInternalServer();
Expand Down Expand Up @@ -111,52 +111,6 @@ static void HookClient(cef_client_t *client)
return handler;
};

// Hook RequestHandler.
static auto Old_GetRequestHandler = client->get_request_handler;
client->get_request_handler = [](struct _cef_client_t* self) -> cef_request_handler_t*
{
auto handler = Old_GetRequestHandler(self);

static auto Old_GetResourceRequestHandler = handler->get_resource_request_handler;
handler->get_resource_request_handler = [](
struct _cef_request_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
int is_navigation,
int is_download,
const cef_string_t* request_initiator,
int* disable_default_handling) -> cef_resource_request_handler_t*
{
auto handler = Old_GetResourceRequestHandler(self, browser, frame, request,
is_navigation, is_download, request_initiator, disable_default_handling);

static auto Old_GetResourceHandler = handler->get_resource_handler;
handler->get_resource_handler = [](
struct _cef_resource_request_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request) -> cef_resource_handler_t*
{
CefScopedStr url{ request->get_url(request) };
cef_resource_handler_t *handler = Old_GetResourceHandler(self, browser, frame, request);

if (wcsncmp(url.str, L"https://assets/", 15) == 0)
return CreateAssetsResourceHandler(url.str + 14, false);
if (wcsncmp(url.str, L"https://plugins/", 16) == 0)
return CreateAssetsResourceHandler(url.str + 15, true);
if (wcsncmp(url.str, L"https://riotclient/", 19) == 0)
return CreateRiotClientResourceHandler(frame, url.str + 18);

return handler;
};

return handler;
};

return handler;
};

static auto GetJSDialogHandler = client->get_jsdialog_handler;
client->get_jsdialog_handler = [](struct _cef_client_t* self)
{
Expand Down Expand Up @@ -208,7 +162,7 @@ static int Hooked_CefBrowserHost_CreateBrowser(
HookClient(client);
}

return Old_CefBrowserHost_CreateBrowser(windowInfo, client, url, settings, extra_info, request_context);
return Old_CefBrowserHost_CreateBrowser(windowInfo, client, url, settings, extra_info, nullptr);
}

static decltype(cef_app_t::on_before_command_line_processing) Old_OnBeforeCommandLineProcessing;
Expand All @@ -226,9 +180,11 @@ static void CEF_CALLBACK Hooked_OnBeforeCommandLineProcessing(

auto chromiumArgs = config::getConfigValue(L"ChromiumArgs");
if (!chromiumArgs.empty())
{
args += L" " + chromiumArgs;
}

if (config::getConfigValue(L"NoProxyServer") == L"0")
if (!config::getConfigValueBool(L"NoProxyServer", true))
{
size_t pos = args.find(L"--no-proxy-server");
if (pos != std::wstring::npos)
Expand All @@ -241,25 +197,55 @@ static void CEF_CALLBACK Hooked_OnBeforeCommandLineProcessing(

Old_OnBeforeCommandLineProcessing(self, process_type, command_line);

auto sPort = config::getConfigValue(L"RemoteDebuggingPort");
REMOTE_DEBUGGING_PORT = wcstol(sPort.c_str(), NULL, 10);
if (REMOTE_DEBUGGING_PORT != 0) {
if (REMOTE_DEBUGGING_PORT = config::getConfigValueInt(L"RemoteDebuggingPort", 0))
{
// Set remote debugging port.
command_line->append_switch_with_value(command_line,
&"remote-debugging-port"_s, &CefStr(std::to_string(REMOTE_DEBUGGING_PORT)));
}

if (config::getConfigValue(L"DisableWebSecurity") == L"1")
if (config::getConfigValueBool(L"DisableWebSecurity", false))
{
// Disable web security.
command_line->append_switch(command_line, &"disable-web-security"_s);
}

if (config::getConfigValue(L"IgnoreCertificateErrors") == L"1")
if (config::getConfigValueBool(L"IgnoreCertificateErrors", false))
{
// Ignore invalid certs.
command_line->append_switch(command_line, &"ignore-certificate-errors"_s);
}

if (config::getConfigValueBool(L"OptimizeClient", true))
{
// Optimize Client.
command_line->append_switch(command_line, &"disable-async-dns"_s);
command_line->append_switch(command_line, &"disable-plugins"_s);
command_line->append_switch(command_line, &"disable-extensions"_s);
command_line->append_switch(command_line, &"disable-background-networking"_s);
command_line->append_switch(command_line, &"disable-background-timer-throttling"_s);
command_line->append_switch(command_line, &"disable-backgrounding-occluded-windows"_s);
command_line->append_switch(command_line, &"disable-renderer-backgrounding"_s);
command_line->append_switch(command_line, &"disable-metrics"_s);
command_line->append_switch(command_line, &"disable-component-update"_s);
command_line->append_switch(command_line, &"disable-domain-reliability"_s);
command_line->append_switch(command_line, &"disable-translate"_s);
command_line->append_switch(command_line, &"disable-gpu-watchdog"_s);
command_line->append_switch(command_line, &"disable-renderer-accessibility"_s);
command_line->append_switch(command_line, &"enable-parallel-downloading"_s);
command_line->append_switch(command_line, &"enable-new-download-backend"_s);
command_line->append_switch(command_line, &"enable-quic"_s);
command_line->append_switch(command_line, &"no-pings"_s);
command_line->append_switch(command_line, &"no-sandbox"_s);
}

if (config::getConfigValueBool(L"SuperLowSpecMode", false))
{
// Super Low Spec Mode.
command_line->append_switch(command_line, &"disable-smooth-scrolling"_s);
command_line->append_switch(command_line, &"wm-window-animations-disabled"_s);
command_line->append_switch_with_value(command_line, &"animation-duration-scale"_s, &"0"_s);
}
}

static Hook<decltype(&cef_initialize)> Old_CefInitialize;
Expand All @@ -274,6 +260,24 @@ static int Hooked_CefInitialize(const struct _cef_main_args_t* args,
GetEnvironmentVariableW(L"LOCALAPPDATA", cachePath, _countof(cachePath));
lstrcatW(cachePath, L"\\Riot Games\\League of Legends\\Cache");
const_cast<cef_settings_t *>(settings)->cache_path = CefStr(cachePath).forawrd();
//const_cast<cef_settings_t *>(settings)->log_severity = LOGSEVERITY_DISABLE;

static auto GetBrowserProcessHandler = app->get_browser_process_handler;
app->get_browser_process_handler = [](cef_app_t *self)
{
auto handler = GetBrowserProcessHandler(self);

static auto OnContextIntialized = handler->on_context_initialized;
handler->on_context_initialized = [](cef_browser_process_handler_t *self)
{
RegisterAssetsSchemeHandlerFactory();
RegisterRiotClientSchemeHandlerFactory();

OnContextIntialized(self);
};

return handler;
};

return Old_CefInitialize(args, settings, app, windows_sandbox_info);
}
Expand Down
25 changes: 23 additions & 2 deletions core/src/browser/riotclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,30 @@ struct RiotClientResourceHandler : CefRefCount<cef_resource_handler_t>
static void CEF_CALLBACK _cancel(struct _cef_resource_handler_t* self) { }
};

cef_resource_handler_t *CreateRiotClientResourceHandler(cef_frame_t *frame, wstring path)
void RegisterRiotClientSchemeHandlerFactory()
{
return new RiotClientResourceHandler(frame, path);
struct RiotClientSchemeHandlerFactory : CefRefCount<cef_scheme_handler_factory_t>
{
RiotClientSchemeHandlerFactory() : CefRefCount(this)
{
cef_scheme_handler_factory_t::create = create;
}

static cef_resource_handler_t* CEF_CALLBACK create(
struct _cef_scheme_handler_factory_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
const cef_string_t* scheme_name,
struct _cef_request_t* request)
{
CefScopedStr url{ request->get_url(request) };
auto path = url.str + 18;

return new RiotClientResourceHandler(frame, path);
}
};

CefRegisterSchemeHandlerFactory(&"https"_s, &CefStr("riotclient"), new RiotClientSchemeHandlerFactory());
}

void SetRiotClientCredentials(const wstring &appPort, const wstring &authToken)
Expand Down
91 changes: 85 additions & 6 deletions core/src/config.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "internal.h"
#include <unordered_map>
#include <fstream>

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -45,13 +47,90 @@ wstring config::getPluginsDir()
return getLoaderDir() + L"\\plugins";
}

wstring config::getConfigValue(const wstring &key)
static auto getConfigMap()
{
auto path = getLoaderDir() + L"\\config";
static bool cached = false;
static std::unordered_map<wstring, wstring> map;

WCHAR value[1024]{};
DWORD length = GetPrivateProfileStringW(L"Main",
key.c_str(), L"", value, 1024, path.c_str());
if (!cached)
{
auto path = config::getLoaderDir() + L"\\config";
std::wifstream file(path);

if (file.is_open())
{
std::wstring line;
while (std::getline(file, line))
{
if (!line.empty() && line[0] != L';')
{
size_t pos = line.find(L"=");
if (pos != std::wstring::npos)
{
std::wstring key = line.substr(0, pos);
std::wstring value = line.substr(pos + 1);
map[key] = value;
}
}
}
file.close();
}

cached = true;
}

return map;
}

wstring config::getConfigValue(const wstring &key, const wstring &fallback)
{
auto map = getConfigMap();
auto it = map.find(key);
auto value = fallback;

if (it != map.end())
value = it->second;

#ifdef _DEBUG
wprintf(L"config: %s -> %s\n", key.c_str(), value.c_str());
#endif

return value;
}

bool config::getConfigValueBool(const wstring &key, bool fallback)
{
auto map = getConfigMap();
auto it = map.find(key);
auto value = fallback;

if (it != map.end())
{
if (it->second == L"0" || it->second == L"false")
value = false;
else if (it->second == L"1" || it->second == L"true")
value = true;
}

#ifdef _DEBUG
wprintf(L"config: %s -> %s\n", key.c_str(), value ? L"true" : L"false");
#endif

return value;
}

int config::getConfigValueInt(const wstring &key, int fallback)
{
auto map = getConfigMap();
auto it = map.find(key);
auto value = fallback;

if (it != map.end())
value = std::stoi(it->second);

#ifdef _DEBUG
wprintf(L"config: %s -> %d\n", key.c_str(), value);
#endif

return wstring(value, length);
return value;
}
6 changes: 5 additions & 1 deletion core/src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ extern decltype(&cef_process_message_create) CefProcessMessage_Create;
extern decltype(&cef_v8context_get_current_context) CefV8Context_GetCurrentContext;
extern decltype(&cef_server_create) CefServer_Create;
extern decltype(&cef_uridecode) CefURIDecode;
extern decltype(&cef_register_scheme_handler_factory) CefRegisterSchemeHandlerFactory;

// Strings helpers.
extern decltype(&cef_string_set) CefString_Set;
Expand Down Expand Up @@ -166,7 +167,10 @@ namespace config
wstring getLoaderDir();
wstring getAssetsDir();
wstring getPluginsDir();
wstring getConfigValue(const wstring &key);

wstring getConfigValue(const wstring &key, const wstring &fallback = L"");
bool getConfigValueBool(const wstring &key, bool fallback);
int getConfigValueInt(const wstring &key, int fallback);
}

namespace utils
Expand Down
2 changes: 2 additions & 0 deletions core/src/libcef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ decltype(&cef_process_message_create) CefProcessMessage_Create;
decltype(&cef_v8context_get_current_context) CefV8Context_GetCurrentContext;
decltype(&cef_server_create) CefServer_Create;
decltype(&cef_uridecode) CefURIDecode;
decltype(&cef_register_scheme_handler_factory) CefRegisterSchemeHandlerFactory;

decltype(&cef_string_set) CefString_Set;
decltype(&cef_string_clear) CefString_Clear;
Expand Down Expand Up @@ -110,6 +111,7 @@ bool LoadLibcefDll(bool is_browser)
(LPVOID &)CefV8Context_GetCurrentContext = GetProcAddress(libcef, "cef_v8context_get_current_context");
(LPVOID &)CefServer_Create = GetProcAddress(libcef, "cef_server_create");
(LPVOID &)CefURIDecode = GetProcAddress(libcef, "cef_uridecode");
(LPVOID &)CefRegisterSchemeHandlerFactory = GetProcAddress(libcef, "cef_register_scheme_handler_factory");

(LPVOID &)CefString_Set = GetProcAddress(libcef, "cef_string_utf16_set");
(LPVOID &)CefString_Clear = GetProcAddress(libcef, "cef_string_utf16_clear");
Expand Down
Loading

0 comments on commit 65592f5

Please sign in to comment.