Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Infrastructure Implementation #21

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ constexpr const char *HTTP_VERSION = "1.1";

Client::Client() {
userAgent_ = DEFAULT_USERAGENT;
httpVersion_ = HTTP_VERSION;
}

Client::~Client() {
Expand Down Expand Up @@ -368,7 +369,7 @@ int Client::SendRequestWithData(const char *method, const RequestParams &req, co
return 0;
}

int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &responseHeaders, net::RequestProgress *progress) {
int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &responseHeaders, net::RequestProgress *progress, std::string *statusLine) {
// Snarf all the data we can into RAM. A little unsafe but hey.
static constexpr float CANCEL_INTERVAL = 0.25f;
bool ready = false;
Expand Down Expand Up @@ -406,6 +407,9 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &
return -1;
}

if (statusLine)
*statusLine = line;

while (true) {
int sz = readbuf->TakeLineCRLF(&line);
if (!sz || sz < 0)
Expand Down
7 changes: 6 additions & 1 deletion Common/Net/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Client : public net::Connection {

int SendRequest(const char *method, const RequestParams &req, const char *otherHeaders, net::RequestProgress *progress);
int SendRequestWithData(const char *method, const RequestParams &req, const std::string &data, const char *otherHeaders, net::RequestProgress *progress);
int ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &responseHeaders, net::RequestProgress *progress);
int ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &responseHeaders, net::RequestProgress *progress, std::string *statusLine = nullptr);
// If your response contains a response, you must read it.
int ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::string> &responseHeaders, Buffer *output, net::RequestProgress *progress);

Expand All @@ -84,8 +84,13 @@ class Client : public net::Connection {
userAgent_ = value;
}

void SetHttpVersion(const char* version) {
httpVersion_ = version;
}

protected:
std::string userAgent_;
const char* httpVersion_;
double dataTimeout_ = 900.0;
};

