From e3103249f48a0b0dd2b2b0d686b5956b287321dd Mon Sep 17 00:00:00 2001
From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com>
Date: Thu, 23 Mar 2023 20:06:53 +0400
Subject: [PATCH] engine: platform: psvita: added developer mode button to
launcher
---
engine/common/launcher.c | 6 +-
engine/platform/platform.h | 1 +
.../sce_sys/livearea/contents/template.xml | 9 +++
engine/platform/psvita/sys_psvita.c | 61 ++++++++++++++++++-
4 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/engine/common/launcher.c b/engine/common/launcher.c
index 598c1c17..4c2f9d66 100644
--- a/engine/common/launcher.c
+++ b/engine/common/launcher.c
@@ -91,9 +91,13 @@ _inline int Sys_Start( void )
#if !XASH_WIN32
int main( int argc, char **argv )
{
+#if XASH_PSVITA
+ // inject -dev -console into args if required
+ szArgc = PSVita_GetArgv( argc, argv, &szArgv );
+#else
szArgc = argc;
szArgv = argv;
-
+#endif // XASH_PSVITA
return Sys_Start();
}
#else
diff --git a/engine/platform/platform.h b/engine/platform/platform.h
index 76805fa4..90a705b9 100644
--- a/engine/platform/platform.h
+++ b/engine/platform/platform.h
@@ -60,6 +60,7 @@ void NSwitch_Shutdown( void );
void PSVita_Init( void );
void PSVita_Shutdown( void );
qboolean PSVita_GetBasePath( char *buf, const size_t buflen );
+int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv );
void PSVita_InputUpdate( void );
#endif
diff --git a/engine/platform/psvita/sce_sys/livearea/contents/template.xml b/engine/platform/psvita/sce_sys/livearea/contents/template.xml
index 1bfb8460..16ef0ae9 100644
--- a/engine/platform/psvita/sce_sys/livearea/contents/template.xml
+++ b/engine/platform/psvita/sce_sys/livearea/contents/template.xml
@@ -8,4 +8,13 @@
startup.png
+
+
+
+ psla:dev
+
+ Developer mode
+
+
+
diff --git a/engine/platform/psvita/sys_psvita.c b/engine/platform/psvita/sys_psvita.c
index 996a3686..0ed9343b 100644
--- a/engine/platform/psvita/sys_psvita.c
+++ b/engine/platform/psvita/sys_psvita.c
@@ -24,6 +24,7 @@ GNU General Public License for more details.
#include
#define DATA_PATH "data/xash3d"
+#define MAX_ARGV 5 // "" -log -dev X NULL
// 200MB libc heap, 512K main thread stack, 40MB for loading game DLLs
// the rest goes to vitaGL
@@ -75,17 +76,73 @@ const size_t __vrtld_num_exports = sizeof( aux_exports ) / sizeof( *aux_exports
/* end of export crap */
+static const char *PSVita_GetLaunchParameter( char *outbuf )
+{
+ SceAppUtilAppEventParam param;
+ memset( ¶m, 0, sizeof( param ) );
+ sceAppUtilReceiveAppEvent( ¶m );
+ if( param.type == 0x05 )
+ {
+ sceAppUtilAppEventParseLiveArea( ¶m, outbuf );
+ return outbuf;
+ }
+ return NULL;
+}
+
void Platform_ShellExecute( const char *path, const char *parms )
{
Con_Reportf( S_WARN "Tried to shell execute ;%s; -- not supported\n", path );
}
+/*
+===========
+PSVita_GetArgv
+
+On the PS Vita under normal circumstances argv is empty, so we'll construct our own
+based on which button the user pressed in the LiveArea launcher.
+===========
+*/
+int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv )
+{
+ static const char *fake_argv[MAX_ARGV] = { "app0:/eboot.bin", NULL };
+ int fake_argc = 1;
+ char tmp[2048] = { 0 };
+ SceAppUtilInitParam initParam = { 0 };
+ SceAppUtilBootParam bootParam = { 0 };
+
+ // on the Vita under normal circumstances argv is empty, unless we're launching from Change Game
+ sceAppUtilInit( &initParam, &bootParam );
+
+ if( in_argc > 1 )
+ {
+ // probably coming from Change Game, in which case we just need to keep the old args
+ *out_argv = in_argv;
+ return in_argc;
+ }
+
+ // got empty args, which means that we're probably coming from LiveArea
+ // construct argv based on which button the user pressed in the LiveArea launcher
+ if( PSVita_GetLaunchParameter( tmp ))
+ {
+ if( !Q_strcmp( tmp, "dev" ))
+ {
+ // user hit the "Developer Mode" button, inject "-log" and "-dev" arguments
+ fake_argv[fake_argc++] = "-log";
+ fake_argv[fake_argc++] = "-dev";
+ fake_argv[fake_argc++] = "2";
+ }
+ }
+
+ *out_argv = (char **)fake_argv;
+ return fake_argc;
+}
+
void PSVita_Init( void )
{
char xashdir[1024] = { 0 };
// cd to the base dir immediately for library loading to work
- if ( PSVita_GetBasePath( xashdir, sizeof( xashdir ) ) )
+ if( PSVita_GetBasePath( xashdir, sizeof( xashdir )))
{
chdir( xashdir );
}
@@ -97,7 +154,7 @@ void PSVita_Init( void )
scePowerSetGpuXbarClockFrequency( 166 );
sceSysmoduleLoadModule( SCE_SYSMODULE_NET );
- if ( vrtld_init( 0 ) < 0 )
+ if( vrtld_init( 0 ) < 0 )
{
Sys_Error( "Could not init vrtld: %s\n", vrtld_dlerror( ) );
}