· 6 years ago · Apr 04, 2019, 09:30 PM
1------------------------------------------------------------------
2-- ATTENTION: These are the API functions currently implemented
3-- in EWT. The documentation is a copy from FireHack because the
4-- idea is EWT to mirror FireHack's API. If you need an API that
5-- is missing here or an API isn't behaving properly, let me know!
6-- FireHack API: https://firehack.io/api/
7------------------------------------------------------------------
8-- LAST UPDATED: 2019-04-04
9
10------------------------- Active Player -------------------
11
12--- Stop falling.
13function StopFalling () end
14
15--- Move to a position.
16-- X (number) - The X coordinate
17-- Y (number) - The Y coordinate
18-- Z (number) - The Z coordinate
19-- InstantTurn (boolean) - Whether to instantly turn toward the destination
20function MoveTo (X, Y, Z[, InstantTurn])
21
22--- Teleport to a position.
23-- X (number) - The X coordinate
24-- Y (number) - The Y coordinate
25-- Z (number) - The Z coordinate
26function Teleport (X, Y, Z)
27
28--- Registers Lua callbacks for Teleport
29-- before (function) - A callback that is called before EWT teleports your character.
30-- after (function) - A callback that is called after EWT teleports your character.
31function AddTeleportCallbacks(before, after)
32-- Example:
33function myTeleportFunc()
34 AddTeleportCallbacks(
35 function()
36 local beforeX, beforeY, beforeZ = ObjectPosition("player")
37 print('Teleported from ' .. beforeX .. ' ' .. beforeY .. ' ' .. beforeZ)
38 end,
39 function()
40 local x, y, z = ObjectPosition("player")
41 print('to x ' .. x .. ' ' .. y .. ' ' .. z)
42 end
43 )
44end
45
46--- Set the direction that the player is facing (angle in XY).
47-- Direction (number) or Object (string) - The direction in radians or the object
48-- Update (boolean) - Whether to immediately notify the server
49function FaceDirection (Direction[, Update])
50
51--- Set the maximum angle from the XY plane that the player can move at
52-- Angle (number) - The maximum angle in degrees
53-- Note that the angle must be between 0º and 90º.
54function SetMaximumClimbAngle (Angle)
55
56--- Get the current map ID
57-- return (number) - The current map ID of the active player.
58function GetMapId()
59
60------------------------- Object --------------------------
61
62if EWT.is80 then
63 ObjectType = {
64 Object = 0,
65 Item = 1,
66 Container = 2,
67 AzeriteEmpoweredItem = 3,
68 AzeriteItem = 4,
69 Unit = 5,
70 Player = 6,
71 ActivePlayer = 7,
72 GameObject = 8,
73 DynamicObject = 9,
74 Corpse = 10,
75 AreaTrigger = 11,
76 SceneObject = 12,
77 ConversationData = 13
78 };
79else
80 ObjectType = {
81 Object = 0,
82 Item = 1,
83 Container = 2,
84 Unit = 3,
85 Player = 4,
86 GameObject = 5,
87 DynamicObject = 6,
88 Corpse = 7,
89 AreaTrigger = 8,
90 SceneObject = 9,
91 ConversationData = 10
92 };
93end
94
95-- Don't use this for BFA
96ObjectTypes = {
97 None = 0,
98 Object = 1,
99 Item = 2,
100 Container = 4,
101 Unit = 8,
102 Player = 16,
103 GameObject = 32,
104 DynamicObject = 64,
105 Corpse = 128,
106 AreaTrigger = 256,
107 SceneObject = 512,
108 All = -1
109};
110
111--- Get an object's pointer.
112-- Object (object) - The object
113-- returns (string or nil) - The pointer as a hexadecimal string prefixed by 0x or nil if the object does not exist.
114-- Note: If the object doesn't exist, for example, ObjectPointer('party1target'), it returns nil.
115-- This API is mainly useful to get the object address of unitIDs like 'target', 'mouseover', etc.
116-- ObjectPointer('0xDEADBEEF') simply returns '0xDEADBEEF' and does NOT check if the address exists in the object manager. Don't do this.
117function ObjectPointer (Object)
118
119--- Get whether an object exists in the object manager.
120-- Object (object) - The object
121-- returns (string or nil) - The pointer as a hexadecimal string prefixed by 0x or nil if the object does not exist.
122-- Note that if the object does not exist in the object manager it is invalid and should not be used.
123-- This API is only useful to check if '0x' strings are *really* valid. In my opinion, it should never be used
124-- if you are properly using GetObjectCount since you will always work with objects that exist.
125-- This API is similar to ObjectPointer, but it checks if the object exists in the object manager.
126-- If you pass a unitID, like ObjectExists('target'), then its performance is the same as ObjectPointer('target').
127-- This API works like UnitIsVisible, but instead of returning boolean, it returns string or nil.
128-- This API has O(n) performance, which means that the more objects in the object manager, the slower it is.
129-- UnitIsVisible has O(1) performance, which means that, no matter how many objects in the object manager, the speed is the same.
130-- But UnitIsVisible may create crash logs if you provide '0x' strings of objects that don't exist.
131function ObjectExists (Object)
132
133--- Get an object's position.
134-- Object (object) - The object
135-- returns (number, number, number) - The X, Y, and Z coordinates
136-- Note: If the object doesn't exist, it returns (nil, nil, nil)
137function ObjectPosition (Object)
138
139--- Get an object's facing.
140-- Object (object) - The object
141-- returns (number or nil) - The facing (angle in XY) in radians
142-- Note: If the object doesn't exist, it returns nil.
143function ObjectFacing (Object)
144GetObjectFacing = ObjectFacing
145
146--- Get an object's GUID.
147-- Object (object) - The object
148-- returns (string or nil) - The GUID as a string or nil if the object doesn't exist.
149-- Note: This API is mainly for WoW Classic 1.12.1, because UnitGUID doesn't exist in this version
150-- and to retrieve the GUID of GameObjects with the "mouseover" token.
151function ObjectGUID (Object)
152
153--- Get an object's name.
154-- Object (object) - The object
155-- returns (string) - The name
156function ObjectName (Object)
157
158--- Get an object's type ID.
159-- Object (object) - The object
160-- returns (integer) - The type ID or nil if there is none
161function ObjectID (Object)
162
163--- Get whether an object is of a type.
164-- Object (object) - The object
165-- Type (ObjectTypes member) - The type
166-- returns (boolean) - Whether the object is of the type
167-- Note: Don't use this for BFA. Use ObjectRawType instead.
168function ObjectIsType (Object, Type)
169
170--- Get an object's type flags.
171-- Object (object) - The object
172-- returns (integer) - One or more members of the ObjectTypes table combined with bit.bor
173-- Note: Don't use this for BFA. Use ObjectRawType instead.
174function ObjectTypeFlags (Object)
175
176--- Get an object's type.
177-- Object (object) - The object
178-- returns (integer) - One member of the ObjectType table.
179function ObjectRawType (Object)
180
181function ObjectIsPlayer(object)
182 local type = ObjectRawType(object)
183 return type == ObjectType.Player or type == ObjectType.ActivePlayer
184end
185
186function ObjectIsUnit(object)
187 local type = ObjectRawType(object)
188 return type == ObjectType.Unit or type == ObjectType.Player or type == ObjectType.ActivePlayer
189end
190
191function ObjectIsGameObject(object)
192 return ObjectRawType(object) == ObjectType.GameObject
193end
194
195function ObjectIsAreaTrigger(object)
196 return ObjectRawType(object) == ObjectType.AreaTrigger
197end
198
199function GetDistanceBetweenPositions (X1, Y1, Z1, X2, Y2, Z2)
200 return math.sqrt(math.pow(X2 - X1, 2) + math.pow(Y2 - Y1, 2) + math.pow(Z2 - Z1, 2));
201end
202
203--- Get the distance between two objects.
204-- Object1 (object) - The first object
205-- Object2 (object) - The second object
206-- returns (number) - The distance
207function GetDistanceBetweenObjects (Object1, Object2)
208
209--- Get the angles between two objects.
210-- Object1 (object) - The first object
211-- Object2 (object) - The second object
212-- returns (number, number) - The facing (angle in XY) and pitch (angle from XY) from the first object to the second
213function GetAnglesBetweenObjects (Object1, Object2)
214
215--- Get the position that is between two objects and a specified distance from the first object.
216-- Object1 (object) - The first object
217-- Object2 (object) - The second object
218-- Distance (number) - The distance from the first object
219-- returns (number, number, number) - The X, Y, and Z coordinates
220function GetPositionBetweenObjects (Object1, Object2, Distance)
221
222function GetPositionFromPosition (X, Y, Z, Distance, AngleXY, AngleXYZ)
223 return math.cos(AngleXY) * Distance + X,
224 math.sin(AngleXY) * Distance + Y,
225 math.sin(AngleXYZ) * Distance + Z;
226end
227
228function GetAnglesBetweenPositions (X1, Y1, Z1, X2, Y2, Z2)
229 return math.atan2(Y2 - Y1, X2 - X1) % (math.pi * 2),
230 math.atan((Z1 - Z2) / math.sqrt(math.pow(X1 - X2, 2) + math.pow(Y1 - Y2, 2))) % math.pi;
231end
232
233function GetPositionBetweenPositions (X1, Y1, Z1, X2, Y2, Z2, DistanceFromPosition1)
234 local AngleXY, AngleXYZ = GetAnglesBetweenPositions(X1, Y1, Z1, X2, Y2, Z2);
235 return GetPositionFromPosition(X1, Y1, Z1, DistanceFromPosition1, AngleXY, AngleXYZ);
236end
237
238--- Get whether an object is facing another.
239-- Object1 (object) - The first object
240-- Object2 (object) - The second object
241-- returns (boolean) - Whether the first object is facing the second
242function ObjectIsFacing (Object1, Object2)
243
244--- Get whether an object is behind another.
245-- Object1 (object) - The first object
246-- Object2 (object) - The second object
247-- returns (boolean) - Whether the first object is behind the second
248function ObjectIsBehind (Object1, Object2)
249
250--- Get one of an object's descriptors.
251-- Object (object) - The object
252-- Offset (integer) - The descriptor offset
253-- Type (Type member) - The descriptor type
254-- returns (Type) - The descriptor value
255function ObjectDescriptor (Object, Offset, Type)
256
257--- Get one of an object's fields.
258-- Object (object) - The object
259-- Offset (integer) - The field offset
260-- Type (Type member) - The field type
261-- returns (Type) - The field value
262function ObjectField (Object, Offset, Type)
263
264--- Interact with Object. Useful for 1.12.1 and 2.4.3 since InteractUnit isn't available in these versions.
265-- Object (object) - The object
266-- returns (boolean) - True if the object is valid, False if not
267function ObjectInteract (Object)
268
269------------------------- Object Manager ------------------
270
271--- Get the number of objects in the object manager and optionally 2 tables with all objects that were updated in the frame.
272-- GetUpdates (boolean) - True to get the tables with the objects that were updated in the frame.
273-- returns (integer, boolean, table, table) - The total number of objects, if the object manager was updated, the added objects and the removed objects.
274-- Note: This should be the first API that you should call before using the other object manager functions.
275-- Ideally, call it once every frame with an OnUpdate frame event.
276-- You can use table.getn or # to get the number of objects in the returned tables.
277function GetObjectCount ([GetUpdates])
278ObjectCount = GetObjectCount
279
280-- Example:
281local initOM = true
282local myOM = {}
283local myFrame = CreateFrame("Frame")
284myFrame:SetScript("OnUpdate", function ()
285 -- The first frame call to GetObjectCount(true) should have total == #added and 'added' will contain all objects.
286 -- The next GetObjectCount(true) calls should have only the updated objects.
287 local total, updated, added, removed = GetObjectCount(true)
288 if initOM then
289 initOM = false
290 for i = 1,total do
291 local thisUnit = GetObjectWithIndex(i) -- thisUnit contains the '0x' string representing the object address
292 -- Do something with the unit
293 myOM[thisUnit] = 1
294 end
295 end
296 for k,v in pairs(added) do
297 -- k - Number = Array index = Don't confuse this with the Object Index used by GetObjectWithIndex. It's not the same thing.
298 -- v - String = Object address
299 print('Added ' .. v)
300 myOM[v] = 1
301 if ObjectIsUnit(v) then
302 local posX, posY, posZ = ObjectPosition(v)
303 end
304 end
305 for k,v in pairs(removed) do
306 print('Removed ' .. v)
307 myOM[v] = nil
308 end
309 local manualCount = 0
310 for k,v in pairs(myOM) do
311 manualCount = manualCount + 1
312 end
313 if #added ~= 0 or #removed ~= 0 then
314 print('Total ' .. total .. ' ' .. #added .. ' ' .. #removed .. ' Manual ' .. manualCount)
315 end
316end);
317
318--- Get an object in the object manager from its index.
319-- Index (integer) - The one-based index of the object. Starts at 1.
320-- returns (object) - The object
321-- Note: If an object is at index 30, this does NOT mean that in the next frame it will be at index 30 again.
322-- This API isn't really needed if you are properly using GetObjectCount(true).
323function GetObjectWithIndex (Index)
324ObjectWithIndex = GetObjectWithIndex
325
326--- Get an object in the object manager from its pointer.
327-- Pointer (string) - A pointer to the object as a hexadecimal string prefixed by 0x
328-- returns (object) - The object
329-- Note: Avoid using this API. Prefer GetObjectWithIndex instead. It's here only because of backwards compatibility.
330function GetObjectWithPointer (Pointer)
331
332--- Get an object in the object manager from its GUID.
333-- GUID (string) - The GUID
334-- returns (object) - The object or nil if it is not in the object manager
335function GetObjectWithGUID (GUID)
336
337--- Gets the active player.
338-- returns (object or nil) - The active player object or nil if it does not exist.
339function GetActivePlayer ()
340
341--- Gets the active mover.
342-- returns (object or nil) - The active mover object or nil if it does not exist.
343-- Note: This is usually the Active Player. When you get mind controlled, lose control of your character or control
344-- something else, then the Active Mover is different.
345function GetActiveMover ()
346
347------------------------- Unit ----------------------------
348
349--- Get an object's facing direction.
350-- @param Object The object. It must be of type Unit.
351-- @param Object The object.
352-- @param Angle The frontal cone angle in degrees. Default: 180 degrees
353-- @return Boolean. Whether it is facing or not.
354function UnitIsFacing (Object, Object[, Angle]) end
355
356MovementFlags = {
357 Forward = 0x1,
358 Backward = 0x2,
359 StrafeLeft = 0x4,
360 StrafeRight = 0x8,
361 TurnLeft = 0x10,
362 TurnRight = 0x20,
363 PitchUp = 0x40,
364 PitchDown = 0x80,
365 Walking = 0x100,
366 Immobilized = 0x400,
367 Falling = 0x800,
368 FallingFar = 0x1000,
369 Swimming = 0x100000,
370 Ascending = 0x200000,
371 Descending = 0x400000,
372 CanFly = 0x800000,
373 Flying = 0x1000000,
374};
375
376--- Get the unit's movement address.
377-- Unit (unit) - The unit
378-- returns (integer) - The movement struct address
379-- Note: If the object is not a unit, then it returns nil.
380function GetUnitMovement (Unit)
381
382--- Get the unit's speed.
383-- Unit (unit) - The unit
384-- returns (number) - currentSpeed, groundSpeed, flightSpeed, swimSpeed
385-- Note: If the object is not a unit, then it returns nil.
386-- This API is only available on 1.12.1 and 2.4.3.
387function GetUnitSpeed (Unit)
388
389--- Get a unit's movement flags.
390-- Unit (unit) - The unit
391-- returns (integer) - The movement flags
392function UnitMovementFlags (Unit)
393
394--- Set a unit's movement flags.
395-- Unit (unit) - The unit
396-- Flags (number) - The new movement flags
397-- returns (boolean) - True if it worked or some error if not.
398function SetMovementFlags (Unit, Flags)
399
400--- Send the player's movement state to the server.
401--- returns (boolean) - True if it worked, False if not. It will only fail if there's no player active.
402function SendMovementUpdate ()
403
404--- Get a unit's bounding radius.
405-- Unit (unit) - The unit
406-- returns (number) - The bounding radius
407function UnitBoundingRadius (Unit)
408
409--- Get a unit's combat reach.
410-- Unit (unit) - The unit
411-- returns (number) - The combat reach
412function UnitCombatReach (Unit)
413
414--- Get a unit's target.
415-- Unit (unit) - The unit
416-- returns (unit) - The target or nil if there is none
417function UnitTarget (Unit)
418
419--- Get an object's creator.
420-- Object (object) - The unit or game object
421-- returns (unit) - The creator or nil if there is none
422function ObjectCreator (Unit)
423UnitCreator = ObjectCreator
424
425--- Get whether a unit can be looted.
426-- Unit (unit) - The unit
427-- returns (boolean) - Whether the unit can be looted
428function UnitCanBeLooted (Unit)
429
430--- Get whether a unit can be skinned.
431-- Unit (unit) - The unit
432-- returns (boolean) - Whether the unit can be skinned
433function UnitCanBeSkinned (Unit)
434
435--- Set a unit's display ID.
436-- Unit (unit) - The unit
437-- DisplayID (integer) - The new display ID
438-- returns (boolean) - Whether the display was changed or not
439-- Note that UnitUpdateModel must be called for the change to be displayed.
440function UnitSetDisplayID (Unit, DisplayID)
441SetDisplayID = UnitSetDisplayID
442
443-- Sets the unit's mount display ID
444function SetMountDisplayID(Unit, DisplayID)
445
446-- Set's the unit's item display ID
447function SetVisibleItem(Unit, SlotID, ItemID [, ItemAppearanceModID])
448
449-- Set's the unit's item enchant ID
450function SetVisibleEnchant(Unit, SlotID, EnchantID)
451
452--- Update a unit's model.
453-- Unit (unit) - The unit
454function UnitUpdateModel (Unit)
455UpdateModel = UnitUpdateModel
456
457--- Get the spell IDs being casted or channelled by the unit
458-- Unit (unit) - The unit
459-- returns (number, number, object, object) - (Spell Cast ID, Spell Channel ID, Cast Object, Channel Object)
460-- Note: If no spells are being casted, it returns 0, 0, nil, nil.
461-- On certain WoW expansions, the Cast Object and Channel Object arent erased after cast. So you must always check if CastID and ChannelID arent 0.
462function UnitCastID (Unit)
463
464--- Get or set unit pitch.
465-- Unit (unit) - The unit
466-- newPitch (number) - The new pitch
467-- update (boolean) - Whether to immediately notify the server
468-- returns (number) - The unit pitch.
469-- Note: If setting the pitch, it doesnt return anything. Also, pitch returns 0 for other units which aren't the current active mover.
470function UnitPitch (Unit[, newPitch, update])
471
472------------------------- World ---------------------------
473
474HitFlags = {
475 M2Collision = 0x1,
476 M2Render = 0x2,
477 WMOCollision = 0x10,
478 WMORender = 0x20,
479 Terrain = 0x100,
480 WaterWalkableLiquid = 0x10000,
481 Liquid = 0x20000,
482 EntityCollision = 0x100000,
483};
484
485--- Perform a raycast between two positions.
486-- StartX (number) - The starting X coordinate
487-- StartY (number) - The starting Y coordinate
488-- StartZ (number) - The starting Z coordinate
489-- EndX (number) - The ending X coordinate
490-- EndY (number) - The ending Y coordinate
491-- EndZ (number) - The ending Z coordinate
492-- Flags (integer) - One or more members of the HitFlags table combined with bit.bor
493-- returns (number, number, number) - The X, Y, and Z coordinates of the hit position, or nil if there was no hit
494-- Note: Be careful with how often you call this API because your FPS can drop a lot.
495-- Note: For generic LoS checks, use 0x100111 for Flags (M2, WMO, Terrain, Entity)
496function TraceLine (StartX, StartY, StartZ, EndX, EndY, EndZ [, Flags])
497
498--- Equivalent to TraceLine(StartX, StartY, 10000, StartX, StartY, -10000, Flags)
499-- StartX (number) - The starting X coordinate
500-- StartY (number) - The starting Y coordinate
501function GetGroundZ(StartX, StartY [, Flags])
502 return TraceLine(StartX, StartY, 10000, StartX, StartY, -10000, Flags)
503end
504
505--- Get the camera position.
506-- returns (number, number, number) - The XYZ coordinates of the camera
507function GetCameraPosition ()
508
509--- Cancel the pending spell if any.
510function CancelPendingSpell ()
511
512--- Simulate a click at a position in the game-world.
513-- X (number) - The X coordinate
514-- Y (number) - The Y coordinate
515-- Z (number) - The Z coordinate
516-- Right (boolean) - Whether to right click rather than left click
517function ClickPosition (X, Y, Z[, Right])
518CastAtPosition = ClickPosition
519
520--- Get information about the last click.
521-- returns (number, number, number, number, object) - The XYZ coordinates of the click, the click type and the object that was clicked.
522-- Click Type: 1 = Normal Terrain/World Click | 2 = Clicked on some Unit/GameObject
523-- Object - string or nil - The address of the last clicked object or nil if it doesn't exist.
524-- Note: If no World Frame is available, it returns nil.
525-- For WoWs < WOTLK, the object does not clear after a terrain click.
526function GetLastClickInfo ()
527
528--- Get whether an AoE spell is pending a target.
529-- returns (boolean) - Whether an AoE spell is pending a target
530function IsAoEPending ()
531 return SpellIsTargeting()
532end
533
534--- Get the screen coordinates relative from World coordinates
535-- X (number) - The X coordinate.
536-- Y (number) - The Y coordinate.
537-- Z (number) - The Z coordinate.
538-- returns (number, number, boolean) - The X and Y screen coordinates for the XYZ coordinates and
539-- whether they are in front of the camera or not.
540function WorldToScreen (X, Y, Z) end
541
542--- Return whether the given coordinates are in front of WoW's camera
543-- X (number) - The X coordinate.
544-- Y (number) - The Y coordinate.
545-- Z (number) - The Z coordinate.
546-- returns (boolean) - Whether they are in front or not.
547function IsInFront (X, Y, Z) end
548
549------------------------- Hacks ---------------------------
550
551Hacks = {
552 Fly = "Fly",
553 Hover = "Hover",
554 Climb = "Climb",
555 MovingLoot = "MovingLoot",
556 WaterWalk = "WaterWalk",
557 M2Collision = "M2Collision",
558 WMOCollision = "WMOCollision",
559 TerrainCollision = "TerrainCollision",
560 Zoom = "Zoom",
561 AlwaysFacing = "AlwaysFacing",
562 AntiAfk = "AntiAfk",
563 NoSwim = "NoSwim",
564 MultiJump = "MultiJump",
565 CRZBlocking = "CRZBlocking",
566 M2Rendering = "M2Rendering",
567 WMORendering = "WMORendering",
568 TerrainRendering = "TerrainRendering",
569 LiquidRendering = "LiquidRendering",
570 CollisionRendering = "CollisionRendering",
571 MountainRendering = "MountainRendering",
572 DetailsRendering = "DetailsRendering",
573 Wireframe = "Wireframe",
574 Freeze = "Freeze",
575 MovingCast = "MovingCast",
576 GoClick = "GoClick",
577 UnlockLua = "UnlockLua",
578 SimpleUnlock = "SimpleUnlock"
579}
580
581--- Get whether a hack is enabled.
582-- Hack (Hacks member) - The hack
583-- returns (boolean) - Whether the hack is enabled
584function IsHackEnabled (Hack)
585
586--- Set whether a hack is enabled.
587-- Hack (Hacks member) - The hack
588-- Enable (boolean) - Whether the hack is to be enabled
589function SetHackEnabled (Hack, Enable)
590SetOptionEnabled = SetHackEnabled
591
592------------------------- File ----------------------------
593
594--- Get the names of the files in a directory.
595-- Path (string) - The path to the files
596-- returns (table) - The file names
597-- Example: "C:\*" would retrieve the names of all of the files in C:\.
598-- Example: "C:\*.dll" would retrieve the names of all of the .dll files in C:\.
599function GetDirectoryFiles (Path)
600
601--- Get the names of the directories in a directory.
602-- Path (string) - The path to the directories
603-- returns (table) - The directory names
604-- Example: "C:\*" would retrieve the names of all of the directories in C:\.
605-- Example: "C:\Program Files*" would retrieve the names of the program files directories in C:\.
606function GetSubdirectories (Path)
607
608--- Get the contents of a text file.
609-- Path (string) - The file path
610-- returns (string) - The file contents
611function ReadFile (Path)
612
613--- Set the contents of or append a text file.
614-- Path (string) - The file path
615-- String (string) - The string to write
616-- Append (boolean) - Whether to append rather than overwrite
617-- Note: If you provide just a filename in Path, then it will create the file where Wow.exe is located.
618function WriteFile (Path, Contents[, Append])
619
620--- Get the directory that the hack is in.
621-- @return The directory that the hack is in.
622function GetHackDirectory () end
623GetFireHackDirectory = GetHackDirectory
624
625--- Get the directory that WoW is in.
626-- returns (string) - The directory that WoW is in
627function GetWoWDirectory ()
628
629------------------------- Scripts -------------------------
630
631--- Load a script from the Scripts folder.
632-- FileName (string) - The script file name
633-- returns - The return values of the script if any
634function LoadScript (FileName)
635
636--- Get the file name of the currently executing script.
637-- returns (string) - The file name of the currently executing script
638-- Note that this can only be called from within a script.
639function GetScriptName ()
640
641------------------------- Callbacks -------------------------
642
643--- Adds a Lua callback for a sent or received game packet (not a socket packet).
644-- mode (string) - "send" or "recv" to listen to sent/received packets
645-- opcode (number) - The opcode that you want to listen. -1 listens everything.
646-- callback (function) - Your Lua callback
647-- returns string (ID of packet callback which is used by RemovePacketCallback)
648-- Example for 3.3.5 using CMSG_MOVE_JUMP: /script AddPacketCallback("send", 0xBB, function(data) print(data) end)
649-- Note: Packet callbacks persist through Lua reloads so if you lose the ID, you can't remove the filter.
650function AddPacketCallback(mode, opcode, callback)
651
652-- Removes a Lua callback added by AddPacketCallback
653-- id (string) - The string returned by AddPacketCallback
654-- returns true on success, false if the callback wasn't found.
655function RemovePacketCallback(id)
656
657
658-- Add a callback to a Lua table that is called every frame, i.e., every "OnUpdate" WoW frame event.
659-- Callback (function) - The callback
660function AddFrameCallback (Callback)
661
662--- Add a timer callback.
663-- Interval (number) - The number of seconds between calls
664-- Callback (function) - The callback
665function AddTimerCallback (Interval, Callback)
666
667--- Add a WoW event callback, i.e., a function that is called on "OnEvent" frame event.
668-- Event (string) - The event name
669-- Callback (function) - The callback
670-- Note that the callback is called with the event arguments.
671function AddEventCallback (Event, Callback)
672
673------------------------- Miscellaneous -------------------
674
675Types = {
676 Bool = "bool",
677 Char = "char",
678 Byte = "byte",
679 SByte = "char",
680 UByte = "byte",
681 Short = "short",
682 SShort = "short",
683 UShort = "ushort",
684 Int = "int",
685 SInt = "int",
686 UInt = "uint",
687 Long = "long",
688 SLong = "long",
689 ULong = "ulong",
690 Float = "float",
691 Double = "double",
692 String = "string",
693 GUID = "guid",
694 Vector3 = "vector3"
695};
696
697--- Open a URL in the default handler for the scheme.
698-- URL (string) - The URL
699function OpenURL (URL)
700
701--- Send an HTTP or HTTPS request.
702-- URL (string) - The URL to send to
703-- PostData (string) - The POST data if any (nil to use a GET request)
704-- OnComplete (body, code, req, res, err) - The function to be called with the response if the request succeeds.
705-- Headers (string) - Headers that should be added to the request. Split with \r\n.
706-- Note: This function doesn't return anything. It's asynchronous. Use the OnComplete callback for that.
707function SendHTTPRequest (URL, PostData, OnComplete [, Headers] )
708Example with some GET authentication + Lua execution:
709
710SendHTTPRequest('http://someurl.com/auth?username=' .. username .. '&pass=' .. password, nil,
711 function(body, code, req, res, err)
712 RunScript(body) -- contents that were downloaded
713 print(code) -- string - HTTP Response Code
714 print(req) -- string - Full HTTP Request
715 print(res) -- string - Full HTTP Response
716 print(err) -- string - Some internal Socket Error
717 end,
718 "Authentication: bmljZQ==\r\nX-My-Server: HelloServer\r\nX-My-Client: HelloClient\r\n"
719)
720
721--- Get a session variable.
722-- Name (string) - The variable name
723-- returns (string) - The value
724function GetSessionVariable (Name)
725
726--- Set a session variable.
727-- Name (string) - The variable name
728-- Value (string) - The new value
729function SetSessionVariable (Name)
730
731--- Get whether the game client is the foreground window.
732-- returns (boolean) - Whether the game client is the foreground window
733function IsForeground ()
734
735--- Get the state of a key.
736-- Key (integer) - The virtual key code
737-- returns (boolean, boolean) - Whether the key is down and whether the key is toggled
738-- Virtual Key Codes: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
739function GetKeyState (Key)
740function GetAsyncKeyState (Key)
741
742--- Get an offset used by EWT.
743-- Name (string) - The offset name
744-- returns (number) - The offset value if found
745-- Example: GetOffset("FrameScript_RegisterFunction") or GetOffset("CGGameObject_C__Animation") for Fishing bobber animation
746-- On WoWs <= 4.3.4, you use this to get certain descriptors too, like GetOffset("UNIT_FIELD_FLAGS").
747function GetOffset (Name)
748
749--- Get a WoW descriptor.
750-- Group (string) - The group that the descriptor belongs
751-- Name (string) - The descriptor name
752-- returns (number) - The offset value if found
753-- Example: GetDescriptor("CGObjectData", "Scale") or GetDescriptor("CGPlayerData", "PlayerTitle")
754-- Notes: Descriptor name follows an upper camel case convention, like UpperCamelCase.
755-- For a list of WoW descriptors, check Ownedcore's Info Dump Threads in the Memory Editing Section
756function GetDescriptor (Group, Name)
757 return GetOffset(Group .. '__' .. Name)
758end
759
760--- Create a Timer (useful for WoW versions below Warlords which don't have the C_Timer API)
761-- Duration (number) - The interval in milliseconds of the timer
762-- Callback (function) - The function to be called when the interval ends
763-- NumRuns (number) - Default: 0 (Repeats infinitely). Number of times the callback must be called.
764-- returns (number) - ID of the timer. Returns nil if error.
765-- Example: local timerId = CreateTimer(200, function() print('Test') end)
766-- Note: Timers persist through Lua reloads so if you lose the ID, you can't stop it.
767-- Note: If the Timer already executed all NumRuns, you don't need to call StopTimer.
768function CreateTimer (Duration, Callback[, NumRuns])
769
770--- Stop a Timer created by CreateTimer
771-- TimerID (number) - The ID of the Timer
772-- returns (boolean) - True if it stopped or error if the timer wasn't found
773-- Notes: Upon calling this function, the Timer is completely destroyed and you must call CreateTimer again.
774-- Example: StopTimer(timerId)
775function StopTimer (TimerID)
776
777--- Sends a key to WoW's window
778-- Key (number or string) - The key to be sent
779-- Release (boolean) - Whether the key should be released. Default: true
780-- Example: SendKey('2') or SendKey(0x32) or SendKey(50) - Keep in mind the keys are in ASCII
781function SendKey (Key[, Release])
782
783--- Reads the given memory address.
784-- Address (number) - The address
785-- Type (string) - The type of data (Types table)
786-- returns the requested type of data (guid, string, bool, number, etc)
787function ReadMemory (Address, Type)
788
789--- Unloads EWT
790function UnloadEWT()
791
792
793--------------- DirectX Drawing Functions -------
794
795--- Draws a DirectX line
796-- startX (number) - The X coordinate of the line start
797-- startY (number) - The Y coordinate of the line start
798-- endX (number) - The X coordinate of the line end
799-- endY (number) - The Y coordinate of the line end
800-- width (number) - The width of the line
801-- return (boolean) - true if it worked, false if not
802function Draw2DLine(startX, startY, endX, endY[, width = 1.0f])
803
804--- Draws a DirectX line
805-- Object (object) - The origin object (start of line)
806-- Target (object) - The target object (end of line)
807-- width (number) - The width of the line
808-- return (boolean) - true if it worked, false if not
809function Draw2DLine(Object, Target[, width = 1.0f])
810
811--- Sets the global RGBA color for the next rendering. No need to call this all the time if you
812--- don't change the color often.
813-- red (number) - The Red component
814-- green (number) - The Green component
815-- blue (number) - The Blue component
816-- alpha (number) - The Alpha component
817function SetDrawColor(red, green, blue[, alpha = 1.0f])
818
819--- Draws a DirectX text
820-- textX (number) - The X coordinate of the text
821-- textY (number) - The Y coordinate of the text
822-- text (number) - The Blue component
823function Draw2DText(textX, textY, text)
824
825-- Example of how to draw a line to your target
826local f = CreateFrame("Frame")
827f:SetScript("OnUpdate", function (self, event, addon)
828 Draw2DLine("player", "target")
829end)
830
831-- Example of how to draw Tracker Projections and Text using the APIs above:
832local OBJECTTRACKER = {}
833local f = CreateFrame("Frame")
834f:SetScript("OnUpdate", function(self, event, addon)
835 local sWidth, sHeight = GetScreenWidth(), GetScreenHeight()
836 SetDrawColor(1, 1, 1, 1) -- white
837 Draw2DText(sWidth * 0.5, sHeight * 0.5, "THIS IS A TEST")
838 local totalObjects = GetObjectCount()
839 for i = 1, totalObjects do
840 local object = GetObjectWithIndex(i)
841 OBJECTTRACKER[object] = CanTrackObject(object)
842 end
843 local playerX, playerY, playerZ = ObjectPosition("player")
844 local camX, camY, camZ = GetCameraPosition()
845 for i, v in pairs(OBJECTTRACKER) do
846 if v then -- Bool: if the object can be tracked or not
847 local targetX, targetY, targetZ = ObjectPosition(i)
848 if targetX and targetY and targetZ then
849 local arg1 = GetDistanceBetweenPositions(playerX, playerY, playerZ, targetX, targetY, targetZ)
850 local arg2 = GetDistanceBetweenPositions(camX, camY, camZ, targetX, targetY, targetZ)
851 if arg1 <= arg2 then
852 if ObjectIsType(i, ObjectTypes.Unit) then
853 local reaction = UnitReaction("player", i)
854 if reaction then
855 if reaction > 4 then
856 if UnitIsPlayer(i) then
857 SetDrawColor(0, 0, 1, 1) -- blue
858 else
859 SetDrawColor(0, 1, 0, 1) -- green
860 end
861 elseif reaction == 4 then
862 SetDrawColor(1, 1, 0, 1) -- yellow
863 elseif reaction < 4 then
864 SetDrawColor(1, 0, 0, 1) -- red
865 end
866 else
867 SetDrawColor(1, 1, 1, 1) -- white
868 end
869 else
870 SetDrawColor(1, 1, 1, 1) -- white
871 end
872 local player2DX, player2DY = WorldToScreen_Original(playerX, playerY, playerZ)
873 local target2DX, target2DY = WorldToScreen_Original(targetX, targetY, targetZ)
874 Draw2DLine(player2DX * sWidth, player2DY * sHeight, target2DX * sWidth, target2DY * sHeight)
875 end
876 end
877 end
878 end
879end)
880
881
882--------------- LibDraw Drawing Functions -------
883-- For more info, check this https://github.com/MrTheSoulz/NerdPack-Protected/blob/master/external/LibDraw.lua
884
885LibDraw.Sync(function()
886 if UnitExists("target") then
887 local playerX, playerY, playerZ = ObjectPosition("player")
888 local targetX, targetY, targetZ = ObjectPosition("target")
889 local reaction = UnitReaction("player", "target")
890 if reaction >= 5 then
891 LibDraw.SetColorRaw(0, 1, 0, 1)
892 elseif reaction == 4 then
893 LibDraw.SetColorRaw(1, 1, 0, 1)
894 elseif reaction <= 3 then
895 LibDraw.SetColorRaw(1, 0, 0, 1)
896 end
897 LibDraw.Line(playerX, playerY, playerZ, targetX, targetY, targetZ)
898 -- LibDraw.Circle(targetX, targetY, targetZ, 5)
899 end
900end)
901LibDraw.Enable(0.01)
902
903https://ewtwow.com/EWT/ewt.lua