static char *GetFullExePath(const char *program) { char *result; char *sep; size_t result_len; unsigned int path_len; sep = strrchr(myargv[0], DIR_SEPARATOR); if (sep == NULL) { result = strdup(program); } else { path_len = sep - myargv[0] + 1; result_len = strlen(program) + path_len + 1; result = malloc(result_len); M_StringCopy(result, myargv[0], result_len); result[path_len] = '\0'; M_StringConcat(result, program, result_len); } return result; }
static int CmdPrintNumber(void) { char tempStr[16]; snprintf(tempStr, sizeof(tempStr), "%d", Pop()); M_StringConcat(PrintBuffer, tempStr, sizeof(PrintBuffer)); return SCRIPT_CONTINUE; }
static void LoadChexDeh(void) { char *chex_deh = NULL; char *sep; if (gameversion == exe_chex) { // Look for chex.deh in the same directory as the IWAD file. sep = strrchr(iwadfile, DIR_SEPARATOR); if (sep != NULL) { size_t chex_deh_len = strlen(iwadfile) + 9; chex_deh = malloc(chex_deh_len); M_StringCopy(chex_deh, iwadfile, chex_deh_len); chex_deh[sep - iwadfile + 1] = '\0'; M_StringConcat(chex_deh, "chex.deh", chex_deh_len); } else { chex_deh = strdup("chex.deh"); } // If the dehacked patch isn't found, try searching the WAD // search path instead. We might find it... if (!M_FileExists(chex_deh)) { free(chex_deh); chex_deh = D_FindWADByName("chex.deh"); } // Still not found? if (chex_deh == NULL) { I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n" "The dehacked file is required in order to emulate\n" "chex.exe correctly. It can be found in your nearest\n" "/idgames repository mirror at:\n\n" " utils/exe_edit/patches/chexdeh.zip"); } if (!DEH_LoadFile(chex_deh)) { I_Error("Failed to load chex.deh needed for emulating chex.exe."); } } }
char *M_StringJoin(const char *s, ...) { char *result; const char *v; va_list args; size_t result_len; result_len = strlen(s) + 1; va_start(args, s); for (;;) { v = va_arg(args, const char *); if (v == NULL) { break; } result_len += strlen(v); } va_end(args); result = malloc(result_len); if (result == NULL) { I_Error("M_StringJoin: Failed to allocate new string."); return NULL; } M_StringCopy(result, s, result_len); va_start(args, s); for (;;) { v = va_arg(args, const char *); if (v == NULL) { break; } M_StringConcat(result, v, result_len); } va_end(args); return result; }
static void QueryResponseCallback(net_addr_t *addr, net_querydata_t *querydata, unsigned int ping_time, TXT_UNCAST_ARG(results_table)) { TXT_CAST_ARG(txt_table_t, results_table); char ping_time_str[16]; char description[47]; // When we connect we'll have to negotiate a common protocol that we // can agree upon between the client and server. If we can't then we // won't be able to connect, so it's pointless to include it in the // results list. If protocol==NET_PROTOCOL_UNKNOWN then this may be // an old, pre-3.0 Chocolate Doom server that doesn't support the new // protocol negotiation mechanism, or it may be an incompatible fork. if (querydata->protocol == NET_PROTOCOL_UNKNOWN) { return; } M_snprintf(ping_time_str, sizeof(ping_time_str), "%ims", ping_time); // Build description from server name field. Because there is limited // space, we only include the player count if there are already players // connected to the server. if (querydata->num_players > 0) { M_snprintf(description, sizeof(description), "(%d/%d) ", querydata->num_players, querydata->max_players); } else { M_StringCopy(description, "", sizeof(description)); } M_StringConcat(description, querydata->description, sizeof(description)); TXT_AddWidgets(results_table, TXT_NewLabel(ping_time_str), TXT_NewButton2(NET_AddrToString(addr), SelectQueryAddress, querydata), TXT_NewLabel(description), NULL); ++query_servers_found; }
void CT_Ticker(void) { int i; int j; char c; int numplayers; for (i = 0; i < maxplayers; i++) { if (!playeringame[i]) { continue; } if ((c = players[i].cmd.chatchar) != 0) { if (c <= CT_PLR_ALL) { chat_dest[i] = c; continue; } else if (c == CT_ESCAPE) { CT_ClearChatMessage(i); } else if (c == KEY_ENTER) { numplayers = 0; for (j = 0; j < maxplayers; j++) { numplayers += playeringame[j]; } CT_AddChar(i, 0); // set the end of message character if (numplayers > 2) { M_StringCopy(plr_lastmsg[i], CT_FromPlrText[i], sizeof(plr_lastmsg[i])); M_StringConcat(plr_lastmsg[i], chat_msg[i], sizeof(plr_lastmsg[i])); } else { M_StringCopy(plr_lastmsg[i], chat_msg[i], sizeof(plr_lastmsg[i])); } if (i != consoleplayer && (chat_dest[i] == consoleplayer + 1 || chat_dest[i] == CT_PLR_ALL) && *chat_msg[i]) { P_SetMessage(&players[consoleplayer], plr_lastmsg[i], true); S_StartSound(NULL, SFX_CHAT); } else if (i == consoleplayer && (*chat_msg[i])) { if (numplayers <= 1) { P_SetMessage(&players[consoleplayer], "THERE ARE NO OTHER PLAYERS IN THE GAME!", true); S_StartSound(NULL, SFX_CHAT); } } CT_ClearChatMessage(i); } else if (c == KEY_BACKSPACE) { CT_BackSpace(i); } else { CT_AddChar(i, c); } } } return; }
// Load dehacked patches needed for certain IWADs. static void LoadIwadDeh(void) { // The Freedoom IWADs have DEHACKED lumps that must be loaded. if (W_CheckNumForName("FREEDOOM") >= 0) { // Old versions of Freedoom (before 2014-09) did not have technically // valid DEHACKED lumps, so ignore errors and just continue if this // is an old IWAD. DEH_LoadLumpByName("DEHACKED", false, true); } // If this is the HACX IWAD, we need to load the DEHACKED lump. if (gameversion == exe_hacx) { if (!DEH_LoadLumpByName("DEHACKED", true, false)) { I_Error("DEHACKED lump not found. Please check that this is the " "Hacx v1.2 IWAD."); } } // Chex Quest needs a separate Dehacked patch which must be downloaded // and installed next to the IWAD. if (gameversion == exe_chex) { char *chex_deh = NULL; char *sep; // Look for chex.deh in the same directory as the IWAD file. sep = strrchr(iwadfile, DIR_SEPARATOR); if (sep != NULL) { size_t chex_deh_len = strlen(iwadfile) + 9; chex_deh = malloc(chex_deh_len); M_StringCopy(chex_deh, iwadfile, chex_deh_len); chex_deh[sep - iwadfile + 1] = '\0'; M_StringConcat(chex_deh, "chex.deh", chex_deh_len); } else { chex_deh = M_StringDuplicate("chex.deh"); } // If the dehacked patch isn't found, try searching the WAD // search path instead. We might find it... if (!M_FileExists(chex_deh)) { free(chex_deh); chex_deh = D_FindWADByName("chex.deh"); } // Still not found? if (chex_deh == NULL) { I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n" "The dehacked file is required in order to emulate\n" "chex.exe correctly. It can be found in your nearest\n" "/idgames repository mirror at:\n\n" " utils/exe_edit/patches/chexdeh.zip"); } if (!DEH_LoadFile(chex_deh)) { I_Error("Failed to load chex.deh needed for emulating chex.exe."); } } }
static int CmdPrintString(void) { M_StringConcat(PrintBuffer, ACStrings[Pop()], sizeof(PrintBuffer)); return SCRIPT_CONTINUE; }
static void HandleArgs(void) { int p; //! // @vanilla // // Disable monsters. // nomonsters = M_ParmExists("-nomonsters"); //! // @vanilla // // Monsters respawn after being killed. // respawnparm = M_ParmExists("-respawn"); //! // @vanilla // @category net // // In deathmatch mode, change a player's class each time the // player respawns. // randomclass = M_ParmExists("-randclass"); //! // @vanilla // // Take screenshots when F1 is pressed. // ravpic = M_ParmExists("-ravpic"); //! // @vanilla // // Don't allow artifacts to be used when the run key is held down. // artiskip = M_ParmExists("-artiskip"); debugmode = M_ParmExists("-debug"); //! // @vanilla // @category net // // Start a deathmatch game. // deathmatch = M_ParmExists("-deathmatch"); // currently broken or unused: cmdfrag = M_ParmExists("-cmdfrag"); // Check WAD file command line options W_ParseCommandLine(); //! // @vanilla // @arg <path> // // Development option to specify path to level scripts. // p = M_CheckParmWithArgs("-scripts", 1); if (p) { sc_FileScripts = true; sc_ScriptsDir = myargv[p+1]; } //! // @arg <skill> // @vanilla // // Set the game skill, 1-5 (1: easiest, 5: hardest). A skill of // 0 disables all monsters. // p = M_CheckParmWithArgs("-skill", 1); if (p) { startskill = myargv[p+1][0] - '1'; autostart = true; } //! // @arg <demo> // @category demo // @vanilla // // Play back the demo named demo.lmp. // p = M_CheckParmWithArgs("-playdemo", 1); if (!p) { //! // @arg <demo> // @category demo // @vanilla // // Play back the demo named demo.lmp, determining the framerate // of the screen. // p = M_CheckParmWithArgs("-timedemo", 1); } if (p) { char *uc_filename; char file[256]; M_StringCopy(file, myargv[p+1], sizeof(file)); // With Vanilla Hexen you have to specify the file without // extension, but make that optional. uc_filename = strdup(myargv[p + 1]); M_ForceUppercase(uc_filename); if (!M_StringEndsWith(uc_filename, ".LMP")) { M_StringConcat(file, ".lmp", sizeof(file)); } free(uc_filename); if (W_AddFile(file) != NULL) { M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name, sizeof(demolumpname)); } else { // The file failed to load, but copy the original arg as a // demo name to make tricks like -playdemo demo1 possible. M_StringCopy(demolumpname, myargv[p+1], sizeof(demolumpname)); } ST_Message("Playing demo %s.\n", myargv[p+1]); } if (M_ParmExists("-testcontrols")) { autostart = true; testcontrols = true; } }
void D_IdentifyVersion(void) { // gamemission is set up by the D_FindIWAD function. But if // we specify '-iwad', we have to identify using // IdentifyIWADByName. However, if the iwad does not match // any known IWAD name, we may have a dilemma. Try to // identify by its contents. // STRIFE-TODO: some elaborate checks? for now we assume... // The logic in strife1.exe is simple: // * if strife1.wad is found, set isregistered = true // * if strife0.wad is found, set isdemoversion = true // Make sure gamemode is set up correctly gamemode = commercial; gamemission = strife; isregistered = true; // Load voices.wad if(isregistered) { char *name = D_FindWADByName("voices.wad"); if(!name) // not found? { int p; // haleyjd STRIFE-FIXME: Temporary? // If -iwad was used, check and see if voices.wad exists on the // same filepath. if((p = M_CheckParm("-iwad")) && p < myargc - 1) { char *iwad = myargv[p + 1]; size_t len = strlen(iwad) + 24; char *filename = malloc(len); char sepchar; // how the heck is Choco surviving without this routine? sepchar = M_GetFilePath(iwad, filename, len); filename[strlen(filename)] = sepchar; M_StringConcat(filename, "voices.wad", sizeof(filename)); if(!M_FileExists(filename)) disable_voices = 1; else name = filename; // STRIFE-FIXME: memory leak!! } else disable_voices = 1; } if(disable_voices) // voices disabled? { if(devparm) printf("Voices disabled\n"); return; } D_AddFile(name); } }