forked from Bad-Scientists/AF-Script-Packet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.d
378 lines (320 loc) · 10.2 KB
/
interface.d
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
/*
* Detection for Action key press
*/
var int PC_ActionKeyPressed;
var int PC_ActionKeyPressedLast;
var int PC_ActionKeyHeld;
var int _PlayerActionKeyHeld_Event;
var int _PlayerActionKeyReleased_Event;
func void FF_CheckActionKey () {
var int actionKey; actionKey = MEM_GetKey ("keyAction"); actionKey = MEM_KeyState (actionKey);
var int secondaryActionKey; secondaryActionKey = MEM_GetSecondaryKey ("keyAction"); secondaryActionKey = MEM_KeyState (secondaryActionKey);
PC_ActionKeyPressed = FALSE;
if (((actionKey == KEY_PRESSED) || (actionKey == KEY_HOLD)) || ((secondaryActionKey == KEY_PRESSED) || (secondaryActionKey == KEY_HOLD))) {
PC_ActionKeyPressed = TRUE;
};
if (PC_ActionKeyPressed != PC_ActionKeyPressedLast) {
if (!PC_ActionKeyPressed) {
if (_PlayerActionKeyReleased_Event) {
Event_Execute (_PlayerActionKeyReleased_Event, 0);
};
};
} else {
if (PC_ActionKeyPressed) {
PC_ActionKeyHeld = TRUE;
if (_PlayerActionKeyHeld_Event) {
Event_Execute (_PlayerActionKeyHeld_Event, 0);
};
};
};
PC_ActionKeyPressedLast = PC_ActionKeyPressed;
if (!PC_ActionKeyPressed) {
FF_Remove (FF_CheckActionKey);
};
};
/*
*
*/
func void _hook_oCAIHuman_PC_ActionMove () {
PC_ActionKeyPressed = MEM_ReadInt (ESP + 4);
//If actionKey is pressed together with other keys ... then this function no longer register actionKey as pressed :-/
//So we will add frame function that will check if keyAction is pressed / held there
if (PC_ActionKeyPressed) {
if (PC_ActionKeyPressed != PC_ActionKeyPressedLast) {
FF_ApplyOnceExtGT (FF_CheckActionKey, 0, -1);
};
};
};
func void PlayerActionKeyHeldEvent_AddListener (var func f) {
Event_AddOnce (_PlayerActionKeyHeld_Event, f);
};
func void PlayerActionKeyHeldEvent_RemoveListener (var func f) {
Event_Remove (_PlayerActionKeyHeld_Event, f);
};
func void PlayerActionKeyReleasedEvent_AddListener (var func f) {
Event_AddOnce (_PlayerActionKeyReleased_Event, f);
};
func void PlayerActionKeyReleasedEvent_RemoveListener (var func f) {
Event_Remove (_PlayerActionKeyReleased_Event, f);
};
func void G12_GetActionKey_Init () {
PC_ActionKeyPressed = 0;
PC_ActionKeyPressedLast = PC_ActionKeyPressed;
if (!_PlayerActionKeyHeld_Event) {
_PlayerActionKeyHeld_Event = Event_Create ();
};
if (!_PlayerActionKeyReleased_Event) {
_PlayerActionKeyReleased_Event = Event_Create ();
};
const int once = 0;
if (!once) {
//G1 hook len 13, G2A hook len = 9
HookEngine (oCAIHuman__PC_ActionMove, MEMINT_SwitchG1G2 (13, 9), "_hook_oCAIHuman_PC_ActionMove");
once = 1;
};
};
/*
* Interception of event messages.
* I am using this to cancel animation: T_DONTKNOW
* Dirty solution, but gets work done.
*/
var int PC_IgnoreAnimations;
var int _PlayerUseItemToStateStart_Event;
var int _PlayerUseItemToStateUse_Event;
//0x006A69E0 public: virtual void __thiscall oCNpc::OnMessage(class zCEventMessage *,class zCVob *)
//0x0074B020 public: virtual void __thiscall oCNpc::OnMessage(class zCEventMessage *,class zCVob *)
func void _hook_oCNpc_OnMessage () {
// if (!PC_IgnoreAnimations) { return; };
if (!Hlp_Is_oCNpc (ECX)) { return; };
var int eMsg; eMsg = MEM_ReadInt (ESP + 4);
var oCNPC npc; npc = _^ (ECX);
var oCMobInter mob;
var oCMsgManipulate msgManipulate;
/*
//EV_DODGE - nothing happens when you call AI_Dodge on monster NPC
if (Hlp_Is_oCMsgMovement (eMsg)) {
enum TMovementSubType {
EV_ROBUSTTRACE,
EV_GOTOPOS,
EV_GOTOVOB,
EV_GOROUTE,
EV_TURN,
EV_TURNTOPOS,
EV_TURNTOVOB,
EV_TURNAWAY,
EV_JUMP,
EV_SETWALKMODE,
EV_WHIRLAROUND,
EV_STANDUP,
EV_CANSEENPC,
EV_STRAFE,
EV_GOTOFP,
EV_DODGE,
EV_BEAMTO,
EV_ALIGNTOFP,
EV_MOVE_MAX
};
//C_NPCIsMonster
if (eMsg_MD_GetSubType (eMsg) == 15) {
var int model; model = oCNPC_GetModel (npc);
var int aniID; aniID = zCModel_GetAniIdFromAniName (model, "T_FISTJUMPB");
PrintS (ConcatStrings ("aniID ", IntToString (aniID)));
var oCMsgMovement msgMovement; msgMovement = _^ (eMsg);
MEM_Info (ConcatStrings ("objectName ", msgMovement.objectName));
MEM_Info (ConcatStrings ("targetVobName ", msgMovement.targetVobName));
MEM_Info (ConcatStrings ("targetName ", msgMovement.targetName));
MEM_Info (ConcatStrings ("bitfield_oCNpcMessage ", IntToString (msgMovement.bitfield_oCNpcMessage)));
MEM_Info (ConcatStrings ("route ", IntToString (msgMovement.route)));
MEM_Info (ConcatStrings ("targetVob ", IntToString (msgMovement.targetVob)));
MEM_Info (ConcatStrings ("angle ", toStringF (msgMovement.angle)));
MEM_Info (ConcatStrings ("timer ", toStringF (msgMovement.timer)));
MEM_Info (ConcatStrings ("targetMode ", IntToString (msgMovement.targetMode)));
MEM_Info (ConcatStrings ("ani ", IntToString (msgMovement.ani)));
msgMovement.ani = aniID;
};
};
*/
if (PC_IgnoreAnimations) {
if (NPC_IsPlayer (npc)) {
if (Hlp_Is_oCMsgConversation (eMsg)) {
/*
enum TConversationSubType {
EV_PLAYANISOUND,
EV_PLAYANI,
EV_PLAYSOUND,
EV_LOOKAT,
EV_OUTPUT,
EV_OUTPUTSVM,
EV_CUTSCENE,
EV_WAITTILLEND,
EV_ASK,
EV_WAITFORQUESTION,
EV_STOPLOOKAT,
EV_STOPPOINTAT,
EV_POINTAT,
EV_QUICKLOOK,
EV_PLAYANI_NOOVERLAY,
EV_PLAYANI_FACE,
EV_PROCESSINFOS,
EV_STOPPROCESSINFOS,
EV_OUTPUTSVM_OVERLAY,
EV_CONV_MAX
};
*/
//EV_PLAYANI
if (eMsg_MD_GetSubType (eMsg) == 1) {
var oCMsgConversation msgConversation; msgConversation = _^ (eMsg);
//&& (Hlp_StrCmp (msgConversation.name, "T_DONTKNOW")) {
PC_IgnoreAnimations -= 1;
msgConversation.name = "";
};
};
};
};
//Item interaction
if (NPC_IsPlayer (npc)) {
var int eventUseItemToState;
if (Hlp_Is_oCMsgManipulate (eMsg)) {
/*
enum TManipulateSubType {
EV_TAKEVOB,
EV_DROPVOB,
EV_THROWVOB,
EV_EXCHANGE,
EV_USEMOB,
EV_USEITEM,
EV_INSERTINTERACTITEM,
EV_REMOVEINTERACTITEM,
EV_CREATEINTERACTITEM,
EV_DESTROYINTERACTITEM,
EV_PLACEINTERACTITEM,
EV_EXCHANGEINTERACTITEM,
EV_USEMOBWITHITEM,
EV_CALLSCRIPT,
EV_EQUIPITEM,
EV_USEITEMTOSTATE,
EV_TAKEMOB,
EV_DROPMOB,
EV_MANIP_MAX
};
*/
//EV_USEITEMTOSTATE
if (eMsg_MD_GetSubType (eMsg) == EV_USEITEMTOSTATE) {
msgManipulate = _^ (eMsg);
if (msgManipulate.npcSlot == 0) {
if (eventUseItemToState == 0) {
eventUseItemToState = 1;
if (_PlayerUseItemToStateStart_Event) {
Event_Execute (_PlayerUseItemToStateStart_Event, 0);
};
};
} else
if (msgManipulate.npcSlot == -1) {
if (eventUseItemToState == 1) {
eventUseItemToState = 0;
if (_PlayerUseItemToStateUse_Event) {
Event_Execute (_PlayerUseItemToStateUse_Event, 0);
};
};
};
};
//EV_USEMOB
if (eMsg_MD_GetSubType (eMsg) == EV_USEMOB) {
//PrintS ("EV_USEMOB");
msgManipulate = _^ (eMsg);
if (Hlp_Is_oCMobInter (msgManipulate.targetVob)) {
mob = _^ (msgManipulate.targetVob);
if ((msgManipulate.targetState == -1) && (mob.state == 1)) {
oCMobInter_SetInteractWith (msgManipulate.targetVob, 0);
};
};
};
};
} else {
//Additional logic for NPCs
if (Hlp_Is_oCMsgManipulate (eMsg)) {
if (eMsg_MD_GetSubType (eMsg) == EV_USEMOB) {
msgManipulate = _^ (eMsg);
//NPC will be able to unlock & lock oCMobLockable objects
if (Hlp_Is_oCMobLockable (msgManipulate.targetVob)) {
if ((msgManipulate.targetVob == npc.interactMob) || (msgManipulate.targetState == -1)) {
var oCMobLockable lock; lock = _^ (msgManipulate.targetVob);
if (Hlp_StrCmp (msgManipulate.name, "LOCK")) {
if (!(lock.bitfield & oCMobLockable_bitfield_locked)) {
lock.bitfield = (lock.bitfield | oCMobLockable_bitfield_locked);
//PrintS ("locking!");
};
};
if (Hlp_StrCmp (msgManipulate.name, "UNLOCK")) {
if (lock.bitfield & oCMobLockable_bitfield_locked) {
lock.bitfield = (lock.bitfield & ~ oCMobLockable_bitfield_locked);
//PrintS ("unlocking!");
};
};
};
};
};
};
};
};
func void PlayerUseItemToStateStartEvent_AddListener (var func f) {
Event_AddOnce (_PlayerUseItemToStateStart_Event, f);
};
func void PlayerUseItemToStateStartEvent_RemoveListener (var func f) {
Event_Remove (_PlayerUseItemToStateStart_Event, f);
};
func void PlayerUseItemToStateUseEvent_AddListener (var func f) {
Event_AddOnce (_PlayerUseItemToStateUse_Event, f);
};
func void PlayerUseItemToStateUseEvent_RemoveListener (var func f) {
Event_Remove (_PlayerUseItemToStateUse_Event, f);
};
func void G12_InterceptNpcEventMessages_Init () {
//Special events detecting item usage event type EV_USEITEMTOSTATE - start and actual item usage (when onstate[0] function is called)
//These will be called only for player!!
if (!_PlayerUseItemToStateStart_Event) {
_PlayerUseItemToStateStart_Event = Event_Create ();
};
if (!_PlayerUseItemToStateUse_Event) {
_PlayerUseItemToStateUse_Event = Event_Create ();
};
const int once = 0;
if (!once) {
//0x006A69E0 public: virtual void __thiscall oCNpc::OnMessage(class zCEventMessage *,class zCVob *)
const int oCNpc__OnMessage_G1 = 6973920;
//0x0074B020 public: virtual void __thiscall oCNpc::OnMessage(class zCEventMessage *,class zCVob *)
const int oCNpc__OnMessage_G2 = 7647264;
HookEngine (MEMINT_SwitchG1G2 (oCNpc__OnMessage_G1, oCNpc__OnMessage_G2), 7, "_hook_oCNpc_OnMessage");
once = 1;
};
};
var int _MouseUpdate_Event;
func void MouseUpdateEvent_AddListener (var func f) {
Event_AddOnce (_MouseUpdate_Event, f);
};
func void MouseUpdateEvent_RemoveListener (var func f) {
Event_Remove (_MouseUpdate_Event, f);
};
func void _hook_mouseUpdate_Event () {
if (_MouseUpdate_Event) {
Event_Execute (_MouseUpdate_Event, 0);
};
};
func void G12_MouseUpdate_Init () {
if (!_MouseUpdate_Event) {
_MouseUpdate_Event = Event_Create ();
};
const int once = 0;
if (!once) {
/*
Code used here was originally created by mud-freak (@szapp)
Originally this was used in Gothic Free Aim
mud-freak's repository:
https://github.com/szapp/GothicFreeAim
*/
const int mouseUpdate_G1 = 5013602; //0x4C8062 // Hook len 5
const int mouseUpdate_G2 = 5062907; //0x4D40FB // Hook len 5
HookEngine (MEMINT_SwitchG1G2 (mouseUpdate_G1, mouseUpdate_G2), 5, "_hook_mouseUpdate_Event");
once = 1;
};
};