Compare commits

..

51 Commits

Author SHA1 Message Date
Alibek Omarov
f0a2362da3 engine: wscript: another try, link nswitch port using gcc and not g++ 2023-12-02 19:29:30 +03:00
Alibek Omarov
be8ade23e8 engine: wscript: add -nostdlib++ for nswitch so we avoid implicit linking to standard C++ library (we link it explicitly ourselves) 2023-12-02 19:21:44 +03:00
Alibek Omarov
6814908d80 scripts: gha: enable verbose build for nswitch port 2023-12-02 19:08:34 +03:00
Alibek Omarov
08dbfc45d3 ref: gl: refactor getting edge position, texture and lightmap coords 2023-12-02 18:02:18 +03:00
Alibek Omarov
89f9b3df68 public: make simple bbox functions inline 2023-12-02 18:01:57 +03:00
Alibek Omarov
40c9a2fb82 engine: make Mod_SampleSizeForFace accept const surface 2023-12-02 18:01:57 +03:00
Andrey Akhmichin
a34c22fb10 engine: client: add support for "mp3 playfile/loopfile" commands. 2023-12-02 01:10:38 +03:00
Alibek Omarov
e161ff0f7a mainui: update 2023-11-27 19:25:36 +03:00
Alibek Omarov
fee42eab5a mainui: update 2023-11-27 19:05:48 +03:00
Alibek Omarov
2d2e03f235 engine: server: reset edict in ParseSaveTables like GoldSrc does which fixes messed up entities in mods that have advanced save-restore system (thanks to vasiavasiavasia95 for figuring out this bug) 2023-11-27 18:42:50 +03:00
Alibek Omarov
4c3c3529e9 engine: network: rename length variable to something that makes sense. Add usage line to http_addcustomserver 2023-11-26 23:20:46 +03:00
Alibek Omarov
7051b844ff engine: network: set HTTP buffer to 8kb on all systems, without depending on random constant like BUFSIZ 2023-11-26 23:19:49 +03:00
Alibek Omarov
68377435c8 engine: server: remove legacy light -> light_level entity key rewrite 2023-11-26 02:23:52 +03:00
Henry Ford
652b1804a8 wscript: make libdl optional for systems that include it in libc 2023-11-25 14:29:52 +03:00
Henry Ford
e7e1677786 engine: common: comply with C89 in OpenBSD wai_getExecutablePath 2023-11-25 14:29:52 +03:00
Henry Ford
f330aac113 engine: common: dont inlcude ucontext.h on OpenBSD where it doesnt exist 2023-11-25 14:29:52 +03:00
Henry Ford
dbdd330cf7 wscript: try to find alloca in stdlib.h on platforms without alloca.h or malloc.h 2023-11-25 14:29:52 +03:00
Andrey Akhmichin
c448c7b0b1 utils: mdldec: avoid double ".smd" extension output. 2023-11-22 11:05:34 +03:00
Andrey Akhmichin
8d7b9c2f01 utils: mdldec: always write trailing slash for non-empty destination path. 2023-11-22 11:03:28 +03:00
Alibek Omarov
b6a235445a vgui_support: update submodule 2023-11-22 11:02:25 +03:00
Alibek Omarov
9fcd4baa87 engine: client: gameui: expose animated_title and hd_background flags to main menu API 2023-11-22 11:01:18 +03:00
Alibek Omarov
fb0102eb8e filesystem: add support for two new liblist.gam keys: animated_title and hd_background 2023-11-22 11:01:18 +03:00
Alibek Omarov
9c1afaa372 filesystem: fix noskills being written as nomodels in gameinfo.txt 2023-11-22 11:01:18 +03:00
Alibek Omarov
1d1a6badb5 filesystem: VFileSystem009: HL25 compatibility (one single new method) 2023-11-22 11:01:18 +03:00
Andrey Akhmichin
2d41c9cb15 utils: mdldec: texture.c: add Targa image format output support. 2023-11-22 10:56:57 +03:00
Alibek Omarov
722cbe1f02 filesystem: forgot to add defaults.h include 2023-11-20 18:52:05 +03:00
Alibek Omarov
8ac2c241c4 mainui: update 2023-11-20 17:33:40 +03:00
Alibek Omarov
dd11f73951 filesystem: respect DEFAULT_MAX_EDICTS value 2023-11-20 17:32:35 +03:00
Alibek Omarov
a443547d4d common: defaults: add default macro for default gameinfo max_edicts value 2023-11-20 17:32:19 +03:00
Andrey Akhmichin
7a795edeb5 utils: mdldec: better validation checks. 2023-11-20 00:19:14 +03:00
Andrey Akhmichin
a8cbfb8dda Documentation: opensource-mods.md: update link to cs16-client. 2023-11-20 00:15:26 +03:00
SNMetamorph
5216cccef4 engine: server: added singleplayer check for userinfo update 2023-11-20 00:14:30 +03:00
SNMetamorph
a87f399e68 engine: client: revert export for pfnSPR_Load and pfnSPR_Frames functions
This needed for native support GoldSrc Monitor utility.
2023-11-20 00:14:06 +03:00
Andrey Akhmichin
dd310ab851 ci: upgrade freebsd tasks. 2023-11-20 00:13:42 +03:00
Andrey Akhmichin
16cc0ca0fe ref: gl: gl2_shim: replace "malloc.h" header with ALLOCA_H macro. 2023-11-20 00:13:04 +03:00
Alibek Omarov
83d26ad233 engine: server: add sv_allow_autoaim cvar 2023-11-20 00:11:10 +03:00
Alibek Omarov
d1f9a8f2db mainui: updates for HL25 2023-11-19 23:43:46 +03:00
Alibek Omarov
a2e1071808 game_launch: force link libm on Linux to workaround HL25 bug
HL25 doesn't link libm probably because of toolchain updates, where
--Wl,--as-needed became the default.

hl_linux is linked to libm which is why they probably didn't noticed this bug.

Workaround until Valve fixes it: https://github.com/ValveSoftware/halflife/issues/3492
2023-11-19 23:43:46 +03:00
Alibek Omarov
0aa8a2891c engine: client: add gles3compat to renderers list 2023-11-03 17:03:27 +03:00
Alibek Omarov
c0ceab7513 wscript: enable ref_gles3compat for Android 2023-11-03 17:01:47 +03:00
Velaron
5c90e716cb engine: platform: android: refactoring 2023-11-03 16:40:06 +03:00
Velaron
0073225549 scripts: gha: Android deps and build scripts 2023-11-03 16:36:55 +03:00
Alibek Omarov
d03a64602b wscript: change defaults for Android 2023-11-03 16:34:21 +03:00
Alibek Omarov
d67a4234cc filesystem: android: simplify code, get getAssets method only once, remove unneeded casts and memsets (where Mem_Calloc is used) 2023-11-03 16:29:57 +03:00
Alibek Omarov
0d37244490 filesystem: add missing const to 2nd argument of stringlistappend 2023-11-03 16:23:52 +03:00
Velaron
6426919cb5 filesystem: add Android assets support 2023-11-03 16:23:03 +03:00
Alibek Omarov
0a0d63663a filesystem: link with libandroid 2023-11-03 16:22:59 +03:00
Alibek Omarov
71b06801ef engine: platform: android: remove dead code 2023-11-03 14:48:28 +03:00
Alibek Omarov
cfc7b35927 engine: client: don't leave the user without mouse cursor if they enabled m_ignore 2023-11-03 14:48:28 +03:00
Alibek Omarov
76564958d1 engine: host: hide -nativeegl for Android SDL builds 2023-11-03 14:48:28 +03:00
Alibek Omarov
a464c3dd66 scripts: waifulib: compiler_optimizations: rename release build type to humanrights with kept compatibility 2023-11-02 14:33:00 +03:00
53 changed files with 1027 additions and 353 deletions

View File

@@ -1,10 +1,10 @@
task: task:
name: freebsd-12-amd64 name: freebsd-12-amd64
freebsd_instance: freebsd_instance:
image_family: freebsd-12-3 image_family: freebsd-12-4
setup_script: setup_script:
- pkg update - pkg update
- pkg install -y git sdl2 python fontconfig - pkg install -y pkgconf git sdl2 python fontconfig opus
- git submodule update --init --recursive - git submodule update --init --recursive
test_script: test_script:
- ./scripts/cirrus/build_freebsd.sh dedicated - ./scripts/cirrus/build_freebsd.sh dedicated
@@ -13,10 +13,10 @@ task:
task: task:
name: freebsd-13-amd64 name: freebsd-13-amd64
freebsd_instance: freebsd_instance:
image_family: freebsd-13-1 image_family: freebsd-13-2
setup_script: setup_script:
- pkg update - pkg update
- pkg install -y git sdl2 python fontconfig - pkg install -y pkgconf git sdl2 python fontconfig opus
- git submodule update --init --recursive - git submodule update --init --recursive
test_script: test_script:
- ./scripts/cirrus/build_freebsd.sh dedicated - ./scripts/cirrus/build_freebsd.sh dedicated
@@ -28,7 +28,19 @@ task:
image_family: freebsd-14-0-snap image_family: freebsd-14-0-snap
setup_script: setup_script:
- pkg update - pkg update
- pkg install -y git sdl2 python fontconfig - pkg install -y pkgconf git sdl2 python fontconfig opus
- git submodule update --init --recursive
test_script:
- ./scripts/cirrus/build_freebsd.sh dedicated
- ./scripts/cirrus/build_freebsd.sh full
task:
name: freebsd-15-amd64
freebsd_instance:
image_family: freebsd-15-0-snap
setup_script:
- pkg update
- pkg install -y pkgconf git sdl2 python fontconfig opus
- git submodule update --init --recursive - git submodule update --init --recursive
test_script: test_script:
- ./scripts/cirrus/build_freebsd.sh dedicated - ./scripts/cirrus/build_freebsd.sh dedicated

View File

@@ -70,9 +70,11 @@ These strings are specific to Xash3D FWGS.
| Key | Type | Default value | Description | | Key | Type | Default value | Description |
| ----------------------- | ---------- | ------------------------ | ----------- | | ----------------------- | ---------- | ------------------------ | ----------- |
| `animated_title` | boolean | 0 | Use animated title in main menu (WON Half-Life logo.avi imitation from Half-Life 25-th anniversary update)
| `autosave_aged_count` | integer | 2 | Auto saves limit used in saves rotation | | `autosave_aged_count` | integer | 2 | Auto saves limit used in saves rotation |
| `gamedll_linux` | string | Generated from `gamedll` | Game server DLL for 32-bit x86 Linux (see LibraryNaming.md for details) | | `gamedll_linux` | string | Generated from `gamedll` | Game server DLL for 32-bit x86 Linux (see LibraryNaming.md for details) |
| `gamedll_osx` | string | Generated from `gamedll` | Game server DLL for 32-bit x86 macOS (see LibraryNaming.md for details) | | `gamedll_osx` | string | Generated from `gamedll` | Game server DLL for 32-bit x86 macOS (see LibraryNaming.md for details) |
| `hd_background` | boolean | 0 | Use HD background for main menu (Half-Life 25-th anniversary update) |
| `internal_vgui_support` | boolean | 0 | Only for programmers! Required to be set as 1 for PrimeXT!<br>When set to 1, the engine will not load vgui_support DLL, as VGUI support is done (or intentionally ignored) on the game side. | | `internal_vgui_support` | boolean | 0 | Only for programmers! Required to be set as 1 for PrimeXT!<br>When set to 1, the engine will not load vgui_support DLL, as VGUI support is done (or intentionally ignored) on the game side. |
| `render_picbutton_text` | boolean | 0 | When set to 1, the UI will not use prerendered `btns_main.bmp` and dynamically render them instead | | `render_picbutton_text` | boolean | 0 | When set to 1, the UI will not use prerendered `btns_main.bmp` and dynamically render them instead |
| `quicksave_aged_count` | integer | 2 | Quick saves limit used in saves rotation | | `quicksave_aged_count` | integer | 2 | Quick saves limit used in saves rotation |
@@ -88,6 +90,7 @@ The table below defines conversion rules from liblist.gam to gameinfo.txt. Some
| `liblist.gam` key | `gameinfo.txt` key | Note | | `liblist.gam` key | `gameinfo.txt` key | Note |
| ----------------- | ------------------ | ---- | | ----------------- | ------------------ | ---- |
| `animated_title` | `animated_title` | |
| `edicts` | `max_edicts` | | | `edicts` | `max_edicts` | |
| `fallback_dir` | `fallback_dir` | | | `fallback_dir` | `fallback_dir` | |
| `game` | `title` | | | `game` | `title` | |
@@ -95,6 +98,7 @@ The table below defines conversion rules from liblist.gam to gameinfo.txt. Some
| `gamedll` | `gamedll` | | | `gamedll` | `gamedll` | |
| `gamedll_linux` | `gamedll_linux` | | | `gamedll_linux` | `gamedll_linux` | |
| `gamedll_osx` | `gamedll_osx` | | | `gamedll_osx` | `gamedll_osx` | |
| `hd_background` | `hd_background` | |
| `icon` | `icon` | | | `icon` | `icon` | |
| `mpentity` | `mp_entity` | | | `mpentity` | `mp_entity` | |
| `mpfilter` | `mp_filter` | | | `mpfilter` | `mp_filter` | |

View File

@@ -228,7 +228,7 @@ Branch **caseclosed** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable
Branch **CAd** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/CAd Branch **CAd** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/CAd
## Counter Strike ## Counter Strike
Reverse-engineered code of client part by a1batross - https://github.com/FWGS/cs16-client/tree/v1.32 Reverse-engineered code of client part by a1batross - https://github.com/Velaron/cs16-client
Reverse-engineered code of server part by nagist - https://github.com/nagist/cs16nd Reverse-engineered code of server part by nagist - https://github.com/nagist/cs16nd

