From d73e035dc4d3119398cd2a392d1da87ea3026dc3 Mon Sep 17 00:00:00 2001 From: rjindael Date: Fri, 8 Sep 2023 21:17:05 -0700 Subject: [PATCH] feat: handle kiseki.loc/asset redirects --- Kiseki.Patcher/Header/Helpers.hpp | 1 + Kiseki.Patcher/Source/Helpers.cpp | 45 ++++++++++++++++++++++++++++ Kiseki.Patcher/Source/Hooks/Http.cpp | 12 +++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Kiseki.Patcher/Header/Helpers.hpp b/Kiseki.Patcher/Header/Helpers.hpp index 1563a78..ddee178 100644 --- a/Kiseki.Patcher/Header/Helpers.hpp +++ b/Kiseki.Patcher/Header/Helpers.hpp @@ -29,5 +29,6 @@ public: static std::string getModulePath(); static std::string getISOTimestamp(); static std::pair> parseURL(const std::string url); + static std::string getRedirectURL(const std::string url); static std::pair httpGet(const std::string url); }; \ No newline at end of file diff --git a/Kiseki.Patcher/Source/Helpers.cpp b/Kiseki.Patcher/Source/Helpers.cpp index 116e410..637dfb0 100644 --- a/Kiseki.Patcher/Source/Helpers.cpp +++ b/Kiseki.Patcher/Source/Helpers.cpp @@ -138,6 +138,51 @@ std::string Helpers::getISOTimestamp() return std::string(buffer); } +std::string Helpers::getRedirectURL(const std::string url) +{ + CURL* curl = curl_easy_init(); + CURLcode result; + + if (!curl) + { + return url; + } + + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0); + curl_easy_setopt(curl, CURLOPT_NOBODY, 1); + curl_easy_setopt(curl, CURLOPT_HEADER, 1); + + result = curl_easy_perform(curl); + + if (result != CURLE_OK) + { + return url; + } + + long response = 0; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); + + if (response != 301 && response != 302) + { + return url; + } + + char* redirectURL; + curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectURL); + + std::string location = redirectURL ? std::string(redirectURL) : ""; + + curl_easy_cleanup(curl); + + if (location.empty()) + { + return url; + } + + return location; +} + std::pair> Helpers::parseURL(const std::string url) { CURLU* curl = curl_url(); diff --git a/Kiseki.Patcher/Source/Hooks/Http.cpp b/Kiseki.Patcher/Source/Hooks/Http.cpp index 244882f..dda340d 100644 --- a/Kiseki.Patcher/Source/Hooks/Http.cpp +++ b/Kiseki.Patcher/Source/Hooks/Http.cpp @@ -23,11 +23,21 @@ void __fastcall Http__httpGetPostWinInet_hook(Http* _this, void*, bool isPost, i { url["path"] = Helpers::toLower(url["path"]); - if (url["host"] == "roblox.com" || url["host"] == "www.roblox.com") + // TODO: This is a weird hack. + if (url["host"] == "kiseki.lol" || url["host"] == "www.kiseki.lol" || url["host"] == "kiseki.loc" || url["host"] == "www.kiseki.loc") + { + if (url["path"] == "/asset" || url["path"] == "/asset/") + { + std::string location = Helpers::getRedirectURL(url["scheme"] + "://" + url["host"] + "/asset?" + url["query"]); + _this = &_changed; + } + } + else if (url["host"] == "roblox.com" || url["host"] == "www.roblox.com") { if (url["path"] == "/game/tools/insertasset.ashx") { _changed.url = "https://sets.pizzaboxer.xyz/" + url["path"] + "?" + url["query"]; + _this = &_changed; } else if (url["path"] == "/asset" || url["path"] == "/asset/" || url["path"] == "/asset/default.ashx") {