/* ==================== Interactive line editing and console scrollback ==================== */ static void Key_Console (int key, int unicode) { // LordHavoc: copied most of this from Q2 to improve keyboard handling switch (key) { case K_KP_SLASH: key = '/'; break; case K_KP_MINUS: key = '-'; break; case K_KP_PLUS: key = '+'; break; case K_KP_HOME: key = '7'; break; case K_KP_UPARROW: key = '8'; break; case K_KP_PGUP: key = '9'; break; case K_KP_LEFTARROW: key = '4'; break; case K_KP_5: key = '5'; break; case K_KP_RIGHTARROW: key = '6'; break; case K_KP_END: key = '1'; break; case K_KP_DOWNARROW: key = '2'; break; case K_KP_PGDN: key = '3'; break; case K_KP_INS: key = '0'; break; case K_KP_DEL: key = '.'; break; } if ((key == 'v' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT])) { char *cbd, *p; if ((cbd = Sys_GetClipboardData()) != 0) { int i; #if 1 p = cbd; while (*p) { if (*p == '\r' && *(p+1) == '\n') { *p++ = ';'; *p++ = ' '; } else if (*p == '\n' || *p == '\r' || *p == '\b') *p++ = ';'; p++; } #else strtok(cbd, "\n\r\b"); #endif i = (int)strlen(cbd); if (i + key_linepos >= MAX_INPUTLINE) i= MAX_INPUTLINE - key_linepos - 1; if (i > 0) { cbd[i] = 0; memmove(key_line + key_linepos + i, key_line + key_linepos, sizeof(key_line) - key_linepos - i); memcpy(key_line + key_linepos, cbd, i); key_linepos += i; } Z_Free(cbd); } return; } if (key == 'l' && keydown[K_CTRL]) { Cbuf_AddText ("clear\n"); return; } if (key == 'u' && keydown[K_CTRL]) // like vi/readline ^u: delete currently edited line { // clear line key_line[0] = ']'; key_line[1] = 0; key_linepos = 1; return; } if (key == 'q' && keydown[K_CTRL]) // like zsh ^q: push line to history, don't execute, and clear { // clear line Key_History_Push(); key_line[0] = ']'; key_line[1] = 0; key_linepos = 1; return; } if (key == K_ENTER || key == K_KP_ENTER) { Cbuf_AddText (key_line+1); // skip the ] Cbuf_AddText ("\n"); Key_History_Push(); key_line[0] = ']'; key_line[1] = 0; // EvilTypeGuy: null terminate key_linepos = 1; // force an update, because the command may take some time if (cls.state == ca_disconnected) CL_UpdateScreen (); return; } if (key == K_TAB) { if(keydown[K_CTRL]) // append to the cvar its value { int cvar_len, cvar_str_len, chars_to_move; char k; char cvar[MAX_INPUTLINE]; const char *cvar_str; // go to the start of the variable while(--key_linepos) { k = key_line[key_linepos]; if(k == '\"' || k == ';' || k == ' ' || k == '\'') break; } key_linepos++; // save the variable name in cvar for(cvar_len=0; (k = key_line[key_linepos + cvar_len]) != 0; cvar_len++) { if(k == '\"' || k == ';' || k == ' ' || k == '\'') break; cvar[cvar_len] = k; } if (cvar_len==0) return; cvar[cvar_len] = 0; // go to the end of the cvar key_linepos += cvar_len; // save the content of the variable in cvar_str cvar_str = Cvar_VariableString(cvar); cvar_str_len = (int)strlen(cvar_str); if (cvar_str_len==0) return; // insert space and cvar_str in key_line chars_to_move = (int)strlen(&key_line[key_linepos]); if (key_linepos + 1 + cvar_str_len + chars_to_move < MAX_INPUTLINE) { if (chars_to_move) memmove(&key_line[key_linepos + 1 + cvar_str_len], &key_line[key_linepos], chars_to_move); key_line[key_linepos++] = ' '; memcpy(&key_line[key_linepos], cvar_str, cvar_str_len); key_linepos += cvar_str_len; key_line[key_linepos + chars_to_move] = 0; } else Con_Printf("Couldn't append cvar value, edit line too long.\n"); return; } // Enhanced command completion // by EvilTypeGuy [email protected] // Thanks to Fett, Taniwha Con_CompleteCommandLine(); return; } // Advanced Console Editing by Radix [email protected] // Added/Modified by EvilTypeGuy [email protected] // Enhanced by [515] // Enhanced by terencehill // move cursor to the previous character if (key == K_LEFTARROW || key == K_KP_LEFTARROW) { if (key_linepos < 2) return; if(keydown[K_CTRL]) // move cursor to the previous word { int pos; char k; pos = key_linepos-1; if(pos) // skip all "; ' after the word while(--pos) { k = key_line[pos]; if (!(k == '\"' || k == ';' || k == ' ' || k == '\'')) break; } if(pos) while(--pos) { k = key_line[pos]; if(k == '\"' || k == ';' || k == ' ' || k == '\'') break; } key_linepos = pos + 1; } else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors { int pos; size_t inchar = 0; pos = (int)u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte while (pos) if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos])) pos-=2; else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos])) pos-=5; else { if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && key_line[pos] == STRING_COLOR_TAG) // consider ^^ as a character pos--; pos--; break; } // we need to move to the beginning of the character when in a wide character: u8_charidx(key_line, pos + 1, &inchar); key_linepos = (int)(pos + 1 - inchar); } else { key_linepos = (int)u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte } return; } // delete char before cursor if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL])) { if (key_linepos > 1) { int newpos = (int)u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte strlcpy(key_line + newpos, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos); key_linepos = newpos; } return; } // delete char on cursor if (key == K_DEL || key == K_KP_DEL) { size_t linelen; linelen = strlen(key_line); if (key_linepos < (int)linelen) memmove(key_line + key_linepos, key_line + key_linepos + u8_bytelen(key_line + key_linepos, 1), linelen - key_linepos); return; } // move cursor to the next character if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW) { if (key_linepos >= (int)strlen(key_line)) return; if(keydown[K_CTRL]) // move cursor to the next word { int pos, len; char k; len = (int)strlen(key_line); pos = key_linepos; while(++pos < len) { k = key_line[pos]; if(k == '\"' || k == ';' || k == ' ' || k == '\'') break; } if (pos < len) // skip all "; ' after the word while(++pos < len) { k = key_line[pos]; if (!(k == '\"' || k == ';' || k == ' ' || k == '\'')) break; } key_linepos = pos; } else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors { int pos, len; len = (int)strlen(key_line); pos = key_linepos; // go beyond all initial consecutive color tags, if any if(pos < len) while (key_line[pos] == STRING_COLOR_TAG) { if(isdigit(key_line[pos+1])) pos+=2; else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4])) pos+=5; else break; } // skip the char if (key_line[pos] == STRING_COLOR_TAG && key_line[pos+1] == STRING_COLOR_TAG) // consider ^^ as a character pos++; pos += (int)u8_bytelen(key_line + pos, 1); // now go beyond all next consecutive color tags, if any if(pos < len) while (key_line[pos] == STRING_COLOR_TAG) { if(isdigit(key_line[pos+1])) pos+=2; else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4])) pos+=5; else break; } key_linepos = pos; } else key_linepos += (int)u8_bytelen(key_line + key_linepos, 1); return; } if (key == K_INS || key == K_KP_INS) // toggle insert mode { key_insert ^= 1; return; } // End Advanced Console Editing if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL])) { Key_History_Up(); return; } if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL])) { Key_History_Down(); return; } if (keydown[K_CTRL]) { // prints all the matching commands if (key == 'f') { Key_History_Find_All(); return; } // Search forwards/backwards, pointing the history's index to the // matching command but without fetching it to let one continue the search. // To fetch it, it suffices to just press UP or DOWN. if (key == 'r') { if (keydown[K_SHIFT]) Key_History_Find_Forwards(); else Key_History_Find_Backwards(); return; } // go to the last/first command of the history if (key == ',') { Key_History_First(); return; } if (key == '.') { Key_History_Last(); return; } } if (key == K_PGUP || key == K_KP_PGUP) { if(keydown[K_CTRL]) { con_backscroll += ((vid_conheight.integer >> 2) / con_textsize.integer)-1; } else con_backscroll += ((vid_conheight.integer >> 1) / con_textsize.integer)-3; return; }
/* ============== SCR_LoadPCX ============== */ void SCR_LoadPCX (char *filename, byte **pic, byte **palette, int *width, int *height) { byte *raw; pcx_t *pcx; int x, y; int len; int dataByte, runLength; byte *out, *pix; *pic = NULL; // // load the file // len = FS_LoadFile (filename, (void **)&raw); if (!raw) return; // Com_Printf ("Bad pcx file %s\n", filename); // // parse the PCX file // pcx = (pcx_t *)raw; raw = &pcx->data; if (pcx->manufacturer != 0x0a || pcx->version != 5 || pcx->encoding != 1 || pcx->bits_per_pixel != 8 || pcx->xmax >= 640 || pcx->ymax >= 480) { Com_Printf ("Bad pcx file %s\n", filename); return; } out = Z_Malloc ( (pcx->ymax+1) * (pcx->xmax+1) ); *pic = out; pix = out; if (palette) { *palette = Z_Malloc(768); memcpy (*palette, (byte *)pcx + len - 768, 768); } if (width) *width = pcx->xmax+1; if (height) *height = pcx->ymax+1; for (y=0 ; y<=pcx->ymax ; y++, pix += pcx->xmax+1) { for (x=0 ; x<=pcx->xmax ; ) { dataByte = *raw++; if((dataByte & 0xC0) == 0xC0) { runLength = dataByte & 0x3F; dataByte = *raw++; } else runLength = 1; while(runLength-- > 0) pix[x++] = dataByte; } } if ( raw - (byte *)pcx > len) { Com_Printf ("PCX file %s was malformed", filename); Z_Free (*pic); *pic = NULL; } FS_FreeFile (pcx); }
/* <4c63> ../engine/cmd.c:521 */ void Cmd_Alias_f(void) { cmdalias_t *a; const char *s; char cmd[MAX_CMD_LINE]; int i, c; if (Cmd_Argc() == 1) { // Output all aliases Con_Printf("Current alias commands:\n"); for (a = cmd_alias; a; a = a->next) { Con_Printf("%s : %s", a->name, a->value); // Don't need \n here, because each alias value is appended with it } return; } s = Cmd_Argv(1); if (Q_strlen(s) >= MAX_ALIAS_NAME) { Con_Printf("Alias name is too long\n"); return; } if (Cvar_FindVar(s)) { Con_Printf("Alias name is invalid\n"); return; } SetCStrikeFlags(); // TODO: Do this once somewhere at the server start if ((g_bIsCStrike || g_bIsCZero) && (!Q_stricmp(s, "cl_autobuy") || !Q_stricmp(s, "cl_rebuy") || !Q_stricmp(s, "gl_ztrick") || !Q_stricmp(s, "gl_ztrick_old") || !Q_stricmp(s, "gl_d3dflip"))) { Con_Printf("Alias name is invalid\n"); return; } // Say hello to my little friend! (c) if (g_bIsTFC && (!Q_stricmp(s, "_special") || !Q_stricmp(s, "special"))) { Con_Printf("Alias name is invalid\n"); return; } // Gather arguments into one string cmd[0] = 0; c = Cmd_Argc(); for (i = 2; i <= c; i++) { Q_strncat(cmd, Cmd_Argv(i), MAX_CMD_LINE - 2 - Q_strlen(cmd)); // always have a space for \n or ' ' and \0 if (i != c) { Q_strcat(cmd, " "); } } Q_strcat(cmd, "\n"); // Search for existing alias for (a = cmd_alias; a; a = a->next) { if (!Q_stricmp(a->name, s)) { if (!Q_strcmp(a->value, cmd)) { // Same value on the alias, return return; } // Release value, will realloc Z_Free(a->value); break; } } if (!a) { // Alloc new alias a = (cmdalias_t *)Z_Malloc(sizeof(cmdalias_t)); a->next = cmd_alias; cmd_alias = a; Q_strncpy(a->name, s, ARRAYSIZE(a->name) - 1); a->name[ARRAYSIZE(a->name) - 1] = 0; } a->value = CopyString(cmd); }
/* ================= S_CodecUtilClose ================= */ void S_CodecUtilClose(snd_stream_t **stream) { FS_FCloseFile((*stream)->file); Z_Free(*stream); *stream = NULL; }
/* ==================== SV_ParseVersionMapping Reads versionmap.cfg which sets up a mapping of client version to installer to download ==================== */ void SV_ParseVersionMapping( void ) { int handle; char *filename = "versionmap.cfg"; char *buf; char *buftrav; char *token; int len; len = FS_SV_FOpenFileRead( filename, &handle ); if ( len >= 0 ) { // the file exists buf = (char *)Z_Malloc( len + 1 ); memset( buf, 0, len + 1 ); FS_Read( (void *)buf, len, handle ); FS_FCloseFile( handle ); // now parse the file, setting the version table info buftrav = buf; token = COM_Parse( &buftrav ); if ( strcmp( token, "RTCW-VersionMap" ) ) { Z_Free( buf ); Com_Error( ERR_FATAL, "invalid versionmap.cfg" ); return; } Com_Printf( "\n------------Update Server-------------\n\nParsing version map..." ); while ( ( token = COM_Parse( &buftrav ) ) && token[0] ) { // read the version number strcpy( versionMap[ numVersions ].version, token ); // read the platform token = COM_Parse( &buftrav ); if ( token && token[0] ) { strcpy( versionMap[ numVersions ].platform, token ); } else { Z_Free( buf ); Com_Error( ERR_FATAL, "error parsing versionmap.cfg, after %s", versionMap[ numVersions ].version ); return; } // read the installer name token = COM_Parse( &buftrav ); if ( token && token[0] ) { strcpy( versionMap[ numVersions ].installer, token ); } else { Z_Free( buf ); Com_Error( ERR_FATAL, "error parsing versionmap.cfg, after %s", versionMap[ numVersions ].platform ); return; } numVersions++; if ( numVersions >= MAX_UPDATE_VERSIONS ) { Z_Free( buf ); Com_Error( ERR_FATAL, "Exceeded maximum number of mappings(%d)", MAX_UPDATE_VERSIONS ); return; } } Com_Printf( " found %d mapping%c\n--------------------------------------\n\n", numVersions, numVersions > 1 ? 's' : ' ' ); Z_Free( buf ); } else { Com_Error( ERR_FATAL, "Couldn't open versionmap.cfg" ); } }
void X_DestroyLUTs(void) { Z_Free(orbitTableX); Z_Free(orbitTableY); Z_Free(FloatBobOffset); }
bool _buildFileListFromSavedList(void) { // open the file up for reading FILE* in; in = fopen("d:\\xbx_filelist","rb"); if(!in) { return false; } // read in the number of files int count; if(!(fread(&count,sizeof(count),1,in))) { fclose(in); return false; } // allocate memory for a temp buffer byte* baseAddr; int bufferSize; bufferSize = count * ( 2 * sizeof(int) + MAX_OSPATH ); buffer = (byte*)Z_Malloc(bufferSize,TAG_TEMP_WORKSPACE,qtrue,32); baseAddr = buffer; // read the rest of the file into a big buffer if(!(fread(buffer,bufferSize,1,in))) { fclose(in); Z_Free(baseAddr); return false; } // allocate some memory for s_Files s_Files = new VVFixedMap<FileInfo, unsigned int>(count); // loop through all the files write out the codes int i; for(i = 0; i < count; i++) { FileInfo info; unsigned int code; // read the code for the file code = *(int*)buffer; buffer += sizeof(code); // read the filename info.name = CopyString((char*)buffer); buffer += (strlen(info.name) + 1); // read the size of the file info.size = *(int*)buffer; buffer += sizeof(info.size); // save the data s_Files->Insert(info, code); } fclose(in); Z_Free(baseAddr); return true; }
static void SV_CloseFile_Hr_v13(void) { if(!saveBuffer) return; Z_Free(saveBuffer); saveBuffer = savePtr = NULL; }
int wipe_exitMelt(int width, int height, int ticks) { Z_Free(y); return 0; }
int HTTPServer_ReadMessage(netadr_t* from, msg_t* msg, ftRequest_t* request) { char stringlinebuf[MAX_STRING_CHARS]; byte* newbuf; char* line; int newsize, i; qboolean gotheader; if (request->recvmsg.maxsize - request->recvmsg.cursize < msg->cursize) { if(request->finallen != -1) { newsize = request->finallen; }else { newsize = 2 * request->recvmsg.maxsize + msg->cursize; } newbuf = Z_Malloc(newsize); if(newbuf == NULL) { return -1; } Com_Memcpy(newbuf, request->recvmsg.data, request->recvmsg.cursize); Z_Free(request->recvmsg.data); request->recvmsg.data = newbuf; request->recvmsg.maxsize = newsize; } Com_Memcpy(&request->recvmsg.data[request->recvmsg.cursize], msg->data, msg->cursize); request->recvmsg.cursize += msg->cursize; /* Is header complete ? */ if(request->finallen == -1) { gotheader = qfalse; /* 1st check if the header is complete */ while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' ) { if(line[0] == '\r') { gotheader = qtrue; break; } } if(gotheader == qfalse) { return 0; } MSG_BeginReading(&request->recvmsg); line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf)); if (!Q_strncmp(line, "HEAD", 4)) { request->mode = HTTP_HEAD; line += 5; }else if (!Q_strncmp(line, "POST", 4)) { request->mode = HTTP_POST; line += 5; }else if (!Q_strncmp(line, "GET", 3)) { request->mode = HTTP_GET; line += 4; }else { Com_DPrintf("Invalid HTTP method from %s\n", NET_AdrToString(from)); return -1; } i = 0; while (*line != ' ' && *line != '\r' && *line) { request->url[i] = *line; i++; line++; } if(*line == ' ') { line++; } if(Q_stricmpn(line,"HTTP/1.",7) || isInteger(line + 7, 2) == qfalse || isInteger(line + 9, 4) == qfalse) { Com_PrintError("HTTP_ReceiveData: Packet is corrupt!\nDebug: %s\n", line); return -1; } request->version = atoi(line + 7); if (request->version != 0 && request->version != 1) { Com_PrintError("HTTP_ReceiveData: Packet has unknown HTTP version 1.%d !\n", request->version); return -1; } request->contentLength = 0; while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' && line[0] != '\r') { if(!Q_stricmpn("Content-Length:", line, 15)) { if(isInteger(line + 15, 0) == qfalse) { Com_PrintError("Sec_GetHTTPPacket: Packet is corrupt!\nDebug: %s\n", line); return -1; } request->contentLength = atoi(line + 15); if(request->contentLength < 0) { request->contentLength = 0; return -1; } } else if(!Q_stricmpn("Content-Type:", line, 13)) { if(line[13] == ' ') { Q_strncpyz(request->contentType, &line[14], sizeof(request->contentType)); }else{ Q_strncpyz(request->contentType, &line[13], sizeof(request->contentType)); } } else if(!Q_stricmpn("Cookie:", line, 7)) { if(line[7] == ' ') { Q_strncpyz(request->cookie, &line[8], sizeof(request->cookie)); }else{ Q_strncpyz(request->cookie, &line[7], sizeof(request->cookie)); } } } if(line[0] == '\0') return -1; request->headerLength = request->recvmsg.readcount; request->finallen = request->contentLength + request->headerLength; if(request->finallen > 1024*1024*640) { request->finallen = request->headerLength; } } if(request->recvmsg.maxsize == request->finallen) request->transferactive = qtrue; if (request->recvmsg.cursize < request->finallen) { /* Still needing bytes... */ return 0; } // Com_Printf("^6HTTP-Message is complete!\n"); // Com_Printf("^6Received: Version: HTTP/1.%d Method: %d Content-Length: %d URL: %s\n", request->version, request->mode, request->contentLength, request->url); return 1; }
wad_file_t *W_AddFile (char *filename) { wadinfo_t header; lumpinfo_t *lump_p; unsigned int i; wad_file_t *wad_file; int length; int startlump; filelump_t *fileinfo; filelump_t *filerover; // open the file and add to directory wad_file = W_OpenFile(filename); if (wad_file == NULL) return NULL; startlump = numlumps; if (strcasecmp(filename + strlen(filename) - 3, "wad")) { // single lump file // fraggle: Swap the filepos and size here. The WAD directory // parsing code expects a little-endian directory, so will swap // them back. Effectively we're constructing a "fake WAD directory" // here, as it would appear on disk. fileinfo = (filelump_t *)Z_Malloc(sizeof(filelump_t), PU_STATIC, 0); fileinfo->filepos = LONG(0); fileinfo->size = LONG(wad_file->length); // Name the lump after the base of the filename (without the // extension). ExtractFileBase(filename, fileinfo->name); numlumps++; } else { // WAD file W_Read(wad_file, 0, &header, sizeof(header)); if (strncmp(header.identification, "IWAD", 4)) { // Homebrew levels? if (strncmp(header.identification, "PWAD", 4)) I_Error("Wad file %s doesn't have IWAD or PWAD id\n", filename); } header.numlumps = LONG(header.numlumps); header.infotableofs = LONG(header.infotableofs); length = header.numlumps * sizeof(filelump_t); fileinfo = (filelump_t *)Z_Malloc(length, PU_STATIC, 0); W_Read(wad_file, header.infotableofs, fileinfo, length); numlumps += header.numlumps; } // Fill in lumpinfo lumpinfo = (lumpinfo_t *)realloc(lumpinfo, numlumps * sizeof(lumpinfo_t)); if (lumpinfo == NULL) I_Error("Couldn't realloc lumpinfo"); lump_p = &lumpinfo[startlump]; filerover = fileinfo; for (i = startlump; i < numlumps; ++i) { lump_p->wad_file = wad_file; lump_p->position = LONG(filerover->filepos); lump_p->size = LONG(filerover->size); lump_p->cache = NULL; strncpy(lump_p->name, filerover->name, 8); ++lump_p; ++filerover; } Z_Free(fileinfo); if (lumphash != NULL) { Z_Free(lumphash); lumphash = NULL; } return wad_file; }
static int FTP_SendReceiveData(ftRequest_t* request) { char* line; char command[MAX_STRING_CHARS]; int status, bytes; byte* buf; netadr_t pasvadr; char stringlinebuf[MAX_STRING_CHARS]; status = FT_ReceiveData(request); if (status == -1 && request->stage < 9999) { return -1; } if(status == 0 && request->stage < 9999) { status = FT_SendData(request); } if (status == -1 && request->stage < 9999) { return -1; } while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' ) { if(isNumeric(line, 0) == qfalse) continue; request->code = atoi(line); if(request->stage > 60) Com_DPrintf("\n"); Com_DPrintf("Response Code = %d\n", request->code); if (request->stage < 0) { continue; } switch (request->code) { case 220: if(request->stage == 0) { // Initial OK response received / Com_DPrintf("FTP_SendReceiveData: Inital OK response received\n"); request->stage = 1; }else { Com_PrintWarning("\nFTP_SendReceiveData: Received: %s - Should not happen!\n", line); } break; case 202: if(request->stage < 21 && request->stage > 10) { request->stage = 21; }else { Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 331: if(request->stage == 10) { Com_DPrintf("FTP_SendReceiveData: Need Password\n"); request->stage = 11; }else if(request->stage == 16){ Com_DPrintf("FTP_SendReceiveData: Need Password\n"); request->stage = 17; }else { Com_Printf("FTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 332: if(request->stage == 10 || request->stage == 12) { Com_DPrintf("FTP_SendReceiveData: Need Account\n"); request->stage = 15; }else { Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 230: if (request->stage <= 20) { Com_DPrintf("FTP_SendReceiveData: Logged in OK\n"); request->stage = 21; }else { Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 227: if(request->stage == 36) { FTP_GetPassiveAddress(line, &pasvadr); if(pasvadr.type == NA_IP) { Com_DPrintf("FTP_SendReceiveData: Entering Passive Mode at %s OK\n", NET_AdrToString(&pasvadr)); request->transfersocket = NET_TcpClientConnect(NET_AdrToString(&pasvadr)); if(request->transfersocket < 0) { request->transfersocket = -1; return -1; } request->stage = 41; }else { Com_PrintWarning("FTP_SendReceiveData: Couldn't read the address/port of passive mode response\n"); return -1; } }else { Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 229: if(request->stage == 32) { FTP_GetExtendedPassiveAddress(line, request->address, &pasvadr); if(pasvadr.type == NA_IP || pasvadr.type == NA_IP6) { Com_DPrintf("FTP_SendReceiveData: Entering Extended Passive Mode at %s OK\n", NET_AdrToString(&pasvadr)); request->transfersocket = NET_TcpClientConnect(NET_AdrToString(&pasvadr)); if(request->transfersocket < 0) { request->transfersocket = -1; return -1; } request->stage = 41; }else { Com_PrintWarning("FTP_SendReceiveData: Couldn't read the address/port of passive mode response\n"); return -1; } }else { Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line); request->stage = -20; } break; case 213: if(request->stage == 50) { bytes = atoi(&line[4]); Com_DPrintf("FTP_SendReceiveData: Requested file will have %d bytes\n", bytes); if(bytes < 1 || bytes > 1024*1024*1024) { Com_PrintWarning("FTP_SendReceiveData: Requested file would exceed %d bytes. Will not download!\n", 1024*1024*1024); } buf = Z_Malloc(bytes); if( buf == NULL) { Com_PrintWarning("FTP_SendReceiveData: Failed to allocate %d bytes for download file!\n", bytes); return -1; } MSG_Init(&request->transfermsg, buf, bytes); request->stage = 51; } break; case 150: case 125: if (request->stage == 60) { request->stage = 61; Com_DPrintf("FTP_SendReceiveData: Begin File Transfer\n"); } break; case 226: /* File transfer is completed from the servers view */ if(request->stage < 9999) request->stage = 9999; break; case 221: if(request->stage < 10000) { Com_Printf("\nThe FTP server closed the control connection before the transfer was completed!\n"); request->stage = -1; } break; case 228: Com_Printf( "\nLong Passive Mode not supported and not requested!\n" ); request->stage = -20; break; case 120: Com_Printf( "The FTP server is not ready at the moment!\n" ); request->stage = -20; break; case 231: if(request->stage < 10000) { Com_Printf("\nThe FTP server logged us out before the transfer was completed!\n"); request->stage = -20; } break; case 350: if(request->stage < 10000) { Com_Printf("\nThe FTP server returned \'%s\' before the transfer was completed. Must not happen!\n", line); request->stage = -20; } break; case 421: request->stage = -1; break; case 500: case 501: case 502: case 503: if (request->stage == 32) { request->stage = 35; Com_DPrintf("FTP_SendReceiveData: Command EPSV is not implemented on FTP server. Trying PASV...\n"); break; }else if (request->stage == 36) { Com_Printf("FTP_SendReceiveData: FTP Server does not support passive mode. Request failed!\n"); request->stage = -10; } default: if (request->code >= 200 && request->code < 300 && request->stage >= 30){ Com_DPrintf("\n"); Com_DPrintf("FTP_SendReceiveData: %s\n", line); request->stage ++; break; }else if (request->code >= 400) { Com_Printf("\nThe FTP server connection got ended with the message: %s\n", line); request->stage = -20; } break; } } switch(request->stage) { case 1: /* Waiting for OK response code (220) */ Com_sprintf(command, sizeof(command), "USER %s\r\n", "anonymous"); FT_AddData(request, command, strlen(command)); request->stage = 10; break; case 11: Com_sprintf(command, sizeof(command), "PASS %s\r\n", "*****@*****.**"); FT_AddData(request, command, strlen(command)); request->stage = 12; break; case 15: Com_sprintf(command, sizeof(command), "ACCT %s\r\n", "nil"); FT_AddData(request, command, strlen(command)); request->stage = 16; break; case 17: Com_sprintf(command, sizeof(command), "PASS %s\r\n", "*****@*****.**"); FT_AddData(request, command, strlen(command)); request->stage = 20; break; case 21: Com_sprintf(command, sizeof(command), "TYPE I\r\n"); FT_AddData(request, command, strlen(command)); request->stage = 30; break; case 31: Com_sprintf(command, sizeof(command), "EPSV\r\n"); FT_AddData(request, command, strlen(command)); request->stage = 32; break; case 35: Com_sprintf(command, sizeof(command), "PASV\r\n"); FT_AddData(request, command, strlen(command)); request->stage = 36; break; case 41: Com_sprintf(command, sizeof(command), "SIZE %s\r\n", request->url); FT_AddData(request, command, strlen(command)); request->stage = 50; break; case 51: Com_sprintf(command, sizeof(command), "RETR %s\r\n", request->url); FT_AddData(request, command, strlen(command)); request->stage = 60; break; case 61: /* Receive new bytes */ request->transferactive = qtrue; status = NET_ReceiveData(request->transfersocket, &request->transfermsg); if (status == -1){ request->transfersocket = -1; }else if(status == -2){ request->transfersocket = -1; } if(request->transfermsg.cursize == request->transfermsg.maxsize && request->transfermsg.maxsize != 0) { /* Comple file retrived */ request->stage = 9999; break; }else if(request->transfersocket == -1){ request->stage = -20; } break; case 9999: status = -1; request->transferactive = qfalse; if(request->transfersocket >= 0) status = NET_ReceiveData(request->transfersocket, &request->transfermsg); if (status == -1 || status == -2){ request->transfersocket = -1; } if(request->transfermsg.cursize == request->transfermsg.maxsize && request->transfermsg.maxsize != 0) { /* Comple file retrived */ Com_sprintf(command, sizeof(command), "QUIT\r\n"); FT_AddData(request, command, strlen(command)); request->stage = 10000; break; }else { Com_Printf("\nThe FTP server closed the data connection before the transfer was completed!\n"); request->stage = -20; break; } case -20: request->transferactive = qfalse; Com_Printf("\nFTP File Transfer has failed!\n"); case -10: request->transferactive = qfalse; if(request->socket >= 0 ) { Com_sprintf(command, sizeof(command), "QUIT\r\n", request->url); FT_AddData(request, command, strlen(command)); } request->stage = -1; break; case -1: Com_Printf("\n"); return -1; break; case 10000: request->transferactive = qfalse; if(request->socket >= 0) { NET_TcpCloseSocket(request->socket); request->socket = -1; } if(request->transfersocket >= 0) { NET_TcpCloseSocket(request->transfersocket); request->transfersocket = -1; } if(request->recvmsg.data != NULL) { Z_Free(request->recvmsg.data); request->recvmsg.data = NULL; } if(request->transfermsg.data == NULL) { request->stage = -1; Com_PrintError("\nReceived complete message but message buffer is NULL!\n"); break; } Com_Memcpy(&request->recvmsg, &request->transfermsg, sizeof(msg_t)); Com_Memset(&request->transfermsg, 0, sizeof(msg_t)); request->contentLength = request->recvmsg.cursize; request->headerLength = 0; request->stage = 10001; request->code = 200; Q_strncpyz(request->status, "OK", sizeof(request->status)); break; case 10001: Com_Printf("\n"); return 1; default: return 0; } return 0; }
~RocketCompiledGeometry() { Z_Free( verts ); Z_Free( indices ); }
// // This function loads the sound data from the WAD lump, // for single sound. // void* getsfx( const char* sfxname, int* len ) { unsigned char *sfx, *srcfx, *paddedsfx; int i; int size; int paddedsize; char name[20]; int sfxlump; int16_t s, t, *upsamps; // Get the sound data from the WAD, allocate lump // in zone memory. sprintf(name, "ds%s", sfxname); // Now, there is a severe problem with the // sound handling, in it is not (yet/anymore) // gamemode aware. That means, sounds from // DOOM II will be requested even with DOOM // shareware. // The sound list is wired into sounds.c, // which sets the external variable. // I do not do runtime patches to that // variable. Instead, we will use a // default sound for replacement. if ( W_CheckNumForName(name) == -1 ) sfxlump = W_GetNumForName("dspistol"); else sfxlump = W_GetNumForName(name); size = W_LumpLength( sfxlump ); // Debug. // fprintf( stderr, "." ); //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n", // sfxname, sfxlump, size ); //fflush( stderr ); sfx = (unsigned char*)W_CacheLumpNum(sfxlump); // upsample to 16 bit x 44.1Khz (playback is 22khz stereo) paddedsize = (size * 8); // Allocate from zone memory. paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 ); paddedsfx += 8; // Now copy and upsample upsamps = (int16_t *)(paddedsfx); srcfx = sfx + 8; for (i = 9; i < size; i++) { s = (255<<5) - (*srcfx<<6); srcfx++; t = (255<<5) - (*srcfx<<6); *upsamps++ = s << 2; *upsamps++ = s << 2; *upsamps++ = s * 3 + t; *upsamps++ = s + 3 * t; } *upsamps++ = t << 2; *upsamps++ = t << 2; *upsamps++ = t * 3; *upsamps++ = t; // Remove the cached lump. Z_Free( sfx ); // Actual data length *len = (size - 8) * 8; // Return allocated padded data. return (void *) (paddedsfx); }
/* ============ Cvar_Get If the variable already exists, the value will not be set unless CVAR_ROM The flags will be or'ed in if the variable exists. ============ */ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) { cvar_t *var; long hash; int index; if ( !var_name || ! var_value ) { Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" ); } if ( !Cvar_ValidateString( var_name ) ) { Com_Printf("invalid cvar name string: %s\n", var_name ); var_name = "BADNAME"; } #if 0 // FIXME: values with backslash happen if ( !Cvar_ValidateString( var_value ) ) { Com_Printf("invalid cvar value string: %s\n", var_value ); var_value = "BADVALUE"; } #endif var = Cvar_FindVar (var_name); if(var) { var_value = Cvar_Validate(var, var_value, qfalse); // Make sure the game code cannot mark engine-added variables as gamecode vars if(var->flags & CVAR_VM_CREATED) { if(!(flags & CVAR_VM_CREATED)) var->flags &= ~CVAR_VM_CREATED; } else if (!(var->flags & CVAR_USER_CREATED)) { if(flags & CVAR_VM_CREATED) flags &= ~CVAR_VM_CREATED; } // if the C code is now specifying a variable that the user already // set a value for, take the new value as the reset value if(var->flags & CVAR_USER_CREATED) { var->flags &= ~CVAR_USER_CREATED; Z_Free( var->resetString ); var->resetString = CopyString( var_value ); if(flags & CVAR_ROM) { // this variable was set by the user, // so force it to value given by the engine. if(var->latchedString) Z_Free(var->latchedString); var->latchedString = CopyString(var_value); } } // Make sure servers cannot mark engine-added variables as SERVER_CREATED if(var->flags & CVAR_SERVER_CREATED) { if(!(flags & CVAR_SERVER_CREATED)) var->flags &= ~CVAR_SERVER_CREATED; } else { if(flags & CVAR_SERVER_CREATED) flags &= ~CVAR_SERVER_CREATED; } var->flags |= flags; // only allow one non-empty reset string without a warning if ( !var->resetString[0] ) { // we don't have a reset string yet Z_Free( var->resetString ); var->resetString = CopyString( var_value ); } else if ( var_value[0] && strcmp( var->resetString, var_value ) ) { Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", var_name, var->resetString, var_value ); } // if we have a latched string, take that value now if ( var->latchedString ) { char *s; s = var->latchedString; var->latchedString = NULL; // otherwise cvar_set2 would free it Cvar_Set2( var_name, s, qtrue ); Z_Free( s ); } // ZOID--needs to be set so that cvars the game sets as // SERVERINFO get sent to clients cvar_modifiedFlags |= flags; return var; } // // allocate a new cvar // // find a free cvar for(index = 0; index < MAX_CVARS; index++) { if(!cvar_indexes[index].name) break; } if(index >= MAX_CVARS) { if(!com_errorEntered) Com_Error(ERR_FATAL, "Error: Too many cvars, cannot create a new one!"); return NULL; } var = &cvar_indexes[index]; if(index >= cvar_numIndexes) cvar_numIndexes = index + 1; var->name = CopyString (var_name); var->string = CopyString (var_value); var->modified = qtrue; var->modificationCount = 1; var->value = atof (var->string); var->integer = atoi(var->string); var->resetString = CopyString( var_value ); var->validate = qfalse; var->description = NULL; // link the variable in var->next = cvar_vars; if(cvar_vars) cvar_vars->prev = var; var->prev = NULL; cvar_vars = var; var->flags = flags; // note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo) cvar_modifiedFlags |= var->flags; hash = generateHashValue(var_name); var->hashIndex = hash; var->hashNext = hashTable[hash]; if(hashTable[hash]) hashTable[hash]->hashPrev = var; var->hashPrev = NULL; hashTable[hash] = var; return var; }
void gld_BindPatch(GLTexture *gltexture, int cm) { const rpatch_t *patch; int i; unsigned char *buffer; if ((gltexture==last_gltexture) && (cm==last_cm)) return; last_gltexture=gltexture; last_cm=cm; if (!gltexture) return; if (gltexture->textype!=GLDT_PATCH) { glBindTexture(GL_TEXTURE_2D, 0); last_gltexture = NULL; last_cm = -1; return; } if (gltexture->glTexID[cm]!=0) { glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]); glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i); #ifdef _DEBUG if (i!=GL_TRUE) lprintf(LO_INFO, "glGetTexParam: %i\n", i); #endif if (i==GL_TRUE) return; } patch=R_CachePatchNum(gltexture->index); buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0); if (gl_paletted_texture) memset(buffer,transparent_pal_index,gltexture->buffer_size); else memset(buffer,0,gltexture->buffer_size); gld_AddPatchToTexture(gltexture, buffer, patch, 0, 0, cm, gl_paletted_texture); if (gltexture->glTexID[cm]==0) glGenTextures(1,&gltexture->glTexID[cm]); glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]); #ifdef USE_GLU_IMAGESCALE if ((gltexture->buffer_width>gltexture->tex_width) || (gltexture->buffer_height>gltexture->tex_height) ) { unsigned char *scaledbuffer; scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0); if (scaledbuffer) { gluScaleImage(GL_RGBA, gltexture->buffer_width, gltexture->buffer_height, GL_UNSIGNED_BYTE,buffer, gltexture->tex_width, gltexture->tex_height, GL_UNSIGNED_BYTE,scaledbuffer); Z_Free(buffer); buffer=scaledbuffer; glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->tex_width, gltexture->tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } else #endif /* USE_GLU_IMAGESCALE */ { if (gl_paletted_texture) { gld_SetTexturePalette(GL_TEXTURE_2D); glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, gltexture->buffer_width, gltexture->buffer_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer); } else { glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->buffer_width, gltexture->buffer_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter); Z_Free(buffer); R_UnlockPatchNum(gltexture->index); }
/* ============ Cvar_Set2 ============ */ cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force ) { cvar_t *var; // Com_DPrintf( "Cvar_Set2: %s %s\n", var_name, value ); if ( !Cvar_ValidateString( var_name ) ) { Com_Printf("invalid cvar name string: %s\n", var_name ); var_name = "BADNAME"; } #if 0 // FIXME if ( value && !Cvar_ValidateString( value ) ) { Com_Printf("invalid cvar value string: %s\n", value ); var_value = "BADVALUE"; } #endif var = Cvar_FindVar (var_name); if (!var) { if ( !value ) { return NULL; } // create it if ( !force ) { return Cvar_Get( var_name, value, CVAR_USER_CREATED ); } else { return Cvar_Get (var_name, value, 0); } } if (!value ) { value = var->resetString; } value = Cvar_Validate(var, value, qtrue); if((var->flags & CVAR_LATCH) && var->latchedString) { if(!strcmp(value, var->string)) { Z_Free(var->latchedString); var->latchedString = NULL; return var; } if(!strcmp(value, var->latchedString)) return var; } else if(!strcmp(value, var->string)) return var; // note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo) cvar_modifiedFlags |= var->flags; if (!force) { if (var->flags & CVAR_ROM) { Com_Printf ("%s is read only.\n", var_name); return var; } if (var->flags & CVAR_INIT) { Com_Printf ("%s is write protected.\n", var_name); return var; } if (var->flags & CVAR_LATCH) { if (var->latchedString) { if (strcmp(value, var->latchedString) == 0) return var; Z_Free (var->latchedString); } else { if (strcmp(value, var->string) == 0) return var; } Com_Printf ("%s will be changed upon restarting.\n", var_name); var->latchedString = CopyString(value); var->modified = qtrue; var->modificationCount++; return var; } if ( (var->flags & CVAR_CHEAT) && !cvar_cheats->integer ) { Com_Printf ("%s is cheat protected.\n", var_name); return var; } } else { if (var->latchedString) { Z_Free (var->latchedString); var->latchedString = NULL; } } if (!strcmp(value, var->string)) return var; // not changed var->modified = qtrue; var->modificationCount++; Z_Free (var->string); // free the old value string var->string = CopyString(value); var->value = atof (var->string); var->integer = atoi (var->string); return var; }
void gld_BindFlat(GLTexture *gltexture) { const unsigned char *flat; int i; unsigned char *buffer; if (gltexture==last_gltexture) return; last_gltexture=gltexture; if (!gltexture) return; if (gltexture->textype!=GLDT_FLAT) { glBindTexture(GL_TEXTURE_2D, 0); last_gltexture = NULL; last_cm = -1; return; } if (gltexture->glTexID[CR_DEFAULT]!=0) { glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]); glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i); #ifdef _DEBUG if (i!=GL_TRUE) lprintf(LO_INFO, "glGetTexParam: %i\n", i); #endif if (i==GL_TRUE) return; } flat=W_CacheLumpNum(gltexture->index); buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0); if (!(gltexture->mipmap && use_mipmapping) && gl_paletted_texture) memset(buffer,transparent_pal_index,gltexture->buffer_size); else memset(buffer,0,gltexture->buffer_size); gld_AddFlatToTexture(gltexture, buffer, flat, !(gltexture->mipmap && use_mipmapping) && gl_paletted_texture); if (gltexture->glTexID[CR_DEFAULT]==0) glGenTextures(1,&gltexture->glTexID[CR_DEFAULT]); glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]); #ifdef USE_GLU_MIPMAP if (gltexture->mipmap && use_mipmapping) { gluBuild2DMipmaps(GL_TEXTURE_2D, gl_tex_format, gltexture->buffer_width, gltexture->buffer_height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_mipmap_filter); if (gl_texture_filter_anisotropic) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0); } else #endif /* USE_GLU_MIPMAP */ { #ifdef USE_GLU_IMAGESCALE if ((gltexture->buffer_width!=gltexture->tex_width) || (gltexture->buffer_height!=gltexture->tex_height) ) { unsigned char *scaledbuffer; scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0); if (scaledbuffer) { gluScaleImage(GL_RGBA, gltexture->buffer_width, gltexture->buffer_height, GL_UNSIGNED_BYTE,buffer, gltexture->tex_width, gltexture->tex_height, GL_UNSIGNED_BYTE,scaledbuffer); Z_Free(buffer); buffer=scaledbuffer; glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->tex_width, gltexture->tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } else #endif /* USE_GLU_IMAGESCALE */ { if (gl_paletted_texture) { gld_SetTexturePalette(GL_TEXTURE_2D); glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, gltexture->buffer_width, gltexture->buffer_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer); } else { glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format, gltexture->buffer_width, gltexture->buffer_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter); } Z_Free(buffer); W_UnlockLumpNum(gltexture->index); }
static void S_VORBIS_CodecCloseStream (snd_stream_t *stream) { ov_clear((OggVorbis_File *)stream->priv); Z_Free(stream->priv); S_CodecUtilClose(&stream); }
void gld_Precache(void) { register int i; register byte *hitlist; if (demoplayback) return; { size_t size = numflats > numsprites ? numflats : numsprites; hitlist = Z_Malloc((size_t)numtextures > size ? numtextures : size,PU_LEVEL,0); } // Precache flats. memset(hitlist, 0, numflats); for (i = numsectors; --i >= 0; ) hitlist[sectors[i].floorpic] = hitlist[sectors[i].ceilingpic] = 1; for (i = numflats; --i >= 0; ) if (hitlist[i]) gld_BindFlat(gld_RegisterFlat(i,true)); // Precache textures. memset(hitlist, 0, numtextures); for (i = numsides; --i >= 0;) hitlist[sides[i].bottomtexture] = hitlist[sides[i].toptexture] = hitlist[sides[i].midtexture] = 1; // Sky texture is always present. // Note that F_SKY1 is the name used to // indicate a sky floor/ceiling as a flat, // while the sky texture is stored like // a wall texture, with an episode dependend // name. hitlist[skytexture] = 0; for (i = numtextures; --i >= 0; ) if (hitlist[i]) gld_BindTexture(gld_RegisterTexture(i,true,false)); // Precache sprites. memset(hitlist, 0, numsprites); { thinker_t *th; for (th = thinkercap.next ; th != &thinkercap ; th=th->next) if (th->function == P_MobjThinker) hitlist[((mobj_t *)th)->sprite] = 1; } for (i=numsprites; --i >= 0;) if (hitlist[i]) { int j = sprites[i].numframes; while (--j >= 0) { short *sflump = sprites[i].spriteframes[j].lump; int k = 7; do gld_BindPatch(gld_RegisterPatch(firstspritelump + sflump[k],CR_DEFAULT),CR_DEFAULT); while (--k >= 0); } } Z_Free(hitlist); }
/* ================= VM_Compile ================= */ void VM_Compile( vm_t *vm, vmHeader_t *header ) { int op; int maxLength; int v; int i; qboolean opt; // allocate a very large temp buffer, we will shrink it later maxLength = header->codeLength * 8; buf = Z_Malloc( maxLength ); jused = Z_Malloc(header->instructionCount + 2 ); Com_Memset(jused, 0, header->instructionCount+2); // ensure that the optimisation pass knows about all the jump // table targets for( i = 0; i < vm->numJumpTableTargets; i++ ) { jused[ *(int *)(vm->jumpTableTargets + ( i * sizeof( int ) ) ) ] = 1; } for(pass=0;pass<2;pass++) { oc0 = -23423; oc1 = -234354; pop0 = -43435; pop1 = -545455; // translate all instructions pc = 0; instruction = 0; code = (byte *)header + header->codeOffset; compiledOfs = 0; LastCommand = LAST_COMMAND_NONE; while ( instruction < header->instructionCount ) { if ( compiledOfs > maxLength - 16 ) { Com_Error( ERR_FATAL, "VM_CompileX86: maxLength exceeded" ); } vm->instructionPointers[ instruction ] = compiledOfs; instruction++; if ( pc > header->codeLength ) { Com_Error( ERR_FATAL, "VM_CompileX86: pc > header->codeLength" ); } op = code[ pc ]; pc++; switch ( op ) { case 0: break; case OP_BREAK: EmitString( "CC" ); // int 3 break; case OP_ENTER: EmitString( "81 EE" ); // sub esi, 0x12345678 Emit4( Constant4() ); break; case OP_CONST: if (code[pc+4] == OP_LOAD4) { EmitAddEDI4(vm); EmitString( "BB" ); // mov ebx, 0x12345678 Emit4( (Constant4()&vm->dataMask) + (int)vm->dataBase); EmitString( "8B 03" ); // mov eax, dword ptr [ebx] EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax pc++; // OP_LOAD4 instruction += 1; break; } if (code[pc+4] == OP_LOAD2) { EmitAddEDI4(vm); EmitString( "BB" ); // mov ebx, 0x12345678 Emit4( (Constant4()&vm->dataMask) + (int)vm->dataBase); EmitString( "0F B7 03" ); // movzx eax, word ptr [ebx] EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax pc++; // OP_LOAD4 instruction += 1; break; } if (code[pc+4] == OP_LOAD1) { EmitAddEDI4(vm); EmitString( "BB" ); // mov ebx, 0x12345678 Emit4( (Constant4()&vm->dataMask) + (int)vm->dataBase); EmitString( "0F B6 03" ); // movzx eax, byte ptr [ebx] EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax pc++; // OP_LOAD4 instruction += 1; break; } if (code[pc+4] == OP_STORE4) { opt = EmitMovEBXEDI(vm, (vm->dataMask & ~3)); EmitString( "B8" ); // mov eax, 0x12345678 Emit4( Constant4() ); // if (!opt) { // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask & ~3 ); // } EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 pc++; // OP_STORE4 instruction += 1; break; } if (code[pc+4] == OP_STORE2) { opt = EmitMovEBXEDI(vm, (vm->dataMask & ~1)); EmitString( "B8" ); // mov eax, 0x12345678 Emit4( Constant4() ); // if (!opt) { // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask & ~1 ); // } EmitString( "66 89 83" ); // mov word ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 pc++; // OP_STORE4 instruction += 1; break; } if (code[pc+4] == OP_STORE1) { opt = EmitMovEBXEDI(vm, vm->dataMask); EmitString( "B8" ); // mov eax, 0x12345678 Emit4( Constant4() ); // if (!opt) { // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask ); // } EmitString( "88 83" ); // mov byte ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 pc++; // OP_STORE4 instruction += 1; break; } if (code[pc+4] == OP_ADD) { EmitString( "81 07" ); // add dword ptr [edi], 0x1234567 Emit4( Constant4() ); pc++; // OP_ADD instruction += 1; break; } if (code[pc+4] == OP_SUB) { EmitString( "81 2F" ); // sub dword ptr [edi], 0x1234567 Emit4( Constant4() ); pc++; // OP_ADD instruction += 1; break; } EmitAddEDI4(vm); EmitString( "C7 07" ); // mov dword ptr [edi], 0x12345678 lastConst = Constant4(); Emit4( lastConst ); if (code[pc] == OP_JUMP) { jused[lastConst] = 1; } break; case OP_LOCAL: EmitAddEDI4(vm); EmitString( "8D 86" ); // lea eax, [0x12345678 + esi] oc0 = oc1; oc1 = Constant4(); Emit4( oc1 ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_ARG: EmitMovEAXEDI(vm); // mov eax,dword ptr [edi] EmitString( "89 86" ); // mov dword ptr [esi+database],eax // FIXME: range check Emit4( Constant1() + (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_CALL: EmitString( "C7 86" ); // mov dword ptr [esi+database],0x12345678 Emit4( (int)vm->dataBase ); Emit4( pc ); EmitString( "FF 15" ); // call asmCallPtr Emit4( (int)&asmCallPtr ); break; case OP_PUSH: EmitAddEDI4(vm); break; case OP_POP: EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_LEAVE: v = Constant4(); EmitString( "81 C6" ); // add esi, 0x12345678 Emit4( v ); EmitString( "C3" ); // ret break; case OP_LOAD4: if (code[pc] == OP_CONST && code[pc+5] == OP_ADD && code[pc+6] == OP_STORE4) { if (oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { compiledOfs -= 11; vm->instructionPointers[ instruction-1 ] = compiledOfs; } pc++; // OP_CONST v = Constant4(); EmitMovEBXEDI(vm, vm->dataMask); if (v == 1 && oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { EmitString( "FF 83"); // inc dword ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); } else { EmitString( "8B 83" ); // mov eax, dword ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); EmitString( "05" ); // add eax, const Emit4( v ); if (oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); } else { EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "8B 1F" ); // mov ebx, dword ptr [edi] EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); } } EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 pc++; // OP_ADD pc++; // OP_STORE instruction += 3; break; } if (code[pc] == OP_CONST && code[pc+5] == OP_SUB && code[pc+6] == OP_STORE4) { if (oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { compiledOfs -= 11; vm->instructionPointers[ instruction-1 ] = compiledOfs; } EmitMovEBXEDI(vm, vm->dataMask); EmitString( "8B 83" ); // mov eax, dword ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); pc++; // OP_CONST v = Constant4(); if (v == 1 && oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { EmitString( "FF 8B"); // dec dword ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); } else { EmitString( "2D" ); // sub eax, const Emit4( v ); if (oc0 == oc1 && pop0 == OP_LOCAL && pop1 == OP_LOCAL) { EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); } else { EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "8B 1F" ); // mov ebx, dword ptr [edi] EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); } } EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 pc++; // OP_SUB pc++; // OP_STORE instruction += 3; break; } if (buf[compiledOfs-2] == 0x89 && buf[compiledOfs-1] == 0x07) { compiledOfs -= 2; vm->instructionPointers[ instruction-1 ] = compiledOfs; EmitString( "8B 80"); // mov eax, dword ptr [eax + 0x1234567] Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; } EmitMovEBXEDI(vm, vm->dataMask); EmitString( "8B 83" ); // mov eax, dword ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_LOAD2: EmitMovEBXEDI(vm, vm->dataMask); EmitString( "0F B7 83" ); // movzx eax, word ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_LOAD1: EmitMovEBXEDI(vm, vm->dataMask); EmitString( "0F B6 83" ); // movzx eax, byte ptr [ebx + 0x12345678] Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_STORE4: EmitMovEAXEDI(vm); EmitString( "8B 5F FC" ); // mov ebx, dword ptr [edi-4] // if (pop1 != OP_CALL) { // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask & ~3 ); // } EmitString( "89 83" ); // mov dword ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 break; case OP_STORE2: EmitMovEAXEDI(vm); EmitString( "8B 5F FC" ); // mov ebx, dword ptr [edi-4] // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask & ~1 ); EmitString( "66 89 83" ); // mov word ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 break; case OP_STORE1: EmitMovEAXEDI(vm); EmitString( "8B 5F FC" ); // mov ebx, dword ptr [edi-4] // EmitString( "81 E3" ); // and ebx, 0x12345678 // Emit4( vm->dataMask ); EmitString( "88 83" ); // mov byte ptr [ebx+0x12345678], eax Emit4( (int)vm->dataBase ); EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 break; case OP_EQ: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "75 06" ); // jne +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_NE: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "74 06" ); // je +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LTI: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "7D 06" ); // jnl +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LEI: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "7F 06" ); // jnle +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GTI: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "7E 06" ); // jng +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GEI: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "7C 06" ); // jnge +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LTU: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "73 06" ); // jnb +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LEU: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "77 06" ); // jnbe +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GTU: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "76 06" ); // jna +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GEU: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "8B 47 04" ); // mov eax, dword ptr [edi+4] EmitString( "3B 47 08" ); // cmp eax, dword ptr [edi+8] EmitString( "72 06" ); // jnae +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_EQF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 40" ); // test ah,0x40 EmitString( "74 06" ); // je +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_NEF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 40" ); // test ah,0x40 EmitString( "75 06" ); // jne +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LTF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 01" ); // test ah,0x01 EmitString( "74 06" ); // je +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_LEF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 41" ); // test ah,0x41 EmitString( "74 06" ); // je +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GTF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 41" ); // test ah,0x41 EmitString( "75 06" ); // jne +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_GEF: EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 EmitString( "D9 47 04" ); // fld dword ptr [edi+4] EmitString( "D8 5F 08" ); // fcomp dword ptr [edi+8] EmitString( "DF E0" ); // fnstsw ax EmitString( "F6 C4 01" ); // test ah,0x01 EmitString( "75 06" ); // jne +6 EmitString( "FF 25" ); // jmp [0x12345678] v = Constant4(); jused[v] = 1; Emit4( (int)vm->instructionPointers + v*4 ); break; case OP_NEGI: EmitString( "F7 1F" ); // neg dword ptr [edi] break; case OP_ADD: EmitMovEAXEDI(vm); // mov eax, dword ptr [edi] EmitString( "01 47 FC" ); // add dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_SUB: EmitMovEAXEDI(vm); // mov eax, dword ptr [edi] EmitString( "29 47 FC" ); // sub dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_DIVI: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "99" ); // cdq EmitString( "F7 3F" ); // idiv dword ptr [edi] EmitString( "89 47 FC" ); // mov dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_DIVU: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "33 D2" ); // xor edx, edx EmitString( "F7 37" ); // div dword ptr [edi] EmitString( "89 47 FC" ); // mov dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_MODI: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "99" ); // cdq EmitString( "F7 3F" ); // idiv dword ptr [edi] EmitString( "89 57 FC" ); // mov dword ptr [edi-4],edx EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_MODU: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "33 D2" ); // xor edx, edx EmitString( "F7 37" ); // div dword ptr [edi] EmitString( "89 57 FC" ); // mov dword ptr [edi-4],edx EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_MULI: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "F7 2F" ); // imul dword ptr [edi] EmitString( "89 47 FC" ); // mov dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_MULU: EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4] EmitString( "F7 27" ); // mul dword ptr [edi] EmitString( "89 47 FC" ); // mov dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_BAND: EmitMovEAXEDI(vm); // mov eax, dword ptr [edi] EmitString( "21 47 FC" ); // and dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_BOR: EmitMovEAXEDI(vm); // mov eax, dword ptr [edi] EmitString( "09 47 FC" ); // or dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_BXOR: EmitMovEAXEDI(vm); // mov eax, dword ptr [edi] EmitString( "31 47 FC" ); // xor dword ptr [edi-4],eax EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_BCOM: EmitString( "F7 17" ); // not dword ptr [edi] break; case OP_LSH: EmitString( "8B 0F" ); // mov ecx, dword ptr [edi] EmitString( "D3 67 FC" ); // shl dword ptr [edi-4], cl EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_RSHI: EmitString( "8B 0F" ); // mov ecx, dword ptr [edi] EmitString( "D3 7F FC" ); // sar dword ptr [edi-4], cl EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_RSHU: EmitString( "8B 0F" ); // mov ecx, dword ptr [edi] EmitString( "D3 6F FC" ); // shr dword ptr [edi-4], cl EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_NEGF: EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "D9 E0" ); // fchs EmitString( "D9 1F" ); // fstp dword ptr [edi] break; case OP_ADDF: EmitString( "D9 47 FC" ); // fld dword ptr [edi-4] EmitString( "D8 07" ); // fadd dword ptr [edi] EmitString( "D9 5F FC" ); // fstp dword ptr [edi-4] EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 break; case OP_SUBF: EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "D8 67 04" ); // fsub dword ptr [edi+4] EmitString( "D9 1F" ); // fstp dword ptr [edi] break; case OP_DIVF: EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "D8 77 04" ); // fdiv dword ptr [edi+4] EmitString( "D9 1F" ); // fstp dword ptr [edi] break; case OP_MULF: EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "D8 4f 04" ); // fmul dword ptr [edi+4] EmitString( "D9 1F" ); // fstp dword ptr [edi] break; case OP_CVIF: EmitString( "DB 07" ); // fild dword ptr [edi] EmitString( "D9 1F" ); // fstp dword ptr [edi] break; case OP_CVFI: #ifndef FTOL_PTR // WHENHELLISFROZENOVER // not IEEE complient, but simple and fast EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "DB 1F" ); // fistp dword ptr [edi] #else // FTOL_PTR // call the library conversion function EmitString( "D9 07" ); // fld dword ptr [edi] EmitString( "FF 15" ); // call ftolPtr Emit4( (int)&ftolPtr ); EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax #endif break; case OP_SEX8: EmitString( "0F BE 07" ); // movsx eax, byte ptr [edi] EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_SEX16: EmitString( "0F BF 07" ); // movsx eax, word ptr [edi] EmitCommand(LAST_COMMAND_MOV_EDI_EAX); // mov dword ptr [edi], eax break; case OP_BLOCK_COPY: // FIXME: range check EmitString( "56" ); // push esi EmitString( "57" ); // push edi EmitString( "8B 37" ); // mov esi,[edi] EmitString( "8B 7F FC" ); // mov edi,[edi-4] EmitString( "B9" ); // mov ecx,0x12345678 Emit4( Constant4() >> 2 ); EmitString( "B8" ); // mov eax, datamask Emit4( vm->dataMask ); EmitString( "BB" ); // mov ebx, database Emit4( (int)vm->dataBase ); EmitString( "23 F0" ); // and esi, eax EmitString( "03 F3" ); // add esi, ebx EmitString( "23 F8" ); // and edi, eax EmitString( "03 FB" ); // add edi, ebx EmitString( "F3 A5" ); // rep movsd EmitString( "5F" ); // pop edi EmitString( "5E" ); // pop esi EmitCommand(LAST_COMMAND_SUB_DI_8); // sub edi, 8 break; case OP_JUMP: EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4 EmitString( "8B 47 04" ); // mov eax,dword ptr [edi+4] // FIXME: range check EmitString( "FF 24 85" ); // jmp dword ptr [instructionPointers + eax * 4] Emit4( (int)vm->instructionPointers ); break; default: Com_Error( ERR_DROP, "VM_CompileX86: bad opcode %i at offset %i", op, pc ); break; } pop0 = pop1; pop1 = op; } } // copy to an exact size buffer on the hunk vm->codeLength = compiledOfs; #ifdef VM_X86_MMAP vm->codeBase = mmap(NULL, compiledOfs, PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); if(vm->codeBase == (void*)-1) Com_Error(ERR_DROP, "VM_CompileX86: can't mmap memory"); #elif _WIN32 // allocate memory with EXECUTE permissions under windows. vm->codeBase = VirtualAlloc(NULL, compiledOfs, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if(!vm->codeBase) Com_Error(ERR_DROP, "VM_CompileX86: VirtualAlloc failed"); #else vm->codeBase = malloc(compiledOfs); #endif Com_Memcpy( vm->codeBase, buf, compiledOfs ); #ifdef VM_X86_MMAP if(mprotect(vm->codeBase, compiledOfs, PROT_READ|PROT_EXEC)) Com_Error(ERR_DROP, "VM_CompileX86: mprotect failed"); #elif _WIN32 { DWORD oldProtect = 0; // remove write permissions. if(!VirtualProtect(vm->codeBase, compiledOfs, PAGE_EXECUTE_READ, &oldProtect)) Com_Error(ERR_DROP, "VM_CompileX86: VirtualProtect failed"); } #endif Z_Free( buf ); Z_Free( jused ); Com_Printf( "VM file %s compiled to %i bytes of code\n", vm->name, compiledOfs ); vm->destroy = VM_Destroy_Compiled; // offset all the instruction pointers for the new location for ( i = 0 ; i < header->instructionCount ; i++ ) { vm->instructionPointers[i] += (int)vm->codeBase; } }
/* ================ SV_SpawnServer Change the server to a new map, taking all connected clients along with it. ================ */ void SV_SpawnServer( char *server, ForceReload_e eForceReload, qboolean bAllowScreenDissolve ) { int i; int checksum; RE_RegisterMedia_LevelLoadBegin( server, eForceReload, bAllowScreenDissolve ); Cvar_SetValue( "cl_paused", 0 ); Cvar_Set( "timescale", "1" );//jic we were skipping // shut down the existing game if it is running SV_ShutdownGameProgs(); Com_Printf ("------ Server Initialization ------\n%s\n", com_version->string); Com_Printf ("Server: %s\n",server); // init client structures and svs.numSnapshotEntities if ( !Cvar_VariableIntegerValue("sv_running") ) { SV_Startup(); } // don't let sound stutter and dump all stuff on the hunk CL_MapLoading(); Hunk_Clear(); // clear out those shaders, images and Models R_InitImages(); R_InitShaders(); R_ModelInit(); // create a heap for Ghoul2 to use for game side model vertex transforms used in collision detection if (!G2VertSpaceServer) { static const int MiniHeapSize=256 * 1024; // maxsize of ghoul2 miniheap G2VertSpaceServer = new CMiniHeap(MiniHeapSize); } if (svs.snapshotEntities) { Z_Free(svs.snapshotEntities); } // allocate the snapshot entities svs.snapshotEntities = (entityState_t *) Z_Malloc (sizeof(entityState_t)*svs.numSnapshotEntities, TAG_CLIENTS, qtrue ); Music_SetLevelName(server); // toggle the server bit so clients can detect that a // server has changed //!@ svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT; // set nextmap to the same map, but it may be overriden // by the game startup or another console command Cvar_Set( "nextmap", va("map %s", server) ); // wipe the entire per-level structure for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { if ( sv.configstrings[i] ) { Z_Free( sv.configstrings[i] ); } } memset (&sv, 0, sizeof(sv)); for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { sv.configstrings[i] = CopyString(""); } sv.time = 1000; G2API_SetTime(sv.time,G2T_SV_TIME); CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum ); // set serverinfo visible name Cvar_Set( "mapname", server ); Cvar_Set( "sv_mapChecksum", va("%i",checksum) ); // serverid should be different each time sv.serverId = com_frameTime; Cvar_Set( "sv_serverid", va("%i", sv.serverId ) ); // clear physics interaction links SV_ClearWorld (); // media configstring setting should be done during // the loading stage, so connected clients don't have // to load during actual gameplay sv.state = SS_LOADING; // load and spawn all other entities SV_InitGameProgs(); // run a few frames to allow everything to settle for ( i = 0 ;i < 3 ; i++ ) { ge->RunFrame( sv.time ); sv.time += 100; G2API_SetTime(sv.time,G2T_SV_TIME); } // create a baseline for more efficient communications SV_CreateBaseline (); for (i=0 ; i<1 ; i++) { // clear all time counters, because we have reset sv.time svs.clients[i].lastPacketTime = 0; svs.clients[i].lastConnectTime = 0; svs.clients[i].nextSnapshotTime = 0; // send the new gamestate to all connected clients if (svs.clients[i].state >= CS_CONNECTED) { char *denied; // connect the client again denied = ge->ClientConnect( i, qfalse, eNO/*qfalse*/ ); // firstTime = qfalse, qbFromSavedGame if ( denied ) { // this generally shouldn't happen, because the client // was connected before the level change SV_DropClient( &svs.clients[i], denied ); } else { svs.clients[i].state = CS_CONNECTED; // when we get the next packet from a connected client, // the new gamestate will be sent } } } // run another frame to allow things to look at all connected clients ge->RunFrame( sv.time ); sv.time += 100; G2API_SetTime(sv.time,G2T_SV_TIME); // save systeminfo and serverinfo strings SV_SetConfigstring( CS_SYSTEMINFO, Cvar_InfoString( CVAR_SYSTEMINFO ) ); cvar_modifiedFlags &= ~CVAR_SYSTEMINFO; SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO ) ); cvar_modifiedFlags &= ~CVAR_SERVERINFO; // any media configstring setting now should issue a warning // and any configstring changes should be reliably transmitted // to all clients sv.state = SS_GAME; // send a heartbeat now so the master will get up to date info svs.nextHeartbeatTime = -9999999; Hunk_SetMark(); Com_Printf ("-----------------------------------\n"); }
/* ================== BotImport_FreeMemory ================== */ void BotImport_FreeMemory( void *ptr ) { Z_Free( ptr ); }
/* ================== SCR_PlayCinematic ================== */ void SCR_PlayCinematic (char *arg) { int32_t width, height; byte *palette; char name[MAX_OSPATH], *dot; int32_t old_khz; cin.isStaticPic = false; // Knightmare added cl.cinematicframe = 0; dot = strstr (arg, "."); if (dot && !strcmp (dot, ".pcx")) { // static pcx image Com_sprintf (name, sizeof(name), "pics/%s", arg); SCR_LoadPCX (name, &cin.pic, &palette, &cin.width, &cin.height); cl.cinematicframe = -1; cl.cinematictime = 1; SCR_EndLoadingPlaque (); cls.state = ca_active; if (!cin.pic) { Com_Printf ("%s not found.\n", name); cl.cinematictime = 0; } else { memcpy (cl.cinematicpalette, palette, sizeof(cl.cinematicpalette)); Z_Free (palette); // Knightmare- HACK to show JPG endscreens cin.isStaticPic = true; Com_sprintf (cin.picName, sizeof(cin.picName), "/pics/%s", arg); } return; } Com_sprintf (name, sizeof(name), "video/%s", arg); FS_FOpenFile (name, &cl.cinematic_file, FS_READ); if (!cl.cinematic_file) { //Com_Error (ERR_DROP, "Cinematic %s not found.\n", name); //Com_Printf (S_COLOR_YELLOW"Cinematic %s not found.\n", name); SCR_FinishCinematic (); cl.cinematictime = 0; // done return; } SCR_EndLoadingPlaque (); cls.state = ca_active; FS_Read (&width, 4, cl.cinematic_file); FS_Read (&height, 4, cl.cinematic_file); cin.width = LittleLong(width); cin.height = LittleLong(height); FS_Read (&cin.s_rate, 4, cl.cinematic_file); cin.s_rate = LittleLong(cin.s_rate); FS_Read (&cin.s_width, 4, cl.cinematic_file); cin.s_width = LittleLong(cin.s_width); FS_Read (&cin.s_channels, 4, cl.cinematic_file); cin.s_channels = LittleLong(cin.s_channels); Huff1TableInit (); // switch up to 22 khz sound if necessary old_khz = Cvar_VariableValue ("s_khz"); if (old_khz < cin.s_rate/1000) // Knighmare- changed != to < { cin.restart_sound = true; Cvar_SetValue ("s_khz", cin.s_rate/1000); CL_Snd_Restart_f (); Cvar_SetValue ("s_khz", old_khz); } cl.cinematicframe = 0; cin.pic = SCR_ReadNextFrame (); cl.cinematictime = Sys_Milliseconds (); }
/* ================== SCR_PlayCinematic ================== */ void SCR_PlayCinematic (char *arg) { int width, height; byte *palette; char name[MAX_OSPATH], *dot; int old_khz; // make sure CD isn't playing music CDAudio_Stop(); cl.cinematicframe = 0; dot = strstr (arg, "."); if (dot && !strcmp (dot, ".pcx")) { // static pcx image Com_sprintf (name, sizeof(name), "pics/%s", arg); SCR_LoadPCX (name, &cin.pic, &palette, &cin.width, &cin.height); cl.cinematicframe = -1; cl.cinematictime = 1; SCR_EndLoadingPlaque (); cls.state = ca_active; if (!cin.pic) { Com_Printf ("%s not found.\n", name); cl.cinematictime = 0; } else { memcpy (cl.cinematicpalette, palette, sizeof(cl.cinematicpalette)); Z_Free (palette); } return; } Com_sprintf (name, sizeof(name), "video/%s", arg); FS_FOpenFile (name, &cl.cinematic_file); if (!cl.cinematic_file) { // Com_Error (ERR_DROP, "Cinematic %s not found.\n", name); SCR_FinishCinematic (); cl.cinematictime = 0; // done return; } SCR_EndLoadingPlaque (); cls.state = ca_active; FS_Read (&width, 4, cl.cinematic_file); FS_Read (&height, 4, cl.cinematic_file); cin.width = LittleLong(width); cin.height = LittleLong(height); FS_Read (&cin.s_rate, 4, cl.cinematic_file); cin.s_rate = LittleLong(cin.s_rate); FS_Read (&cin.s_width, 4, cl.cinematic_file); cin.s_width = LittleLong(cin.s_width); FS_Read (&cin.s_channels, 4, cl.cinematic_file); cin.s_channels = LittleLong(cin.s_channels); Huff1TableInit (); // switch up to 22 khz sound if necessary old_khz = Cvar_VariableValue ("s_khz"); if (old_khz != cin.s_rate/1000) { cin.restart_sound = true; Cvar_SetValue ("s_khz", cin.s_rate/1000); CL_Snd_Restart_f (); Cvar_SetValue ("s_khz", old_khz); } cl.cinematicframe = 0; cin.pic = SCR_ReadNextFrame (); cl.cinematictime = Sys_Milliseconds (); }
void* Z_Malloc ( int size, int tag, void* user ) { int extra; memblock_t* start; memblock_t* rover; memblock_t* newblock; memblock_t* base; size = (size + 3) & ~3; // scan through the block list, // looking for the first free block // of sufficient size, // throwing out any purgable blocks along the way. // account for size of block header size += sizeof(memblock_t); // if there is a free block behind the rover, // back up over them base = mainzone->rover; if (!base->prev->user) base = base->prev; rover = base; start = base->prev; do { if (rover == start) { // scanned all the way around the list I_Error ("Z_Malloc: failed on allocation of %i bytes", size); } if (rover->user) { if (rover->tag < PU_PURGELEVEL) { // hit a block that can't be purged, // so move base past it base = rover = rover->next; } else { // free the rover block (adding the size to base) // the rover can be the base block base = base->prev; Z_Free ((byte *)rover+sizeof(memblock_t)); base = base->next; rover = base->next; } } else rover = rover->next; } while (base->user || base->size < size); // found a block big enough extra = base->size - size; if (extra > MINFRAGMENT) { // there will be a free fragment after the allocated block newblock = (memblock_t *) ((byte *)base + size ); newblock->size = extra; // NULL indicates free block. newblock->user = NULL; newblock->tag = 0; newblock->prev = base; newblock->next = base->next; newblock->next->prev = newblock; base->next = newblock; base->size = size; } if (user) { // mark as an in use block base->user = user; *(void **)user = (void *) ((byte *)base + sizeof(memblock_t)); } else { if (tag >= PU_PURGELEVEL) I_Error ("Z_Malloc: an owner is required for purgable blocks"); // mark as in use, but unowned base->user = (void *)2; } base->tag = tag; // next allocation will start looking here mainzone->rover = base->next; base->id = ZONEID; return (void *) ((byte *)base + sizeof(memblock_t)); }
/* <4e74> ../engine/cmd.c:271 */ void Cmd_StuffCmds_f(void) { int i; int s; char *build; if (Cmd_Argc() != 1) { Con_Printf("stuffcmds : execute command line parameters\n"); return; } if (com_argc <= 1) { return; } // Get total length for the command line parameters s = 0; for (i = 1; i < com_argc; i++) { if (com_argv[i]) { s += Q_strlen(com_argv[i]) + 1; } } if (s == 0) { return; } // Create buffer able to get all arguments build = (char *)Z_Malloc(s + com_argc * 2); build[0] = 0; // Iterate thru arguments searching for ones starting with + for (i = 1; i < com_argc; i++) { if (com_argv[i] && com_argv[i][0] == '+') { // Add command or cvar Q_strcat(build, &com_argv[i][1]); // Then add all following parameters till we meet argument with + or -, which means next command/cvar/parameter i++; while (com_argv[i] && com_argv[i][0] != '+' && com_argv[i][0] != '-') { Q_strcat(build, " "); Q_strcat(build, com_argv[i]); i++; } // End up with new line which split commands for command processor Q_strcat(build, "\n"); i--; } } if (build[0] != 0) { Cbuf_InsertText(build); } // Free buffers Z_Free(build); }
/* ============ Cmd_Alias_f ============ */ void Cmd_Alias_f(void) { cmd_alias_t *alias; const char *name; // Get args if (Cmd_Argc() < 2) { Com_Printf("alias <name> : show an alias\n"); Com_Printf("alias <name> <exec> : create an alias\n"); return; } name = Cmd_Argv(1); // Find existing alias for (alias = cmd_aliases; alias; alias = alias->next) { if (!strcmp(name, alias->name)) break; } // Modify/create an alias if (Cmd_Argc() > 2) { cmd_function_t *cmd; // Crude protection from infinite loops if (!strcmp(Cmd_Argv(2), name)) { Com_Printf("Can't make an alias to itself\n"); return; } // Don't allow overriding builtin commands cmd = Cmd_FindCommand( name ); if (cmd && cmd->function != Cmd_RunAlias_f) { Com_Printf("Can't override a builtin function with an alias\n"); return; } // Create/update an alias if (!alias) { alias = S_Malloc(sizeof(cmd_alias_t)); alias->name = CopyString(name); alias->exec = CopyString(Cmd_ArgsFrom(2)); alias->next = cmd_aliases; cmd_aliases = alias; Cmd_AddCommand(name, Cmd_RunAlias_f); } else { // Reallocate the exec string Z_Free(alias->exec); alias->exec = CopyString(Cmd_ArgsFrom(2)); Cmd_AddCommand(name, Cmd_RunAlias_f); } } // Show the alias if (!alias) Com_Printf("Alias %s does not exist\n", name); else if (Cmd_Argc() == 2) Com_Printf("%s ==> %s\n", alias->name, alias->exec); // update autogen.cfg cvar_modifiedFlags |= CVAR_ARCHIVE; }
/* =============== SV_SetConfigstring =============== */ void SV_SetConfigstring (int index, const char *val) { int len, i; int maxChunkSize = MAX_STRING_CHARS - 24; client_t *client; if ( index < 0 || index >= MAX_CONFIGSTRINGS ) { Com_Error (ERR_DROP, "SV_SetConfigstring: bad index %i\n", index); } if ( !val ) { val = ""; } // don't bother broadcasting an update if no change if ( !strcmp( val, sv.configstrings[ index ] ) ) { return; } // change the string in sv Z_Free( sv.configstrings[index] ); sv.configstrings[index] = CopyString( val ); // send it to all the clients if we aren't // spawning a new server if ( sv.state == SS_GAME || sv.restarting ) { // send the data to all relevent clients for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) { if ( client->state < CS_PRIMED ) { continue; } // do not always send server info to all clients if ( index == CS_SERVERINFO && client->gentity && (client->gentity->r.svFlags & SVF_NOSERVERINFO) ) { continue; } len = strlen( val ); if( len >= maxChunkSize ) { int sent = 0; int remaining = len; char *cmd; char buf[MAX_STRING_CHARS]; while (remaining > 0 ) { if ( sent == 0 ) { cmd = "bcs0"; } else if( remaining < maxChunkSize ) { cmd = "bcs2"; } else { cmd = "bcs1"; } Q_strncpyz( buf, &val[sent], maxChunkSize ); SV_SendServerCommand( client, "%s %i \"%s\"\n", cmd, index, buf ); sent += (maxChunkSize - 1); remaining -= (maxChunkSize - 1); } } else { // standard cs, just send it SV_SendServerCommand( client, "cs %i \"%s\"\n", index, val ); } } } }
/* ============== S_LoadSound The filename may be different than sfx->name in the case of a forced fallback of a player specific sound ============== */ qboolean S_LoadSound( sfx_t *sfx ) { byte *data; short *samples; snd_info_t info; // int size; #ifndef NO_DMAHD if (dmaHD_Enabled()) return dmaHD_LoadSound(sfx); #endif // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*') { return qfalse; } // load it in data = S_CodecLoad(sfx->soundName, &info); if(!data) return qfalse; if ( info.width == 1 ) { Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName); } if ( info.rate != 22050 ) { Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName); } samples = Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2); sfx->lastTimeUsed = Com_Milliseconds()+1; // each of these compression schemes works just fine // but the 16bit quality is much nicer and with a local // install assured we can rely upon the sound memory // manager to do the right thing for us and page // sound in as needed if( sfx->soundCompressed == qtrue) { sfx->soundCompressionMethod = 1; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, data + info.dataofs ); S_AdpcmEncodeSound(sfx, samples); #if 0 } else if (info.samples>(SND_CHUNK_SIZE*16) && info.width >1) { sfx->soundCompressionMethod = 3; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); encodeMuLaw( sfx, samples); } else if (info.samples>(SND_CHUNK_SIZE*6400) && info.width >1) { sfx->soundCompressionMethod = 2; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); encodeWavelet( sfx, samples); #endif } else { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); } Hunk_FreeTempMemory(samples); Z_Free(data); return qtrue; }