From 16be481d5f6f6eb209b83daa0a456eed848ece4e Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sun, 13 Oct 2019 12:29:01 +0200 Subject: [PATCH] Added RetroArch username detection. --- code/libretro/libretro.c | 15 +- code/psp2/con_psp2.c | 63 -- code/psp2/dll_psp2.c | 218 ------- code/psp2/dll_psp2.h | 59 -- code/psp2/endian.h | 0 code/psp2/net_psp2.c | 1198 ---------------------------------- code/psp2/psp2_dll_defs.h | 78 --- code/psp2/psp2_dll_hacks.c | 93 --- code/psp2/psp2_dll_imports.h | 62 -- code/psp2/psp2_gamma.c | 33 - code/psp2/psp2_glimp.c | 182 ------ code/psp2/psp2_input.c | 274 -------- code/psp2/psp2_snd.c | 145 ---- code/psp2/sys_main.c | 511 --------------- code/psp2/sys_psp2.c | 706 -------------------- 15 files changed, 13 insertions(+), 3624 deletions(-) delete mode 100644 code/psp2/con_psp2.c delete mode 100644 code/psp2/dll_psp2.c delete mode 100644 code/psp2/dll_psp2.h delete mode 100644 code/psp2/endian.h delete mode 100644 code/psp2/net_psp2.c delete mode 100644 code/psp2/psp2_dll_defs.h delete mode 100644 code/psp2/psp2_dll_hacks.c delete mode 100644 code/psp2/psp2_dll_imports.h delete mode 100644 code/psp2/psp2_gamma.c delete mode 100644 code/psp2/psp2_glimp.c delete mode 100644 code/psp2/psp2_input.c delete mode 100644 code/psp2/psp2_snd.c delete mode 100644 code/psp2/sys_main.c delete mode 100644 code/psp2/sys_psp2.c diff --git a/code/libretro/libretro.c b/code/libretro/libretro.c index 1d0a4a8..c43ab41 100644 --- a/code/libretro/libretro.c +++ b/code/libretro/libretro.c @@ -568,7 +568,7 @@ Sys_Init void Sys_Init(void) { Cmd_AddCommand("in_restart", Sys_In_Restart_f); Cvar_Set("arch", OS_STRING " " ARCH_STRING); - Cvar_Set("username", Sys_GetCurrentUser()); + Cvar_Set("name", Sys_GetCurrentUser()); } /* @@ -1191,6 +1191,7 @@ void retro_run(void) Com_Init(commandLine); NET_Init(); update_variables(false); + Cvar_Set("name", Sys_GetCurrentUser()); first_boot = false; } @@ -1299,7 +1300,17 @@ Sys_GetCurrentUser */ char nick[128]; char *Sys_GetCurrentUser(void) { - sprintf(nick, "username"); + const char *default_username = NULL; + sprintf(nick, "UnnamedPlayer"); + + if (environ_cb(RETRO_ENVIRONMENT_GET_USERNAME, &default_username)) + { + if (default_username && default_username[0] != '\0') + { + sprintf(nick, default_username); + } + } + return nick; } diff --git a/code/psp2/con_psp2.c b/code/psp2/con_psp2.c deleted file mode 100644 index 1109448..0000000 --- a/code/psp2/con_psp2.c +++ /dev/null @@ -1,63 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include -#include "../qcommon/q_shared.h" -#include "sys_local.h" - -/* -================== -CON_Shutdown -================== -*/ -void CON_Shutdown(void) { -} - -/* -================== -CON_Init -================== -*/ -void CON_Init(void) { -} - -/* -================== -CON_Input -================== -*/ -char *CON_Input(void) { - return NULL; -} - -/* -================== -CON_Print -================== -*/ -void CON_Print(const char *msg) { -#ifndef RELEASE - FILE* f = fopen("ux0:data/ioq3/log.txt", "a+"); - fwrite(msg, 1, strlen(msg), f); - fclose(f); -#endif -} diff --git a/code/psp2/dll_psp2.c b/code/psp2/dll_psp2.c deleted file mode 100644 index 54a345b..0000000 --- a/code/psp2/dll_psp2.c +++ /dev/null @@ -1,218 +0,0 @@ -/* -dll_vita.c - libdl function wrappers for vita -Copyright (C) 2018 fgsfds - -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, either version 3 of the License, or -(at your option) any later version. - -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 for more details. -*/ - -#include "dll_psp2.h" -#include - -#define MAX_DLNAMELEN 256 - -typedef struct dll_s -{ - SceUID handle; - char name[MAX_DLNAMELEN]; - int refcnt; - dllexport_t *exp; - struct dll_s *next; -} dll_t; - -typedef struct modarg_s -{ - sysfuncs_t imports; - dllexport_t *exports; -} modarg_t; - -static sysfuncs_t sys_exports = { - // mem - malloc, - calloc, - realloc, - free, - // io - fopen, - fclose, - fseek, - ftell, - fprintf, - fread, - fwrite, - // string - sprintf, - snprintf, - vsnprintf, -}; - -static modarg_t modarg; - -static dll_t *dll_list; -static char *dll_err = NULL; -static char dll_err_buf[1024]; - -static void *dlfind( const char *name ) -{ - dll_t *d = NULL; - for( d = dll_list; d; d = d->next ) - if( !strcmp( d->name, name ) ) - break; - return d; -} - -static const char *dlname( void *handle ) -{ - dll_t *d = NULL; - // iterate through all dll_ts to check if the handle is actually in the list - // and not some bogus pointer from god knows where - for( d = dll_list; d; d = d->next ) if( d == handle ) break; - return d ? d->name : NULL; -} - -void *dlopen( const char *name, int flag ) -{ - if( !name ) return NULL; - - dll_t *old = dlfind( name ); - if( old ) { old->refcnt++; return old; } - - char fullpath[128]; - snprintf( fullpath, sizeof(fullpath), name ); - - modarg.imports = sys_exports; - modarg.exports = NULL; - - int status = 0; - modarg_t *arg = &modarg; - SceUID h = sceKernelLoadStartModule( fullpath, sizeof( arg ), &arg, 0, NULL, &status ); - - if( !h ) { dll_err = "dlopen(): something went wrong"; return NULL; } - if( h < 0 ) - { - snprintf( dll_err_buf, sizeof( dll_err_buf ), "dlopen(%s): error 0x%X\n", name, h ); - dll_err = dll_err_buf; - return NULL; - } - - if( status == SCE_KERNEL_START_FAILED || status == SCE_KERNEL_START_NO_RESIDENT ) - { - dll_err = "dlopen(): module_start() failed"; - return NULL; - } - - if( !modarg.exports ) - { - dll_err = "dlopen(): NULL exports"; - return NULL; - } - - dll_t *new = calloc( 1, sizeof( dll_t ) ); - if( !new ) { dll_err = "dlopen(): out of memory"; return NULL; } - snprintf( new->name, MAX_DLNAMELEN, name ); - new->handle = h; - new->exp = modarg.exports; - new->refcnt = 1; - - new->next = dll_list; - dll_list = new; - - return new; -} - -void *dlsym( void *handle, const char *symbol ) -{ - if( !handle || !symbol ) { dll_err = "dlsym(): NULL args"; return NULL; } - if( !dlname( handle ) ) { dll_err = "dlsym(): unknown handle"; return NULL; } - dll_t *d = handle; - if( !d->refcnt ) { dll_err = "dlsym(): call dlopen() first"; return NULL; } - dllexport_t *f = NULL; - for( f = d->exp; f && f->func; f++ ) - if( !strcmp( f->name, symbol ) ) - break; - - if( f && f->func ) - { - return f->func; - } - else - { - dll_err = "dlsym(): symbol not found in dll"; - return NULL; - } -} - -int dlclose( void *handle ) -{ - if( !handle ) { dll_err = "dlclose(): NULL arg"; return -1; } - if( !dlname( handle ) ) { dll_err = "dlclose(): unknown handle"; return -2; } - - dll_t *d = handle; - d->refcnt--; - if( d->refcnt <= 0 ) - { - int status = 0; - int ret = sceKernelStopUnloadModule( d->handle, 0, NULL, 0, NULL, &status ); - if( ret != SCE_OK ) - { - snprintf( dll_err_buf, sizeof( dll_err_buf ), "dlclose(): error %d", ret ); - dll_err = dll_err_buf; - } - else if( status == SCE_KERNEL_STOP_CANCEL ) - { - dll_err = "dlclose(): module doesn't want to stop"; - return -3; - } - - if( d == dll_list ) - dll_list = d->next; - else - for( dll_t *pd = dll_list; pd; pd = pd->next ) - { - if( pd->next == d ) - { - pd->next = d->next; - break; - } - } - - free( d ); - } - - return 0; -} - -char *dlerror( void ) -{ - char *err = dll_err; - dll_err = NULL; - return err; -} - -int dladdr( const void *addr, Dl_info *info ) -{ - dll_t *d = NULL; - dllexport_t *f = NULL; - for( d = dll_list; d; d = d->next ) - for( f = d->exp; f && f->func; f++ ) - if( f->func == addr ) goto for_end; -for_end: - if( d && f && f->func ) - { - if( info ) - { - info->dli_fhandle = d; - info->dli_sname = f->name; - info->dli_saddr = addr; - } - return 1; - } - return 0; -} diff --git a/code/psp2/dll_psp2.h b/code/psp2/dll_psp2.h deleted file mode 100644 index 53469b5..0000000 --- a/code/psp2/dll_psp2.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef DLL_VITA_H -#define DLL_VITA_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define RTLD_LAZY 0x0001 -#define RTLD_NOW 0x0002 - -typedef struct dllexport_s -{ - const char *name; - void *func; -} dllexport_t; - -typedef struct Dl_info_s -{ - void *dli_fhandle; - const char *dli_sname; - const void *dli_saddr; -} Dl_info; - -typedef struct sysfuncs_s -{ - // mem - void* (*pfnSysMalloc)(size_t); - void* (*pfnSysCalloc)(size_t, size_t); - void* (*pfnSysRealloc)(void*, size_t); - void (*pfnSysFree)(void*); - // i/o - FILE* (*pfnSysFopen)(const char*, const char*); - int (*pfnSysFclose)(FILE*); - int (*pfnSysFseek)(FILE*, long int, int); - long int (*pfnSysFtell)(FILE*); - int (*pfnSysFprintf)(FILE*, const char*, ...); - size_t (*pfnSysFread)(void*, size_t, size_t, FILE*); - size_t (*pfnSysFwrite)(const void*, size_t, size_t, FILE*); - // sprintf - int (*pfnSprintf)(char*, const char*, ...); - int (*pfnSnprintf)(char*, int, const char*, ...); - int (*pfnVsnprintf)(char*, int, const char*, va_list); -} sysfuncs_t; - -void *dlsym(void *handle, const char *symbol ); -void *dlopen(const char *name, int flag ); -int dlclose(void *handle); -char *dlerror( void ); -int dladdr( const void *addr, Dl_info *info ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/psp2/endian.h b/code/psp2/endian.h deleted file mode 100644 index e69de29..0000000 diff --git a/code/psp2/net_psp2.c b/code/psp2/net_psp2.c deleted file mode 100644 index 66aee14..0000000 --- a/code/psp2/net_psp2.c +++ /dev/null @@ -1,1198 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include "../qcommon/q_shared.h" -#include "../qcommon/qcommon.h" - -# include -# include -# include -# include -# include -# include -# include -# include - -typedef int SOCKET; -# define INVALID_SOCKET -1 -# define SOCKET_ERROR -1 -# define closesocket close -# define ioctlsocket ioctl -typedef int ioctlarg_t; -# define socketError errno - -#include -#include - -#define INADDR_BROADCAST SCE_NET_INADDR_BROADCAST -#define INADDR_ANY SCE_NET_INADDR_ANY - -struct sockaddr_storage { - uint8_t ss_len; - sa_family_t ss_family; - char ss_padding[128]; -}; - -struct addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; - -const char *gai_strerror(int errcode) { - return ""; -} - -#define NI_NUMERICHOST 0 - -static qboolean usingSocks = qfalse; -static int networkingEnabled = 0; - -static cvar_t *net_enabled; - -static cvar_t *net_socksEnabled; -static cvar_t *net_socksServer; -static cvar_t *net_socksPort; -static cvar_t *net_socksUsername; -static cvar_t *net_socksPassword; - -static cvar_t *net_ip; -static cvar_t *net_port; - -static cvar_t *net_dropsim; - -static struct sockaddr socksRelayAddr; - -static SOCKET ip_socket = INVALID_SOCKET; -static SOCKET socks_socket = INVALID_SOCKET; - -#ifndef IF_NAMESIZE -#define IF_NAMESIZE 16 -#endif - -// use an admin local address per default so that network admins can decide on how to handle quake3 traffic. -#define NET_MULTICAST_IP6 "ff04::696f:7175:616b:6533" - -#define MAX_IPS 32 - -typedef struct -{ - char ifname[IF_NAMESIZE]; - - netadrtype_t type; - sa_family_t family; - struct sockaddr_storage addr; - struct sockaddr_storage netmask; -} nip_localaddr_t; - -static nip_localaddr_t localIP[MAX_IPS]; -static int numIP; - - -//============================================================================= - - -/* -==================== -NET_ErrorString -==================== -*/ -char error[256]; -char *NET_ErrorString( void ) { - sprintf(error, "sceNet returned 0x%08X", socketError); - return error; -} - -static void NetadrToSockadr( netadr_t *a, struct sockaddr *s ) { - if( a->type == NA_BROADCAST ) { - ((struct sockaddr_in *)s)->sin_family = AF_INET; - ((struct sockaddr_in *)s)->sin_port = a->port; - ((struct sockaddr_in *)s)->sin_addr.s_addr = INADDR_BROADCAST; - } - else if( a->type == NA_IP ) { - ((struct sockaddr_in *)s)->sin_family = AF_INET; - ((struct sockaddr_in *)s)->sin_addr.s_addr = *(int *)&a->ip; - ((struct sockaddr_in *)s)->sin_port = a->port; - } -} - - -static void SockadrToNetadr( struct sockaddr *s, netadr_t *a ) { - if (s->sa_family == AF_INET) { - a->type = NA_IP; - *(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr; - a->port = ((struct sockaddr_in *)s)->sin_port; - } -} - - -static struct addrinfo *SearchAddrInfo(struct addrinfo *hints, sa_family_t family) -{ - while(hints) - { - if(hints->ai_family == family) - return hints; - - hints = hints->ai_next; - } - - return NULL; -} - -static inline in_addr_t inet_addr( const char *cp ) -{ - int32_t b1, b2, b3, b4; - int res = sscanf( cp, "%d.%d.%d.%d", &b1, &b2, &b3, &b4 ); - if( res != 4 ) return (in_addr_t)(-1); // is actually expected behavior - return htonl( (b1 << 24) | (b2 << 16) | (b3 << 8) | b4 ); -} - -/* -============= -Sys_StringToSockaddr -============= -*/ -static qboolean Sys_StringToSockaddr(const char *s, struct sockaddr *sadr, int sadr_len, sa_family_t family) -{ - struct hostent *h; - //char *colon; // bk001204 - unused - - memset (sadr, 0, sizeof(*sadr)); - ((struct sockaddr_in *)sadr)->sin_family = AF_INET; - - ((struct sockaddr_in *)sadr)->sin_port = 0; - - if ( s[0] >= '0' && s[0] <= '9') - { - *(int *)&((struct sockaddr_in *)sadr)->sin_addr = inet_addr(s); - } - else - { - if (! (h = gethostbyname(s)) ) - return qfalse; - *(int *)&((struct sockaddr_in *)sadr)->sin_addr = *(int *)h->h_addr_list[0]; - } - - return qtrue; -} - -/* -============= -Sys_SockaddrToString -============= -*/ -static void Sys_SockaddrToString(char *dest, int destlen, struct sockaddr *input) -{ - int haddr = sceNetNtohl(((struct sockaddr_in *)input)->sin_addr.s_addr); - - sprintf(dest, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff, (haddr >> 16) & 0xff, (haddr >> 8) & 0xff, haddr & 0xff, sceNetNtohs(((struct sockaddr_in *)input)->sin_port)); - -} - -/* -============= -Sys_StringToAdr -============= -*/ -qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family ) { - struct sockaddr_storage sadr; - sa_family_t fam; - - switch(family) - { - case NA_IP: - fam = AF_INET; - break; - default: - fam = AF_UNSPEC; - break; - } - if( !Sys_StringToSockaddr(s, (struct sockaddr *) &sadr, sizeof(sadr), fam ) ) { - return qfalse; - } - - SockadrToNetadr( (struct sockaddr *) &sadr, a ); - return qtrue; -} - -/* -=================== -NET_CompareBaseAdrMask - -Compare without port, and up to the bit number given in netmask. -=================== -*/ -qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask) -{ - byte cmpmask, *addra, *addrb; - int curbyte; - - if (a.type != b.type) - return qfalse; - - if (a.type == NA_LOOPBACK) - return qtrue; - - if(a.type == NA_IP) - { - addra = (byte *) &a.ip; - addrb = (byte *) &b.ip; - - if(netmask < 0 || netmask > 32) - netmask = 32; - } - else - { - Com_Printf ("NET_CompareBaseAdr: bad address type\n"); - return qfalse; - } - - curbyte = netmask >> 3; - - if(curbyte && memcmp(addra, addrb, curbyte)) - return qfalse; - - netmask &= 0x07; - if(netmask) - { - cmpmask = (1 << netmask) - 1; - cmpmask <<= 8 - netmask; - - if((addra[curbyte] & cmpmask) == (addrb[curbyte] & cmpmask)) - return qtrue; - } - else - return qtrue; - - return qfalse; -} - - -/* -=================== -NET_CompareBaseAdr - -Compares without the port -=================== -*/ -qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b) -{ - return NET_CompareBaseAdrMask(a, b, -1); -} - -const char *NET_AdrToString (netadr_t a) -{ - static char s[NET_ADDRSTRMAXLEN]; - - if (a.type == NA_LOOPBACK) - Com_sprintf (s, sizeof(s), "loopback"); - else if (a.type == NA_BOT) - Com_sprintf (s, sizeof(s), "bot"); - else if (a.type == NA_IP) - { - struct sockaddr_storage sadr; - - memset(&sadr, 0, sizeof(sadr)); - NetadrToSockadr(&a, (struct sockaddr *) &sadr); - Sys_SockaddrToString(s, sizeof(s), (struct sockaddr *) &sadr); - } - - return s; -} - -const char *NET_AdrToStringwPort (netadr_t a) -{ - static char s[NET_ADDRSTRMAXLEN]; - - if (a.type == NA_LOOPBACK) - Com_sprintf (s, sizeof(s), "loopback"); - else if (a.type == NA_BOT) - Com_sprintf (s, sizeof(s), "bot"); - else if(a.type == NA_IP) - Com_sprintf(s, sizeof(s), "%s:%hu", NET_AdrToString(a), ntohs(a.port)); - - return s; -} - - -qboolean NET_CompareAdr (netadr_t a, netadr_t b) -{ - if(!NET_CompareBaseAdr(a, b)) - return qfalse; - - if (a.type == NA_IP) - { - if (a.port == b.port) - return qtrue; - } - else - return qtrue; - - return qfalse; -} - - -qboolean NET_IsLocalAddress( netadr_t adr ) { - return adr.type == NA_LOOPBACK; -} - -//============================================================================= - -/* -================== -NET_GetPacket - -Receive one packet -================== -*/ -qboolean NET_GetPacket(netadr_t *net_from, msg_t *net_message, fd_set *fdr) -{ - int ret; - struct sockaddr_storage from; - socklen_t fromlen; - int err; - - if(ip_socket != INVALID_SOCKET && FD_ISSET(ip_socket, fdr)) - { - fromlen = sizeof(from); - ret = recvfrom( ip_socket, (void *)net_message->data, net_message->maxsize, 0, (struct sockaddr *) &from, &fromlen ); - - if (ret == SOCKET_ERROR) - { - err = socketError; - - if( err != SCE_NET_EAGAIN && err != SCE_NET_ECONNRESET && err < 0 ) - Com_Printf( "NET_GetPacket: %s\n", NET_ErrorString() ); - } - else - { - - memset( ((struct sockaddr_in *)&from)->sin_zero, 0, 8 ); - - if ( usingSocks && memcmp( &from, &socksRelayAddr, fromlen ) == 0 ) { - if ( ret < 10 || net_message->data[0] != 0 || net_message->data[1] != 0 || net_message->data[2] != 0 || net_message->data[3] != 1 ) { - return qfalse; - } - net_from->type = NA_IP; - net_from->ip[0] = net_message->data[4]; - net_from->ip[1] = net_message->data[5]; - net_from->ip[2] = net_message->data[6]; - net_from->ip[3] = net_message->data[7]; - net_from->port = *(short *)&net_message->data[8]; - net_message->readcount = 10; - } - else { - SockadrToNetadr( (struct sockaddr *) &from, net_from ); - net_message->readcount = 0; - } - - if( ret >= net_message->maxsize ) { - Com_Printf( "Oversize packet from %s\n", NET_AdrToString (*net_from) ); - return qfalse; - } - - net_message->cursize = ret; - return qtrue; - } - } - - return qfalse; -} - -//============================================================================= - -static char socksBuf[4096]; - -/* -================== -Sys_SendPacket -================== -*/ -void Sys_SendPacket( int length, const void *data, netadr_t to ) { - int ret = SOCKET_ERROR; - struct sockaddr_storage addr; - - if( to.type != NA_BROADCAST && to.type != NA_IP && to.type != NA_IP6 && to.type != NA_MULTICAST6) - { - Com_Error( ERR_FATAL, "Sys_SendPacket: bad address type" ); - return; - } - - if( (ip_socket == INVALID_SOCKET && to.type == NA_IP) || - (ip_socket == INVALID_SOCKET && to.type == NA_BROADCAST) ) - return; - - if(to.type == NA_MULTICAST6 && (net_enabled->integer & NET_DISABLEMCAST)) - return; - - memset(&addr, 0, sizeof(addr)); - NetadrToSockadr( &to, (struct sockaddr *) &addr ); - - if( usingSocks && to.type == NA_IP ) { - socksBuf[0] = 0; // reserved - socksBuf[1] = 0; - socksBuf[2] = 0; // fragment (not fragmented) - socksBuf[3] = 1; // address type: IPV4 - *(int *)&socksBuf[4] = ((struct sockaddr_in *)&addr)->sin_addr.s_addr; - *(short *)&socksBuf[8] = ((struct sockaddr_in *)&addr)->sin_port; - memcpy( &socksBuf[10], data, length ); - ret = sendto( ip_socket, socksBuf, length+10, 0, &socksRelayAddr, sizeof(socksRelayAddr) ); - } - else { - if(addr.ss_family == AF_INET) - ret = sendto( ip_socket, data, length, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in) ); - } - if( ret == SOCKET_ERROR ) { - int err = socketError; - - // wouldblock is silent - if( err == SCE_NET_EAGAIN ) { - return; - } - - // some PPP links do not allow broadcasts and return an error - if( ( err == SCE_NET_EADDRNOTAVAIL ) && ( ( to.type == NA_BROADCAST ) ) ) { - return; - } - - Com_Printf( "Sys_SendPacket: %s\n", NET_ErrorString() ); - } -} - - -//============================================================================= - -/* -================== -Sys_IsLANAddress - -LAN clients will have their rate var ignored -================== -*/ -qboolean Sys_IsLANAddress( netadr_t adr ) { - int index, run, addrsize; - qboolean differed; - byte *compareadr, *comparemask, *compareip; - - if( adr.type == NA_LOOPBACK ) { - return qtrue; - } - - if( adr.type == NA_IP ) - { - // RFC1918: - // 10.0.0.0 - 10.255.255.255 (10/8 prefix) - // 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) - // 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) - if(adr.ip[0] == 10) - return qtrue; - if(adr.ip[0] == 172 && (adr.ip[1]&0xf0) == 16) - return qtrue; - if(adr.ip[0] == 192 && adr.ip[1] == 168) - return qtrue; - - if(adr.ip[0] == 127) - return qtrue; - } - - // Now compare against the networks this computer is member of. - for(index = 0; index < numIP; index++) - { - if(localIP[index].type == adr.type) - { - if(adr.type == NA_IP) - { - compareip = (byte *) &((struct sockaddr_in *) &localIP[index].addr)->sin_addr.s_addr; - comparemask = (byte *) &((struct sockaddr_in *) &localIP[index].netmask)->sin_addr.s_addr; - compareadr = adr.ip; - - addrsize = sizeof(adr.ip); - } - - differed = qfalse; - for(run = 0; run < addrsize; run++) - { - if((compareip[run] & comparemask[run]) != (compareadr[run] & comparemask[run])) - { - differed = qtrue; - break; - } - } - - if(!differed) - return qtrue; - - } - } - - return qfalse; -} - -/* -================== -Sys_ShowIP -================== -*/ -void Sys_ShowIP(void) { - int i; - char addrbuf[NET_ADDRSTRMAXLEN]; - - for(i = 0; i < numIP; i++) - { - Sys_SockaddrToString(addrbuf, sizeof(addrbuf), (struct sockaddr *) &localIP[i].addr); - - if(localIP[i].type == NA_IP) - Com_Printf( "IP: %s\n", addrbuf); - } -} - - -//============================================================================= - - -/* -==================== -NET_IPSocket -==================== -*/ -SOCKET NET_IPSocket( char *net_interface, int port, int *err ) { - - SOCKET newsocket; - struct sockaddr_in address; - ioctlarg_t _true = 1; - int i = 1; - - *err = 0; - - if( net_interface ) { - Com_Printf( "Opening IP socket: %s:%i\n", net_interface, port ); - } - else { - Com_Printf( "Opening IP socket: 0.0.0.0:%i\n", port ); - } - - if( ( newsocket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) == INVALID_SOCKET ) { - *err = socketError; - Com_Printf( "WARNING: NET_IPSocket: socket: %s\n", NET_ErrorString() ); - return newsocket; - } - - // make it non-blocking - setsockopt(newsocket, SOL_SOCKET, SO_NONBLOCK, (char *)&_true, sizeof(_true)); - - // make it broadcast capable - if( setsockopt( newsocket, SOL_SOCKET, SO_BROADCAST, (char *) &i, sizeof(i) ) == SOCKET_ERROR ) { - Com_Printf( "WARNING: NET_IPSocket: setsockopt SO_BROADCAST: %s\n", NET_ErrorString() ); - } - - if( !net_interface || !net_interface[0]) { - address.sin_family = AF_INET; - address.sin_addr.s_addr = INADDR_ANY; - } - else - { - if(!Sys_StringToSockaddr( net_interface, (struct sockaddr *)&address, sizeof(address), AF_INET)) - { - closesocket(newsocket); - return INVALID_SOCKET; - } - } - - if( port == PORT_ANY ) { - address.sin_port = 0; - } - else { - address.sin_port = htons( (short)port ); - } - - if( bind( newsocket, (void *)&address, sizeof(address) ) == SOCKET_ERROR ) { - Com_Printf( "WARNING: NET_IPSocket: bind: %s\n", NET_ErrorString() ); - *err = socketError; - closesocket( newsocket ); - return INVALID_SOCKET; - } - - return newsocket; -} - -/* -==================== -NET_OpenSocks -==================== -*/ -void NET_OpenSocks( int port ) { - struct sockaddr_in address; - struct hostent *h; - int len; - qboolean rfc1929; - unsigned char buf[64]; - - usingSocks = qfalse; - - Com_Printf( "Opening connection to SOCKS server.\n" ); - - if ( ( socks_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) == INVALID_SOCKET ) { - Com_Printf( "WARNING: NET_OpenSocks: socket: %s\n", NET_ErrorString() ); - return; - } - - h = gethostbyname( net_socksServer->string ); - if ( h == NULL ) { - Com_Printf( "WARNING: NET_OpenSocks: gethostbyname: %s\n", NET_ErrorString() ); - return; - } - if ( h->h_addrtype != AF_INET ) { - Com_Printf( "WARNING: NET_OpenSocks: gethostbyname: address type was not AF_INET\n" ); - return; - } - address.sin_family = AF_INET; - address.sin_addr.s_addr = *(int *)h->h_addr_list[0]; - address.sin_port = htons( (short)net_socksPort->integer ); - - if ( connect( socks_socket, (struct sockaddr *)&address, sizeof( address ) ) == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: connect: %s\n", NET_ErrorString() ); - return; - } - - // send socks authentication handshake - if ( *net_socksUsername->string || *net_socksPassword->string ) { - rfc1929 = qtrue; - } - else { - rfc1929 = qfalse; - } - - buf[0] = 5; // SOCKS version - // method count - if ( rfc1929 ) { - buf[1] = 2; - len = 4; - } - else { - buf[1] = 1; - len = 3; - } - buf[2] = 0; // method #1 - method id #00: no authentication - if ( rfc1929 ) { - buf[2] = 2; // method #2 - method id #02: username/password - } - if ( send( socks_socket, (void *)buf, len, 0 ) == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() ); - return; - } - - // get the response - len = recv( socks_socket, (void *)buf, 64, 0 ); - if ( len == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() ); - return; - } - if ( len != 2 || buf[0] != 5 ) { - Com_Printf( "NET_OpenSocks: bad response\n" ); - return; - } - switch( buf[1] ) { - case 0: // no authentication - break; - case 2: // username/password authentication - break; - default: - Com_Printf( "NET_OpenSocks: request denied\n" ); - return; - } - - // do username/password authentication if needed - if ( buf[1] == 2 ) { - int ulen; - int plen; - - // build the request - ulen = strlen( net_socksUsername->string ); - plen = strlen( net_socksPassword->string ); - - buf[0] = 1; // username/password authentication version - buf[1] = ulen; - if ( ulen ) { - memcpy( &buf[2], net_socksUsername->string, ulen ); - } - buf[2 + ulen] = plen; - if ( plen ) { - memcpy( &buf[3 + ulen], net_socksPassword->string, plen ); - } - - // send it - if ( send( socks_socket, (void *)buf, 3 + ulen + plen, 0 ) == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() ); - return; - } - - // get the response - len = recv( socks_socket, (void *)buf, 64, 0 ); - if ( len == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() ); - return; - } - if ( len != 2 || buf[0] != 1 ) { - Com_Printf( "NET_OpenSocks: bad response\n" ); - return; - } - if ( buf[1] != 0 ) { - Com_Printf( "NET_OpenSocks: authentication failed\n" ); - return; - } - } - - // send the UDP associate request - buf[0] = 5; // SOCKS version - buf[1] = 3; // command: UDP associate - buf[2] = 0; // reserved - buf[3] = 1; // address type: IPV4 - *(int *)&buf[4] = INADDR_ANY; - *(short *)&buf[8] = htons( (short)port ); // port - if ( send( socks_socket, (void *)buf, 10, 0 ) == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() ); - return; - } - - // get the response - len = recv( socks_socket, (void *)buf, 64, 0 ); - if( len == SOCKET_ERROR ) { - Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() ); - return; - } - if( len < 2 || buf[0] != 5 ) { - Com_Printf( "NET_OpenSocks: bad response\n" ); - return; - } - // check completion code - if( buf[1] != 0 ) { - Com_Printf( "NET_OpenSocks: request denied: %i\n", buf[1] ); - return; - } - if( buf[3] != 1 ) { - Com_Printf( "NET_OpenSocks: relay address is not IPV4: %i\n", buf[3] ); - return; - } - ((struct sockaddr_in *)&socksRelayAddr)->sin_family = AF_INET; - ((struct sockaddr_in *)&socksRelayAddr)->sin_addr.s_addr = *(int *)&buf[4]; - ((struct sockaddr_in *)&socksRelayAddr)->sin_port = *(short *)&buf[8]; - memset( ((struct sockaddr_in *)&socksRelayAddr)->sin_zero, 0, 8 ); - - usingSocks = qtrue; -} - - -/* -===================== -NET_AddLocalAddress -===================== -*/ -static void NET_AddLocalAddress(char *ifname, struct sockaddr *addr, struct sockaddr *netmask) -{ - int addrlen; - sa_family_t family; - - // only add addresses that have all required info. - if(!addr || !netmask || !ifname) - return; - - family = addr->sa_family; - - if(numIP < MAX_IPS) - { - if(family == AF_INET) - { - addrlen = sizeof(struct sockaddr_in); - localIP[numIP].type = NA_IP; - } - else - return; - - Q_strncpyz(localIP[numIP].ifname, ifname, sizeof(localIP[numIP].ifname)); - - localIP[numIP].family = family; - - memcpy(&localIP[numIP].addr, addr, addrlen); - memcpy(&localIP[numIP].netmask, netmask, addrlen); - - numIP++; - } -} - -static unsigned long myAddr; -static void NET_GetLocalAddress( void ) { - char hostname[256]; - struct addrinfo hint; - struct addrinfo *res = NULL; - - numIP = 0; - - SceNetCtlInfo info; - sceNetCtlInetGetInfo(SCE_NETCTL_INFO_GET_IP_ADDRESS, &info); - sceNetInetPton(SCE_NET_AF_INET, info.ip_address, &myAddr); - - //->Com_Printf( "Hostname: %s\n", hostname ); - - memset(&hint, 0, sizeof(hint)); - - hint.ai_family = AF_UNSPEC; - hint.ai_socktype = SOCK_DGRAM; - - - - //if(!getaddrinfo(hostname, NULL, &hint, &res)) - { - struct sockaddr_in mask4; - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_port = 5000; - addr.sin_addr.s_addr = myAddr; - - /* On operating systems where it's more difficult to find out the configured interfaces, we'll just assume a - * netmask with all bits set. */ - - memset(&mask4, 0, sizeof(mask4)); - mask4.sin_family = AF_INET; - memset(&mask4.sin_addr.s_addr, 0xFF, sizeof(mask4.sin_addr.s_addr)); - - // add all IPs from returned list. - NET_AddLocalAddress("", (struct sockaddr*)&addr, (struct sockaddr *) &mask4); - - Sys_ShowIP(); - } - -} - -/* -==================== -NET_OpenIP -==================== -*/ -void NET_OpenIP( void ) { - int i; - int err; - int port; - int port6; - - port = net_port->integer; - - NET_GetLocalAddress(); - - // automatically scan for a valid port, so multiple - // dedicated servers can be started without requiring - // a different net_port for each one - - if(net_enabled->integer & NET_ENABLEV4) - { - for( i = 0 ; i < 10 ; i++ ) { - ip_socket = NET_IPSocket( net_ip->string, port + i, &err ); - if (ip_socket != INVALID_SOCKET) { - Cvar_SetValue( "net_port", port + i ); - - if (net_socksEnabled->integer) - NET_OpenSocks( port + i ); - - break; - } - else - { - if(err == SCE_NET_EAFNOSUPPORT) - break; - } - } - - if(ip_socket == INVALID_SOCKET) - Com_Printf( "WARNING: Couldn't bind to a v4 ip address.\n"); - } -} - - -//=================================================================== - - -/* -==================== -NET_GetCvars -==================== -*/ -static qboolean NET_GetCvars( void ) { - int modified; - -#ifdef DEDICATED - // I want server owners to explicitly turn on ipv6 support. - net_enabled = Cvar_Get( "net_enabled", "1", CVAR_LATCH | CVAR_ARCHIVE ); -#else - /* End users have it enabled so they can connect to ipv6-only hosts, but ipv4 will be - * used if available due to ping */ - net_enabled = Cvar_Get( "net_enabled", "3", CVAR_LATCH | CVAR_ARCHIVE ); -#endif - modified = net_enabled->modified; - net_enabled->modified = qfalse; - - net_ip = Cvar_Get( "net_ip", "0.0.0.0", CVAR_LATCH ); - modified += net_ip->modified; - net_ip->modified = qfalse; - - net_port = Cvar_Get( "net_port", va( "%i", PORT_SERVER ), CVAR_LATCH ); - modified += net_port->modified; - net_port->modified = qfalse; - - net_socksEnabled = Cvar_Get( "net_socksEnabled", "0", CVAR_LATCH | CVAR_ARCHIVE ); - modified += net_socksEnabled->modified; - net_socksEnabled->modified = qfalse; - - net_socksServer = Cvar_Get( "net_socksServer", "", CVAR_LATCH | CVAR_ARCHIVE ); - modified += net_socksServer->modified; - net_socksServer->modified = qfalse; - - net_socksPort = Cvar_Get( "net_socksPort", "1080", CVAR_LATCH | CVAR_ARCHIVE ); - modified += net_socksPort->modified; - net_socksPort->modified = qfalse; - - net_socksUsername = Cvar_Get( "net_socksUsername", "", CVAR_LATCH | CVAR_ARCHIVE ); - modified += net_socksUsername->modified; - net_socksUsername->modified = qfalse; - - net_socksPassword = Cvar_Get( "net_socksPassword", "", CVAR_LATCH | CVAR_ARCHIVE ); - modified += net_socksPassword->modified; - net_socksPassword->modified = qfalse; - - net_dropsim = Cvar_Get("net_dropsim", "", CVAR_TEMP); - - return modified ? qtrue : qfalse; -} - - -/* -==================== -NET_Config -==================== -*/ -void NET_Config( qboolean enableNetworking ) { - qboolean modified; - qboolean stop; - qboolean start; - - // get any latched changes to cvars - modified = NET_GetCvars(); - - if( !net_enabled->integer ) { - enableNetworking = 0; - } - - // if enable state is the same and no cvars were modified, we have nothing to do - if( enableNetworking == networkingEnabled && !modified ) { - return; - } - - if( enableNetworking == networkingEnabled ) { - if( enableNetworking ) { - stop = qtrue; - start = qtrue; - } - else { - stop = qfalse; - start = qfalse; - } - } - else { - if( enableNetworking ) { - stop = qfalse; - start = qtrue; - } - else { - stop = qtrue; - start = qfalse; - } - networkingEnabled = enableNetworking; - } - - if( stop ) { - if ( ip_socket != INVALID_SOCKET ) { - closesocket( ip_socket ); - ip_socket = INVALID_SOCKET; - } - - if ( socks_socket != INVALID_SOCKET ) { - closesocket( socks_socket ); - socks_socket = INVALID_SOCKET; - } - - } - - if( start ) - { - if (net_enabled->integer) - { - NET_OpenIP(); - } - } -} - - -/* -==================== -NET_Init -==================== -*/ -static void *net_memory = NULL; -#define NET_INIT_SIZE 1*1024*1024 -void NET_Init( void ) { - - sceSysmoduleLoadModule(SCE_SYSMODULE_NET); - sceSysmoduleLoadModule(SCE_SYSMODULE_HTTP); - SceNetInitParam initparam; - int ret = sceNetShowNetstat(); - if (ret == SCE_NET_ERROR_ENOTINIT) { - net_memory = malloc(NET_INIT_SIZE); - - initparam.memory = net_memory; - initparam.size = NET_INIT_SIZE; - initparam.flags = 0; - - ret = sceNetInit(&initparam); - - } - ret = sceNetCtlInit(); - if (ret < 0){ - sceNetTerm(); - free(net_memory); - net_memory = NULL; - } - - NET_Config( qtrue ); - - Cmd_AddCommand ("net_restart", NET_Restart_f); -} - - -/* -==================== -NET_Shutdown -==================== -*/ -void NET_Shutdown( void ) { - if ( !networkingEnabled ) { - return; - } - - NET_Config( qfalse ); - - sceNetCtlTerm(); - sceNetTerm(); - if (net_memory) free(net_memory); - net_memory = NULL; - sceSysmoduleUnloadModule(SCE_SYSMODULE_HTTP); - sceSysmoduleUnloadModule(SCE_SYSMODULE_NET); -} - -/* -==================== -NET_Event - -Called from NET_Sleep which uses select() to determine which sockets have seen action. -==================== -*/ - -void NET_Event(fd_set *fdr) -{ - byte bufData[MAX_MSGLEN + 1]; - netadr_t from = {0}; - msg_t netmsg; - - while(1) - { - MSG_Init(&netmsg, bufData, sizeof(bufData)); - - if(NET_GetPacket(&from, &netmsg, fdr)) - { - if(net_dropsim->value > 0.0f && net_dropsim->value <= 100.0f) - { - // com_dropsim->value percent of incoming packets get dropped. - if(rand() < (int) (((double) RAND_MAX) / 100.0 * (double) net_dropsim->value)) - continue; // drop this packet - } - - if(com_sv_running->integer) - Com_RunAndTimeServerPacket(&from, &netmsg); - else - CL_PacketEvent(from, &netmsg); - } - else - break; - } -} - -/* -==================== -NET_Sleep - -Sleeps msec or until something happens on the network -==================== -*/ -void NET_Sleep(int msec) -{ - struct timeval timeout; - fd_set fdr; - int retval; - SOCKET highestfd = INVALID_SOCKET; - - if(msec < 0) - msec = 0; - - FD_ZERO(&fdr); - - if(ip_socket != INVALID_SOCKET) - { - FD_SET(ip_socket, &fdr); - - highestfd = ip_socket; - } - - timeout.tv_sec = msec/1000; - timeout.tv_usec = (msec%1000)*1000; - - retval = select(highestfd + 1, &fdr, NULL, NULL, &timeout); - - if(retval == SOCKET_ERROR) - Com_Printf("Warning: select() syscall failed: %s\n", NET_ErrorString()); - else if(retval > 0) - NET_Event(&fdr); -} - -/* -==================== -NET_Restart_f -==================== -*/ -void NET_Restart_f(void) -{ - NET_Config(qtrue); -} - -void NET_JoinMulticast6(void) {} -void NET_LeaveMulticast6() {} diff --git a/code/psp2/psp2_dll_defs.h b/code/psp2/psp2_dll_defs.h deleted file mode 100644 index ddcd74e..0000000 --- a/code/psp2/psp2_dll_defs.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#ifndef _VITA_DEFS_H -#define _VITA_DEFS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "psp2_dll_imports.h" - -#define DEFAULT_BASEDIR "ux0:/data/iortcw" - -#ifndef PATH_MAX -#define PATH_MAX 256 -#endif - -#undef mkdir -#define mkdir( path, mode ) sceIoMkdir( (path), (mode) ) -#define _snprintf snprintf -#define _sprintf sprintf - -// HACK: don't use actual libc functions for mem and io -#undef malloc -#undef calloc -#undef realloc -#undef free -#undef fopen -#undef fclose -#undef fseek -#undef ftell -#undef fread -#undef fwrite -#undef fprintf -#undef sprintf -#undef snprintf -#undef vsnprintf -#undef _vsnprintf - -#define malloc SYS_MALLOC -#define calloc SYS_CALLOC -#define realloc SYS_REALLOC -#define free( x ) SYS_FREE( x ) -#define fopen SYS_FOPEN -#define fclose SYS_FCLOSE -#define fseek SYS_FSEEK -#define ftell SYS_FTELL -#define fread SYS_FREAD -#define fwrite SYS_FWRITE -#define fprintf SYS_FPRINTF -#define sprintf SYS_SPRINTF -#define snprintf SYS_SNPRINTF -#define vsnprintf SYS_VSNPRINTF -#define _vsnprintf vsnprintf - -typedef struct dllexport_s -{ - const char *name; - void *func; -} dllexport_t; - -extern dllexport_t psp2_exports[]; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/psp2/psp2_dll_hacks.c b/code/psp2/psp2_dll_hacks.c deleted file mode 100644 index 868bbf6..0000000 --- a/code/psp2/psp2_dll_hacks.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include -#include - -void* __dso_handle = (void*) &__dso_handle; - -extern void _init_vita_reent( void ); -extern void _free_vita_reent( void ); -extern void _init_vita_heap( void ); -extern void _free_vita_heap( void ); - -extern void __libc_init_array( void ); -extern void __libc_fini_array( void ); - -void _init_vita_newlib( void ) -{ - _init_vita_heap( ); - _init_vita_reent( ); -} - -void _free_vita_newlib( void ) -{ - _free_vita_reent( ); - _free_vita_heap( ); -} - -void _fini( void ) { } -void _init( void ) { } - -// small heap for internal libc use -unsigned int _newlib_heap_size_user = 2 * 1024 * 1024; - -////////////////////////////////////// - -typedef struct modarg_s -{ - sysfuncs_t imports; - dllexport_t *exports; -} modarg_t; - -extern void dllEntry( intptr_t (*syscallptr)( intptr_t arg,... ) ); -extern intptr_t vmMain( intptr_t command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7, intptr_t arg8, intptr_t arg9, intptr_t arg10, intptr_t arg11 ); - -dllexport_t psp2_exports[] = -{ - { "dllEntry", (void*)dllEntry }, - { "vmMain", (void*)vmMain }, - { NULL, NULL }, -}; - -int module_stop( SceSize argc, const void *args ) -{ - __libc_fini_array( ); - _free_vita_newlib( ); - return SCE_KERNEL_STOP_SUCCESS; -} - -int module_exit( ) -{ - __libc_fini_array( ); - _free_vita_newlib( ); - return SCE_KERNEL_STOP_SUCCESS; -} - -sysfuncs_t g_engsysfuncs; - -#ifdef GAMEDLL -typedef struct { - char *funcStr; - uint8_t *funcPtr; -} funcList_t; - -extern funcList_t funcList[]; -#endif - -void _start() __attribute__ ((weak, alias ("module_start"))); -int module_start( SceSize argc, void *args ) -{ - _init_vita_newlib( ); - __libc_init_array( ); - - modarg_t *arg = *(modarg_t **)args; - arg->exports = psp2_exports; - g_engsysfuncs = arg->imports; - -#ifdef GAMEDLL - // HACK - funcList[14].funcPtr = (void*)g_engsysfuncs.pfnSnprintf; -#endif - - return SCE_KERNEL_START_SUCCESS; -} diff --git a/code/psp2/psp2_dll_imports.h b/code/psp2/psp2_dll_imports.h deleted file mode 100644 index fbb7580..0000000 --- a/code/psp2/psp2_dll_imports.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#ifndef _SYSFUNCS_H -#define _SYSFUNCS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include -#include -#include -#include - -typedef struct sysfuncs_s -{ - // mem - void* (*pfnSysMalloc)(size_t); - void* (*pfnSysCalloc)(size_t, size_t); - void* (*pfnSysRealloc)(void*, size_t); - void (*pfnSysFree)(void*); - // i/o - FILE* (*pfnSysFopen)(const char*, const char*); - int (*pfnSysFclose)(FILE*); - int (*pfnSysFseek)(FILE*, long int, int); - long int (*pfnSysFtell)(FILE*); - int (*pfnSysFprintf)(FILE*, const char*, ...); - size_t (*pfnSysFread)(void*, size_t, size_t, FILE*); - size_t (*pfnSysFwrite)(const void*, size_t, size_t, FILE*); - // sprintf - int (*pfnSprintf)(char*, const char*, ...); - int (*pfnSnprintf)(char*, int, const char*, ...); - int (*pfnVsnprintf)(char*, int, const char*, va_list); -} sysfuncs_t; - -extern sysfuncs_t g_engsysfuncs; - -// needed because we don't want to use a new heap for each dll -#define SYS_MALLOC (*g_engsysfuncs.pfnSysMalloc) -#define SYS_CALLOC (*g_engsysfuncs.pfnSysCalloc) -#define SYS_REALLOC (*g_engsysfuncs.pfnSysRealloc) -#define SYS_FREE (*g_engsysfuncs.pfnSysFree) - -#define SYS_FOPEN (*g_engsysfuncs.pfnSysFopen) -#define SYS_FCLOSE (*g_engsysfuncs.pfnSysFclose) -#define SYS_FSEEK (*g_engsysfuncs.pfnSysFseek) -#define SYS_FTELL (*g_engsysfuncs.pfnSysFtell) -#define SYS_FPRINTF (*g_engsysfuncs.pfnSysFprintf) -#define SYS_FREAD (*g_engsysfuncs.pfnSysFread) -#define SYS_FWRITE (*g_engsysfuncs.pfnSysFwrite) - -#define SYS_SPRINTF (*g_engsysfuncs.pfnSprintf) -#define SYS_SNPRINTF (*g_engsysfuncs.pfnSnprintf) -#define SYS_VSNPRINTF (*g_engsysfuncs.pfnVsnprintf) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/psp2/psp2_gamma.c b/code/psp2/psp2_gamma.c deleted file mode 100644 index 7d674ec..0000000 --- a/code/psp2/psp2_gamma.c +++ /dev/null @@ -1,33 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include "../renderercommon/tr_common.h" -#include "../qcommon/qcommon.h" - -/* -================= -GLimp_SetGamma -================= -*/ -void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) -{ -} diff --git a/code/psp2/psp2_glimp.c b/code/psp2/psp2_glimp.c deleted file mode 100644 index 8542eae..0000000 --- a/code/psp2/psp2_glimp.c +++ /dev/null @@ -1,182 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include -#include -#include -#include - -#include "../renderercommon/tr_common.h" -#include "../sys/sys_local.h" - -#include -#include "vitaGL.h" - -/* -=============== -GLimp_Shutdown -=============== -*/ -void GLimp_Shutdown( void ) -{ - ri.IN_Shutdown(); -} - -/* -=============== -GLimp_Minimize - -Minimize the game so that user is back at the desktop -=============== -*/ -void GLimp_Minimize( void ) -{ -} - - -/* -=============== -GLimp_LogComment -=============== -*/ -extern void log2file(const char *format, ...); -void GLimp_LogComment( char *comment ) -{ -#ifndef RELEASE - log2file(comment); -#endif -} - -#define R_MODE_FALLBACK 3 // 640 * 480 - -/* -=============== -GLimp_Init - -This routine is responsible for initializing the OS specific portions -of OpenGL -=============== -*/ -uint16_t* indices; -float *gVertexBuffer; -uint8_t *gColorBuffer; -uint8_t *gColorBuffer255; -float *gTexCoordBuffer; -float *gVertexBufferPtr; -uint8_t *gColorBufferPtr; -float *gTexCoordBufferPtr; -uint8_t inited = 0; - -typedef struct vidmode_s -{ - const char *description; - int width, height; - float pixelAspect; // pixel width / height -} vidmode_t; -extern vidmode_t r_vidModes[]; - -uint32_t cur_width; - -void GLimp_Init( qboolean coreContext) -{ - - if (r_mode->integer < 0) r_mode->integer = 3; - - glConfig.vidWidth = r_vidModes[r_mode->integer].width; - glConfig.vidHeight = r_vidModes[r_mode->integer].height; - glConfig.colorBits = 32; - glConfig.depthBits = 32; - glConfig.stencilBits = 8; - glConfig.displayFrequency = 60; - glConfig.stereoEnabled = qfalse; - - glConfig.driverType = GLDRV_ICD; - glConfig.hardwareType = GLHW_GENERIC; - glConfig.deviceSupportsGamma = qfalse; - glConfig.textureCompression = TC_NONE; - glConfig.textureEnvAddAvailable = qfalse; - glConfig.windowAspect = ((float)r_vidModes[r_mode->integer].width) / ((float)r_vidModes[r_mode->integer].height); - glConfig.isFullscreen = qtrue; - - if (!inited){ -#ifdef URBANTERROR - vglInitExtended(0x100000, glConfig.vidWidth, glConfig.vidHeight, 0x1000000, SCE_GXM_MULTISAMPLE_4X); -#else - vglInitExtended(0x100000, glConfig.vidWidth, glConfig.vidHeight, 0x1800000, SCE_GXM_MULTISAMPLE_4X); -#endif - vglUseVram(GL_TRUE); - - inited = 1; - cur_width = glConfig.vidWidth; - }else if (glConfig.vidWidth != cur_width){ // Changed resolution in game, restarting the game -#ifdef URBANTERROR - sceAppMgrLoadExec("app0:/urbanterror.bin", NULL, NULL); -#elif defined(OPENARENA) - sceAppMgrLoadExec("app0:/openarena.bin", NULL, NULL); -#else - sceAppMgrLoadExec("app0:/eboot.bin", NULL, NULL); -#endif - } - vglStartRendering(); - int i; - indices = (uint16_t*)malloc(sizeof(uint16_t*)*MAX_INDICES); - for (i=0;i -#include -#include -#include - -#include "../client/client.h" -#include "../sys/sys_local.h" - -static int hires_x, hires_y; -/* -=============== -IN_Frame -=============== -*/ -uint32_t oldkeys, oldanalogs; -void Key_Event(int key, int value, int time){ - Com_QueueEvent(time, SE_KEY, key, value, 0, NULL); -} - -void Sys_SetKeys(uint32_t keys, int time){ - int port; - - if (!poll_cb) - return; - - poll_cb(); - - if (!input_cb) - return; - - for (port = 0; port < MAX_PADS; port++) - { - if (!input_cb) - break; - - switch (quake_devices[port]) - { - case RETRO_DEVICE_JOYPAD: - case RETRO_DEVICE_JOYPAD_ALT: - case RETRO_DEVICE_MODERN: - { - unsigned i; - int16_t ret = 0; - if (libretro_supports_bitmasks) - ret = input_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); - else - { - for (i=RETRO_DEVICE_ID_JOYPAD_B; i <= RETRO_DEVICE_ID_JOYPAD_R3; ++i) - { - if (input_cb(port, RETRO_DEVICE_JOYPAD, 0, i)) - ret |= (1 << i); - } - } - - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP)) - Key_Event(K_UPARROW, 1, time); - else - Key_Event(K_UPARROW, 0); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN)) - Key_Event(K_DOWNARROW, 1, time); - else - Key_Event(K_DOWNARROW, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) - Key_Event(K_LEFTARROW, 1, time); - else - Key_Event(K_LEFTARROW, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) - Key_Event(K_RIGHTARROW, 1), time); - else - Key_Event(K_RIGHTARROW, 0), time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_START)) - Key_Event(K_ESCAPE, 1, time); - else - Key_Event(K_ESCAPE, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT)) - Key_Event(K_ENTER, 1, time); - else - Key_Event(K_ENTER, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_Y)) - Key_Event(K_AUX3, 1); - else - Key_Event(K_AUX3, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_X)) - Key_Event(K_AUX4, 1, time); - else - Key_Event(K_AUX4, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_B)) - { - Key_Event(K_AUX1, 1, time); - } - else - { - Key_Event(K_AUX1, 0, time); - } - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_A)) - Key_Event(K_AUX2, 1, time); - else - Key_Event(K_AUX2, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_L)) - Key_Event(K_AUX5, 1); - else - Key_Event(K_AUX5, 0, time); - if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_R)) - Key_Event(K_AUX6, 1, time); - else - Key_Event(K_AUX6, 0, time); - } - break; - /* - case RETRO_DEVICE_KEYBOARD: - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) - Sys_SetKeys(K_MOUSE1, 1); - else - Sys_SetKeys(K_MOUSE1, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) - Sys_SetKeys(K_MOUSE2, 1); - else - Sys_SetKeys(K_MOUSE2, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE)) - Sys_SetKeys(K_MOUSE3, 1); - else - Sys_SetKeys(K_MOUSE3, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP)) - Sys_SetKeys(K_MOUSE4, 1); - else - Sys_SetKeys(K_MOUSE4, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN)) - Sys_SetKeys(K_MOUSE5, 1); - else - Sys_SetKeys(K_MOUSE5, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP)) - Sys_SetKeys(K_MOUSE6, 1); - else - Sys_SetKeys(K_MOUSE6, 0); - if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN)) - Sys_SetKeys(K_MOUSE7, 1); - else - Sys_SetKeys(K_MOUSE7, 0); - if (quake_devices[0] == RETRO_DEVICE_KEYBOARD) { - if (input_cb(port, RETRO_DEVICE_KEYBOARD, 0, RETROK_UP)) - Sys_SetKeys(K_UPARROW, 1); - else - Sys_SetKeys(K_UPARROW, 0); - if (input_cb(port, RETRO_DEVICE_KEYBOARD, 0, RETROK_DOWN)) - Sys_SetKeys(K_DOWNARROW, 1); - else - Sys_SetKeys(K_DOWNARROW, 0); - if (input_cb(port, RETRO_DEVICE_KEYBOARD, 0, RETROK_LEFT)) - Sys_SetKeys(K_LEFTARROW, 1); - else - Sys_SetKeys(K_LEFTARROW, 0); - if (input_cb(port, RETRO_DEVICE_KEYBOARD, 0, RETROK_RIGHT)) - Sys_SetKeys(K_RIGHTARROW, 1); - else - Sys_SetKeys(K_RIGHTARROW, 0); - } - break; - */ - case RETRO_DEVICE_NONE: - break; - } - } -} - -// Left analog virtual values -#define LANALOG_LEFT 0x01 -#define LANALOG_RIGHT 0x02 -#define LANALOG_UP 0x04 -#define LANALOG_DOWN 0x08 - -int old_x = - 1, old_y; - -void IN_Frame( void ) -{ - SceCtrlData keys; - sceCtrlPeekBufferPositive(0, &keys, 1); - int time = Sys_Milliseconds(); - if(keys.buttons != oldkeys) - Sys_SetKeys(keys.buttons, time); - oldkeys = keys.buttons; - - // Emulating mouse with touch - SceTouchData touch; - sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1); - if (touch.reportNum > 0){ - if (old_x != -1) Com_QueueEvent(time, SE_MOUSE, (touch.report[0].x - old_x), (touch.report[0].y - old_y), 0, NULL); - old_x = touch.report[0].x; - old_y = touch.report[0].y; - }else old_x = -1; - - // Emulating mouse with right analog - int right_x = (keys.rx - 127) * 256; - int right_y = (keys.ry - 127) * 256; - IN_RescaleAnalog(&right_x, &right_y, 7680); - hires_x += right_x; - hires_y += right_y; - if (hires_x != 0 || hires_y != 0) { - // increase slowdown variable to slow down aiming, could be made user-adjustable - int slowdown = 1024; - Com_QueueEvent(time, SE_MOUSE, hires_x / slowdown, hires_y / slowdown, 0, NULL); - hires_x %= slowdown; - hires_y %= slowdown; - } - - // Emulating keys with left analog (TODO: Replace this dirty hack with a serious implementation) - uint32_t virt_buttons = 0x00; - if (keys.lx < 80) virt_buttons += LANALOG_LEFT; - else if (keys.lx > 160) virt_buttons += LANALOG_RIGHT; - if (keys.ly < 80) virt_buttons += LANALOG_UP; - else if (keys.ly > 160) virt_buttons += LANALOG_DOWN; - if (virt_buttons != oldanalogs){ - if((virt_buttons & LANALOG_LEFT) != (oldanalogs & LANALOG_LEFT)) - Key_Event(K_AUX7, (virt_buttons & LANALOG_LEFT) == LANALOG_LEFT, time); - if((virt_buttons & LANALOG_RIGHT) != (oldanalogs & LANALOG_RIGHT)) - Key_Event(K_AUX8, (virt_buttons & LANALOG_RIGHT) == LANALOG_RIGHT, time); - if((virt_buttons & LANALOG_UP) != (oldanalogs & LANALOG_UP)) - Key_Event(K_AUX9, (virt_buttons & LANALOG_UP) == LANALOG_UP, time); - if((virt_buttons & LANALOG_DOWN) != (oldanalogs & LANALOG_DOWN)) - Key_Event(K_AUX10, (virt_buttons & LANALOG_DOWN) == LANALOG_DOWN, time); - } - oldanalogs = virt_buttons; - -} - -/* -=============== -IN_Init -=============== -*/ -void IN_Init( void *windowData ) -{ - sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE); - sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START); -} - -/* -=============== -IN_Shutdown -=============== -*/ -void IN_Shutdown( void ) -{ -} - -/* -=============== -IN_Restart -=============== -*/ -void IN_Restart( void ) -{ -} diff --git a/code/psp2/psp2_snd.c b/code/psp2/psp2_snd.c deleted file mode 100644 index 3141794..0000000 --- a/code/psp2/psp2_snd.c +++ /dev/null @@ -1,145 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include -#include -#include - -#include "../qcommon/q_shared.h" -#include "../client/snd_local.h" - -qboolean snd_inited = qfalse; - -#define SAMPLE_RATE 48000 -#define AUDIOSIZE 16384 - -SceRtcTick initial_tick; -float tickRate; -int chn = -1; -qboolean stop_audio = qfalse; -uint8_t *audiobuffer; - -static int audio_thread(int args, void *argp) -{ - chn = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, AUDIOSIZE / 2, SAMPLE_RATE, SCE_AUDIO_OUT_MODE_MONO); - sceAudioOutSetConfig(chn, -1, -1, -1); - int vol[] = {32767, 32767}; - sceAudioOutSetVolume(chn, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, vol); - - while (!stop_audio) - { - sceAudioOutOutput(chn, audiobuffer); - } - - sceAudioOutReleasePort(chn); - free(audiobuffer); - - sceKernelExitDeleteThread(0); - return 0; -} - -uint8_t psp2_inited = 0; - -/* -=============== -SNDDMA_Init -=============== -*/ -qboolean SNDDMA_Init(void) -{ - if (psp2_inited) return qtrue; - psp2_inited = 1; - Com_Printf("Initializing audio device.\n"); - dma.samplebits = 16; - dma.speed = SAMPLE_RATE; - dma.channels = 1; - dma.samples = AUDIOSIZE / 2; - dma.fullsamples = dma.samples / dma.channels; - dma.submission_chunk = 1; - dma.buffer = audiobuffer = malloc(AUDIOSIZE); - dma.isfloat = 0; - - tickRate = 1.0f / sceRtcGetTickResolution(); - - SceUID audiothread = sceKernelCreateThread("Audio Thread", (void*)&audio_thread, 0x10000100, 0x10000, 0, 0, NULL); - int res = sceKernelStartThread(audiothread, sizeof(audiothread), &audiothread); - if (res != 0){ - Com_Printf("Failed to init audio thread (0x%x)\n", res); - return qfalse; - } - - sceRtcGetCurrentTick(&initial_tick); - snd_inited = qtrue; - - return qtrue; -} - -/* -=============== -SNDDMA_GetDMAPos -=============== -*/ -int SNDDMA_GetDMAPos(void) -{ - if (!snd_inited) return 0; - - SceRtcTick tick; - sceRtcGetCurrentTick(&tick); - const unsigned int deltaTick = tick.tick - initial_tick.tick; - const float deltaSecond = deltaTick * tickRate; - uint64_t samplepos = deltaSecond * SAMPLE_RATE; - return samplepos; -} - -/* -=============== -SNDDMA_Shutdown -=============== -*/ -void SNDDMA_Shutdown(void) -{ - Com_Printf("Closing audio device...\n"); - if(snd_inited){ - //-> stop_audio = qtrue; - //-> chn = -1; - } -} - -/* -=============== -SNDDMA_Submit - -Send sound to device if buffer isn't really the dma buffer -=============== -*/ -void SNDDMA_Submit(void) -{ -} - -/* -=============== -SNDDMA_BeginPainting -=============== -*/ -void SNDDMA_BeginPainting (void) -{ -} diff --git a/code/psp2/sys_main.c b/code/psp2/sys_main.c deleted file mode 100644 index 2ced875..0000000 --- a/code/psp2/sys_main.c +++ /dev/null @@ -1,511 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "sys_local.h" -#include "sys_loadlib.h" - -#include "../qcommon/q_shared.h" -#include "../qcommon/qcommon.h" - -#ifdef URBANTERROR -int _newlib_heap_size_user = 305 * 1024 * 1024; -#else -int _newlib_heap_size_user = 256 * 1024 * 1024; -#endif - -static char binaryPath[MAX_OSPATH] = {0}; -static char installPath[MAX_OSPATH] = {0}; - -mode_t umask(mode_t mask) { - return 0; -} - -/* -================= -Sys_SetBinaryPath -================= -*/ -void Sys_SetBinaryPath(const char *path) { - Q_strncpyz(binaryPath, path, sizeof(binaryPath)); -} - -/* -================= -Sys_BinaryPath -================= -*/ -char *Sys_BinaryPath(void) { - return binaryPath; -} - -/* -================= -Sys_SetDefaultInstallPath -================= -*/ -void Sys_SetDefaultInstallPath(const char *path) { - Q_strncpyz(installPath, path, sizeof(installPath)); -} - -/* -================= -Sys_DefaultInstallPath -================= -*/ -char *Sys_DefaultInstallPath(void) { - if (*installPath) - return installPath; - else - return Sys_Cwd(); -} - -/* -================= -Sys_DefaultAppPath -================= -*/ -char *Sys_DefaultAppPath(void) { - return Sys_BinaryPath(); -} - -/* -================= -Sys_In_Restart_f - -Restart the input subsystem -================= -*/ -void Sys_In_Restart_f(void) { - IN_Restart(); -} - -/* -================= -Sys_ConsoleInput - -Handle new console input -================= -*/ -char *Sys_ConsoleInput(void) { - return CON_Input(); -} - -/* -================== -Sys_GetClipboardData -================== -*/ -char *Sys_GetClipboardData(void) { -#ifdef DEDICATED - return NULL; -#else - char *data = NULL; - char *cliptext; - - /* if ((cliptext = SDL_GetClipboardText()) != NULL) { - if (cliptext[0] != '\0') { - size_t bufsize = strlen(cliptext) + 1; - - data = Z_Malloc(bufsize); - Q_strncpyz(data, cliptext, bufsize); - - // find first listed char and set to '\0' - strtok(data, "\n\r\b"); - } - SDL_free(cliptext); - }*/ - return data; -#endif -} - -void Sys_InitPIDFile(const char *gamedir) {} - -void Sys_RemovePIDFile(const char *gamedir) {} - -/* -================= -Sys_Exit - -Single exit point (regular exit or in case of error) -================= -*/ -static __attribute__ ((noreturn)) void Sys_Exit(int exitCode) { - CON_Shutdown(); - - NET_Shutdown(); - - Sys_PlatformExit(); - - exit(exitCode); -} - -/* -================= -Sys_Quit -================= -*/ -void Sys_Quit(void) { - Sys_Exit(0); -} - -/* -================= -Sys_GetProcessorFeatures -================= -*/ -cpuFeatures_t Sys_GetProcessorFeatures(void) { - return (cpuFeatures_t) 0; -} - -/* -================= -Sys_Init -================= -*/ -void Sys_Init(void) { - Cmd_AddCommand("in_restart", Sys_In_Restart_f); - Cvar_Set("arch", OS_STRING " " ARCH_STRING); - Cvar_Set("username", Sys_GetCurrentUser()); -} - -/* -================= -Sys_Print -================= -*/ -void Sys_Print(const char *msg) { - CON_Print(msg); -} - -/* -================= -Sys_Error -================= -*/ -void Sys_Error(const char *error, ...) { - va_list argptr; - char string[1024]; - - va_start (argptr, error); - Q_vsnprintf(string, sizeof(string), error, argptr); - va_end (argptr); - - Sys_ErrorDialog(string); - - Sys_Exit(3); -} - -/* -============ -Sys_FileTime - -returns -1 if not present -============ -*/ -int Sys_FileTime(char *path) { - struct stat buf; - - if (stat(path, &buf) == -1) - return -1; - - return buf.st_mtime; -} - -/* -================= -Sys_UnloadDll -================= -*/ -void Sys_UnloadDll( void *dllHandle ) -{ - if( !dllHandle ) - { - Com_Printf("Sys_UnloadDll(NULL)\n"); - return; - } - - Sys_UnloadLibrary(dllHandle); -} - -/* -================= -Sys_LoadDll - -First try to load library name from system library path, -from executable path, then fs_basepath. -================= -*/ - -void *Sys_LoadDll(const char *name, qboolean useSystemLib) -{ - void *dllhandle = NULL; - - if(!Sys_DllExtension(name)) - { - Com_Printf("Refusing to attempt to load library \"%s\": Extension not allowed.\n", name); - return NULL; - } - - if(useSystemLib) - { - Com_Printf("Trying to load \"%s\"...\n", name); - dllhandle = Sys_LoadLibrary(name); - } - - if(!dllhandle) - { - const char *topDir; - char libPath[MAX_OSPATH]; - int len; - - topDir = Sys_BinaryPath(); - - if(!*topDir) - topDir = "."; - - len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name); - if(len < sizeof(libPath)) - { - Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, topDir); - dllhandle = Sys_LoadLibrary(libPath); - } - else - { - Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, topDir); - } - - if(!dllhandle) - { - const char *basePath = Cvar_VariableString("fs_basepath"); - - if(!basePath || !*basePath) - basePath = "."; - - if(FS_FilenameCompare(topDir, basePath)) - { - len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name); - if(len < sizeof(libPath)) - { - Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, basePath); - dllhandle = Sys_LoadLibrary(libPath); - } - else - { - Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, basePath); - } - } - - if(!dllhandle) - Com_Printf("Loading \"%s\" failed\n", name); - } - } - - return dllhandle; -} - -/* -================= -Sys_LoadGameDll - -Used to load a development dll instead of a virtual machine -================= -*/ -void *Sys_LoadGameDll(const char *name, - intptr_t (QDECL **entryPoint)(int, ...), - intptr_t (*systemcalls)(intptr_t, ...)) -{ - void *libHandle; - void (*dllEntry)(intptr_t (*syscallptr)(intptr_t, ...)); - - assert(name); - - if(!Sys_DllExtension(name)) - { - Com_Printf("Refusing to attempt to load library \"%s\": Extension not allowed.\n", name); - return NULL; - } - - Com_Printf( "Loading DLL file: %s\n", name); - libHandle = Sys_LoadLibrary(name); - - if(!libHandle) - { - Com_Printf("Sys_LoadGameDll(%s) failed:\n\"%s\"\n", name, Sys_LibraryError()); - return NULL; - } - - dllEntry = Sys_LoadFunction( libHandle, "dllEntry" ); - *entryPoint = Sys_LoadFunction( libHandle, "vmMain" ); - - if ( !*entryPoint || !dllEntry ) - { - Com_Printf ( "Sys_LoadGameDll(%s) failed to find vmMain function:\n\"%s\" !\n", name, Sys_LibraryError( ) ); - Sys_UnloadLibrary(libHandle); - - return NULL; - } - - Com_Printf ( "Sys_LoadGameDll(%s) found vmMain function at %p\n", name, *entryPoint ); - dllEntry( systemcalls ); - - return libHandle; -} - -/* -================= -Sys_ParseArgs -================= -*/ -void Sys_ParseArgs(int argc, char **argv) { - if (argc == 2) { - if (!strcmp(argv[1], "--version") || - !strcmp(argv[1], "-v")) { - const char *date = PRODUCT_DATE; -#ifdef DEDICATED - fprintf( stdout, Q3_VERSION " dedicated server (%s)\n", date ); -#else - fprintf(stdout, Q3_VERSION " client (%s)\n", date); -#endif - Sys_Exit(0); - } - } -} - -#ifndef DEFAULT_BASEDIR -# define DEFAULT_BASEDIR Sys_BinaryPath() -#endif - -/* -================= -Sys_SigHandler -================= -*/ -void Sys_SigHandler(int signal) { - static qboolean signalcaught = qfalse; - - if (signalcaught) { - fprintf(stderr, "DOUBLE SIGNAL FAULT: Received signal %d, exiting...\n", - signal); - } else { - signalcaught = qtrue; - VM_Forced_Unload_Start(); -#ifndef DEDICATED - CL_Shutdown(va("Received signal %d", signal), qtrue, qtrue); -#endif - SV_Shutdown(va("Received signal %d", signal)); - VM_Forced_Unload_Done(); - } - - if (signal == SIGTERM || signal == SIGINT) - Sys_Exit(1); - else - Sys_Exit(2); -} - -/* -================= -main -================= -*/ -int quake_main (unsigned int argc, void* argv){ - int i; - - char commandLine[MAX_STRING_CHARS] = {0}; - - Sys_PlatformInit(); - - // Set the initial time base - Sys_Milliseconds(); - - sceIoMkdir(DEFAULT_BASEDIR, 777); - Sys_SetBinaryPath(DEFAULT_BASEDIR); - Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); - - // Quake III: Team Arena, Urban Terror & OpenArena support -#ifdef URBANTERROR - sprintf(commandLine, "+set fs_game q3ut4"); -#else -# ifndef OPENARENA - sceAppUtilInit(&(SceAppUtilInitParam){}, &(SceAppUtilBootParam){}); - SceAppUtilAppEventParam eventParam; - memset(&eventParam, 0, sizeof(SceAppUtilAppEventParam)); - sceAppUtilReceiveAppEvent(&eventParam); - if (eventParam.type == 0x05){ - char buffer[2048]; - memset(buffer, 0, 2048); - sceAppUtilAppEventParseLiveArea(&eventParam, buffer); - if (strstr(buffer, "open") != NULL) sceAppMgrLoadExec("app0:/openarena.bin", NULL, NULL); - else if (strstr(buffer, "terror") != NULL) sceAppMgrLoadExec("app0:/urbanterror.bin", NULL, NULL); - else sprintf(commandLine, "+set fs_game missionpack"); - } -# endif -#endif - CON_Init(); - Com_Init(commandLine); - NET_Init(); - - while (1) { - // Prevent screen power-off - sceKernelPowerTick(0); - - Com_Frame(); - } - - return 0; -} - -extern void IN_Init( void *windowData ); - -int main(int argc, char **argv) { - - // Setting maximum clocks - scePowerSetArmClockFrequency(444); - scePowerSetBusClockFrequency(222); - scePowerSetGpuClockFrequency(222); - scePowerSetGpuXbarClockFrequency(166); - - // Starting input - IN_Init(NULL); - - // We need a bigger stack to run Quake 3, so we create a new thread with a proper stack size - SceUID main_thread = sceKernelCreateThread("Quake III", quake_main, 0x40, 0x200000, 0, 0, NULL); - if (main_thread >= 0){ - sceKernelStartThread(main_thread, 0, NULL); - sceKernelWaitThreadEnd(main_thread, NULL, NULL); - } - return 0; - -} - diff --git a/code/psp2/sys_psp2.c b/code/psp2/sys_psp2.c deleted file mode 100644 index 6e486da..0000000 --- a/code/psp2/sys_psp2.c +++ /dev/null @@ -1,706 +0,0 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code 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; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code 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 for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#include "../qcommon/q_shared.h" -#include "../qcommon/qcommon.h" -#include "sys_local.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -void log2file(const char *format, ...) { - __gnuc_va_list arg; - int done; - va_start(arg, format); - char msg[512]; - done = vsprintf(msg, format, arg); - va_end(arg); - int i; - sprintf(msg, "%s\n", msg); - CON_Print(msg); -} - -#ifndef RELEASE -# define printf log2file -#endif - -qboolean stdinIsATTY; - -// Used to determine where to store user-specific files -static char homePath[MAX_OSPATH] = {0}; - -// Used to store the Steam Quake 3 installation path -static char steamPath[MAX_OSPATH] = {0}; - -// Used to store the GOG Quake 3 installation path -static char gogPath[MAX_OSPATH] = {0}; - -/* -================== -Sys_DefaultHomePath -================== -*/ -char *Sys_DefaultHomePath(void) { - char *p; - - if (!*homePath && com_homepath != NULL) { - if ((p = getenv("HOME")) != NULL) { - Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP); -#ifdef __APPLE__ - Q_strcat(homePath, sizeof(homePath), - "Library/Application Support/"); - - if(com_homepath->string[0]) - Q_strcat(homePath, sizeof(homePath), com_homepath->string); - else - Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_MACOSX); -#else - if (com_homepath->string[0]) - Q_strcat(homePath, sizeof(homePath), com_homepath->string); - else - Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_UNIX); -#endif - } - } - - return homePath; -} - -/* -================ -Sys_SteamPath -================ -*/ -char *Sys_SteamPath(void) { - // Disabled since Steam doesn't let you install Quake 3 on Mac/Linux -#if 0 //#ifdef STEAMPATH_NAME - char *p; - - if( ( p = getenv( "HOME" ) ) != NULL ) - { -#ifdef __APPLE__ - char *steamPathEnd = "/Library/Application Support/Steam/SteamApps/common/" STEAMPATH_NAME; -#else - char *steamPathEnd = "/.steam/steam/SteamApps/common/" STEAMPATH_NAME; -#endif - Com_sprintf(steamPath, sizeof(steamPath), "%s%s", p, steamPathEnd); - } -#endif - - return steamPath; -} - -/* -================ -Sys_GogPath -================ -*/ -char *Sys_GogPath(void) { - // GOG also doesn't let you install Quake 3 on Mac/Linux - return gogPath; -} - -/* -================ -Sys_Milliseconds -================ -*/ -int curtime; -int Sys_Milliseconds(void) { - static uint64_t base; - - uint64_t time = sceKernelGetProcessTimeWide() / 1000; - - if (!base) { - base = time; - } - - curtime = (int)(time - base); - - return curtime; -} - -/* -================== -Sys_RandomBytes -================== -*/ -qboolean Sys_RandomBytes(byte *string, int len) { - return qfalse; -} - -/* -================== -Sys_GetCurrentUser -================== -*/ -char nick[SCE_SYSTEM_PARAM_USERNAME_MAXSIZE]; -char *Sys_GetCurrentUser(void) { - SceAppUtilInitParam init_param; - SceAppUtilBootParam boot_param; - memset(&init_param, 0, sizeof(SceAppUtilInitParam)); - memset(&boot_param, 0, sizeof(SceAppUtilBootParam)); - sceAppUtilInit(&init_param, &boot_param); - sceAppUtilSystemParamGetString(SCE_SYSTEM_PARAM_ID_USERNAME, nick, SCE_SYSTEM_PARAM_USERNAME_MAXSIZE); - return nick; -} - -/* -================== -Sys_LowPhysicalMemory - -TODO -================== -*/ -qboolean Sys_LowPhysicalMemory(void) { - return qfalse; -} - -/* -================== -Sys_Basename -================== -*/ -const char *Sys_Basename(char *path) { - char *p = strrchr(path, '/'); - return p ? p + 1 : (char *) path; -} - -/* -================== -Sys_Dirname -================== -*/ -const char *Sys_Dirname(char *path) { - static const char dot[] = "."; - char *last_slash; - - /* Find last '/'. */ - last_slash = path != NULL ? strrchr(path, '/') : NULL; - - if (last_slash != NULL && last_slash != path && last_slash[1] == '\0') { - /* Determine whether all remaining characters are slashes. */ - char *runp; - - for (runp = last_slash; runp != path; --runp) - if (runp[-1] != '/') - break; - - /* The '/' is the last character, we have to look further. */ - if (runp != path) - last_slash = memrchr(path, '/', runp - path); - } - - if (last_slash != NULL) { - /* Determine whether all remaining characters are slashes. */ - char *runp; - - for (runp = last_slash; runp != path; --runp) - if (runp[-1] != '/') - break; - - /* Terminate the path. */ - if (runp == path) { - /* The last slash is the first character in the string. We have to - return "/". As a special case we have to return "//" if there - are exactly two slashes at the beginning of the string. See - XBD 4.10 Path Name Resolution for more information. */ - if (last_slash == path + 1) - ++last_slash; - else - last_slash = path + 1; - } else - last_slash = runp; - - last_slash[0] = '\0'; - } else - /* This assignment is ill-designed but the XPG specs require to - return a string containing "." in any case no directory part is - found and so a static and constant string is required. */ - path = (char *) dot; - - return path; -} - -/* -============== -Sys_FOpen -============== -*/ -FILE *Sys_FOpen(const char *ospath, const char *mode) { - struct stat buf; - - // check if path exists and is a directory - if (!stat(ospath, &buf) && S_ISDIR(buf.st_mode)) - return NULL; - - return fopen(ospath, mode); -} - -/* -================== -Sys_Mkdir -================== -*/ -qboolean Sys_Mkdir(const char *path) { - - int result = sceIoMkdir(path, 0777); - //printf("Sys_Mkdir: 0x%08X\n", result); - if (result != 0 && result != 0x80010011 - && result != 0x8001000D) - return errno == EEXIST; - - return qtrue; -} - -/* -================== -Sys_Mkfifo -================== -*/ -FILE *Sys_Mkfifo(const char *ospath) { - return NULL; -} - -/* -================== -Sys_Cwd -================== -*/ -char *Sys_Cwd(void) { - return DEFAULT_BASEDIR; -} - -/* -============================================================== - -DIRECTORY SCANNING - -============================================================== -*/ - -#define MAX_FOUND_FILES 0x1000 - -/* -================== -Sys_ListFilteredFiles -================== -*/ -void Sys_ListFilteredFiles(const char *basedir, char *subdirs, char *filter, char **list, int *numfiles) { - char search[MAX_OSPATH], newsubdirs[MAX_OSPATH]; - char filename[MAX_OSPATH]; - DIR *fdir; - struct dirent *d; - struct stat st; - - if (*numfiles >= MAX_FOUND_FILES - 1) { - return; - } - - if (strlen(subdirs)) { - Com_sprintf(search, sizeof(search), "%s/%s", basedir, subdirs); - } else { - Com_sprintf(search, sizeof(search), "%s", basedir); - } - - if ((fdir = opendir(search)) == NULL) { - return; - } - - while ((d = readdir(fdir)) != NULL) { - Com_sprintf(filename, sizeof(filename), "%s/%s", search, d->d_name); - if (stat(filename, &st) == -1) - continue; - - if (st.st_mode & S_IFDIR) { - if (Q_stricmp(d->d_name, ".") && Q_stricmp(d->d_name, "..")) { - if (strlen(subdirs)) { - Com_sprintf(newsubdirs, sizeof(newsubdirs), "%s/%s", subdirs, d->d_name); - } else { - Com_sprintf(newsubdirs, sizeof(newsubdirs), "%s", d->d_name); - } - Sys_ListFilteredFiles(basedir, newsubdirs, filter, list, numfiles); - } - } - if (*numfiles >= MAX_FOUND_FILES - 1) { - break; - } - Com_sprintf(filename, sizeof(filename), "%s/%s", subdirs, d->d_name); - if (!Com_FilterPath(filter, filename, qfalse)) - continue; - list[*numfiles] = CopyString(filename); - (*numfiles)++; - } - - closedir(fdir); -} - -/* -================== -Sys_ListFiles -================== -*/ -char **Sys_ListFiles(const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs) { - struct dirent *d; - DIR *fdir; - qboolean dironly = wantsubs; - char search[MAX_OSPATH]; - int nfiles; - char **listCopy; - char *list[MAX_FOUND_FILES]; - int i; - struct stat st; - - int extLen; - - if (filter) { - - nfiles = 0; - Sys_ListFilteredFiles(directory, "", filter, list, &nfiles); - - list[nfiles] = NULL; - *numfiles = nfiles; - - if (!nfiles) - return NULL; - - listCopy = Z_Malloc((nfiles + 1) * sizeof(*listCopy)); - for (i = 0; i < nfiles; i++) { - listCopy[i] = list[i]; - } - listCopy[i] = NULL; - - return listCopy; - } - - if (!extension) - extension = ""; - - if (extension[0] == '/' && extension[1] == 0) { - extension = ""; - dironly = qtrue; - } - - extLen = strlen(extension); - - // search - nfiles = 0; - - if ((fdir = opendir(directory)) == NULL) { - *numfiles = 0; - return NULL; - } - - while ((d = readdir(fdir)) != NULL) { - Com_sprintf(search, sizeof(search), "%s/%s", directory, d->d_name); - if (stat(search, &st) == -1) - continue; - if ((dironly && !(st.st_mode & S_IFDIR)) || - (!dironly && (st.st_mode & S_IFDIR))) - continue; - - if (*extension) { - if (strlen(d->d_name) < extLen || - Q_stricmp( - d->d_name + strlen(d->d_name) - extLen, - extension)) { - continue; // didn't match - } - } - - if (nfiles == MAX_FOUND_FILES - 1) - break; - list[nfiles] = CopyString(d->d_name); - nfiles++; - } - - list[nfiles] = NULL; - - closedir(fdir); - - // return a copy of the list - *numfiles = nfiles; - - if (!nfiles) { - return NULL; - } - - listCopy = Z_Malloc((nfiles + 1) * sizeof(*listCopy)); - for (i = 0; i < nfiles; i++) { - listCopy[i] = list[i]; - } - listCopy[i] = NULL; - - return listCopy; -} - -/* -================== -Sys_FreeFileList -================== -*/ -void Sys_FreeFileList(char **list) { - int i; - - if (!list) { - return; - } - - for (i = 0; list[i]; i++) { - Z_Free(list[i]); - } - - Z_Free(list); -} - -/* -================== -Sys_Sleep - -Block execution for msec or until input is received. -================== -*/ -void Sys_Sleep(int msec) { - if (msec == 0) - return; - - if (stdinIsATTY) { - fd_set fdset; - - FD_ZERO(&fdset); - FD_SET(STDIN_FILENO, &fdset); - if (msec < 0) { - select(STDIN_FILENO + 1, &fdset, NULL, NULL, NULL); - } else { - struct timeval timeout; - - timeout.tv_sec = msec / 1000; - timeout.tv_usec = (msec % 1000) * 1000; - select(STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout); - } - } else { - // With nothing to select() on, we can't wait indefinitely - if (msec < 0) - msec = 10; - - sceKernelDelayThread(msec * 1000); - - } -} - -/* -============== -Sys_ErrorDialog - -Display an error message -============== -*/ -void Sys_ErrorDialog(const char *error) { - char buffer[1024]; - unsigned int size; - int f = -1; - const char *homepath = Cvar_VariableString("fs_homepath"); - const char *gamedir = Cvar_VariableString("fs_game"); - const char *fileName = "crashlog.txt"; - char *dirpath = FS_BuildOSPath(homepath, gamedir, ""); - char *ospath = FS_BuildOSPath(homepath, gamedir, fileName); - - Sys_Print(va("%s\n", error)); - - // Make sure the write path for the crashlog exists... - - if (!Sys_Mkdir(homepath)) { - Com_Printf("ERROR: couldn't create path '%s' for crash log.\n", homepath); - return; - } - - if (!Sys_Mkdir(dirpath)) { - Com_Printf("ERROR: couldn't create path '%s' for crash log.\n", dirpath); - return; - } - - // We might be crashing because we maxed out the Quake MAX_FILE_HANDLES, - // which will come through here, so we don't want to recurse forever by - // calling FS_FOpenFileWrite()...use the Unix system APIs instead. - f = open(ospath, O_CREAT | O_TRUNC | O_WRONLY, 0640); - if (f == -1) { - Com_Printf("ERROR: couldn't open %s\n", fileName); - return; - } - - // We're crashing, so we don't care much if write() or close() fails. - while ((size = CON_LogRead(buffer, sizeof(buffer))) > 0) { - if (write(f, buffer, size) != size) { - Com_Printf("ERROR: couldn't fully write to %s\n", fileName); - break; - } - } - - close(f); -} - -/* -============== -Sys_GLimpSafeInit - -Unix specific "safe" GL implementation initialisation -============== -*/ -void Sys_GLimpSafeInit(void) { - // NOP -} - -/* -============== -Sys_GLimpInit - -Unix specific GL implementation initialisation -============== -*/ -void Sys_GLimpInit(void) { - // NOP -} - -void Sys_SetFloatEnv(void) { - // rounding toward nearest - // fesetround(FE_TONEAREST); - // TODO: PSP2 ? -} - -/* -============== -Sys_PlatformInit - -Unix specific initialisation -============== -*/ -void Sys_PlatformInit(void) { - const char *term = getenv("TERM"); - - signal(SIGHUP, Sys_SigHandler); - signal(SIGQUIT, Sys_SigHandler); - signal(SIGTRAP, Sys_SigHandler); - signal(SIGABRT, Sys_SigHandler); - signal(SIGBUS, Sys_SigHandler); - - Sys_SetFloatEnv(); - - stdinIsATTY = isatty(STDIN_FILENO) && - !(term && (!strcmp(term, "raw") || !strcmp(term, "dumb"))); -} - -/* -============== -Sys_PlatformExit - -Unix specific deinitialisation -============== -*/ -void Sys_PlatformExit(void) { -} - -/* -============== -Sys_SetEnv - -set/unset environment variables (empty value removes it) -============== -*/ - -void Sys_SetEnv(const char *name, const char *value) { - if (value && *value) - setenv(name, value, 1); - else - unsetenv(name); -} - -/* -============== -Sys_PID -============== -*/ -int Sys_PID(void) { - return getpid(); -} - -/* -============== -Sys_PIDIsRunning -============== -*/ -qboolean Sys_PIDIsRunning(int pid) { - return kill(pid, 0) == 0; -} - -/* -================= -Sys_DllExtension - -Check if filename should be allowed to be loaded as a DLL. -================= -*/ -qboolean Sys_DllExtension(const char *name) { - const char *p; - char c = 0; - - if (COM_CompareExtension(name, DLL_EXT)) { - return qtrue; - } - - // Check for format of filename.so.1.2.3 - p = strstr(name, DLL_EXT "."); - - if (p) { - p += strlen(DLL_EXT); - - // Check if .so is only followed for periods and numbers. - while (*p) { - c = *p; - - if (!isdigit(c) && c != '.') { - return qfalse; - } - - p++; - } - - // Don't allow filename to end in a period. file.so., file.so.0., etc - if (c != '.') { - return qtrue; - } - } - - return qfalse; -}