Skip to content

Commit

Permalink
Only use KEYBOARD.COK when it is available, otherwise use embedded ta…
Browse files Browse the repository at this point in the history
…ble (#322)

* Some executables accept a -german command line option for a 'safe' environment

* Add ascii table for carmageddon, and use it when KEYBOARD.COK is not available

* Remove unneeded braces in input.c

* Use KEY_SHIFT_ANY instead of KEY_LSHIFT

* Remove empty line

* Move ascii tables to external header

* Make sure to treat extended ASCII as unsigned: they must be positive to avoid out-of-bounds texture access
  • Loading branch information
madebr authored May 4, 2023
1 parent 99473ff commit 07d5173
Show file tree
Hide file tree
Showing 8 changed files with 933 additions and 66 deletions.
13 changes: 8 additions & 5 deletions src/DETHRACE/common/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void ResetPollKeys(void) {
void CheckKeysForMouldiness(void) {
LOG_TRACE9("()");

if ((PDGetTotalTime() - gLast_poll_keys) > 500) {
if (PDGetTotalTime() - gLast_poll_keys > 500) {
ResetPollKeys();
CyclePollKeys();
PollKeys();
Expand All @@ -110,7 +110,7 @@ tKey_down_result PDKeyDown2(int pKey_index) {
the_time = PDGetTotalTime();
if (gKey_array[pKey_index]) {
if (gLast_key_down == pKey_index) {
if ((the_time - gLast_key_down_time) < 300) {
if (the_time - gLast_key_down_time < 300) {
return tKey_down_still;
} else {
gLast_key_down_time = the_time;
Expand Down Expand Up @@ -403,13 +403,15 @@ int AddRollingLetter(char pChar, int pX, int pY, tRolling_type rolling_type) {
let->current_offset = (gCurrent_graf_data->save_slot_letter_height * let->number_of_letters);
for (i = 0; i < let->number_of_letters; i++) {
if (rolling_type == eRT_numeric) {
let->letters[i] = pChar;
/* The (tU8) cast makes sure extended ASCII is positive. */
let->letters[i] = (tU8)pChar;
} else {
let->letters[i] = IRandomBetween('A', 'Z' + 1);
}
}
if (rolling_type != eRT_looping_random) {
let->letters[0] = pChar;
/* The (tU8) cast makes sure extended ASCII is positive. */
let->letters[0] = (tU8)pChar;
}

return 0;
Expand Down Expand Up @@ -539,7 +541,8 @@ int ChangeCharTo(int pSlot_index, int pChar_index, char pNew_char) {
return AddRollingLetter(pNew_char, x_coord, y_coord, new_type);
}
if (pNew_char != ROLLING_LETTER_LOOP_RANDOM) {
let->letters[0] = pNew_char;
/* The (tU8) cast makes sure extended ASCII is positive. */
let->letters[0] = (tU8)pNew_char;
}
if (pNew_char == ' ') {
let->letters[0] = ' ';
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/common/pedestrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ void LoadInPedestrians(FILE* pF, int pSubs_count, tPed_subs* pSubs_array) {
ped_count = temp_int;
}
gPedestrian_array = BrMemAllocate(sizeof(tPedestrian_data) * (ped_count + (gAusterity_mode ? 0 : 200)), kMem_ped_array_stain);
if (PDKeyDown(KEY_LCTRL) && PDKeyDown(KEY_LSHIFT) && PDKeyDown(KEY_A)) {
if (PDKeyDown(KEY_CTRL_ANY) && PDKeyDown(KEY_SHIFT_ANY) && PDKeyDown(KEY_A)) {
check_for_duplicates = 1;
DRS3StartSound(gEffects_outlet, 3202);
DRS3StartSound(gEffects_outlet, 3202);
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/pc-dos/dossys.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ int original_main(int pArgc, char** pArgv) {
sscanf(pArgv[i], "%d", &arg);
gSound_detail_level = arg;

} else if (strcasecmp(pArgv[i], "-robots") == 0) {
} else if (strcasecmp(pArgv[i], "-robots") == 0 || strcasecmp(pArgv[i], "-german") == 0) {
gSausage_override = 1;
} else if (strcasecmp(pArgv[i], "-lomem") == 0) {
gAustere_override = 1;
Expand Down
24 changes: 15 additions & 9 deletions src/DETHRACE/pc-win95/win95sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ void PDSetKeyArray(int* pKeys, int pMark) {
case KEY_ALT_ANY:
if (KEYDOWN(keystate, gScan_code[KEY_LALT]) || KEYDOWN(keystate, gScan_code[KEY_RALT])) {
pKeys[KEY_ALT_ANY] = pMark;

} else {
if (pKeys[KEY_ALT_ANY] == pMark) {
pKeys[KEY_ALT_ANY] = 0;
Expand Down Expand Up @@ -309,7 +308,7 @@ void Win32ReleaseInputDevice(void) {
int PDGetASCIIFromKey(int pKey) {
LOG_TRACE("(%d)", pKey);

if (PDKeyDown(KEY_LSHIFT)) {
if (PDKeyDown(KEY_SHIFT_ANY)) {
return gASCII_shift_table[pKey];
} else {
return gASCII_table[pKey];
Expand Down Expand Up @@ -368,11 +367,21 @@ void PDInitialiseSystem(void) {
ShowCursor_(0);
KeyBegin();

// dethrace: demos do not ship with KEYBOARD.COK file
if (harness_game_info.defines.ascii_table == NULL) {
PathCat(the_path, gApplication_path, "KEYBOARD.COK");
f = fopen(the_path, "rb");
if (f == NULL) {
if (harness_game_info.defines.requires_ascii_table) {
#if !defined(DETHRACE_FIX_BUGS)
PDFatalError("This .exe must have KEYBOARD.COK in the DATA folder.");
#endif
}
// dethrace: demos do not ship with KEYBOARD.COK file
memcpy(gASCII_table, harness_game_info.defines.ascii_table, sizeof(gASCII_table));
memcpy(gASCII_shift_table, harness_game_info.defines.ascii_shift_table, sizeof(gASCII_shift_table));
} else {
PathCat(the_path, gApplication_path, "KEYBOARD.COK");
f = fopen(the_path, "rb");
if (!f) {
if (f == NULL) {
PDFatalError("This .exe must have KEYBOARD.COK in the DATA folder.");
}
fseek(f, 0, 2);
Expand All @@ -381,9 +390,6 @@ void PDInitialiseSystem(void) {
fread(gASCII_table, len, 1u, f);
fread(gASCII_shift_table, len, 1u, f);
fclose(f);
} else {
memcpy(gASCII_table, harness_game_info.defines.ascii_table, sizeof(gASCII_table));
memcpy(gASCII_shift_table, harness_game_info.defines.ascii_shift_table, sizeof(gASCII_shift_table));
}
Win32InitInputDevice();
}
Expand Down Expand Up @@ -915,7 +921,7 @@ int original_main(int pArgc, char** pArgv) {
sscanf(pArgv[i], "%d", &arg);
gSound_detail_level = arg;

} else if (strcasecmp(pArgv[i], "-robots") == 0) {
} else if (strcasecmp(pArgv[i], "-robots") == 0 || strcasecmp(pArgv[i], "-german") == 0) {
gSausage_override = 1;
} else if (strcasecmp(pArgv[i], "-lomem") == 0) {
gAustere_override = 1;
Expand Down
1 change: 1 addition & 0 deletions src/harness/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target_sources(harness PRIVATE
include/harness/win95_polyfill_defs.h
# cameras/debug_camera.c
# cameras/debug_camera.h
ascii_tables.h
harness_trace.c
harness.c
harness.h
Expand Down
Loading

0 comments on commit 07d5173

Please sign in to comment.