2013-03-01 16:58:05 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2021-03-03 04:57:25 +00:00
|
|
|
#include "ppsspp_config.h"
|
2019-09-28 17:45:45 +00:00
|
|
|
#include <deque>
|
2017-02-27 19:51:36 +00:00
|
|
|
#include <thread>
|
2017-12-20 09:22:15 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
2020-09-29 10:19:22 +00:00
|
|
|
#include <set>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdarg>
|
2017-02-27 19:51:36 +00:00
|
|
|
|
2013-03-24 17:18:22 +00:00
|
|
|
#include "Core/Reporting.h"
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/File/VFS/VFS.h"
|
2013-04-29 01:56:09 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2020-08-10 07:12:51 +00:00
|
|
|
#include "Common/Serialize/SerializeFuncs.h"
|
2020-09-29 10:19:22 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2016-07-25 00:31:41 +00:00
|
|
|
#include "Core/Core.h"
|
2013-05-20 03:20:41 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2013-03-01 16:58:05 +00:00
|
|
|
#include "Core/Config.h"
|
2014-02-15 23:28:13 +00:00
|
|
|
#include "Core/CwCheat.h"
|
2016-06-27 07:01:09 +00:00
|
|
|
#include "Core/Loaders.h"
|
2014-02-09 21:45:51 +00:00
|
|
|
#include "Core/SaveState.h"
|
2013-03-01 16:58:05 +00:00
|
|
|
#include "Core/System.h"
|
2016-06-27 07:01:09 +00:00
|
|
|
#include "Core/FileSystems/BlockDevices.h"
|
2014-02-09 22:13:46 +00:00
|
|
|
#include "Core/FileSystems/MetaFileSystem.h"
|
2020-08-26 02:54:51 +00:00
|
|
|
#include "Core/HLE/Plugins.h"
|
2013-05-20 03:20:41 +00:00
|
|
|
#include "Core/HLE/sceDisplay.h"
|
|
|
|
#include "Core/HLE/sceKernelMemory.h"
|
2013-12-29 23:11:29 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2013-04-29 00:49:17 +00:00
|
|
|
#include "GPU/GPUInterface.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/Net/HTTPClient.h"
|
|
|
|
#include "Common/Net/Resolve.h"
|
|
|
|
#include "Common/Net/URL.h"
|
2020-10-01 07:27:25 +00:00
|
|
|
#include "Common/Thread/ThreadUtil.h"
|
2013-03-01 16:58:05 +00:00
|
|
|
|
|
|
|
namespace Reporting
|
|
|
|
{
|
|
|
|
const int DEFAULT_PORT = 80;
|
2013-03-02 07:11:34 +00:00
|
|
|
const u32 SPAM_LIMIT = 100;
|
2016-06-12 14:30:36 +00:00
|
|
|
const int PAYLOAD_BUFFER_SIZE = 200;
|
2013-03-01 20:56:51 +00:00
|
|
|
|
|
|
|
// Internal limiter on number of requests per instance.
|
|
|
|
static u32 spamProtectionCount = 0;
|
|
|
|
// Temporarily stores a reference to the hostname.
|
|
|
|
static std::string lastHostname;
|
2020-10-10 13:09:32 +00:00
|
|
|
|
2014-02-09 22:04:16 +00:00
|
|
|
// Keeps track of whether a harmful setting was ever used.
|
|
|
|
static bool everUnsupported = false;
|
2014-02-16 04:34:03 +00:00
|
|
|
// Support is cached here to avoid checking it on every single request.
|
|
|
|
static bool currentSupported = false;
|
2016-06-28 05:59:09 +00:00
|
|
|
// Whether the most recent server request seemed successful.
|
|
|
|
static bool serverWorking = true;
|
2018-06-03 21:47:49 +00:00
|
|
|
// The latest compatibility result from the server.
|
|
|
|
static std::vector<std::string> lastCompatResult;
|
2013-03-01 16:58:05 +00:00
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
static std::mutex pendingMessageLock;
|
|
|
|
static std::condition_variable pendingMessageCond;
|
|
|
|
static std::deque<int> pendingMessages;
|
|
|
|
static bool pendingMessagesDone = false;
|
|
|
|
static std::thread messageThread;
|
|
|
|
static std::thread compatThread;
|
|
|
|
|
2016-06-12 14:30:36 +00:00
|
|
|
enum class RequestType
|
2013-03-02 06:34:02 +00:00
|
|
|
{
|
2016-06-12 14:30:36 +00:00
|
|
|
NONE,
|
2013-03-02 06:34:02 +00:00
|
|
|
MESSAGE,
|
2014-09-27 22:37:53 +00:00
|
|
|
COMPAT,
|
2013-03-02 06:34:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Payload
|
|
|
|
{
|
|
|
|
RequestType type;
|
2013-03-04 07:36:24 +00:00
|
|
|
std::string string1;
|
|
|
|
std::string string2;
|
2014-09-27 22:37:53 +00:00
|
|
|
int int1;
|
|
|
|
int int2;
|
|
|
|
int int3;
|
2013-03-02 06:34:02 +00:00
|
|
|
};
|
2016-06-12 19:07:21 +00:00
|
|
|
static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE];
|
2013-03-02 06:34:02 +00:00
|
|
|
static int payloadBufferPos = 0;
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
static std::mutex crcLock;
|
|
|
|
static std::condition_variable crcCond;
|
2021-05-09 16:38:48 +00:00
|
|
|
static Path crcFilename;
|
|
|
|
static std::map<Path, u32> crcResults;
|
2021-02-17 03:32:46 +00:00
|
|
|
static volatile bool crcPending = false;
|
2021-02-17 03:37:48 +00:00
|
|
|
static volatile bool crcCancel = false;
|
2019-09-28 17:45:45 +00:00
|
|
|
static std::thread crcThread;
|
2016-06-27 07:01:09 +00:00
|
|
|
|
|
|
|
static int CalculateCRCThread() {
|
2020-11-30 23:46:26 +00:00
|
|
|
SetCurrentThreadName("ReportCRC");
|
2016-06-27 07:01:09 +00:00
|
|
|
|
|
|
|
// TODO: Use the blockDevice from pspFileSystem?
|
|
|
|
FileLoader *fileLoader = ConstructFileLoader(crcFilename);
|
|
|
|
BlockDevice *blockDevice = constructBlockDevice(fileLoader);
|
|
|
|
|
|
|
|
u32 crc = 0;
|
|
|
|
if (blockDevice) {
|
2021-02-17 03:37:48 +00:00
|
|
|
crc = blockDevice->CalculateCRC(&crcCancel);
|
2016-06-27 07:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete blockDevice;
|
|
|
|
delete fileLoader;
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(crcLock);
|
2016-06-27 07:01:09 +00:00
|
|
|
crcResults[crcFilename] = crc;
|
2021-02-17 03:32:46 +00:00
|
|
|
crcPending = false;
|
2016-06-27 07:01:09 +00:00
|
|
|
crcCond.notify_one();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
void QueueCRC(const Path &gamePath) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(crcLock);
|
2016-06-27 07:01:09 +00:00
|
|
|
|
|
|
|
auto it = crcResults.find(gamePath);
|
|
|
|
if (it != crcResults.end()) {
|
|
|
|
// Nothing to do, we've already calculated it.
|
|
|
|
// Note: we assume it stays static until the app is closed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-17 03:32:46 +00:00
|
|
|
if (crcPending) {
|
2016-06-27 07:01:09 +00:00
|
|
|
// Already in process.
|
2021-08-21 18:58:25 +00:00
|
|
|
INFO_LOG(SYSTEM, "CRC already pending");
|
2016-06-27 07:01:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-21 18:58:25 +00:00
|
|
|
INFO_LOG(SYSTEM, "Starting CRC calculation");
|
2016-06-27 07:01:09 +00:00
|
|
|
crcFilename = gamePath;
|
2021-02-17 03:32:46 +00:00
|
|
|
crcPending = true;
|
2021-02-17 03:37:48 +00:00
|
|
|
crcCancel = false;
|
2019-09-28 17:45:45 +00:00
|
|
|
crcThread = std::thread(CalculateCRCThread);
|
2016-06-27 07:01:09 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
bool HasCRC(const Path &gamePath) {
|
2021-01-25 03:53:47 +00:00
|
|
|
std::lock_guard<std::mutex> guard(crcLock);
|
|
|
|
return crcResults.find(gamePath) != crcResults.end();
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
uint32_t RetrieveCRC(const Path &gamePath) {
|
2021-01-25 03:53:47 +00:00
|
|
|
QueueCRC(gamePath);
|
2016-06-27 07:01:09 +00:00
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
std::unique_lock<std::mutex> guard(crcLock);
|
2016-06-27 07:01:09 +00:00
|
|
|
auto it = crcResults.find(gamePath);
|
|
|
|
while (it == crcResults.end()) {
|
2017-02-27 20:57:46 +00:00
|
|
|
crcCond.wait(guard);
|
2016-06-27 07:01:09 +00:00
|
|
|
it = crcResults.find(gamePath);
|
|
|
|
}
|
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
if (crcThread.joinable())
|
|
|
|
crcThread.join();
|
2016-06-27 07:01:09 +00:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
static uint32_t RetrieveCRCUnlessPowerSaving(const Path &gamePath) {
|
2021-01-31 20:12:54 +00:00
|
|
|
// It's okay to use it if we have it already.
|
2021-05-09 16:38:48 +00:00
|
|
|
if (Core_GetPowerSaving() && !HasCRC(gamePath)) {
|
2021-01-31 20:12:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
return RetrieveCRC(gamePath);
|
2021-01-31 20:12:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 03:32:46 +00:00
|
|
|
static void PurgeCRC() {
|
|
|
|
std::unique_lock<std::mutex> guard(crcLock);
|
2021-08-21 18:58:25 +00:00
|
|
|
if (crcPending) {
|
|
|
|
INFO_LOG(SYSTEM, "Cancelling CRC calculation");
|
|
|
|
crcCancel = true;
|
|
|
|
while (crcPending) {
|
|
|
|
crcCond.wait(guard);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
INFO_LOG(SYSTEM, "no CRC pending");
|
2021-02-17 03:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (crcThread.joinable())
|
|
|
|
crcThread.join();
|
|
|
|
}
|
|
|
|
|
2021-08-21 18:58:25 +00:00
|
|
|
void CancelCRC() {
|
|
|
|
PurgeCRC();
|
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns the full host (e.g. report.ppsspp.org:80.)
|
2016-06-26 06:11:07 +00:00
|
|
|
std::string ServerHost()
|
2013-03-24 16:53:41 +00:00
|
|
|
{
|
|
|
|
if (g_Config.sReportHost.compare("default") == 0)
|
|
|
|
return "";
|
|
|
|
return g_Config.sReportHost;
|
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns the length of the hostname part (e.g. before the :80.)
|
2013-03-01 16:58:05 +00:00
|
|
|
static size_t ServerHostnameLength()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return g_Config.sReportHost.npos;
|
|
|
|
|
|
|
|
// IPv6 literal?
|
2013-10-05 17:16:06 +00:00
|
|
|
std::string hostString = ServerHost();
|
|
|
|
if (hostString[0] == '[')
|
2013-03-01 16:58:05 +00:00
|
|
|
{
|
2013-10-05 17:16:06 +00:00
|
|
|
size_t length = hostString.find("]:");
|
|
|
|
if (length != hostString.npos)
|
2013-03-01 16:58:05 +00:00
|
|
|
++length;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
else
|
2013-10-05 17:16:06 +00:00
|
|
|
return hostString.find(':');
|
2013-03-01 16:58:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns only the hostname part (e.g. "report.ppsspp.org".)
|
2013-03-01 16:58:05 +00:00
|
|
|
static const char *ServerHostname()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string host = ServerHost();
|
2013-03-01 16:58:05 +00:00
|
|
|
size_t length = ServerHostnameLength();
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// This means there's no port number - it's already the hostname.
|
|
|
|
if (length == host.npos)
|
|
|
|
lastHostname = host;
|
|
|
|
else
|
|
|
|
lastHostname = host.substr(0, length);
|
2013-03-01 16:58:05 +00:00
|
|
|
return lastHostname.c_str();
|
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns only the port part (e.g. 80) as an int.
|
2013-03-01 16:58:05 +00:00
|
|
|
static int ServerPort()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string host = ServerHost();
|
2013-03-01 16:58:05 +00:00
|
|
|
size_t offset = ServerHostnameLength();
|
2013-04-14 08:25:25 +00:00
|
|
|
// If there's no port, use the default one.
|
2013-03-24 16:53:41 +00:00
|
|
|
if (offset == host.npos)
|
2013-03-01 16:58:05 +00:00
|
|
|
return DEFAULT_PORT;
|
|
|
|
|
|
|
|
// Skip the colon.
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string port = host.substr(offset + 1);
|
2013-03-01 16:58:05 +00:00
|
|
|
return atoi(port.c_str());
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:56:51 +00:00
|
|
|
// Should only be called once per request.
|
|
|
|
bool CheckSpamLimited()
|
|
|
|
{
|
|
|
|
return ++spamProtectionCount >= SPAM_LIMIT;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:24:40 +00:00
|
|
|
bool SendReportRequest(const char *uri, const std::string &data, const std::string &mimeType, Buffer *output = NULL)
|
2013-03-01 20:56:51 +00:00
|
|
|
{
|
|
|
|
http::Client http;
|
2021-05-16 16:55:50 +00:00
|
|
|
http::RequestProgress progress(&pendingMessagesDone);
|
2021-05-01 17:59:15 +00:00
|
|
|
Buffer theVoid = Buffer::Void();
|
2013-03-01 20:56:51 +00:00
|
|
|
|
2021-05-01 06:12:42 +00:00
|
|
|
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
|
|
|
|
|
2021-05-01 17:59:15 +00:00
|
|
|
if (output == nullptr)
|
2013-03-01 20:56:51 +00:00
|
|
|
output = &theVoid;
|
|
|
|
|
2016-04-09 16:21:31 +00:00
|
|
|
const char *serverHost = ServerHostname();
|
|
|
|
if (!serverHost)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (http.Resolve(serverHost, ServerPort())) {
|
2013-03-01 20:56:51 +00:00
|
|
|
http.Connect();
|
2021-05-01 17:19:27 +00:00
|
|
|
int result = http.POST(uri, data, mimeType, output, &progress);
|
2013-03-01 20:56:51 +00:00
|
|
|
http.Disconnect();
|
2016-06-28 05:59:09 +00:00
|
|
|
|
|
|
|
return result >= 200 && result < 300;
|
2016-04-09 16:21:31 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2013-03-01 20:56:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 01:27:51 +00:00
|
|
|
std::string StripTrailingNull(const std::string &str)
|
|
|
|
{
|
|
|
|
size_t pos = str.find_first_of('\0');
|
|
|
|
if (pos != str.npos)
|
|
|
|
return str.substr(0, pos);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-04-29 01:56:09 +00:00
|
|
|
std::string GetPlatformIdentifer()
|
|
|
|
{
|
|
|
|
// TODO: Do we care about OS version?
|
2016-10-12 09:13:16 +00:00
|
|
|
#if defined(__ANDROID__)
|
2013-04-29 01:56:09 +00:00
|
|
|
return "Android";
|
2019-05-04 23:05:26 +00:00
|
|
|
#elif defined(_WIN64) && defined(_M_ARM64)
|
|
|
|
return "Windows ARM64";
|
2013-04-29 02:36:15 +00:00
|
|
|
#elif defined(_WIN64)
|
|
|
|
return "Windows 64";
|
2019-05-04 23:05:26 +00:00
|
|
|
#elif defined(_WIN32) && defined(_M_ARM)
|
|
|
|
return "Windows ARM32";
|
2013-04-29 01:56:09 +00:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
return "Windows";
|
2021-03-03 04:57:25 +00:00
|
|
|
#elif PPSSPP_PLATFORM(IOS)
|
2013-04-29 01:56:09 +00:00
|
|
|
return "iOS";
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
return "Mac";
|
|
|
|
#elif defined(LOONGSON)
|
|
|
|
return "Loongson";
|
2019-09-28 16:00:20 +00:00
|
|
|
#elif defined(__SWITCH__)
|
|
|
|
return "Switch";
|
2013-04-29 02:36:15 +00:00
|
|
|
#elif defined(__linux__)
|
|
|
|
return "Linux";
|
2015-05-26 11:27:56 +00:00
|
|
|
#elif defined(__Bitrig__)
|
|
|
|
return "Bitrig";
|
|
|
|
#elif defined(__DragonFly__)
|
|
|
|
return "DragonFly";
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
return "FreeBSD";
|
2015-05-26 11:27:56 +00:00
|
|
|
#elif defined(__FreeBSD_kernel__) && defined(__GLIBC__)
|
|
|
|
return "GNU/kFreeBSD";
|
2015-05-26 11:27:56 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
return "NetBSD";
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
return "OpenBSD";
|
2013-04-29 01:56:09 +00:00
|
|
|
#else
|
|
|
|
return "Unknown";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-06 16:19:10 +00:00
|
|
|
bool MessageAllowed();
|
|
|
|
void SendReportMessage(const char *message, const char *formatted);
|
|
|
|
|
2014-02-09 21:56:08 +00:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
// New game, clean slate.
|
|
|
|
spamProtectionCount = 0;
|
2021-06-06 16:19:10 +00:00
|
|
|
ResetCounts();
|
2014-02-09 22:04:16 +00:00
|
|
|
everUnsupported = false;
|
2014-02-16 04:34:03 +00:00
|
|
|
currentSupported = IsSupported();
|
2019-09-28 17:45:45 +00:00
|
|
|
pendingMessagesDone = false;
|
2021-06-06 16:19:10 +00:00
|
|
|
Reporting::SetupCallbacks(&MessageAllowed, &SendReportMessage);
|
2014-02-16 04:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2019-09-28 17:45:45 +00:00
|
|
|
pendingMessageLock.lock();
|
|
|
|
pendingMessagesDone = true;
|
|
|
|
pendingMessageCond.notify_one();
|
|
|
|
pendingMessageLock.unlock();
|
|
|
|
if (compatThread.joinable())
|
|
|
|
compatThread.join();
|
|
|
|
if (messageThread.joinable())
|
|
|
|
messageThread.join();
|
2021-02-17 03:32:46 +00:00
|
|
|
PurgeCRC();
|
2019-09-28 17:45:45 +00:00
|
|
|
|
2014-02-16 04:34:03 +00:00
|
|
|
// Just so it can be enabled in the menu again.
|
|
|
|
Init();
|
2014-02-09 22:04:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 17:43:12 +00:00
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
|
|
|
const int LATEST_VERSION = 1;
|
|
|
|
auto s = p.Section("Reporting", 0, LATEST_VERSION);
|
|
|
|
if (!s || s < LATEST_VERSION) {
|
|
|
|
// Don't report from old savestates, they may "entomb" bugs.
|
|
|
|
everUnsupported = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-10 04:20:42 +00:00
|
|
|
Do(p, everUnsupported);
|
2014-02-17 17:43:12 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 22:04:16 +00:00
|
|
|
void UpdateConfig()
|
|
|
|
{
|
2014-02-16 04:34:03 +00:00
|
|
|
currentSupported = IsSupported();
|
|
|
|
if (!currentSupported && PSP_IsInited())
|
2014-02-09 22:04:16 +00:00
|
|
|
everUnsupported = true;
|
2014-02-09 21:56:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 06:11:07 +00:00
|
|
|
std::string CurrentGameID()
|
2013-03-02 06:34:02 +00:00
|
|
|
{
|
2014-02-09 22:35:40 +00:00
|
|
|
// TODO: Maybe ParamSFOData shouldn't include nulls in std::strings? Don't work to break savedata, though...
|
2021-02-28 18:52:35 +00:00
|
|
|
const std::string disc_id = StripTrailingNull(g_paramSFO.GetDiscID());
|
2016-06-26 06:11:07 +00:00
|
|
|
const std::string disc_version = StripTrailingNull(g_paramSFO.GetValueString("DISC_VERSION"));
|
|
|
|
return disc_id + "_" + disc_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddGameInfo(UrlEncoder &postdata)
|
|
|
|
{
|
|
|
|
postdata.Add("game", CurrentGameID());
|
2014-02-09 22:35:40 +00:00
|
|
|
postdata.Add("game_title", StripTrailingNull(g_paramSFO.GetValueString("TITLE")));
|
|
|
|
postdata.Add("sdkver", sceKernelGetCompiledSdkVersion());
|
|
|
|
}
|
2013-03-02 06:34:02 +00:00
|
|
|
|
2014-02-09 22:35:40 +00:00
|
|
|
void AddSystemInfo(UrlEncoder &postdata)
|
|
|
|
{
|
2013-04-29 07:30:54 +00:00
|
|
|
std::string gpuPrimary, gpuFull;
|
2013-05-18 16:47:17 +00:00
|
|
|
if (gpu)
|
|
|
|
gpu->GetReportingInfo(gpuPrimary, gpuFull);
|
2014-02-09 22:35:40 +00:00
|
|
|
|
2013-04-29 01:27:51 +00:00
|
|
|
postdata.Add("version", PPSSPP_GIT_VERSION);
|
2013-04-29 07:30:54 +00:00
|
|
|
postdata.Add("gpu", gpuPrimary);
|
|
|
|
postdata.Add("gpu_full", gpuFull);
|
2013-04-29 01:56:09 +00:00
|
|
|
postdata.Add("cpu", cpu_info.Summarize());
|
|
|
|
postdata.Add("platform", GetPlatformIdentifer());
|
2014-02-09 22:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddConfigInfo(UrlEncoder &postdata)
|
|
|
|
{
|
2013-05-20 03:20:41 +00:00
|
|
|
postdata.Add("pixel_width", PSP_CoreParameter().pixelWidth);
|
|
|
|
postdata.Add("pixel_height", PSP_CoreParameter().pixelHeight);
|
2014-02-09 22:35:40 +00:00
|
|
|
|
2014-02-10 01:15:00 +00:00
|
|
|
g_Config.GetReportingInfo(postdata);
|
2014-02-09 22:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddGameplayInfo(UrlEncoder &postdata)
|
|
|
|
{
|
|
|
|
// Just to get an idea of how long they played.
|
2013-06-01 05:31:05 +00:00
|
|
|
postdata.Add("ticks", (const uint64_t)CoreTiming::GetTicks());
|
2013-05-20 03:20:41 +00:00
|
|
|
|
2017-03-12 03:24:00 +00:00
|
|
|
float vps, fps;
|
|
|
|
__DisplayGetAveragedFPS(&vps, &fps);
|
|
|
|
postdata.Add("vps", vps);
|
|
|
|
postdata.Add("fps", fps);
|
2013-04-29 01:56:09 +00:00
|
|
|
|
2014-02-09 21:45:51 +00:00
|
|
|
postdata.Add("savestate_used", SaveState::HasLoadedState());
|
2014-02-09 22:35:40 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 13:02:23 +00:00
|
|
|
void AddScreenshotData(MultipartFormDataEncoder &postdata, const Path &filename)
|
2016-06-12 17:00:32 +00:00
|
|
|
{
|
|
|
|
std::string data;
|
2021-05-09 13:02:23 +00:00
|
|
|
if (!filename.empty() && File::ReadFileToString(false, filename, data))
|
2016-06-12 17:00:32 +00:00
|
|
|
postdata.Add("screenshot", data, "screenshot.jpg", "image/jpeg");
|
|
|
|
|
|
|
|
const std::string iconFilename = "disc0:/PSP_GAME/ICON0.PNG";
|
|
|
|
std::vector<u8> iconData;
|
|
|
|
if (pspFileSystem.ReadEntireFile(iconFilename, iconData) >= 0) {
|
|
|
|
postdata.Add("icon", iconData, "icon.png", "image/png");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 22:35:40 +00:00
|
|
|
int Process(int pos)
|
|
|
|
{
|
2020-11-30 23:46:26 +00:00
|
|
|
SetCurrentThreadName("Report");
|
2016-06-27 07:01:09 +00:00
|
|
|
|
2014-02-09 22:35:40 +00:00
|
|
|
Payload &payload = payloadBuffer[pos];
|
2016-06-28 05:59:09 +00:00
|
|
|
Buffer output;
|
2014-02-09 22:35:40 +00:00
|
|
|
|
2016-06-12 17:00:32 +00:00
|
|
|
MultipartFormDataEncoder postdata;
|
2014-02-09 22:35:40 +00:00
|
|
|
AddSystemInfo(postdata);
|
|
|
|
AddGameInfo(postdata);
|
|
|
|
AddConfigInfo(postdata);
|
|
|
|
AddGameplayInfo(postdata);
|
2013-03-02 06:34:02 +00:00
|
|
|
|
|
|
|
switch (payload.type)
|
|
|
|
{
|
2016-06-12 14:30:36 +00:00
|
|
|
case RequestType::MESSAGE:
|
2016-06-27 07:01:09 +00:00
|
|
|
// TODO: Add CRC?
|
2013-04-29 01:27:51 +00:00
|
|
|
postdata.Add("message", payload.string1);
|
|
|
|
postdata.Add("value", payload.string2);
|
2016-06-12 14:34:21 +00:00
|
|
|
// We tend to get corrupted data, this acts as a very primitive verification check.
|
|
|
|
postdata.Add("verify", payload.string1 + payload.string2);
|
2013-03-04 07:36:24 +00:00
|
|
|
payload.string1.clear();
|
|
|
|
payload.string2.clear();
|
2013-03-02 06:34:02 +00:00
|
|
|
|
2014-02-10 09:24:40 +00:00
|
|
|
postdata.Finish();
|
2016-06-28 06:00:09 +00:00
|
|
|
serverWorking = true;
|
2016-06-28 05:59:09 +00:00
|
|
|
if (!SendReportRequest("/report/message", postdata.ToString(), postdata.GetMimeType()))
|
|
|
|
serverWorking = false;
|
2013-03-02 06:34:02 +00:00
|
|
|
break;
|
2014-09-27 22:37:53 +00:00
|
|
|
|
2016-06-12 14:30:36 +00:00
|
|
|
case RequestType::COMPAT:
|
2014-09-27 22:37:53 +00:00
|
|
|
postdata.Add("compat", payload.string1);
|
2016-06-12 14:34:21 +00:00
|
|
|
// We tend to get corrupted data, this acts as a very primitive verification check.
|
|
|
|
postdata.Add("verify", payload.string1);
|
2014-09-27 22:37:53 +00:00
|
|
|
postdata.Add("graphics", StringFromFormat("%d", payload.int1));
|
|
|
|
postdata.Add("speed", StringFromFormat("%d", payload.int2));
|
|
|
|
postdata.Add("gameplay", StringFromFormat("%d", payload.int3));
|
2021-01-31 20:12:54 +00:00
|
|
|
postdata.Add("crc", StringFromFormat("%08x", RetrieveCRCUnlessPowerSaving(PSP_CoreParameter().fileToStart)));
|
2018-06-03 21:47:49 +00:00
|
|
|
postdata.Add("suggestions", payload.string1 != "perfect" && payload.string1 != "playable" ? "1" : "0");
|
2021-05-09 13:02:23 +00:00
|
|
|
AddScreenshotData(postdata, Path(payload.string2));
|
2014-09-27 22:37:53 +00:00
|
|
|
payload.string1.clear();
|
2016-06-12 17:00:32 +00:00
|
|
|
payload.string2.clear();
|
2014-09-27 22:37:53 +00:00
|
|
|
|
|
|
|
postdata.Finish();
|
2016-06-28 06:00:09 +00:00
|
|
|
serverWorking = true;
|
2016-06-28 05:59:09 +00:00
|
|
|
if (!SendReportRequest("/report/compat", postdata.ToString(), postdata.GetMimeType(), &output)) {
|
|
|
|
serverWorking = false;
|
|
|
|
} else {
|
2018-06-03 21:47:49 +00:00
|
|
|
std::string result;
|
|
|
|
output.TakeAll(&result);
|
|
|
|
|
|
|
|
lastCompatResult.clear();
|
|
|
|
if (result.empty() || result[0] == '0')
|
2016-06-28 05:59:09 +00:00
|
|
|
serverWorking = false;
|
2018-06-03 21:47:49 +00:00
|
|
|
else if (result[0] != '1')
|
|
|
|
SplitString(result, '\n', lastCompatResult);
|
2016-06-28 05:59:09 +00:00
|
|
|
}
|
2014-09-27 22:37:53 +00:00
|
|
|
break;
|
2016-06-12 19:07:21 +00:00
|
|
|
|
|
|
|
case RequestType::NONE:
|
|
|
|
break;
|
2013-03-02 06:34:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 14:30:36 +00:00
|
|
|
payload.type = RequestType::NONE;
|
|
|
|
|
2013-03-02 06:34:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-01 19:57:39 +00:00
|
|
|
bool IsSupported()
|
|
|
|
{
|
|
|
|
// Disabled when using certain hacks, because they make for poor reports.
|
2020-08-26 02:54:51 +00:00
|
|
|
if (CheatsInEffect() || HLEPlugins::HasEnabled())
|
2014-02-15 23:28:13 +00:00
|
|
|
return false;
|
2017-12-01 18:06:06 +00:00
|
|
|
if (g_Config.iLockedCPUSpeed != 0)
|
2014-02-15 23:19:59 +00:00
|
|
|
return false;
|
2019-02-03 22:34:50 +00:00
|
|
|
if (g_Config.uJitDisableFlags != 0)
|
|
|
|
return false;
|
2015-08-16 20:58:48 +00:00
|
|
|
// Don't allow builds without version info from git. They're useless for reporting.
|
|
|
|
if (strcmp(PPSSPP_GIT_VERSION, "unknown") == 0)
|
|
|
|
return false;
|
2021-04-17 21:28:53 +00:00
|
|
|
// Don't report from games without a version ID (i.e. random hashed homebrew IDs.)
|
|
|
|
// The problem is, these aren't useful because the hashes end up different for different people.
|
|
|
|
// TODO: Should really hash the ELF instead of the path, but then that affects savestates/cheats.
|
2021-08-11 04:43:04 +00:00
|
|
|
if (PSP_IsInited() && g_paramSFO.GetValueString("DISC_VERSION").empty())
|
2021-04-17 21:28:53 +00:00
|
|
|
return false;
|
2014-02-09 22:13:46 +00:00
|
|
|
|
|
|
|
// Some users run the exe from a zip or something, and don't have fonts.
|
|
|
|
// This breaks things, but let's not report it since it's confusing.
|
2014-03-03 15:24:25 +00:00
|
|
|
#if defined(USING_WIN_UI) || defined(APPLE)
|
2021-05-05 23:31:38 +00:00
|
|
|
if (!File::Exists(g_Config.flash0Directory / "font/jpn0.pgf"))
|
2014-02-09 22:13:46 +00:00
|
|
|
return false;
|
2014-03-03 15:24:25 +00:00
|
|
|
#else
|
2021-04-25 19:13:25 +00:00
|
|
|
File::FileInfo fo;
|
2014-03-03 15:24:25 +00:00
|
|
|
if (!VFSGetFileInfo("flash0/font/jpn0.pgf", &fo))
|
|
|
|
return false;
|
|
|
|
#endif
|
2014-02-09 22:13:46 +00:00
|
|
|
|
2014-02-16 04:34:03 +00:00
|
|
|
return !everUnsupported;
|
2013-09-01 19:57:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
bool IsEnabled()
|
2013-03-01 16:58:05 +00:00
|
|
|
{
|
2014-02-20 09:02:22 +00:00
|
|
|
if (g_Config.sReportHost.empty() || (!currentSupported && PSP_IsInited()))
|
2013-03-24 16:53:41 +00:00
|
|
|
return false;
|
2013-03-01 16:58:05 +00:00
|
|
|
// Disabled by default for now.
|
|
|
|
if (g_Config.sReportHost.compare("default") == 0)
|
2013-03-24 16:53:41 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-12 17:33:33 +00:00
|
|
|
bool Enable(bool flag, std::string host)
|
2013-09-01 19:57:39 +00:00
|
|
|
{
|
|
|
|
if (IsSupported() && IsEnabled() != flag)
|
|
|
|
{
|
|
|
|
// "" means explicitly disabled. Don't ever turn on by default.
|
|
|
|
// "default" means it's okay to turn it on by default.
|
|
|
|
g_Config.sReportHost = flag ? host : "";
|
2016-06-12 17:33:33 +00:00
|
|
|
return true;
|
2013-09-01 19:57:39 +00:00
|
|
|
}
|
2016-06-12 17:33:33 +00:00
|
|
|
return false;
|
2013-09-01 19:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnableDefault()
|
|
|
|
{
|
|
|
|
g_Config.sReportHost = "default";
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:11:40 +00:00
|
|
|
ReportStatus GetStatus()
|
2016-06-28 05:59:09 +00:00
|
|
|
{
|
|
|
|
if (!serverWorking)
|
2017-12-13 22:11:40 +00:00
|
|
|
return ReportStatus::FAILING;
|
2016-06-28 05:59:09 +00:00
|
|
|
|
|
|
|
for (int pos = 0; pos < PAYLOAD_BUFFER_SIZE; ++pos)
|
|
|
|
{
|
|
|
|
if (payloadBuffer[pos].type != RequestType::NONE)
|
2017-12-13 22:11:40 +00:00
|
|
|
return ReportStatus::BUSY;
|
2016-06-28 05:59:09 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:11:40 +00:00
|
|
|
return ReportStatus::WORKING;
|
2016-06-28 05:59:09 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 14:30:36 +00:00
|
|
|
int NextFreePos()
|
|
|
|
{
|
|
|
|
int start = payloadBufferPos % PAYLOAD_BUFFER_SIZE;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
int pos = payloadBufferPos++ % PAYLOAD_BUFFER_SIZE;
|
|
|
|
if (payloadBuffer[pos].type == RequestType::NONE)
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
while (payloadBufferPos != start);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
int ProcessPending() {
|
2020-11-30 23:46:26 +00:00
|
|
|
SetCurrentThreadName("Report");
|
2019-09-28 17:45:45 +00:00
|
|
|
|
|
|
|
std::unique_lock<std::mutex> guard(pendingMessageLock);
|
|
|
|
while (!pendingMessagesDone) {
|
|
|
|
while (!pendingMessages.empty() && !pendingMessagesDone) {
|
|
|
|
int pos = pendingMessages.front();
|
|
|
|
pendingMessages.pop_front();
|
|
|
|
|
|
|
|
guard.unlock();
|
|
|
|
Process(pos);
|
|
|
|
guard.lock();
|
|
|
|
}
|
|
|
|
if (pendingMessagesDone) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pendingMessageCond.wait(guard);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-06 16:19:10 +00:00
|
|
|
bool MessageAllowed() {
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled() || CheckSpamLimited())
|
2021-06-06 16:19:10 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2013-03-01 16:58:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 16:19:10 +00:00
|
|
|
void SendReportMessage(const char *message, const char *formatted) {
|
2016-06-12 14:30:36 +00:00
|
|
|
int pos = NextFreePos();
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
2015-03-22 07:12:08 +00:00
|
|
|
|
|
|
|
Payload &payload = payloadBuffer[pos];
|
2016-06-12 14:30:36 +00:00
|
|
|
payload.type = RequestType::MESSAGE;
|
2015-03-22 07:12:08 +00:00
|
|
|
payload.string1 = message;
|
|
|
|
payload.string2 = formatted;
|
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
std::lock_guard<std::mutex> guard(pendingMessageLock);
|
|
|
|
pendingMessages.push_back(pos);
|
|
|
|
pendingMessageCond.notify_one();
|
|
|
|
|
|
|
|
if (!messageThread.joinable()) {
|
|
|
|
messageThread = std::thread(ProcessPending);
|
|
|
|
}
|
2015-03-22 07:12:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 07:01:09 +00:00
|
|
|
void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay, const std::string &screenshotFilename)
|
2014-09-27 22:37:53 +00:00
|
|
|
{
|
|
|
|
if (!IsEnabled())
|
|
|
|
return;
|
2016-06-12 14:30:36 +00:00
|
|
|
int pos = NextFreePos();
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
2014-09-27 22:37:53 +00:00
|
|
|
|
|
|
|
Payload &payload = payloadBuffer[pos];
|
2016-06-12 14:30:36 +00:00
|
|
|
payload.type = RequestType::COMPAT;
|
2014-09-27 22:37:53 +00:00
|
|
|
payload.string1 = compat;
|
2016-06-12 17:00:32 +00:00
|
|
|
payload.string2 = screenshotFilename;
|
2014-09-27 22:37:53 +00:00
|
|
|
payload.int1 = graphics;
|
|
|
|
payload.int2 = speed;
|
|
|
|
payload.int3 = gameplay;
|
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
if (compatThread.joinable())
|
|
|
|
compatThread.join();
|
|
|
|
compatThread = std::thread(Process, pos);
|
2014-09-27 22:37:53 +00:00
|
|
|
}
|
2018-06-03 21:47:49 +00:00
|
|
|
|
|
|
|
std::vector<std::string> CompatibilitySuggestions() {
|
|
|
|
return lastCompatResult;
|
|
|
|
}
|
2013-06-01 05:31:05 +00:00
|
|
|
}
|