Expand Down
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ static const ConfigSetting networkSettings[] = {
ConfigSetting("EnableAdhocServer", &g_Config.bEnableAdhocServer, false, CfgFlag::PER_GAME),
ConfigSetting("proAdhocServer", &g_Config.proAdhocServer, "socom.cc", CfgFlag::PER_GAME),
ConfigSetting("PortOffset", &g_Config.iPortOffset, 10000, CfgFlag::PER_GAME),
ConfigSetting("PrimaryDNSServer", &g_Config.primaryDNSServer, "135.148.144.253", CfgFlag::PER_GAME),
ConfigSetting("SecondaryDNSServer", &g_Config.secondaryDNSServer, "0.0.0.0", CfgFlag::PER_GAME),
ConfigSetting("MinTimeout", &g_Config.iMinTimeout, 0, CfgFlag::PER_GAME),
ConfigSetting("ForcedFirstConnect", &g_Config.bForcedFirstConnect, false, CfgFlag::PER_GAME),
ConfigSetting("EnableUPnP", &g_Config.bEnableUPnP, false, CfgFlag::PER_GAME),
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ struct Config {

// Networking
std::string proAdhocServer;
std::string primaryDNSServer;
std::string secondaryDNSServer;
bool bEnableWlan;
bool bEnableAdhocServer;
bool bEnableUPnP;
Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/PSPMsgDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static const float FONT_SCALE = 0.65f;

// These are rough, it seems to take a long time to init, and probably depends on threads.
// TODO: This takes like 700ms on a PSP but that's annoyingly long.
const static int MSG_INIT_DELAY_US = 300000;
const static int MSG_INIT_DELAY_US = 350000;
const static int MSG_SHUTDOWN_DELAY_US = 26000;

PSPMsgDialog::PSPMsgDialog(UtilityDialogType type) : PSPDialog(type) {
Expand Down
102 changes: 76 additions & 26 deletions Core/Dialog/PSPNetconfDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const float FONT_SCALE = 0.65f;

// Needs testing.
const static int NET_INIT_DELAY_US = 200000;
const static int NET_SHUTDOWN_DELAY_US = 200000;
const static int NET_SHUTDOWN_DELAY_US = 501000;
const static int NET_CONNECT_TIMEOUT = 15000000; // Using 15 secs to match the timeout on Adhoc Server side (SERVER_USER_TIMEOUT)

struct ScanInfos {
Expand Down Expand Up @@ -79,6 +79,7 @@ int PSPNetconfDialog::Init(u32 paramAddr) {
connResult = -1;
scanInfosAddr = 0;
scanStep = 0;
canceling = false;
startTime = (u64)(time_now_d() * 1000000.0);

StartFade(true);
Expand Down Expand Up @@ -244,6 +245,7 @@ int PSPNetconfDialog::Update(int animSpeed) {
// It seems JPCSP doesn't check for NETCONF_STATUS_APNET
if (request.netAction == NETCONF_CONNECT_APNET || request.netAction == NETCONF_STATUS_APNET || request.netAction == NETCONF_CONNECT_APNET_LAST) {
int state = NetApctl_GetState();
bool timedout = (state == PSP_NET_APCTL_STATE_DISCONNECTED && now - startTime > NET_CONNECT_TIMEOUT);

UpdateFade(animSpeed);
StartDraw();
Expand Down Expand Up @@ -285,33 +287,69 @@ int PSPNetconfDialog::Update(int animSpeed) {
DrawBanner();
DrawIndicator();

if (state == PSP_NET_APCTL_STATE_GOT_IP || state == PSP_NET_APCTL_STATE_GETTING_IP) {
DisplayMessage(di->T("ObtainingIP", "Obtaining IP address.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
if (!g_Config.bEnableWlan) {
DisplayMessage(di->T("WlanIsOff", "A connection error has occurred.\nThe WIRELESS switch on the PPSSPP system is not turned on."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
DisplayButtons(DS_BUTTON_CANCEL, di->T("Back"));
}
else if (timedout) {
// FIXME: Do we need to show error message on timeout?
DisplayMessage(di->T("InternalError", "An internal error has occurred.") + StringFromFormat("\n(%08X)", connResult));
DisplayButtons(DS_BUTTON_CANCEL, di->T("Back"));
}
else if (canceling) {
DisplayMessage(di->T("CancelingPleaseWait", "Canceling.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
}
else {
// Skipping the Select Connection screen since we only have 1 fake profile
DisplayMessage(di->T("ConnectingAP", "Connecting to the access point.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);

if (state == PSP_NET_APCTL_STATE_GOT_IP || state == PSP_NET_APCTL_STATE_GETTING_IP) {
DisplayMessage(di->T("ObtainingIP", "Obtaining IP address.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
}
else {
// Skipping the Select Connection screen since we only have 1 fake profile
DisplayMessage(di->T("ConnectingAP", "Connecting to the access point.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
DisplayButtons(DS_BUTTON_CANCEL, di->T("Cancel"));
}

// The Netconf dialog stays visible until the network reaches the state PSP_NET_APCTL_STATE_GOT_IP.
if (state == PSP_NET_APCTL_STATE_GOT_IP) {
if (pendingStatus != SCE_UTILITY_STATUS_FINISHED) {
StartFade(false);
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NET_SHUTDOWN_DELAY_US);
}
}

else if (state == PSP_NET_APCTL_STATE_JOINING) {
// Switch to the next (Obtaining IP) message animation
// TODO: Should be animating the top and bottom lines widening-from-the-middle animation instead of fading-out and in
//StartFade(true);
}

else if (state == PSP_NET_APCTL_STATE_DISCONNECTED) {
// FIXME: Based on JPCSP+official prx, sceNetApctl* calls supposed to runs on SceDialogmainGraphics thread instead of current thread where Update is being called (ie. Main), thus animation smoothness won't be affected by blocking syscalls
// When connecting with infrastructure, simulate a connection using the first network configuration entry.
if (connResult < 0 && (now - startTime > 2000000)) {
connResult = sceNetApctlConnect(1);
}
}
}
DisplayButtons(DS_BUTTON_CANCEL, di->T("Cancel"));

// The Netconf dialog stays visible until the network reaches the state PSP_NET_APCTL_STATE_GOT_IP.
// The Netconf dialog stays visible until the network reaches the state PSP_NET_APCTL_STATE_GOT_IP.
if (state == PSP_NET_APCTL_STATE_GOT_IP) {
// Checking pendingStatus to make sure ChangeStatus not to continously extending the delay ticks on every call for eternity
if (pendingStatus != SCE_UTILITY_STATUS_FINISHED) {
StartFade(false);
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NET_SHUTDOWN_DELAY_US);
}
}

else if (state == PSP_NET_APCTL_STATE_JOINING) {
// Switch to the next message
StartFade(true);
}

else if (state == PSP_NET_APCTL_STATE_DISCONNECTED) {
// When connecting with infrastructure, simulate a connection using the first network configuration entry.
if (connResult < 0) {
connResult = sceNetApctlConnect(1);
if (!canceling && state != PSP_NET_APCTL_STATE_GOT_IP && state != PSP_NET_APCTL_STATE_GETTING_IP && IsButtonPressed(cancelButtonFlag)) {
if (state != PSP_NET_APCTL_STATE_DISCONNECTED) {
canceling = true;
sceNetApctlDisconnect();
}
StartFade(false);
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NET_SHUTDOWN_DELAY_US);
request.common.result = SCE_UTILITY_DIALOG_RESULT_ABORT;
}
}

Expand All @@ -320,23 +358,29 @@ int PSPNetconfDialog::Update(int animSpeed) {
else if (request.netAction == NETCONF_CONNECT_ADHOC || request.netAction == NETCONF_CREATE_ADHOC || request.netAction == NETCONF_JOIN_ADHOC) {
int state = NetAdhocctl_GetState();
bool timedout = (state == ADHOCCTL_STATE_DISCONNECTED && now - startTime > NET_CONNECT_TIMEOUT);
std::string channel = std::to_string(g_Config.iWlanAdhocChannel);
if (g_Config.iWlanAdhocChannel == PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC)
channel = "Automatic";

UpdateFade(animSpeed);
StartDraw();
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0xC0C8B2AC));
DrawBanner();
DrawIndicator();

if (timedout) {
// FIXME: Do we need to show error message?
if (!g_Config.bEnableWlan) {
DisplayMessage(di->T("WlanIsOff", "A connection error has occurred.\nThe WIRELESS switch on the PPSSPP system is not turned on."));
DisplayButtons(DS_BUTTON_CANCEL, di->T("Back"));
}
else if (timedout) {
// FIXME: Do we need to show error message on timeout?
DisplayMessage(di->T("InternalError", "An internal error has occurred.") + StringFromFormat("\n(%08X)", connResult));
DisplayButtons(DS_BUTTON_CANCEL, di->T("Back"));
}
else if (canceling) {
DisplayMessage(di->T("CancelingPleaseWait", "Canceling.\nPlease wait..."), di->T("Channel:") + std::string(" ") + di->T(channel));
}
else {
std::string channel = std::to_string(g_Config.iWlanAdhocChannel);
if (g_Config.iWlanAdhocChannel == PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC)
channel = "Automatic";

DisplayMessage(di->T("ConnectingPleaseWait", "Connecting.\nPlease wait..."), di->T("Channel:") + std::string(" ") + di->T(channel));

// Only Join mode is showing Cancel button on KHBBS and the button will fade out before the dialog is fading out, probably because it's already connected thus can't be canceled anymore
Expand All @@ -345,6 +389,7 @@ int PSPNetconfDialog::Update(int animSpeed) {

// KHBBS will first enter the arena using NETCONF_CONNECT_ADHOC (auto-create group when not exist yet?), but when the event started the event's creator use NETCONF_CREATE_ADHOC while the joining players use NETCONF_JOIN_ADHOC
if (request.NetconfData.IsValid()) {
// FIXME: Based on JPCSP+official prx, sceNetAdhocctl* calls supposed to runs on SceDialogmainGraphics thread instead of current thread where Update is being called (ie. Main), thus animation smoothness won't be affected by blocking syscalls
if (state == ADHOCCTL_STATE_DISCONNECTED) {
switch (request.netAction)
{
Expand Down Expand Up @@ -441,7 +486,11 @@ int PSPNetconfDialog::Update(int animSpeed) {
scanInfosAddr = 0;
}

if ((request.netAction == NETCONF_JOIN_ADHOC || timedout) && IsButtonPressed(cancelButtonFlag)) {
if ((request.netAction == NETCONF_JOIN_ADHOC || timedout || !g_Config.bEnableWlan) && IsButtonPressed(cancelButtonFlag)) {
if (state != ADHOCCTL_STATE_DISCONNECTED) {
canceling = true;
sceNetAdhocctlDisconnect();
}
StartFade(false);
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NET_SHUTDOWN_DELAY_US);
request.common.result = SCE_UTILITY_DIALOG_RESULT_ABORT;
Expand All @@ -454,9 +503,6 @@ int PSPNetconfDialog::Update(int animSpeed) {
EndDraw();
}

if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED)
Memory::Memcpy(requestAddr, &request, request.common.size, "NetConfDialogParam");

return 0;
}

Expand All @@ -469,6 +515,10 @@ int PSPNetconfDialog::Shutdown(bool force) {
ChangeStatusShutdown(NET_SHUTDOWN_DELAY_US);
}

// FIXME: This should probably be done within FinishShutdown? since FinishShutdown is not overrideable, Shutdown is the closes method
if (Memory::IsValidAddress(requestAddr)) // Need to validate first to prevent Invalid address when the game is being Shutdown/Exited to menu
Memory::Memcpy(requestAddr, &request, request.common.size, "NetConfDialogParam");

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions Core/Dialog/PSPNetconfDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PSPNetconfDialog: public PSPDialog {
u32 requestAddr = 0;
int connResult = -1;
bool hideNotice = false;
bool canceling = false;

int yesnoChoice = 0;
float scrollPos_ = 0.0f;
Expand Down
40 changes: 40 additions & 0 deletions Core/HLE/FunctionWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ template<int func(u32, u32, u32, u32, u32)> void WrapI_UUUUU() {
RETURN(retval);
}

template<int func(u32, const char*, u32, u32, int)> void WrapI_UCUUI() {
int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4));
RETURN(retval);
}

template<int func(u32, int, const char*, u32, u32)> void WrapI_UICUU() {
int retval = func(PARAM(0), PARAM(1), Memory::GetCharPointer(PARAM(2)), PARAM(3), PARAM(4));
RETURN(retval);
}

template<int func()> void WrapI_V() {
int retval = func();
RETURN(retval);
Expand Down Expand Up @@ -438,11 +448,21 @@ template<int func(int, int, int, u32, int)> void WrapI_IIIUI() {
RETURN(retval);
}

template<int func(int, int, int, u32, u32)> void WrapI_IIIUU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
RETURN(retval);
}

template<int func(int, u32, u32, int, int)> void WrapI_IUUII() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
RETURN(retval);
}

template<int func(int, u32, u32, int, int, int)> void WrapI_IUUIII() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
RETURN(retval);
}

template<int func(int, const char *, int, u32, u32)> void WrapI_ICIUU() {
int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4));
RETURN(retval);
Expand Down Expand Up @@ -483,6 +503,11 @@ template<int func(const char *, u32)> void WrapI_CU() {
RETURN(retval);
}

template<int func(int, const char*, u32)> void WrapI_ICU() {
int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2));
RETURN(retval);
}

template<int func(const char *, u32, int)> void WrapI_CUI() {
int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
RETURN(retval);
Expand Down Expand Up @@ -755,6 +780,16 @@ template<int func(int, u32, u32, u32)> void WrapI_IUUU() {
RETURN(retval);
}

template<int func(int, u32, int, int, u32, u32)> void WrapI_IUIIUU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
RETURN(retval);
}

template<int func(int, u32, int, int, u32, int)> void WrapI_IUIIUI() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
RETURN(retval);
}

template<int func(int, u32, u32)> void WrapI_IUU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2));
RETURN(retval);
Expand All @@ -765,6 +800,11 @@ template<u32 func(u32, u32, u32, u32, u32, u32, u32)> void WrapU_UUUUUUU() {
RETURN(retval);
}

template<int func(u32, u32, u32, u32, u32, u32, u32)> void WrapI_UUUUUUU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
RETURN(retval);
}

template<int func(int, u32, u32, u32, u32, u32, u32)> void WrapI_IUUUUUU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
RETURN(retval);
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/HLETables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "sceNet.h"
#include "sceNetAdhoc.h"
#include "sceNp.h"
#include "sceNp2.h"
#include "sceMpeg.h"
#include "sceOpenPSID.h"
#include "sceP3da.h"
Expand Down Expand Up @@ -307,6 +308,8 @@ void RegisterAllModules() {
Register_sceDdrdb();
Register_mp4msv();
Register_InterruptManagerForKernel();
Register_sceNpMatching2();
Register_sceNetApctl_internal_user();
// add new modules here.
}

Loading
Loading