-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnpc_congaline.sp
771 lines (637 loc) · 29.7 KB
/
npc_congaline.sp
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
#include <sdktools>
#include <sdkhooks>
#include <tf2_stocks>
#include <PathFollower>
#include <PathFollower_Nav>
#include <dhooks>
#include <dynamic>
#include <CBaseAnimatingOverlay>
#pragma newdecls required;
#define RAD2DEG(%1) ((%1) * (180.0 / FLOAT_PI))
#define DEG2RAD(%1) ((%1) * FLOAT_PI / 180.0)
#define EF_BONEMERGE (1 << 0)
#define EF_PARENT_ANIMATES (1 << 9)
//SDKCalls
Handle g_hMyNextBotPointer;
Handle g_hGetLocomotionInterface;
Handle g_hGetBodyInterface;
Handle g_hRun;
Handle g_hApproach;
Handle g_hFaceTowards;
Handle g_hResetSequence;
Handle g_hGetVelocity;
Handle g_hSetVelocity;
Handle g_hStudioFrameAdvance;
Handle g_hJump;
Handle g_hGetMaxAcceleration;
Handle g_hGetGroundSpeed;
Handle g_hLookupPoseParameter;
Handle g_hSetPoseParameter;
Handle g_hGetPoseParameter;
Handle g_hLookupSequence;
Handle g_hAddGestureSequence;
Handle g_hSDKWorldSpaceCenter;
Handle g_hStudio_FindAttachment;
Handle g_hGetAttachment;
//Stuck detection
Handle g_hStuckMonitor;
Handle g_hClearStuckStatus;
Handle g_hIsStuck;
//DHooks
Handle g_hGetFrictionSideways;
Handle g_hGetStepHeight;
Handle g_hGetGravity;
Handle g_hGetGroundNormal;
Handle g_hShouldCollideWith;
Handle g_hGetSolidMask;
Handle g_hStartActivity;
Handle g_hGetHullWidth;
Handle g_hGetHullHeight;
Handle g_hGetStandHullHeight;
Handle g_hGetCrouchHullHeight;
//NavAreas
Address TheNavAreas;
Address navarea_count;
char s_cast[][] =
{
{"models/bots/skeleton_sniper/skeleton_sniper.mdl"},
{"models/bots/skeleton_sniper_boss/skeleton_sniper_boss.mdl"},
{"models/bots/engineer/bot_engineer.mdl"},
{"models/player/demo.mdl"},
{"models/player/engineer.mdl"},
{"models/player/heavy.mdl"},
{"models/player/medic.mdl"},
{"models/player/pyro.mdl"},
{"models/player/scout.mdl"},
{"models/player/sniper.mdl"},
{"models/player/soldier.mdl"},
{"models/player/spy.mdl"}
}
public Plugin myinfo =
{
name = "[TF2] NextBot Conga Line",
author = "Pelipoika",
description = "",
version = "1.0",
url = ""
};
methodmap BaseNPC
{
public BaseNPC(float vecPos[3], float vecAng[3], const char[] model, const char[] modelscale = "1.0", const char[] health = "100", bool bGroundNormal = true)
{
int npc = CreateEntityByName("base_boss");
DispatchKeyValueVector(npc, "origin", vecPos);
DispatchKeyValueVector(npc, "angles", vecAng);
DispatchKeyValue(npc, "model", s_cast[GetRandomInt(0, sizeof(s_cast) - 1)]);
DispatchKeyValue(npc, "modelscale", modelscale);
DispatchKeyValue(npc, "health", health);
DispatchSpawn(npc);
AcceptEntityInput(npc, "DisableShadow");
Address pNB = SDKCall(g_hMyNextBotPointer, npc);
Address pLocomotion = SDKCall(g_hGetLocomotionInterface, pNB);
DHookRaw(g_hGetStepHeight, true, pLocomotion);
DHookRaw(g_hGetGravity, true, pLocomotion);
DHookRaw(g_hShouldCollideWith, true, pLocomotion);
DHookRaw(g_hGetMaxAcceleration, true, pLocomotion);
DHookRaw(g_hGetFrictionSideways, true, pLocomotion);
if(bGroundNormal)
DHookRaw(g_hGetGroundNormal, true, pLocomotion)
Address pBody = SDKCall(g_hGetBodyInterface, pNB);
DHookRaw(g_hGetSolidMask, true, pBody);
DHookRaw(g_hStartActivity, true, pBody);
DHookRaw(g_hGetHullWidth, true, pBody);
DHookRaw(g_hGetHullHeight, true, pBody);
DHookRaw(g_hGetStandHullHeight, true, pBody);
DHookRaw(g_hGetCrouchHullHeight, true, pBody);
SetEntityFlags(npc, FL_NOTARGET);
SetEntData(npc, FindSendPropInfo("CTFBaseBoss", "m_lastHealthPercentage") + 28, false, 4, true); //ResolvePlayerCollisions
SetEntProp(npc, Prop_Data, "m_takedamage", 0);
SetEntProp(npc, Prop_Data, "m_nSolidType", 0);
SetEntProp(npc, Prop_Data, "m_lifeState", 1);
ActivateEntity(npc);
char strName[64];
Format(strName, sizeof(strName), "conganpc_%x", EntIndexToEntRef(npc));
Dynamic brain = Dynamic();
brain.SetBool("Pathing", false);
brain.SetName(strName);
SDKHook(npc, SDKHook_Think, BasicPetThink);
//Fix collisions
SetEntPropVector(npc, Prop_Send, "m_vecMaxs", view_as<float>( { 6.5, 6.5, 34.0 } ));
SetEntPropVector(npc, Prop_Data, "m_vecMaxs", view_as<float>( { 6.5, 6.5, 34.0 } ));
SetEntPropVector(npc, Prop_Send, "m_vecMins", view_as<float>( { -6.5, -6.5, 0.0 } ));
SetEntPropVector(npc, Prop_Data, "m_vecMins", view_as<float>( { -6.5, -6.5, 0.0 } ));
return view_as<BaseNPC>(npc);
}
property int index
{
public get()
{
return view_as<int>(this);
}
}
public Dynamic GetBrainInterface()
{
char strName[64];
Format(strName, sizeof(strName), "conganpc_%x", EntIndexToEntRef(this.index));
Dynamic brain = Dynamic.FindByName(strName);
if(!brain.IsValid)
{
AcceptEntityInput(this.index, "Kill");
}
return brain;
}
public Address GetLocomotionInterface()
{
Address pNB = SDKCall(g_hMyNextBotPointer, this.index);
return SDKCall(g_hGetLocomotionInterface, pNB);
}
public Address GetBodyInterface()
{
Address pNB = SDKCall(g_hMyNextBotPointer, this.index);
return SDKCall(g_hGetBodyInterface, pNB);
}
property bool Pathing
{
public get()
{
bool Pathing = false;
Dynamic brain = this.GetBrainInterface();
if(brain.IsValid)
{
Pathing = brain.GetBool("Pathing");
}
return Pathing;
}
public set(bool path)
{
Dynamic brain = this.GetBrainInterface();
if(brain.IsValid)
{
brain.SetBool("Pathing", path);
path ? PF_StartPathing(this.index) : PF_StopPathing(this.index);
}
}
}
public Address GetStudioHdr()
{
return view_as<Address>(GetEntData(this.index, 283 * 4));
}
public float GetPoseParameter(int iParameter)
{
return SDKCall(g_hGetPoseParameter, this.index, iParameter);
}
public void SetPoseParameter(int iParameter, float value)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return;
SDKCall(g_hSetPoseParameter, this.index, pStudioHdr, iParameter, value);
}
public int LookupPoseParameter(const char[] szName)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hLookupPoseParameter, this.index, pStudioHdr, szName);
}
public int LookupSequence(const char[] anim)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hLookupSequence, pStudioHdr, anim);
}
public void SetAnimation(const char[] anim)
{
int iSequence = this.LookupSequence(anim);
if(iSequence >= 0)
SDKCall(g_hResetSequence, this.index, iSequence);
}
public bool IsPlayingGesture(const char[] anim)
{
int iSequence = this.LookupSequence(anim);
if(iSequence >= 0)
return IsPlayingGesture(this.index, iSequence);
return false;
}
public int PlayGesture(const char[] anim, bool autokill = true)
{
int iSequence = this.LookupSequence(anim);
if(iSequence < 0)
return -1;
return SDKCall(g_hAddGestureSequence, this.index, iSequence, autokill);
}
public void CreatePather(int iTarget, float flStep, float flJump, float flDrop, int iSolid, float flAhead, float flRePath, float flHull)
{
PF_Create(this.index, flStep, flJump, flDrop, 0.6, iSolid, flAhead, flRePath, flHull);
PF_SetGoalEntity(this.index, iTarget);
PF_EnableCallback(this.index, PFCB_Approach, PluginBot_Approach);
}
public void Approach(const float vecGoal[3])
{
SDKCall(g_hApproach, this.GetLocomotionInterface(), vecGoal, 0.1);
}
public void FaceTowards(const float vecGoal[3], float speed = 200.0)
{
//Sad!
ConVar flTurnRate = FindConVar("tf_base_boss_max_turn_rate");
float flPrevValue = flTurnRate.FloatValue;
flTurnRate.FloatValue = speed;
SDKCall(g_hFaceTowards, this.GetLocomotionInterface(), vecGoal);
flTurnRate.FloatValue = flPrevValue;
}
public void Jump()
{
SDKCall(g_hJump, this.GetLocomotionInterface());
}
public void Update()
{
SDKCall(g_hStudioFrameAdvance, this.index);
SDKCall(g_hRun, this.GetLocomotionInterface());
SDKCall(g_hStuckMonitor, this.GetLocomotionInterface());
bool bStuck = SDKCall(g_hIsStuck, this.GetLocomotionInterface());
if(bStuck)
{
PrintToServer("STUCK");
SDKCall(g_hClearStuckStatus, this.GetLocomotionInterface(), "Un-Stuck");
TeleportEntity(this.index, WorldSpaceCenter(GetEntPropEnt(this.index, Prop_Send, "m_hOwnerEntity")), NULL_VECTOR, NULL_VECTOR);
}
}
public void GetVelocity(float vecOut[3])
{
SDKCall(g_hGetVelocity, this.GetLocomotionInterface(), vecOut);
}
public void SetVelocity(const float vec[3])
{
SDKCall(g_hSetVelocity, this.GetLocomotionInterface(), vec);
}
public int FindAttachment(const char[] pAttachmentName)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hStudio_FindAttachment, pStudioHdr, pAttachmentName) + 1;
}
public void GetAttachment(const char[] szName, float absOrigin[3], float absAngles[3])
{
SDKCall(g_hGetAttachment, this.index, this.FindAttachment(szName), absOrigin, absAngles);
}
public int EquipItem(const char[] attachment, const char[] model, const char[] anim = "", int skin = 0, float flScale = 1.0)
{
int item = CreateEntityByName("prop_dynamic");
DispatchKeyValue(item, "model", model);
DispatchKeyValueFloat(item, "modelscale", flScale == 1.0 ? GetEntPropFloat(this.index, Prop_Send, "m_flModelScale") : flScale);
DispatchSpawn(item);
SetEntProp(item, Prop_Send, "m_nSkin", skin);
SetEntProp(item, Prop_Send, "m_hOwnerEntity", this.index);
SetEntProp(item, Prop_Send, "m_fEffects", EF_BONEMERGE|EF_PARENT_ANIMATES);
if(!StrEqual(anim, ""))
{
SetVariantString(anim);
AcceptEntityInput(item, "SetAnimation");
}
SetVariantString("!activator");
AcceptEntityInput(item, "SetParent", this.index);
AcceptEntityInput(item, "DisableShadow");
SetVariantString(attachment);
AcceptEntityInput(item, "SetParentAttachmentMaintainOffset");
return item;
}
}
methodmap CongaLeader < BaseNPC
{
public CongaLeader(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/player/engineer.mdl", "0.4");
int skin = GetRandomInt(0, 1);
SetEntProp(pet.index, Prop_Send, "m_nSkin", skin);
pet.CreatePather(client, 18.0, 18.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 1.0, 2.0);
OnCongaMoveToSuccess(pet.index, Address_Null);
PF_EnableCallback(pet.index, PFCB_OnMoveToSuccess, OnCongaMoveToSuccess);
PF_EnableCallback(pet.index, PFCB_PathFailed, OnCongaMoveToFailure);
PF_EnableCallback(pet.index, PFCB_OnMoveToFailure, OnCongaMoveToFailure);
pet.Pathing = true;
pet.EquipItem("head", "models/player/items/taunts/bumpercar/parts/bumpercar.mdl", _, skin);
pet.SetAnimation("kart_idle");
//Kart
//kart_idle
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
return view_as<CongaLeader>(pet);
}
}
methodmap CongaMember < BaseNPC
{
public CongaMember(CongaMember leader, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/player/engineer.mdl", "0.35");
int skin = GetRandomInt(0, 1)
SetEntProp(pet.index, Prop_Send, "m_nSkin", skin);
pet.CreatePather(view_as<int>(leader), 18.0, 18.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 1.0, 2.0);
pet.Pathing = true;
pet.EquipItem("head", "models/player/items/taunts/bumpercar/parts/bumpercar.mdl", _, skin);
pet.SetAnimation("kart_idle");
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", view_as<int>(leader));
return view_as<CongaMember>(pet);
}
}
public void OnCongaMoveToSuccess(int bot_entidx, Address path)
{
//Pick a random goal area
NavArea RandomArea = PickRandomArea();
if(RandomArea != NavArea_Null)
{
if(HasTFAttributes(RandomArea, BLUE_SPAWN_ROOM)
|| HasTFAttributes(RandomArea, RED_SPAWN_ROOM)
|| !HasTFAttributes(RandomArea, BOMB_DROP))
{
//PrintToChatAll("OnCongaMoveToSuccess; Picked bad goal, try again");
OnCongaMoveToSuccess(bot_entidx, path);
return;
}
float vecGoal[3]; RandomArea.GetCenter(vecGoal);
//PrintToChatAll("OnCongaMoveToSuccess; new goal %f %f %f", vecGoal[0],vecGoal[1],vecGoal[2]);
PF_SetGoalVector(bot_entidx, vecGoal);
}
else
{
//PrintToChatAll("OnCongaMoveToSuccess; RandomArea was NULL, try again");
OnCongaMoveToSuccess(bot_entidx, path);
}
}
public void OnCongaMoveToFailure(int bot_entidx, Address path, MoveToFailureType type)
{
//PrintToChatAll("OnCongaMoveToFailure %i type %i", bot_entidx, type);
OnCongaMoveToSuccess(bot_entidx, path);
}
stock NavArea PickRandomArea()
{
int iAreaCount = LoadFromAddress(navarea_count, NumberType_Int32);
//Pick a random goal area
return view_as<NavArea>(LoadFromAddress(TheNavAreas + view_as<Address>(4 * GetRandomInt(0, iAreaCount - 1)), NumberType_Int32));
}
public void BasicPetThink(int iEntity)
{
int client = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity");
if(client <= 0)
{
AcceptEntityInput(iEntity, "Kill");
return;
}
SetEntProp(iEntity, Prop_Data, "m_bSequenceLoops", true);
BaseNPC npc = view_as<BaseNPC>(iEntity);
npc.Update();
float flOrigin[3], flAbsAngles[3];
GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", flOrigin);
GetEntPropVector(iEntity, Prop_Data, "m_angRotation", flAbsAngles);
float flCPos[3]; flCPos = WorldSpaceCenter(client);
float flDistance = GetVectorDistance(flCPos, flOrigin);
const float flDistanceLimit = 40.0;
//const float flMoveSpeed = 15.0
const float flMoveSpeed = 30.0
//We don't wanna fall too behind.
SetEntPropFloat(iEntity, Prop_Data, "m_speed", (flDistance >= flDistanceLimit) ? (flMoveSpeed * 3) : (flMoveSpeed));
npc.Pathing = (flDistance > flDistanceLimit);
float flGroundSpeed = SDKCall(g_hGetGroundSpeed, npc.GetLocomotionInterface());
float m_flGroundSpeed = GetEntPropFloat(iEntity, Prop_Data, "m_flGroundSpeed");
if(m_flGroundSpeed != 0.0)
{
float flReturnValue = clamp(flGroundSpeed / m_flGroundSpeed, -4.0, 12.0);
SetEntPropFloat(iEntity, Prop_Send, "m_flPlaybackRate", flReturnValue);
}
}
stock float[] WorldSpaceCenter(int entity)
{
float vecPos[3];
SDKCall(g_hSDKWorldSpaceCenter, entity, vecPos);
return vecPos;
}
public float clamp(float a, float b, float c) { return (a > c ? c : (a < b ? b : a)); }
public Action Command_CongaLine(int client, int argc)
{
//What are you.
if(!(client > 0 && client <= MaxClients && IsClientInGame(client)))
return Plugin_Handled;
int iMemberCount = 10;
if(argc > 0)
{
char strMemberCount[4];
GetCmdArg(1, strMemberCount, sizeof(strMemberCount));
iMemberCount = StringToInt(strMemberCount);
}
float wsc[3]; wsc = WorldSpaceCenter(client);
CongaMember leader = view_as<CongaMember>(CongaLeader(client, wsc, NULL_VECTOR));
SetEntProp(leader.index, Prop_Send, "m_hEffectEntity", view_as<int>(leader));
//First congaer in the line.
CongaMember iLineLeader = leader;
for (int i = 1; i <= iMemberCount; i++)
{
leader = CongaMember(leader, wsc, NULL_VECTOR);
SetEntProp(leader.index, Prop_Send, "m_hEffectEntity", view_as<int>(iLineLeader));
}
return Plugin_Handled;
}
public Action Command_CongaStop(int client, int argc)
{
//What are you.
if(!(client > 0 && client <= MaxClients && IsClientInGame(client)))
return Plugin_Handled;
int pet = -1;
while((pet = FindEntityByClassname(pet, "base_boss")) != -1)
{
if(PF_Exists(pet)) PF_Destroy(pet);
AcceptEntityInput(pet, "Kill");
}
return Plugin_Handled;
}
public void OnPluginStart()
{
RegAdminCmd("sm_congaline", Command_CongaLine, ADMFLAG_ROOT);
RegAdminCmd("sm_congastop", Command_CongaStop, ADMFLAG_ROOT);
Handle hConf = LoadGameConfigFile("tf2.pets");
//SDKCalls
//This call is used to get an entitys center position
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "CBaseEntity::WorldSpaceCenter");
PrepSDKCall_SetReturnInfo(SDKType_Vector, SDKPass_ByRef);
if ((g_hSDKWorldSpaceCenter = EndPrepSDKCall()) == null) SetFailState("Failed to create SDKCall for CBaseEntity::WorldSpaceCenter offset!");
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "CBaseAnimating::StudioFrameAdvance");
if ((g_hStudioFrameAdvance = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create SDKCall for CBaseAnimating::StudioFrameAdvance offset!");
//ResetSequence( int nSequence );
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::ResetSequence");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
if ((g_hResetSequence = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create SDKCall for CBaseAnimating::ResetSequence signature!");
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "CBaseEntity::MyNextBotPointer");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if ((g_hMyNextBotPointer = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create SDKCall for CBaseEntity::MyNextBotPointer offset!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "INextBot::GetLocomotionInterface");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if((g_hGetLocomotionInterface = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for INextBot::GetLocomotionInterface!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "INextBot::GetBodyInterface");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if((g_hGetBodyInterface = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for INextBot::GetBodyInterface!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::Run");
if((g_hRun = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::Run!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::Approach");
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
if((g_hApproach = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::Approach!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::FaceTowards");
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
if((g_hFaceTowards = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::FaceTowards!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::Jump");
if((g_hJump = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::Jump!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::GetVelocity");
PrepSDKCall_SetReturnInfo(SDKType_Vector, SDKPass_ByRef);
if((g_hGetVelocity = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::GetVelocity!");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::SetVelocity");
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
if((g_hSetVelocity = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::SetVelocity!");
//ILocomotion::GetGroundSpeed()
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::GetGroundSpeed");
PrepSDKCall_SetReturnInfo(SDKType_Float, SDKPass_Plain);
if((g_hGetGroundSpeed = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::GetGroundSpeed!");
//ILocomotion::IsStuck()
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::IsStuck");
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
if((g_hIsStuck = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::IsStuck!");
//ILocomotion::ClearStuckStatus(char const* reason)
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::IsStuck");
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
if((g_hClearStuckStatus = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::ClearStuckStatus!");
//ILocomotion::StuckMonitor
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "ILocomotion::StuckMonitor");
if((g_hStuckMonitor = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Virtual Call for ILocomotion::StuckMonitor!");
//CBaseAnimating::GetPoseParameter(int iParameter)
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::GetPoseParameter");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_Float, SDKPass_Plain);
if((g_hGetPoseParameter = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for CBaseAnimating::GetPoseParameter");
//SetPoseParameter( CStudioHdr *pStudioHdr, int iParameter, float flValue );
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::SetPoseParameter");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_Float, SDKPass_Plain);
if((g_hSetPoseParameter = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for CBaseAnimating::SetPoseParameter");
//LookupPoseParameter( CStudioHdr *pStudioHdr, const char *szName );
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::LookupPoseParameter");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if((g_hLookupPoseParameter = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for CBaseAnimating::LookupPoseParameter");
//-----------------------------------------------------------------------------
// Purpose: lookup attachment by name
//-----------------------------------------------------------------------------
StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "Studio_FindAttachment");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); //pStudioHdr
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer); //pAttachmentName
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); //return index
if((g_hStudio_FindAttachment = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for Studio_FindAttachment");
//-----------------------------------------------------------------------------
// Purpose: Returns the world location and world angles of an attachment
// Input : attachment name
// Output : location and angles
//-----------------------------------------------------------------------------
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::GetAttachment");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); //iAttachment
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef, _, VENCODE_FLAG_COPYBACK); //absOrigin
PrepSDKCall_AddParameter(SDKType_QAngle, SDKPass_ByRef, _, VENCODE_FLAG_COPYBACK); //absAngles
if((g_hGetAttachment = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for CBaseAnimating::GetAttachment");
//-----------------------------------------------------------------------------
// Purpose: Looks up a sequence by sequence name first, then by activity name.
// Input : label - The sequence name or activity name to look up.
// Output : Returns the sequence index of the matching sequence, or ACT_INVALID.
//-----------------------------------------------------------------------------
//LookupSequence( CStudioHdr *pStudioHdr, const char *label );
StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "LookupSequence");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); //pStudioHdr
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer); //label
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); //return index
if((g_hLookupSequence = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for LookupSequence");
//int CBaseAnimatingOverlay::AddGestureSequence( int nSequence, bool autokill )
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimatingOverlay::AddGestureSequence");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if((g_hAddGestureSequence = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create Call for CBaseAnimatingOverlay::AddGestureSequence");
//DHooks
g_hGetFrictionSideways = DHookCreateEx(hConf, "ILocomotion::GetFrictionSideways",HookType_Raw, ReturnType_Float, ThisPointer_Address, ILocomotion_GetFrictionSideways);
g_hGetStepHeight = DHookCreateEx(hConf, "ILocomotion::GetStepHeight", HookType_Raw, ReturnType_Float, ThisPointer_Address, ILocomotion_GetStepHeight);
g_hGetGravity = DHookCreateEx(hConf, "ILocomotion::GetGravity", HookType_Raw, ReturnType_Float, ThisPointer_Address, ILocomotion_GetGravity);
g_hGetGroundNormal = DHookCreateEx(hConf, "ILocomotion::GetGroundNormal", HookType_Raw, ReturnType_VectorPtr, ThisPointer_Address, ILocomotion_GetGroundNormal);
g_hGetMaxAcceleration = DHookCreateEx(hConf, "ILocomotion::GetMaxAcceleration", HookType_Raw, ReturnType_Float, ThisPointer_Address, ILocomotion_GetMaxAcceleration);
g_hShouldCollideWith = DHookCreateEx(hConf, "ILocomotion::ShouldCollideWith", HookType_Raw, ReturnType_Bool, ThisPointer_Address, ILocomotion_ShouldCollideWith);
DHookAddParam(g_hShouldCollideWith, HookParamType_CBaseEntity);
g_hGetSolidMask = DHookCreateEx(hConf, "IBody::GetSolidMask", HookType_Raw, ReturnType_Int, ThisPointer_Address, IBody_GetSolidMask);
g_hGetHullWidth = DHookCreateEx(hConf, "IBody::GetHullWidth", HookType_Raw, ReturnType_Float, ThisPointer_Address, IBody_GetHullWidth);
g_hGetHullHeight = DHookCreateEx(hConf, "IBody::GetHullHeight", HookType_Raw, ReturnType_Float, ThisPointer_Address, IBody_GetHullHeight);
g_hGetStandHullHeight = DHookCreateEx(hConf, "IBody::GetStandHullHeight", HookType_Raw, ReturnType_Float, ThisPointer_Address, IBody_GetStandHullHeight);
g_hGetCrouchHullHeight = DHookCreateEx(hConf, "IBody::GetCrouchHullHeight", HookType_Raw, ReturnType_Float, ThisPointer_Address, IBody_GetCrouchHullHeight);
g_hStartActivity = DHookCreateEx(hConf, "IBody::StartActivity", HookType_Raw, ReturnType_Bool, ThisPointer_Address, IBody_StartActivity);
delete hConf;
}
public void OnMapStart()
{
Handle hConf = LoadGameConfigFile("tf2.pets");
navarea_count = GameConfGetAddress(hConf, "navarea_count");
PrintToServer("[npc_congaline] Found \"navarea_count\" @ 0x%X", navarea_count);
if(LoadFromAddress(navarea_count, NumberType_Int32) <= 0)
{
SetFailState("[npc_congaline] No nav mesh!");
return;
}
//TheNavAreas is nicely above navarea_count
TheNavAreas = view_as<Address>(LoadFromAddress(navarea_count + view_as<Address>(0x4), NumberType_Int32));
PrintToServer("[npc_congaline] Found \"TheNavAreas\" @ 0x%X", TheNavAreas);
delete hConf;
}
Handle DHookCreateEx(Handle gc, const char[] key, HookType hooktype, ReturnType returntype, ThisPointerType thistype, DHookCallback callback)
{
int iOffset = GameConfGetOffset(gc, key);
if(iOffset == -1)
{
SetFailState("Failed to get offset of %s", key);
return null;
}
return DHookCreate(iOffset, hooktype, returntype, thistype, callback);
}
public MRESReturn ILocomotion_GetGroundNormal(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturnVector(hReturn, view_as<float>({0.0, 0.0, 1.0})); return MRES_Supercede; }
public MRESReturn ILocomotion_GetStepHeight(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 32.0); return MRES_Supercede; }
public MRESReturn ILocomotion_GetMaxAcceleration(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 1700.0); return MRES_Supercede; }
public MRESReturn ILocomotion_GetFrictionSideways(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 3.0); return MRES_Supercede; }
public MRESReturn ILocomotion_ShouldCollideWith(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, false); return MRES_Supercede; }
public MRESReturn ILocomotion_GetGravity(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 800.0); return MRES_Supercede; }
public MRESReturn IBody_GetSolidMask(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, MASK_NPCSOLID | MASK_PLAYERSOLID); return MRES_Supercede; }
public MRESReturn IBody_StartActivity(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, true); return MRES_Supercede; }
public MRESReturn IBody_GetCrouchHullHeight(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 16.0); return MRES_Supercede; }
public MRESReturn IBody_GetStandHullHeight(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 34.0); return MRES_Supercede; }
public MRESReturn IBody_GetHullWidth(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 13.0); return MRES_Supercede; }
public MRESReturn IBody_GetHullHeight(Address pThis, Handle hReturn, Handle hParams) { DHookSetReturn(hReturn, 34.0); return MRES_Supercede; }
public void PluginBot_Approach(int bot_entidx, const float vec[3])
{
BaseNPC npc = view_as<BaseNPC>(bot_entidx);
npc.Approach(vec);
npc.FaceTowards(vec);
}