Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use KEYBOARD.COK when it is available, otherwise use embedded table #322

Merged
merged 7 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in the German Carmageddon DOS executable.

This makes sure the extended ASCII codes remain positive.
Before, these became negative here.

Not doing this causes an out-of-bounds access when reading the texture of an extended ASCII character.

} 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