View File

@@ -189,4 +189,8 @@ Default build-depended cvar and constant values
#define DEFAULT_FULLSCREEN "1" // must be a string #define DEFAULT_FULLSCREEN "1" // must be a string
#endif // DEFAULT_FULLSCREEN #endif // DEFAULT_FULLSCREEN
#ifndef DEFAULT_MAX_EDICTS
#define DEFAULT_MAX_EDICTS 1200 // was 900 before HL25
#endif // DEFAULT_MAX_EDICTS
#endif // DEFAULTS_H #endif // DEFAULTS_H

View File

@@ -19,6 +19,8 @@ GNU General Public License for more details.
#define GFL_NOMODELS (1<<0) #define GFL_NOMODELS (1<<0)
#define GFL_NOSKILLS (1<<1) #define GFL_NOSKILLS (1<<1)
#define GFL_RENDER_PICBUTTON_TEXT (1<<2) #define GFL_RENDER_PICBUTTON_TEXT (1<<2)
#define GFL_HD_BACKGROUND (1<<3)
#define GFL_ANIMATED_TITLE (1<<4)
/* /*
======================================================================== ========================================================================

View File

@@ -85,6 +85,12 @@ void CL_PlayCDTrack_f( void )
paused = false; paused = false;
looped = false; looped = false;
} }
else if( !Q_stricmp( command, "playfile" ))
{
S_StartBackgroundTrack( pszTrack, NULL, 0, true );
paused = false;
looped = false;
}
else if( !Q_stricmp( command, "loop" )) else if( !Q_stricmp( command, "loop" ))
{ {
if( Q_isdigit( pszTrack )) if( Q_isdigit( pszTrack ))
@@ -96,6 +102,12 @@ void CL_PlayCDTrack_f( void )
paused = false; paused = false;
looped = true; looped = true;
} }
else if( !Q_stricmp( command, "loopfile" ))
{
S_StartBackgroundTrack( pszTrack, pszTrack, 0, true );
paused = false;
looped = true;
}
else if( !Q_stricmp( command, "pause" )) else if( !Q_stricmp( command, "pause" ))
{ {
S_StreamSetPause( true ); S_StreamSetPause( true );

View File

@@ -1320,9 +1320,10 @@ HSPRITE pfnSPR_LoadExt( const char *szPicName, uint texFlags )
========= =========
pfnSPR_Load pfnSPR_Load
function exported for support GoldSrc Monitor utility
========= =========
*/ */
static HSPRITE GAME_EXPORT pfnSPR_Load( const char *szPicName ) HSPRITE EXPORT pfnSPR_Load( const char *szPicName )
{ {
model_t *spr; model_t *spr;
@@ -1368,9 +1369,10 @@ static const model_t *CL_GetSpritePointer( HSPRITE hSprite )
========= =========
pfnSPR_Frames pfnSPR_Frames
function exported for support GoldSrc Monitor utility
========= =========
*/ */
static int GAME_EXPORT pfnSPR_Frames( HSPRITE hPic ) int EXPORT pfnSPR_Frames( HSPRITE hPic )
{ {
int numFrames = 0; int numFrames = 0;

View File

@@ -414,11 +414,15 @@ static void UI_ConvertGameInfo( GAMEINFO *out, gameinfo_t *in )
out->gamemode = in->gamemode; out->gamemode = in->gamemode;
if( in->nomodels ) if( in->nomodels )
out->flags |= GFL_NOMODELS; SetBits( out->flags, GFL_NOMODELS );
if( in->noskills ) if( in->noskills )
out->flags |= GFL_NOSKILLS; SetBits( out->flags, GFL_NOSKILLS );
if( in->render_picbutton_text ) if( in->render_picbutton_text )
out->flags |= GFL_RENDER_PICBUTTON_TEXT; SetBits( out->flags, GFL_RENDER_PICBUTTON_TEXT );
if( in->hd_background )
SetBits( out->flags, GFL_HD_BACKGROUND );
if( in->animated_title )
SetBits( out->flags, GFL_ANIMATED_TITLE );
} }
/* /*

View File

@@ -172,8 +172,6 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
{ {
if( newstate == oldstate ) if( newstate == oldstate )
return; return;
if( m_ignore.value )
return;
// since SetCursorType controls cursor visibility // since SetCursorType controls cursor visibility
// execute it first, and then check mouse grab state // execute it first, and then check mouse grab state
@@ -194,6 +192,10 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
#endif #endif
} }
// don't leave the user without cursor if they enabled m_ignore
if( m_ignore.value )
return;
if( oldstate == key_game ) if( oldstate == key_game )
{ {
IN_DeactivateMouse(); IN_DeactivateMouse();

View File

@@ -569,6 +569,9 @@ static void R_CollectRendererNames( void )
#if XASH_REF_GL4ES_ENABLED #if XASH_REF_GL4ES_ENABLED
"gl4es", "gl4es",
#endif #endif
#if XASH_REF_GLES3COMPAT_ENABLED
"gles3compat",
#endif
#if XASH_REF_SOFT_ENABLED #if XASH_REF_SOFT_ENABLED
"soft", "soft",
#endif #endif
@@ -589,6 +592,9 @@ static void R_CollectRendererNames( void )
#if XASH_REF_GL4ES_ENABLED #if XASH_REF_GL4ES_ENABLED
"GL4ES", "GL4ES",
#endif #endif
#if XASH_REF_GLES3COMPAT_ENABLED
"GLES3 (gl2_shim)"
#endif
#if XASH_REF_SOFT_ENABLED #if XASH_REF_SOFT_ENABLED
"Software", "Software",
#endif #endif

View File

@@ -320,7 +320,9 @@ void Sys_RestoreCrashHandler( void )
#elif XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX #elif XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX
// Posix signal handler // Posix signal handler
#ifndef XASH_OPENBSD
#include <ucontext.h> #include <ucontext.h>
#endif
#include <signal.h> #include <signal.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "library.h" #include "library.h"

View File

@@ -139,7 +139,7 @@ void Sys_PrintUsage( void )
O("-sdl_joy_old_api ","use SDL legacy joystick API") O("-sdl_joy_old_api ","use SDL legacy joystick API")
O("-sdl_renderer <n>","use alternative SDL_Renderer for software") O("-sdl_renderer <n>","use alternative SDL_Renderer for software")
#endif // XASH_SDL #endif // XASH_SDL
#if XASH_ANDROID #if XASH_ANDROID && !XASH_SDL
O("-nativeegl ","use native egl implementation. Use if screen does not update or black") O("-nativeegl ","use native egl implementation. Use if screen does not update or black")
#endif // XASH_ANDROID #endif // XASH_ANDROID
#if XASH_DOS #if XASH_DOS

View File

@@ -980,7 +980,7 @@ Mod_SampleSizeForFace
return the current lightmap resolution per face return the current lightmap resolution per face
================== ==================
*/ */
int Mod_SampleSizeForFace( msurface_t *surf ) int Mod_SampleSizeForFace( const msurface_t *surf )
{ {
if( !surf || !surf->texinfo ) if( !surf || !surf->texinfo )
return LM_SAMPLE_SIZE; return LM_SAMPLE_SIZE;

View File

@@ -155,7 +155,7 @@ int Mod_CheckLump( const char *filename, const int lump, int *lumpsize );
int Mod_ReadLump( const char *filename, const int lump, void **lumpdata, int *lumpsize ); int Mod_ReadLump( const char *filename, const int lump, void **lumpdata, int *lumpsize );
int Mod_SaveLump( const char *filename, const int lump, void *lumpdata, int lumpsize ); int Mod_SaveLump( const char *filename, const int lump, void *lumpdata, int lumpsize );
mleaf_t *Mod_PointInLeaf( const vec3_t p, mnode_t *node ); mleaf_t *Mod_PointInLeaf( const vec3_t p, mnode_t *node );
int Mod_SampleSizeForFace( msurface_t *surf ); int Mod_SampleSizeForFace( const msurface_t *surf );
byte *Mod_GetPVSForPoint( const vec3_t p ); byte *Mod_GetPVSForPoint( const vec3_t p );
void Mod_UnloadBrushModel( model_t *mod ); void Mod_UnloadBrushModel( model_t *mod );
void Mod_PrintWorldStats_f( void ); void Mod_PrintWorldStats_f( void );

View File

@@ -2200,6 +2200,8 @@ HTTP downloader
================================================= =================================================
*/ */
#define MAX_HTTP_BUFFER_SIZE (BIT( 13 ))
typedef struct httpserver_s typedef struct httpserver_s
{ {
char host[256]; char host[256];
@@ -2240,7 +2242,7 @@ typedef struct httpfile_s
qboolean process; qboolean process;
// query or response // query or response
char buf[BUFSIZ+1]; char buf[MAX_HTTP_BUFFER_SIZE+1];
int header_size, query_length, bytes_sent; int header_size, query_length, bytes_sent;
} httpfile_t; } httpfile_t;
@@ -2385,18 +2387,18 @@ process incoming data
*/ */
static qboolean HTTP_ProcessStream( httpfile_t *curfile ) static qboolean HTTP_ProcessStream( httpfile_t *curfile )
{ {
char buf[BUFSIZ+1]; char buf[sizeof( curfile->buf )];
char *begin = 0; char *begin = 0;
int res; int res;
if( curfile->header_size >= BUFSIZ ) if( curfile->header_size >= sizeof( buf ))
{ {
Con_Reportf( S_ERROR "Header to big\n"); Con_Reportf( S_ERROR "Header too big, the size is %s\n", curfile->header_size );
HTTP_FreeFile( curfile, true ); HTTP_FreeFile( curfile, true );
return false; return false;
} }
while( ( res = recv( curfile->socket, buf, BUFSIZ - curfile->header_size, 0 )) > 0) // if we got there, we are receiving data while( ( res = recv( curfile->socket, buf, sizeof( buf ) - curfile->header_size, 0 )) > 0) // if we got there, we are receiving data
{ {
curfile->blocktime = 0; curfile->blocktime = 0;
@@ -2409,7 +2411,7 @@ static qboolean HTTP_ProcessStream( httpfile_t *curfile )
if( begin ) // Got full header if( begin ) // Got full header
{ {
int cutheadersize = begin - curfile->buf + 4; // after that begin of data int cutheadersize = begin - curfile->buf + 4; // after that begin of data
char *length; char *content_length_line;
Con_Reportf( "HTTP: Got response!\n" ); Con_Reportf( "HTTP: Got response!\n" );
@@ -2428,10 +2430,13 @@ static qboolean HTTP_ProcessStream( httpfile_t *curfile )
} }
// print size // print size
length = Q_stristr( curfile->buf, "Content-Length: " ); content_length_line = Q_stristr( curfile->buf, "Content-Length: " );
if( length ) if( content_length_line )
{ {
int size = Q_atoi( length += 16 ); int size;
content_length_line += sizeof( "Content-Length: " ) - 1;
size = Q_atoi( content_length_line );
Con_Reportf( "HTTP: File size is %d\n", size ); Con_Reportf( "HTTP: File size is %d\n", size );
@@ -2873,6 +2878,10 @@ static void HTTP_AddCustomServer_f( void )
{ {
HTTP_AddCustomServer( Cmd_Argv( 1 )); HTTP_AddCustomServer( Cmd_Argv( 1 ));
} }
else
{
Con_Printf( S_USAGE "http_addcustomserver <url>\n" );
}
} }
/* /*

View File

@@ -632,12 +632,14 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
else else
{ {
const char* PATH = getenv("PATH"); const char* PATH = getenv("PATH");
const char* begin;
size_t argv0_length;
if (!PATH) if (!PATH)
break; break;
size_t argv0_length = strlen(argv[0]); argv0_length = strlen(argv[0]);
const char* begin = PATH; begin = PATH;
while (1) while (1)
{ {
const char* separator = strchr(begin, ':'); const char* separator = strchr(begin, ':');

View File

@@ -32,10 +32,9 @@ struct jnimethods_s
JNIEnv *env; JNIEnv *env;
jobject activity; jobject activity;
jclass actcls; jclass actcls;
jmethodID getID; jmethodID loadAndroidID;
jmethodID saveID; jmethodID getAndroidID;
jmethodID loadID; jmethodID saveAndroidID;
jmethodID getKeyboardHeight;
} jni; } jni;
void Android_Init( void ) void Android_Init( void )
@@ -43,10 +42,9 @@ void Android_Init( void )
jni.env = (JNIEnv *)SDL_AndroidGetJNIEnv(); jni.env = (JNIEnv *)SDL_AndroidGetJNIEnv();
jni.activity = (jobject)SDL_AndroidGetActivity(); jni.activity = (jobject)SDL_AndroidGetActivity();
jni.actcls = (*jni.env)->GetObjectClass( jni.env, jni.activity ); jni.actcls = (*jni.env)->GetObjectClass( jni.env, jni.activity );
jni.loadID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "loadAndroidID", "()Ljava/lang/String;" ); jni.loadAndroidID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "loadAndroidID", "()Ljava/lang/String;" );
jni.getID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "getAndroidID", "()Ljava/lang/String;" ); jni.getAndroidID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "getAndroidID", "()Ljava/lang/String;" );
jni.saveID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "saveAndroidID", "(Ljava/lang/String;)V" ); jni.saveAndroidID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "saveAndroidID", "(Ljava/lang/String;)V" );
jni.getKeyboardHeight = (*jni.env)->GetMethodID( jni.env, jni.actcls, "getKeyboardHeight", "()I" );
SDL_SetHint( SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight" ); SDL_SetHint( SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight" );
SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1" ); SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1" );
@@ -95,7 +93,7 @@ const char *Android_GetAndroidID( void )
if( COM_CheckString( id ) ) return id; if( COM_CheckString( id ) ) return id;
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getID ); resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAndroidID );
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL ); resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
Q_strncpy( id, resultCStr, sizeof( id ) ); Q_strncpy( id, resultCStr, sizeof( id ) );
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr ); (*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
@@ -114,7 +112,7 @@ const char *Android_LoadID( void )
jstring resultJNIStr; jstring resultJNIStr;
const char *resultCStr; const char *resultCStr;
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.loadID ); resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.loadAndroidID );
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL ); resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
Q_strncpy( id, resultCStr, sizeof( id ) ); Q_strncpy( id, resultCStr, sizeof( id ) );
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr ); (*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
@@ -129,7 +127,7 @@ Android_SaveID
*/ */
void Android_SaveID( const char *id ) void Android_SaveID( const char *id )
{ {
(*jni.env)->CallVoidMethod( jni.env, jni.activity, jni.saveID, (*jni.env)->NewStringUTF( jni.env, id ) ); (*jni.env)->CallVoidMethod( jni.env, jni.activity, jni.saveAndroidID, (*jni.env)->NewStringUTF( jni.env, id ) );
} }
/* /*
@@ -144,14 +142,4 @@ void Platform_ShellExecute( const char *path, const char *parms )
#endif #endif
} }
/*
========================
Android_GetKeyboardHeight
========================
*/
int Android_GetKeyboardHeight( void )
{
return (*jni.env)->CallIntMethod( jni.env, jni.activity, jni.getKeyboardHeight );
}
#endif // XASH_DEDICATED #endif // XASH_DEDICATED

View File

@@ -63,7 +63,6 @@ const char *Android_LoadID( void );
void Android_SaveID( const char *id ); void Android_SaveID( const char *id );
void Android_Init( void ); void Android_Init( void );
void *Android_GetNativeObject( const char *name ); void *Android_GetNativeObject( const char *name );
int Android_GetKeyboardHeight( void );
#endif #endif
#if XASH_WIN32 #if XASH_WIN32

View File

@@ -307,7 +307,7 @@ typedef struct ref_api_s
qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType ); qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType );
// brushes // brushes
int (*Mod_SampleSizeForFace)( struct msurface_s *surf ); int (*Mod_SampleSizeForFace)( const struct msurface_s *surf );
qboolean (*Mod_BoxVisible)( const vec3_t mins, const vec3_t maxs, const byte *visbits ); qboolean (*Mod_BoxVisible)( const vec3_t mins, const vec3_t maxs, const byte *visbits );
struct world_static_s *(*GetWorld)( void ); // returns &world struct world_static_s *(*GetWorld)( void ); // returns &world
mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node ); mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node );

View File

@@ -472,6 +472,8 @@ extern convar_t sv_userinfo_penalty_multiplier;
extern convar_t sv_userinfo_penalty_attempts; extern convar_t sv_userinfo_penalty_attempts;
extern convar_t sv_fullupdate_penalty_time; extern convar_t sv_fullupdate_penalty_time;
extern convar_t sv_log_outofband; extern convar_t sv_log_outofband;
extern convar_t sv_allow_autoaim;
extern convar_t sv_aim;
//=========================================================== //===========================================================
// //

View File

@@ -1772,6 +1772,9 @@ static qboolean SV_ShouldUpdateUserinfo( sv_client_t *cl )
if( FBitSet( cl->flags, FCL_FAKECLIENT )) if( FBitSet( cl->flags, FCL_FAKECLIENT ))
return allow; return allow;
if( Host_IsLocalGame( ))
return allow;
// start from 1 second // start from 1 second
if( !cl->userinfo_penalty ) if( !cl->userinfo_penalty )
cl->userinfo_penalty = sv_userinfo_penalty_time.value; cl->userinfo_penalty = sv_userinfo_penalty_time.value;

View File

@@ -2385,7 +2385,9 @@ static void GAME_EXPORT pfnGetAimVector( edict_t* ent, float speed, float *rgflR
// try all possible entities // try all possible entities
VectorCopy( svgame.globals->v_forward, bestdir ); VectorCopy( svgame.globals->v_forward, bestdir );
bestdist = Cvar_VariableValue( "sv_aim" ); if( sv_allow_autoaim.value )
bestdist = sv_aim.value;
else bestdist = 0;
check = EDICT_NUM( 1 ); // start at first client check = EDICT_NUM( 1 ); // start at first client
for( i = 1; i < svgame.numEntities; i++, check++ ) for( i = 1; i < svgame.numEntities; i++, check++ )
@@ -4965,12 +4967,6 @@ static qboolean SV_ParseEdict( char **pfile, edict_t *ent )
pkvd[i].szValue = copystring( temp ); pkvd[i].szValue = copystring( temp );
} }
#endif #endif
if( !Q_strcmp( pkvd[i].szKeyName, "light" ))
{
Mem_Free( pkvd[i].szKeyName );
pkvd[i].szKeyName = copystring( "light_level" );
}
if( !pkvd[i].fHandled ) if( !pkvd[i].fHandled )
{ {
pkvd[i].szClassName = classname; pkvd[i].szClassName = classname;

View File

@@ -23,6 +23,7 @@ CVAR_DEFINE_AUTO( sv_lan, "0", 0, "server is a lan server ( no heartbeat, no aut
CVAR_DEFINE_AUTO( sv_lan_rate, "20000.0", 0, "rate for lan server" ); CVAR_DEFINE_AUTO( sv_lan_rate, "20000.0", 0, "rate for lan server" );
CVAR_DEFINE_AUTO( sv_nat, "0", 0, "enable NAT bypass for this server" ); CVAR_DEFINE_AUTO( sv_nat, "0", 0, "enable NAT bypass for this server" );
CVAR_DEFINE_AUTO( sv_aim, "1", FCVAR_ARCHIVE|FCVAR_SERVER, "auto aiming option" ); CVAR_DEFINE_AUTO( sv_aim, "1", FCVAR_ARCHIVE|FCVAR_SERVER, "auto aiming option" );
CVAR_DEFINE_AUTO( sv_allow_autoaim, "0", FCVAR_ARCHIVE|FCVAR_SERVER, "auto aiming option (for HL25 compatibility)" );
CVAR_DEFINE_AUTO( sv_unlag, "1", 0, "allow lag compensation on server-side" ); CVAR_DEFINE_AUTO( sv_unlag, "1", 0, "allow lag compensation on server-side" );
CVAR_DEFINE_AUTO( sv_maxunlag, "0.5", 0, "max latency value which can be interpolated (by default ping should not exceed 500 units)" ); CVAR_DEFINE_AUTO( sv_maxunlag, "0.5", 0, "max latency value which can be interpolated (by default ping should not exceed 500 units)" );
CVAR_DEFINE_AUTO( sv_unlagpush, "0.0", 0, "interpolation bias for unlag time" ); CVAR_DEFINE_AUTO( sv_unlagpush, "0.0", 0, "interpolation bias for unlag time" );
@@ -885,6 +886,7 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_fps ); Cvar_RegisterVariable( &sv_fps );
Cvar_RegisterVariable( &showtriggers ); Cvar_RegisterVariable( &showtriggers );
Cvar_RegisterVariable( &sv_aim ); Cvar_RegisterVariable( &sv_aim );
Cvar_RegisterVariable( &sv_allow_autoaim );
Cvar_RegisterVariable( &deathmatch ); Cvar_RegisterVariable( &deathmatch );
Cvar_RegisterVariable( &coop ); Cvar_RegisterVariable( &coop );
Cvar_RegisterVariable( &teamplay ); Cvar_RegisterVariable( &teamplay );

View File

@@ -984,7 +984,10 @@ static void ParseSaveTables( SAVERESTOREDATA *pSaveData, SAVE_HEADER *pHeader, i
InitEntityTable( pSaveData, pSaveData->tableCount ); InitEntityTable( pSaveData, pSaveData->tableCount );
for( i = 0; i < pSaveData->tableCount; i++ ) for( i = 0; i < pSaveData->tableCount; i++ )
{
svgame.dllFuncs.pfnSaveReadFields( pSaveData, "ETABLE", &pSaveData->pTable[i], gEntityTable, ARRAYSIZE( gEntityTable )); svgame.dllFuncs.pfnSaveReadFields( pSaveData, "ETABLE", &pSaveData->pTable[i], gEntityTable, ARRAYSIZE( gEntityTable ));
pSaveData->pTable[i].pent = NULL;
}
pSaveData->pBaseData = pSaveData->pCurrentData; pSaveData->pBaseData = pSaveData->pCurrentData;
pSaveData->size = 0; pSaveData->size = 0;

View File

@@ -225,9 +225,13 @@ def build(bld):
# Switch and PSVita have custom parameters # Switch and PSVita have custom parameters
if bld.env.DEST_OS in ['nswitch', 'psvita']: if bld.env.DEST_OS in ['nswitch', 'psvita']:
program = 'cxxprogram'
if bld.env.DEST_OS == 'nswitch':
program = 'cprogram' # avoid linking with g++, we link standard library explicitly
bld(source = source, bld(source = source,
target = 'xash', target = 'xash',
features = 'c cxxprogram', features = ['c', program],
includes = includes, includes = includes,
use = libs, use = libs,
install_path = None, install_path = None,

View File

@@ -233,6 +233,13 @@ public:
return FS_FileTime( p, false ); return FS_FileTime( p, false );
} }
long int GetFileModificationTime( const char *path )
{
// TODO: properly reverse-engineer this
FixupPath( p, path );
return FS_FileTime( p, false );
}
void FileTimeToString( char *p, int size, long int time ) override void FileTimeToString( char *p, int size, long int time ) override
{ {
const time_t curtime = time; const time_t curtime = time;

View File

@@ -40,8 +40,7 @@ public:
virtual ~IBaseInterface() {} virtual ~IBaseInterface() {}
}; };
class IVFileSystem009 : public IBaseInterface class IVFileSystem009 : public IBaseInterface {
{
public: public:
virtual void Mount() = 0; /* linkage=_ZN11IFileSystem5MountEv */ virtual void Mount() = 0; /* linkage=_ZN11IFileSystem5MountEv */
@@ -148,6 +147,8 @@ public:
virtual FileHandle_t OpenFromCacheForRead(const char *, const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20OpenFromCacheForReadEPKcS1_S1_ */ virtual FileHandle_t OpenFromCacheForRead(const char *, const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20OpenFromCacheForReadEPKcS1_S1_ */
virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */ virtual void AddSearchPathNoWrite(const char *, const char *) = 0; /* linkage=_ZN11IFileSystem20AddSearchPathNoWriteEPKcS1_ */
virtual long int GetFileModificationTime(const char *) = 0; /* linkage=_ZN11IFileSystem23GetFileModificationTimeEPKc */
}; };
#endif // VFILESYSTEM009_H #endif // VFILESYSTEM009_H

325
filesystem/android.c Normal file
View File

@@ -0,0 +1,325 @@
/*
android.c - android support for filesystem
Copyright (C) 2022 Velaron
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 "port.h"
#if XASH_ANDROID
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include STDINT_H
#include "filesystem_internal.h"
#include "crtlib.h"
#include "xash3d_mathlib.h"
#include "common/com_strings.h"
#include <jni.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <time.h>
struct android_assets_s
{
string package_name;
qboolean engine;
AAssetManager *asset_manager;
AAssetDir *dir;
};
struct jni_methods_s
{
JNIEnv *env;
jobject activity;
jclass activity_class;
jmethodID getPackageName;
jmethodID getCallingPackage;
jmethodID getAssetsList;
jmethodID getAssets;
} jni;
static void Android_GetAssetManager( android_assets_t *assets )
{
jobject assetManager;
assetManager = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAssets, assets->engine );
if( assetManager )
assets->asset_manager = AAssetManager_fromJava( jni.env, assetManager );
else if( assets->engine )
Con_Reportf( S_WARN "Couldn't add engine assets!" );
}
static const char *Android_GetPackageName( qboolean engine )
{
static string pkg;
jstring resultJNIStr;
const char *resultCStr;
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, engine ? jni.getPackageName : jni.getCallingPackage );
if( !resultJNIStr )
return NULL;
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
Q_strncpy( pkg, resultCStr, sizeof( pkg ));
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
return pkg;
}
static void Android_ListDirectory( stringlist_t *list, const char *path, qboolean engine )
{
jstring JStr = (*jni.env)->NewStringUTF( jni.env, path );
jobjectArray JNIArray = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAssetsList, engine, JStr );
int JNIArraySize = (*jni.env)->GetArrayLength( jni.env, JNIArray );
for( int i = 0; i < JNIArraySize; i++ )
{
jstring JNIStr = (*jni.env)->GetObjectArrayElement( jni.env, JNIArray, i );
const char *CStr = (*jni.env)->GetStringUTFChars( jni.env, JNIStr, NULL );
stringlistappend( list, (char *)CStr );
(*jni.env)->ReleaseStringUTFChars( jni.env, JNIStr, CStr );
}
}
static void FS_CloseAndroidAssets( android_assets_t *assets )
{
if( assets->dir )
AAssetDir_close( assets->dir );
Mem_Free( assets );
}
static android_assets_t *FS_LoadAndroidAssets( qboolean engine )
{
android_assets_t *assets = Mem_Calloc( fs_mempool, sizeof( *assets ));
assets->engine = engine;
Android_GetAssetManager( assets );
if( !assets->asset_manager )
{
FS_CloseAndroidAssets( assets );
return NULL;
}
assets->dir = AAssetManager_openDir( assets->asset_manager, "" );
if( !assets->dir )
{
FS_CloseAndroidAssets( assets );
return NULL;
}
return assets;
}
static int FS_FileTime_AndroidAssets( searchpath_t *search, const char *filename )
{
static time_t time;
if( !time )
{
struct tm file_tm;
strptime( __DATE__ " "__TIME__, "%b %d %Y %H:%M:%S", &file_tm );
time = mktime( &file_tm );
}
return time;
}
static int FS_FindFile_AndroidAssets( struct searchpath_s *search, const char *path, char *fixedname, size_t len )
{
AAsset *assets = AAssetManager_open( search->assets->asset_manager, path, AASSET_MODE_UNKNOWN );
if( assets )
{
AAsset_close( assets );
Q_strncpy( fixedname, path, len );
return 0;
}
return -1;
}
static void FS_PrintInfo_AndroidAssets( searchpath_t *search, char *dst, size_t size )
{
Q_snprintf( dst, size, "%s", search->assets->package_name );
}
static void FS_Close_AndroidAssets( searchpath_t *search )
{
FS_CloseAndroidAssets( search->assets );
}
static void FS_Search_AndroidAssets( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{
string temp;
stringlist_t dirlist;
const char *slash, *backslash, *colon, *separator;
int basepathlength, dirlistindex, resultlistindex;
char *basepath;
slash = Q_strrchr( pattern, '/' );
backslash = Q_strrchr( pattern, '\\' );
colon = Q_strrchr( pattern, ':' );
separator = Q_max( slash, backslash );
separator = Q_max( separator, colon );
basepathlength = separator ? (separator + 1 - pattern) : 0;
basepath = Mem_Calloc( fs_mempool, basepathlength + 1 );
if( basepathlength )
memcpy( basepath, pattern, basepathlength );
basepath[basepathlength] = '\0';
stringlistinit( &dirlist );
Android_ListDirectory( &dirlist, basepath, search->assets->engine );
Q_strncpy( temp, basepath, sizeof( temp ));
for( dirlistindex = 0; dirlistindex < dirlist.numstrings; dirlistindex++ )
{
Q_strncpy( &temp[basepathlength], dirlist.strings[dirlistindex], sizeof( temp ) - basepathlength );
if( matchpattern( temp, (char *)pattern, true ))
{
for( resultlistindex = 0; resultlistindex < list->numstrings; resultlistindex++ )
{
if( !Q_strcmp( list->strings[resultlistindex], temp ))
break;
}
if( resultlistindex == list->numstrings )
stringlistappend( list, temp );
}
}
stringlistfreecontents( &dirlist );
Mem_Free( basepath );
}
static file_t *FS_OpenFile_AndroidAssets( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
{
file_t *file = Mem_Calloc( fs_mempool, sizeof( *file ));
AAsset *assets = AAssetManager_open( search->assets->asset_manager, filename, AASSET_MODE_RANDOM );
file->handle = AAsset_openFileDescriptor( assets, &file->offset, &file->real_length );
file->position = 0;
file->ungetc = EOF;
AAsset_close( assets );
return file;
}
static byte *FS_LoadAndroidAssetsFile( searchpath_t *search, const char *path, int pack_ind, fs_offset_t *filesize )
{
byte *buf;
off_t size;
AAsset *asset;
if( filesize ) *filesize = 0;
asset = AAssetManager_open( search->assets->asset_manager, path, AASSET_MODE_RANDOM );
if( !asset )
return NULL;
size = AAsset_getLength( asset );
buf = (byte *)Mem_Malloc( fs_mempool, size + 1 );
buf[size] = '\0';
if( AAsset_read( asset, buf, size ) < 0 )
{
Mem_Free( buf );
AAsset_close( asset );
return NULL;
}
AAsset_close( asset );
if( filesize ) *filesize = size;
return buf;
}
searchpath_t *FS_AddAndroidAssets_Fullpath( const char *path, int flags )
{
searchpath_t *search;
android_assets_t *assets = NULL;
qboolean engine = true;
if( FBitSet( flags, FS_STATIC_PATH | FS_CUSTOM_PATH ))
return NULL;
if( FBitSet( flags, FS_GAMEDIR_PATH ) && Q_stricmp( GI->basedir, GI->gamefolder ))
engine = false;
assets = FS_LoadAndroidAssets( engine );
if( !assets )
{
Con_Reportf( S_ERROR "%s: unable to load Android assets \"%s\"\n", __FUNCTION__, Android_GetPackageName( engine ));
return NULL;
}
Q_strncpy( assets->package_name, Android_GetPackageName( engine ), sizeof( assets->package_name ));
search = Mem_Calloc( fs_mempool, sizeof( *search ));
Q_strncpy( search->filename, assets->package_name, sizeof( search->filename ));
search->assets = assets;
search->type = SEARCHPATH_ANDROID_ASSETS;
SetBits( search->flags, FS_NOWRITE_PATH | FS_CUSTOM_PATH );
search->pfnPrintInfo = FS_PrintInfo_AndroidAssets;
search->pfnClose = FS_Close_AndroidAssets;
search->pfnOpenFile = FS_OpenFile_AndroidAssets;
search->pfnFileTime = FS_FileTime_AndroidAssets;
search->pfnFindFile = FS_FindFile_AndroidAssets;
search->pfnSearch = FS_Search_AndroidAssets;
search->pfnLoadFile = FS_LoadAndroidAssetsFile;
Con_Reportf( "Adding Android assets: %s\n", assets->package_name );
return search;
}
void FS_InitAndroid( void )
{
jmethodID getContext;
jni.env = (JNIEnv *)Sys_GetNativeObject( "JNIEnv" );
jni.activity_class = Sys_GetNativeObject( "ActivityClass" );
getContext = (*jni.env)->GetStaticMethodID( jni.env, jni.activity_class, "getContext", "()Landroid/content/Context;" );
jni.activity = (*jni.env)->CallStaticObjectMethod( jni.env, jni.activity_class, getContext );
jni.getPackageName = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getPackageName", "()Ljava/lang/String;" );
jni.getCallingPackage = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getCallingPackage", "()Ljava/lang/String;" );
jni.getAssetsList = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getAssetsList", "(ZLjava/lang/String;)[Ljava/lang/String;" );
jni.getAssets = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getAssets", "(Z)Landroid/content/res/AssetManager;" );
}
#endif // XASH_ANDROID

View File

@@ -34,6 +34,7 @@ GNU General Public License for more details.
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "port.h" #include "port.h"
#include "defaults.h"
#include "const.h" #include "const.h"
#include "crtlib.h" #include "crtlib.h"
#include "crclib.h" #include "crclib.h"
@@ -71,8 +72,10 @@ const fs_archive_t g_archives[] =
static const fs_archive_t g_directory_archive = static const fs_archive_t g_directory_archive =
{ NULL, SEARCHPATH_PLAIN, FS_AddDir_Fullpath, false }; { NULL, SEARCHPATH_PLAIN, FS_AddDir_Fullpath, false };
// static const fs_archive_t g_android_archive = #ifdef XASH_ANDROID
// { NULL, SEARCHPATH_ANDROID, FS_AddAndroid_Fullpath, false, false }; static const fs_archive_t g_android_archive =
{ NULL, SEARCHPATH_ANDROID_ASSETS, FS_AddAndroidAssets_Fullpath, false };
#endif
#ifdef XASH_REDUCE_FD #ifdef XASH_REDUCE_FD
static file_t *fs_last_readfile; static file_t *fs_last_readfile;
@@ -154,7 +157,7 @@ void stringlistfreecontents( stringlist_t *list )
list->strings = NULL; list->strings = NULL;
} }
void stringlistappend( stringlist_t *list, char *text ) void stringlistappend( stringlist_t *list, const char *text )
{ {
size_t textlen; size_t textlen;
@@ -403,6 +406,10 @@ void FS_AddGameDirectory( const char *dir, uint flags )
stringlistfreecontents( &list ); stringlistfreecontents( &list );
#ifdef XASH_ANDROID
FS_AddArchive_Fullpath( &g_android_archive, dir, flags );
#endif
// add the directory to the search path // add the directory to the search path
// (unpacked files have the priority over packed files) // (unpacked files have the priority over packed files)
search = FS_AddArchive_Fullpath( &g_directory_archive, dir, flags ); search = FS_AddArchive_Fullpath( &g_directory_archive, dir, flags );
@@ -596,7 +603,7 @@ static void FS_WriteGameInfo( const char *filepath, gameinfo_t *GameInfo )
} }
if( GameInfo->noskills ) if( GameInfo->noskills )
FS_Printf( f, "noskills\t\t\"%i\"\n", GameInfo->nomodels ); FS_Printf( f, "noskills\t\t\"%i\"\n", GameInfo->noskills );
#define SAVE_AGED_COUNT 2 // the default count of quick and auto saves #define SAVE_AGED_COUNT 2 // the default count of quick and auto saves
if( GameInfo->quicksave_aged_count != SAVE_AGED_COUNT ) if( GameInfo->quicksave_aged_count != SAVE_AGED_COUNT )
@@ -606,6 +613,13 @@ static void FS_WriteGameInfo( const char *filepath, gameinfo_t *GameInfo )
FS_Printf( f, "autosave_aged_count\t\t%d\n", GameInfo->autosave_aged_count ); FS_Printf( f, "autosave_aged_count\t\t%d\n", GameInfo->autosave_aged_count );
#undef SAVE_AGED_COUNT #undef SAVE_AGED_COUNT
// HL25 compatibility
if( GameInfo->animated_title )
FS_Printf( f, "animated_title\t\t%i\n", GameInfo->animated_title );
if( GameInfo->hd_background )
FS_Printf( f, "hd_background\t\t%i\n", GameInfo->hd_background );
// always expose our extensions :) // always expose our extensions :)
FS_Printf( f, "internal_vgui_support\t\t%s\n", GameInfo->internal_vgui_support ? "1" : "0" ); FS_Printf( f, "internal_vgui_support\t\t%s\n", GameInfo->internal_vgui_support ? "1" : "0" );
FS_Printf( f, "render_picbutton_text\t\t%s\n", GameInfo->render_picbutton_text ? "1" : "0" ); FS_Printf( f, "render_picbutton_text\t\t%s\n", GameInfo->render_picbutton_text ? "1" : "0" );
@@ -638,7 +652,7 @@ void FS_InitGameInfo( gameinfo_t *GameInfo, const char *gamedir )
Q_strncpy( GameInfo->sp_entity, "info_player_start", sizeof( GameInfo->sp_entity )); Q_strncpy( GameInfo->sp_entity, "info_player_start", sizeof( GameInfo->sp_entity ));
Q_strncpy( GameInfo->mp_entity, "info_player_deathmatch", sizeof( GameInfo->mp_entity )); Q_strncpy( GameInfo->mp_entity, "info_player_deathmatch", sizeof( GameInfo->mp_entity ));
GameInfo->max_edicts = 900; // default value if not specified GameInfo->max_edicts = DEFAULT_MAX_EDICTS; // default value if not specified
GameInfo->max_tents = 500; GameInfo->max_tents = 500;
GameInfo->max_beams = 128; GameInfo->max_beams = 128;
GameInfo->max_particles = 4096; GameInfo->max_particles = 4096;
@@ -783,6 +797,17 @@ void FS_ParseGenericGameInfo( gameinfo_t *GameInfo, const char *buf, const qbool
pfile = COM_ParseFile( pfile, token, sizeof( token )); pfile = COM_ParseFile( pfile, token, sizeof( token ));
GameInfo->max_edicts = bound( MIN_EDICTS, Q_atoi( token ), MAX_EDICTS ); GameInfo->max_edicts = bound( MIN_EDICTS, Q_atoi( token ), MAX_EDICTS );
} }
// valid for both
else if( !Q_stricmp( token, "hd_background" ))
{
pfile = COM_ParseFile( pfile, token, sizeof( token ));
GameInfo->hd_background = Q_atoi( token ) ? true : false;
}
else if( !Q_stricmp( token, "animated_title" ))
{
pfile = COM_ParseFile( pfile, token, sizeof( token ));
GameInfo->animated_title = Q_atoi( token ) ? true : false;
}
// only for gameinfo // only for gameinfo
else if( isGameInfo ) else if( isGameInfo )
{ {
@@ -1406,6 +1431,10 @@ qboolean FS_InitStdio( qboolean unused_set_to_true, const char *rootdir, const c
FS_InitMemory(); FS_InitMemory();
#ifdef XASH_ANDROID
FS_InitAndroid();
#endif
Q_strncpy( fs_rootdir, rootdir, sizeof( fs_rootdir )); Q_strncpy( fs_rootdir, rootdir, sizeof( fs_rootdir ));
Q_strncpy( fs_gamedir, gamedir, sizeof( fs_gamedir )); Q_strncpy( fs_gamedir, gamedir, sizeof( fs_gamedir ));
Q_strncpy( fs_basedir, basedir, sizeof( fs_basedir )); Q_strncpy( fs_basedir, basedir, sizeof( fs_basedir ));

View File

@@ -106,6 +106,10 @@ typedef struct gameinfo_s
int quicksave_aged_count; // min is 1, max is 99 int quicksave_aged_count; // min is 1, max is 99
int autosave_aged_count; // min is 1, max is 99 int autosave_aged_count; // min is 1, max is 99
// HL25 compatibility keys
qboolean hd_background;
qboolean animated_title;
} gameinfo_t; } gameinfo_t;
typedef enum typedef enum

View File

@@ -22,6 +22,10 @@ GNU General Public License for more details.
#include "xash3d_types.h" #include "xash3d_types.h"
#include "filesystem.h" #include "filesystem.h"
#if XASH_ANDROID
#include <android/asset_manager.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@@ -31,6 +35,10 @@ typedef struct dir_s dir_t;
typedef struct zip_s zip_t; typedef struct zip_s zip_t;
typedef struct pack_s pack_t; typedef struct pack_s pack_t;
typedef struct wfile_s wfile_t; typedef struct wfile_s wfile_t;
#if XASH_ANDROID
typedef struct android_assets_s android_assets_t;
// typedef struct android_saf_s android_saf_t;
#endif
#define FILE_BUFF_SIZE (2048) #define FILE_BUFF_SIZE (2048)
@@ -58,7 +66,8 @@ enum
SEARCHPATH_PAK, SEARCHPATH_PAK,
SEARCHPATH_WAD, SEARCHPATH_WAD,
SEARCHPATH_ZIP, SEARCHPATH_ZIP,
SEARCHPATH_PK3DIR, // it's actually a plain directory but it must behave like a ZIP archive SEARCHPATH_PK3DIR, // it's actually a plain directory but it must behave like a ZIP archive,
SEARCHPATH_ANDROID_ASSETS
}; };
typedef struct stringlist_s typedef struct stringlist_s
@@ -81,6 +90,9 @@ typedef struct searchpath_s
pack_t *pack; pack_t *pack;
wfile_t *wad; wfile_t *wad;
zip_t *zip; zip_t *zip;
#if XASH_ANDROID
android_assets_t *assets;
#endif
}; };
struct searchpath_s *next; struct searchpath_s *next;
@@ -179,7 +191,7 @@ qboolean MD5_HashFile( byte digest[16], const char *pszFileName, uint seed[4] );
// stringlist ops // stringlist ops
void stringlistinit( stringlist_t *list ); void stringlistinit( stringlist_t *list );
void stringlistfreecontents( stringlist_t *list ); void stringlistfreecontents( stringlist_t *list );
void stringlistappend( stringlist_t *list, char *text ); void stringlistappend( stringlist_t *list, const char *text );
void stringlistsort( stringlist_t *list ); void stringlistsort( stringlist_t *list );
void listdirectory( stringlist_t *list, const char *path ); void listdirectory( stringlist_t *list, const char *path );
@@ -225,6 +237,12 @@ searchpath_t *FS_AddDir_Fullpath( const char *path, int flags );
qboolean FS_FixFileCase( dir_t *dir, const char *path, char *dst, const size_t len, qboolean createpath ); qboolean FS_FixFileCase( dir_t *dir, const char *path, char *dst, const size_t len, qboolean createpath );
void FS_InitDirectorySearchpath( searchpath_t *search, const char *path, int flags ); void FS_InitDirectorySearchpath( searchpath_t *search, const char *path, int flags );
//
// android.c
//
void FS_InitAndroid( void );
searchpath_t *FS_AddAndroidAssets_Fullpath( const char *path, int flags );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -10,19 +10,19 @@ def configure(conf):
} }
conf.env.append_unique('CXXFLAGS', conf.get_flags_by_compiler(nortti, conf.env.COMPILER_CC)) conf.env.append_unique('CXXFLAGS', conf.get_flags_by_compiler(nortti, conf.env.COMPILER_CC))
if conf.env.DEST_OS != 'android': if conf.env.DEST_OS == 'android':
if conf.env.cxxshlib_PATTERN.startswith('lib'): conf.check_cc(lib='android')
elif conf.env.cxxshlib_PATTERN.startswith('lib'): # remove lib prefix for other systems than Android
conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:] conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:]
def build(bld): def build(bld):
bld(name = 'filesystem_includes', export_includes = '.') bld(name = 'filesystem_includes', export_includes = '.')
libs = [ 'filesystem_includes' ] libs = [ 'filesystem_includes', 'sdk_includes' ]
# on PSVita do not link any libraries that are already in the main executable, but add the includes target # on PSVita do not link any libraries that are already in the main executable, but add the includes target
if bld.env.DEST_OS == 'psvita': if bld.env.DEST_OS != 'psvita':
libs += [ 'sdk_includes' ] libs += [ 'public', 'ANDROID' ]
else:
libs += [ 'public' ]
bld.shlib(target = 'filesystem_stdio', bld.shlib(target = 'filesystem_stdio',
features = 'cxx seq', features = 'cxx seq',

View File

@@ -21,21 +21,19 @@ def configure(conf):
conf.define_cond('XASH_DISABLE_MENU_CHANGEGAME', conf.options.DISABLE_MENU_CHANGEGAME) conf.define_cond('XASH_DISABLE_MENU_CHANGEGAME', conf.options.DISABLE_MENU_CHANGEGAME)
def build(bld): def build(bld):
libs = ['sdk_includes']
source = ['game.cpp'] source = ['game.cpp']
defines = []
if bld.env.DEST_OS != 'win32': if bld.env.DEST_OS == 'win32':
libs += [ 'DL' ]
else:
libs += ['USER32', 'SHELL32']
source += ['game.rc'] source += ['game.rc']
# Half-Life 25th anniversary update doesn't have server library explicitly linked to libm
if bld.env.DEST_OS == 'linux':
bld.env.LDFLAGS += ['-Wl,--no-as-needed', '-lm']
bld(source = source, bld(source = source,
target = 'xash3d', # hl.exe target = 'xash3d', # hl.exe
features = 'c cxx cxxprogram', features = 'c cxx cxxprogram',
use = libs, use = 'sdk_includes DL USER32 SHELL32',
defines = defines,
rpath = bld.env.DEFAULT_RPATH, rpath = bld.env.DEFAULT_RPATH,
install_path = bld.env.BINDIR, install_path = bld.env.BINDIR,
subsystem = bld.env.MSVC_SUBSYSTEM subsystem = bld.env.MSVC_SUBSYSTEM

View File

@@ -384,18 +384,6 @@ void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, v
// //
// bounds operations // bounds operations
// //
/*
=================
ClearBounds
=================
*/
void ClearBounds( vec3_t mins, vec3_t maxs )
{
// make bogus range
mins[0] = mins[1] = mins[2] = 999999.0f;
maxs[0] = maxs[1] = maxs[2] = -999999.0f;
}
/* /*
================= =================
AddPointToBounds AddPointToBounds
@@ -416,7 +404,7 @@ void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs )
/* /*
================= =================
ExpandBounds ExpandBounds (not used anywhere?)
================= =================
*/ */
void ExpandBounds( vec3_t mins, vec3_t maxs, float offset ) void ExpandBounds( vec3_t mins, vec3_t maxs, float offset )
@@ -429,34 +417,6 @@ void ExpandBounds( vec3_t mins, vec3_t maxs, float offset )
maxs[2] += offset; maxs[2] += offset;
} }
/*
=================
BoundsIntersect
=================
*/
qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 )
{
if( mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2] )
return false;
if( maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2] )
return false;
return true;
}
/*
=================
BoundsAndSphereIntersect
=================
*/
qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius )
{
if( mins[0] > origin[0] + radius || mins[1] > origin[1] + radius || mins[2] > origin[2] + radius )
return false;
if( maxs[0] < origin[0] - radius || maxs[1] < origin[1] - radius || maxs[2] < origin[2] - radius )
return false;
return true;
}
/* /*
================= =================
SphereIntersect SphereIntersect

View File

@@ -195,10 +195,32 @@ void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles ); void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles );
void PlaneIntersect( const struct mplane_s *plane, const vec3_t p0, const vec3_t p1, vec3_t out ); void PlaneIntersect( const struct mplane_s *plane, const vec3_t p0, const vec3_t p1, vec3_t out );
void ClearBounds( vec3_t mins, vec3_t maxs ); static inline void ClearBounds( vec3_t mins, vec3_t maxs )
{
// make bogus range
mins[0] = mins[1] = mins[2] = 999999.0f;
maxs[0] = maxs[1] = maxs[2] = -999999.0f;
}
static inline qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 )
{
if( mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2] )
return false;
if( maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2] )
return false;
return true;
}
static inline qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius )
{
if( mins[0] > origin[0] + radius || mins[1] > origin[1] + radius || mins[2] > origin[2] + radius )
return false;
if( maxs[0] < origin[0] - radius || maxs[1] < origin[1] - radius || maxs[2] < origin[2] - radius )
return false;
return true;
}
void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 );
qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius );
qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir ); qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir );
float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ); float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
void ExpandBounds( vec3_t mins, vec3_t maxs, float offset ); void ExpandBounds( vec3_t mins, vec3_t maxs, float offset );

View File

@@ -34,7 +34,7 @@ Limitations:
#include "gl_local.h" #include "gl_local.h"
#ifndef XASH_GL_STATIC #ifndef XASH_GL_STATIC
#include "gl2_shim.h" #include "gl2_shim.h"
#include <malloc.h> #include ALLOCA_H
#define MAX_SHADERLEN 4096 #define MAX_SHADERLEN 4096
// increase this when adding more attributes // increase this when adding more attributes

View File

@@ -391,30 +391,15 @@ float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture, int *pV
// Generate lighting coordinates at each vertex for decal vertices v[] on surface psurf // Generate lighting coordinates at each vertex for decal vertices v[] on surface psurf
static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount )
{ {
float s, t;
mtexinfo_t *tex;
mextrasurf_t *info = surf->info;
float sample_size; float sample_size;
int j; int j;
sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); sample_size = gEngfuncs.Mod_SampleSizeForFace( surf );
tex = surf->texinfo;
for( j = 0; j < vertCount; j++, v += VERTEXSIZE ) for( j = 0; j < vertCount; j++, v += VERTEXSIZE )
{ {
// lightmap texture coordinates // lightmap texture coordinates
s = DotProduct( v, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; R_LightmapCoord( v, surf, sample_size, &v[5] );
s += surf->light_s * sample_size;
s += sample_size * 0.5f;
s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width;
t = DotProduct( v, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1];
t += surf->light_t * sample_size;
t += sample_size * 0.5f;
t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->height;
v[5] = s;
v[6] = t;
} }
} }

View File

@@ -439,6 +439,7 @@ void GL_ResetFogColor( void );
void R_GenerateVBO( void ); void R_GenerateVBO( void );
void R_ClearVBO( void ); void R_ClearVBO( void );
void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf ); void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf );
void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample_size, vec2_t coords );
// //
// gl_rpart.c // gl_rpart.c

View File

@@ -61,6 +61,52 @@ void Mod_SetOrthoBounds( const float *mins, const float *maxs )
Vector2Subtract( maxs, world_orthocenter, world_orthohalf ); Vector2Subtract( maxs, world_orthocenter, world_orthohalf );
} }
void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample_size, vec2_t coords )
{
const mextrasurf_t *info = surf->info;
float s, t;
s = DotProduct( v, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0];
s += surf->light_s * sample_size;
s += sample_size * 0.5f;
s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width;
t = DotProduct( v, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1];
t += surf->light_t * sample_size;
t += sample_size * 0.5f;
t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width;
Vector2Set( coords, s, t );
}
static void R_TextureCoord( const vec3_t v, const msurface_t *surf, vec2_t coords )
{
const mtexinfo_t *info = surf->texinfo;
float s, t;
s = DotProduct( v, info->vecs[0] );
t = DotProduct( v, info->vecs[1] );
if( !FBitSet( surf->flags, SURF_DRAWTURB ))
{
s = ( s + info->vecs[0][3] ) / info->texture->width;
t = ( t + info->vecs[1][3] ) / info->texture->height;
}
Vector2Set( coords, s, t );
}
static void R_GetEdgePosition( const model_t *mod, const msurface_t *fa, int i, vec3_t vec )
{
const int lindex = mod->surfedges[fa->firstedge + i];
const medge_t *pedges = mod->edges;
if( lindex > 0 )
VectorCopy( mod->vertexes[pedges[lindex].v[0]].position, vec );
else
VectorCopy( mod->vertexes[pedges[-lindex].v[1]].position, vec );
}
static void BoundPoly( int numverts, float *verts, vec3_t mins, vec3_t maxs ) static void BoundPoly( int numverts, float *verts, vec3_t mins, vec3_t maxs )
{ {
int i, j; int i, j;
@@ -81,9 +127,8 @@ static void BoundPoly( int numverts, float *verts, vec3_t mins, vec3_t maxs )
static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int numverts, float *verts ) static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int numverts, float *verts )
{ {
vec3_t front[SUBDIVIDE_SIZE], back[SUBDIVIDE_SIZE]; vec3_t front[SUBDIVIDE_SIZE], back[SUBDIVIDE_SIZE];
mextrasurf_t *warpinfo = warpface->info;
float dist[SUBDIVIDE_SIZE]; float dist[SUBDIVIDE_SIZE];
float m, frac, s, t, *v; float m, frac, *v;
int i, j, k, f, b; int i, j, k, f, b;
float sample_size; float sample_size;
vec3_t mins, maxs; vec3_t mins, maxs;
@@ -160,41 +205,13 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu
for( i = 0; i < numverts; i++, verts += 3 ) for( i = 0; i < numverts; i++, verts += 3 )
{ {
VectorCopy( verts, poly->verts[i] ); VectorCopy( verts, poly->verts[i] );
R_TextureCoord( verts, warpface, &poly->verts[i][3] );
if( FBitSet( warpface->flags, SURF_DRAWTURB ))
{
s = DotProduct( verts, warpface->texinfo->vecs[0] );
t = DotProduct( verts, warpface->texinfo->vecs[1] );
}
else
{
s = DotProduct( verts, warpface->texinfo->vecs[0] ) + warpface->texinfo->vecs[0][3];
t = DotProduct( verts, warpface->texinfo->vecs[1] ) + warpface->texinfo->vecs[1][3];
s /= warpface->texinfo->texture->width;
t /= warpface->texinfo->texture->height;
}
poly->verts[i][3] = s;
poly->verts[i][4] = t;
// for speed reasons // for speed reasons
if( !FBitSet( warpface->flags, SURF_DRAWTURB )) if( !FBitSet( warpface->flags, SURF_DRAWTURB ))
{ {
// lightmap texture coordinates // lightmap texture coordinates
s = DotProduct( verts, warpinfo->lmvecs[0] ) + warpinfo->lmvecs[0][3]; R_LightmapCoord( verts, warpface, sample_size, &poly->verts[i][5] );
s -= warpinfo->lightmapmins[0];
s += warpface->light_s * sample_size;
s += sample_size * 0.5f;
s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width;
t = DotProduct( verts, warpinfo->lmvecs[1] ) + warpinfo->lmvecs[1][3];
t -= warpinfo->lightmapmins[1];
t += warpface->light_t * sample_size;
t += sample_size * 0.5f;
t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->height;
poly->verts[i][5] = s;
poly->verts[i][6] = t;
} }
} }
} }
@@ -240,26 +257,16 @@ can be done reasonably.
void GL_SubdivideSurface( model_t *loadmodel, msurface_t *fa ) void GL_SubdivideSurface( model_t *loadmodel, msurface_t *fa )
{ {
vec3_t verts[SUBDIVIDE_SIZE]; vec3_t verts[SUBDIVIDE_SIZE];
int numverts; int i;
int i, lindex;
float *vec;
// convert edges back to a normal polygon // convert edges back to a normal polygon
numverts = 0;
for( i = 0; i < fa->numedges; i++ ) for( i = 0; i < fa->numedges; i++ )
{ R_GetEdgePosition( loadmodel, fa, i, verts[i] );
lindex = loadmodel->surfedges[fa->firstedge + i];
if( lindex > 0 ) vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
else vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
VectorCopy( vec, verts[numverts] );
numverts++;
}
SetBits( fa->flags, SURF_DRAWTURB_QUADS ); // predict state SetBits( fa->flags, SURF_DRAWTURB_QUADS ); // predict state
// do subdivide // do subdivide
SubdividePolygon_r( loadmodel, fa, numverts, verts[0] ); SubdividePolygon_r( loadmodel, fa, fa->numedges, verts[0] );
} }
/* /*
@@ -269,14 +276,10 @@ GL_BuildPolygonFromSurface
*/ */
void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
{ {
int i, lindex, lnumverts; int i, lnumverts;
medge_t *pedges, *r_pedge;
mextrasurf_t *info = fa->info;
float sample_size; float sample_size;
texture_t *tex; texture_t *tex;
gl_texture_t *glt; gl_texture_t *glt;
float *vec;
float s, t;
glpoly_t *poly; glpoly_t *poly;
if( !mod || !fa->texinfo || !fa->texinfo->texture ) if( !mod || !fa->texinfo || !fa->texinfo->texture )
@@ -296,7 +299,6 @@ void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
sample_size = gEngfuncs.Mod_SampleSizeForFace( fa ); sample_size = gEngfuncs.Mod_SampleSizeForFace( fa );
// reconstruct the polygon // reconstruct the polygon
pedges = mod->edges;
lnumverts = fa->numedges; lnumverts = fa->numedges;
// detach if already created, reconstruct again // detach if already created, reconstruct again
@@ -312,44 +314,9 @@ void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
for( i = 0; i < lnumverts; i++ ) for( i = 0; i < lnumverts; i++ )
{ {
lindex = mod->surfedges[fa->firstedge + i]; R_GetEdgePosition( mod, fa, i, poly->verts[i] );
R_TextureCoord( poly->verts[i], fa, &poly->verts[i][3] );
if( lindex > 0 ) R_LightmapCoord( poly->verts[i], fa, sample_size, &poly->verts[i][5] );
{
r_pedge = &pedges[lindex];
vec = mod->vertexes[r_pedge->v[0]].position;
}
else
{
r_pedge = &pedges[-lindex];
vec = mod->vertexes[r_pedge->v[1]].position;
}
s = DotProduct( vec, fa->texinfo->vecs[0] ) + fa->texinfo->vecs[0][3];
s /= fa->texinfo->texture->width;
t = DotProduct( vec, fa->texinfo->vecs[1] ) + fa->texinfo->vecs[1][3];
t /= fa->texinfo->texture->height;
VectorCopy( vec, poly->verts[i] );
poly->verts[i][3] = s;
poly->verts[i][4] = t;
// lightmap texture coordinates
s = DotProduct( vec, info->lmvecs[0] ) + info->lmvecs[0][3];
s -= info->lightmapmins[0];
s += fa->light_s * sample_size;
s += sample_size * 0.5f;
s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width;
t = DotProduct( vec, info->lmvecs[1] ) + info->lmvecs[1][3];
t -= info->lightmapmins[1];
t += fa->light_t * sample_size;
t += sample_size * 0.5f;
t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->height;
poly->verts[i][5] = s;
poly->verts[i][6] = t;
} }
// remove co-linear points - Ed // remove co-linear points - Ed

View File

@@ -16,7 +16,7 @@ build_engine()
if [ "$APP" = "xashds" ]; then if [ "$APP" = "xashds" ]; then
./waf configure -T release -d --enable-tests || die_configure ./waf configure -T release -d --enable-tests || die_configure
elif [ "$APP" = "xash3d-fwgs" ]; then elif [ "$APP" = "xash3d-fwgs" ]; then
./waf configure -T release --enable-stb --enable-utils --enable-gl4es --enable-gles1 --enable-gles2 --enable-tests || die_configure ./waf configure -T release --enable-utils --enable-gl4es --enable-gles1 --enable-gles2 --enable-tests || die_configure
else else
die die
fi fi

View File

@@ -1,25 +1,22 @@
#!/bin/bash #!/bin/bash
export ANDROID_SDK_HOME=$GITHUB_WORKSPACE/sdk unset ANDROID_SDK_ROOT
export ANDROID_NDK_HOME=$ANDROID_SDK_HOME/ndk-bundle export JAVA_HOME=$GITHUB_WORKSPACE/jdk-17.0.7+7
export ANDROID_HOME=$GITHUB_WORKSPACE/sdk
export PATH=$PATH:$JAVA_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/tools/bin
pushd android pushd android
if [[ "$GH_CPU_ARCH" == "32" ]]; then
export ARCHS="armeabi armeabi-v7a x86"
elif [[ "$GH_CPU_ARCH" == "64" ]]; then
export ARCHS="aarch64 x86_64"
elif [[ "$GH_CPU_ARCH" == "32&64" ]]; then
export ARCHS="armeabi armeabi-v7a x86 aarch64 x86_64"
fi
sh compile.sh release ./gradlew assembleContinuous
pushd app/build/outputs/apk/continuous
$ANDROID_HOME/build-tools/34.0.0/apksigner sign --ks $GITHUB_WORKSPACE/android/debug.keystore --ks-key-alias androiddebugkey \
--ks-pass pass:android --key-pass pass:android --out app-continuous-signed.apk app-continuous-unsigned.apk
popd
popd popd
mkdir -p artifacts/ mkdir -p artifacts/
if [[ "$GH_CPU_ARCH" == "64" ]]; then mv android/app/build/outputs/apk/continuous/app-continuous-signed.apk artifacts/xash3d-fwgs-android.apk
mv android/xashdroid.apk artifacts/xashdroid-64.apk
else
mv android/xashdroid.apk artifacts/xashdroid-32.apk
fi

View File

@@ -41,7 +41,7 @@ make -C libsolder install || die
echo "Building engine..." echo "Building engine..."
./waf configure -T release --nswitch || die_configure ./waf configure -T release --nswitch || die_configure
./waf build install --destdir=pkgtemp/xash3d || die ./waf build install --destdir=pkgtemp/xash3d -v || die
echo "Building HLSDK..." echo "Building HLSDK..."

View File

@@ -1,38 +1,43 @@
#!/bin/bash #!/bin/bash
echo "Download HLSDK"
cd $GITHUB_WORKSPACE cd $GITHUB_WORKSPACE
git clone --depth 1 --recursive https://github.com/FWGS/hlsdk-xash3d -b mobile_hacks hlsdk || exit 1
echo "Download and unpack Android SDK" echo "Download JDK 17"
wget https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.7_7.tar.gz -qO jdk.tar.gz || exit 1
tar -xzf jdk.tar.gz
export JAVA_HOME=$GITHUB_WORKSPACE/jdk-17.0.7+7
export PATH=$PATH:$JAVA_HOME/bin
echo "Download hlsdk-portable"
git clone --depth 1 --recursive https://github.com/FWGS/hlsdk-portable -b mobile_hacks hlsdk || exit 1
echo "Download Android SDK"
mkdir -p sdk || exit 1 mkdir -p sdk || exit 1
pushd sdk pushd sdk
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -qO sdk.zip > /dev/null || exit 1 wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip -qO sdk.zip || exit 1
unzip -q sdk.zip || exit 1 unzip -q sdk.zip || exit 1
mv cmdline-tools tools
mkdir -p cmdline-tools
mv tools cmdline-tools/tools
unset ANDROID_SDK_ROOT
export ANDROID_HOME=$GITHUB_WORKSPACE/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/tools/bin
popd popd
echo "Download all needed tools and NDK" echo "Download all needed tools and Android NDK"
yes | sdk/tools/bin/sdkmanager --licenses > /dev/null 2>/dev/null # who even reads licenses? :) yes | sdkmanager --licenses > /dev/null 2>/dev/null # who even reads licenses? :)
sdk/tools/bin/sdkmanager --install build-tools\;29.0.1 platform-tools platforms\;android-29 > /dev/null 2>/dev/null sdkmanager --install build-tools\;34.0.0 platform-tools platforms\;android-34 ndk\;26.0.10792818
wget https://dl.google.com/android/repository/android-ndk-r25-linux.zip -qO ndk.zip > /dev/null || exit 1
unzip -q ndk.zip || exit 1
mv android-ndk-r25 sdk/ndk-bundle || exit 1
echo "Download Xash3D FWGS Android source" echo "Download Xash3D FWGS Android source code"
git clone --depth 1 https://github.com/FWGS/xash3d-android-project -b waf android || exit 1 git clone --depth 1 --recursive https://github.com/Velaron/xash3d-android-project -b gradle android || exit 1
pushd android pushd android/app/src/main/cpp
mv xash3d-fwgs xash3d-fwgs-sub mv xash3d-fwgs xash3d-fwgs-sub
ln -s $GITHUB_WORKSPACE xash3d-fwgs ln -s $GITHUB_WORKSPACE xash3d-fwgs
echo "Installed Xash3D FWGS source symlink" echo "Installed Xash3D FWGS source symlink"
mv hlsdk-xash3d hlsdk-xash3d-sub mv hlsdk-portable hlsdk-portable-sub
ln -s $GITHUB_WORKSPACE/hlsdk hlsdk-xash3d ln -s $GITHUB_WORKSPACE/hlsdk hlsdk-portable
echo "Installed HLSDK source symlink" echo "Installed hlsdk-portable source symlink"
mv xash-extras xash-extras-sub
ln -s $GITHUB_WORKSPACE/xash-extras xash-extras
echo "Installed xash-extras symlink"
popd popd

View File

@@ -30,7 +30,7 @@ compiler_optimizations.CFLAGS['gottagofast'] = {
} }
''' '''
VALID_BUILD_TYPES = ['fastnative', 'fast', 'release', 'debug', 'sanitize', 'msan', 'none'] VALID_BUILD_TYPES = ['fastnative', 'fast', 'humanrights', 'debug', 'sanitize', 'msan', 'none']
LINKFLAGS = { LINKFLAGS = {
'common': { 'common': {
@@ -75,7 +75,7 @@ CFLAGS = {
'clang': ['-Ofast', '-march=native'], 'clang': ['-Ofast', '-march=native'],
'default': ['-O3'] 'default': ['-O3']
}, },
'release': { 'humanrights': {
'msvc': ['/O2', '/Zi'], 'msvc': ['/O2', '/Zi'],
'owcc': ['-O3', '-foptimize-sibling-calls', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-fschedule-insns', '-funsafe-math-optimizations', '-funroll-loops', '-frerun-optimizer', '-finline-functions', '-finline-limit=512', '-fguess-branch-probability', '-fno-strict-aliasing', '-floop-optimize'], 'owcc': ['-O3', '-foptimize-sibling-calls', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-fschedule-insns', '-funsafe-math-optimizations', '-funroll-loops', '-frerun-optimizer', '-finline-functions', '-finline-limit=512', '-fguess-branch-probability', '-fno-strict-aliasing', '-floop-optimize'],
'gcc': ['-O3', '-fno-semantic-interposition'], 'gcc': ['-O3', '-fno-semantic-interposition'],
@@ -119,7 +119,7 @@ POLLY_CFLAGS = {
def options(opt): def options(opt):
grp = opt.add_option_group('Compiler optimization options') grp = opt.add_option_group('Compiler optimization options')
grp.add_option('-T', '--build-type', action='store', dest='BUILD_TYPE', default='release', grp.add_option('-T', '--build-type', action='store', dest='BUILD_TYPE', default='humanrights',
help = 'build type: debug, release or none(custom flags)') help = 'build type: debug, release or none(custom flags)')
grp.add_option('--enable-lto', action = 'store_true', dest = 'LTO', default = False, grp.add_option('--enable-lto', action = 'store_true', dest = 'LTO', default = False,
@@ -131,6 +131,11 @@ def options(opt):
def configure(conf): def configure(conf):
conf.start_msg('Build type') conf.start_msg('Build type')
# legacy naming for default release build
# https://chaos.social/@karolherbst/111340511652012860
if conf.options.BUILD_TYPE == 'release':
conf.options.BUILD_TYPE = 'humanrights'
if not conf.options.BUILD_TYPE in VALID_BUILD_TYPES: if not conf.options.BUILD_TYPE in VALID_BUILD_TYPES:
conf.end_msg(conf.options.BUILD_TYPE, color='RED') conf.end_msg(conf.options.BUILD_TYPE, color='RED')
conf.fatal('Invalid build type. Valid are: %s' % ', '.join(VALID_BUILD_TYPES)) conf.fatal('Invalid build type. Valid are: %s' % ', '.join(VALID_BUILD_TYPES))

View File

@@ -13,6 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
*/ */
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -32,6 +33,167 @@ studiohdr_t *model_hdr;
studiohdr_t *texture_hdr; studiohdr_t *texture_hdr;
studiohdr_t **anim_hdr; studiohdr_t **anim_hdr;
/*
============
IsValidName
============
*/
static qboolean IsValidName( char *name )
{
if( !( isalpha( *name ) || isdigit( *name )))
return false;
while( *( ++name ))
{
if( isalpha( *name ) || isdigit( *name )
|| *name == '.' || *name == '-' || *name == '_'
|| *name == ' ' || *name == '(' || *name == ')'
|| *name == '[' || *name == ']')
continue;
// Found control character Ctrl+Shift+A(SOH|^A|0x1) in the end of name in some models.
else if( name[1] == '\0' )
{
*name = '\0';
return true;
}
return false;
}
return true;
}
/*
============
TextureNameFix
============
*/
static void TextureNameFix( void )
{
int i, j, len, counter, protected = 0;
qboolean hasduplicates = false;
mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ), *texture1;
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
ExtractFileName( texture->name, sizeof( texture->name ));
texture -= i;
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
{
if( !IsValidName( texture->name ))
{
Q_snprintf( texture->name, sizeof( texture->name ), "MDLDEC_Texture%i.bmp", ++protected );
continue;
}
counter = 0;
texture1 = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
for( j = 0; j < texture_hdr->numtextures; ++j, ++texture1 )
{
if( j != i && !Q_strncmp( texture1->name, texture->name, sizeof( texture1->name)))
{
len = Q_snprintf( texture1->name, sizeof( texture1->name ), "%s_%i.bmp", texture1->name, ++counter );
if( len == -1 )
Q_snprintf( texture1->name, sizeof( texture1->name ), "MDLDEC_Texture%i_%i.bmp", j, counter );
}
}
if( counter > 0 )
{
printf( "WARNING: Texture name \"%s\" is repeated %i times.\n", texture->name, counter );
hasduplicates = true;
}
}
if( protected )
printf( "WARNING: Gived name to %i protected texture(s).\n", protected );
if( hasduplicates )
puts( "WARNING: Added numeric suffix to repeated texture name(s)." );
}
/*
============
BodypartNameFix
============
*/
static void BodypartNameFix( void )
{
int i, j, k, len, counter, protected = 0, protected_models = 0;
qboolean hasduplicates = false;
mstudiobodyparts_t *bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex );
mstudiomodel_t *model, *model1;
for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
ExtractFileName( bodypart->name, sizeof( bodypart->name ));
bodypart -= i;
for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
{
if( !IsValidName( bodypart->name ))
{
Q_snprintf( bodypart->name, sizeof( bodypart->name ), "MDLDEC_Bodypart%i", ++protected );
continue;
}
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
for( j = 0; j < bodypart->nummodels; ++j, ++model )
{
ExtractFileName( model->name, sizeof( model->name ));
COM_StripExtension( model->name );
}
model -= j;
for( j = 0; j < bodypart->nummodels; ++j, ++model )
{
if( !IsValidName( model->name ))
{
Q_snprintf( model->name, sizeof( model->name ), "MDLDEC_Model%i", ++protected_models );
continue;
}
counter = 0;
model1 = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
for( k = 0; k < bodypart->nummodels; ++k, ++model1 )
{
if( k != j && !Q_strncmp( model1->name, model->name, sizeof( model1->name )))
{
len = Q_snprintf( model1->name, sizeof( model1->name ), "%s_%i", model1->name, ++counter );
if( len == -1 )
Q_snprintf( model1->name, sizeof( model1->name ), "MDLDEC_Model%i_%i", k, counter );
}
}
if( counter > 0 )
{
printf( "WARNING: Sequence name \"%s\" is repeated %i times.\n", model->name, counter );
hasduplicates = true;
}
}
}
if( protected )
printf( "WARNING: Gived name to %i protected bodypart(s).\n", protected );
if( protected_models )
printf( "WARNING: Gived name to %i protected model(s).\n", protected_models );
if( hasduplicates )
puts( "WARNING: Added numeric suffix to repeated bodypart name(s)." );
}
/* /*
============ ============
SequenceNameFix SequenceNameFix
@@ -39,30 +201,52 @@ SequenceNameFix
*/ */
static void SequenceNameFix( void ) static void SequenceNameFix( void )
{ {
int i, j, counter; int i, j, len, counter, protected = 0;
qboolean hasduplicates = false; qboolean hasduplicates = false;
mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ), *seqdesc1; mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ), *seqdesc1;
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc ) for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{ {
counter = 1; ExtractFileName( seqdesc->label, sizeof( seqdesc->label ));
COM_StripExtension( seqdesc->label );
}
seqdesc -= i;
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{
if( !IsValidName( seqdesc->label ))
{
Q_snprintf( seqdesc->label, sizeof( seqdesc->label ), "MDLDEC_Sequence%i", ++protected );
continue;
}
counter = 0;
seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ); seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
for( j = 0; j < model_hdr->numseq; ++j, ++seqdesc1 ) for( j = 0; j < model_hdr->numseq; ++j, ++seqdesc1 )
if( j != i && !Q_strncmp( seqdesc1->label, seqdesc->label, sizeof( seqdesc1->label ) ) ) {
Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "%s_%i", seqdesc1->label, ++counter ); if( j != i && !Q_strncmp( seqdesc1->label, seqdesc->label, sizeof( seqdesc1->label )))
{
len = Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "%s_%i", seqdesc1->label, ++counter );
if( counter > 1 ) if( len == -1 )
Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "MDLDEC_Sequence%i_%i", j, counter );
}
}
if( counter > 0 )
{ {
printf( "WARNING: Sequence name \"%s\" is repeated %i times.\n", seqdesc->label, counter ); printf( "WARNING: Sequence name \"%s\" is repeated %i times.\n", seqdesc->label, counter );
Q_snprintf( seqdesc->label, sizeof( seqdesc->label ), "%s_1", seqdesc->label );
hasduplicates = true; hasduplicates = true;
} }
} }
if( protected )
printf( "WARNING: Gived name to %i protected sequence(s).\n", protected );
if( hasduplicates ) if( hasduplicates )
puts( "WARNING: Added numeric suffix to repeated sequence name(s)." ); puts( "WARNING: Added numeric suffix to repeated sequence name(s)." );
} }
@@ -74,15 +258,19 @@ BoneNameFix
*/ */
static void BoneNameFix( void ) static void BoneNameFix( void )
{ {
int i, counter = 0; int i, protected = 0;
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ); mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
for( i = 0; i < model_hdr->numbones; ++i, ++bone ) for( i = 0; i < model_hdr->numbones; ++i, ++bone )
if( bone->name[0] == '\0' ) {
Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++counter ); bone->name[sizeof( bone->name ) - 1] = '\0';
if( counter ) if( !IsValidName( bone->name ) )
printf( "WARNING: Gived name to %i unnamed bone(s).\n", counter ); Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++protected );
}
if( protected )
printf( "WARNING: Gived name to %i protected bone(s).\n", protected );
} }
/* /*
@@ -94,6 +282,7 @@ static qboolean LoadMDL( const char *modelname )
{ {
int i; int i;
size_t len; size_t len;
off_t filesize;
char texturename[MAX_SYSPATH]; char texturename[MAX_SYSPATH];
char seqgroupname[MAX_SYSPATH]; char seqgroupname[MAX_SYSPATH];
const char *ext; const char *ext;
@@ -118,13 +307,13 @@ static qboolean LoadMDL( const char *modelname )
return false; return false;
} }
if( Q_strcmp( ext, "mdl" ) ) if( Q_stricmp( ext, "mdl" ) )
{ {
fprintf( stderr, "ERROR: Only .mdl-files is supported.\n" ); fprintf( stderr, "ERROR: Only .mdl-files is supported.\n" );
return false; return false;
} }
model_hdr = (studiohdr_t *)LoadFile( modelname ); model_hdr = (studiohdr_t *)LoadFile( modelname, &filesize );
if( !model_hdr ) if( !model_hdr )
{ {
@@ -132,6 +321,12 @@ static qboolean LoadMDL( const char *modelname )
return false; return false;
} }
if( filesize < sizeof( studiohdr_t ) || filesize != model_hdr->length )
{
fprintf( stderr, "ERROR: Wrong file size! File %s may be corrupted!\n", modelname );
return false;
}
if( memcmp( &model_hdr->ident, id_mdlhdr, sizeof( id_mdlhdr ) ) ) if( memcmp( &model_hdr->ident, id_mdlhdr, sizeof( id_mdlhdr ) ) )
{ {
if( !memcmp( &model_hdr->ident, id_seqhdr, sizeof( id_seqhdr ) ) ) if( !memcmp( &model_hdr->ident, id_seqhdr, sizeof( id_seqhdr ) ) )
@@ -144,7 +339,7 @@ static qboolean LoadMDL( const char *modelname )
if( model_hdr->version != STUDIO_VERSION ) if( model_hdr->version != STUDIO_VERSION )
{ {
fprintf( stderr, "ERROR: %s has unknown Studio MDL format version.\n", modelname ); fprintf( stderr, "ERROR: %s has unknown Studio MDL format version %d.\n", modelname, model_hdr->version );
return false; return false;
} }
@@ -156,17 +351,18 @@ static qboolean LoadMDL( const char *modelname )
if( destdir[0] != '\0' ) if( destdir[0] != '\0' )
{ {
if( !MakeDirectory( destdir ) ) if( !MakeDirectory( destdir ))
{ {
fprintf( stderr, "ERROR: Couldn't create directory %s\n", destdir ); fprintf( stderr, "ERROR: Couldn't create directory %s\n", destdir );
return false; return false;
} }
COM_PathSlashFix( destdir );
} }
else else
COM_ExtractFilePath( modelname, destdir ); COM_ExtractFilePath( modelname, destdir );
if( destdir[0] != '\0' )
COM_PathSlashFix( destdir );
len -= ( sizeof( ".mdl" ) - 1 ); // path length without extension len -= ( sizeof( ".mdl" ) - 1 ); // path length without extension
if( !model_hdr->numtextures ) if( !model_hdr->numtextures )
@@ -174,7 +370,7 @@ static qboolean LoadMDL( const char *modelname )
Q_strncpy( texturename, modelname, sizeof( texturename )); Q_strncpy( texturename, modelname, sizeof( texturename ));
Q_strncpy( &texturename[len], "t.mdl", sizeof( texturename ) - len ); Q_strncpy( &texturename[len], "t.mdl", sizeof( texturename ) - len );
texture_hdr = (studiohdr_t *)LoadFile( texturename ); texture_hdr = (studiohdr_t *)LoadFile( texturename, &filesize );
if( !texture_hdr ) if( !texture_hdr )
{ {
@@ -182,7 +378,7 @@ static qboolean LoadMDL( const char *modelname )
// dirty hack for casesensetive filesystems // dirty hack for casesensetive filesystems
texturename[len] = 'T'; texturename[len] = 'T';
texture_hdr = (studiohdr_t *)LoadFile( texturename ); texture_hdr = (studiohdr_t *)LoadFile( texturename, &filesize );
if( !texture_hdr ) if( !texture_hdr )
#endif #endif
@@ -192,6 +388,12 @@ static qboolean LoadMDL( const char *modelname )
} }
} }
if( filesize < sizeof( studiohdr_t ) || filesize != model_hdr->length )
{
fprintf( stderr, "ERROR: Wrong file size! File %s may be corrupted!\n", texturename );
return false;
}
if( memcmp( &texture_hdr->ident, id_mdlhdr, sizeof( id_mdlhdr ) ) if( memcmp( &texture_hdr->ident, id_mdlhdr, sizeof( id_mdlhdr ) )
|| !texture_hdr->numtextures ) || !texture_hdr->numtextures )
{ {
@@ -220,7 +422,7 @@ static qboolean LoadMDL( const char *modelname )
{ {
Q_snprintf( &seqgroupname[len], sizeof( seqgroupname ) - len, "%02d.mdl", i ); Q_snprintf( &seqgroupname[len], sizeof( seqgroupname ) - len, "%02d.mdl", i );
anim_hdr[i] = (studiohdr_t *)LoadFile( seqgroupname ); anim_hdr[i] = (studiohdr_t *)LoadFile( seqgroupname, &filesize );
if( !anim_hdr[i] ) if( !anim_hdr[i] )
{ {
@@ -228,6 +430,12 @@ static qboolean LoadMDL( const char *modelname )
return false; return false;
} }
if( filesize < sizeof( studiohdr_t ) || filesize != model_hdr->length )
{
fprintf( stderr, "ERROR: Wrong file size! File %s may be corrupted!\n", seqgroupname );
return false;
}
if( memcmp( &anim_hdr[i]->ident, id_seqhdr, sizeof( id_seqhdr ) ) ) if( memcmp( &anim_hdr[i]->ident, id_seqhdr, sizeof( id_seqhdr ) ) )
{ {
fprintf( stderr, "ERROR: %s is not a valid sequence file.\n", seqgroupname ); fprintf( stderr, "ERROR: %s is not a valid sequence file.\n", seqgroupname );
@@ -238,6 +446,22 @@ static qboolean LoadMDL( const char *modelname )
COM_FileBase( modelname, modelfile, sizeof( modelfile )); COM_FileBase( modelname, modelfile, sizeof( modelfile ));
// Some validation checks was found in mdldec-golang by Psycrow101
if( model_hdr->numhitboxes > model_hdr->numbones * ( MAXSTUDIOSRCBONES / MAXSTUDIOBONES ))
{
printf( "WARNING: Invalid hitboxes number %d.\n", model_hdr->numhitboxes );
model_hdr->numhitboxes = 0;
}
else if( model_hdr->hitboxindex + model_hdr->numhitboxes * ( sizeof( mstudiobbox_t ) + sizeof( mstudiohitboxset_t )) > model_hdr->length )
{
printf( "WARNING: Invalid hitboxes offset %d.\n", model_hdr->hitboxindex );
model_hdr->numhitboxes = 0;
}
TextureNameFix();
BodypartNameFix();
SequenceNameFix(); SequenceNameFix();
BoneNameFix(); BoneNameFix();

View File

@@ -321,7 +321,6 @@ static void WriteBodyGroupInfo( FILE *fp )
int i, j; int i, j;
mstudiobodyparts_t *bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex ); mstudiobodyparts_t *bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex );
mstudiomodel_t *model; mstudiomodel_t *model;
char modelname[64];
fprintf( fp, "// %i reference mesh%s\n", model_hdr->numbodyparts, model_hdr->numbodyparts > 1 ? "es" : "" ); fprintf( fp, "// %i reference mesh%s\n", model_hdr->numbodyparts, model_hdr->numbodyparts > 1 ? "es" : "" );
@@ -331,9 +330,7 @@ static void WriteBodyGroupInfo( FILE *fp )
if( bodypart->nummodels == 1 ) if( bodypart->nummodels == 1 )
{ {
COM_FileBase( model->name, modelname, sizeof( modelname )); fprintf( fp, "$body \"%s\" \"%s\"\n", bodypart->name, model->name );
fprintf( fp, "$body \"%s\" \"%s\"\n", bodypart->name, modelname );
continue; continue;
} }
@@ -349,9 +346,7 @@ static void WriteBodyGroupInfo( FILE *fp )
continue; continue;
} }
COM_FileBase( model->name, modelname, sizeof( modelname )); fprintf( fp, "\tstudio \"%s\"\n", model->name );
fprintf( fp, "\tstudio \"%s\"\n", modelname );
} }
fputs( "}\n", fp ); fputs( "}\n", fp );

View File

@@ -490,7 +490,6 @@ static void WriteReferences( void )
FILE *fp; FILE *fp;
mstudiomodel_t *model; mstudiomodel_t *model;
mstudiobodyparts_t *bodypart; mstudiobodyparts_t *bodypart;
char name[64];
char filename[MAX_SYSPATH]; char filename[MAX_SYSPATH];
if( !CreateBoneTransformMatrices( &bonetransform ) ) if( !CreateBoneTransformMatrices( &bonetransform ) )
@@ -517,13 +516,11 @@ static void WriteReferences( void )
if( !Q_strncmp( model->name, "blank", 5 ) ) if( !Q_strncmp( model->name, "blank", 5 ) )
continue; continue;
COM_FileBase( model->name, name, sizeof( name )); len = Q_snprintf( filename, MAX_SYSPATH, "%s%s.smd", destdir, model->name );
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s.smd", destdir, name );
if( len == -1 ) if( len == -1 )
{ {
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", name ); fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", model->name );
goto _fail; goto _fail;
} }

View File

@@ -20,6 +20,7 @@ GNU General Public License for more details.
#include "crtlib.h" #include "crtlib.h"
#include "studio.h" #include "studio.h"
#include "img_bmp.h" #include "img_bmp.h"
#include "img_tga.h"
#include "mdldec.h" #include "mdldec.h"
#include "texture.h" #include "texture.h"
@@ -28,37 +29,13 @@ GNU General Public License for more details.
WriteBMP WriteBMP
============ ============
*/ */
static void WriteBMP( mstudiotexture_t *texture ) static void WriteBMP( FILE *fp, mstudiotexture_t *texture )
{ {
int i, len; int i;
FILE *fp;
const byte *p; const byte *p;
byte *palette, *pic; byte *palette, *pic;
char filename[MAX_SYSPATH], texturename[64];
rgba_t rgba_palette[256]; rgba_t rgba_palette[256];
bmp_t bmp_hdr = {0,}; bmp_t bmp_hdr = {0,};
size_t texture_size;
COM_FileBase( texture->name, texturename, sizeof( texturename ));
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s.bmp", destdir, texturename );
if( len == -1 )
{
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.bmp\n", texturename );
return;
}
fp = fopen( filename, "wb" );
if( !fp )
{
fprintf( stderr, "ERROR: Can't write texture file %s\n", filename );
return;
}
texture_size = texture->height * texture->width;
pic = (byte *)texture_hdr + texture->index;
palette = pic + texture_size;
bmp_hdr.id[0] = 'B'; bmp_hdr.id[0] = 'B';
bmp_hdr.id[1] = 'M'; bmp_hdr.id[1] = 'M';
@@ -66,13 +43,16 @@ static void WriteBMP( mstudiotexture_t *texture )
bmp_hdr.height = texture->height; bmp_hdr.height = texture->height;
bmp_hdr.planes = 1; bmp_hdr.planes = 1;
bmp_hdr.bitsPerPixel = 8; bmp_hdr.bitsPerPixel = 8;
bmp_hdr.bitmapDataSize = texture_size; bmp_hdr.bitmapDataSize = bmp_hdr.width * bmp_hdr.height;
bmp_hdr.colors = 256; bmp_hdr.colors = 256;
bmp_hdr.fileSize = sizeof( bmp_hdr ) + texture_size + sizeof( rgba_palette ); bmp_hdr.fileSize = sizeof( bmp_hdr ) + bmp_hdr.bitmapDataSize + sizeof( rgba_palette );
bmp_hdr.bitmapDataOffset = sizeof( bmp_hdr ) + sizeof( rgba_palette ); bmp_hdr.bitmapDataOffset = sizeof( bmp_hdr ) + sizeof( rgba_palette );
bmp_hdr.bitmapHeaderSize = BI_SIZE; bmp_hdr.bitmapHeaderSize = BI_SIZE;
pic = (byte *)texture_hdr + texture->index;
palette = pic + bmp_hdr.bitmapDataSize;
fwrite( &bmp_hdr, sizeof( bmp_hdr ), 1, fp ); fwrite( &bmp_hdr, sizeof( bmp_hdr ), 1, fp );
p = palette; p = palette;
@@ -95,10 +75,52 @@ static void WriteBMP( mstudiotexture_t *texture )
fwrite( p, bmp_hdr.width, 1, fp ); fwrite( p, bmp_hdr.width, 1, fp );
p -= bmp_hdr.width; p -= bmp_hdr.width;
} }
}
fclose( fp ); /*
============
WriteTGA
============
*/
static void WriteTGA( FILE *fp, mstudiotexture_t *texture )
{
int i;
const byte *p;
byte *palette, *pic;
rgb_t rgb_palette[256];
tga_t tga_hdr = {0,};
printf( "Texture: %s\n", filename ); tga_hdr.colormap_type = tga_hdr.image_type = 1;
tga_hdr.colormap_length = 256;
tga_hdr.colormap_size = 24;
tga_hdr.pixel_size = 8;
tga_hdr.width = texture->width;
tga_hdr.height = texture->height;
pic = (byte *)texture_hdr + texture->index;
palette = pic + tga_hdr.width * tga_hdr.height;
fwrite( &tga_hdr, sizeof( tga_hdr ), 1, fp );
p = palette;
for( i = 0; i < (int)tga_hdr.colormap_length; i++ )
{
rgb_palette[i][2] = *p++;
rgb_palette[i][1] = *p++;
rgb_palette[i][0] = *p++;
}
fwrite( rgb_palette, sizeof( rgb_palette ), 1, fp );
p = pic;
p += ( tga_hdr.height - 1 ) * tga_hdr.width;
for( i = 0; i < tga_hdr.height; i++ )
{
fwrite( p, tga_hdr.width, 1, fp );
p -= tga_hdr.width;
}
} }
/* /*
@@ -108,10 +130,37 @@ WriteTextures
*/ */
void WriteTextures( void ) void WriteTextures( void )
{ {
int i; int i, len;
FILE *fp;
mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ); mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
char filename[MAX_SYSPATH];
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture ) for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
WriteBMP( texture ); {
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s", destdir, texture->name );
if( len == -1 )
{
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s\n", texture->name );
continue;
}
fp = fopen( filename, "wb" );
if( !fp )
{
fprintf( stderr, "ERROR: Can't write texture file %s\n", filename );
continue;
}
if( !Q_stricmp( COM_FileExtension( texture->name ), "tga" ))
WriteTGA( fp, texture );
else
WriteBMP( fp, texture );
fclose( fp );
printf( "Texture: %s\n", filename );
}
} }

