Valhalla Legends Forums Archive | BnetDocs Research and Discussion | Re: [C#] PacketID Constants for C#

AuthorMessageTime
Smarter
As more and more programmers language of choice is becoming C#, I have converted the Consts to C# format, and hope they are added to BNETDocs: Redux:

[code]
    public enum PacketIDConstants : byte
    {
        // PacketID Constants for C#
        // Generated by BNETDocs: Redux on September 26, 2007, and Modified for C# by Smarter.


        // Battle.net Messages Constants
        // -------------------

        SID_NULL = 0x00,
        SID_STOPADV = 0x02,
        SID_SERVERLIST = 0x04,
        SID_CLIENTID = 0x05,
        SID_STARTVERSIONING = 0x06,
        SID_REPORTVERSION = 0x07,
        SID_STARTADVEX = 0x08,
        SID_GETADVLISTEX = 0x09,
        SID_ENTERCHAT = 0x0A,
        SID_GETCHANNELLIST = 0x0B,
        SID_JOINCHANNEL = 0x0C,
        SID_CHATCOMMAND = 0x0E,
        SID_CHATEVENT = 0x0F,
        SID_LEAVECHAT = 0x10,
        SID_LOCALEINFO = 0x12,
        SID_FLOODDETECTED = 0x13,
        SID_UDPPINGRESPONSE = 0x14,
        SID_CHECKAD = 0x15,
        SID_CLICKAD = 0x16,
        SID_REGISTRY = 0x18,
        SID_MESSAGEBOX = 0x19,
        SID_STARTADVEX2 = 0x1A,
        SID_GAMEDATAADDRESS = 0x1B,
        SID_STARTADVEX3 = 0x1C,
        SID_LOGONCHALLENGEEX = 0x1D,
        SID_CLIENTID2 = 0x1E,
        SID_LEAVEGAME = 0x1F,
        SID_DISPLAYAD = 0x21,
        SID_NOTIFYJOIN = 0x22,
        SID_PING = 0x25,
        SID_READUSERDATA = 0x26,
        SID_WRITEUSERDATA = 0x27,
        SID_LOGONCHALLENGE = 0x28,
        SID_LOGONRESPONSE = 0x29,
        SID_CREATEACCOUNT = 0x2A,
        SID_SYSTEMINFO = 0x2B,
        SID_GAMERESULT = 0x2C,
        SID_GETICONDATA = 0x2D,
        SID_GETLADDERDATA = 0x2E,
        SID_FINDLADDERUSER = 0x2F,
        SID_CDKEY = 0x30,
        SID_CHANGEPASSWORD = 0x31,
        SID_CHECKDATAFILE = 0x32,
        SID_GETFILETIME = 0x33,
        SID_QUERYREALMS = 0x34,
        SID_PROFILE = 0x35,
        SID_CDKEY2 = 0x36,
        SID_LOGONRESPONSE2 = 0x3A,
        SID_CHECKDATAFILE2 = 0x3C,
        SID_CREATEACCOUNT2 = 0x3D,
        SID_LOGONREALMEX = 0x3E,
        SID_STARTVERSIONING2 = 0x3F,
        SID_QUERYREALMS2 = 0x40,
        SID_QUERYADURL = 0x41,
        SID_WARCRAFTGENERAL = 0x44,
        SID_NETGAMEPORT = 0x45,
        SID_NEWS_INFO = 0x46,
        SID_OPTIONALWORK = 0x4A,
        SID_EXTRAWORK = 0x4B,
        SID_REQUIREDWORK = 0x4C,
        SID_AUTH_INFO = 0x50,
        SID_AUTH_CHECK = 0x51,
        SID_AUTH_ACCOUNTCREATE = 0x52,
        SID_AUTH_ACCOUNTLOGON = 0x53,
        SID_AUTH_ACCOUNTLOGONPROOF = 0x54,
        SID_AUTH_ACCOUNTCHANGE = 0x55,
        SID_AUTH_ACCOUNTCHANGEPROOF = 0x56,
        SID_AUTH_ACCOUNTUPGRADE = 0x57,
        SID_AUTH_ACCOUNTUPGRADEPROOF = 0x58,
        SID_SETEMAIL = 0x59,
        SID_RESETPASSWORD = 0x5A,
        SID_CHANGEEMAIL = 0x5B,
        SID_SWITCHPRODUCT = 0x5C,
        SID_WARDEN = 0x5E,
        SID_GAMEPLAYERSEARCH = 0x60,
        SID_FRIENDSLIST = 0x65,
        SID_FRIENDSUPDATE = 0x66,
        SID_FRIENDSADD = 0x67,
        SID_FRIENDSREMOVE = 0x68,
        SID_FRIENDSPOSITION = 0x69,
        SID_CLANFINDCANDIDATES = 0x70,
        SID_CLANINVITEMULTIPLE = 0x71,
        SID_CLANCREATIONINVITATION = 0x72,
        SID_CLANDISBAND = 0x73,
        SID_CLANMAKECHIEFTAIN = 0x74,
        SID_CLANINFO = 0x75,
        SID_CLANQUITNOTIFY = 0x76,
        SID_CLANINVITATION = 0x77,
        SID_CLANREMOVEMEMBER = 0x78,
        SID_CLANINVITATIONRESPONSE = 0x79,
        SID_CLANRANKCHANGE = 0x7A,
        SID_CLANSETMOTD = 0x7B,
        SID_CLANMOTD = 0x7C,
        SID_CLANMEMBERLIST = 0x7D,
        SID_CLANMEMBERREMOVED = 0x7E,
        SID_CLANMEMBERSTATUSCHANGE = 0x7F,
        SID_CLANMEMBERRANKCHANGE = 0x81,
        SID_CLANMEMBERINFORMATION = 0x82,

        // Battle.net UDP Messages Constants
        // -------------------

        PKT_CLIENTREQ = 0x03,
        PKT_SERVERPING = 0x05,
        PKT_KEEPALIVE = 0x07,
        PKT_CONNTEST = 0x08,
        PKT_CONNTEST2 = 0x09,

        // Realm Messages Constants
        // -------------------

        MCP_STARTUP = 0x01,
        MCP_CHARCREATE = 0x02,
        MCP_CREATEGAME = 0x03,
        MCP_JOINGAME = 0x04,
        MCP_GAMELIST = 0x05,
        MCP_GAMEINFO = 0x06,
        MCP_CHARLOGON = 0x07,
        MCP_CHARDELETE = 0x0A,
        MCP_REQUESTLADDERDATA = 0x11,
        MCP_MOTD = 0x12,
        MCP_CANCELGAMECREATE = 0x13,
        MCP_CREATEQUEUE = 0x14,
        MCP_CHARLIST = 0x17,
        MCP_CHARUPGRADE = 0x18,
        MCP_CHARLIST2 = 0x19,

        // D2GS Messages Constants
        // -------------------

        D2GS_WALKTOLOCATION = 0x01,
        D2GS_WALKTOENTITY = 0x02,
        D2GS_RUNTOLOCATION = 0x03,
        D2GS_RUNTOENTITY = 0x04,
        D2GS_LEFTSKILLONLOCATION = 0x05,
        D2GS_LEFTSKILLONENTITY = 0x06,
        D2GS_LEFTSKILLONENTITYEX = 0x07,
        D2GS_LEFTSKILLONLOCATIONEX = 0x08,
        D2GS_LEFTSKILLONENTITYEX2 = 0x09,
        D2GS_LEFTSKILLONENTITYEX3 = 0x0A,
        D2GS_RIGHTSKILLONLOCATION = 0x0C,
        D2GS_RIGHTSKILLONENTITY = 0x0D,
        D2GS_RIGHTSKILLONENTITYEX = 0x0E,
        D2GS_RIGHTSKILLONLOCATIONEX = 0x0F,
        D2GS_CHARTOOBJ = 0x10,
        D2GS_RIGHTSKILLONENTITYEX2 = 0x10,
        D2GS_RIGHTSKILLONENTITYEX3 = 0x11,
        D2GS_0x12 = 0x12,
        D2GS_INTERACTWITHENTITY = 0x13,
        D2GS_OVERHEADMESSAGE = 0x14,
        D2GS_CHATMESSAGE = 0x15,
        D2GS_PICKUPITEM = 0x16,
        D2GS_DROPITEM = 0x17,
        D2GS_ITEMTOBUFFER = 0x18,
        D2GS_SMALLGOLDPICKUP = 0x19,
        D2GS_PICKUPBUFFERITEM = 0x19,
        D2GS_ITEMTOBODY = 0x1A,
        D2GS_SWAP2HANDEDITEM = 0x1B,
        D2GS_PICKUPBODYITEM = 0x1C,
        D2GS_SETBYTEATTR = 0x1D,
        D2GS_SWITCHBODYITEM = 0x1D,
        D2GS_SETWORDATTR = 0x1E,
        D2GS_SETDWORDATTR = 0x1F,
        D2GS_SWITCHINVENTORYITEM = 0x1F,
        D2GS_USEITEM = 0x20,
        D2GS_STACKITEM = 0x21,
        D2GS_REMOVESTACKITEM = 0x22,
        D2GS_ITEMTOBELT = 0x23,
        D2GS_REMOVEBELTITEM = 0x24,
        D2GS_SWITCHBELTITEM = 0x25,
        D2GS_USEBELTITEM = 0x26,
        D2GS_INSERTSOCKETITEM = 0x28,
        D2GS_SCROLLTOTOME = 0x29,
        D2GS_ITEMTOCUBE = 0x2A,
        D2GS_UNSELECTOBJ = 0x2D,
        D2GS_NPCINIT = 0x2F,
        D2GS_NPCCANCEL = 0x30,
        D2GS_NPCBUY = 0x32,
        D2GS_NPCSELL = 0x33,
        D2GS_NPCTRADE = 0x38,
        D2GS_CHARACTERPHRASE = 0x3F,
        D2GS_WAYPOINT = 0x49,
        D2GS_TRADE = 0x4F,
        D2GS_DROPGOLD = 0x50,
        D2GS_WORLDOBJECT = 0x51,
        D2GS_REQUESTENTERENVIRONMENT = 0x5C,
        D2GS_PARTY = 0x5E,
        D2GS_POTIONTOMERCENARY = 0x61,
        D2GS_GAMELOGON = 0x68,
        D2GS_ENTERGAMEENVIRONMENT = 0x6A,
        D2GS_PING = 0x6D,
        D2GS_TRADEACTION = 0x77,
        D2GS_LOGONRESPONSE = 0x7A,
        D2GS_SERVERCONNECTED = 0xAF,

        // BotNet Messages Constants
        // -------------------

        PACKET_IDLE = 0x00,
        PACKET_LOGON = 0x01,
        PACKET_STATSUPDATE = 0x02,
        PACKET_DATABASE = 0x03,
        PACKET_MESSAGE = 0x04,
        PACKET_CYCLE = 0x05,
        PACKET_USERINFO = 0x06,
        PACKET_USERLOGGINGOFF = 0x07,
        PACKET_BROADCASTMESSAGE = 0x07,
        PACKET_COMMAND = 0x08,
        PACKET_CHANGEDBPASSWORD = 0x09,
        PACKET_BOTNETVERSION = 0x0A,
        PACKET_BOTNETCHAT = 0x0B,
        PACKET_ACCOUNT = 0x0D,
        PACKET_CHATDROPOPTIONS = 0x10,

        // BNLS Messages Constants
        // -------------------

        BNLS_NULL = 0x00,
        BNLS_CDKEY = 0x01,
        BNLS_LOGONCHALLENGE = 0x02,
        BNLS_LOGONPROOF = 0x03,
        BNLS_CREATEACCOUNT = 0x04,
        BNLS_CHANGECHALLENGE = 0x05,
        BNLS_CHANGEPROOF = 0x06,
        BNLS_UPGRADECHALLENGE = 0x07,
        BNLS_UPGRADEPROOF = 0x08,
        BNLS_VERSIONCHECK = 0x09,
        BNLS_CONFIRMLOGON = 0x0A,
        BNLS_HASHDATA = 0x0B,
        BNLS_CDKEY_EX = 0x0C,
        BNLS_CHOOSENLSREVISION = 0x0D,
        BNLS_AUTHORIZE = 0x0E,
        BNLS_AUTHORIZEPROOF = 0x0F,
        BNLS_REQUESTVERSIONBYTE = 0x10,
        BNLS_VERIFYSERVER = 0x11,
        BNLS_RESERVESERVERSLOTS = 0x12,
        BNLS_SERVERLOGONCHALLENGE = 0x13,
        BNLS_SERVERLOGONPROOF = 0x14,
        BNLS_VERSIONCHECKEX = 0x18,
        BNLS_VERSIONCHECKEX2 = 0x1A
    }
[/code]
September 26, 2007, 8:46 AM
LockesRabb
Wow, you actually did the entire thing. You actually didn't need to do the entire thing, only the syntax was needed.

What usually is needed for setting up code generation is:

header
comment tag
proper format
footer

In your case, it would have been:

header:
public enum PacketIDConstants : byte
{

comment tag: //

proper format: PACKET_NAME = 0x00,

footer: }

Once someone gives me all the needed data as I have given in the above example for C Sharp (C#), I just plug them into the code generator, and it takes care of the rest. Here's the code snippet used for the C# generator:

[code] } elseif($lang == 'csharp'){
$commentizer = '//';
include 'bdif/codecomments.dm';
$commentizer = '//';
echo 'public enum PacketIDConstants : byte<br>{<br>';
if($gid != 'all'){
$sqlquery = 'SELECT * FROM packets WHERE pgroup='.$gid.' GROUP BY messagename ORDER BY messageid,direction DESC';
} else {
$sqlquery = 'SELECT * FROM packets GROUP BY messagename ORDER BY pgroup,messageid,direction DESC';
}
$packetsarray = mysql_query($sqlquery);
$pgroup = -1;
while($row = mysql_fetch_array($packetsarray)){
if($row['pgroup'] != $pgroup){
$pgroup = $row['pgroup'];
$groupname = GetInfo('groups', 'id', $pgroup, 'groupname');
if($ie) echo '';
echo '<br>'.$commentizer.' '.$groupname.' Constants<br>';
echo $commentizer.' -------------------<br><br>';
if($ie) echo '';
}
$pid = $row['id'];
$messageid = $row['messageid'];
$messagename = $row['messagename'];

echo ''.$messagename.' = '.$messageid.',<br>';
}
echo '}';
[/code]

The great thing is, as packets are added, edited and removed, the code generator will dynamically generate the updated list accordingly. Even if new packet groups are added, they'll be included automatically.

As for giving you proper due credit (well deserved, since you manually set up each and every packet constant!), you've been contributed proper due credit on the credits page:

http://bnetdocs.dementedminds.net/?op=credits

Thanks for your contribution! It most certainly is appreciated!
September 26, 2007, 9:40 AM
Hell-Lord
Jinxbot has a better sorted list if you need one. It also contains detailed comments.
September 26, 2007, 9:59 AM
Smarter
A little note, the last Enum cannot end with a comma, the last one just ends normally [code]        BNLS_VERSIONCHECKEX = 0x18,
        BNLS_VERSIONCHECKEX2 = 0x1A[/code] ;).
September 26, 2007, 10:24 AM
LockesRabb
[quote author=Smarter link=topic=17053.msg173246#msg173246 date=1190802248]
A little note, the last Enum cannot end with a comma, the last one just ends normally [code]        BNLS_VERSIONCHECKEX = 0x18,
        BNLS_VERSIONCHECKEX2 = 0x1A[/code] ;).
[/quote]

Fixed. Thanks.
September 26, 2007, 11:07 AM
Myndfyr
[quote author=Smarter link=topic=17053.msg173246#msg173246 date=1190802248]
A little note, the last Enum cannot end with a comma, the last one just ends normally [code]        BNLS_VERSIONCHECKEX = 0x18,
        BNLS_VERSIONCHECKEX2 = 0x1A[/code] ;).
[/quote]

Actually, in C# an enum *can* end with a comma, and in fact I do that typically.  Makes adding a new one just a bit easier.
September 29, 2007, 12:45 AM
JoeTheOdd
I have my constants in FelBot as a class with a bunch of integer fields. That way you can write testing code somewhat easier, but just passing a magic integer around, but to each their own.
October 3, 2007, 7:17 AM
Camel
[quote author=Joe[x86] link=topic=17053.msg173488#msg173488 date=1191395871]
I have my constants in FelBot as a class with a bunch of integer fields. That way you can write testing code somewhat easier, but just passing a magic integer around, but to each their own.
[/quote]

An enum is just a set of typed constants.
October 3, 2007, 11:46 PM
JoeTheOdd
How easy is it to pass an integer instead of an enum'd value? Or does the enum itself extend a base type?
October 6, 2007, 1:19 PM
Quarantine
Magic numbers are never cool. They lead to cryptic code and debugging nightmares at times.

Let's use enums for the better of mankind. I'm sure if you get an exception in .NET Intellisense will list the value of the field in the class as the corresponding enumeration entry. Aka much cleaner.

Not 100% sure though.
October 6, 2007, 2:06 PM
Myndfyr
[quote author=Joe[x86] link=topic=17053.msg173627#msg173627 date=1191676787]
How easy is it to pass an integer instead of an enum'd value? Or does the enum itself extend a base type?
[/quote]

Enums extend System.Enum, though syntactically they can extend any base integral type:
[code]
// as used in Bnet:
public enum BncsPacketID : byte {
//...
}

// as used in WoW
public enum ClientOpcode : short {
  // ...
}

// enums default to ints
[/code]

Enums can (syntactically) extend byte, sbyte, short, ushort, int, uint, long, and ulong.  Enums that extend sbyte, ushort, uint, and ulong are not CLS-compliant.

They do requre explicit casts to their integral counterparts because an implicit cast would involve a loss of information.  So you'd need to do something like:
[code]
buffer.AddInt16((short)ClientOpcode.GuildSetPublicNote);
[/code]

The other advantage is this:
[code]
ClientOpcode code = ClientOpcode.GuildSetPublicNote;
Console.WriteLine(code);
[/code]
Output:
GuildSetPublicNote
October 6, 2007, 7:56 PM
Camel
Java is the same way, although it's a little trickier to get an enum to bind to a set value. Here's how I define release types for my battle.net bot:

[code]
/**
* This file is distributed under the GPL
* $Id: ReleaseType.java 731 2007-10-06 19:38:20Z scotta $
*/

package net.bnubot.vercheck;

public enum ReleaseType {
Stable(0),
ReleaseCandidate(1),
Beta(2),
Alpha(3),
Development(4);

private int t;
private ReleaseType(int t) {
this.t = t;
}

public boolean isDevelopment() {
return (t == Development.t);
}
...
}
[/code]

And its use:
[code]ReleaseType rt = Enum.valueOf(ReleaseType.class, "Development");
System.out.println(rt.toString());[/code]
October 7, 2007, 8:19 AM

Search