Skip to content

Commit

Permalink
Implement network (#366)
Browse files Browse the repository at this point in the history
* SendCarData, ReceivedStartRace

* fixes heap overflow during join

* fixes access on possibly-null pDetails

* DoNetScores

* Fix cast warning of comparefn of qsort

* DisplayUserMessage

* Pack tNet_contents on 4 byte boundary so 32-bit and 64-bit Intel cpu get same struct lay-out

* Add a few static assertions to verify net message offsets

* Add dethrace Wireshark dissector (WIP)

* add dissector installation instructions

* Set wireshark info column

* Fix various typo's

* 4-byte align tNet_message_join as well + more dethrace.lua

* Add more assertions

* Fix network car choose loop

* player scores

* tidy

* mechanics

* Implement SortNetHeadAscending for 'Terminal Tag'

* Update WireShark dissector

* start of tNet_message_pedestrian dissector

* network player cars can see each other move

* netmsgid tidy ups

* dissector: print HOST/CLIENT in info column

* Don't allow hosting a game when starting dethrace with --no-bind

* fix oldd copy

* time_step is integer, fixes client car out of sync

* wasted, recover, kick player out

* NetSendPointCrush

* crushpoint, declarewinner

* network race summary wip

* Start and finish a game of tag/fox

* network fixes

* Players can now send love letters to each other

* Rewrite if's a bit

* Use enum values for GetMiscString and DoFancyHeadup

* Fix fox effect

* Fix fox/it effect at start of race

* Use KEYMAP_ enum values

* Disable address sanitizer and dr_dprintf logging

---------

Co-authored-by: Dethrace Labs <[email protected]>
  • Loading branch information
madebr and dethrace-labs authored Jun 20, 2024
1 parent 1d5f6f1 commit 673244b
Show file tree
Hide file tree
Showing 30 changed files with 3,145 additions and 198 deletions.
335 changes: 317 additions & 18 deletions src/DETHRACE/common/car.c

Large diffs are not rendered by default.

158 changes: 149 additions & 9 deletions src/DETHRACE/common/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,6 @@ void ConcussMe(void) {
// IDA: void __cdecl CheckHelp()
void CheckHelp(void) {
LOG_TRACE("()");
NOT_IMPLEMENTED();
}

// IDA: void __cdecl CheckLoadSave()
Expand Down Expand Up @@ -1283,7 +1282,27 @@ void CheckHornLocal(tCar_spec* pCar) {
// IDA: void __usercall CheckHorn3D(tCar_spec *pCar@<EAX>)
void CheckHorn3D(tCar_spec* pCar) {
LOG_TRACE("(%p)", pCar);
STUB_ONCE();

if (pCar->keys.horn && pCar->horn_sound_tag == 0) {
pCar->horn_sound_tag = DRS3StartSound3D(gEffects_outlet,
5209,
&pCar->car_master_actor->t.t.translate.t,
&pCar->velocity_bu_per_sec,
0,
255,
((pCar->car_ID & 7) << 12) + 0xc000,
0x10000);
} else {
if (!pCar->keys.horn && pCar->horn_sound_tag != 0) {
while (S3SoundStillPlaying(pCar->horn_sound_tag)) {
DRS3StopSound(pCar->horn_sound_tag);
DRS3StopOutletSound(gEffects_outlet);
}
if (!S3SoundStillPlaying(pCar->horn_sound_tag)) {
pCar->horn_sound_tag = 0;
}
}
}
}

// IDA: void __cdecl CheckHorns()
Expand Down Expand Up @@ -1378,14 +1397,14 @@ void CheckMapRenderMove(void) {
old_x = gMap_render_x;
if (gMap_mode) {
amount = gFrame_period * .1f;
if (KeyIsDown(30)) {
if (KeyIsDown(KEYMAP_MOVE_UP)) {
gMap_render_y -= amount;
} else if (KeyIsDown(31)) {
} else if (KeyIsDown(KEYMAP_MOVE_DOWN)) {
gMap_render_y += amount;
}
if (KeyIsDown(32)) {
if (KeyIsDown(KEYMAP_MOVE_LEFT)) {
gMap_render_x -= amount;
} else if (KeyIsDown(33)) {
} else if (KeyIsDown(KEYMAP_MOVE_RIGHT)) {
gMap_render_x += amount;
}
if (gMap_render_x != old_x || gMap_render_y != old_y) {
Expand Down Expand Up @@ -1731,7 +1750,7 @@ void FlipUpCar(tCar_spec* car) {
count = 0;
if (car->driver == eDriver_local_human && gNet_mode == eNet_mode_none) {
FadePaletteDown();
while (KeyIsDown(44)) {
while (KeyIsDown(KEYMAP_REPAIR)) {
;
}
}
Expand Down Expand Up @@ -2480,7 +2499,99 @@ void EnterUserMessage(void) {
int the_key;
int abuse_num;
LOG_TRACE("()");
STUB_ONCE();

if (!gEntering_message) {
return;
}
if (gNet_mode == eNet_mode_none) {
return;
}
if (!gCurrent_net_game->options.enable_text_messages) {
return;
}
the_key = PDAnyKeyDown();
if (gEntering_message == 1) {
if (the_key != -1) {
return;
}
gEntering_message = 2;
}
if (about_to_die) {
if (the_key != -1) {
return;
}
gEntering_message = 0;
about_to_die = 0;
return;
}
if (the_key == last_key) {
if (next_time < PDGetTotalTime()) {
next_time += 100;
} else {
the_key = -1;
}
} else {
last_key = the_key;
next_time = PDGetTotalTime() + 500;
}
switch (the_key) {
case -1:
case KEY_SHIFT_ANY:
break;
case KEY_CTRL_ANY:
case KEY_CTRL_ANY_2:
case KEY_TAB:
case KEY_ESCAPE:
about_to_die = 1;
break;
case KEY_BACKSPACE:
case KEY_DELETE:
case KEY_LEFT:
len = strlen(&gString[20]);
if (len > 0) {
gString[20 + len - 1] = '\0';
}
break;
case KEY_RETURN:
case KEY_KP_ENTER:
len = strlen(gNet_players[gThis_net_player_index].player_name);
if (len <= 18) {
the_message = gString + 18 - len;
strcpy(the_message, gNet_players[gThis_net_player_index].player_name);
the_message[len + 0] = ':';
the_message[len + 1] = ' ';
gString[COUNT_OF(gString) - 1] = '\0';
NetSendHeadupToAllPlayers(the_message);
gString[20] = '\0';
NewTextHeadupSlot(4, 0, 1000, -4, GetMiscString(kMiscString_MESSAGE_SENT));
about_to_die = 1;
}
break;
default:
if (gKey_mapping[KEYMAP_SEND_MESSAGE] == the_key) {
about_to_die = 1;
} else if (the_key <= KEY_KP_NUMLOCK || the_key >= KEY_SPACE) {
len = strlen(&gString[20]);
if (len < 64 - 1) {
gString[20 + len] = PDGetASCIIFromKey(the_key);
if (gString[20 + len] < gFonts[4].offset || gString[20 + len] >= gFonts[4].offset + gFonts[4].num_entries) {
gString[20 + len] = '\0';
}
gString[20 + len + 1] = '\0';
}
} else if (the_key < KEY_KP_0 || the_key > KEY_KP_9) {
gEntering_message = 0;
} else {
if (the_key == KEY_KP_0) {
abuse_num = 9;
} else {
abuse_num = the_key - KEY_KP_1;
}
if (gAbuse_text[abuse_num] != NULL) {
strcpy(&gString[20], gAbuse_text[abuse_num]);
}
}
}
}

// IDA: void __cdecl DisplayUserMessage()
Expand All @@ -2489,7 +2600,36 @@ void DisplayUserMessage(void) {
int len;
tDR_font* font;
LOG_TRACE("()");
NOT_IMPLEMENTED();

font = &gFonts[FONT_NEWHITE];
the_message = &gString[20];
if (!gEntering_message || gNet_mode == eNet_mode_none) {
return;
}

len = strlen(the_message);
if (len < 63 && (PDGetTotalTime() & 512) != 0) {
the_message[len] = '_';
the_message[len + 1] = '\0';
}
DimRectangle(gBack_screen,
15 * gBack_screen->width / 100,
gCurrent_graf_data->net_message_enter_y - font->height,
85 * gBack_screen->width / 100,
gCurrent_graf_data->net_message_enter_y + 6 * font->height,
1);

TransDRPixelmapText(gBack_screen, 20 * gBack_screen->width / 100, gCurrent_graf_data->net_message_enter_y, font, GetMiscString(kMiscString_ENTER_MESSAGE), 100);
OoerrIveGotTextInMeBoxMissus(
FONT_NEWHITE,
the_message,
gBack_screen,
20 * gBack_screen->width / 100,
gCurrent_graf_data->net_message_enter_y + 2 * font->height,
80 * gBack_screen->width / 100,
gCurrent_graf_data->net_message_enter_y + 6 * font->height,
0);
the_message[len] = 0;
}

// IDA: void __cdecl InitAbuseomatic()
Expand Down
32 changes: 27 additions & 5 deletions src/DETHRACE/common/crush.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,29 @@ void DoPratcamHit(br_vector3* pHit_vector) {
br_scalar strength;
LOG_TRACE("(%p)", pHit_vector);

STUB_ONCE();
strength = BrVector3LengthSquared(pHit_vector);
if (strength > 0.2f) {
strength_modifier = 8;
} else if (strength > 0.015f) {
strength_modifier = 4;
} else if (strength >= 0.001f) {
strength_modifier = 0;
} else {
return;
}
if (fabsf(pHit_vector->v[2]) >= fabsf(pHit_vector->v[0])) {
if (pHit_vector->v[2] >= 0.f) {
PratcamEvent(14 + strength_modifier);
} else {
PratcamEvent(13 + strength_modifier);
}
} else {
if (pHit_vector->v[0] >= 0.f) {
PratcamEvent(15 + strength_modifier);
} else {
PratcamEvent(16 + strength_modifier);
}
}
}

// IDA: void __usercall DamageSystems(tCar_spec *pCar@<EAX>, br_vector3 *pImpact_point@<EDX>, br_vector3 *pEnergy_vector@<EBX>, int pWas_hitting_a_car@<ECX>)
Expand Down Expand Up @@ -1153,7 +1175,7 @@ int DoCrashEarnings(tCar_spec* pCar1, tCar_spec* pCar2) {
NetEarnCredits(NetPlayerFromCar(culprit), credits);
} else {
PratcamEvent(32);
DoFancyHeadup(11);
DoFancyHeadup(kFancyHeadupYouWastedEm);
credits_squared = sqr(0.7f / victim->car_model_actors[victim->principal_car_actor].crush_data.softness_factor) * gWasted_creds[gProgram_state.skill_level] + 50.0f;
credits = 100 * (int)(credits_squared / 100.0);
AwardTime(gWasted_time[gProgram_state.skill_level]);
Expand Down Expand Up @@ -1218,13 +1240,13 @@ int DoCrashEarnings(tCar_spec* pCar1, tCar_spec* pCar2) {
AwardTime(MIN(time, 90));
if (pCar2) {
if (head_on) {
DoFancyHeadup(10);
DoFancyHeadup(kFancyHeadupHeadOnBonus);
} else if (bonus_level <= 2) {
if (bonus_level > 1) {
DoFancyHeadup(2);
DoFancyHeadup(kFancyHeadupExtraStyleBonus);
}
} else {
DoFancyHeadup(3);
DoFancyHeadup(kFancyHeadupBonusForArtisticImpression);
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/DETHRACE/common/depth.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,15 @@ void ToggleSkyQuietly(void) {
// IDA: void __cdecl ToggleSky()
void ToggleSky(void) {
LOG_TRACE("()");
NOT_IMPLEMENTED();

SetSkyTextureOn(!GetSkyTextureOn());
if (gProgram_state.current_depth_effect.sky_texture != NULL) {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_SkyTextureOn));
} else if (gSwap_sky_texture != NULL) {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_SkyTextureOff));
} else {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_ThereIsNoSkyTextureForThisRace));
}
}

// IDA: int __cdecl GetDepthCueingOn()
Expand Down Expand Up @@ -962,7 +970,15 @@ void ToggleDepthCueingQuietly(void) {
// IDA: void __cdecl ToggleDepthCueing()
void ToggleDepthCueing(void) {
LOG_TRACE("()");
NOT_IMPLEMENTED();

SetDepthCueingOn(!GetDepthCueingOn());
if (gProgram_state.current_depth_effect.type != eDepth_effect_none) {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_DepthCueingOn));
} else if (gSwap_depth_effect_type != eDepth_effect_none) {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_DepthCueingOff));
} else {
NewTextHeadupSlot(4, 0, 2000, -4, GetMiscString(kMiscString_ThereIsNoDepthCueingForThisRace));
}
}

// IDA: void __cdecl ChangeDepthEffect()
Expand All @@ -976,7 +992,11 @@ void ChangeDepthEffect(void) {
br_scalar distance;
tSpecial_volume* special_volume;
LOG_TRACE("()");
STUB_ONCE();

gProgram_state.current_depth_effect.type = gProgram_state.default_depth_effect.type;
gProgram_state.current_depth_effect.sky_texture = gProgram_state.default_depth_effect.sky_texture;
gProgram_state.current_depth_effect.start = gProgram_state.default_depth_effect.start;
gProgram_state.current_depth_effect.end = gProgram_state.default_depth_effect.end;
}

// IDA: void __cdecl MungeForwardSky()
Expand Down
8 changes: 7 additions & 1 deletion src/DETHRACE/common/displays.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,13 @@ void MoveHeadupTo(int pHeadup_index, int pNew_x, int pNew_y) {
int delta_x;
tHeadup* the_headup;
LOG_TRACE("(%d, %d, %d)", pHeadup_index, pNew_x, pNew_y);
NOT_IMPLEMENTED();

if (pHeadup_index >= 0) {
delta_x = gHeadups[pHeadup_index].x - gHeadups[pHeadup_index].original_x;
gHeadups[pHeadup_index].original_x = pNew_x;
gHeadups[pHeadup_index].x = pNew_x + delta_x;
gHeadups[pHeadup_index].y = pNew_y;
}
}

// IDA: void __usercall ChangeHeadupText(int pHeadup_index@<EAX>, char *pNew_text@<EDX>)
Expand Down
Loading

0 comments on commit 673244b

Please sign in to comment.