Skip to content

Commit 8c8686d

Browse files
committed
Use a more complicated PCGW query for non-Epic/non-GOG games to avoid HTTP 500.
1 parent 6cde45e commit 8c8686d

3 files changed

Lines changed: 95 additions & 18 deletions

File tree

CHANGELOG.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
26.4.30.2
1+
26.4.31
2+
=======
3+
+ Remove SK version number from HTTPS user agent string for all non-PCGW requests, because
4+
various existing services do not expect that additional info in the string.
5+
+ Use gamesdb.gog.com instead of PCGW to resolve Steam AppIDs for Epic games.
6+
+ Use a more complicated PCGW query for non-Epic/non-GOG games to avoid HTTP 500.
7+
8+
26.4.30.2
29
=========
310
+ Added support for NVIDIA's undocumented NvAPI_DRS_SetSettingEx and
411
NvAPI_DRS_GetSettingEx functions.

include/SpecialK/DLL_VERSION.H

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#define SK_YEAR 26
44
#define SK_MONTH 4
5-
#define SK_DATE 30
6-
#define SK_REV_N 2
7-
#define SK_REV 2
5+
#define SK_DATE 31
6+
#define SK_REV_N 0
7+
#define SK_REV 0
88

99
#ifndef _A2
1010
#define _A2(a) #a

src/core.cpp

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <imgui/font_awesome.h>
5555

5656
#include <filesystem>
57+
#include <json/json.hpp>
5758

5859

5960
#ifdef _WIN64
@@ -3732,40 +3733,109 @@ SK_FrameCallback ( SK_RenderBackend& rb,
37323733

37333734
if (config.platform.equivalent_steam_app == -1)
37343735
{
3735-
SK_RunOnce (
3736-
auto appname =
3737-
SK_GetFriendlyAppName ();
3736+
auto appname =
3737+
SK_GetFriendlyAppName ();
37383738

3739+
// Holy crap this is a mess; would use gamesdb.gog.com, but it is unclear how it
3740+
// generates "xboxone" (Microsoft Store) ids.
3741+
if (! appname.empty ())
3742+
SK_RunOnce (
37393743
std::wstring search_string =
37403744
SK_Network_MakeEscapeSequencedURL (SK_Platform_RemoveTrademarkSymbols (SK_UTF8ToWideChar (appname)));
37413745

3742-
std::wstring url =
3746+
std::wstring url0 =
37433747
SK_FormatStringW (
3744-
LR"(https://www.pcgamingwiki.com/w/index.php?search=%ws)", search_string.c_str ()
3748+
LR"(https://www.pcgamingwiki.com/w/api.php?action=opensearch&format=json&redirects=resolve&search=%ws)", search_string.c_str ()
37453749
);
37463750

37473751
if (! search_string.empty ())
37483752
SK_Network_EnqueueDownload (
3749-
sk_download_request_s (L"pcgw_entry.html", url.data (),
3753+
sk_download_request_s (L"api.php", url0.data (),
37503754
[]( const std::vector <uint8_t>&& data,
3751-
const std::wstring_view file )
3755+
const std::wstring_view )
37523756
{
37533757
if (data.empty ())
37543758
return true;
37553759

3756-
std::ignore = file;
3760+
static SK_LazyGlobal <nlohmann::json> json;
37573761

3758-
auto steamdb_appid =
3759-
StrStrIA ((const char *)data.data (), "https://steamdb.info/app/");
3762+
static std::wstring redirected_url = L"";
37603763

3761-
if (steamdb_appid != nullptr)
3762-
{
3763-
if (1 != sscanf (steamdb_appid, "https://steamdb.info/app/%d/", &config.platform.equivalent_steam_app))
3764+
try {
3765+
json.get () = std::move
3766+
( nlohmann::json::parse
3767+
( data.cbegin (),
3768+
data.cend (),
3769+
nullptr,
3770+
true ) );
3771+
3772+
for (const auto& text : json.get ())
37643773
{
3765-
config.platform.equivalent_steam_app = 0;
3774+
if (text.is_array ())
3775+
{
3776+
for (const auto& entry : text)
3777+
{
3778+
if (entry.is_string ())
3779+
{
3780+
redirected_url =
3781+
SK_FormatStringW (
3782+
LR"(https://www.pcgamingwiki.com/w/api.php?action=parse&format=xml&redirects=1&prop=wikitext&page=%hs)",
3783+
entry.get <std::string> ().c_str ()
3784+
);
3785+
3786+
break;
3787+
}
3788+
}
3789+
3790+
break;
3791+
}
37663792
}
37673793
}
37683794

3795+
catch (const std::exception& e)
3796+
{
3797+
SK_LOGi0 (L"JSON Parse Failure: %hs", e.what ());
3798+
}
3799+
3800+
if (! redirected_url.empty ())
3801+
{
3802+
SK_Network_EnqueueDownload (
3803+
sk_download_request_s (L"api.php", redirected_url.data (),
3804+
[]( const std::vector <uint8_t>&& data,
3805+
const std::wstring_view )
3806+
{
3807+
if (data.empty ())
3808+
return true;
3809+
3810+
std::string data_str (
3811+
data.begin (), data.end () );
3812+
3813+
SK_LOGi1 (L"PCGW Query Response for URL %ws: %hs", redirected_url.c_str (),
3814+
data_str.c_str ());
3815+
3816+
auto steam_appid =
3817+
StrStrIA (data_str.c_str (), "|steam appid ");
3818+
3819+
steam_appid = steam_appid == nullptr ?
3820+
nullptr :
3821+
StrStrIA (steam_appid, "= ");
3822+
3823+
if (steam_appid != nullptr)
3824+
{
3825+
if (1 != sscanf (steam_appid + 1, "%d", &config.platform.equivalent_steam_app))
3826+
{
3827+
config.platform.equivalent_steam_app = 0;
3828+
}
3829+
}
3830+
3831+
config.utility.save_async ();
3832+
3833+
return true;
3834+
} ),
3835+
false
3836+
);
3837+
}
3838+
37693839
return true;
37703840
} ),
37713841
false

0 commit comments

Comments
 (0)