-
Notifications
You must be signed in to change notification settings - Fork 46
/
cheat_vehicle.cpp
1871 lines (1574 loc) · 49.5 KB
/
cheat_vehicle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
PROJECT: mod_sa
LICENSE: See LICENSE in the top level directory
COPYRIGHT: Copyright we_sux, BlastHack
mod_sa is available from https://github.com/BlastHackNet/mod_s0beit_sa/
mod_sa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mod_sa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mod_sa. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
// new function to jump into vehicles without jacking (also for single player)
bool vehicleJumper ( int iVehicleID )
{
// can't touch this
if ( iVehicleID == VEHICLE_SELF )
return false;
// get vehicle_info
struct vehicle_info *pVehicle = vehicle_info_get( iVehicleID, 0 );
// check that the vehicle is legit
if ( isBadPtr_GTA_pVehicle(pVehicle) )
return false;
traceLastFunc( "vehicleJumper()" );
// if SAMP is loaded, check if the vehicle is streamed in
if ( g_SAMP != NULL )
{
int iVehicleSAMPID = getSAMPVehicleIDFromGTAVehicle( pVehicle );
if ( isBadSAMPVehicleID(iVehicleSAMPID) )
return false;
}
if ( pVehicle->hitpoints == 0.0f )
{
cheat_state_text( "Vehicle is destroyed" );
return false;
}
if ( cheat_state->actor.air_brake )
{
cheat_state_text( "On foot airbrake must be disabled" );
return false;
}
if ( cheat_state->actor.stick )
{
cheat_state_text( "On foot stick must be disabled" );
return false;
}
if ( !pVehicle->base.bIsVisible )
{
cheat_state_text( "Vehicle is not visible." );
return false;
}
struct actor_info *self = actor_info_get( ACTOR_SELF, 0 );
if ( self != NULL && pVehicle->base.interior_id != self->base.interior_id )
{
cheat_state_text( "Vehicle is in another interior." );
return false;
}
int iGTAVehicleID;
iGTAVehicleID = ScriptCarId( pVehicle );
if ( pVehicle->passengers[0] == self )
return false;
if ( !pVehicle->base.bUsesCollision )
pVehicle->base.bUsesCollision = 1;
// put into first available seat
if ( pVehicle->passengers[0] == NULL )
{
GTAfunc_PutActorInCar(GetVehicleByGtaId(iGTAVehicleID));
pGameInterface->GetCamera()->RestoreWithJumpCut();
return true;
}
const int seat_count = gta_vehicle_get_by_id( pVehicle->base.model_alt_id )->passengers;
if ( seat_count > 0 )
{
for ( int seat = 1; seat <= seat_count; seat++ )
{
if ( pVehicle->passengers[seat] == NULL )
{
GTAfunc_PutActorInCarAsPassenger(GetVehicleByGtaId((iGTAVehicleID)), seat - 1);
pGameInterface->GetCamera()->RestoreWithJumpCut();
return true;
}
}
}
// no seats left, oh well
cheat_state_text( "No seats left to teleport into." );
return false;
}
void cheat_vehicle_teleport ( struct vehicle_info *info, const float pos[3], int interior_id, bool keepSpeed )
{
if ( info == NULL )
return;
traceLastFunc( "cheat_vehicle_teleport()" );
float diff[3];
float new_pos[3];
struct vehicle_info *temp;
vect3_vect3_sub( pos, &info->base.matrix[4 * 3], diff );
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
vect3_vect3_add( &temp->base.matrix[4 * 3], diff, new_pos );
vehicle_detachables_teleport( temp, &temp->base.matrix[4 * 3], new_pos );
vect3_copy( new_pos, &temp->base.matrix[4 * 3] );
if (!keepSpeed)
{
vect3_zero(temp->speed);
vect3_zero(temp->spin);
}
gta_interior_id_set( interior_id );
temp->base.interior_id = ( uint8_t ) interior_id;
if ( !set.trailer_support )
break;
}
}
void cheat_handle_vehicle_unflip ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_unflip()" );
/* Unflip */
//if ( KEY_PRESSED(set.key_unflip) )
//{ }
/* Rotate vehicle while the unflip key is held down */
if ( KEYCOMBO_DOWN(set.key_unflip) )
{
traceLastFunc( "cheat_handle_vehicle_unflip()" );
// inter-frame timing info from the game
float fTimeStep = *(float *)0xB7CB5C;
// get our vehicle, gravity, and matrix
CVehicle *cveh = getSelfCVehicle();
CVector cvehGrav;
CMatrix cvehMatrix;
cveh->GetGravity( &cvehGrav );
cveh->GetMatrix( &cvehMatrix );
// get "down" from vehicle model
CVector rotationAxis = cheat_vehicle_getPositionUnder( cveh );
// normalize our vectors
cvehGrav.Normalize();
rotationAxis.Normalize();
// axis and rotation for gravity
float theta = acos( rotationAxis.DotProduct(&cvehGrav) );
if ( !near_zero(theta) )
{
rotationAxis.CrossProduct( &cvehGrav );
rotationAxis.Normalize();
rotationAxis.ZeroNearZero();
cvehMatrix = cvehMatrix.Rotate( &rotationAxis, -theta );
}
// slow turn to the right
theta = M_PI / ( 75.0f / fTimeStep );
CVector slowTurnAxis = cvehMatrix.vUp;
slowTurnAxis.Normalize();
slowTurnAxis.ZeroNearZero();
cvehMatrix = cvehMatrix.Rotate( &cvehMatrix.vUp, theta );
// set the new matrix
cveh->SetMatrix( &cvehMatrix );
// no more spin cycle for you
CVector vZero ( 0.0f, 0.0f, 0.0f );
cveh->SetTurnSpeed( &vZero );
}
}
void cheat_vehicle_air_brake_set ( int enabled )
{
cheat_state->vehicle.air_brake = enabled;
cheat_handle_vehicle_air_brake( NULL, 0.0f );
}
void cheat_handle_vehicle_air_brake ( struct vehicle_info *info, double time_diff )
{
static float orig_matrix[16];
static int orig_matrix_set;
struct vehicle_info *temp;
if ( info == NULL )
{
orig_matrix_set = 0;
return;
}
traceLastFunc( "cheat_handle_vehicle_air_brake()" );
// handle key presses
if ( set.air_brake_toggle )
{
if ( KEYCOMBO_PRESSED(set.key_air_brake_mod) )
cheat_state->vehicle.air_brake ^= 1;
if ( KEYCOMBO_PRESSED(set.key_air_brake_mod2) && cheat_state->vehicle.air_brake )
cheat_state->vehicle.air_brake_slowmo ^= 1;
}
else
{
if ( KEYCOMBO_PRESSED(set.key_air_brake_mod) )
cheat_state->vehicle.air_brake = 1;
else if ( KEYCOMBO_RELEASED(set.key_air_brake_mod) )
cheat_state->vehicle.air_brake = 0;
if ( KEYCOMBO_PRESSED(set.key_air_brake_mod2) && cheat_state->vehicle.air_brake )
cheat_state->vehicle.air_brake_slowmo = 1;
else if ( KEYCOMBO_RELEASED(set.key_air_brake_mod2) && cheat_state->vehicle.air_brake )
cheat_state->vehicle.air_brake_slowmo = 0;
}
// do airbrake
if ( !cheat_state->vehicle.air_brake )
{
orig_matrix_set = 0;
cheat_state->vehicle.air_brake_slowmo = 0;
}
else
{
if ( !orig_matrix_set )
{
matrix_copy( info->base.matrix, orig_matrix );
orig_matrix_set = 1;
}
if ( !KEYCOMBO_DOWN(set.key_unflip) ) /* allow the unflip rotation feature to work */
matrix_copy( orig_matrix, info->base.matrix );
/* XXX allow some movement */
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
/* prevent all kinds of movement */
vect3_zero( temp->speed );
vect3_zero( temp->spin );
if ( !set.trailer_support )
break;
}
static uint32_t time_start;
float *matrix = info->base.matrix;
float d[4] = { 0.0f, 0.0f, 0.0f, (float) time_diff * set.air_brake_speed };
float xyvect[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; /* rotation vector */
float zvect[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; /* rotation vector */
float theta = set.air_brake_rot_speed * (float) time_diff * M_PI * 2.0f;
if ( cheat_state->vehicle.air_brake_slowmo )
{
d[3] /= 10.0f;
theta /= 2.0f;
}
if ( KEYCOMBO_DOWN(set.key_air_brake_forward) )
d[0] += 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_backward) )
d[0] -= 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_left) )
d[1] += 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_right) )
d[1] -= 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_up) )
d[2] += 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_down) )
d[2] -= 1.0f;
if ( !near_zero(set.air_brake_accel_time) )
{
if ( !vect3_near_zero(d) )
time_start = ( time_start == 0 ) ? time_get() : time_start;
else
time_start = 0; /* no keys pressed */
/* acceleration */
if ( time_start != 0 )
{
float t = TIME_TO_FLOAT( time_get() - time_start );
if ( t < set.air_brake_accel_time )
d[3] *= t / set.air_brake_accel_time;
}
}
/* pitch (x-axis) */
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_pitch1) )
xyvect[0] += 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_pitch2) )
xyvect[0] -= 1.0f;
/* roll (y-axis) */
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_roll1) )
xyvect[1] += 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_roll2) )
xyvect[1] -= 1.0f;
/* yaw (z-axis) */
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_yaw1) )
zvect[2] -= 1.0f;
if ( KEYCOMBO_DOWN(set.key_air_brake_rot_yaw2) )
zvect[2] += 1.0f;
if ( !vect3_near_zero(xyvect) )
{
vect3_normalize( xyvect, xyvect );
matrix_vect4_mult( matrix, xyvect, xyvect );
matrix_vect3_rotate( matrix, xyvect, theta, matrix );
}
if ( !vect3_near_zero(zvect) )
{
vect3_normalize( zvect, zvect );
matrix_vect3_rotate( matrix, zvect, theta, matrix );
}
switch ( set.air_brake_behaviour )
{
case 0:
matrix[4 * 1 + 0] += d[0] * d[3];
matrix[4 * 1 + 1] += d[1] * d[3];
matrix[4 * 1 + 2] += d[2] * d[3];
break;
case 1: /* mixed 2d/3d mode */
{
/* convert the vehicle's 3d rotation vector to a 2d angle */
float a = atan2f( matrix[4 * 1 + 0], matrix[4 * 1 + 1] );
/* calculate new position */
matrix[4 * 3 + 0] += ( d[0] * sinf(a) - d[1] * cosf(a) ) * d[3];
matrix[4 * 3 + 1] += ( d[0] * cosf(a) + d[1] * sinf(a) ) * d[3];
matrix[4 * 3 + 2] += d[2] * d[3];
}
break;
case 2: /* full 3d movement */
if ( !vect3_near_zero(d) )
{
float vect[4] = { -d[1], d[0], d[2], 0.0f }; /* swap x & y + invert y */
float out[4];
/* out = matrix * norm(d) */
vect3_normalize( vect, vect );
matrix_vect4_mult( matrix, vect, out );
matrix[4 * 3 + 0] += out[0] * d[3];
matrix[4 * 3 + 1] += out[1] * d[3];
matrix[4 * 3 + 2] += out[2] * d[3];
}
break;
}
matrix_copy( matrix, orig_matrix );
// heh
int gonadsMult = 1000;
float strifeMult = 0.000001f;
int gonads = rand() % gonadsMult;
float strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fX = strife;
gonads = rand() % gonadsMult;
strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fY = strife;
strifeMult = 0.000000001f;
gonads = rand() % gonadsMult;
strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fZ = strife;
}
}
/*
Causing loading screen way too regulary.
void cheat_handle_vehicle_slowTeleport ( struct vehicle_info *vehicle_info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_slowTeleport()" );
if ( vehicle_info == NULL )
return;
if ( !set.teleport_slow || !cheat_state->vehicle.tele_on
|| KEY_PRESSED(set.key_slowTeleport_stop) )
{
cheat_state->vehicle.tele_on = 0;
return;
}
// inveh cross-map-teleport-alike-flying
if ( set.teleport_slow && cheat_state->vehicle.tele_on &&
cheat_state->state == CHEAT_STATE_VEHICLE && vehicle_info != NULL )
{
if ( vect3_dist(cheat_state->vehicle.tele_coords,
&vehicle_info->base.matrix[4*3]) < 5.0 )
{
cheat_state->vehicle.tele_on = 0;
vect3_zero( cheat_state->vehicle.tele_coords );
}
CVehicle *cveh = pPools->GetVehicle( (DWORD *)vehicle_info );
CMatrix cvehMatrix;
cveh->GetMatrix( &cvehMatrix );
CVector *veh_vect = cveh->GetPosition();
CVector LocationVect;
CVector vectToLocation;
LocationVect.fX = cheat_state->vehicle.tele_coords[0];
LocationVect.fY = cheat_state->vehicle.tele_coords[1];
LocationVect.fZ = cheat_state->vehicle.tele_coords[2];
vectToLocation = *veh_vect - LocationVect;
// direction
CVector up = cvehMatrix.vUp;
up.CrossProduct( &vectToLocation );
up.Normalize();
CVector down = up;
down.CrossProduct( &cvehMatrix.vUp );
down.Normalize();
CVector moredown = down;
moredown.CrossProduct( &up );
cvehMatrix.vRight = up;
cvehMatrix.vUp = moredown;
cvehMatrix.vFront = -down;
cveh->SetMatrix( &cvehMatrix );
// height
CVector front = cvehMatrix.vFront;
front.CrossProduct( &vectToLocation );
front.Normalize();
CVector back = front;
back.CrossProduct( &cvehMatrix.vFront );
back.Normalize();
CVector moreback = back;
moreback.CrossProduct( &front );
moreback.Normalize();
cvehMatrix.vRight = -back;
cvehMatrix.vUp = front;
cvehMatrix.vFront = moreback;
cveh->SetMatrix( &cvehMatrix );
// set speed into direction car is facing
float dir[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
float vect[4];
matrix_vect4_mult( vehicle_info->base.matrix, dir, vect );
if ( !vect3_near_zero(vect) && !vect3_near_zero(vehicle_info->speed) )
{
float speed = vect3_length( vehicle_info->speed );
vect3_mult( vect, speed, vehicle_info->speed );
}
//set speed end
}
}
*/
void cheat_handle_vehicle_warp ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_warp()" );
static struct vehicle_state state;
static float raildist;
static uint32_t warp_time = 0;
static int warping = 0;
if ( warp_time != 0 )
{
if ( time_get() - warp_time > MSEC_TO_TIME(100) )
{
warp_time = 0;
}
else
{
vehicle_state_restore( info, &state );
if ( info->vehicle_type == VEHICLE_TYPE_TRAIN )
info->m_fTrainRailDistance = raildist;
}
}
/* warp factor: fuck you */
if ( KEYCOMBO_PRESSED(set.key_warp_mod) )
{
struct vehicle_info *temp;
float dir[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
float vect[4];
if ( set.warp_use_speed && !vect3_near_zero(info->speed) && vect3_length(info->speed) >= 0.01f )
{
/* use normalized speed vector */
vect3_copy( info->speed, dir );
vect3_normalize( dir, vect );
}
else
{
/* use vehicle direction matrix */
matrix_vect4_mult( info->base.matrix, dir, vect );
if ( vect3_near_zero(vect) )
return; /* shouldn't happen */
}
vehicle_state_store( info, &state );
if ( info->vehicle_type == VEHICLE_TYPE_TRAIN )
raildist = info->m_fTrainRailDistance;
warp_time = 0;
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
vect3_mult( vect, set.warp_speed, temp->speed );
if ( !set.trailer_support )
break;
}
}
if ( KEYCOMBO_DOWN(set.key_warp_mod) && info->vehicle_type == VEHICLE_TYPE_TRAIN )
info->m_fTrainSpeed = set.warp_speed;
if ( KEYCOMBO_RELEASED(set.key_warp_mod) )
{
struct vehicle_info *temp;
warp_time = time_get();
vehicle_state_restore( info, &state );
if ( info->vehicle_type == VEHICLE_TYPE_TRAIN )
info->m_fTrainRailDistance = raildist;
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
temp->collision_something = 0.0f;
if ( !set.trailer_support )
break;
}
}
}
void cheat_handle_vehicle_hop ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_hop()" );
if ( KEYCOMBO_DOWN(set.key_vehicle_hop) )
{
CVehicle *cveh = pGameInterface->GetPools()->GetVehicle( (DWORD *)info );
CVector vecSpeedAdd, vecMoveSpeed;
float theDotProduct;
bool isBigHop = false;
bool isHopThisFrame = false;
cveh->GetGravity( &vecSpeedAdd );
vecSpeedAdd = -vecSpeedAdd;
cveh->GetMoveSpeed( &vecMoveSpeed );
theDotProduct = vecMoveSpeed.DotProduct( &vecSpeedAdd );
if ( theDotProduct < set.vehicle_hop_speed / 2.0f )
isHopThisFrame = true;
if ( theDotProduct < -0.1f )
isBigHop = true;
for ( ; cveh != NULL; cveh = cveh->GetTowedVehicle() )
{
cveh->GetMoveSpeed( &vecMoveSpeed );
if ( isHopThisFrame )
{
if ( isBigHop )
vecMoveSpeed += ( vecSpeedAdd * (set.vehicle_hop_speed * 2.0f) );
else
vecMoveSpeed += ( vecSpeedAdd * (set.vehicle_hop_speed / 2.0f) );
cveh->SetMoveSpeed( &vecMoveSpeed );
}
//set.vehicle_hop_speed;
if ( !set.trailer_support )
break;
}
}
}
void cheat_handle_vehicle_brake ( struct vehicle_info *info, double time_diff )
{
traceLastFunc( "cheat_handle_vehicle_brake()" );
float speed;
struct vehicle_info *temp;
if ( KEYCOMBO_DOWN(set.key_brake_mod) && !cheat_state->vehicle.air_brake )
{
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
speed = vect3_length( temp->speed );
vect3_normalize( temp->speed, temp->speed );
speed -= time_diff * set.brake_mult / 1.3f;
if ( speed < 0.0f )
speed = 0.0f;
if ( vect3_near_zero(temp->speed) )
{
vect3_zero( temp->speed );
}
else
{
if ( temp->vehicle_type == VEHICLE_TYPE_TRAIN )
{
if ( temp->m_fTrainSpeed <= 0.05f && temp->m_fTrainSpeed >= -0.05f )
temp->m_fTrainSpeed = 0.0f;
else if ( temp->m_fTrainSpeed < 0.0f )
temp->m_fTrainSpeed += time_diff * set.brake_mult;
else
temp->m_fTrainSpeed -= time_diff * set.brake_mult;
}
vect3_mult( temp->speed, speed, temp->speed );
// heh
int gonadsMult = 1000;
float strifeMult = 0.0000001f;
int gonads = rand() % gonadsMult;
float strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fX += strife;
gonads = rand() % gonadsMult;
strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fY += strife;
}
if ( !set.trailer_support )
break;
}
}
}
void cheat_handle_vehicle_nitro ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_nitro()" );
static uint32_t timer;
static int decelerating;
static float speed_off;
float pre_speed[3];
struct vehicle_info *temp;
if ( KEYCOMBO_DOWN(set.key_warp_mod) )
vect3_copy( info->speed, pre_speed );
if ( KEYCOMBO_PRESSED(set.key_nitro_mod) )
{
speed_off = vect3_length( info->speed );
decelerating = 0;
timer = time_get();
}
/* "nitro" acceleration mod */
if ( KEYCOMBO_DOWN(set.key_nitro_mod) && !vect3_near_zero(info->speed) )
{
float etime = TIME_TO_FLOAT( time_get() - timer ) / set.nitro_accel_time;
float speed = set.nitro_high;
if ( !near_zero(set.nitro_accel_time) )
{
etime += 1.0f - ( set.nitro_high - speed_off ) / set.nitro_high;
if ( etime < 1.0f )
speed *= etime;
}
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
if ( !vect3_near_zero(temp->speed) )
{
if ( temp->vehicle_type == VEHICLE_TYPE_TRAIN )
{
if ( temp->m_fTrainSpeed < 0.0f && temp->m_fTrainSpeed > -set.nitro_high )
temp->m_fTrainSpeed -= speed;
else if ( temp->m_fTrainSpeed < set.nitro_high )
temp->m_fTrainSpeed += speed;
}
vect3_normalize( temp->speed, temp->speed );
vect3_mult( temp->speed, speed, temp->speed );
if ( vect3_near_zero(temp->speed) )
vect3_zero( temp->speed );
}
if ( !set.trailer_support )
break;
}
// heh
int gonadsMult = 1000;
float strifeMult = 0.0000001f;
int gonads = rand() % gonadsMult;
float strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fX += strife;
gonads = rand() % gonadsMult;
strife = (double)gonads * strifeMult;
if ( strife < strifeMult * gonadsMult / 2 )
strife -= strifeMult * gonadsMult;
info->m_SpeedVec.fY += strife;
}
if ( KEYCOMBO_RELEASED(set.key_nitro_mod) )
{
if ( vect3_length(info->speed) > set.nitro_low )
{
speed_off = vect3_length( info->speed );
decelerating = 1;
timer = time_get();
}
}
if ( decelerating )
{
float speed = set.nitro_low;
float etime = TIME_TO_FLOAT( time_get() - timer );
if ( etime < set.nitro_decel_time )
speed = speed_off - ( speed_off - speed ) * ( etime / set.nitro_decel_time );
else
decelerating = 0;
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
if ( vect3_length(temp->speed) > speed )
{
vect3_normalize( temp->speed, temp->speed );
vect3_mult( temp->speed, speed, temp->speed );
}
/* // first fix trains before uncommenting this..
if ( temp->vehicle_type == VEHICLE_TYPE_TRAIN )
{
if ( temp->m_fTrainSpeed > speed )
temp->m_fTrainSpeed = vect3_length( temp->speed );
else if ( temp->m_fTrainSpeed < -speed )
temp->m_fTrainSpeed = -vect3_length( temp->speed );
}
*/
if ( !set.trailer_support )
break;
}
}
/* actual NOS of the game, toggle infinite NOS, w00t! */
if ( KEYCOMBO_PRESSED(set.key_nitro) )
{
if ( !cheat_state->vehicle.infNOS_toggle_on )
{
cheat_state->vehicle.infNOS_toggle_on = true;
patcher_install( &patch_vehicle_inf_NOS );
vehicle_addUpgrade( info, 1010 );
}
else
{
cheat_state->vehicle.infNOS_toggle_on = false;
patcher_remove( &patch_vehicle_inf_NOS );
GTAfunc_removeVehicleUpgrade( info, 1010 );
}
}
}
//MATRIX4X4
// VECTOR right
// float X [4*0+0]
// float Y [4*0+1]
// float Z [4*0+2] Roll
// DWORD flags;
// VECTOR up;
// float X [4*1+0]
// float Y [4*1+1]
// float Z [4*1+2] Pitch
// float pad_u;
// VECTOR at; Front
// float X [4*2+0]
// float Y [4*2+1]
// float Z [4*2+2] Yaw
//
void cheat_handle_vehicle_quick_turn ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_quick_turn()" );
if ( KEYCOMBO_PRESSED(set.key_quick_turn_180) )
{
/* simply invert the X and Y axis.. */
for ( struct vehicle_info * temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
vect3_invert( &temp->base.matrix[4 * 0], &temp->base.matrix[4 * 0] );
vect3_invert( &temp->base.matrix[4 * 1], &temp->base.matrix[4 * 1] );
vect3_invert( temp->speed, temp->speed );
if ( !cheat_state->vehicle.keep_trailer_attached || !set.trailer_support )
break;
}
if ( info->vehicle_type == VEHICLE_TYPE_TRAIN )
{
for ( struct vehicle_info * temp = info; temp != NULL; temp = temp->m_train_next_carriage )
{
if(temp == NULL) return;
if ( !g_SAMP )
{
temp->m_trainFlags.bDirection ^= 1;
if ( info->m_train_next_carriage == temp && info->base.model_alt_id == 538 )
{ //avoid brown streak bug
if ( temp->m_fDistanceToNextCarriage == 16.5f )
temp->m_fDistanceToNextCarriage = 20.8718f;
else
temp->m_fDistanceToNextCarriage = -16.5f;
}
temp->m_fDistanceToNextCarriage *= -1;
}
temp->m_fTrainSpeed = -info->m_fTrainSpeed;
}
}
}
if ( KEYCOMBO_PRESSED(set.key_quick_turn_left) )
{
struct vehicle_info *temp;
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
// do new heading
float *heading_matrix = temp->base.matrix;
MATRIX4X4 *heading_matrix4x4 = temp->base.matrixStruct;
// rotate on z axis
CVehicle *cveh = pGameInterface->GetPools()->GetVehicle( (DWORD *)temp );
CVector posUnder = cheat_vehicle_getPositionUnder( cveh );
float heading_vector_zrotate[3] = { posUnder.fX, posUnder.fY, posUnder.fZ };
float heading_theta = M_PI / 2.0f;
vect3_normalize( heading_vector_zrotate, heading_vector_zrotate );
matrix_vect3_rotate( heading_matrix, heading_vector_zrotate, heading_theta, heading_matrix );
// do new speed
if ( !temp->m_SpeedVec.IsNearZero() )
{
temp->m_SpeedVec.CrossProduct( &posUnder );
}
if ( !cheat_state->vehicle.keep_trailer_attached || !set.trailer_support )
break;
}
}
if ( KEYCOMBO_PRESSED(set.key_quick_turn_right) )
{
struct vehicle_info *temp;
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
// do new heading
float *heading_matrix = temp->base.matrix;
MATRIX4X4 *heading_matrix4x4 = temp->base.matrixStruct;
// rotate on z axis
CVehicle *cveh = pGameInterface->GetPools()->GetVehicle( (DWORD *)temp );
CVector posUnder = cheat_vehicle_getPositionUnder( cveh );
posUnder = -posUnder;
float heading_zvectrotate[4] = { posUnder.fX, posUnder.fY, posUnder.fZ };
float heading_theta = M_PI / 2.0f;
vect3_normalize( heading_zvectrotate, heading_zvectrotate );
matrix_vect3_rotate( heading_matrix, heading_zvectrotate, heading_theta, heading_matrix );
// do new speed
if ( !temp->m_SpeedVec.IsNearZero() )
{
temp->m_SpeedVec.CrossProduct( &posUnder );
}
if ( !cheat_state->vehicle.keep_trailer_attached || !set.trailer_support )
break;
}
}
}
void cheat_handle_vehicle_protection ( struct vehicle_info *info, float time_diff )
{
traceLastFunc( "cheat_handle_vehicle_protection()" );
static float last_spin[3];
struct vehicle_info *temp;
if ( KEYCOMBO_PRESSED(set.key_protection) )
cheat_state->vehicle.protection ^= 1;
if ( KEYCOMBO_DOWN(set.key_warp_mod) )
return;
if ( cheat_state->vehicle.protection )
{
for ( temp = info; temp != NULL; temp = temp->trailer )
{
if(temp == NULL) return;
if ( !vect3_near_zero(temp->spin) && vect3_length(temp->spin) > set.protection_spin_cap )
{
vect3_normalize( temp->spin, temp->spin );
vect3_mult( temp->spin, set.protection_spin_cap, temp->spin );
}
if ( !vect3_near_zero(temp->speed) && vect3_length(temp->speed) > set.protection_speed_cap )
{
vect3_normalize( temp->speed, temp->speed );
vect3_mult( temp->speed, set.protection_speed_cap, temp->speed );
}
if ( temp->base.matrix[4 * 2 + 2] < 0.0f )
{
if ( !vect3_near_zero(last_spin) && !vect3_near_zero(temp->spin) && vect3_length(temp->spin) < 0.10f )
{
vect3_normalize( temp->spin, temp->spin );
vect3_mult( temp->spin, 0.10f, temp->spin );
}
}
else if ( temp == info ) /* only copy the first vehicle's spin info */
{
vect3_copy( temp->spin, last_spin );
}
vehicle_prevent_below_height( temp, set.protection_min_height );
if ( !set.trailer_support )
break;
}
}
}
void cheat_handle_vehicle_engine ( struct vehicle_info *vehicle_info, float time_diff )
{
if ( vehicle_info == NULL )
return;
traceLastFunc( "cheat_handle_vehicle_engine()" );
struct vehicle_info *veh_self = vehicle_info_get( VEHICLE_SELF, 0 );