View File

@@ -54,6 +54,27 @@ qboolean MakeDirectory( const char *path )
return true; return true;
} }
/*
============
ExtractFileName
============
*/
void ExtractFileName( char *name, size_t size )
{
char tmp[MAX_SYSPATH];
if( !( name && *name ) || size <= 0 )
return;
name[size - 1] = '\0';
if( Q_strpbrk( name, "/\\" ))
{
Q_strncpy( tmp, COM_FileWithoutPath( name ), sizeof( tmp ));
Q_strncpy( name, tmp, size );
}
}
/* /*
============ ============
GetFileSize GetFileSize
@@ -75,25 +96,24 @@ off_t GetSizeOfFile( FILE *fp )
LoadFile LoadFile
============ ============
*/ */
byte *LoadFile( const char *filename ) byte *LoadFile( const char *filename, off_t *size )
{ {
FILE *fp; FILE *fp;
byte *buf; byte *buf;
off_t size;
fp = fopen( filename, "rb" ); fp = fopen( filename, "rb" );
if( !fp ) if( !fp )
return NULL; return NULL;
size = GetSizeOfFile( fp ); *size = GetSizeOfFile( fp );
buf = malloc( size ); buf = malloc( *size );
if( !buf ) if( !buf )
return NULL; return NULL;
fread( buf, size, 1, fp ); fread( buf, *size, 1, fp );
fclose( fp ); fclose( fp );
return buf; return buf;

View File

@@ -17,8 +17,9 @@ GNU General Public License for more details.
#define UTILS_H #define UTILS_H
qboolean MakeDirectory( const char *path ); qboolean MakeDirectory( const char *path );
void ExtractFileName( char *name, size_t size );
off_t GetSizeOfFile( FILE *fp ); off_t GetSizeOfFile( FILE *fp );
byte *LoadFile( const char *filename ); byte *LoadFile( const char *filename, off_t *size );
#endif // UTILS_H #endif // UTILS_H

10
wscript
View File

@@ -196,11 +196,14 @@ def configure(conf):
# modify options dictionary early # modify options dictionary early
if conf.env.DEST_OS == 'android': if conf.env.DEST_OS == 'android':
conf.options.NO_VGUI= True # skip vgui conf.options.NO_VGUI = True # skip vgui
conf.options.NANOGL = True conf.options.NANOGL = True
conf.options.GLWES = True conf.options.GLWES = True
conf.options.GL4ES = True conf.options.GL4ES = True
conf.options.GLES3COMPAT = True
conf.options.GL = False conf.options.GL = False
conf.options.SINGLE_BINARY = True
conf.define('XASH_SDLMAIN', 1)
elif conf.env.MAGX: elif conf.env.MAGX:
conf.options.SDL12 = True conf.options.SDL12 = True
conf.options.NO_VGUI = True conf.options.NO_VGUI = True
@@ -375,6 +378,9 @@ def configure(conf):
conf.define('ALLOCA_H', 'alloca.h') conf.define('ALLOCA_H', 'alloca.h')
elif conf.check_cc(header_name='malloc.h', mandatory=False): elif conf.check_cc(header_name='malloc.h', mandatory=False):
conf.define('ALLOCA_H', 'malloc.h') conf.define('ALLOCA_H', 'malloc.h')
elif conf.check_cc(fragment = '''#include <stdlib.h>
int main(void) { alloca(1); }''', msg = 'Checking for alloca in stdlib.h'):
conf.define('ALLOCA_H', 'stdlib.h')
if conf.env.DEST_OS == 'nswitch': if conf.env.DEST_OS == 'nswitch':
conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER') conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER')
@@ -403,7 +409,7 @@ def configure(conf):
for i in a: for i in a:
conf.check_cc(lib = i) conf.check_cc(lib = i)
else: else:
conf.check_cc(lib='dl') conf.check_cc(lib='dl', mandatory = False)
conf.check_cc(lib='m') conf.check_cc(lib='m')