mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: platform: refactor variable declarations
This commit is contained in:
@@ -78,14 +78,12 @@ Android_GetAndroidID
|
||||
const char *Android_GetAndroidID( void )
|
||||
{
|
||||
static char id[32];
|
||||
jstring resultJNIStr;
|
||||
const char *resultCStr;
|
||||
|
||||
if( !COM_StringEmpty( id ))
|
||||
return id;
|
||||
|
||||
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAndroidID );
|
||||
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||
jstring resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getAndroidID );
|
||||
const char *resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||
Q_strncpy( id, resultCStr, sizeof( id ) );
|
||||
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
|
||||
(*jni.env)->DeleteLocalRef( jni.env, resultJNIStr );
|
||||
@@ -101,11 +99,8 @@ Android_LoadID
|
||||
const char *Android_LoadID( void )
|
||||
{
|
||||
static char id[32];
|
||||
jstring resultJNIStr;
|
||||
const char *resultCStr;
|
||||
|
||||
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.loadAndroidID );
|
||||
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||
jstring resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.loadAndroidID );
|
||||
const char *resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||
Q_strncpy( id, resultCStr, sizeof( id ) );
|
||||
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
|
||||
(*jni.env)->DeleteLocalRef( jni.env, resultJNIStr );
|
||||
|
||||
@@ -23,7 +23,6 @@ GNU General Public License for more details.
|
||||
void *ANDROID_LoadLibrary( const char *path )
|
||||
{
|
||||
const char *name = COM_FileWithoutPath( path );
|
||||
void *handle;
|
||||
|
||||
Con_Reportf( "%s: loading \"%s\" (name: \"%s\")\n", __func__, path, name );
|
||||
|
||||
@@ -36,7 +35,7 @@ void *ANDROID_LoadLibrary( const char *path )
|
||||
|
||||
Con_Reportf( "%s: trying APK path \"%s\"\n", __func__, fullpath );
|
||||
|
||||
handle = dlopen( fullpath, RTLD_NOW );
|
||||
void *handle = dlopen( fullpath, RTLD_NOW );
|
||||
if( handle )
|
||||
{
|
||||
Con_Reportf( "%s: loaded from APK path\n", __func__ );
|
||||
@@ -58,7 +57,7 @@ void *ANDROID_LoadLibrary( const char *path )
|
||||
Q_strncpy( libpath, hInst->fullPath, sizeof( libpath ));
|
||||
Mem_Free( hInst );
|
||||
|
||||
handle = dlopen( libpath, RTLD_NOW );
|
||||
void *handle = dlopen( libpath, RTLD_NOW );
|
||||
if( handle )
|
||||
{
|
||||
Con_Reportf( "%s: loaded from VFS path\n", __func__ );
|
||||
@@ -77,7 +76,7 @@ void *ANDROID_LoadLibrary( const char *path )
|
||||
|
||||
// find in system search path (APK's LD_LIBRARY_PATH)
|
||||
Con_Reportf( "%s: trying LD_LIBRARY_PATH for \"%s\"\n", __func__, name );
|
||||
handle = dlopen( name, RTLD_NOW );
|
||||
void *handle = dlopen( name, RTLD_NOW );
|
||||
if( handle )
|
||||
{
|
||||
Con_Reportf( "%s: loaded from LD_LIBRARY_PATH\n", __func__ );
|
||||
|
||||
@@ -52,9 +52,7 @@ byte scantokey[128] =
|
||||
// will be implemented later
|
||||
void Platform_RunEvents( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < keystate.buf_head;i++ )
|
||||
for( int i = 0; i < keystate.buf_head;i++ )
|
||||
{
|
||||
int k = keystate.buf[i];
|
||||
int key = scantokey[k&0x7f];
|
||||
|
||||
@@ -51,12 +51,11 @@ static void DOS_GetScreenRes( int *x, int *y )
|
||||
|
||||
qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
{
|
||||
qboolean retval;
|
||||
|
||||
if( type != REF_SOFTWARE )
|
||||
return false; /// glide???
|
||||
|
||||
if( !(retval = VID_SetMode()) )
|
||||
qboolean retval = VID_SetMode();
|
||||
if( !retval )
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
@@ -86,13 +85,12 @@ qboolean VID_SetMode( void )
|
||||
|
||||
rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mode )
|
||||
{
|
||||
int render_w, render_h;
|
||||
uint rotate = vid_rotate->value;
|
||||
|
||||
DOS_GetScreenRes( &width, &height );
|
||||
|
||||
render_w = width;
|
||||
render_h = height;
|
||||
int render_w = width;
|
||||
int render_h = height;
|
||||
|
||||
Con_Reportf( "%s: forced resolution to %dx%d)\n", __func__, width, height );
|
||||
|
||||
@@ -445,7 +443,6 @@ void vesa_free_mode_info( void )
|
||||
|
||||
void init_13h( void )
|
||||
{
|
||||
int r, g, b;
|
||||
union REGS regs;
|
||||
|
||||
// set 13h vga mode
|
||||
@@ -455,9 +452,9 @@ void init_13h( void )
|
||||
|
||||
// set 332 palette
|
||||
outp(0x3c8, 0);
|
||||
for (r=0; r<8; r++)
|
||||
for (b=0; b<4; b++)
|
||||
for (g=0; g<8; g++)
|
||||
for (int r=0; r<8; r++)
|
||||
for (int b=0; b<4; b++)
|
||||
for (int g=0; g<8; g++)
|
||||
{
|
||||
outp(0x3c9, (b<<4)+8);
|
||||
outp(0x3c9, (g<<3)+4);
|
||||
@@ -515,8 +512,6 @@ void SW_UnlockBuffer( void )
|
||||
|
||||
qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b )
|
||||
{
|
||||
int i;
|
||||
|
||||
*stride = 320;
|
||||
|
||||
vesa_get_info();
|
||||
|
||||
@@ -33,7 +33,6 @@ GNU General Public License for more details.
|
||||
|
||||
int dladdr(void *address, Dl_info* dl)
|
||||
{
|
||||
void *v;
|
||||
v = _rld_new_interface(_RLD_DLADDR, address, dl);
|
||||
void *v = _rld_new_interface(_RLD_DLADDR, address, dl);
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
@@ -333,9 +333,9 @@ void Evdev_CloseDevice_f ( void )
|
||||
|
||||
void IN_EvdevFrame ( void )
|
||||
{
|
||||
int dx = 0, dy = 0, i;
|
||||
int dx = 0, dy = 0;
|
||||
|
||||
for( i = 0; i < evdev.devices; i++ )
|
||||
for( int i = 0; i < evdev.devices; i++ )
|
||||
{
|
||||
struct input_event ev;
|
||||
|
||||
@@ -403,8 +403,6 @@ void Evdev_SetGrab( qboolean grab )
|
||||
{
|
||||
// grab only if evdev is secondary input source
|
||||
#if XASH_INPUT != INPUT_EVDEV
|
||||
int i;
|
||||
|
||||
if( grab )
|
||||
{
|
||||
Key_Event( K_ESCAPE, 0 ); //Do not leave ESC down
|
||||
@@ -413,7 +411,7 @@ void Evdev_SetGrab( qboolean grab )
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < evdev.devices; i++ )
|
||||
for( int i = 0; i < evdev.devices; i++ )
|
||||
ioctl( evdev.fds[i], EVIOCGRAB, (void*) 0 );
|
||||
}
|
||||
evdev.grab = grab;
|
||||
@@ -454,14 +452,12 @@ void Evdev_Init( void )
|
||||
|
||||
void Evdev_Shutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
Cmd_RemoveCommand( "evdev_open" );
|
||||
Cmd_RemoveCommand( "evdev_close" );
|
||||
Cmd_RemoveCommand( "evdev_autodetect" );
|
||||
Cvar_RegisterVariable( &evdev_keydebug );
|
||||
|
||||
for( i = 0; i < evdev.devices; i++ )
|
||||
for( int i = 0; i < evdev.devices; i++ )
|
||||
{
|
||||
ioctl( evdev.fds[i], EVIOCGRAB, (void*) 0 );
|
||||
close( evdev.fds[i] );
|
||||
|
||||
@@ -279,17 +279,15 @@ void SNDDMA_Submit( void )
|
||||
}
|
||||
else // period is 1/2 of samples
|
||||
{
|
||||
int s, w, frames;
|
||||
void *start;
|
||||
|
||||
if( !snd.buffer )
|
||||
return;
|
||||
|
||||
s = snd.samplepos * 2;
|
||||
start = (void *)&snd.buffer[s];
|
||||
frames = s_alsa.period_size / 2;
|
||||
int s = snd.samplepos * 2;
|
||||
void *start = (void *)&snd.buffer[s];
|
||||
int frames = s_alsa.period_size / 2;
|
||||
// write to card
|
||||
if( ( w = snd_pcm_writei( s_alsa.pcm_handle, start, frames ) ) < 0)
|
||||
int w = snd_pcm_writei( s_alsa.pcm_handle, start, frames );
|
||||
if( w < 0 )
|
||||
{
|
||||
// xrun occured
|
||||
snd_pcm_prepare( s_alsa.pcm_handle );
|
||||
|
||||
@@ -46,24 +46,20 @@ int Linux_GetProcessID( void )
|
||||
|
||||
qboolean Platform_DebuggerPresent( void )
|
||||
{
|
||||
char buf[4096];
|
||||
ssize_t num_read;
|
||||
int status_fd;
|
||||
|
||||
status_fd = open( "/proc/self/status", O_RDONLY );
|
||||
int status_fd = open( "/proc/self/status", O_RDONLY );
|
||||
if ( status_fd == -1 )
|
||||
return 0;
|
||||
|
||||
num_read = read( status_fd, buf, sizeof( buf ) );
|
||||
char buf[4096];
|
||||
ssize_t num_read = read( status_fd, buf, sizeof( buf ) );
|
||||
close( status_fd );
|
||||
|
||||
if ( num_read > 0 )
|
||||
{
|
||||
static const char TracerPid[] = "TracerPid:";
|
||||
const byte *tracer_pid;
|
||||
|
||||
buf[num_read] = 0;
|
||||
tracer_pid = (const byte*)Q_strstr( buf, TracerPid );
|
||||
const byte *tracer_pid = (const byte*)Q_strstr( buf, TracerPid );
|
||||
if( !tracer_pid )
|
||||
return false;
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ void FB_GetScreenRes( int *x, int *y )
|
||||
|
||||
qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
{
|
||||
qboolean retval;
|
||||
string fbdev = DEFAULT_FBDEV;
|
||||
fb.fd = -1;
|
||||
|
||||
if( type != REF_SOFTWARE )
|
||||
return false;
|
||||
|
||||
string fbdev = DEFAULT_FBDEV;
|
||||
|
||||
Sys_GetParmFromCmdLine( "-fbdev", fbdev );
|
||||
|
||||
fb.fd = open( fbdev, O_RDWR );
|
||||
@@ -74,7 +74,8 @@ qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
ioctl(fb.fd, FBIOGET_FSCREENINFO, &fb.finfo);
|
||||
ioctl(fb.fd, FBIOGET_VSCREENINFO, &fb.vinfo);
|
||||
|
||||
if( !(retval = VID_SetMode()) )
|
||||
qboolean retval = VID_SetMode();
|
||||
if( !retval )
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
@@ -124,12 +125,10 @@ qboolean VID_SetMode( void )
|
||||
|
||||
rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mode )
|
||||
{
|
||||
int render_w, render_h;
|
||||
|
||||
FB_GetScreenRes( &width, &height );
|
||||
|
||||
render_w = width;
|
||||
render_h = height;
|
||||
int render_w = width;
|
||||
int render_h = height;
|
||||
|
||||
Con_Reportf( "%s: forced resolution to %dx%d)\n", __func__, width, height );
|
||||
|
||||
|
||||
@@ -42,17 +42,14 @@ static struct sbrk_state_s
|
||||
|
||||
static void SWAP_Initialize(void)
|
||||
{
|
||||
char *path;
|
||||
char *prealloc = getenv("SWAP_SIZE");
|
||||
int fd;
|
||||
|
||||
if( s.top )
|
||||
return;
|
||||
|
||||
path = getenv("SWAP_PATH");
|
||||
char *prealloc = getenv("SWAP_SIZE");
|
||||
char *path = getenv("SWAP_PATH");
|
||||
if( !path )
|
||||
path = XASH_DEFAULT_SWAP_PATH;
|
||||
fd = open( path, O_CREAT|O_RDWR, 0600 );
|
||||
int fd = open( path, O_CREAT|O_RDWR, 0600 );
|
||||
|
||||
if( prealloc ) s.prealloc = atoi(prealloc);
|
||||
else s.prealloc = 128*1024*1024;
|
||||
@@ -75,10 +72,8 @@ void *SWAP_Sbrk(size_t size)
|
||||
return s.top;
|
||||
else if( size > 0 )
|
||||
{
|
||||
void *res;
|
||||
|
||||
//write(1, buf, snprintf(buf, 32, "allocating %d\n", size) );
|
||||
res = s.top;
|
||||
void *res = s.top;
|
||||
s.size += size;
|
||||
s.top = res + size;
|
||||
if( s.size + size > s.prealloc )
|
||||
|
||||
@@ -53,10 +53,8 @@ static qboolean Sys_IsCrashHandlerFrame( const char *name )
|
||||
static void Sys_AppendPrint( struct print_data *pd, const char *fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
int len;
|
||||
|
||||
va_start( va, fmt );
|
||||
len = Q_vsnprintf( pd->message, pd->message_size, fmt, va );
|
||||
int len = Q_vsnprintf( pd->message, pd->message_size, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
if( len > 0 )
|
||||
|
||||
@@ -75,10 +75,6 @@ qboolean COM_CheckLibraryDirectDependency( const char *name, const char *depname
|
||||
|
||||
void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean directpath )
|
||||
{
|
||||
dll_user_t *hInst = NULL;
|
||||
void *pHandle = NULL;
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
COM_ResetLibraryError();
|
||||
|
||||
// platforms where gameinfo mechanism is impossible
|
||||
@@ -88,21 +84,20 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
|
||||
|
||||
// platforms where gameinfo mechanism is working goes here
|
||||
// and use FS_FindLibrary
|
||||
hInst = FS_FindLibrary( dllname, directpath );
|
||||
dll_user_t *hInst = FS_FindLibrary( dllname, directpath );
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
if( !hInst )
|
||||
{
|
||||
// try to find by linker(LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, LD_32_LIBRARY_PATH and so on...)
|
||||
if( !pHandle )
|
||||
{
|
||||
pHandle = dlopen( dllname, RTLD_NOW );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
void *pHandle = dlopen( dllname, RTLD_NOW );
|
||||
if( pHandle )
|
||||
return pHandle;
|
||||
|
||||
Q_snprintf( buf, sizeof( buf ), "Failed to find library %s", dllname );
|
||||
COM_PushLibraryError( buf );
|
||||
COM_PushLibraryError( dlerror() );
|
||||
return NULL;
|
||||
}
|
||||
Q_snprintf( buf, sizeof( buf ), "Failed to find library %s", dllname );
|
||||
COM_PushLibraryError( buf );
|
||||
COM_PushLibraryError( dlerror() );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( hInst->custom_loader )
|
||||
@@ -120,7 +115,7 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pHandle = hInst->hInstance;
|
||||
void *pHandle = hInst->hInstance;
|
||||
|
||||
Mem_Free( hInst );
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ GNU General Public License for more details.
|
||||
void Platform_ShellExecute( const char *path, const char *parms )
|
||||
{
|
||||
const char *argv[] = { OPEN_COMMAND, path, NULL };
|
||||
pid_t id;
|
||||
|
||||
id = fork();
|
||||
pid_t id = fork();
|
||||
|
||||
if( id == 0 )
|
||||
{
|
||||
@@ -44,9 +42,7 @@ void Posix_Daemonize( void )
|
||||
if( Sys_CheckParm( "-daemonize" ))
|
||||
{
|
||||
#if XASH_POSIX && defined(_POSIX_VERSION) && !defined(XASH_MOBILE_PLATFORM)
|
||||
pid_t daemon;
|
||||
|
||||
daemon = fork();
|
||||
pid_t daemon = fork();
|
||||
|
||||
if( daemon < 0 )
|
||||
{
|
||||
|
||||
@@ -40,11 +40,9 @@ static inline void utf2ascii( char *dst, const SceWChar16 *src, unsigned dstsize
|
||||
|
||||
static void IME_Open( void )
|
||||
{
|
||||
SceInt32 res;
|
||||
SceImeDialogParam param;
|
||||
|
||||
memset( ime_string, 0, sizeof( ime_string ) );
|
||||
|
||||
SceImeDialogParam param;
|
||||
sceImeDialogParamInit( ¶m );
|
||||
param.supportedLanguages = SCE_IME_LANGUAGE_ENGLISH;
|
||||
param.languagesForced = SCE_TRUE;
|
||||
@@ -54,7 +52,7 @@ static void IME_Open( void )
|
||||
param.initialText = (SceWChar16 *)u"";
|
||||
param.inputTextBuffer = ime_string;
|
||||
|
||||
res = sceImeDialogInit( ¶m );
|
||||
SceInt32 res = sceImeDialogInit( ¶m );
|
||||
if ( res < 0 )
|
||||
{
|
||||
Con_Reportf( S_WARN "Could not open IME keyboard: %d\n", res );
|
||||
|
||||
@@ -187,13 +187,11 @@ qboolean PSVita_GetBasePath( char *buf, const size_t buflen )
|
||||
// check if a xash3d folder exists on one of these drives
|
||||
// default to the last one (ux0)
|
||||
static const char *drives[] = { "uma0", "imc0", "ux0" };
|
||||
SceUID dir;
|
||||
size_t i;
|
||||
|
||||
for ( i = 0; i < sizeof( drives ) / sizeof( *drives ); ++i )
|
||||
for ( size_t i = 0; i < sizeof( drives ) / sizeof( *drives ); ++i )
|
||||
{
|
||||
Q_snprintf( buf, buflen, "%s:" DATA_PATH, drives[i] );
|
||||
dir = sceIoDopen( buf );
|
||||
SceUID dir = sceIoDopen( buf );
|
||||
if ( dir >= 0 )
|
||||
{
|
||||
sceIoDclose( dir );
|
||||
|
||||
@@ -221,12 +221,7 @@ SDLash_MouseEvent
|
||||
*/
|
||||
static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
|
||||
{
|
||||
int down;
|
||||
|
||||
if( button.state == SDL_RELEASED )
|
||||
down = 0;
|
||||
else
|
||||
down = 1;
|
||||
const int down = button.state != SDL_RELEASED;
|
||||
|
||||
switch( button.button )
|
||||
{
|
||||
|
||||
@@ -46,21 +46,18 @@ static char sdl_backend_name[32];
|
||||
|
||||
static void SDL_SoundCallback( void *userdata, Uint8 *stream, int len )
|
||||
{
|
||||
const int size = snd.samples << 1;
|
||||
int pos;
|
||||
int wrapped;
|
||||
|
||||
if( !snd.buffer )
|
||||
{
|
||||
memset( stream, 0, len );
|
||||
return;
|
||||
}
|
||||
|
||||
pos = snd.samplepos << 1;
|
||||
const int size = snd.samples << 1;
|
||||
int pos = snd.samplepos << 1;
|
||||
if( pos >= size )
|
||||
pos = snd.samplepos = 0;
|
||||
|
||||
wrapped = pos + len - size;
|
||||
int wrapped = pos + len - size;
|
||||
|
||||
if( wrapped < 0 )
|
||||
{
|
||||
@@ -90,7 +87,6 @@ Returns false if nothing is found.
|
||||
*/
|
||||
qboolean SNDDMA_Init( void )
|
||||
{
|
||||
SDL_AudioSpec desired, obtained;
|
||||
int samplecount;
|
||||
const char *driver = NULL;
|
||||
|
||||
@@ -104,6 +100,7 @@ qboolean SNDDMA_Init( void )
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_AudioSpec desired, obtained;
|
||||
memset( &desired, 0, sizeof( desired ) );
|
||||
desired.freq = SOUND_DMA_SPEED;
|
||||
desired.format = AUDIO_S16SYS;
|
||||
|
||||
@@ -22,14 +22,13 @@ double Platform_DoubleTime( void )
|
||||
{
|
||||
static Uint64 g_PerformanceFrequency;
|
||||
static Uint64 g_ClockStart;
|
||||
Uint64 CurrentTime;
|
||||
|
||||
if( !g_PerformanceFrequency )
|
||||
{
|
||||
g_PerformanceFrequency = SDL_GetPerformanceFrequency();
|
||||
g_ClockStart = SDL_GetPerformanceCounter();
|
||||
}
|
||||
CurrentTime = SDL_GetPerformanceCounter();
|
||||
Uint64 CurrentTime = SDL_GetPerformanceCounter();
|
||||
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
||||
}
|
||||
|
||||
|
||||
@@ -100,24 +100,24 @@ vidmode_t *R_GetVideoMode( int num )
|
||||
|
||||
static void R_InitVideoModes( void )
|
||||
{
|
||||
char buf[MAX_VA_STRING];
|
||||
SDL_Rect **modes;
|
||||
int len = 0, i = 0, j;
|
||||
|
||||
modes = SDL_ListModes( NULL, SDL_FULLSCREEN );
|
||||
SDL_Rect **modes = SDL_ListModes( NULL, SDL_FULLSCREEN );
|
||||
|
||||
if( !modes || modes == (void*)-1 )
|
||||
return;
|
||||
|
||||
for( len = 0; modes[len]; len++ );
|
||||
int len = 0;
|
||||
for( ; modes[len]; len++ );
|
||||
|
||||
vidmodes = Mem_Malloc( host.mempool, len * sizeof( vidmode_t ) );
|
||||
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
// from smallest to largest
|
||||
for( ; i < len; i++ )
|
||||
for( int i = 0; i < len; i++ )
|
||||
{
|
||||
SDL_Rect *mode = modes[len - i - 1];
|
||||
|
||||
int j;
|
||||
for( j = 0; j < num_vidmodes; j++ )
|
||||
{
|
||||
if( mode->w == vidmodes[j].width &&
|
||||
@@ -140,12 +140,10 @@ static void R_InitVideoModes( void )
|
||||
|
||||
static void R_FreeVideoModes( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !vidmodes )
|
||||
return;
|
||||
|
||||
for( i = 0; i < num_vidmodes; i++ )
|
||||
for( int i = 0; i < num_vidmodes; i++ )
|
||||
Mem_Free( (char*)vidmodes[i].desc );
|
||||
Mem_Free( vidmodes );
|
||||
|
||||
@@ -380,7 +378,6 @@ R_Init_Video
|
||||
qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
{
|
||||
string safe;
|
||||
qboolean retval;
|
||||
|
||||
refState.desktopBitsPixel = 16;
|
||||
|
||||
@@ -407,7 +404,8 @@ qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
break;
|
||||
}
|
||||
|
||||
if( !(retval = VID_SetMode()) )
|
||||
qboolean retval = VID_SetMode();
|
||||
if( !retval )
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
@@ -463,12 +461,10 @@ Set the described video mode
|
||||
*/
|
||||
qboolean VID_SetMode( void )
|
||||
{
|
||||
int iScreenWidth, iScreenHeight;
|
||||
rserr_t err;
|
||||
window_mode_t window_mode;
|
||||
|
||||
iScreenWidth = Cvar_VariableInteger( "width" );
|
||||
iScreenHeight = Cvar_VariableInteger( "height" );
|
||||
int iScreenWidth = Cvar_VariableInteger( "width" );
|
||||
int iScreenHeight = Cvar_VariableInteger( "height" );
|
||||
|
||||
if( iScreenWidth < VID_MIN_WIDTH ||
|
||||
iScreenHeight < VID_MIN_HEIGHT ) // trying to get resolution automatically by default
|
||||
@@ -477,7 +473,7 @@ qboolean VID_SetMode( void )
|
||||
iScreenHeight = 240;
|
||||
}
|
||||
|
||||
window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
window_mode_t window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
SetBits( gl_vsync.flags, FCVAR_CHANGED );
|
||||
|
||||
if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, window_mode )) == rserr_ok )
|
||||
|
||||
@@ -215,11 +215,9 @@ SDLash_InputEvent
|
||||
*/
|
||||
static void SDLash_InputEvent( SDL_TextInputEvent input )
|
||||
{
|
||||
const char *text;
|
||||
|
||||
VGui_ReportTextInput( input.text );
|
||||
|
||||
for( text = input.text; *text; text++ )
|
||||
for( const char *text = input.text; *text; text++ )
|
||||
{
|
||||
int ch = (byte)*text;
|
||||
|
||||
|
||||
@@ -85,12 +85,12 @@ Platform_GetClipobardText
|
||||
*/
|
||||
int Platform_GetClipboardText( char *buffer, size_t size )
|
||||
{
|
||||
int textLength;
|
||||
char *sdlbuffer = SDL_GetClipboardText();
|
||||
|
||||
if( !sdlbuffer )
|
||||
return 0;
|
||||
|
||||
int textLength;
|
||||
if (buffer && size > 0)
|
||||
{
|
||||
textLength = Q_strncpy( buffer, sdlbuffer, size );
|
||||
@@ -164,9 +164,7 @@ SDLash_FreeCursors
|
||||
*/
|
||||
void SDLash_FreeCursors( void )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for( ; i < ARRAYSIZE( cursors.cursors ); i++ )
|
||||
for( int i = 0; i < ARRAYSIZE( cursors.cursors ); i++ )
|
||||
{
|
||||
if( cursors.cursors[i] )
|
||||
SDL_FreeCursor( cursors.cursors[i] );
|
||||
@@ -260,11 +258,8 @@ Platform_GetKeyModifiers
|
||||
*/
|
||||
key_modifier_t Platform_GetKeyModifiers( void )
|
||||
{
|
||||
SDL_Keymod modFlags;
|
||||
key_modifier_t resultFlags;
|
||||
|
||||
resultFlags = KeyModifier_None;
|
||||
modFlags = SDL_GetModState();
|
||||
key_modifier_t resultFlags = KeyModifier_None;
|
||||
SDL_Keymod modFlags = SDL_GetModState();
|
||||
if( FBitSet( modFlags, KMOD_LCTRL ))
|
||||
SetBits( resultFlags, KeyModifier_LeftCtrl );
|
||||
if( FBitSet( modFlags, KMOD_RCTRL ))
|
||||
|
||||
@@ -195,10 +195,7 @@ static void SDLash_SetActiveGameController( SDL_JoystickID id )
|
||||
|
||||
static void SDLash_GameControllerAdded( int device_index )
|
||||
{
|
||||
SDL_GameController *gc;
|
||||
SDL_GameController **list;
|
||||
|
||||
gc = SDL_GameControllerOpen( device_index );
|
||||
SDL_GameController *gc = SDL_GameControllerOpen( device_index );
|
||||
if( !gc )
|
||||
{
|
||||
Con_Printf( S_ERROR "SDL_GameControllerOpen: %s\n", SDL_GetError( ));
|
||||
@@ -217,7 +214,7 @@ static void SDLash_GameControllerAdded( int device_index )
|
||||
}
|
||||
#endif // XASH_ANDROID
|
||||
|
||||
list = Mem_Realloc( host.mempool, g_gamepads, sizeof( *list ) * ( g_num_gamepads + 1 ));
|
||||
SDL_GameController **list = Mem_Realloc( host.mempool, g_gamepads, sizeof( *list ) * ( g_num_gamepads + 1 ));
|
||||
list[g_num_gamepads++] = gc;
|
||||
|
||||
g_gamepads = list;
|
||||
@@ -236,21 +233,18 @@ static void SDLash_GameControllerAdded( int device_index )
|
||||
|
||||
static void SDLash_GameControllerRemoved( SDL_JoystickID id )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( id == g_current_gamepad_id )
|
||||
SDLash_SetActiveGameController( -1 );
|
||||
|
||||
// now close the device
|
||||
for( i = 0; i < g_num_gamepads; i++ )
|
||||
for( size_t i = 0; i < g_num_gamepads; i++ )
|
||||
{
|
||||
SDL_GameController *gc = g_gamepads[i];
|
||||
SDL_Joystick *joy;
|
||||
|
||||
if( !gc )
|
||||
continue;
|
||||
|
||||
joy = SDL_GameControllerGetJoystick( gc );
|
||||
SDL_Joystick *joy = SDL_GameControllerGetJoystick( gc );
|
||||
|
||||
if( !joy )
|
||||
continue;
|
||||
@@ -335,7 +329,6 @@ void Platform_Vibrate2( float time, int val1, int val2, uint flags )
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 9 )
|
||||
SDL_GameController *gc = g_current_gamepad;
|
||||
Uint32 ms;
|
||||
|
||||
if( g_current_gamepad_id < 0 || !gc )
|
||||
return;
|
||||
@@ -346,7 +339,7 @@ void Platform_Vibrate2( float time, int val1, int val2, uint flags )
|
||||
if( val2 < 0 )
|
||||
val2 = COM_RandomLong( 0x7FFF, 0xFFFF );
|
||||
|
||||
ms = (Uint32)ceil( time );
|
||||
Uint32 ms = (Uint32)ceil( time );
|
||||
SDL_GameControllerRumble( gc, val1, val2, ms );
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 9 )
|
||||
}
|
||||
@@ -370,8 +363,6 @@ Platform_JoyInit
|
||||
*/
|
||||
int Platform_JoyInit( void )
|
||||
{
|
||||
int count, numJoysticks, i;
|
||||
|
||||
SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1" );
|
||||
SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1" );
|
||||
|
||||
@@ -386,9 +377,9 @@ int Platform_JoyInit( void )
|
||||
SDLash_GameControllerAddMappings( "gamecontrollerdb.txt" ); // shipped in extras.pk3
|
||||
SDLash_GameControllerAddMappings( "controllermappings.txt" );
|
||||
|
||||
count = 0;
|
||||
numJoysticks = SDL_NumJoysticks();
|
||||
for ( i = 0; i < numJoysticks; i++ )
|
||||
int count = 0;
|
||||
int numJoysticks = SDL_NumJoysticks();
|
||||
for ( int i = 0; i < numJoysticks; i++ )
|
||||
{
|
||||
if( SDL_IsGameController( i ))
|
||||
++count;
|
||||
@@ -405,11 +396,9 @@ Platform_JoyShutdown
|
||||
*/
|
||||
void Platform_JoyShutdown( void )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
SDLash_SetActiveGameController( -1 );
|
||||
|
||||
for( i = 0; i < g_num_gamepads; i++ )
|
||||
for( size_t i = 0; i < g_num_gamepads; i++ )
|
||||
{
|
||||
if( !g_gamepads[i] )
|
||||
continue;
|
||||
|
||||
@@ -40,14 +40,11 @@ static char sdl_backend_name[32];
|
||||
static void SDL_SoundCallback( void *userdata, Uint8 *stream, int len )
|
||||
{
|
||||
const int size = snd.samples << 1;
|
||||
int pos;
|
||||
int wrapped;
|
||||
|
||||
pos = snd.samplepos << 1;
|
||||
int pos = snd.samplepos << 1;
|
||||
if( pos >= size )
|
||||
pos = snd.samplepos = 0;
|
||||
|
||||
wrapped = pos + len - size;
|
||||
int wrapped = pos + len - size;
|
||||
|
||||
if( wrapped < 0 )
|
||||
{
|
||||
|
||||
@@ -22,14 +22,13 @@ double Platform_DoubleTime( void )
|
||||
{
|
||||
static Uint64 g_PerformanceFrequency;
|
||||
static Uint64 g_ClockStart;
|
||||
Uint64 CurrentTime;
|
||||
|
||||
if( !g_PerformanceFrequency )
|
||||
{
|
||||
g_PerformanceFrequency = SDL_GetPerformanceFrequency();
|
||||
g_ClockStart = SDL_GetPerformanceCounter();
|
||||
}
|
||||
CurrentTime = SDL_GetPerformanceCounter();
|
||||
Uint64 CurrentTime = SDL_GetPerformanceCounter();
|
||||
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
||||
}
|
||||
|
||||
|
||||
@@ -100,13 +100,12 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *
|
||||
|
||||
if( !SDL_LockTexture( sw.tex, NULL, &pixels, &pitch ))
|
||||
{
|
||||
int bits;
|
||||
uint amask;
|
||||
|
||||
// lock successfull, release
|
||||
SDL_UnlockTexture( sw.tex );
|
||||
|
||||
// enough for building blitter tables
|
||||
int bits;
|
||||
uint amask;
|
||||
SDL_PixelFormatEnumToMasks( format, &bits, r, g, b, &amask );
|
||||
*bpp = SDL_BYTESPERPIXEL( format );
|
||||
*stride = pitch / *bpp;
|
||||
@@ -247,21 +246,20 @@ vidmode_t *R_GetVideoMode( int num )
|
||||
|
||||
static void R_InitVideoModes( void )
|
||||
{
|
||||
char buf[MAX_VA_STRING];
|
||||
int display_index = 0;
|
||||
int i, modes;
|
||||
|
||||
num_vidmodes = 0;
|
||||
modes = SDL_GetNumDisplayModes( display_index );
|
||||
int modes = SDL_GetNumDisplayModes( display_index );
|
||||
|
||||
if( !modes )
|
||||
return;
|
||||
|
||||
vidmodes = Mem_Malloc( host.mempool, modes * sizeof( vidmode_t ) );
|
||||
|
||||
for( i = 0; i < modes; i++ )
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
for( int i = 0; i < modes; i++ )
|
||||
{
|
||||
int j;
|
||||
SDL_DisplayMode mode;
|
||||
|
||||
if( SDL_GetDisplayMode( display_index, i, &mode ) < 0 )
|
||||
@@ -273,6 +271,7 @@ static void R_InitVideoModes( void )
|
||||
if( mode.w < VID_MIN_WIDTH || mode.h < VID_MIN_HEIGHT )
|
||||
continue;
|
||||
|
||||
int j;
|
||||
for( j = 0; j < num_vidmodes; j++ )
|
||||
{
|
||||
if( mode.w == vidmodes[j].width && mode.h == vidmodes[j].height )
|
||||
@@ -294,12 +293,10 @@ static void R_InitVideoModes( void )
|
||||
|
||||
static void R_FreeVideoModes( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !vidmodes )
|
||||
return;
|
||||
|
||||
for( i = 0; i < num_vidmodes; i++ )
|
||||
for( int i = 0; i < num_vidmodes; i++ )
|
||||
Mem_Free( (char*)vidmodes[i].desc );
|
||||
Mem_Free( vidmodes );
|
||||
|
||||
@@ -432,13 +429,11 @@ static qboolean VID_GuessFullscreenMode( int display_index, const SDL_DisplayMod
|
||||
|
||||
static int VID_GetDisplayIndex( const char *caller, SDL_Window *window )
|
||||
{
|
||||
int display_index;
|
||||
|
||||
if( !window )
|
||||
return 0;
|
||||
|
||||
display_index = SDL_GetWindowDisplayIndex( window );
|
||||
|
||||
int display_index = SDL_GetWindowDisplayIndex( window );
|
||||
|
||||
if( display_index < 0 )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: SDL_GetWindowDisplayIndex: %s\n", caller, SDL_GetError());
|
||||
@@ -604,13 +599,12 @@ static rserr_t VID_SetScreenResolution( int width, int height, window_mode_t win
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect r;
|
||||
int x, y;
|
||||
|
||||
SDL_SetWindowSize( host.hWnd, width, height );
|
||||
|
||||
SDL_Rect r;
|
||||
if( VID_GetDisplayBounds( display_index, host.hWnd, &r ) >= 0 )
|
||||
{
|
||||
int x, y;
|
||||
SDL_GetWindowPosition( host.hWnd, &x, &y );
|
||||
|
||||
if( x <= r.x || y <= r.y )
|
||||
@@ -901,7 +895,6 @@ qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
{
|
||||
string safe;
|
||||
SDL_DisplayMode display_mode;
|
||||
|
||||
SDL_GetCurrentDisplayMode( VID_GetDisplayIndex( __func__, NULL ), &display_mode );
|
||||
|
||||
refState.desktopBitsPixel = SDL_BITSPERPIXEL( display_mode.format );
|
||||
@@ -969,7 +962,6 @@ qboolean R_Init_Video( ref_graphic_apis_t type )
|
||||
rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mode )
|
||||
{
|
||||
rserr_t err;
|
||||
SDL_DisplayMode display_mode;
|
||||
|
||||
if( !host.hWnd )
|
||||
err = VID_CreateWindow( width, height, window_mode );
|
||||
@@ -979,6 +971,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mod
|
||||
if( err != rserr_ok )
|
||||
return err;
|
||||
|
||||
SDL_DisplayMode display_mode;
|
||||
SDL_GetWindowDisplayMode( host.hWnd, &display_mode );
|
||||
refState.desktopBitsPixel = SDL_BITSPERPIXEL( display_mode.format );
|
||||
refState.window_mode = window_mode;
|
||||
@@ -994,12 +987,9 @@ Set the described video mode
|
||||
*/
|
||||
qboolean VID_SetMode( void )
|
||||
{
|
||||
int width, height;
|
||||
rserr_t err;
|
||||
window_mode_t window_mode;
|
||||
|
||||
width = window_width.value;
|
||||
height = window_height.value;
|
||||
int width = window_width.value;
|
||||
int height = window_height.value;
|
||||
|
||||
// get default resolution if values aren't set
|
||||
if( width < VID_MIN_WIDTH || height < VID_MIN_HEIGHT )
|
||||
@@ -1025,7 +1015,7 @@ qboolean VID_SetMode( void )
|
||||
}
|
||||
#endif
|
||||
|
||||
window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
window_mode_t window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
SetBits( gl_vsync.flags, FCVAR_CHANGED );
|
||||
|
||||
err = R_ChangeDisplaySettings( width, height, window_mode );
|
||||
@@ -1174,8 +1164,6 @@ void VID_Info_f( void )
|
||||
int width, height;
|
||||
int render_width, render_height;
|
||||
int x, y;
|
||||
int display_index;
|
||||
SDL_DisplayMode dm;
|
||||
|
||||
SDL_GetWindowSize( host.hWnd, &width, &height );
|
||||
VID_GetWindowSizeInPixels( host.hWnd, sw.renderer, &render_width, &render_height );
|
||||
@@ -1193,12 +1181,13 @@ void VID_Info_f( void )
|
||||
Con_Printf( "Window resizable: %s" S_DEFAULT "\n", FBitSet( flags, SDL_WINDOW_RESIZABLE ) ? S_GREEN "true" : S_RED "false" );
|
||||
Con_Printf( "Window maximized: %s" S_DEFAULT "\n", FBitSet( flags, SDL_WINDOW_MAXIMIZED ) ? S_GREEN "true" : S_RED "false" );
|
||||
|
||||
display_index = SDL_GetWindowDisplayIndex( host.hWnd );
|
||||
int display_index = SDL_GetWindowDisplayIndex( host.hWnd );
|
||||
if( display_index >= 0 )
|
||||
Con_Printf( "Window display index: " S_GREEN "%d" S_DEFAULT "\n", display_index );
|
||||
else
|
||||
Con_Printf( "Window display index: " S_RED "fail: " S_DEFAULT "%s\n", SDL_GetError( ));
|
||||
|
||||
SDL_DisplayMode dm;
|
||||
if( SDL_GetWindowDisplayMode( host.hWnd, &dm ) >= 0 )
|
||||
Con_Printf( "Window display mode: " S_GREEN "%dx%d@%d" S_DEFAULT "\n", dm.w, dm.h, dm.refresh_rate );
|
||||
else
|
||||
|
||||
@@ -150,12 +150,12 @@ void Platform_EnableTextInput( qboolean enable )
|
||||
|
||||
int Platform_GetClipboardText( char *buffer, size_t size )
|
||||
{
|
||||
int len;
|
||||
char *text = SDL_GetClipboardText();
|
||||
|
||||
if( !text )
|
||||
return 0;
|
||||
|
||||
int len;
|
||||
if( buffer && size > 0 )
|
||||
len = Q_strncpy( buffer, text, size );
|
||||
else
|
||||
|
||||
@@ -28,18 +28,15 @@ static char sdl_backend_name[32];
|
||||
|
||||
static void SDLash_OutputCallback( void *userdata, SDL_AudioStream *stream, int additional_amount, int len )
|
||||
{
|
||||
const int size = snd.samples << 1;
|
||||
int pos;
|
||||
int wrapped;
|
||||
|
||||
(void)userdata;
|
||||
(void)additional_amount;
|
||||
|
||||
pos = snd.samplepos << 1;
|
||||
const int size = snd.samples << 1;
|
||||
int pos = snd.samplepos << 1;
|
||||
if( pos >= size )
|
||||
pos = snd.samplepos = 0;
|
||||
|
||||
wrapped = pos + len - size;
|
||||
int wrapped = pos + len - size;
|
||||
|
||||
if( wrapped < 0 )
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@ double Platform_DoubleTime( void )
|
||||
{
|
||||
static Uint64 g_PerformanceFrequency;
|
||||
static Uint64 g_ClockStart;
|
||||
Uint64 CurrentTime;
|
||||
|
||||
if( !g_PerformanceFrequency )
|
||||
{
|
||||
@@ -31,7 +30,7 @@ double Platform_DoubleTime( void )
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
CurrentTime = SDL_GetPerformanceCounter();
|
||||
Uint64 CurrentTime = SDL_GetPerformanceCounter();
|
||||
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
||||
}
|
||||
|
||||
|
||||
@@ -119,8 +119,8 @@ static qboolean VID_CreateWindow( const int input_width, const int input_height,
|
||||
if( window_mode == WINDOW_MODE_FULLSCREEN )
|
||||
{
|
||||
SDL_DisplayID display = SDL_GetPrimaryDisplay();
|
||||
SDL_DisplayMode dm;
|
||||
|
||||
SDL_DisplayMode dm;
|
||||
if( SDL_GetClosestFullscreenDisplayMode( display, rect.w, rect.h, 0.0f, true, &dm ))
|
||||
{
|
||||
SetBits( flags, SDL_WINDOW_FULLSCREEN );
|
||||
@@ -139,9 +139,7 @@ static qboolean VID_CreateWindow( const int input_width, const int input_height,
|
||||
if( window_mode == WINDOW_MODE_BORDERLESS )
|
||||
{
|
||||
SDL_DisplayID display = SDL_GetPrimaryDisplay();
|
||||
const SDL_DisplayMode *dm;
|
||||
|
||||
dm = SDL_GetDesktopDisplayMode( display );
|
||||
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode( display );
|
||||
|
||||
if( dm )
|
||||
{
|
||||
@@ -510,10 +508,8 @@ struct vidmode_s *R_GetVideoMode( int num )
|
||||
|
||||
qboolean VID_SetMode( void )
|
||||
{
|
||||
window_mode_t window_mode;
|
||||
int screen_width = Cvar_VariableInteger( "width" );
|
||||
int screen_height = Cvar_VariableInteger( "height" );
|
||||
rserr_t err;
|
||||
|
||||
if( screen_width < VID_MIN_WIDTH || screen_height < VID_MIN_HEIGHT )
|
||||
{
|
||||
@@ -529,10 +525,10 @@ qboolean VID_SetMode( void )
|
||||
}
|
||||
#endif
|
||||
|
||||
window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
window_mode_t window_mode = bound( 0, vid_fullscreen.value, WINDOW_MODE_COUNT - 1 );
|
||||
SetBits( gl_vsync.flags, FCVAR_CHANGED );
|
||||
|
||||
err = R_ChangeDisplaySettings( screen_width, screen_height, window_mode );
|
||||
rserr_t err = R_ChangeDisplaySettings( screen_width, screen_height, window_mode );
|
||||
|
||||
switch( err )
|
||||
{
|
||||
|
||||
@@ -71,9 +71,7 @@ static BOOL WINAPI Wcon_HandleConsole(DWORD CtrlType)
|
||||
|
||||
static void Wcon_PrintInternal( const char *msg, int length )
|
||||
{
|
||||
char *pTemp;
|
||||
DWORD cbWritten;
|
||||
const char *pMsgString;
|
||||
static char tmpBuf[2048];
|
||||
static char szOutput[2048];
|
||||
|
||||
@@ -83,8 +81,8 @@ static void Wcon_PrintInternal( const char *msg, int length )
|
||||
else
|
||||
szOutput[sizeof( szOutput ) - 1] = '\0';
|
||||
|
||||
pTemp = tmpBuf;
|
||||
pMsgString = szOutput;
|
||||
char *pTemp = tmpBuf;
|
||||
const char *pMsgString = szOutput;
|
||||
while( pMsgString && *pMsgString )
|
||||
{
|
||||
if( IsColorString( pMsgString ))
|
||||
@@ -287,9 +285,7 @@ static void Wcon_EventRightArrow( void )
|
||||
|
||||
static int Wcon_EventNewline( void )
|
||||
{
|
||||
int nLen;
|
||||
|
||||
nLen = 0;
|
||||
int nLen = 0;
|
||||
Wcon_PrintInternal( "\n", 0 );
|
||||
if( s_wcd.consoleTextLen )
|
||||
{
|
||||
@@ -317,8 +313,6 @@ static int Wcon_EventNewline( void )
|
||||
|
||||
static void Wcon_EventBackspace( void )
|
||||
{
|
||||
int nCount;
|
||||
|
||||
if( s_wcd.cursorPosition < 1 )
|
||||
{
|
||||
return;
|
||||
@@ -329,7 +323,7 @@ static void Wcon_EventBackspace( void )
|
||||
|
||||
Wcon_PrintInternal( "\b", 0 );
|
||||
|
||||
for( nCount = s_wcd.cursorPosition; nCount < s_wcd.consoleTextLen; ++nCount )
|
||||
for( int nCount = s_wcd.cursorPosition; nCount < s_wcd.consoleTextLen; ++nCount )
|
||||
{
|
||||
s_wcd.consoleText[nCount] = s_wcd.consoleText[nCount + 1];
|
||||
Wcon_PrintInternal( s_wcd.consoleText + nCount, 1 );
|
||||
@@ -337,7 +331,7 @@ static void Wcon_EventBackspace( void )
|
||||
|
||||
Wcon_PrintInternal( " ", 0 );
|
||||
|
||||
nCount = s_wcd.consoleTextLen;
|
||||
int nCount = s_wcd.consoleTextLen;
|
||||
while( nCount >= s_wcd.cursorPosition )
|
||||
{
|
||||
Wcon_PrintInternal( "\b", 0 );
|
||||
@@ -356,14 +350,12 @@ static void Wcon_EventTab( void )
|
||||
|
||||
static void Wcon_EventCharacter(char c)
|
||||
{
|
||||
int nCount;
|
||||
|
||||
if( s_wcd.consoleTextLen >= ( sizeof( s_wcd.consoleText ) - 2 ))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nCount = s_wcd.consoleTextLen;
|
||||
int nCount = s_wcd.consoleTextLen;
|
||||
while( nCount > s_wcd.cursorPosition )
|
||||
{
|
||||
s_wcd.consoleText[nCount] = s_wcd.consoleText[nCount - 1];
|
||||
@@ -388,12 +380,11 @@ static void Wcon_EventCharacter(char c)
|
||||
static void Wcon_UpdateStatusLine( void )
|
||||
{
|
||||
COORD coord;
|
||||
WORD wAttrib;
|
||||
DWORD dwWritten;
|
||||
|
||||
coord.X = 0;
|
||||
coord.Y = 0;
|
||||
wAttrib = g_color_table[5] | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
|
||||
WORD wAttrib = g_color_table[5] | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
|
||||
|
||||
FillConsoleOutputCharacter( s_wcd.hOutput, ' ', 80, coord, &dwWritten );
|
||||
FillConsoleOutputAttribute( s_wcd.hOutput, wAttrib, 80, coord, &dwWritten );
|
||||
@@ -615,15 +606,14 @@ returned input text
|
||||
*/
|
||||
char *Wcon_Input( void )
|
||||
{
|
||||
DWORD i;
|
||||
DWORD eventsCount;
|
||||
static INPUT_RECORD events[1024];
|
||||
|
||||
|
||||
if( !s_wcd.inputEnabled || !s_wcd.hWnd )
|
||||
return NULL;
|
||||
|
||||
while( true )
|
||||
{
|
||||
DWORD eventsCount;
|
||||
if( !GetNumberOfConsoleInputEvents( s_wcd.hInput, &eventsCount ))
|
||||
{
|
||||
return NULL;
|
||||
@@ -640,7 +630,7 @@ char *Wcon_Input( void )
|
||||
if( eventsCount == 0 )
|
||||
return NULL;
|
||||
|
||||
for( i = 0; i < eventsCount; i++ )
|
||||
for( DWORD i = 0; i < eventsCount; i++ )
|
||||
{
|
||||
INPUT_RECORD *pRec = &events[i];
|
||||
if( pRec->EventType != KEY_EVENT )
|
||||
|
||||
@@ -36,11 +36,11 @@ static int Sys_ModuleName( HANDLE process, char *name, void *address, int len )
|
||||
{
|
||||
static HMODULE *moduleArray;
|
||||
static unsigned int moduleCount;
|
||||
DWORD bytesRequired;
|
||||
|
||||
if( len < 3 )
|
||||
return 0;
|
||||
|
||||
DWORD bytesRequired;
|
||||
if( !moduleArray && EnumProcessModules( process, NULL, 0, &bytesRequired ))
|
||||
{
|
||||
if( bytesRequired )
|
||||
|
||||
@@ -52,20 +52,18 @@ static void CopySections( const byte *data, PIMAGE_NT_HEADERS old_headers, PMEMO
|
||||
{
|
||||
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION( module->headers );
|
||||
byte *codeBase = module->codeBase;
|
||||
int i, size;
|
||||
byte *dest;
|
||||
|
||||
for( i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
for( int i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
{
|
||||
if( section->SizeOfRawData == 0 )
|
||||
{
|
||||
// section doesn't contain data in the dll itself, but may define
|
||||
// uninitialized data
|
||||
size = old_headers->OptionalHeader.SectionAlignment;
|
||||
int size = old_headers->OptionalHeader.SectionAlignment;
|
||||
|
||||
if( size > 0 )
|
||||
{
|
||||
dest = (byte *)VirtualAlloc((byte *)CALCULATE_ADDRESS(codeBase, section->VirtualAddress), size, MEM_COMMIT, PAGE_READWRITE );
|
||||
byte *dest = (byte *)VirtualAlloc((byte *)CALCULATE_ADDRESS(codeBase, section->VirtualAddress), size, MEM_COMMIT, PAGE_READWRITE );
|
||||
section->Misc.PhysicalAddress = (DWORD)dest;
|
||||
memset( dest, 0, size );
|
||||
}
|
||||
@@ -74,7 +72,7 @@ static void CopySections( const byte *data, PIMAGE_NT_HEADERS old_headers, PMEMO
|
||||
}
|
||||
|
||||
// commit memory block and copy data from dll
|
||||
dest = (byte *)VirtualAlloc((byte *)CALCULATE_ADDRESS(codeBase, section->VirtualAddress), section->SizeOfRawData, MEM_COMMIT, PAGE_READWRITE );
|
||||
byte *dest = (byte *)VirtualAlloc((byte *)CALCULATE_ADDRESS(codeBase, section->VirtualAddress), section->SizeOfRawData, MEM_COMMIT, PAGE_READWRITE );
|
||||
memcpy( dest, (byte *)CALCULATE_ADDRESS(data, section->PointerToRawData), section->SizeOfRawData );
|
||||
section->Misc.PhysicalAddress = (DWORD)dest;
|
||||
}
|
||||
@@ -84,13 +82,12 @@ static void FreeSections( PIMAGE_NT_HEADERS old_headers, PMEMORYMODULE module )
|
||||
{
|
||||
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(module->headers);
|
||||
byte *codeBase = module->codeBase;
|
||||
int i, size;
|
||||
|
||||
for( i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
for( int i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
{
|
||||
if( section->SizeOfRawData == 0 )
|
||||
{
|
||||
size = old_headers->OptionalHeader.SectionAlignment;
|
||||
int size = old_headers->OptionalHeader.SectionAlignment;
|
||||
if( size > 0 )
|
||||
{
|
||||
VirtualFree((byte *)CALCULATE_ADDRESS( codeBase, section->VirtualAddress ), size, MEM_DECOMMIT );
|
||||
@@ -107,12 +104,10 @@ static void FreeSections( PIMAGE_NT_HEADERS old_headers, PMEMORYMODULE module )
|
||||
static void FinalizeSections( MEMORYMODULE *module )
|
||||
{
|
||||
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION( module->headers );
|
||||
int i;
|
||||
|
||||
// loop through all sections and change access flags
|
||||
for( i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
for( int i = 0; i < module->headers->FileHeader.NumberOfSections; i++, section++ )
|
||||
{
|
||||
DWORD protect, oldProtect, size;
|
||||
int executable = (section->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
|
||||
int readable = (section->Characteristics & IMAGE_SCN_MEM_READ) != 0;
|
||||
int writeable = (section->Characteristics & IMAGE_SCN_MEM_WRITE) != 0;
|
||||
@@ -125,12 +120,12 @@ static void FinalizeSections( MEMORYMODULE *module )
|
||||
}
|
||||
|
||||
// determine protection flags based on characteristics
|
||||
protect = ProtectionFlags[executable][readable][writeable];
|
||||
DWORD protect = ProtectionFlags[executable][readable][writeable];
|
||||
if( section->Characteristics & IMAGE_SCN_MEM_NOT_CACHED )
|
||||
protect |= PAGE_NOCACHE;
|
||||
|
||||
// determine size of region
|
||||
size = section->SizeOfRawData;
|
||||
DWORD size = section->SizeOfRawData;
|
||||
|
||||
if( size == 0 )
|
||||
{
|
||||
@@ -142,6 +137,7 @@ static void FinalizeSections( MEMORYMODULE *module )
|
||||
|
||||
if( size > 0 )
|
||||
{
|
||||
DWORD oldProtect;
|
||||
// change memory access flags
|
||||
if( !VirtualProtect((LPVOID)section->Misc.PhysicalAddress, size, protect, &oldProtect ))
|
||||
Sys_Error( "error protecting memory page\n" );
|
||||
@@ -153,7 +149,6 @@ static void PerformBaseRelocation( MEMORYMODULE *module, DWORD delta )
|
||||
{
|
||||
PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY( module, IMAGE_DIRECTORY_ENTRY_BASERELOC );
|
||||
byte *codeBase = module->codeBase;
|
||||
DWORD i;
|
||||
|
||||
if( directory->Size > 0 )
|
||||
{
|
||||
@@ -163,15 +158,13 @@ static void PerformBaseRelocation( MEMORYMODULE *module, DWORD delta )
|
||||
byte *dest = (byte *)CALCULATE_ADDRESS( codeBase, relocation->VirtualAddress );
|
||||
word *relInfo = (word *)((byte *)relocation + IMAGE_SIZEOF_BASE_RELOCATION );
|
||||
|
||||
for( i = 0; i<((relocation->SizeOfBlock-IMAGE_SIZEOF_BASE_RELOCATION) / 2); i++, relInfo++ )
|
||||
for( DWORD i = 0; i<((relocation->SizeOfBlock-IMAGE_SIZEOF_BASE_RELOCATION) / 2); i++, relInfo++ )
|
||||
{
|
||||
DWORD *patchAddrHL;
|
||||
int type, offset;
|
||||
|
||||
// the upper 4 bits define the type of relocation
|
||||
type = *relInfo >> 12;
|
||||
int type = *relInfo >> 12;
|
||||
// the lower 12 bits define the offset
|
||||
offset = *relInfo & 0xfff;
|
||||
int offset = *relInfo & 0xfff;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
@@ -199,10 +192,7 @@ FARPROC MemoryGetProcAddress( void *module, const char *name )
|
||||
{
|
||||
PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY((MEMORYMODULE *)module, IMAGE_DIRECTORY_ENTRY_EXPORT );
|
||||
byte *codeBase = ((PMEMORYMODULE)module)->codeBase;
|
||||
PIMAGE_EXPORT_DIRECTORY exports;
|
||||
int idx = -1;
|
||||
DWORD i, *nameRef;
|
||||
WORD *ordinal;
|
||||
|
||||
if( directory->Size == 0 )
|
||||
{
|
||||
@@ -210,7 +200,7 @@ FARPROC MemoryGetProcAddress( void *module, const char *name )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
exports = (PIMAGE_EXPORT_DIRECTORY)CALCULATE_ADDRESS( codeBase, directory->VirtualAddress );
|
||||
PIMAGE_EXPORT_DIRECTORY exports = (PIMAGE_EXPORT_DIRECTORY)CALCULATE_ADDRESS( codeBase, directory->VirtualAddress );
|
||||
|
||||
if( exports->NumberOfNames == 0 || exports->NumberOfFunctions == 0 )
|
||||
{
|
||||
@@ -219,10 +209,10 @@ FARPROC MemoryGetProcAddress( void *module, const char *name )
|
||||
}
|
||||
|
||||
// search function name in list of exported names
|
||||
nameRef = (DWORD *)CALCULATE_ADDRESS( codeBase, exports->AddressOfNames );
|
||||
ordinal = (WORD *)CALCULATE_ADDRESS( codeBase, exports->AddressOfNameOrdinals );
|
||||
DWORD *nameRef = (DWORD *)CALCULATE_ADDRESS( codeBase, exports->AddressOfNames );
|
||||
WORD *ordinal = (WORD *)CALCULATE_ADDRESS( codeBase, exports->AddressOfNameOrdinals );
|
||||
|
||||
for( i = 0; i < exports->NumberOfNames; i++, nameRef++, ordinal++ )
|
||||
for( DWORD i = 0; i < exports->NumberOfNames; i++, nameRef++, ordinal++ )
|
||||
{
|
||||
// GetProcAddress case insensative ?????
|
||||
if( !Q_stricmp( name, (const char *)CALCULATE_ADDRESS( codeBase, *nameRef )))
|
||||
@@ -261,11 +251,9 @@ static int BuildImportTable( MEMORYMODULE *module )
|
||||
for( ; !IsBadReadPtr( importDesc, sizeof( IMAGE_IMPORT_DESCRIPTOR )) && importDesc->Name; importDesc++ )
|
||||
{
|
||||
DWORD *thunkRef, *funcRef;
|
||||
LPCSTR libname;
|
||||
void *handle;
|
||||
|
||||
libname = (LPCSTR)CALCULATE_ADDRESS( codeBase, importDesc->Name );
|
||||
handle = COM_LoadLibrary( libname, false, true );
|
||||
LPCSTR libname = (LPCSTR)CALCULATE_ADDRESS( codeBase, importDesc->Name );
|
||||
void *handle = COM_LoadLibrary( libname, false, true );
|
||||
|
||||
if( handle == NULL )
|
||||
{
|
||||
@@ -324,8 +312,6 @@ void MemoryFreeLibrary( void *hInstance )
|
||||
|
||||
if( module != NULL )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( module->initialized != 0 )
|
||||
{
|
||||
// notify library about detaching from process
|
||||
@@ -337,7 +323,7 @@ void MemoryFreeLibrary( void *hInstance )
|
||||
if( module->modules != NULL )
|
||||
{
|
||||
// free previously opened libraries
|
||||
for( i = 0; i < module->numModules; i++ )
|
||||
for( int i = 0; i < module->numModules; i++ )
|
||||
{
|
||||
if( module->modules[i] != NULL )
|
||||
COM_FreeLibrary( module->modules[i] );
|
||||
|
||||
@@ -29,13 +29,12 @@ static const wchar_t *FS_PathToWideChar( const char *path )
|
||||
|
||||
static DWORD GetOffsetByRVA( DWORD rva, PIMAGE_NT_HEADERS nt_header )
|
||||
{
|
||||
int i = 0;
|
||||
PIMAGE_SECTION_HEADER sect_header = IMAGE_FIRST_SECTION( nt_header );
|
||||
|
||||
if (!rva)
|
||||
return rva;
|
||||
|
||||
for( i = 0; i < nt_header->FileHeader.NumberOfSections; i++, sect_header++)
|
||||
PIMAGE_SECTION_HEADER sect_header = IMAGE_FIRST_SECTION( nt_header );
|
||||
|
||||
for( int i = 0; i < nt_header->FileHeader.NumberOfSections; i++, sect_header++)
|
||||
{
|
||||
if( rva >= sect_header->VirtualAddress && rva < sect_header->VirtualAddress + sect_header->Misc.VirtualSize )
|
||||
break;
|
||||
@@ -63,14 +62,12 @@ static void FsGetString( file_t *f, char *str )
|
||||
|
||||
static void FreeNameFuncGlobals( dll_user_t *hInst )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !hInst ) return;
|
||||
|
||||
if( hInst->ordinals ) Mem_Free( hInst->ordinals );
|
||||
if( hInst->funcs ) Mem_Free( hInst->funcs );
|
||||
|
||||
for( i = 0; i < hInst->num_ordinals; i++ )
|
||||
for( int i = 0; i < hInst->num_ordinals; i++ )
|
||||
{
|
||||
if( hInst->names[i] )
|
||||
Mem_Free( hInst->names[i] );
|
||||
@@ -282,10 +279,8 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
|
||||
{
|
||||
if( !Q_strcmp( "GiveFnptrsToDll", hInst->names[i] )) // main entry point for user dlls
|
||||
{
|
||||
void *fn_offset;
|
||||
|
||||
index = hInst->ordinals[i];
|
||||
fn_offset = COM_GetProcAddress( hInst, "GiveFnptrsToDll" );
|
||||
void *fn_offset = COM_GetProcAddress( hInst, "GiveFnptrsToDll" );
|
||||
hInst->funcBase = (uintptr_t)(fn_offset) - hInst->funcs[index];
|
||||
break;
|
||||
}
|
||||
@@ -306,14 +301,13 @@ table_error:
|
||||
static const char *GetLastErrorAsString( void )
|
||||
{
|
||||
const DWORD fm_flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK;
|
||||
DWORD errorcode;
|
||||
wchar_t wide_errormessage[256];
|
||||
static string errormessage;
|
||||
|
||||
errorcode = GetLastError();
|
||||
DWORD errorcode = GetLastError();
|
||||
if ( !errorcode )
|
||||
return "";
|
||||
|
||||
wchar_t wide_errormessage[256];
|
||||
FormatMessageW( fm_flags, NULL, errorcode, 0, wide_errormessage, ARRAYSIZE( wide_errormessage ), NULL );
|
||||
Q_UTF16ToUTF8( errormessage, sizeof( errormessage ), wide_errormessage, ARRAYSIZE( wide_errormessage ));
|
||||
|
||||
@@ -322,32 +316,27 @@ static const char *GetLastErrorAsString( void )
|
||||
|
||||
static PIMAGE_IMPORT_DESCRIPTOR GetImportDescriptor( const char *name, byte *data, PIMAGE_NT_HEADERS *peheader )
|
||||
{
|
||||
PIMAGE_DOS_HEADER dosHeader;
|
||||
PIMAGE_NT_HEADERS peHeader;
|
||||
PIMAGE_DATA_DIRECTORY importDir;
|
||||
PIMAGE_IMPORT_DESCRIPTOR importDesc;
|
||||
|
||||
if ( !data )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: couldn't load %s\n", __func__, name );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dosHeader = (PIMAGE_DOS_HEADER)data;
|
||||
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)data;
|
||||
if ( dosHeader->e_magic != IMAGE_DOS_SIGNATURE )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: %s is not a valid executable file\n", __func__, name );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
peHeader = (PIMAGE_NT_HEADERS)( data + dosHeader->e_lfanew );
|
||||
PIMAGE_NT_HEADERS peHeader = (PIMAGE_NT_HEADERS)( data + dosHeader->e_lfanew );
|
||||
if ( peHeader->Signature != IMAGE_NT_SIGNATURE )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: %s is missing a PE header\n", __func__, name );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
importDir = &peHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
|
||||
PIMAGE_DATA_DIRECTORY importDir = &peHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
|
||||
if( importDir->Size <= 0 )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: %s has no dependencies\n", __func__, name );
|
||||
@@ -355,36 +344,30 @@ static PIMAGE_IMPORT_DESCRIPTOR GetImportDescriptor( const char *name, byte *dat
|
||||
}
|
||||
|
||||
*peheader = peHeader;
|
||||
importDesc = (PIMAGE_IMPORT_DESCRIPTOR)CALCULATE_ADDRESS( data, GetOffsetByRVA( importDir->VirtualAddress, peHeader ) );
|
||||
|
||||
return importDesc;
|
||||
return (PIMAGE_IMPORT_DESCRIPTOR)CALCULATE_ADDRESS( data, GetOffsetByRVA( importDir->VirtualAddress, peHeader ) );
|
||||
}
|
||||
|
||||
static void ListMissingModules( dll_user_t *hInst )
|
||||
{
|
||||
PIMAGE_NT_HEADERS peHeader;
|
||||
PIMAGE_IMPORT_DESCRIPTOR importDesc;
|
||||
byte *data;
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
if( !hInst || !g_fsapi.LoadFile ) return;
|
||||
|
||||
data = g_fsapi.LoadFile( hInst->dllName, NULL, false );
|
||||
byte *data = g_fsapi.LoadFile( hInst->dllName, NULL, false );
|
||||
if( !data ) return;
|
||||
|
||||
importDesc = GetImportDescriptor( hInst->dllName, data, &peHeader );
|
||||
PIMAGE_NT_HEADERS peHeader;
|
||||
PIMAGE_IMPORT_DESCRIPTOR importDesc = GetImportDescriptor( hInst->dllName, data, &peHeader );
|
||||
if( !importDesc )
|
||||
{
|
||||
Mem_Free( data );
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[MAX_VA_STRING];
|
||||
for( ; !IsBadReadPtr( importDesc, sizeof( IMAGE_IMPORT_DESCRIPTOR ) ) && importDesc->Name; importDesc++ )
|
||||
{
|
||||
HMODULE hMod;
|
||||
const char *importName = (const char *)CALCULATE_ADDRESS( data, GetOffsetByRVA( importDesc->Name, peHeader ) );
|
||||
|
||||
hMod = LoadLibraryExW( FS_PathToWideChar( importName ), NULL, LOAD_LIBRARY_AS_DATAFILE );
|
||||
HMODULE hMod = LoadLibraryExW( FS_PathToWideChar( importName ), NULL, LOAD_LIBRARY_AS_DATAFILE );
|
||||
if ( !hMod )
|
||||
{
|
||||
Q_snprintf( buf, sizeof( buf ), "%s not found!", importName );
|
||||
@@ -400,23 +383,18 @@ static void ListMissingModules( dll_user_t *hInst )
|
||||
|
||||
qboolean COM_CheckLibraryDirectDependency( const char *name, const char *depname, qboolean directpath )
|
||||
{
|
||||
PIMAGE_NT_HEADERS peHeader;
|
||||
PIMAGE_IMPORT_DESCRIPTOR importDesc;
|
||||
byte *data;
|
||||
dll_user_t *hInst;
|
||||
qboolean ret = FALSE;
|
||||
|
||||
hInst = FS_FindLibrary( name, directpath );
|
||||
dll_user_t *hInst = FS_FindLibrary( name, directpath );
|
||||
if ( !hInst ) return FALSE;
|
||||
|
||||
data = FS_LoadFile( name, NULL, false );
|
||||
byte *data = FS_LoadFile( name, NULL, false );
|
||||
if ( !data )
|
||||
{
|
||||
COM_FreeLibrary( hInst );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
importDesc = GetImportDescriptor( name, data, &peHeader );
|
||||
PIMAGE_NT_HEADERS peHeader;
|
||||
PIMAGE_IMPORT_DESCRIPTOR importDesc = GetImportDescriptor( name, data, &peHeader );
|
||||
if ( !importDesc )
|
||||
{
|
||||
COM_FreeLibrary( hInst );
|
||||
@@ -450,12 +428,11 @@ smart dll loader - can loading dlls from pack or wad files
|
||||
*/
|
||||
void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean directpath )
|
||||
{
|
||||
dll_user_t *hInst;
|
||||
char buf[MAX_VA_STRING];
|
||||
|
||||
COM_ResetLibraryError();
|
||||
|
||||
hInst = FS_FindLibrary( dllname, directpath );
|
||||
dll_user_t *hInst = FS_FindLibrary( dllname, directpath );
|
||||
if( !hInst )
|
||||
{
|
||||
Q_snprintf( buf, sizeof( buf ), "Failed to find library %s", dllname );
|
||||
@@ -558,16 +535,15 @@ void COM_FreeLibrary( void *hInstance )
|
||||
void *COM_FunctionFromName( void *hInstance, const char *pName )
|
||||
{
|
||||
dll_user_t *hInst = (dll_user_t *)hInstance;
|
||||
int i, index;
|
||||
|
||||
if( !hInst || !hInst->hInstance )
|
||||
return 0;
|
||||
|
||||
for( i = 0; i < hInst->num_ordinals; i++ )
|
||||
for( int i = 0; i < hInst->num_ordinals; i++ )
|
||||
{
|
||||
if( !Q_strcmp( pName, hInst->names[i] ))
|
||||
{
|
||||
index = hInst->ordinals[i];
|
||||
int index = hInst->ordinals[i];
|
||||
return (void *)( hInst->funcs[index] + hInst->funcBase );
|
||||
}
|
||||
}
|
||||
@@ -581,14 +557,13 @@ void *COM_FunctionFromName( void *hInstance, const char *pName )
|
||||
const char *COM_NameForFunction( void *hInstance, void *function )
|
||||
{
|
||||
dll_user_t *hInst = (dll_user_t *)hInstance;
|
||||
int i, index;
|
||||
|
||||
if( !hInst || !hInst->hInstance )
|
||||
return NULL;
|
||||
|
||||
for( i = 0; i < hInst->num_ordinals; i++ )
|
||||
for( int i = 0; i < hInst->num_ordinals; i++ )
|
||||
{
|
||||
index = hInst->ordinals[i];
|
||||
int index = hInst->ordinals[i];
|
||||
|
||||
if(( (char*)function - (char*)hInst->funcBase ) == hInst->funcs[index] )
|
||||
return hInst->names[i];
|
||||
|
||||
@@ -25,13 +25,14 @@ double Platform_DoubleTime( void )
|
||||
{
|
||||
static LARGE_INTEGER g_PerformanceFrequency;
|
||||
static LARGE_INTEGER g_ClockStart;
|
||||
LARGE_INTEGER CurrentTime;
|
||||
|
||||
if( !g_PerformanceFrequency.QuadPart )
|
||||
{
|
||||
QueryPerformanceFrequency( &g_PerformanceFrequency );
|
||||
QueryPerformanceCounter( &g_ClockStart );
|
||||
}
|
||||
|
||||
LARGE_INTEGER CurrentTime;
|
||||
QueryPerformanceCounter( &CurrentTime );
|
||||
|
||||
return (double)( CurrentTime.QuadPart - g_ClockStart.QuadPart ) / (double)( g_PerformanceFrequency.QuadPart );
|
||||
@@ -84,11 +85,10 @@ void Win32_Shutdown( void )
|
||||
|
||||
qboolean Win32_NanoSleep( int nsec )
|
||||
{
|
||||
LARGE_INTEGER ts;
|
||||
|
||||
if( !g_waitable_timer )
|
||||
return false;
|
||||
|
||||
LARGE_INTEGER ts;
|
||||
ts.QuadPart = -nsec / 100;
|
||||
|
||||
if( !SetWaitableTimer( g_waitable_timer, &ts, 0, NULL, NULL, FALSE ))
|
||||
|
||||
Reference in New Issue
Block a user