|
1 | 1 | #include "flap.h" |
2 | 2 |
|
3 | 3 | #include "car.h" |
| 4 | +#include "compress.h" |
4 | 5 | #include "crush.h" |
| 6 | +#include "globvars.h" |
| 7 | +#include "globvrpb.h" |
| 8 | +#include "network.h" |
5 | 9 | #include "physics.h" |
6 | 10 | #include "piping.h" |
7 | 11 |
|
@@ -50,13 +54,131 @@ void C2_HOOK_FASTCALL SendSemiDetachBit(tCar_spec* pCar, br_actor* pActor, float |
50 | 54 | } |
51 | 55 | C2_HOOK_FUNCTION_ORIGINAL(0x0042dab0, SendSemiDetachBit, SendSemiDetachBit_original) |
52 | 56 |
|
| 57 | +int C2_HOOK_FASTCALL BitIsInBentPartOfCar(br_actor* pActor, float pArg2, float pArg3) { |
| 58 | + tCar_spec* car; |
| 59 | + float delta; |
| 60 | + |
| 61 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tCar_spec, old_frame_mat, 0x1c); |
| 62 | + |
| 63 | + if (pActor->user == NULL) { |
| 64 | + return 1; |
| 65 | + } |
| 66 | + /* FIXME: what type is stored in pActor->user? */ |
| 67 | + car = *(tCar_spec**)pActor->user; |
| 68 | + if (car == NULL) { |
| 69 | + return 1; |
| 70 | + } |
| 71 | + delta = .4f * (pArg2 - pArg3); |
| 72 | + if (delta < 0.f) { |
| 73 | + return pArg3 + delta > car->old_frame_mat.m[2][2]; |
| 74 | + } else { |
| 75 | + return pArg3 + delta < car->old_frame_mat.m[3][2]; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +void C2_HOOK_FASTCALL SendDetachBit(tCar_spec* pCar, br_actor* pActor) { |
| 80 | + tNet_message* message; |
| 81 | + br_vector3 p1; |
| 82 | + br_vector3 p2; |
| 83 | + br_vector3 p3; |
| 84 | + br_bounds3 bnds; |
| 85 | + |
| 86 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tNet_message, guaranteed.contents.detach_bit.ID, 0x1c); |
| 87 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tNet_message, guaranteed.contents.detach_bit.field_0x4, 0x20); |
| 88 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tNet_message, guaranteed.contents.detach_bit.field_0x8, 0x24); |
| 89 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tNet_message, guaranteed.contents.detach_bit.bounds_min, 0x28); |
| 90 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tNet_message, guaranteed.contents.detach_bit.bounds_max, 0x2e); |
| 91 | + |
| 92 | +#if !defined(C2_HOOKS_ENABLED) |
| 93 | + NOT_IMPLEMENTED(); /* FIXME: what type is pActor->user? */ |
| 94 | +#endif |
| 95 | + |
| 96 | + message = NetBuildGuaranteedMessage(51, 0); |
| 97 | + message->guaranteed.contents.detach_bit.ID = NetPlayerFromCar(pCar)->ID; |
| 98 | + message->guaranteed.contents.detach_bit.field_0x4 = ((undefined**)pActor->user)[0x8][0x20]; |
| 99 | + message->guaranteed.contents.detach_bit.field_0x8 = C2V(gPHIL_last_physics_tick) + 120; |
| 100 | + if (!GetSDBJointPosAndBounds(&p1, &p2, &p3, &bnds, pActor)) { |
| 101 | + CompressVector3(&message->guaranteed.contents.detach_bit.bounds_min, &bnds.min, -10.f, 10.f); |
| 102 | + CompressVector3(&message->guaranteed.contents.detach_bit.bounds_max, &bnds.max, -10.f, 10.f); |
| 103 | + NetGuaranteedSendMessageToEverybody(C2V(gCurrent_net_game), message, 0); |
| 104 | + } |
| 105 | +} |
| 106 | + |
53 | 107 | void (C2_HOOK_FASTCALL * DoDetaching_original)(void); |
54 | 108 | void C2_HOOK_FASTCALL DoDetaching(void) { |
55 | 109 |
|
56 | | -#if defined(C2_HOOKS_ENABLED) |
| 110 | +#if 0//defined(C2_HOOKS_ENABLED) |
57 | 111 | DoDetaching_original(); |
58 | 112 | #else |
59 | | - NOT_IMPLEMENTED(); |
| 113 | + |
| 114 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tCar_crush_spec, field_0x174, 0x174); |
| 115 | + C2_HOOK_STATIC_ASSERT_STRUCT_OFFSET(tCar_crush_spec, field_0x180, 0x180); |
| 116 | + |
| 117 | + if (C2V(gNet_mode) == eNet_mode_none || C2V(gNet_mode) == eNet_mode_host) { |
| 118 | + int new_count_crush_detach_list; |
| 119 | + int i; |
| 120 | + |
| 121 | + new_count_crush_detach_list = 0; |
| 122 | + for (i = 0; i < C2V(gCount_crush_detach_list); i++) { |
| 123 | + tCrush_detach_list_item* detach_list_item; |
| 124 | + int keep; |
| 125 | + int synced; |
| 126 | + |
| 127 | + detach_list_item = &C2V(gCrush_detach_list)[i]; |
| 128 | + keep = 1; |
| 129 | + synced = 0; |
| 130 | + if (C2V(gPHIL_last_physics_tick) >= detach_list_item->time) { |
| 131 | + keep = 0; |
| 132 | + |
| 133 | + if (!((detach_list_item->car->car_crush_spec->field_0x144 |
| 134 | + && BitIsInBentPartOfCar(detach_list_item->actor, |
| 135 | + detach_list_item->car->car_crush_spec->field_0x174, |
| 136 | + detach_list_item->car->car_crush_spec->field_0x180)) |
| 137 | + || detach_list_item->car->car_crush_spec->field_0x4b8)) { |
| 138 | + |
| 139 | + if (C2V(gNet_mode) == eNet_mode_none) { |
| 140 | + if (detach_list_item->field_0x10) { |
| 141 | + |
| 142 | + DetachBit(detach_list_item->car, detach_list_item->actor, NULL); |
| 143 | + } else { |
| 144 | + SemiDetachBit(detach_list_item->car, detach_list_item->actor, detach_list_item->field_0x8, &keep, NULL, NULL, NULL, NULL); |
| 145 | + } |
| 146 | + } else { |
| 147 | + if (detach_list_item->field_0x10) { |
| 148 | + int j; |
| 149 | + |
| 150 | + for (j = 0; j < C2V(gCount_net_crush_detach_list); j++) { |
| 151 | + if (C2V(gNet_crush_detach_list)[j].actor == detach_list_item->actor) { |
| 152 | + synced = 1; |
| 153 | + break; |
| 154 | + } |
| 155 | + } |
| 156 | + if (!synced) { |
| 157 | + SendDetachBit(detach_list_item->car, detach_list_item->actor); |
| 158 | + } |
| 159 | + } else { |
| 160 | + int j; |
| 161 | + |
| 162 | + for (j = 0; j < C2V(gCount_net_crush_semi_detach_bit_list); j++) { |
| 163 | + if (C2V(gNet_crush_semi_detach_bit_list)[j].actor == detach_list_item->actor) { |
| 164 | + synced = 1; |
| 165 | + break; |
| 166 | + } |
| 167 | + } |
| 168 | + if (!synced) { |
| 169 | + SendSemiDetachBit(detach_list_item->car, detach_list_item->actor, detach_list_item->field_0x8, NULL); |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + if (keep && i != new_count_crush_detach_list) { |
| 176 | + C2V(gCrush_detach_list)[new_count_crush_detach_list] = C2V(gCrush_detach_list)[i]; |
| 177 | + new_count_crush_detach_list += 1; |
| 178 | + } |
| 179 | + } |
| 180 | + C2V(gCount_crush_detach_list) = new_count_crush_detach_list; |
| 181 | + } |
60 | 182 | #endif |
61 | 183 | } |
62 | 184 | C2_HOOK_FUNCTION_ORIGINAL(0x00436ad0, DoDetaching, DoDetaching_original) |
|
0 commit comments