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

Add a bunch of restrictions when online #19871

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ static const ConfigSetting networkSettings[] = {
ConfigSetting("UPnPUseOriginalPort", &g_Config.bUPnPUseOriginalPort, false, CfgFlag::PER_GAME),
ConfigSetting("InfrastructureUsername", &g_Config.sInfrastructureUsername, &DefaultInfrastructureUsername, CfgFlag::PER_GAME),
ConfigSetting("InfrastructureAutoDNS", &g_Config.bInfrastructureAutoDNS, true, CfgFlag::PER_GAME),
ConfigSetting("AllowSavestateWhileConnected", &g_Config.bAllowSavestateWhileConnected, false, CfgFlag::DONT_SAVE),

ConfigSetting("EnableNetworkChat", &g_Config.bEnableNetworkChat, false, CfgFlag::PER_GAME),
ConfigSetting("ChatButtonPosition", &g_Config.iChatButtonPosition, (int)ScreenEdgePosition::BOTTOM_LEFT, CfgFlag::PER_GAME),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ struct Config {
std::string sInfrastructureDNSServer;
std::string sInfrastructureUsername; // Username used for Infrastructure play. Different restrictions.
bool bInfrastructureAutoDNS;
bool bAllowSavestateWhileConnected; // Developer option, ini-only. No normal users need this, it's always wrong to save/load state when online.

bool bEnableWlan;
std::map<std::string, std::string> mHostToAlias; // Local DNS database stored in ini file
Expand Down
11 changes: 9 additions & 2 deletions Core/FrameTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Core/System.h"
#include "Core/Config.h"
#include "Core/HW/Display.h"
#include "Core/HLE/sceNet.h"
#include "Core/FrameTiming.h"

FrameTiming g_frameTiming;
Expand Down Expand Up @@ -93,10 +94,16 @@ Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval) {
wantInstant = true;
}

if (PSP_CoreParameter().fastForward) {
if (PSP_CoreParameter().fastForward && NetworkAllowSpeedControl()) {
wantInstant = true;
}
if (PSP_CoreParameter().fpsLimit != FPSLimit::NORMAL) {

FPSLimit limit = PSP_CoreParameter().fpsLimit;
if (!NetworkAllowSpeedControl()) {
limit = FPSLimit::NORMAL;
}

if (limit != FPSLimit::NORMAL) {
int limit;
if (PSP_CoreParameter().fpsLimit == FPSLimit::CUSTOM1)
limit = g_Config.iFpsLimit1;
Expand Down
5 changes: 5 additions & 0 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "Core/HLE/FunctionWrappers.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceNet.h"
#include "Core/HLE/sceKernelThread.h"
#include "Core/HLE/sceKernelInterrupt.h"
#include "Core/HW/Display.h"
Expand Down Expand Up @@ -353,6 +354,10 @@ void __DisplaySetWasPaused() {

// TOOD: Should return 59.997?
static int FrameTimingLimit() {
if (!NetworkAllowSpeedControl()) {
return 60;
}

bool challenge = Achievements::HardcoreModeActive();

auto fixRate = [=](int limit) {
Expand Down
28 changes: 28 additions & 0 deletions Core/HLE/sceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ int NetApctl_Term();
void NetApctl_InitDefaultInfo();
void NetApctl_InitInfo(int confId);

bool NetworkWarnUserIfOnlineAndCantSavestate() {
if (netInited && !g_Config.bAllowSavestateWhileConnected) {
auto nw = GetI18NCategory(I18NCat::NETWORKING);
g_OSD.Show(OSDType::MESSAGE_INFO, nw->T("Save states are not available when online"), 3.0f, "saveonline");
return true;
} else {
return false;
}
}

bool NetworkWarnUserIfOnlineAndCantSpeed() {
if (netInited) {
auto nw = GetI18NCategory(I18NCat::NETWORKING);
g_OSD.Show(OSDType::MESSAGE_INFO, nw->T("Speed controls are not available when online"), 3.0f, "speedonline");
return true;
} else {
return false;
}
}

bool NetworkAllowSpeedControl() {
return !netInited;
}

bool NetworkAllowSaveState() {
return !netInited || g_Config.bAllowSavestateWhileConnected;
}

void AfterApctlMipsCall::DoState(PointerWrap & p) {
auto s = p.Section("AfterApctlMipsCall", 1, 1);
if (!s)
Expand Down
7 changes: 7 additions & 0 deletions Core/HLE/sceNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ int NetApctl_GetState();
int sceNetApctlConnect(int connIndex);
int sceNetApctlTerm();

// These return false if allowed to be consistent with the similar function for achievements.
bool NetworkWarnUserIfOnlineAndCantSavestate();
bool NetworkWarnUserIfOnlineAndCantSpeed();

bool NetworkAllowSaveState();
bool NetworkAllowSpeedControl();

enum class InfraGameState {
Unknown,
Working,
Expand Down
37 changes: 36 additions & 1 deletion Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "Core/FileSystems/MetaFileSystem.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/sceNet.h"
#include "Core/HLE/ReplaceTables.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h"
Expand Down Expand Up @@ -404,6 +405,9 @@ namespace SaveState

void Enqueue(const SaveState::Operation &op)
{
if (!NetworkAllowSaveState()) {
return;
}
if (Achievements::HardcoreModeActive()) {
if (g_Config.bAchievementsSaveStateInHardcoreMode && ((op.type == SaveState::SAVESTATE_SAVE) || (op.type == SAVESTATE_SAVE_SCREENSHOT))) {
// We allow saving in hardcore mode if this setting is on.
Expand All @@ -423,6 +427,10 @@ namespace SaveState

void Load(const Path &filename, int slot, Callback callback, void *cbUserData)
{
if (!NetworkAllowSaveState()) {
return;
}

rewindStates.NotifyState();
if (coreState == CoreState::CORE_RUNTIME_ERROR)
Core_Break("savestate.load", 0);
Expand All @@ -431,6 +439,10 @@ namespace SaveState

void Save(const Path &filename, int slot, Callback callback, void *cbUserData)
{
if (!NetworkAllowSaveState()) {
return;
}

rewindStates.NotifyState();
if (coreState == CoreState::CORE_RUNTIME_ERROR)
Core_Break("savestate.save", 0);
Expand All @@ -444,6 +456,9 @@ namespace SaveState

void Rewind(Callback callback, void *cbUserData)
{
if (netInited) {
return;
}
if (coreState == CoreState::CORE_RUNTIME_ERROR)
Core_Break("savestate.rewind", 0);
Enqueue(Operation(SAVESTATE_REWIND, Path(), -1, callback, cbUserData));
Expand Down Expand Up @@ -574,6 +589,10 @@ namespace SaveState

void LoadSlot(const Path &gameFilename, int slot, Callback callback, void *cbUserData)
{
if (!NetworkAllowSaveState()) {
return;
}

Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
if (!fn.empty()) {
// This add only 1 extra state, should we just always enable it?
Expand Down Expand Up @@ -611,6 +630,10 @@ namespace SaveState

bool UndoLoad(const Path &gameFilename, Callback callback, void *cbUserData)
{
if (!NetworkAllowSaveState()) {
return false;
}

if (g_Config.sStateLoadUndoGame != GenerateFullDiscId(gameFilename)) {
if (callback) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
Expand All @@ -634,6 +657,10 @@ namespace SaveState

void SaveSlot(const Path &gameFilename, int slot, Callback callback, void *cbUserData)
{
if (!NetworkAllowSaveState()) {
return;
}

Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
Path fnUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_STATE_EXTENSION);
if (!fn.empty()) {
Expand Down Expand Up @@ -671,7 +698,11 @@ namespace SaveState
}
}

bool UndoSaveSlot(const Path &gameFilename, int slot) {
bool UndoSaveSlot(const Path &gameFilename, int slot) {
if (!NetworkAllowSaveState()) {
return false;
}

Path fnUndo = GenerateSaveSlotFilename(gameFilename, slot, UNDO_STATE_EXTENSION);

// Do nothing if there's no undo.
Expand All @@ -690,6 +721,10 @@ namespace SaveState


bool UndoLastSave(const Path &gameFilename) {
if (!NetworkAllowSaveState()) {
return false;
}

if (g_Config.sStateUndoLastSaveGame != GenerateFullDiscId(gameFilename))
return false;

Expand Down
26 changes: 14 additions & 12 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ using namespace std::placeholders;
#include "Core/MIPS/MIPS.h"
#include "Core/HLE/sceCtrl.h"
#include "Core/HLE/sceSas.h"
#include "Core/HLE/sceNet.h"
#include "Core/HLE/sceNetAdhoc.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/RetroAchievements.h"
Expand Down Expand Up @@ -678,7 +679,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
}
break;
case VIRTKEY_FASTFORWARD:
if (down) {
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
if (coreState == CORE_STEPPING_CPU) {
Core_Resume();
}
Expand All @@ -689,7 +690,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
break;

case VIRTKEY_SPEED_TOGGLE:
if (down) {
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
// Cycle through enabled speeds.
if (PSP_CoreParameter().fpsLimit == FPSLimit::NORMAL && g_Config.iFpsLimit1 >= 0) {
PSP_CoreParameter().fpsLimit = FPSLimit::CUSTOM1;
Expand All @@ -705,7 +706,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
break;

case VIRTKEY_SPEED_CUSTOM1:
if (down) {
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
if (PSP_CoreParameter().fpsLimit == FPSLimit::NORMAL) {
PSP_CoreParameter().fpsLimit = FPSLimit::CUSTOM1;
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("fixed", "Speed: alternate"), 1.0, "altspeed");
Expand All @@ -718,7 +719,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
}
break;
case VIRTKEY_SPEED_CUSTOM2:
if (down) {
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
if (PSP_CoreParameter().fpsLimit == FPSLimit::NORMAL) {
PSP_CoreParameter().fpsLimit = FPSLimit::CUSTOM2;
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("SpeedCustom2", "Speed: alternate 2"), 1.0, "altspeed");
Expand All @@ -743,7 +744,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {

case VIRTKEY_FRAME_ADVANCE:
// Can't do this reliably in an async fashion, so we just set a variable.
if (down) {
if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) {
doFrameAdvance_.store(true);
}
break;
Expand Down Expand Up @@ -797,7 +798,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
#endif

case VIRTKEY_REWIND:
if (down && !Achievements::WarnUserIfHardcoreModeActive(false)) {
if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate()) {
if (SaveState::CanRewind()) {
SaveState::Rewind(&AfterSaveStateAction);
} else {
Expand All @@ -806,23 +807,23 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
}
break;
case VIRTKEY_SAVE_STATE:
if (down && !Achievements::WarnUserIfHardcoreModeActive(true)) {
if (down && !Achievements::WarnUserIfHardcoreModeActive(true) && !NetworkWarnUserIfOnlineAndCantSavestate()) {
SaveState::SaveSlot(gamePath_, g_Config.iCurrentStateSlot, &AfterSaveStateAction);
}
break;
case VIRTKEY_LOAD_STATE:
if (down && !Achievements::WarnUserIfHardcoreModeActive(false)) {
if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate()) {
SaveState::LoadSlot(gamePath_, g_Config.iCurrentStateSlot, &AfterSaveStateAction);
}
break;
case VIRTKEY_PREVIOUS_SLOT:
if (down && !Achievements::WarnUserIfHardcoreModeActive(true)) {
if (down && !Achievements::WarnUserIfHardcoreModeActive(true) && !NetworkWarnUserIfOnlineAndCantSavestate()) {
SaveState::PrevSlot();
System_PostUIMessage(UIMessage::SAVESTATE_DISPLAY_SLOT);
}
break;
case VIRTKEY_NEXT_SLOT:
if (down && !Achievements::WarnUserIfHardcoreModeActive(true)) {
if (down && !Achievements::WarnUserIfHardcoreModeActive(true) && NetworkWarnUserIfOnlineAndCantSavestate()) {
SaveState::NextSlot();
System_PostUIMessage(UIMessage::SAVESTATE_DISPLAY_SLOT);
}
Expand Down Expand Up @@ -904,7 +905,8 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
g_Config.iInternalScreenRotation = ROTATION_LOCKED_HORIZONTAL180;
break;
case VIRTKEY_TOGGLE_WLAN:
if (down) {
// Let's not allow the user to toggle wlan while connected, could get confusing.
if (down && !netInited) {
auto n = GetI18NCategory(I18NCat::NETWORKING);
auto di = GetI18NCategory(I18NCat::DIALOG);
g_Config.bEnableWlan = !g_Config.bEnableWlan;
Expand Down Expand Up @@ -1841,7 +1843,7 @@ void EmuScreen::resized() {
}

bool MustRunBehind() {
return __NetAdhocConnected();
return netInited || __NetAdhocConnected();
}

bool ShouldRunBehind() {
Expand Down
1 change: 0 additions & 1 deletion UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class BoolButton : public MultiTouchButton {
public:
BoolButton(bool *value, const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), value_(value) {

}
bool Touch(const TouchInput &input) override;
bool IsDown() override { return *value_; }
Expand Down
Loading
Loading