ArcEmu: [Lua] Packet editing - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Lua] Packet editing

#1 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 16 November 2009 - 04:08 AM

Welcome to the second installment of the The More You Know™ Lua tutorial series. The idea of these is to give small but extremely useful pockets of information for Lua scripters.
Posted Image
Packet Editing

1. What are Packets?
Packets are small chunks of data exchanged between the client (WoW) and the server (ArcEmu, etc). Packets are used for all communication between players and servers. They are very small, usually in total only a few bytes in size. Thus, packet editing gives you essentially byte-by-byte control of what happens between players and the server.

2. It's complicated.
This isn't easy. There is little documentation about packets available, and most of the packet structures are discovered by looking through the core. C++ knowledge is advised. But, on the upside, you can have heaps of fun once you DO work out how to use them :D.

3. Packet structures
Every packet that's sent has a type. As in, one packet might be designed to make a monster move, another might be designed to play a sound. And every single one of those types has it's own packet structure. A packet structure is basically a blueprint of what the packet will contain. Packet structures say what bytes will go where within that packet. And, you can't edit packets without knowing their structure.
There's a catch - it's really hard to find these structures. There's the official packet documentation - http://www.arcemu.in...p?title=Packets - but there's hardly anything there. You're best bet is searching the core for what you want.

4. Working through an example
Today I'm going to show you how to change the weather in the game, the manual way. From here on I'm going to assume that you have the defined variables.lua in your scripts folder.

Step 1: Create the packet object
local packet = LuaPacket:CreatePacket(type, size)

Remember how we said that packets have types? Well that's what you do in this step. Every packet type is listed in defined variables.lua, under "opcodes.h" subheading. Hopefully you've already researched what packet you need, so you won't need this. I know I want me a SMSG_WEATHER type packet to change the weather.
size refers to how many bytes of data the packet will contain. The easiest thing to do is make this some high number like 100 to start with.
This command uses the LuaPacket class to create a new packet object that we will use in our other functions.
local packet = LuaPacket:CreatePacket(SMSG_WEATHER, 100)

Step 2: Add dataz to it
packet:Write<datatype>(data)

This is where you're packet structure comes in. I've updated the wiki with the SMSG_WEATHER structure for you all to see: http://www.arcemu.in...le=SMSG_WEATHER . By looking at that site, we need to give the type, density and sound of the weather we want, and then also tack on a 0 at the end (in that order).
The <datatype> is given on that webpage - it's right next the name of the data we're going to add. As in, "type" is a uint32, "density" will be a float, etc. Depending on what those data types are, the <datatype> will change:

Quote

WriteByte +- Writes an int8
WriteUByte +- Writes an uint8
WriteShort +- Writes an int16
WriteUShort +- Writes an uint16
WriteLong +- Writes an int32
WriteULong +- Writes an uint32
WriteFloat +- Writes a float
WriteDouble +- Writes a double
WriteGUID +- Writes an uint64

So, in my case, to add the data to our initialised packet:
packet:WriteULong(8) --weather type first: datatype uint32, value: 8 (snow)
packet:WriteFloat(2.0) --density next: datatype float, value: 2.0 (max density)
packet:WriteULong(8538) --sound next: datatype uint32, sound id 8538 (it's a snowy sound)
packet:WriteUByte(0) --our forced "0" we must tack on the end with SMSG_WEATHER.

Step 3: Send the packet
Now that we have built a packet, we have to send it. You have many options for sending packets:
   Unit:SendPacket(packet, self)                   	+- Sends the packet to the nearby units. if self is true, the packet will also be sent to Unit.
   Plyr:SendPacketToGroup(packet)			+- Sends the packet to Plyr's group.
   Plyr:SendPacketToGuild(packet)			+- Sends the packet to Plyr's guild.
   Plyr:SendPacketToPlayer(packet)                	+- Sends the packet to Plyr.
   Unit:SendPacketToZone(packet,zone_id)          	+- Sends the packet to Zone zone_id. 
   Unit:SendPacketToInstance(packet,instance_id)  	+- Sends the packet to Instance instance_id.
   Unit:SendPacketToWorld(packet)                 	+- Sends the packet to the world.

Hmm... who should I make it snow for? Just one player? A guild? The world? I've decided that I want to send it to just one player, so they get freaked out when it starts snowing in Orgrimmar.
player:SendPacketToPlayer(packet) --sends our packet.


5. Done
Well, you're done. That poor player is now getting snowed on. And yes, it's a pain, and takes a long time to do, but it is pretty advanced work. Yes, it IS much easier just to use player:SetPlayerWeather(8, 2.0), but this was to show you how to get down to one of the most advanced edits available in HypArc.
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
1

#2 User is offline   paroxysm 

  • Chatty Cathy
  • Group: Retired
  • Posts: 320
  • Joined: 25-June 08
  • Gender:Male
  • Server OS:Windows

Posted 16 November 2009 - 01:26 PM

I commend your progess on getting packets to work Lua side, however, from what I've seen it seems very limited and the syntax to invoke this is not very eye friendly. I suggest you implement packets as objects in Lua. By that you can create a packet just like you would in C++, weather_packet = LuaPacket:CreatePacket(op_code,size). This way, you can treat the packet much more object oriented like weather_packet:WriteUInt8-64,weather_packet:ReadUInt8-16, weather_packet:AppendGUID()... etc and such. This way, the syntax looks much cleaner and friendlier. :rolleyes:
0

#3 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 04 December 2009 - 05:18 AM

Updated guide with new packets system!
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#4 User is offline   alleycat 

  • Helps so much & is so mature & gay
  • PipPipPipPipPip
  • Group: Members
  • Posts: 835
  • Joined: 25-July 08
  • Gender:Male

Posted 04 December 2009 - 12:23 PM

Quote

2. It's complicated.
This isn't easy.

Lolz
I can haz cookie?
0

#5 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 04 December 2009 - 02:49 PM

Well, it may not be hard for the Arcemu scripting community, but it was originally posted on wow-v which has significantly less scripters, so I tried to ease them in to a new concept. :lol:
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#6 User is offline   link_S 

  • Newbie
  • Group: Members
  • Posts: 2
  • Joined: 07-February 09

Posted 30 December 2009 - 05:02 PM

I'm very curious about how you decided the function names for writing values to the stack. It's very wierd in my opinion.

This is my view of it;
Why did you pick the Byte to represent the int8 when in C++ it's really the uint8?
And why did you pick the Long to represent the int32(normal integer) when in C++ it consists of 64 bits and not 32 as the integer?

Please correct me if I'm wrong.

In my opinion, I'd wanted the Long to represent the int64 and the Byte to represent uint8. Because for us C++ developers who sometimes use lua, and want to add packets to it. Don't get lost :(
0

#7 User is offline   paroxysm 

  • Chatty Cathy
  • Group: Retired
  • Posts: 320
  • Joined: 25-June 08
  • Gender:Male
  • Server OS:Windows

Posted 30 December 2009 - 07:29 PM

The names were picked for simplicity, on my system, long are 4 bytes not 8. The reason such names were picked is if you try to declare a integer, a signed version is simply int, however to get an unsigned int, you put the unsigned keyword before. So the same concept was followed when designing these packet api.
0

#8 User is offline   link_S 

  • Newbie
  • Group: Members
  • Posts: 2
  • Joined: 07-February 09

Posted 31 December 2009 - 06:23 AM

Thanks for your answer. But it seems wierd that the bits are changed from system to system. As on my multiple systems I've always had the BYTE as 8 bits unsigned. And the Long always 64 bits signed. "/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users