Skip to content

Commit

Permalink
Fixes for Portuguese Carmageddon (#353)
Browse files Browse the repository at this point in the history
* Fix bugs exposed by Portuguese Carmageddon

* Fixes for warnings/errors found in rec2

* Macos says "no"

* Last argument of _partSet can be a pointer

* feof is a macro dereferencing f on some systems

* Allow longer program_name in addr2ine

* Fix casing issue with sounds

French Carmageddon provides DATA/SOUND/fyeah1.WAV where it expects DATA/SOUND/FYEAH1.WAV

* tools: add encode capability to decode script

* Replace font id integers with enum

* Result of BrFileGetLine is not used

* Document the StripControls fix

Co-authored-by: Dethrace Engineering Department <78985374+dethrace-labs@users.noreply.github.com>

---------

Co-authored-by: Dethrace Engineering Department <78985374+dethrace-labs@users.noreply.github.com>
  • Loading branch information
madebr and dethrace-labs committed May 28, 2024
1 parent e07b711 commit 62bbf66
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 106 deletions.
6 changes: 4 additions & 2 deletions src/BRSRC13/CORE/FW/datafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,17 @@ int TextReadLine(br_datafile* df, char** ident, char** data) {
LOG_TRACE9("(%p, %p, %p)", df, ident, data);

while (1) {
int a;
cp = BrScratchString();
int a = BrFileGetLine(cp, 256, df->h);
BrFileGetLine(cp, 256, df->h);
if (BrFileEof(df->h) != 0) {
return 0;
}
for (; (*cp == ' ') || (*cp == '\t'); cp++) {
}
if (*cp != '\0')
if (*cp != '\0') {
break;
}
}
*ident = cp;
while ((*cp != ' ') && (*cp != '\t') && (*cp != '\0')) {
Expand Down
2 changes: 1 addition & 1 deletion src/BRSRC13/CORE/MATH/matrix4.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ br_scalar BrMatrix4Inverse(br_matrix4* A, br_matrix4* B) {
if (fabs(det) < BR_SCALAR_EPSILON * 2)
return 0;

idet = 1.0 / det;
idet = 1.0f / det;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
A(i, j) = A(i, j) * idet;
Expand Down
2 changes: 1 addition & 1 deletion src/BRSRC13/CORE/PIXELMAP/pmdsptch.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ br_uint_16 BrPixelmapTextWidth(br_pixelmap* dst, br_font* font, char* text) {

if (font->flags & BR_FONTF_PROPORTIONAL) {
for (i = 0, w = 0, j = BrStrLen(text); i < j; i++, text++)
w += font->width[(int)*text] + 1;
w += font->width[*(br_uint_8*)text] + 1;
w -= 1;
return w;
} else
Expand Down
4 changes: 2 additions & 2 deletions src/BRSRC13/CORE/PIXELMAP/pmgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ br_error _M_br_device_pixelmap_gen_text(br_device_pixelmap* self, br_point* poin
}
} else {
while (*text != '\0') {
r.w = font->width[(int)*text];
r.w = font->width[*(br_uint_8*)text];
s_stride = (r.w + 7) / 8;
if (x + r.w > 0) {
self->dispatch->_copyBits(self, &p, &font->glyphs[font->encoding[(unsigned)*text]], s_stride, &r, colour);
self->dispatch->_copyBits(self, &p, &font->glyphs[font->encoding[*(br_uint_8*)text]], s_stride, &r, colour);
}
x += r.w + 1;
p.x += r.w + 1;
Expand Down
3 changes: 2 additions & 1 deletion src/BRSRC13/CORE/PIXELMAP/pmmemops.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ void pm_mem_copy_bits(br_uint_8* dst, br_uint_32 dst_qual, br_uint_32 dst_stride
colour_byte1 = colour;

for (; height != 0; height--, src += src_stride, dst += dst_stride) {
br_uint_8 row_end_bit_byte;
mask = *src & start_mask;
tmp_dst = dst;
tmp_src = src;
br_uint_8 row_end_bit_byte = end_bit_byte;
row_end_bit_byte = end_bit_byte;
while (row_end_bit_byte != 0) {
if (mask & 0x80) {
tmp_dst[0] = colour_byte1;
Expand Down
2 changes: 1 addition & 1 deletion src/BRSRC13/CORE/STD/brstdfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void BrStdioClose(void* f) {
}

int BrStdioEof(void* f) {
return feof(f);
return feof((FILE*)f);
}

int BrStdioGetChar(void* f) {
Expand Down
4 changes: 1 addition & 3 deletions src/BRSRC13/CORE/V1DB/prepmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ void CopyVertex(v11group* group, int v, prep_vertex* src, br_model* model) {

srcv = model->vertices + src->v;

group->vertices[v].p.v[0] = srcv->p.v[0] - model->pivot.v[0];
group->vertices[v].p.v[1] = srcv->p.v[1] - model->pivot.v[1];
group->vertices[v].p.v[2] = srcv->p.v[2] - model->pivot.v[2];
BrVector3Sub(&group->vertices[v].p, &srcv->p, &model->pivot);

group->vertices[v].map = srcv->map;

Expand Down
4 changes: 4 additions & 0 deletions src/BRSRC13/CORE/V1DB/v1dbfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ int FopWrite_VERTICES(br_datafile* df, br_vertex* vertices, int nvertices) {
df->prims->chunk_write(df, CHUNKID_MODEL_VERTICES, df->prims->struct_size(df, &br_vertex_F, NULL) * nvertices + df->prims->count_size(df));
df->prims->count_write(df, nvertices);
DfStructWriteArray(df, &br_vertex_F, vertices, nvertices);
return 0;
}

// IDA: int __usercall FopRead_VERTICES@<EAX>(br_datafile *df@<EAX>, br_uint_32 id@<EDX>, br_uint_32 length@<EBX>, br_uint_32 count@<ECX>)
Expand Down Expand Up @@ -389,6 +390,7 @@ int FopWrite_VERTEX_UV(br_datafile* df, br_vertex* vertices, int nvertices) {
df->prims->chunk_write(df, CHUNKID_MODEL_VERTEX_UV, df->prims->struct_size(df, &br_vertex_uv_F, NULL) * nvertices + df->prims->count_size(df));
df->prims->count_write(df, nvertices);
DfStructWriteArray(df, &br_vertex_uv_F, vertices, nvertices);
return 0;
}

// IDA: int __usercall FopRead_VERTEX_UV@<EAX>(br_datafile *df@<EAX>, br_uint_32 id@<EDX>, br_uint_32 length@<EBX>, br_uint_32 count@<ECX>)
Expand All @@ -413,6 +415,7 @@ int FopRead_OLD_VERTICES_UV(br_datafile* df, br_uint_32 id, br_uint_32 length, b
ptr = BrResAllocate(v1db.res, count * sizeof(br_vertex), BR_MEMORY_VERTICES);
DfStructReadArray(df, &br_old_vertex_uv_F, ptr, count);
DfPush(DF_VERTEX, ptr, count);
return 0;
}

// IDA: int __usercall FopRead_MATERIAL_INDEX@<EAX>(br_datafile *df@<EAX>, br_uint_32 id@<EDX>, br_uint_32 length@<EBX>, br_uint_32 count@<ECX>)
Expand Down Expand Up @@ -447,6 +450,7 @@ int FopWrite_MATERIAL_INDEX(br_datafile* df, br_material** materials, int nmater
for (i = 0; i < nmaterials; i++) {
df->prims->name_write(df, materials[i]->identifier);
}
return 0;
}

// IDA: int __usercall FopRead_OLD_MATERIAL_INDEX@<EAX>(br_datafile *df@<EAX>, br_uint_32 id@<EDX>, br_uint_32 length@<EBX>, br_uint_32 count@<ECX>)
Expand Down
4 changes: 2 additions & 2 deletions src/BRSRC13/include/brender/br_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ typedef struct br_renderer_dispatch {
br_error (*_stateStoredAvail)(br_renderer*, br_int_32*, br_uint_32, br_token_value*);
br_error (*_bufferStoredNew)(br_renderer*, br_buffer_stored**, br_token, br_device_pixelmap*, br_token_value*);
br_error (*_bufferStoredAvail)(br_renderer*, br_int_32*, br_token, br_token_value*);
br_error (*_partSet)(br_renderer*, br_token, br_int_32, br_token, br_uint_32);
br_error (*_partSet)(br_renderer*, br_token, br_int_32, br_token, uintptr_t);
br_error (*_partSetMany)(br_renderer*, br_token, br_int_32, br_token_value*, br_int_32*);
br_error (*_partQuery)(br_renderer*, br_token, br_int_32, br_uint_32*, br_token);
br_error (*_partQueryBuffer)(br_renderer*, br_token, br_int_32, br_uint_32*, br_uint_32*, br_size_t, br_token);
Expand Down Expand Up @@ -2261,7 +2261,7 @@ typedef struct br_primitive_state_dispatch {
br_error (*_queryManySize)(br_object*, br_size_t*, br_token_value*);
br_error (*_queryAll)(br_object*, br_token_value*, br_size_t);
br_error (*_queryAllSize)(br_object*, br_size_t*);
br_error (*_partSet)(br_primitive_state*, br_token, br_int_32, br_token, br_uint_32);
br_error (*_partSet)(br_primitive_state*, br_token, br_int_32, br_token, uintptr_t);
br_error (*_partSetMany)(br_primitive_state*, br_token, br_int_32, br_token_value*, br_int_32*);
br_error (*_partQuery)(br_primitive_state*, br_token, br_int_32, br_uint_32*, br_token);
br_error (*_partQueryBuffer)(br_primitive_state*, br_token, br_int_32, br_uint_32*, br_uint_32*, br_size_t, br_token);
Expand Down
14 changes: 7 additions & 7 deletions src/DETHRACE/common/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,13 +2445,13 @@ void DrawSomeText2(tDR_font* pFont) {

// IDA: void __cdecl DrawSomeText()
void DrawSomeText(void) {
DrawSomeText2(&gFonts[1]);
DrawSomeText2(&gFonts[2]);
DrawSomeText2(&gFonts[3]);
DrawSomeText2(&gFonts[4]);
DrawSomeText2(&gFonts[6]);
DrawSomeText2(&gFonts[7]);
DrawSomeText2(&gFonts[8]);
DrawSomeText2(&gFonts[kFont_ORANGHED]);
DrawSomeText2(&gFonts[kFont_BLUEHEAD]);
DrawSomeText2(&gFonts[kFont_GREENHED]);
DrawSomeText2(&gFonts[kFont_MEDIUMHD]);
DrawSomeText2(&gFonts[kFont_NEWHITE]);
DrawSomeText2(&gFonts[kFont_NEWRED]);
DrawSomeText2(&gFonts[kFont_NEWBIGGR]);
}

// IDA: void __cdecl SaySorryYouLittleBastard()
Expand Down
56 changes: 28 additions & 28 deletions src/DETHRACE/common/flicplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,34 +2025,34 @@ void LoadInterfaceStrings(void) {
gTranslations[i].text = BrMemAllocate(strlen(str) + 1, kMem_translations_text);
strcpy(gTranslations[i].text, str);
}
LoadFont(2);
LoadFont(1);
LoadFont(3);
LoadFont(15);
LoadFont(14);
LoadFont(16);
LoadFont(13);
LoadFont(10);
LoadFont(12);
LoadFont(9);
LoadFont(11);
LoadFont(19);
LoadFont(18);
LoadFont(20);
LoadFont(17);
gTrans_fonts[0] = &gFonts[1];
gTrans_fonts[1] = &gFonts[15];
gTrans_fonts[2] = &gFonts[14];
gTrans_fonts[3] = &gFonts[16];
gTrans_fonts[4] = &gFonts[13];
gTrans_fonts[5] = &gFonts[10];
gTrans_fonts[6] = &gFonts[12];
gTrans_fonts[7] = &gFonts[9];
gTrans_fonts[8] = &gFonts[11];
gTrans_fonts[9] = &gFonts[19];
gTrans_fonts[10] = &gFonts[20];
gTrans_fonts[11] = &gFonts[18];
gTrans_fonts[12] = &gFonts[17];
LoadFont(kFont_BLUEHEAD);
LoadFont(kFont_ORANGHED);
LoadFont(kFont_GREENHED);
LoadFont(kFont_LITPLAQ);
LoadFont(kFont_BUTTOUT);
LoadFont(kFont_DRKPLAQ);
LoadFont(kFont_BUTTIN);
LoadFont(kFont_GRNLIT);
LoadFont(kFont_GRYLIT);
LoadFont(kFont_GRNDK);
LoadFont(kFont_GRYDK);
LoadFont(kFont_LITPLAQ1);
LoadFont(kFont_BUTTOUT1);
LoadFont(kFont_DRKPLAQ1);
LoadFont(kFont_BUTTIN1);
gTrans_fonts[0] = &gFonts[kFont_ORANGHED];
gTrans_fonts[1] = &gFonts[kFont_LITPLAQ];
gTrans_fonts[2] = &gFonts[kFont_BUTTOUT];
gTrans_fonts[3] = &gFonts[kFont_DRKPLAQ];
gTrans_fonts[4] = &gFonts[kFont_BUTTIN];
gTrans_fonts[5] = &gFonts[kFont_GRNLIT];
gTrans_fonts[6] = &gFonts[kFont_GRYLIT];
gTrans_fonts[7] = &gFonts[kFont_GRNDK];
gTrans_fonts[8] = &gFonts[kFont_GRYDK];
gTrans_fonts[9] = &gFonts[kFont_LITPLAQ1];
gTrans_fonts[10] = &gFonts[kFont_DRKPLAQ1];
gTrans_fonts[11] = &gFonts[kFont_BUTTOUT1];
gTrans_fonts[12] = &gFonts[kFont_BUTTIN1];

#ifdef DETHRACE_FIX_BUGS
fclose(f);
Expand Down
4 changes: 2 additions & 2 deletions src/DETHRACE/common/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,13 +1725,13 @@ void RenderAFrame(int pDepth_mask_on) {
map_timer_x - gCurrent_graf_data->map_timer_border_x,
gCurrent_graf_data->map_timer_text_y - gCurrent_graf_data->map_timer_border_y,
map_timer_width + 2 * gCurrent_graf_data->map_timer_border_x,
gFonts[2].height + 2 * gCurrent_graf_data->map_timer_border_y,
gFonts[kFont_BLUEHEAD].height + 2 * gCurrent_graf_data->map_timer_border_y,
0);
TransDRPixelmapText(
gBack_screen,
map_timer_x,
gCurrent_graf_data->map_timer_text_y,
&gFonts[2],
&gFonts[kFont_BLUEHEAD],
the_text,
gBack_screen->width);
}
Expand Down
16 changes: 8 additions & 8 deletions src/DETHRACE/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,16 @@ void InitRace(void) {
FlushInterfaceFonts();
}
} else {
LoadFont(1);
LoadFont(2);
LoadFont(3);
LoadFont(kFont_ORANGHED);
LoadFont(kFont_BLUEHEAD);
LoadFont(kFont_GREENHED);
}
LoadFont(4);
LoadFont(5);
LoadFont(kFont_MEDIUMHD);
LoadFont(kFont_TIMER);
PossibleService();
LoadFont(6);
LoadFont(7);
LoadFont(8);
LoadFont(kFont_NEWHITE);
LoadFont(kFont_NEWRED);
LoadFont(kFont_NEWBIGGR);
PossibleService();
ResetRecoveryVouchers();
gMap_mode = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/common/loadsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void DoSaveGame(int pSave_allowed) {
gProgram_state.saving = 1;
gSave_allowed = pSave_allowed;
LoadSavedGames();
LoadFont(0);
LoadFont(kFont_TYPEABLE);
if (!pSave_allowed && !ConfirmMidGameSave()) {
gProgram_state.saving = 0;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/common/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ void NetFullScreenMessage(int pStr_index, int pLeave_it_up_there) {
s,
gBack_screen,
0,
gGraf_specs[gGraf_spec_index].total_height / 2 - gFonts[4].height,
gGraf_specs[gGraf_spec_index].total_height / 2 - gFonts[kFont_MEDIUMHD].height,
gGraf_specs[gGraf_spec_index].total_width,
gGraf_specs[gGraf_spec_index].total_height,
1);
Expand Down
26 changes: 13 additions & 13 deletions src/DETHRACE/common/newgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ void DrawColumnHeading__newgame(int pStr_index, int pX) {
TransDRPixelmapText(gBack_screen,
pX,
gCurrent_graf_data->joinable_games_y - gCurrent_graf_data->joinable_games_y_pitch,
&gFonts[12],
&gFonts[kFont_GRYLIT],
GetMiscString(pStr_index),
pX + DRTextWidth(&gFonts[12], GetMiscString(pStr_index)));
pX + DRTextWidth(&gFonts[kFont_GRYLIT], GetMiscString(pStr_index)));
}

// IDA: void __usercall DrawGames(int pCurrent_choice@<EAX>, int pCurrent_mode@<EDX>)
Expand Down Expand Up @@ -529,9 +529,9 @@ void DrawGames(int pCurrent_choice, int pCurrent_mode) {
DrawColumnHeading__newgame(kMiscString_NetworkGamesTableHeading_STATUS, gCurrent_graf_data->joinable_games_x_4);
BrPixelmapLine(gBack_screen,
gCurrent_graf_data->joinable_games_sel_left,
gCurrent_graf_data->joinable_games_y + gFonts[12].height + 1 - (TranslationMode() ? 2 : 0) - gCurrent_graf_data->joinable_games_y_pitch,
gCurrent_graf_data->joinable_games_y + gFonts[kFont_GRYLIT].height + 1 - (TranslationMode() ? 2 : 0) - gCurrent_graf_data->joinable_games_y_pitch,
gCurrent_graf_data->joinable_games_sel_right - 1,
gCurrent_graf_data->joinable_games_y + gFonts[12].height + 1 - (TranslationMode() ? 2 : 0) - gCurrent_graf_data->joinable_games_y_pitch,
gCurrent_graf_data->joinable_games_y + gFonts[kFont_GRYLIT].height + 1 - (TranslationMode() ? 2 : 0) - gCurrent_graf_data->joinable_games_y_pitch,
6);
for (i = 0; i < COUNT_OF(gGames_to_join); i++) {
if (gGames_to_join[i].game == NULL) {
Expand Down Expand Up @@ -788,10 +788,10 @@ tJoin_or_host_result JoinOrHostGame(tNet_game_details** pGame_to_join) {
LOG_TRACE("(%p)", pGame_to_join);

gCurrent_game_selection = 0;
LoadFont(9);
LoadFont(10);
LoadFont(3);
LoadFont(12);
LoadFont(kFont_GRNDK);
LoadFont(kFont_GRNLIT);
LoadFont(kFont_GREENHED);
LoadFont(kFont_GRYLIT);
SetAlwaysTyping();
InitGamesToJoin();
NetStartProducingJoinList(AddToJoinList);
Expand Down Expand Up @@ -1258,7 +1258,7 @@ void DoNetOptions(tNet_game_options* pGame_options) {

gThe_interface_spec__newgame = &interface_spec;
gRadio_selected = -1;
LoadFont(12);
LoadFont(kFont_GRYLIT);
SetNetOptions(pGame_options);
if (DoInterfaceScreen(&interface_spec, 0, 0) == 0) {
GetNetOptions(pGame_options);
Expand Down Expand Up @@ -1391,12 +1391,12 @@ void DrawNetChoose(int pCurrent_choice, int pCurrent_mode) {
gCurrent_graf_data->net_descr_race_l,
gCurrent_graf_data->net_choose_race_y,
gCurrent_graf_data->net_descr_race_r - gCurrent_graf_data->net_descr_race_l,
gFonts[10].height + 1 - (TranslationMode() ? 2 : 0), 0);
gFonts[kFont_GRNLIT].height + 1 - (TranslationMode() ? 2 : 0), 0);
sprintf(s, "%s %s", GetMiscString(kMiscString_FIRST_RACE), gRace_list[gRace_index].name);
DRPixelmapCentredText(gBack_screen,
gCurrent_graf_data->net_choose_race_x,
gCurrent_graf_data->net_choose_race_y,
&gFonts[10], s);
&gFonts[kFont_GRNLIT], s);
BrPixelmapRectangleFill(gBack_screen,
gCurrent_graf_data->net_descr_race_l,
gCurrent_graf_data->net_descr_race_top - (TranslationMode() ? 2 : 0),
Expand Down Expand Up @@ -1526,8 +1526,8 @@ int NetGameChoices(tNet_game_type* pGame_type, tNet_game_options* pGame_options,
gRace_index = *pRace_index;
gLast_game_type = *pGame_type;
do {
LoadFont(10);
LoadFont(9);
LoadFont(kFont_GRNLIT);
LoadFont(kFont_GRNDK);
gThe_interface_spec__newgame = &interface_spec;
gLast_net_choose_box = -1;
gOptions = pGame_options;
Expand Down
Loading

0 comments on commit 62bbf66

Please sign in to comment.