Skip to content

Commit 1c10b74

Browse files
Networking #1 - Lobby implemented (#335)
* Basic networking functions implemented to get the lobby functional * Apply suggestions from code review * PDNetObtainSystemUserName gets local system name --------- Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
1 parent 7d475fc commit 1c10b74

34 files changed

+4199
-1176
lines changed

.github/scripts/build-msvc.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$ErrorActionPreference = "Stop"
2+
13
if ($($Env:PLATFORM_ARCH) -eq "x86") {
24
$sdl_path = "x86"
35
} else {
@@ -18,7 +20,13 @@ Expand-Archive $Env:TEMP\SDL2-devel.zip -DestinationPath $Env:TEMP
1820

1921
# build
2022
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON "-DSDL2_ROOT_DIR=$($Env:TEMP)\SDL2-$sdl2_version" -B build
23+
if ($LASTEXITCODE -ne 0) {
24+
Exit $LASTEXITCODE
25+
}
2126
cmake --build build --config RelWithDebInfo
27+
if ($LASTEXITCODE -ne 0) {
28+
Exit $LASTEXITCODE
29+
}
2230

2331
# copy SDL2.dll to build folder, so tests can run
2432
cp $Env:TEMP\SDL2-$sdl2_version\lib\$sdl_path\SDL2.dll build

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ endfunction()
4848

4949
test_big_endian(IS_BIGENDIAN)
5050

51-
find_package(SDL2 REQUIRED)
51+
find_package(SDL2 CONFIG)
52+
if(NOT SDL2_FOUND)
53+
find_package(SDL2 MODULE REQUIRED)
54+
endif()
5255

5356
add_subdirectory(lib/libsmacker)
5457
add_subdirectory(lib/glad)

src/DETHRACE/CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ target_include_directories(dethrace_obj
1010
pd
1111
)
1212

13+
# add_compile_options(-fsanitize=address)
14+
# add_link_options(-fsanitize=address)
15+
1316
target_link_libraries(dethrace_obj PUBLIC SDL2::SDL2 smackw32 harness brender s3)
1417

1518

@@ -35,6 +38,7 @@ else()
3538
-Wstrict-prototypes
3639
)
3740
endif()
41+
target_compile_definitions(dethrace_obj PRIVATE INSIDE_DETHRACE)
3842
if(DETHRACE_FIX_BUGS)
3943
target_compile_definitions(dethrace_obj PRIVATE DETHRACE_FIX_BUGS)
4044
endif()
@@ -154,14 +158,15 @@ target_sources(dethrace_obj PRIVATE
154158
common/world.h
155159
constants.h
156160
dr_types.h
157-
pc-dos/dosnet.c
158161
pd/net.h
159-
pc-dos/dossys.c
160162
pd/sys.h
161163
pc-win95/win95sys.c
162164
pc-win95/dinput.h
163165
pc-win95/ssdx.c
164166
pc-win95/ssdx.h
167+
pc-win95/win95net.c
168+
pc-dos/dosnet.c
169+
pc-dos/dossys.c
165170
)
166171

167172
# Create our main game binary.
@@ -184,7 +189,7 @@ if(NOT MSVC)
184189
else()
185190
target_link_libraries(dethrace PRIVATE dbghelp)
186191
target_link_options(dethrace PRIVATE /subsystem:windows /ENTRY:mainCRTStartup)
187-
target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED)
192+
target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED -DWIN32_LEAN_AND_MEAN)
188193
endif()
189194

190195
if(DETHRACE_IDE_ROOT_DIR)

src/DETHRACE/common/car.c

