Avoid relocations for cheat codes

This commit is contained in:
Kp 2013-11-28 02:16:05 +00:00
parent 08efe14586
commit fa496dc992

View file

@ -1368,59 +1368,59 @@ static int HandleTestKey(int key)
typedef struct cheat_code typedef struct cheat_code
{ {
const char string[CHEAT_MAX_LEN]; const char string[CHEAT_MAX_LEN];
int *stateptr; int (game_cheats::*stateptr);
} __pack__ cheat_code; } __pack__ cheat_code;
static const cheat_code cheat_codes[] = { static const cheat_code cheat_codes[] = {
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
{ "gabbagabbahey", &cheats.enabled }, { "gabbagabbahey", &game_cheats::enabled },
{ "scourge", &cheats.wowie }, { "scourge", &game_cheats::wowie },
{ "bigred", &cheats.wowie2 }, { "bigred", &game_cheats::wowie2 },
{ "mitzi", &cheats.allkeys }, { "mitzi", &game_cheats::allkeys },
{ "racerx", &cheats.invul }, { "racerx", &game_cheats::invul },
{ "guile", &cheats.cloak }, { "guile", &game_cheats::cloak },
{ "twilight", &cheats.shields }, { "twilight", &game_cheats::shields },
{ "poboys", &cheats.killreactor }, { "poboys", &game_cheats::killreactor },
{ "farmerjoe", &cheats.levelwarp }, { "farmerjoe", &game_cheats::levelwarp },
{ "bruin", &cheats.extralife }, { "bruin", &game_cheats::extralife },
{ "porgys", &cheats.rapidfire }, { "porgys", &game_cheats::rapidfire },
{ "ahimsa", &cheats.robotfiringsuspended }, { "ahimsa", &game_cheats::robotfiringsuspended },
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
{ "gabbagabbahey", &cheats.lamer }, { "gabbagabbahey", &game_cheats::lamer },
{ "motherlode", &cheats.lamer }, { "motherlode", &game_cheats::lamer },
{ "currygoat", &cheats.lamer }, { "currygoat", &game_cheats::lamer },
{ "zingermans", &cheats.lamer }, { "zingermans", &game_cheats::lamer },
{ "eatangelos", &cheats.lamer }, { "eatangelos", &game_cheats::lamer },
{ "ericaanne", &cheats.lamer }, { "ericaanne", &game_cheats::lamer },
{ "joshuaakira", &cheats.lamer }, { "joshuaakira", &game_cheats::lamer },
{ "whammazoom", &cheats.lamer }, { "whammazoom", &game_cheats::lamer },
{ "honestbob", &cheats.wowie }, { "honestbob", &game_cheats::wowie },
{ "algroove", &cheats.allkeys }, { "algroove", &game_cheats::allkeys },
{ "alifalafel", &cheats.accessory }, { "alifalafel", &game_cheats::accessory },
{ "almighty", &cheats.invul }, { "almighty", &game_cheats::invul },
{ "blueorb", &cheats.shields }, { "blueorb", &game_cheats::shields },
{ "delshiftb", &cheats.killreactor }, { "delshiftb", &game_cheats::killreactor },
{ "freespace", &cheats.levelwarp }, { "freespace", &game_cheats::levelwarp },
{ "rockrgrl", &cheats.fullautomap }, { "rockrgrl", &game_cheats::fullautomap },
{ "wildfire", &cheats.rapidfire }, { "wildfire", &game_cheats::rapidfire },
{ "duddaboo", &cheats.bouncyfire }, { "duddaboo", &game_cheats::bouncyfire },
{ "imagespace", &cheats.robotfiringsuspended }, { "imagespace", &game_cheats::robotfiringsuspended },
{ "spaniard", &cheats.killallrobots }, { "spaniard", &game_cheats::killallrobots },
{ "silkwing", &cheats.robotskillrobots }, { "silkwing", &game_cheats::robotskillrobots },
{ "godzilla", &cheats.monsterdamage }, { "godzilla", &game_cheats::monsterdamage },
{ "helpvishnu", &cheats.buddyclone }, { "helpvishnu", &game_cheats::buddyclone },
{ "gowingnut", &cheats.buddyangry }, { "gowingnut", &game_cheats::buddyangry },
#endif #endif
{ "flash", &cheats.exitpath }, { "flash", &game_cheats::exitpath },
{ "astral", &cheats.ghostphysics }, { "astral", &game_cheats::ghostphysics },
{ "buggin", &cheats.turbo }, { "buggin", &game_cheats::turbo },
{ "bittersweet", &cheats.acid }, { "bittersweet", &game_cheats::acid },
}; };
static int FinalCheats(int key) static int FinalCheats(int key)
{ {
static char cheat_buffer[CHEAT_MAX_LEN]; static char cheat_buffer[CHEAT_MAX_LEN];
int *gotcha; int (game_cheats::*gotcha);
if (Game_mode & GM_MULTI) if (Game_mode & GM_MULTI)
return 0; return 0;
@ -1436,14 +1436,14 @@ static int FinalCheats(int key)
Assert(cheatlen <= CHEAT_MAX_LEN); Assert(cheatlen <= CHEAT_MAX_LEN);
if (d_strnicmp(cheat_codes[i].string, cheat_buffer+CHEAT_MAX_LEN-cheatlen, cheatlen)==0) if (d_strnicmp(cheat_codes[i].string, cheat_buffer+CHEAT_MAX_LEN-cheatlen, cheatlen)==0)
{ {
gotcha = cheat_codes[i].stateptr;
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
if (!cheats.enabled && *cheat_codes[i].stateptr != cheats.enabled) if (!cheats.enabled && cheats.*gotcha != cheats.enabled)
return 0; return 0;
if (!cheats.enabled) if (!cheats.enabled)
HUD_init_message_literal(HM_DEFAULT, TXT_CHEATS_ENABLED); HUD_init_message_literal(HM_DEFAULT, TXT_CHEATS_ENABLED);
#endif #endif
gotcha = cheat_codes[i].stateptr; cheats.*gotcha = !(cheats.*gotcha);
*cheat_codes[i].stateptr = !*cheat_codes[i].stateptr;
cheats.enabled = 1; cheats.enabled = 1;
digi_play_sample( SOUND_CHEATER, F1_0); digi_play_sample( SOUND_CHEATER, F1_0);
Players[Player_num].score = 0; Players[Player_num].score = 0;
@ -1452,7 +1452,7 @@ static int FinalCheats(int key)
} }
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
if (gotcha == &cheats.wowie) if (gotcha == &game_cheats::wowie)
{ {
HUD_init_message_literal(HM_DEFAULT, TXT_WOWIE_ZOWIE); HUD_init_message_literal(HM_DEFAULT, TXT_WOWIE_ZOWIE);
@ -1472,7 +1472,7 @@ static int FinalCheats(int key)
update_laser_weapon_info(); update_laser_weapon_info();
} }
if (gotcha == &cheats.wowie2) if (gotcha == &game_cheats::wowie2)
{ {
HUD_init_message(HM_DEFAULT, "SUPER %s",TXT_WOWIE_ZOWIE); HUD_init_message(HM_DEFAULT, "SUPER %s",TXT_WOWIE_ZOWIE);
@ -1492,13 +1492,13 @@ static int FinalCheats(int key)
update_laser_weapon_info(); update_laser_weapon_info();
} }
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
if (gotcha == &cheats.lamer) if (gotcha == &game_cheats::lamer)
{ {
Players[Player_num].shields=Players[Player_num].energy=i2f(1); Players[Player_num].shields=Players[Player_num].energy=i2f(1);
HUD_init_message_literal(HM_DEFAULT, "Take that...cheater!"); HUD_init_message_literal(HM_DEFAULT, "Take that...cheater!");
} }
if (gotcha == &cheats.wowie) if (gotcha == &game_cheats::wowie)
{ {
HUD_init_message_literal(HM_DEFAULT, TXT_WOWIE_ZOWIE); HUD_init_message_literal(HM_DEFAULT, TXT_WOWIE_ZOWIE);
@ -1533,7 +1533,7 @@ static int FinalCheats(int key)
update_laser_weapon_info(); update_laser_weapon_info();
} }
if (gotcha == &cheats.accessory) if (gotcha == &game_cheats::accessory)
{ {
Players[Player_num].flags |=PLAYER_FLAGS_HEADLIGHT; Players[Player_num].flags |=PLAYER_FLAGS_HEADLIGHT;
Players[Player_num].flags |=PLAYER_FLAGS_AFTERBURNER; Players[Player_num].flags |=PLAYER_FLAGS_AFTERBURNER;
@ -1543,27 +1543,27 @@ static int FinalCheats(int key)
} }
#endif #endif
if (gotcha == &cheats.allkeys) if (gotcha == &game_cheats::allkeys)
{ {
HUD_init_message_literal(HM_DEFAULT, TXT_ALL_KEYS); HUD_init_message_literal(HM_DEFAULT, TXT_ALL_KEYS);
Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY; Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY;
} }
if (gotcha == &cheats.invul) if (gotcha == &game_cheats::invul)
{ {
Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE; Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
HUD_init_message(HM_DEFAULT, "%s %s!", TXT_INVULNERABILITY, (Players[Player_num].flags&PLAYER_FLAGS_INVULNERABLE)?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "%s %s!", TXT_INVULNERABILITY, (Players[Player_num].flags&PLAYER_FLAGS_INVULNERABLE)?TXT_ON:TXT_OFF);
Players[Player_num].invulnerable_time = GameTime64+i2f(1000); Players[Player_num].invulnerable_time = GameTime64+i2f(1000);
} }
if (gotcha == &cheats.shields) if (gotcha == &game_cheats::shields)
{ {
HUD_init_message_literal(HM_DEFAULT, TXT_FULL_SHIELDS); HUD_init_message_literal(HM_DEFAULT, TXT_FULL_SHIELDS);
Players[Player_num].shields = MAX_SHIELDS; Players[Player_num].shields = MAX_SHIELDS;
} }
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
if (gotcha == &cheats.cloak) if (gotcha == &game_cheats::cloak)
{ {
Players[Player_num].flags ^= PLAYER_FLAGS_CLOAKED; Players[Player_num].flags ^= PLAYER_FLAGS_CLOAKED;
HUD_init_message(HM_DEFAULT, "%s %s!", TXT_CLOAK, (Players[Player_num].flags&PLAYER_FLAGS_CLOAKED)?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "%s %s!", TXT_CLOAK, (Players[Player_num].flags&PLAYER_FLAGS_CLOAKED)?TXT_ON:TXT_OFF);
@ -1574,7 +1574,7 @@ static int FinalCheats(int key)
} }
} }
if (gotcha == &cheats.extralife) if (gotcha == &game_cheats::extralife)
{ {
if (Players[Player_num].lives<50) if (Players[Player_num].lives<50)
{ {
@ -1584,18 +1584,18 @@ static int FinalCheats(int key)
} }
#endif #endif
if (gotcha == &cheats.killreactor) if (gotcha == &game_cheats::killreactor)
{ {
kill_and_so_forth(); kill_and_so_forth();
} }
if (gotcha == &cheats.exitpath) if (gotcha == &game_cheats::exitpath)
{ {
if (create_special_path()) if (create_special_path())
HUD_init_message_literal(HM_DEFAULT, "Exit path illuminated!"); HUD_init_message_literal(HM_DEFAULT, "Exit path illuminated!");
} }
if (gotcha == &cheats.levelwarp) if (gotcha == &game_cheats::levelwarp)
{ {
newmenu_item m; newmenu_item m;
char text[10]=""; char text[10]="";
@ -1613,12 +1613,12 @@ static int FinalCheats(int key)
} }
} }
if (gotcha == &cheats.ghostphysics) if (gotcha == &game_cheats::ghostphysics)
{ {
HUD_init_message(HM_DEFAULT, "%s %s!", "Ghosty mode", cheats.ghostphysics?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "%s %s!", "Ghosty mode", cheats.ghostphysics?TXT_ON:TXT_OFF);
} }
if (gotcha == &cheats.rapidfire) if (gotcha == &game_cheats::rapidfire)
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
{ {
do_megawow_powerup(200); do_megawow_powerup(200);
@ -1628,46 +1628,46 @@ static int FinalCheats(int key)
HUD_init_message(HM_DEFAULT, "Rapid fire %s!", cheats.rapidfire?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "Rapid fire %s!", cheats.rapidfire?TXT_ON:TXT_OFF);
} }
if (gotcha == &cheats.bouncyfire) if (gotcha == &game_cheats::bouncyfire)
{ {
HUD_init_message(HM_DEFAULT, "Bouncing weapons %s!", cheats.bouncyfire?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "Bouncing weapons %s!", cheats.bouncyfire?TXT_ON:TXT_OFF);
} }
#endif #endif
if (gotcha == &cheats.turbo) if (gotcha == &game_cheats::turbo)
{ {
HUD_init_message(HM_DEFAULT, "%s %s!", "Turbo mode", cheats.turbo?TXT_ON:TXT_OFF); HUD_init_message(HM_DEFAULT, "%s %s!", "Turbo mode", cheats.turbo?TXT_ON:TXT_OFF);
} }
if (gotcha == &cheats.robotfiringsuspended) if (gotcha == &game_cheats::robotfiringsuspended)
{ {
HUD_init_message(HM_DEFAULT, "Robot firing %s!", cheats.robotfiringsuspended?TXT_OFF:TXT_ON); HUD_init_message(HM_DEFAULT, "Robot firing %s!", cheats.robotfiringsuspended?TXT_OFF:TXT_ON);
} }
#if defined(DXX_BUILD_DESCENT_II) #if defined(DXX_BUILD_DESCENT_II)
if (gotcha == &cheats.killallrobots) if (gotcha == &game_cheats::killallrobots)
{ {
kill_all_robots(); kill_all_robots();
} }
if (gotcha == &cheats.robotskillrobots) if (gotcha == &game_cheats::robotskillrobots)
{ {
HUD_init_message_literal(HM_DEFAULT, cheats.robotskillrobots?"Rabid robots!":"Kill the player!"); HUD_init_message_literal(HM_DEFAULT, cheats.robotskillrobots?"Rabid robots!":"Kill the player!");
} }
if (gotcha == &cheats.monsterdamage) if (gotcha == &game_cheats::monsterdamage)
{ {
HUD_init_message_literal(HM_DEFAULT, cheats.monsterdamage?"Oh no, there goes Tokyo!":"What have you done, I'm shrinking!!"); HUD_init_message_literal(HM_DEFAULT, cheats.monsterdamage?"Oh no, there goes Tokyo!":"What have you done, I'm shrinking!!");
} }
if (gotcha == &cheats.buddyclone) if (gotcha == &game_cheats::buddyclone)
{ {
HUD_init_message_literal(HM_DEFAULT, "What's this? Another buddy bot!"); HUD_init_message_literal(HM_DEFAULT, "What's this? Another buddy bot!");
create_buddy_bot(); create_buddy_bot();
} }
if (gotcha == &cheats.buddyangry) if (gotcha == &game_cheats::buddyangry)
{ {
if (cheats.buddyangry) if (cheats.buddyangry)
@ -1683,7 +1683,7 @@ static int FinalCheats(int key)
} }
#endif #endif
if (gotcha == &cheats.acid) if (gotcha == &game_cheats::acid)
{ {
HUD_init_message_literal(HM_DEFAULT, cheats.acid?"Going up!":"Coming down!"); HUD_init_message_literal(HM_DEFAULT, cheats.acid?"Going up!":"Coming down!");
} }