123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- #include "doomstat.h"
- #include "g_game.h"
- #include "r_data.h"
- #include "p_inter.h"
- #include "p_tick.h"
- #include "m_cheat.h"
- #include "m_argv.h"
- #include "s_sound.h"
- #include "sounds.h"
- #include "dstrings.h"
- #include "r_main.h"
- #include "p_map.h"
- #include "d_deh.h"
- #include "p_tick.h"
- #define plyr (players+consoleplayer)
- static void cheat_mus();
- static void cheat_choppers();
- static void cheat_god();
- static void cheat_fa();
- static void cheat_k();
- static void cheat_kfa();
- static void cheat_noclip();
- static void cheat_pw();
- static void cheat_behold();
- static void cheat_clev();
- static void cheat_mypos();
- static void cheat_rate();
- static void cheat_comp();
- static void cheat_friction();
- static void cheat_pushers();
- static void cheat_tnttran();
- static void cheat_massacre();
- static void cheat_ddt();
- static void cheat_hom();
- static void cheat_fast();
- static void cheat_tntkey();
- static void cheat_tntkeyx();
- static void cheat_tntkeyxx();
- static void cheat_tntweap();
- static void cheat_tntweapx();
- static void cheat_tntammo();
- static void cheat_tntammox();
- static void cheat_smart();
- static void cheat_pitch();
- static void cheat_megaarmour();
- static void cheat_health();
- struct cheat_s cheat[] = {
- {"idmus", "Change music", always,
- cheat_mus, -2, 0, 0 },
- {"idchoppers", "Chainsaw", not_net | not_demo,
- cheat_choppers, 0, 0, 0 },
- {"iddqd", "God mode", not_net | not_demo,
- cheat_god, 0, 0, 0 },
- #if 0
- {"idk", NULL, not_net | not_demo | not_deh,
- cheat_k },
- #endif
- {"idkfa", "Ammo & Keys", not_net | not_demo,
- cheat_kfa, 0, 0, 0 },
- {"idfa", "Ammo", not_net | not_demo,
- cheat_fa, 0, 0, 0 },
- {"idspispopd", "No Clipping 1", not_net | not_demo,
- cheat_noclip, 0, 0, 0 },
- {"idclip", "No Clipping 2", not_net | not_demo,
- cheat_noclip, 0, 0, 0 },
- {"idbeholdh", "Invincibility", not_net | not_demo,
- cheat_health, 0, 0, 0 },
- {"idbeholdm", "Invincibility", not_net | not_demo,
- cheat_megaarmour, 0, 0, 0 },
- {"idbeholdv", "Invincibility", not_net | not_demo,
- cheat_pw, pw_invulnerability, 0, 0 },
- {"idbeholds", "Berserk", not_net | not_demo,
- cheat_pw, pw_strength, 0, 0 },
- {"idbeholdi", "Invisibility", not_net | not_demo,
- cheat_pw, pw_invisibility, 0, 0 },
- {"idbeholdr", "Radiation Suit", not_net | not_demo,
- cheat_pw, pw_ironfeet, 0, 0 },
- {"idbeholda", "Auto-map", not_dm,
- cheat_pw, pw_allmap, 0, 0 },
- {"idbeholdl", "Lite-Amp Goggles", not_dm,
- cheat_pw, pw_infrared, 0, 0 },
- {"idbehold", "BEHOLD menu", not_dm,
- cheat_behold, 0, 0, 0 },
- {"idclev", "Level Warp", not_net | not_demo | not_menu,
- cheat_clev, -2, 0, 0},
- {"idmypos", "Player Position", not_dm,
- cheat_mypos, 0, 0, 0 },
- {"idrate", "Frame rate", 0,
- cheat_rate, 0, 0, 0 },
- {"tntcomp", NULL, not_net | not_demo,
- cheat_comp, 0, 0, 0 },
- {"tntem", NULL, not_net | not_demo,
- cheat_massacre, 0, 0, 0 },
- {"iddt", "Map cheat", not_dm,
- cheat_ddt, 0, 0, 0 },
- {"tnthom", NULL, always,
- cheat_hom, 0, 0, 0 },
- {"tntkey", NULL, not_net | not_demo,
- cheat_tntkey, 0, 0, 0 },
- {"tntkeyr", NULL, not_net | not_demo,
- cheat_tntkeyx, 0, 0, 0 },
- {"tntkeyy", NULL, not_net | not_demo,
- cheat_tntkeyx, 0, 0, 0 },
- {"tntkeyb", NULL, not_net | not_demo,
- cheat_tntkeyx, 0, 0, 0 },
- {"tntkeyrc", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_redcard, 0, 0 },
- {"tntkeyyc", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_yellowcard, 0, 0 },
- {"tntkeybc", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_bluecard, 0, 0 },
- {"tntkeyrs", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_redskull, 0, 0 },
- {"tntkeyys", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_yellowskull, 0, 0 },
- {"tntkeybs", NULL, not_net | not_demo,
- cheat_tntkeyxx, it_blueskull, 0, 0 },
- {"tntka", NULL, not_net | not_demo,
- cheat_k, 0, 0, 0 },
- {"tntweap", NULL, not_net | not_demo,
- cheat_tntweap, 0, 0, 0 },
- {"tntweap", NULL, not_net | not_demo,
- cheat_tntweapx, -1, 0, 0},
- {"tntammo", NULL, not_net | not_demo,
- cheat_tntammo, 0, 0, 0 },
- {"tntammo", NULL, not_net | not_demo,
- cheat_tntammox, -1, 0, 0},
- {"tnttran", NULL, always,
- cheat_tnttran, 0, 0, 0 },
- {"tntsmart", NULL, not_net | not_demo,
- cheat_smart, 0, 0, 0},
- {"tntpitch", NULL, always,
- cheat_pitch, 0, 0, 0},
-
- {"tntran", NULL, always,
- cheat_tnttran, 0, 0, 0 },
- {"tntamo", NULL, not_net | not_demo,
- cheat_tntammo, 0, 0, 0 },
- {"tntamo", NULL, not_net | not_demo,
- cheat_tntammox, -1, 0, 0},
- {"tntfast", NULL, not_net | not_demo,
- cheat_fast, 0, 0, 0 },
- {"tntice", NULL, not_net | not_demo,
- cheat_friction, 0, 0, 0 },
- {"tntpush", NULL, not_net | not_demo,
- cheat_pushers, 0, 0, 0 },
- {NULL, NULL, 0, NULL, 0, 0, 0}
- };
- static void cheat_mus(buf)
- char buf[3];
- {
- int musnum;
-
-
- if (!isdigit(buf[0]) || !isdigit(buf[1]))
- return;
- plyr->message = s_STSTR_MUS;
- if (gamemode == commercial)
- {
- musnum = mus_runnin + (buf[0]-'0')*10 + buf[1]-'0' - 1;
-
- if (musnum < mus_runnin || ((buf[0]-'0')*10 + buf[1]-'0') > 35)
- plyr->message = s_STSTR_NOMUS;
- else
- {
- S_ChangeMusic(musnum, 1);
- idmusnum = musnum;
- }
- }
- else
- {
- musnum = mus_e1m1 + (buf[0]-'1')*9 + (buf[1]-'1');
-
- if (buf[0] < '1' || buf[1] < '1' || ((buf[0]-'1')*9 + buf[1]-'1') > 31)
- plyr->message = s_STSTR_NOMUS;
- else
- {
- S_ChangeMusic(musnum, 1);
- idmusnum = musnum;
- }
- }
- }
- static void cheat_choppers()
- {
- plyr->weaponowned[wp_chainsaw] = true;
- plyr->powers[pw_invulnerability] = true;
- plyr->message = s_STSTR_CHOPPERS;
- }
- static void cheat_god()
- {
- plyr->cheats ^= CF_GODMODE;
- if (plyr->cheats & CF_GODMODE)
- {
- if (plyr->mo)
- plyr->mo->health = god_health;
- plyr->health = god_health;
- plyr->message = s_STSTR_DQDON;
- }
- else
- plyr->message = s_STSTR_DQDOFF;
- }
- static void cheat_health()
- {
- if (!(plyr->cheats & CF_GODMODE)) {
- if (plyr->mo)
- plyr->mo->health = mega_health;
- plyr->health = mega_health;
- plyr->message = s_STSTR_BEHOLDX;
- }
- }
- static void cheat_megaarmour()
- {
- plyr->armorpoints = idfa_armor;
- plyr->armortype = idfa_armor_class;
- plyr->message = s_STSTR_BEHOLDX;
- }
- static void cheat_fa()
- {
- int i;
- if (!plyr->backpack)
- {
- for (i=0 ; i<NUMAMMO ; i++)
- plyr->maxammo[i] *= 2;
- plyr->backpack = true;
- }
- plyr->armorpoints = idfa_armor;
- plyr->armortype = idfa_armor_class;
-
- for (i=0;i<NUMWEAPONS;i++)
- if (!(((i == wp_plasma || i == wp_bfg) && gamemode == shareware) ||
- (i == wp_supershotgun && gamemode != commercial)))
- plyr->weaponowned[i] = true;
- for (i=0;i<NUMAMMO;i++)
- if (i!=am_cell || gamemode!=shareware)
- plyr->ammo[i] = plyr->maxammo[i];
- plyr->message = s_STSTR_FAADDED;
- }
- static void cheat_k()
- {
- int i;
- for (i=0;i<NUMCARDS;i++)
- if (!plyr->cards[i])
- {
- plyr->cards[i] = true;
- plyr->message = "Keys Added";
- }
- }
- static void cheat_kfa()
- {
- cheat_k();
- cheat_fa();
- plyr->message = STSTR_KFAADDED;
- }
- static void cheat_noclip()
- {
-
-
- plyr->message = (plyr->cheats ^= CF_NOCLIP) & CF_NOCLIP ?
- s_STSTR_NCON : s_STSTR_NCOFF;
- }
- static void cheat_pw(int pw)
- {
- if (plyr->powers[pw])
- plyr->powers[pw] = pw!=pw_strength && pw!=pw_allmap;
- else
- {
- P_GivePower(plyr, pw);
- if (pw != pw_strength)
- plyr->powers[pw] = -1;
- }
- plyr->message = s_STSTR_BEHOLDX;
- }
- static void cheat_behold()
- {
- plyr->message = s_STSTR_BEHOLD;
- }
- static void cheat_clev(char buf[3])
- {
- int epsd, map;
- if (gamemode == commercial)
- {
- epsd = 1;
- map = (buf[0] - '0')*10 + buf[1] - '0';
- }
- else
- {
- epsd = buf[0] - '0';
- map = buf[1] - '0';
- }
-
- if (epsd < 1 || map < 1 ||
- (gamemode == retail && (epsd > 4 || map > 9 )) ||
- (gamemode == registered && (epsd > 3 || map > 9 )) ||
- (gamemode == shareware && (epsd > 1 || map > 9 )) ||
- (gamemode == commercial && (epsd > 1 || map > 32 )) )
- return;
-
- idmusnum = -1;
- plyr->message = s_STSTR_CLEV;
- G_DeferedInitNew(gameskill, epsd, map);
- }
- static void cheat_mypos()
- {
- doom_printf("Position (%d,%d,%d)\tAngle %-.0f",
- players[consoleplayer].mo->x >> FRACBITS,
- players[consoleplayer].mo->y >> FRACBITS,
- players[consoleplayer].mo->z >> FRACBITS,
- players[consoleplayer].mo->angle * (90.0/ANG90));
- }
- static void cheat_rate()
- {
- rendering_stats ^= 1;
- }
- static void cheat_comp()
- {
-
- compatibility_level++; compatibility_level %= MAX_COMPATIBILITY_LEVEL;
-
-
- G_Compatibility();
- doom_printf("New compatibility level:\n%s",
- comp_lev_str[compatibility_level]);
- }
- static void cheat_friction()
- {
- plyr->message =
- (variable_friction = !variable_friction) ? "Variable Friction enabled" :
- "Variable Friction disabled";
- }
- static void cheat_pushers()
- {
- plyr->message =
- (allow_pushers = !allow_pushers) ? "Pushers enabled" : "Pushers disabled";
- }
- static void cheat_tnttran()
- {
- plyr->message =
- (general_translucency = !general_translucency) ? "Translucency enabled" :
- "Translucency disabled";
-
- if (general_translucency && !main_tranmap)
- R_InitTranMap(0);
- }
- static void cheat_massacre()
- {
-
-
-
-
-
- int killcount=0;
- thinker_t *currentthinker = NULL;
- extern void A_PainDie(mobj_t *);
-
- uint_64_t mask = MF_FRIEND;
- P_MapStart();
- do
- while ((currentthinker = P_NextThinker(currentthinker,th_all)) != NULL)
- if (currentthinker->function == P_MobjThinker &&
- !(((mobj_t *) currentthinker)->flags & mask) &&
- (((mobj_t *) currentthinker)->flags & MF_COUNTKILL ||
- ((mobj_t *) currentthinker)->type == MT_SKULL))
- {
- if (((mobj_t *) currentthinker)->health > 0)
- {
- killcount++;
- P_DamageMobj((mobj_t *)currentthinker, NULL, NULL, 10000);
- }
- if (((mobj_t *) currentthinker)->type == MT_PAIN)
- {
- A_PainDie((mobj_t *) currentthinker);
- P_SetMobjState ((mobj_t *) currentthinker, S_PAIN_DIE6);
- }
- }
- while (!killcount && mask ? mask=0, 1 : 0);
- P_MapEnd();
-
-
- doom_printf("%d Monster%s Killed", killcount, killcount==1 ? "" : "s");
- }
- static void cheat_ddt()
- {
- extern int ddt_cheating;
- if (automapmode & am_active)
- ddt_cheating = (ddt_cheating+1) % 3;
- }
- static void cheat_hom()
- {
- extern int autodetect_hom;
- plyr->message = (autodetect_hom = !autodetect_hom) ? "HOM Detection On" :
- "HOM Detection Off";
- }
- static void cheat_fast()
- {
- plyr->message = (fastparm = !fastparm) ? "Fast Monsters On" :
- "Fast Monsters Off";
- G_SetFastParms(fastparm);
- }
- static void cheat_tntkey()
- {
- plyr->message = "Red, Yellow, Blue";
- }
- static void cheat_tntkeyx()
- {
- plyr->message = "Card, Skull";
- }
- static void cheat_tntkeyxx(int key)
- {
- plyr->message = (plyr->cards[key] = !plyr->cards[key]) ?
- "Key Added" : "Key Removed";
- }
- static void cheat_tntweap()
- {
- plyr->message = gamemode==commercial ?
- "Weapon number 1-9" : "Weapon number 1-8";
- }
- static void cheat_tntweapx(buf)
- char buf[3];
- {
- int w = *buf - '1';
- if ((w==wp_supershotgun && gamemode!=commercial) ||
- ((w==wp_bfg || w==wp_plasma) && gamemode==shareware))
- return;
- if (w==wp_fist)
- cheat_pw(pw_strength);
- else
- if (w >= 0 && w < NUMWEAPONS) {
- if ((plyr->weaponowned[w] = !plyr->weaponowned[w]))
- plyr->message = "Weapon Added";
- else
- {
- plyr->message = "Weapon Removed";
- if (w==plyr->readyweapon)
- plyr->pendingweapon = P_SwitchWeapon(plyr);
- }
- }
- }
- static void cheat_tntammo()
- {
- plyr->message = "Ammo 1-4, Backpack";
- }
- static void cheat_tntammox(buf)
- char buf[1];
- {
- int a = *buf - '1';
- if (*buf == 'b')
- if ((plyr->backpack = !plyr->backpack))
- for (plyr->message = "Backpack Added", a=0 ; a<NUMAMMO ; a++)
- plyr->maxammo[a] <<= 1;
- else
- for (plyr->message = "Backpack Removed", a=0 ; a<NUMAMMO ; a++)
- {
- if (plyr->ammo[a] > (plyr->maxammo[a] >>= 1))
- plyr->ammo[a] = plyr->maxammo[a];
- }
- else
- if (a>=0 && a<NUMAMMO)
- {
- a = a==am_cell ? am_misl : a==am_misl ? am_cell : a;
- plyr->message = (plyr->ammo[a] = !plyr->ammo[a]) ?
- plyr->ammo[a] = plyr->maxammo[a], "Ammo Added" : "Ammo Removed";
- }
- }
- static void cheat_smart()
- {
- plyr->message = (monsters_remember = !monsters_remember) ?
- "Smart Monsters Enabled" : "Smart Monsters Disabled";
- }
- static void cheat_pitch()
- {
- plyr->message=(pitched_sounds = !pitched_sounds) ? "Pitch Effects Enabled" :
- "Pitch Effects Disabled";
- }
- #define CHEAT_ARGS_MAX 8
- boolean M_FindCheats(int key)
- {
- static uint_64_t sr;
- static char argbuf[CHEAT_ARGS_MAX+1], *arg;
- static int init, argsleft, cht;
- int i, ret, matchedbefore;
-
-
- if (argsleft)
- {
- *arg++ = tolower(key);
- if (!--argsleft)
- cheat[cht].func(argbuf);
- return 1;
- }
- key = tolower(key) - 'a';
- if (key < 0 || key >= 32)
- {
- sr = 0;
- return 0;
- }
- if (!init)
- {
- init = 1;
- for (i=0;cheat[i].cheat;i++)
- {
- uint_64_t c=0, m=0;
- const char *p;
- for (p=cheat[i].cheat; *p; p++)
- {
- unsigned keynum = tolower(*p)-'a';
- if (keynum >= 32)
- continue;
- c = (c<<5) + keynum;
- m = (m<<5) + 31;
- }
- cheat[i].code = c;
- cheat[i].mask = m;
- }
- }
- sr = (sr<<5) + key;
- for (matchedbefore = ret = i = 0; cheat[i].cheat; i++)
- if ((sr & cheat[i].mask) == cheat[i].code &&
- !(cheat[i].when & not_dm && deathmatch) &&
- !(cheat[i].when & not_coop && netgame && !deathmatch) &&
- !(cheat[i].when & not_demo && (demorecording || demoplayback)) &&
- !(cheat[i].when & not_menu && menuactive) &&
- !(cheat[i].when & not_deh && M_CheckParm("-deh"))) {
- if (cheat[i].arg < 0)
- {
- cht = i;
- arg = argbuf;
- argsleft = -cheat[i].arg;
- ret = 1;
- }
- else
- if (!matchedbefore)
- {
- matchedbefore = ret = 1;
- cheat[i].func(cheat[i].arg);
- }
- }
- return ret;
- }
|