From 955fadcbef8f04f5335935ecc9680114a41e6c5a Mon Sep 17 00:00:00 2001 From: Robin <99972691+KcRobin9@users.noreply.github.com> Date: Wed, 13 Aug 2025 04:52:12 +0200 Subject: [PATCH 1/5] Implement mmNetObject::Predict First draft. Not sure about the constant (name). The first `ARTSPTR->GetUpdateDelta()` could be put directly in the function call if you prefer. --- code/midtown/game.asm | 151 +----------------------------- code/midtown/mmgame/netobject.cpp | 40 +++++++- code/midtown/mmgame/netobject.h | 2 +- 3 files changed, 41 insertions(+), 152 deletions(-) diff --git a/code/midtown/game.asm b/code/midtown/game.asm index a1f20d3c..047c7d8c 100644 --- a/code/midtown/game.asm +++ b/code/midtown/game.asm @@ -56788,150 +56788,6 @@ loc_432F69: retn 4 ?PositionUpdate@mmNetObject@@QAEXPAUNETGAME_MSG@@@Z ENDP -ALIGN 16 -?Predict@mmNetObject@@QAEXXZ PROC PUBLIC - push ebp - mov ebp, esp - push ecx - push ebx - mov ebx, ecx - mov eax, dword ptr [ebx+90h] - test eax, eax - jz loc_43301B - mov eax, dword ptr [ebx+0BCh] - push edi - cmp eax, 42C80000h - push esi - jnz loc_432FC8 - mov edi, dword ptr [ebx+24h] - lea esi, [ebx+0C4h] - add edi, 20h - mov ecx, 0Ch - rep movsd - pop esi - mov dword ptr [ebx+90h], 0 - pop edi - pop ebx - mov esp, ebp - pop ebp - retn - -loc_432FC8: - fld dword ptr [ebx+0BCh] - fst dword ptr [ebp-4] - fcomp dword ptr [flt_61B114] - fnstsw ax - test ah, 41h - jnz loc_43300A - mov eax, dword ptr [?ARTSPTR@@3PAVasSimulation@@A] - mov edx, dword ptr [ebp-4] - push ecx - mov ecx, dword ptr [ebx+0C0h] - fld dword ptr [eax+13Ch] - fstp dword ptr [esp] - push ecx - mov ecx, dword ptr [ebx+24h] - lea eax, [ebx+0C4h] - push edx - push eax - add ecx, 20h - call ?Approach@Matrix34@@QAEHABV1@MMM@Z - -loc_43300A: - pop esi - mov dword ptr [ebx+90h], 0 - pop edi - pop ebx - mov esp, ebp - pop ebp - retn - -loc_43301B: - mov ecx, dword ptr [?ARTSPTR@@3PAVasSimulation@@A] - fld dword ptr [ebx+0B8h] - mov edx, dword ptr [ecx+13Ch] - mov dword ptr [ebp-4], edx - fmul dword ptr [ebp-4] - fadd dword ptr [ebx+0B4h] - fcom dword ptr [flt_61B114] - fnstsw ax - test ah, 41h - jz loc_433050 - fstp st - fld dword ptr [flt_61B114] - jmp loc_433065 - -loc_433050: - fcom dword ptr [flt_61B104] - fnstsw ax - test ah, 1 - jnz loc_433065 - fstp st - fld dword ptr [flt_61B104] - -loc_433065: - fld dword ptr [ebx+0A0h] - fmul dword ptr [ebp-4] - fadd dword ptr [ebx+9Ch] - fcom dword ptr [flt_61B114] - fnstsw ax - test ah, 41h - jz loc_43308B - fstp st - fld dword ptr [flt_61B114] - jmp loc_4330A0 - -loc_43308B: - fcom dword ptr [flt_61B118] - fnstsw ax - test ah, 1 - jnz loc_4330A0 - fstp st - fld dword ptr [flt_61B118] - -loc_4330A0: - fld dword ptr [ebx+0ACh] - fmul dword ptr [ebp-4] - fadd dword ptr [ebx+0A8h] - fcom dword ptr [flt_61B114] - fnstsw ax - test ah, 41h - jz loc_4330C6 - fstp st - fld dword ptr [flt_61B114] - jmp loc_4330DB - -loc_4330C6: - fcom dword ptr [flt_61B104] - fnstsw ax - test ah, 1 - jnz loc_4330DB - fstp st - fld dword ptr [flt_61B104] - -loc_4330DB: - mov eax, dword ptr [ebx+80h] - fld st(1) - fsub dword ptr [flt_61B104] - fld st(3) - fxch st(1) - fstp dword ptr [eax+185Ch] - mov ecx, dword ptr [ebx+80h] - fld st(1) - fxch st(1) - fstp dword ptr [ecx+1854h] - mov edx, dword ptr [ebx+80h] - fstp dword ptr [edx+172Ch] - fxch st(2) - fstp dword ptr [ebx+0B4h] - fstp dword ptr [ebx+9Ch] - fstp dword ptr [ebx+0A8h] - pop ebx - mov esp, ebp - pop ebp - retn -?Predict@mmNetObject@@QAEXXZ ENDP - ALIGN 16 ?Update@mmNetObject@@UAEXXZ PROC PUBLIC push esi @@ -470464,12 +470320,6 @@ flt_61B10C dd 041800000r ALIGN 4 flt_61B110 dd 0BF800000r -ALIGN 4 -flt_61B114 dd 000000000r - -ALIGN 4 -flt_61B118 dd 040000000r - ALIGN 4 ??_7mmNetObject@@6B@ dd offset ??_GmmNetObject@@UAEPAXI@Z dd offset ?GetClass@asNode@@UAEPAVMetaClass@@XZ @@ -522325,6 +522175,7 @@ EXTERN ?PreSetup@Dialog_Message@@UAEXXZ:PROC EXTERN ?PreSetup@NetArena@@UAEXXZ:PROC EXTERN ?PreSetup@VehShowcase@@UAEXXZ:PROC EXTERN ?PreUpdate@mmAnimInstState@@SAXM@Z:PROC +EXTERN ?Predict@mmNetObject@@QAEXXZ:PROC EXTERN ?Print@asBenchStats@@QAEXXZ:PROC EXTERN ?PrintString@MiniParser@@QAEXPBDH@Z:PROC EXTERN ?Printf@MiniParser@@QAAXPBDZZ:PROC diff --git a/code/midtown/mmgame/netobject.cpp b/code/midtown/mmgame/netobject.cpp index eb87b411..f95e85e0 100644 --- a/code/midtown/mmgame/netobject.cpp +++ b/code/midtown/mmgame/netobject.cpp @@ -20,6 +20,7 @@ define_dummy_symbol(mmgame_netobject); #include "netobject.h" +#include "arts7/sim.h" #include "mmcar/car.h" #include "mmcityinfo/vehlist.h" @@ -38,6 +39,43 @@ void mmNetObject::Init(mmCar* car, char* vehicle, i32 variant, ulong player_id, SetName(name); } +void mmNetObject::Predict() +{ + if (MatrixChanged) + { + constexpr f32 INSTANT_UPDATE_FLAG = 100.0f; + + if (field_BC == INSTANT_UPDATE_FLAG) + { + ICS->Matrix = Matrix; + MatrixChanged = false; + } + + else if (field_BC > 0.0f) + { + const f32 seconds = ARTSPTR->GetUpdateDelta(); + ICS->Matrix.Approach(Matrix, field_BC, field_C0, seconds); + MatrixChanged = false; + } + } + else + { + const f32 seconds = ARTSPTR->GetUpdateDelta(); + + const f32 steering = std::clamp(SteeringDelta * seconds + PrevSteering, 0.0f, 2.0f); + const f32 throttle = std::clamp(ThrottleDelta * seconds + PrevThrottle, 0.0f, 1.0f); + const f32 brakes = std::clamp(BrakesDelta * seconds + PrevBrakes, 0.0f, 1.0f); + + Car->Sim.Steering = steering - 1.0f; // Convert [0, 2] range to [-1, 1] + Car->Sim.Engine.Throttle = throttle; + Car->Sim.Brakes = brakes; + + PrevSteering = steering; + PrevThrottle = throttle; + PrevBrakes = brakes; + } +} + void mmNetObject::ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id, char* name) { vehicle = VehList()->GetVehicleInfo(vehicle)->BaseName; @@ -61,4 +99,4 @@ void mmNetObject::ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id SetCar(car); PlayerID = player_id; SetName(name); -} +} \ No newline at end of file diff --git a/code/midtown/mmgame/netobject.h b/code/midtown/mmgame/netobject.h index 1582ceac..7b2db917 100644 --- a/code/midtown/mmgame/netobject.h +++ b/code/midtown/mmgame/netobject.h @@ -67,7 +67,7 @@ class mmNetObject final : public asNetObject ARTS_IMPORT void PositionUpdate(NETGAME_MSG* arg1); // ?Predict@mmNetObject@@QAEXXZ - ARTS_IMPORT void Predict(); + ARTS_EXPORT void Predict(); // ?ReInit@mmNetObject@@QAEXPAVmmCar@@PADHK1@Z ARTS_EXPORT void ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id, char* name); From 9ae97cc4be1f9337af2916e20458a21111a2a118 Mon Sep 17 00:00:00 2001 From: Robin <99972691+KcRobin9@users.noreply.github.com> Date: Wed, 13 Aug 2025 23:39:38 +0200 Subject: [PATCH 2/5] Implement more NetObject Functions At the moment there are still some compiler errors related to unresolved external symbols. --- code/midtown/game.asm | 670 +----------------------------- code/midtown/mmgame/netobject.cpp | 255 +++++++++++- code/midtown/mmgame/netobject.h | 22 +- 3 files changed, 274 insertions(+), 673 deletions(-) diff --git a/code/midtown/game.asm b/code/midtown/game.asm index 047c7d8c..a3e3ade8 100644 --- a/code/midtown/game.asm +++ b/code/midtown/game.asm @@ -56247,601 +56247,6 @@ loc_43272A: retn 4 ??_EmmGameMulti@@UAEPAXI@Z ENDP -ALIGN 16 -??0mmNetObject@@QAE@XZ PROC PUBLIC - push ebp - mov ebp, esp - push -1 - push offset ??0mmNetObject@@QAE@XZ_SEH - mov eax, dword ptr fs:[0] - push eax - mov dword ptr fs:[0], esp - push ecx - push esi - mov esi, ecx - push edi - mov dword ptr [ebp-10h], esi - call ??0asNetObject@@QAE@XZ - xor edi, edi - mov dword ptr [esi], offset ??_7mmNetObject@@6B@ - mov dword ptr [esi+84h], edi - mov dword ptr [esi+30h], edi - mov dword ptr [esi+8Ch], edi - mov dword ptr [esi+88h], edi - mov dword ptr [esi+80h], edi - mov dword ptr [esi+0B4h], edi - mov dword ptr [esi+0B0h], edi - mov dword ptr [esi+9Ch], edi - mov dword ptr [esi+98h], edi - mov dword ptr [esi+0A8h], edi - mov dword ptr [esi+0A4h], edi - mov dword ptr [?time_delta@@3MA], 41200000h - lea ecx, [esi+0C4h] - mov dword ptr [ebp-4], edi - mov dword ptr [esi+94h], edi - mov dword ptr [esi+0BCh], edi - mov dword ptr [esi+0C0h], edi - mov dword ptr [esi+2Ch], edi - call ?Identity@Matrix34@@QAEXXZ - mov ecx, dword ptr [ebp-0Ch] - mov dword ptr [esi+34h], edi - mov eax, esi - pop edi - mov dword ptr fs:[0], ecx - pop esi - mov esp, ebp - pop ebp - retn -??0mmNetObject@@QAE@XZ ENDP - -ALIGN 16 -?Clear@mmNetObject@@QAEXXZ PROC PUBLIC - push esi - mov esi, ecx - push edi - xor edi, edi - mov ecx, dword ptr [esi+80h] - mov dword ptr [esi+0BCh], edi - cmp ecx, edi - mov dword ptr [esi+0C0h], edi - mov dword ptr [esi+94h], edi - mov dword ptr [esi+2Ch], edi - mov dword ptr [esi+30h], edi - jz loc_43282D - call ?RemoveVehicleAudio@mmCar@@QAEXXZ - -loc_43282D: - push edi - mov ecx, esi - call ?SetCar@mmNetObject@@QAEXPAVmmCar@@@Z - push edi - mov ecx, esi - mov dword ptr [esi+20h], edi - mov dword ptr [esi+84h], edi - call ?SetActive@mmNetObject@@QAEXH@Z - pop edi - pop esi - retn -?Clear@mmNetObject@@QAEXXZ ENDP - -ALIGN 16 -?Activate@mmNetObject@@QAEXXZ PROC PUBLIC - push esi - mov esi, ecx - mov eax, dword ptr [esi+80h] - test eax, eax - jz loc_432894 - lea ecx, [eax+1FFCh] - call ?Activate@mmCarModel@@QAEXXZ - mov eax, dword ptr [esi+80h] - add eax, 50h - mov edx, dword ptr [eax+18h] - or edx, 1 - mov dword ptr [eax+18h], edx - mov eax, dword ptr [esi+80h] - test byte ptr [eax+2018h], 80h - jz loc_432894 - mov ecx, dword ptr [eax+2308h] - call ?Activate@mmTrailer@@QAEXXZ - -loc_432894: - mov eax, dword ptr [esi+18h] - or al, 1 - mov dword ptr [esi+18h], eax - pop esi - retn -?Activate@mmNetObject@@QAEXXZ ENDP - -ALIGN 16 -?Deactivate@mmNetObject@@QAEXXZ PROC PUBLIC - push esi - mov esi, ecx - mov eax, dword ptr [esi+80h] - test eax, eax - jz loc_4328EE - lea ecx, [eax+1FFCh] - call ?Deactivate@mmCarModel@@QAEXXZ - mov eax, dword ptr [esi+80h] - add eax, 50h - mov edx, dword ptr [eax+18h] - and edx, -2 - mov dword ptr [eax+18h], edx - mov eax, dword ptr [esi+80h] - test byte ptr [eax+2018h], 80h - jz loc_4328E4 - mov ecx, dword ptr [eax+2308h] - call ?Deactivate@mmTrailer@@QAEXXZ - -loc_4328E4: - mov dword ptr [esi+84h], 0 - -loc_4328EE: - mov eax, dword ptr [esi+18h] - and al, 0FEh - mov dword ptr [esi+18h], eax - pop esi - retn -?Deactivate@mmNetObject@@QAEXXZ ENDP - -ALIGN 16 -?SetCar@mmNetObject@@QAEXPAVmmCar@@@Z PROC PUBLIC - push ebp - mov ebp, esp - mov eax, dword ptr [ebp+8] - mov dword ptr [ecx+80h], eax - pop ebp - retn 4 -?SetCar@mmNetObject@@QAEXPAVmmCar@@@Z ENDP - -ALIGN 16 -?SetActive@mmNetObject@@QAEXH@Z PROC PUBLIC - push ebp - mov ebp, esp - mov edx, dword ptr [ebp+8] - xor eax, eax - test edx, edx - setnz al - mov dword ptr [ecx+88h], eax - pop ebp - retn 4 -?SetActive@mmNetObject@@QAEXH@Z ENDP - -ALIGN 16 -?SetLocalData@mmNetObject@@UAEXXZ PROC PUBLIC - push ebp - mov ebp, esp - sub esp, 0Ch - mov eax, dword ptr [?NETMGR@@3VasNetwork@@A+50h] - push esi - test eax, eax - mov esi, ecx - jz loc_432BBC - mov eax, dword ptr [esi+20h] - push edi - mov edi, dword ptr [esi+80h] - push ebx - lea ebx, [esi+38h] - mov dword ptr [esi+3Ch], eax - mov dword ptr [ebx], 1F5h - mov ecx, dword ptr [edi+185Ch] - mov dword ptr [esi+40h], ecx - fld dword ptr [edi+172Ch] - fmul dword ptr [flt_61B0F4] - call __ftol - mov byte ptr [esi+44h], al - fld dword ptr [edi+1854h] - fmul dword ptr [flt_61B0F4] - call __ftol - lea edx, [ebp-0Ch] - lea ecx, [edi+0C0h] - push edx - mov byte ptr [esi+45h], al - call ?GetEulers@Matrix34@@QBE?AVVector3@@XZ - mov edx, dword ptr [eax] - lea ecx, [esi+48h] - mov dword ptr [esi+48h], edx - mov edx, dword ptr [eax+4] - mov dword ptr [ecx+4], edx - mov eax, dword ptr [eax+8] - lea edx, [esi+54h] - mov dword ptr [ecx+8], eax - mov eax, dword ptr [esi+80h] - lea ecx, [eax+0E4h] - mov edi, dword ptr [eax+0E4h] - mov dword ptr [edx], edi - mov edi, dword ptr [ecx+4] - mov dword ptr [edx+4], edi - mov ecx, dword ptr [ecx+8] - mov dword ptr [edx+8], ecx - lea edx, [eax+154h] - lea ecx, [esi+60h] - mov edi, dword ptr [edx] - mov dword ptr [ecx], edi - mov edi, dword ptr [edx+4] - mov dword ptr [ecx+4], edi - mov edx, dword ptr [edx+8] - mov dword ptr [ecx+8], edx - mov edx, dword ptr [esi+8Ch] - mov ecx, dword ptr [eax+18D0h] - inc edx - mov dword ptr [esi+70h], ecx - mov ecx, edx - mov dword ptr [esi+8Ch], edx - mov edx, dword ptr [esi+34h] - mov dword ptr [esi+78h], ecx - mov cx, word ptr [esi+30h] - mov dword ptr [esi+6Ch], edx - mov word ptr [esi+74h], cx - mov byte ptr [esi+7Dh], 0 - mov word ptr [esi+76h], 0 - mov ecx, dword ptr [eax+1F5Ch] - test ecx, ecx - jz loc_432B80 - mov word ptr [esi+76h], 2 - -loc_432B80: - test byte ptr [eax+2018h], 4 - jz loc_432B8D - or byte ptr [esi+76h], 8 - -loc_432B8D: - lea ecx, [eax+174Ch] - call ?GetCurrentGear@mmTransmission@@QAEHXZ - cmp eax, -1 - jnz loc_432BA1 - or byte ptr [esi+76h], 4 - -loc_432BA1: - mov dx, word ptr [esi+2Ch] - push 0 - or word ptr [esi+76h], dx - push 48h - push ebx - push 0 - mov ecx, offset ?NETMGR@@3VasNetwork@@A - call ?Send@asNetwork@@QAEXKPAXKH@Z - pop ebx - pop edi - -loc_432BBC: - pop esi - mov esp, ebp - pop ebp - retn -?SetLocalData@mmNetObject@@UAEXXZ ENDP - -ALIGN 16 -?PositionUpdate@mmNetObject@@QAEXPAUNETGAME_MSG@@@Z PROC PUBLIC - push ebp - mov ebp, esp - sub esp, 8 - push ebx - mov ebx, ecx - xor eax, eax - push edi - mov ecx, dword ptr [ebx+8Ch] - mov edi, dword ptr [ebp+8] - test ecx, ecx - setz al - mov dword ptr [ebx+90h], 1 - mov dword ptr [ebp-8], eax - mov eax, dword ptr [edi+40h] - cmp eax, ecx - jb loc_432F69 - mov ecx, dword ptr [ebx+80h] - mov dword ptr [ebx+8Ch], eax - mov edx, dword ptr [edi+8] - xor eax, eax - mov dword ptr [ecx+185Ch], edx - mov al, byte ptr [edi+0Dh] - mov dword ptr [ebp-4], eax - mov ecx, dword ptr [ebx+80h] - fild dword ptr [ebp-4] - xor edx, edx - push esi - lea esi, [ebx+0E8h] - fmul dword ptr [flt_61B0F8] - fstp dword ptr [ecx+1854h] - mov dl, byte ptr [edi+0Ch] - mov eax, dword ptr [ebx+80h] - mov dword ptr [ebp-4], edx - lea ecx, [edi+28h] - fild dword ptr [ebp-4] - fmul dword ptr [flt_61B0F8] - fstp dword ptr [eax+172Ch] - mov edx, dword ptr [ebx+24h] - mov eax, dword ptr [ecx] - add edx, 0B4h - mov dword ptr [edx], eax - mov eax, dword ptr [ecx+4] - mov dword ptr [edx+4], eax - mov ecx, dword ptr [ecx+8] - mov dword ptr [edx+8], ecx - mov edx, dword ptr [ebx+80h] - mov eax, dword ptr [edi+38h] - lea ecx, [edi+1Ch] - mov dword ptr [edx+18D0h], eax - mov edx, esi - mov eax, dword ptr [ecx] - mov dword ptr [edx], eax - mov eax, dword ptr [ecx+4] - mov dword ptr [edx+4], eax - mov ecx, dword ptr [ecx+8] - mov dword ptr [edx+8], ecx - lea edx, [edi+10h] - lea ecx, [ebx+0C4h] - push edx - call ?FromEulers@Matrix34@@QAEXABVVector3@@@Z - mov eax, dword ptr [ebx+24h] - mov ecx, dword ptr [ebp-8] - test ecx, ecx - fld dword ptr [eax+48h] - fsub dword ptr [esi+4] - fld dword ptr [eax+4Ch] - fsub dword ptr [esi+8] - fld dword ptr [eax+44h] - fsub dword ptr [esi] - fld st(2) - fmul st, st(3) - fld st(2) - fmul st, st(3) - faddp st(1), st - fld st(1) - fmul st, st(2) - faddp st(1), st - fstp dword ptr [ebp-4] - fstp st - fstp st - fstp st - jz loc_432D00 - lea edi, [eax+20h] - mov ecx, 0Ch - lea esi, [ebx+0C4h] - rep movsd - mov ecx, ebx - call ?Activate@mmNetObject@@QAEXXZ - mov eax, dword ptr [ebp+8] - mov edi, eax - mov ecx, dword ptr [eax+34h] - mov dword ptr [ebx+94h], ecx - -loc_432D00: - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B0FC] - fnstsw ax - test ah, 41h - jnz loc_432D1A - mov eax, 42C80000h - jmp loc_432DF7 - -loc_432D1A: - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B100] - fnstsw ax - test ah, 1 - jz loc_432D53 - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B104] - fnstsw ax - test ah, 41h - jnz loc_432D53 - mov dword ptr [ebx+0BCh], 3F600000h - mov dword ptr [ebx+0C0h], 40400000h - jmp loc_432E03 - -loc_432D53: - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B108] - fnstsw ax - test ah, 1 - jz loc_432D89 - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B100] - fnstsw ax - test ah, 41h - jnz loc_432D89 - mov dword ptr [ebx+0BCh], 3FE00000h - mov dword ptr [ebx+0C0h], 40000000h - jmp loc_432E03 - -loc_432D89: - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B10C] - fnstsw ax - test ah, 1 - jz loc_432DBF - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B108] - fnstsw ax - test ah, 41h - jnz loc_432DBF - mov dword ptr [ebx+0BCh], 40200000h - mov dword ptr [ebx+0C0h], 3F800000h - jmp loc_432E03 - -loc_432DBF: - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B0FC] - fnstsw ax - test ah, 1 - jz loc_432DF5 - fld dword ptr [ebp-4] - fcomp dword ptr [flt_61B10C] - fnstsw ax - test ah, 41h - jnz loc_432DF5 - mov dword ptr [ebx+0BCh], 40A00000h - mov dword ptr [ebx+0C0h], 3F000000h - jmp loc_432E03 - -loc_432DF5: - xor eax, eax - -loc_432DF7: - mov dword ptr [ebx+0BCh], eax - mov dword ptr [ebx+0C0h], eax - -loc_432E03: - xor edx, edx - xor eax, eax - mov dx, word ptr [edi+3Ch] - mov ecx, dword ptr [ebx+80h] - mov dword ptr [ebx+30h], edx - mov ax, word ptr [edi+3Eh] - mov dword ptr [ebx+2Ch], eax - mov al, byte ptr [edi+3Eh] - test al, 2 - jz loc_432E2C - add ecx, 50h - call ?PlayHorn@mmCarSim@@QAEXXZ - jmp loc_432E34 - -loc_432E2C: - add ecx, 50h - call ?StopHorn@mmCarSim@@QAEXXZ - -loc_432E34: - mov al, byte ptr [edi+3Eh] - mov ecx, dword ptr [ebx+80h] - test al, 8 - jz loc_432E5A - add ecx, 50h - call ?StartSiren@mmCarSim@@QAEXXZ - mov eax, dword ptr [ebx+80h] - mov ecx, dword ptr [eax+2018h] - or ecx, 4 - jmp loc_432E71 - -loc_432E5A: - add ecx, 50h - call ?StopSiren@mmCarSim@@QAEXXZ - mov eax, dword ptr [ebx+80h] - mov ecx, dword ptr [eax+2018h] - and ecx, -5 - -loc_432E71: - mov dword ptr [eax+2018h], ecx - mov al, byte ptr [edi+3Eh] - test al, 4 - jz loc_432EAD - mov ecx, dword ptr [ebx+80h] - add ecx, 174Ch - call ?GetCurrentGear@mmTransmission@@QAEHXZ - cmp eax, -1 - jz loc_432EA7 - mov ecx, dword ptr [ebx+80h] - push 0 - add ecx, 174Ch - call ?SetCurrentGear@mmTransmission@@QAEHH@Z - -loc_432EA7: - test byte ptr [edi+3Eh], 4 - jnz loc_432ED6 - -loc_432EAD: - mov ecx, dword ptr [ebx+80h] - add ecx, 174Ch - call ?GetCurrentGear@mmTransmission@@QAEHXZ - cmp eax, -1 - jnz loc_432ED6 - mov ecx, dword ptr [ebx+80h] - push 2 - add ecx, 174Ch - call ?SetCurrentGear@mmTransmission@@QAEHH@Z - -loc_432ED6: - mov eax, dword ptr [ebx+80h] - pop esi - fld dword ptr [?time_delta@@3MA] - fld dword ptr [eax+1854h] - fsub dword ptr [ebx+0B0h] - fmul st, st(1) - fstp dword ptr [ebx+0B8h] - fld dword ptr [eax+185Ch] - fsub dword ptr [flt_61B110] - fsub dword ptr [ebx+98h] - fmul st, st(1) - fstp dword ptr [ebx+0A0h] - fld dword ptr [eax+172Ch] - fsub dword ptr [ebx+0A4h] - fmul st, st(1) - fstp dword ptr [ebx+0ACh] - fstp st - fld dword ptr [eax+1854h] - fst dword ptr [ebx+0B4h] - fstp dword ptr [ebx+0B0h] - fld dword ptr [eax+185Ch] - fsub dword ptr [flt_61B110] - fst dword ptr [ebx+9Ch] - fstp dword ptr [ebx+98h] - fld dword ptr [eax+172Ch] - fst dword ptr [ebx+0A8h] - fstp dword ptr [ebx+0A4h] - mov ecx, dword ptr [edi+34h] - mov dword ptr [ebx+34h], ecx - -loc_432F69: - pop edi - pop ebx - mov esp, ebp - pop ebp - retn 4 -?PositionUpdate@mmNetObject@@QAEXPAUNETGAME_MSG@@@Z ENDP - -ALIGN 16 -?Update@mmNetObject@@UAEXXZ PROC PUBLIC - push esi - mov esi, ecx - call ?Predict@mmNetObject@@QAEXXZ - mov eax, dword ptr [?ARTSPTR@@3PAVasSimulation@@A] - fld dword ptr [eax+13Ch] - mov eax, dword ptr [esi+80h] - fadd dword ptr [esi+94h] - fstp dword ptr [esi+94h] - test byte ptr [eax+2018h], 80h - jz loc_433176 - mov ecx, dword ptr [eax+2308h] - push 0Bh - add ecx, 24h - push 0Ah - push ecx - mov ecx, offset ?PHYS@@3VmmPhysicsMGR@@A - call ?DeclareMover@mmPhysicsMGR@@QAEXPAVmmInstance@@HH@Z - -loc_433176: - mov edx, dword ptr [esi+80h] - push 0Bh - add edx, 1FFCh - push 1 - push edx - mov ecx, offset ?PHYS@@3VmmPhysicsMGR@@A - call ?DeclareMover@mmPhysicsMGR@@QAEXPAVmmInstance@@HH@Z - mov ecx, esi - call ?Update@asNetObject@@UAEXXZ - pop esi - retn -?Update@mmNetObject@@UAEXXZ ENDP - -ALIGN 16 -??_GmmNetObject@@UAEPAXI@Z PROC PRIVATE - push ebp - mov ebp, esp - push esi - mov esi, ecx - call ??1mmNetObject@@UAE@XZ - test byte ptr [ebp+8], 1 - jz loc_4331EA - push esi - call ?arts_operator_delete@@YAXPAX@Z - add esp, 4 - -loc_4331EA: - mov eax, esi - pop esi - pop ebp - retn 4 -??_GmmNetObject@@UAEPAXI@Z ENDP - ALIGN 16 ??0mmRainAudio@@QAE@XZ PROC PUBLIC push ebp @@ -459094,15 +458499,6 @@ loc_610694: jmp ___CxxFrameHandler ?InitOtherPlayers@mmGameMulti@@UAEXXZ_SEH ENDP -loc_6106B0: - mov ecx, dword ptr [ebp-10h] - jmp ??1asNetObject@@UAE@XZ - -??0mmNetObject@@QAE@XZ_SEH PROC PRIVATE - mov eax, offset stru_629770 - jmp ___CxxFrameHandler -??0mmNetObject@@QAE@XZ_SEH ENDP - loc_6106D0: mov eax, dword ptr [ebp-10h] push eax @@ -470296,50 +469692,6 @@ ALIGN 4 dd offset __purecall dd offset __purecall -ALIGN 4 -flt_61B0F4 dd 0437F0000r - -ALIGN 4 -flt_61B0F8 dd 03B808081r - -ALIGN 4 -flt_61B0FC dd 041C80000r - -ALIGN 4 -flt_61B100 dd 040800000r - -ALIGN 4 -flt_61B104 dd 03F800000r - -ALIGN 4 -flt_61B108 dd 041100000r - -ALIGN 4 -flt_61B10C dd 041800000r - -ALIGN 4 -flt_61B110 dd 0BF800000r - -ALIGN 4 -??_7mmNetObject@@6B@ dd offset ??_GmmNetObject@@UAEPAXI@Z - dd offset ?GetClass@asNode@@UAEPAVMetaClass@@XZ - dd offset ?GetTypeNameV@Base@@UAEPBDXZ - dd offset ?BeforeSave@Base@@UAEXXZ - dd offset ?AfterLoad@Base@@UAEXXZ - dd offset ?Cull@asCullable@@UAEXXZ - dd offset ?Update@mmNetObject@@UAEXXZ - dd offset ?Reset@asNode@@UAEXXZ - dd offset ?ResChange@asNode@@UAEXHH@Z - dd offset ?UpdatePaused@asNode@@UAEXXZ - dd offset ?Load@asNode@@UAEXXZ - dd offset ?Save@asNode@@UAEXXZ - dd offset ?AddWidgets@asNode@@UAEXPAVBank@@@Z - dd offset ?OpenWidgets@asNode@@UAEXPADPAVbkWindow@@@Z - dd offset ?CloseWidgets@asNode@@UAEXXZ - dd offset ?SetLocalData@mmNetObject@@UAEXXZ - dd offset ?PositionUpdate@asNetObject@@UAEXPAVMatrix34@@VVector3@@MMM@Z - dd 40400000h - ALIGN 4 ??_7mmWaypointInstance@@6B@ dd offset ??_EmmWaypointInstance@@UAEPAXI@Z dd offset ?GetClass@mmWaypointInstance@@UAEPAVMetaClass@@XZ @@ -480325,19 +479677,6 @@ ALIGN 4 stru_629768 dd 0FFFFFFFFh dd offset loc_610694 -ALIGN 4 -stru_629770 dd 19930520h - dd 1 - dd offset stru_629790 - dd 0 - dd 0 - dd 0 - dd 0 - -ALIGN 4 -stru_629790 dd 0FFFFFFFFh - dd offset loc_6106B0 - ALIGN 4 stru_629798 dd 19930520h dd 4 @@ -521537,6 +520876,7 @@ EXTERN ??0mmIODev@@QAE@XZ:PROC EXTERN ??0mmInfoBase@@QAE@XZ:PROC EXTERN ??0mmInstance@@QAE@XZ:PROC EXTERN ??0mmMatrixInstance@@QAE@XZ:PROC +EXTERN ??0mmNetObject@@QAE@XZ:PROC EXTERN ??0mmNumber@@QAE@XZ:PROC EXTERN ??0mmNumberFont@@QAE@XZ:PROC EXTERN ??0mmShardManager@@QAE@XZ:PROC @@ -521756,6 +521096,7 @@ EXTERN ?Action@UILabel@@UAEXTeqEvent@@@Z:PROC EXTERN ?Action@mmCompBase@@UAEXTeqEvent@@@Z:PROC EXTERN ?Action@mmCompBase@@UAEXTeqEvent@@MMH@Z:PROC EXTERN ?Action@uiWidget@@UAEXTeqEvent@@@Z:PROC +EXTERN ?Activate@mmNetObject@@QAEXXZ:PROC EXTERN ?ActivateMapNetObject@mmGameMulti@@QAEXH@Z:PROC EXTERN ?ActiveFlag@@3HA:BYTE EXTERN ?Add@?$agiLib@VagiTexParameters@@VagiTexDef@@@@QAEHAAVagiTexParameters@@@Z:PROC @@ -521829,6 +521170,7 @@ EXTERN ?CheckCDFile@DSGlobal@@QAEEPAD@Z:PROC EXTERN ?CheckInput@UIMenu@@UAEXXZ:PROC EXTERN ?ChooseNextLaneLink@aiMap@@QAEHPAVaiRailSet@@@Z:PROC EXTERN ?CityName@@3PADA:BYTE +EXTERN ?Clear@mmNetObject@@QAEXXZ:PROC EXTERN ?ClearAction@UIMenu@@QAEXXZ:PROC EXTERN ?ClearDamage@mmCar@@QAEXXZ:PROC EXTERN ?CloseWidgets@asNode@@UAEXXZ:PROC @@ -521862,6 +521204,7 @@ EXTERN ?Cull@mmHudMap@@UAEXXZ:PROC EXTERN ?Cull@mmWPHUD@@UAEXXZ:PROC EXTERN ?Cull@mmWaypoints@@UAEXXZ:PROC EXTERN ?CurrentMenuSelected@MenuManager@@QAEHXZ:PROC +EXTERN ?Deactivate@mmNetObject@@QAEXXZ:PROC EXTERN ?DeactivateMapNetObject@mmGameMulti@@QAEXH@Z:PROC EXTERN ?DebugLog@@YAXHPAXH@Z:PROC EXTERN ?DebugLogShutdown@@YAXXZ:PROC @@ -522167,6 +521510,7 @@ EXTERN ?Police@aiMap@@QAEPAVaiVehiclePolice@@H@Z:PROC EXTERN ?Poll@mmJoystick@@QAEKXZ:PROC EXTERN ?Poly@agiRasterizer@@UAEXPAHH@Z:PROC EXTERN ?Pop@eqEventQ@@QAEHPATeqEvent@@@Z:PROC +EXTERN ?PositionUpdate@mmNetObject@@QAEXPAUNETGAME_MSG@@@Z:PROC EXTERN ?PostSetup@UIMenu@@UAEXXZ:PROC EXTERN ?PostSetup@VehShowcase@@UAEXXZ:PROC EXTERN ?PostUpdate@mmPhysEntity@@UAEXXZ:PROC @@ -522175,7 +521519,6 @@ EXTERN ?PreSetup@Dialog_Message@@UAEXXZ:PROC EXTERN ?PreSetup@NetArena@@UAEXXZ:PROC EXTERN ?PreSetup@VehShowcase@@UAEXXZ:PROC EXTERN ?PreUpdate@mmAnimInstState@@SAXM@Z:PROC -EXTERN ?Predict@mmNetObject@@QAEXXZ:PROC EXTERN ?Print@asBenchStats@@QAEXXZ:PROC EXTERN ?PrintString@MiniParser@@QAEXPBDH@Z:PROC EXTERN ?Printf@MiniParser@@QAAXPBDZZ:PROC @@ -522215,7 +521558,6 @@ EXTERN ?Relight@mmStaticInstance@@UAIXXZ:PROC EXTERN ?RemoveAllChildren@asNode@@QAEXXZ:PROC EXTERN ?RemoveChild@asNode@@QAEHPAV1@@Z:PROC EXTERN ?RemoveMe@HashTable@@AAEXXZ:PROC -EXTERN ?RemoveVehicleAudio@mmCar@@QAEXXZ:PROC EXTERN ?ReportTimeAlloc@@YAXM@Z:PROC EXTERN ?ResChange@asNode@@UAEXHH@Z:PROC EXTERN ?Reset@AudManager@@UAEXXZ:PROC @@ -522250,6 +521592,8 @@ EXTERN ?Seek@Stream@@QAEHH@Z:PROC EXTERN ?SendChatMessage@mmGame@@UAEXPAD@Z:PROC EXTERN ?Set@Vector3@@QAEXMMM@Z:PROC EXTERN ?Set@Vector4@@QAEXMMMM@Z:PROC +EXTERN ?SetActive@mmNetObject@@QAEXH@Z:PROC +EXTERN ?SetCar@mmNetObject@@QAEXPAVmmCar@@@Z:PROC EXTERN ?SetCompositionWindow@UITextField@@QAEXXZ:PROC EXTERN ?SetCurrentCity@mmCityList@@QAEXH@Z:PROC EXTERN ?SetCurrentCity@mmCityList@@QAEXPAD@Z:PROC diff --git a/code/midtown/mmgame/netobject.cpp b/code/midtown/mmgame/netobject.cpp index f95e85e0..a45a05e4 100644 --- a/code/midtown/mmgame/netobject.cpp +++ b/code/midtown/mmgame/netobject.cpp @@ -22,7 +22,93 @@ define_dummy_symbol(mmgame_netobject); #include "arts7/sim.h" #include "mmcar/car.h" +#include "mmcar/trailer.h" #include "mmcityinfo/vehlist.h" +#include "mmphysics/phys.h" + +#include "mmnetwork/network.h" + +mmNetObject::mmNetObject() + : asNetObject() + , field_28(0) + , Flags(0) + , Score(0) + , Time(0.0f) + , LocalData {} + , Car(nullptr) + , IsEnabled(false) + , Active(0) + , UpdateCount(0) + , MatrixChanged(false) + , ActivateTime(0.0f) + , Steering(0.0f) + , PrevSteering(0.0f) + , SteeringDelta(0.0f) + , Throttle(0.0f) + , PrevThrottle(0.0f) + , ThrottleDelta(0.0f) + , Brakes(0.0f) + , PrevBrakes(0.0f) + , BrakesDelta(0.0f) + , field_BC(0.0f) + , field_C0(0.0f) + , Matrix(IDENTITY) +{ + time_delta = 10.0f; +} + +void mmNetObject::Activate() +{ + if (Car) + { + Car->Model.Activate(); + Car->Sim.ActivateNode(); + + if (Car->Model.HasTrailer()) + { + Car->Trailer->Activate(); + } + } + + ActivateNode(); +} + +void mmNetObject::Clear() +{ + field_BC = 0.0f; + field_C0 = 0.0f; + ActivateTime = 0.0f; + Flags = 0; + Score = 0; + + if (Car) + { + Car->RemoveVehicleAudio(); + } + + SetCar(nullptr); + PlayerID = 0; + IsEnabled = false; + SetActive(false); +} + +void mmNetObject::Deactivate() +{ + if (Car) + { + Car->Model.Deactivate(); + Car->Sim.DeactivateNode(); + + if (Car->Model.HasTrailer()) + { + Car->Trailer->Deactivate(); + } + + IsEnabled = false; + } + + DeactivateNode(); +} void mmNetObject::Init(mmCar* car, char* vehicle, i32 variant, ulong player_id, char* name) { @@ -31,7 +117,7 @@ void mmNetObject::Init(mmCar* car, char* vehicle, i32 variant, ulong player_id, car->Init(vehicle, CAR_TYPE_NETOBJECT, variant); ICS = car->GetICS(); UpdateCount = 0; - MatrixChanged = 0; + MatrixChanged = false; Flags = 0; Score = 0; SetCar(car); @@ -39,6 +125,106 @@ void mmNetObject::Init(mmCar* car, char* vehicle, i32 variant, ulong player_id, SetName(name); } +void mmNetObject::PositionUpdate(NETGAME_MSG* msg) +{ + MatrixChanged = true; + + if (msg->LastUpdateIdx < UpdateCount) + return; + + UpdateCount = msg->LastUpdateIdx; + + Car->Sim.Steering = msg->Steering; + Car->Sim.Brakes = static_cast(msg->Brakes) / 255.0f; + Car->Sim.Engine.Throttle = static_cast(msg->Throttle) / 255.0f; + + Car->Sim.CurrentDamage = msg->Damage; + ICS->LinearMomentum = msg->Velocity; + + Matrix.m3 = msg->Position; + Matrix.FromEulers(msg->Rotation); + + if (UpdateCount == 0) + { + ICS->Matrix = Matrix; + Activate(); + ActivateTime = msg->Time; + } + + const f32 dist_sq = ICS->Matrix.m3.Dist2(Matrix.m3); + + if (dist_sq > 25.0f) + { + field_BC = 100.0f; + field_C0 = 100.0f; + } + else if (dist_sq > 16.0f) + { + field_BC = 5.0f; + field_C0 = 0.5f; + } + else if (dist_sq > 9.0f) + { + field_BC = 2.5f; + field_C0 = 1.0f; + } + else if (dist_sq > 4.0f) + { + field_BC = 1.75f; + field_C0 = 2.0f; + } + else if (dist_sq > 1.0f) + { + field_BC = 0.875f; + field_C0 = 3.0f; + } + else + { + field_BC = 0.0f; + field_C0 = 0.0f; + } + + Score = msg->Score; + Flags = msg->Flags; + + if (msg->Flags & NET_FLAG_HORN) + Car->Sim.PlayHorn(); + else + Car->Sim.StopHorn(); + + if (msg->Flags & NET_FLAG_SIREN) + { + Car->Sim.StartSiren(); + Car->Model.CarFlags |= CAR_FLAG_SIREN_ON; + } + else + { + Car->Sim.StopSiren(); + Car->Model.CarFlags &= ~CAR_FLAG_SIREN_ON; + } + + if (msg->Flags & NET_FLAG_REVERSE) + { + if (!Car->Sim.Trans.IsReverse()) + Car->Sim.Trans.SetCurrentGear(0); + } + else + { + if (Car->Sim.Trans.IsReverse()) + Car->Sim.Trans.SetCurrentGear(2); + } + + SteeringDelta = (Car->Sim.Steering + 1.0f - Steering) * time_delta; + ThrottleDelta = (Car->Sim.Engine.Throttle - Throttle) * time_delta; + BrakesDelta = (Car->Sim.Brakes - Brakes) * time_delta; + + PrevSteering = Steering = Car->Sim.Steering + 1.0f; // Convert [-1, 1] to [0, 2] + PrevThrottle = Throttle = Car->Sim.Engine.Throttle; + PrevBrakes = Brakes = Car->Sim.Brakes; + + Time = msg->Time; +} + void mmNetObject::Predict() { if (MatrixChanged) @@ -99,4 +285,71 @@ void mmNetObject::ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id SetCar(car); PlayerID = player_id; SetName(name); +} + +void mmNetObject::SetActive(b32 active) +{ + Active = active; +} + +void mmNetObject::SetCar(mmCar* car) +{ + Car = car; +} + +void mmNetObject::SetLocalData() +{ + if (!NETMGR.InSession()) + return; + + LocalData.SenderId = PlayerID; + LocalData.MessageId = 501; + + LocalData.Steering = Car->Sim.Steering; + LocalData.Throttle = static_cast(Car->Sim.Engine.Throttle * 255.0f); + LocalData.Brakes = static_cast(Car->Sim.Brakes * 255.0f); + + LocalData.Rotation = Car->Sim.ICS.Matrix.GetEulers(); + LocalData.Position = Car->Sim.ICS.Matrix.m3; + LocalData.Velocity = Car->Sim.ICS.LinearMomentum; + LocalData.Damage = Car->Sim.CurrentDamage; + + LocalData.LastUpdateIdx = ++UpdateCount; + + LocalData.Time = Time; + LocalData.Score = Score; // u16 -> i32 + LocalData.StringValue[1] = 0; + + LocalData.Flags = 0; + + if (Car->Sim.HornPlaying) + LocalData.Flags |= NET_FLAG_HORN; + + if (Car->Model.CarFlags & CAR_FLAG_SIREN_ON) + LocalData.Flags |= NET_FLAG_SIREN; + + if (Car->Sim.Trans.IsReverse()) + LocalData.Flags |= NET_FLAG_REVERSE; + + LocalData.Flags |= static_cast(Flags); + + NETMGR.Send(0, &LocalData, sizeof(NETGAME_MSG), 0); +} + +void mmNetObject::Update() +{ + Predict(); + + ActivateTime += ARTSPTR->GetUpdateDelta(); + + if (Car->Model.HasTrailer()) + { + PHYS.DeclareMover(&Car->Trailer->Inst, MOVER_TYPE_10, + MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS); + } + + PHYS.DeclareMover( + &Car->Model, MOVER_TYPE_PERM, MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS); + + asNetObject::Update(); } \ No newline at end of file diff --git a/code/midtown/mmgame/netobject.h b/code/midtown/mmgame/netobject.h index 7b2db917..01f971bd 100644 --- a/code/midtown/mmgame/netobject.h +++ b/code/midtown/mmgame/netobject.h @@ -42,29 +42,33 @@ struct NETGAME_MSG char StringValue[4]; }; +#define NET_FLAG_HORN 0x2 +#define NET_FLAG_REVERSE 0x4 +#define NET_FLAG_SIREN 0x8 + class mmNetObject final : public asNetObject { public: // ??0mmNetObject@@QAE@XZ - ARTS_IMPORT mmNetObject(); + ARTS_EXPORT mmNetObject(); // ??1mmNetObject@@UAE@XZ ARTS_EXPORT ~mmNetObject() override = default; // ?Activate@mmNetObject@@QAEXXZ - ARTS_IMPORT void Activate(); + ARTS_EXPORT void Activate(); // ?Clear@mmNetObject@@QAEXXZ - ARTS_IMPORT void Clear(); + ARTS_EXPORT void Clear(); // ?Deactivate@mmNetObject@@QAEXXZ - ARTS_IMPORT void Deactivate(); + ARTS_EXPORT void Deactivate(); // ?Init@mmNetObject@@QAEXPAVmmCar@@PADHK1@Z ARTS_EXPORT void Init(mmCar* car, char* vehicle, i32 variant, ulong player_id, char* name); // ?PositionUpdate@mmNetObject@@QAEXPAUNETGAME_MSG@@@Z - ARTS_IMPORT void PositionUpdate(NETGAME_MSG* arg1); + ARTS_EXPORT void PositionUpdate(NETGAME_MSG* msg); // ?Predict@mmNetObject@@QAEXXZ ARTS_EXPORT void Predict(); @@ -73,16 +77,16 @@ class mmNetObject final : public asNetObject ARTS_EXPORT void ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id, char* name); // ?SetActive@mmNetObject@@QAEXH@Z - ARTS_IMPORT void SetActive(i32 arg1); + ARTS_EXPORT void SetActive(i32 active); // ?SetCar@mmNetObject@@QAEXPAVmmCar@@@Z - ARTS_IMPORT void SetCar(mmCar* arg1); + ARTS_EXPORT void SetCar(mmCar* car); // ?SetLocalData@mmNetObject@@UAEXXZ - ARTS_IMPORT void SetLocalData() override; + ARTS_EXPORT void SetLocalData() override; // ?Update@mmNetObject@@UAEXXZ - ARTS_IMPORT void Update() override; + ARTS_EXPORT void Update() override; u32 field_28; u32 Flags; From 7b9b60203c067f97c79e654e87ec0bb3d1f51bf7 Mon Sep 17 00:00:00 2001 From: Robin <99972691+KcRobin9@users.noreply.github.com> Date: Thu, 14 Aug 2025 00:12:53 +0200 Subject: [PATCH 3/5] Bug Fixes --- code/midtown/mmgame/netobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/midtown/mmgame/netobject.cpp b/code/midtown/mmgame/netobject.cpp index a45a05e4..770dc1ac 100644 --- a/code/midtown/mmgame/netobject.cpp +++ b/code/midtown/mmgame/netobject.cpp @@ -129,7 +129,7 @@ void mmNetObject::PositionUpdate(NETGAME_MSG* msg) { MatrixChanged = true; - if (msg->LastUpdateIdx < UpdateCount) + if ((msg->LastUpdateIdx < 0) || (static_cast(msg->LastUpdateIdx) < UpdateCount)) return; UpdateCount = msg->LastUpdateIdx; @@ -317,7 +317,7 @@ void mmNetObject::SetLocalData() LocalData.LastUpdateIdx = ++UpdateCount; LocalData.Time = Time; - LocalData.Score = Score; // u16 -> i32 + LocalData.Score = static_cast(Score); LocalData.StringValue[1] = 0; LocalData.Flags = 0; From e82dc03f56468a3069ff765a41dc615b5f29901d Mon Sep 17 00:00:00 2001 From: Robin <99972691+KcRobin9@users.noreply.github.com> Date: Wed, 27 Aug 2025 23:25:24 +0200 Subject: [PATCH 4/5] Address Review Comments --- code/midtown/game.asm | 4 --- code/midtown/mmgame/netobject.cpp | 46 +++++++------------------------ code/midtown/mmgame/netobject.h | 15 ++++------ 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/code/midtown/game.asm b/code/midtown/game.asm index a3e3ade8..f34e94d4 100644 --- a/code/midtown/game.asm +++ b/code/midtown/game.asm @@ -517745,10 +517745,6 @@ PUBLIC ?mmGameMultiMetaClass@@3VMetaClass@@A ALIGN 4 dword_6A77E0 dd ? -ALIGN 8 -PUBLIC ?time_delta@@3MA -?time_delta@@3MA dd ? - ALIGN 4 dword_6A77EC dd ? diff --git a/code/midtown/mmgame/netobject.cpp b/code/midtown/mmgame/netobject.cpp index 770dc1ac..d618531b 100644 --- a/code/midtown/mmgame/netobject.cpp +++ b/code/midtown/mmgame/netobject.cpp @@ -28,34 +28,8 @@ define_dummy_symbol(mmgame_netobject); #include "mmnetwork/network.h" -mmNetObject::mmNetObject() - : asNetObject() - , field_28(0) - , Flags(0) - , Score(0) - , Time(0.0f) - , LocalData {} - , Car(nullptr) - , IsEnabled(false) - , Active(0) - , UpdateCount(0) - , MatrixChanged(false) - , ActivateTime(0.0f) - , Steering(0.0f) - , PrevSteering(0.0f) - , SteeringDelta(0.0f) - , Throttle(0.0f) - , PrevThrottle(0.0f) - , ThrottleDelta(0.0f) - , Brakes(0.0f) - , PrevBrakes(0.0f) - , BrakesDelta(0.0f) - , field_BC(0.0f) - , field_C0(0.0f) - , Matrix(IDENTITY) -{ - time_delta = 10.0f; -} +// ?time_delta@@3MA +ARTS_EXPORT f32 time_delta = 10.0f; void mmNetObject::Activate() { @@ -129,14 +103,14 @@ void mmNetObject::PositionUpdate(NETGAME_MSG* msg) { MatrixChanged = true; - if ((msg->LastUpdateIdx < 0) || (static_cast(msg->LastUpdateIdx) < UpdateCount)) + if (msg->LastUpdateIdx < UpdateCount) return; UpdateCount = msg->LastUpdateIdx; Car->Sim.Steering = msg->Steering; - Car->Sim.Brakes = static_cast(msg->Brakes) / 255.0f; - Car->Sim.Engine.Throttle = static_cast(msg->Throttle) / 255.0f; + Car->Sim.Brakes = msg->Brakes / 255.0f; + Car->Sim.Engine.Throttle = msg->Throttle / 255.0f; Car->Sim.CurrentDamage = msg->Damage; ICS->LinearMomentum = msg->Velocity; @@ -277,8 +251,8 @@ void mmNetObject::ReInit(mmCar* car, char* vehicle, i32 variant, ulong player_id field_C0 = 0.0f; Matrix.Identity(); UpdateCount = 0; - MatrixChanged = 0; - IsEnabled = 0; + MatrixChanged = false; + IsEnabled = false; Flags = 0; Score = 0; ICS = car->GetICS(); @@ -342,14 +316,14 @@ void mmNetObject::Update() ActivateTime += ARTSPTR->GetUpdateDelta(); + PHYS.DeclareMover( + &Car->Model, MOVER_TYPE_PERM, MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS); + if (Car->Model.HasTrailer()) { PHYS.DeclareMover(&Car->Trailer->Inst, MOVER_TYPE_10, MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS); } - PHYS.DeclareMover( - &Car->Model, MOVER_TYPE_PERM, MOVER_FLAG_ACTIVE | MOVER_FLAG_COLLIDE_TERRAIN | MOVER_FLAG_COLLIDE_MOVERS); - asNetObject::Update(); } \ No newline at end of file diff --git a/code/midtown/mmgame/netobject.h b/code/midtown/mmgame/netobject.h index 01f971bd..f6b3eeac 100644 --- a/code/midtown/mmgame/netobject.h +++ b/code/midtown/mmgame/netobject.h @@ -29,8 +29,8 @@ struct NETGAME_MSG i32 MessageId; i32 SenderId; f32 Steering; - char Throttle; - char Brakes; + u8 Throttle; + u8 Brakes; Vector3 Rotation; Vector3 Position; Vector3 Velocity; @@ -38,7 +38,7 @@ struct NETGAME_MSG f32 Damage; u16 Score; u16 Flags; - i32 LastUpdateIdx; + u32 LastUpdateIdx; char StringValue[4]; }; @@ -92,10 +92,10 @@ class mmNetObject final : public asNetObject u32 Flags; i32 Score; f32 Time; - NETGAME_MSG LocalData; + NETGAME_MSG LocalData {}; mmCar* Car; b32 IsEnabled; - u32 Active; + b32 Active; u32 UpdateCount; b32 MatrixChanged; f32 ActivateTime; @@ -110,10 +110,7 @@ class mmNetObject final : public asNetObject f32 BrakesDelta; f32 field_BC; f32 field_C0; - Matrix34 Matrix; + Matrix34 Matrix = IDENTITY; }; check_size(mmNetObject, 0xF4); - -// ?time_delta@@3MA -ARTS_IMPORT extern f32 time_delta; From 6daff008d49b8d92daa9985d541469889598ced3 Mon Sep 17 00:00:00 2001 From: Robin <99972691+KcRobin9@users.noreply.github.com> Date: Sun, 7 Sep 2025 02:46:12 +0200 Subject: [PATCH 5/5] Address Review Comments II --- code/midtown/mmgame/netobject.cpp | 7 ++-- code/midtown/mmgame/netobject.h | 60 ++++++++++++++++++------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/code/midtown/mmgame/netobject.cpp b/code/midtown/mmgame/netobject.cpp index d618531b..3ca3960a 100644 --- a/code/midtown/mmgame/netobject.cpp +++ b/code/midtown/mmgame/netobject.cpp @@ -28,8 +28,7 @@ define_dummy_symbol(mmgame_netobject); #include "mmnetwork/network.h" -// ?time_delta@@3MA -ARTS_EXPORT f32 time_delta = 10.0f; +f32 time_delta = 10.0f; void mmNetObject::Activate() { @@ -56,9 +55,7 @@ void mmNetObject::Clear() Score = 0; if (Car) - { Car->RemoveVehicleAudio(); - } SetCar(nullptr); PlayerID = 0; @@ -277,7 +274,7 @@ void mmNetObject::SetLocalData() return; LocalData.SenderId = PlayerID; - LocalData.MessageId = 501; + LocalData.MessageId = PlayerUpdate; LocalData.Steering = Car->Sim.Steering; LocalData.Throttle = static_cast(Car->Sim.Engine.Throttle * 255.0f); diff --git a/code/midtown/mmgame/netobject.h b/code/midtown/mmgame/netobject.h index f6b3eeac..8985fb61 100644 --- a/code/midtown/mmgame/netobject.h +++ b/code/midtown/mmgame/netobject.h @@ -24,6 +24,17 @@ class mmCar; +#define NET_FLAG_HORN 0x2 +#define NET_FLAG_REVERSE 0x4 +#define NET_FLAG_SIREN 0x8 + +enum NetgameMessageId +{ + PlayerUpdate = 501, + Chat = 504, + BootPlayer = 513, +}; + struct NETGAME_MSG { i32 MessageId; @@ -42,10 +53,6 @@ struct NETGAME_MSG char StringValue[4]; }; -#define NET_FLAG_HORN 0x2 -#define NET_FLAG_REVERSE 0x4 -#define NET_FLAG_SIREN 0x8 - class mmNetObject final : public asNetObject { public: @@ -88,29 +95,32 @@ class mmNetObject final : public asNetObject // ?Update@mmNetObject@@UAEXXZ ARTS_EXPORT void Update() override; - u32 field_28; - u32 Flags; - i32 Score; - f32 Time; + u32 field_28 {}; + u32 Flags {}; + i32 Score {}; + f32 Time {}; NETGAME_MSG LocalData {}; - mmCar* Car; - b32 IsEnabled; - b32 Active; - u32 UpdateCount; - b32 MatrixChanged; - f32 ActivateTime; - f32 Steering; - f32 PrevSteering; - f32 SteeringDelta; - f32 Throttle; - f32 PrevThrottle; - f32 ThrottleDelta; - f32 Brakes; - f32 PrevBrakes; - f32 BrakesDelta; - f32 field_BC; - f32 field_C0; + mmCar* Car {}; + b32 IsEnabled {}; + b32 Active {}; + u32 UpdateCount {}; + b32 MatrixChanged {}; + f32 ActivateTime {}; + f32 Steering {}; + f32 PrevSteering {}; + f32 SteeringDelta {}; + f32 Throttle {}; + f32 PrevThrottle {}; + f32 ThrottleDelta {}; + f32 Brakes {}; + f32 PrevBrakes {}; + f32 BrakesDelta {}; + f32 field_BC {}; + f32 field_C0 {}; Matrix34 Matrix = IDENTITY; }; check_size(mmNetObject, 0xF4); + +// ?time_delta@@3MA +ARTS_EXPORT extern f32 time_delta; \ No newline at end of file