+39-15
Original file line numberDiff line numberDiff line change
@@ -494,44 +494,68 @@ void SetInitialPosition(tRace_info* pThe_race, int pCar_index, int pGrid_index)
494494
car = pThe_race->opponent_list[pCar_index].car_spec;
495495
BrMatrix34Identity(&car_actor->t.t.mat);
496496
place_on_grid = 1;
497-
if (gNet_mode && !gCurrent_net_game->options.grid_start && pThe_race->number_of_net_start_points) {
498-
TELL_ME_IF_WE_PASS_THIS_WAY();
497+
if (gNet_mode != eNet_mode_none && !gCurrent_net_game->options.grid_start && pThe_race->number_of_net_start_points != 0) {
498+
start_i = i = IRandomBetween(0, pThe_race->number_of_net_start_points - 1);
499+
do {
500+
PossibleService();
501+
for (j = 0; j < gNumber_of_net_players; j++) {
502+
if (j != pCar_index) {
503+
BrVector3Copy(&real_pos, &pThe_race->opponent_list[j].car_spec->car_master_actor->t.t.translate.t);
504+
if (real_pos.v[0] > 500.f) {
505+
real_pos.v[0] -= 1000.f;
506+
real_pos.v[1] -= 1000.f;
507+
real_pos.v[2] -= 1000.f;
508+
}
509+
BrVector3Sub(&dist, &real_pos, &pThe_race->net_starts[i].pos);
510+
if (BrVector3LengthSquared(&dist) < 16.f) {
511+
break;
512+
}
513+
}
514+
}
515+
if (j == gNumber_of_net_players) {
516+
BrVector3Copy(&car_actor->t.t.translate.t, &pThe_race->net_starts[i].pos);
517+
initial_yaw = BrDegreeToAngle(pThe_race->net_starts[i].yaw);
518+
place_on_grid = 0;
519+
}
520+
i++;
521+
if (i == pThe_race->number_of_net_start_points) {
522+
i = 0;
523+
}
524+
} while (start_i != i);
499525
}
500526
if (place_on_grid) {
501-
initial_yaw = (pThe_race->initial_yaw * 182.0444444444445);
527+
initial_yaw = BrDegreeToAngle(pThe_race->initial_yaw);
502528
BrMatrix34RotateY(&initial_yaw_matrix, initial_yaw);
503-
grid_offset.v[0] = 0.0 - pGrid_index % 2;
504-
grid_offset.v[1] = 0.0;
505-
grid_offset.v[2] = (double)(pGrid_index / 2) * 2.0 + (double)(pGrid_index % 2) * 0.40000001;
529+
grid_offset.v[0] = 0.0f - pGrid_index % 2;
530+
grid_offset.v[1] = 0.0f;
531+
grid_offset.v[2] = (br_scalar)(pGrid_index / 2) * 2.0f + (br_scalar)(pGrid_index % 2) * 0.4f;
506532
BrMatrix34ApplyV(&car_actor->t.t.translate.t, &grid_offset, &initial_yaw_matrix);
507533
BrVector3Accumulate(&car_actor->t.t.translate.t, &pThe_race->initial_position);
508534
}
509535
FindBestY(
510536
&car_actor->t.t.translate.t,
511537
gTrack_actor,
512-
10.0,
538+
10.0f,
513539
&nearest_y_above,
514540
&nearest_y_below,
515541
&above_model,
516542
&below_model,
517543
&above_face_index,
518544
&below_face_index);
519-
if (nearest_y_above == 30000.0) {
520-
if (nearest_y_below == -30000.0) {
521-
car_actor->t.t.translate.t.v[1] = 0.0;
522-
} else {
523-
car_actor->t.t.translate.t.v[1] = nearest_y_below;
524-
}
525-
} else {
545+
if (nearest_y_above != 30000.0f) {
526546
car_actor->t.t.translate.t.v[1] = nearest_y_above;
547+
} else if (nearest_y_below != -30000.0f) {
548+
car_actor->t.t.translate.t.v[1] = nearest_y_below;
549+
} else {
550+
car_actor->t.t.translate.t.v[1] = 0.0f;
527551
}
528552
BrMatrix34PreRotateY(&car_actor->t.t.mat, initial_yaw);
529553
if (gNet_mode) {
530554
BrMatrix34Copy(
531555
&gNet_players[pThe_race->opponent_list[pCar_index].net_player_index].initial_position,
532556
&car->car_master_actor->t.t.mat);
533557
}
534-
if (gNet_mode && car->disabled && car_actor->t.t.translate.t.v[0] < 500.0) {
558+
if (gNet_mode != eNet_mode_none && car->disabled && car_actor->t.t.translate.t.v[0] < 500.0f) {
535559
DisableCar(car);
536560
}
537561
// Enable to start all opponent cars upside down ;)

src/DETHRACE/common/controls.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,34 @@ void InitAbuseomatic(void) {
25002500
int i;
25012501
int len;
25022502
LOG_TRACE("()");
2503-
NOT_IMPLEMENTED();
2503+
2504+
gString[20] = '\0';
2505+
PDBuildAppPath(path);
2506+
strcat(path, "ABUSE.TXT");
2507+
for (i = 0; i < COUNT_OF(gAbuse_text); i++) {
2508+
gAbuse_text[i] = NULL;
2509+
}
2510+
f = fopen(path, "rt");
2511+
if (f == NULL) {
2512+
return;
2513+
}
2514+
for (i = 0; i < COUNT_OF(gAbuse_text); i++) {
2515+
if (fgets(s, COUNT_OF(s) - 1, f) == NULL) {
2516+
break;
2517+
}
2518+
len = strlen(s);
2519+
if (len > 63) {
2520+
s[63] = '\0';
2521+
}
2522+
len = strlen(s);
2523+
while (len != 0 && s[len - 1] < ' ') {
2524+
s[len - 1] = '\0';
2525+
len--;
2526+
}
2527+
gAbuse_text[i] = BrMemAllocate(strlen(s) + 1, kMem_abuse_text);
2528+
strcpy(gAbuse_text[i], s);
2529+
}
2530+
fclose(f);
25042531
}
25052532

25062533
// IDA: void __cdecl DisposeAbuseomatic()

src/DETHRACE/common/errors.c

+10
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ void dr_dprintf(char* fmt_string, ...) {
242242
return;
243243
}
244244

245+
if (gDiagnostic_file == NULL) {
246+
return;
247+
}
248+
245249
if (first_time == 0) {
246250
first_time = GetTotalTime();
247251
}
@@ -254,6 +258,12 @@ void dr_dprintf(char* fmt_string, ...) {
254258
va_end(args);
255259
fputs("\n", gDiagnostic_file);
256260
fflush(gDiagnostic_file);
261+
262+
// Added by dethrace for debugging
263+
// va_start(args, fmt_string);
264+
// vprintf(fmt_string, args);
265+
// va_end(args);
266+
// printf("\n");
257267
}
258268

259269
// IDA: int __usercall DoErrorInterface@<EAX>(int pMisc_text_index@<EAX>)

src/DETHRACE/common/init.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ void InitGame(int pStart_race) {
425425

426426
gWaiting_for_unpause = 1;
427427
gWait_for_it = 1;
428-
if (gNet_mode) {
428+
if (gNet_mode != eNet_mode_none) {
429429
gCredit_period = gCredit_period_network[gCurrent_net_game->type];
430430
} else {
431431
gCredit_period = gCredit_period_single[gProgram_state.skill_level];
@@ -448,10 +448,10 @@ void InitGame(int pStart_race) {
448448
gProgram_state.current_car.power_up_levels[i] = 0;
449449
}
450450
}
451-
for (i = 0; gNumber_of_races > i; ++i) {
451+
for (i = 0; i < gNumber_of_races; i++) {
452452
gRace_list[i].been_there_done_that = 0;
453453
}
454-
for (i = 0; gNumber_of_racers > i; ++i) {
454+
for (i = 0; i < gNumber_of_racers; i++) {
455455
gOpponents[i].dead = 0;
456456
}
457457
gProgram_state.rank = gInitial_rank;
@@ -470,7 +470,7 @@ void DisposeGameIfNecessary(void) {
470470
int i;
471471
LOG_TRACE("()");
472472

473-
if (gNet_mode) {
473+
if (gNet_mode != eNet_mode_none) {
474474
NetLeaveGame(gCurrent_net_game);
475475
}
476476
if (gGame_initialized) {

src/DETHRACE/common/intrface.c

+20-24
Original file line numberDiff line numberDiff line change
@@ -511,33 +511,29 @@ int DoInterfaceScreen(tInterface_spec* pSpec, int pOptions, int pCurrent_choice)
511511
} else {
512512
result = gCurrent_choice;
513513
}
514-
if (!go_ahead) {
515-
if (!escaped) {
516-
if (pSpec->end_flic_otherwise > 0) {
517-
DRS3StartSound(gEffects_outlet, 3007);
518-
RunFlic(pSpec->end_flic_otherwise);
519-
} else if (pSpec->end_flic_otherwise < 0) {
520-
FadePaletteDown();
521-
}
522-
goto LABEL_230;
523-
} else {
524-
if (pSpec->end_flic_escaped > 0) {
525-
DRS3StartSound(gEffects_outlet, 3007);
526-
RunFlic(pSpec->end_flic_escaped);
527-
} else if (pSpec->end_flic_escaped < 0) {
528-
FadePaletteDown();
529-
}
530-
goto LABEL_230;
514+
if (go_ahead) {
515+
if (pSpec->end_flic_go_ahead > 0) {
516+
DRS3StartSound(gIndexed_outlets[0], 3007);
517+
RunFlic(pSpec->end_flic_go_ahead);
518+
} else if (pSpec->end_flic_go_ahead < 0) {
519+
FadePaletteDown();
520+
}
521+
} else if (escaped) {
522+
if (pSpec->end_flic_escaped > 0) {
523+
DRS3StartSound(gIndexed_outlets[0], 3007);
524+
RunFlic(pSpec->end_flic_escaped);
525+
} else if (pSpec->end_flic_escaped < 0) {
526+
FadePaletteDown();
527+
}
528+
} else {
529+
if (pSpec->end_flic_otherwise > 0) {
530+
DRS3StartSound(gIndexed_outlets[0], 3007);
531+
RunFlic(pSpec->end_flic_otherwise);
532+
} else if (pSpec->end_flic_otherwise < 0) {
533+
FadePaletteDown();
531534
}
532-
}
533-
if (pSpec->end_flic_go_ahead > 0) {
534-
DRS3StartSound(gEffects_outlet, 3007);
535-
RunFlic(pSpec->end_flic_go_ahead);
536-
} else if (pSpec->end_flic_go_ahead < 0) {
537-
FadePaletteDown();
538535
}
539536

540-
LABEL_230:
541537
gProgram_state.dont_save_or_load = 0;
542538
EndMouseCursor();
543539
UnlockInterfaceStuff();

src/DETHRACE/common/loading.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,12 @@ int OriginalCarmaCDinDrive(void) {
34113411
// IDA: int __cdecl CarmaCDinDriveOrFullGameInstalled()
34123412
int CarmaCDinDriveOrFullGameInstalled(void) {
34133413
LOG_TRACE("()");
3414-
NOT_IMPLEMENTED();
3414+
3415+
if (gCD_fully_installed) {
3416+
return 1;
3417+
} else {
3418+
return OriginalCarmaCDinDrive();
3419+
}
34153420
}
34163421

34173422
// IDA: void __usercall ReadNetworkSettings(FILE *pF@<EAX>, tNet_game_options *pOptions@<EDX>)

src/DETHRACE/common/mainmenu.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ int DoMainMenuInterface(tU32 pTime_out, int pContinue_allowed) {
323323
if (pContinue_allowed) {
324324
gMain_menu_spec = &interface_spec1;
325325
result = DoInterfaceScreen(&interface_spec1, gFaded_palette | 2, 0);
326-
if (result != 7 && result && result != 1 && result != 2) {
327-
RunFlic(12);
328-
} else {
326+
if (result == 0 || result == 1 || result == 2 || result == 7) {
329327
FadePaletteDown();
328+
} else {
329+
RunFlic(12);
330330
}
331331
switch (result) {
332332
case 0:
@@ -352,10 +352,10 @@ int DoMainMenuInterface(tU32 pTime_out, int pContinue_allowed) {
352352
} else {
353353
interface_spec2.time_out = pTime_out;
354354
result = DoInterfaceScreen(&interface_spec2, gFaded_palette, 0);
355-
if (result != 4 && result != -1) {
356-
RunFlic(32);
357-
} else {
355+
if (result == -1 || result == 4) {
358356
FadePaletteDown();
357+
} else {
358+
RunFlic(32);
359359
}
360360
switch (result) {
361361
case 0:

0 commit comments

Comments
 (0)