From ae15cba56ca971d2ecbd25b6fb57b87935bcdffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Jan 2025 23:31:20 +0100 Subject: [PATCH] Move the logic for loading the json file to the function. Minor cleanup. --- Core/HLE/sceNet.cpp | 27 ++++++++++++++++----------- UI/PauseScreen.cpp | 5 +++-- assets/infra-dns.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 889fbc9513..51d9b9b2aa 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -134,13 +134,23 @@ void AfterApctlMipsCall::SetData(int HandlerID, int OldState, int NewState, int argsAddr = ArgsAddr; } -bool LoadDNSForGameID(std::string_view jsonStr, std::string_view gameID, InfraDNSConfig *dns) { +bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) { using namespace json; - json::JsonReader reader(jsonStr.data(), jsonStr.length()); - if (!reader.ok() || !reader.root()) { - ERROR_LOG(Log::IO, "Error parsing JSON from store"); + + // TODO: Load from cache instead of zip (if possible), and sometimes update it. + size_t jsonSize; + std::unique_ptr data(g_VFS.ReadFile("infra-dns.json", &jsonSize)); + if (!data) { return false; } + + std::string_view jsonStr = std::string_view((const char *)data.get(), jsonSize); + json::JsonReader reader(jsonStr.data(), jsonStr.length()); + if (!reader.ok() || !reader.root()) { + ERROR_LOG(Log::IO, "Error parsing DNS JSON"); + return false; + } + const JsonGet root = reader.root(); const JsonGet def = root.getDict("default"); @@ -210,7 +220,6 @@ bool LoadDNSForGameID(std::string_view jsonStr, std::string_view gameID, InfraDN } // TODO: Check for not working platforms - break; } @@ -637,6 +646,7 @@ u32 Net_Term() { FreeUser(netThread2Addr); netInited = false; + g_infraDNSConfig = {}; return 0; } @@ -704,12 +714,7 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini if (g_Config.bInfrastructureAutoDNS) { // Load the automatic DNS config. std::string discID = g_paramSFO.GetDiscID(); - size_t jsonSize; - uint8_t *data = g_VFS.ReadFile("infra-dns.json", &jsonSize); - if (data && g_Config.bInfrastructureAutoDNS) { - std::string_view json = std::string_view((const char *)data, jsonSize); - LoadDNSForGameID(json, discID, &g_infraDNSConfig); - } + LoadDNSForGameID(discID, &g_infraDNSConfig); } netInited = true; diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 55dc6ecbb7..56128b2d58 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -42,6 +42,7 @@ #include "Core/ELF/ParamSFO.h" #include "Core/HLE/sceDisplay.h" #include "Core/HLE/sceUmd.h" +#include "Core/HLE/sceNet.h" #include "GPU/GPUCommon.h" #include "GPU/GPUState.h" @@ -415,8 +416,8 @@ void GamePauseScreen::CreateViews() { rightColumnItems->Add(new Choice(pa->T("Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings); rightColumnItems->Add(new Choice(pa->T("Create Game Config")))->OnClick.Handle(this, &GamePauseScreen::OnCreateConfig); } - UI::Choice *displayEditor_ = rightColumnItems->Add(new Choice(gr->T("Display layout & effects"))); - displayEditor_->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn { + + rightColumnItems->Add(new Choice(gr->T("Display layout & effects")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn { screenManager()->push(new DisplayLayoutScreen(gamePath_)); return UI::EVENT_DONE; }); diff --git a/assets/infra-dns.json b/assets/infra-dns.json index 2933f461ae..dbf3176c72 100644 --- a/assets/infra-dns.json +++ b/assets/infra-dns.json @@ -1,5 +1,5 @@ { - "comment": "This file contains our built-in DNS used by the Auto mode in Infrastructure. In addition to being shipped, it'll also be hosted on ppsspp.org. Key names below are not important.", + "comment": "This file contains our built-in DNS used by the Auto mode in Infrastructure. In addition to being shipped, it'll also be hosted on ppsspp.org. Game names below are not important.", "default": { "dns": "67.222.156.251", "revival_credits": {