Register for your free account! | Forgot your password?

You last visited: Today at 08:00

  • Please register to post and access all features, it's quick, easy and FREE!


Packet Structures From XML

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 754
Packet Structures From XML

Not sure, if it works nor if I have done it right, but it looks correct to me.

However would it be a good thing to read packet structures from a xml file like this or is there better ways?

The reason I'm interested in it, it's because you do not need to open source to edit offsets nor build, if an offset is wrong or something.

The wrapper:
Code:
    public class PacketStructure
    {
        public int Size;
        private XmlTextReader Reader;
        public Dictionary<int, PacketData> Data;

        public static Func<string, int> ToInt32 = new Func<string, int>(int.Parse);
        public static Func<string, uint> ToUInt32 = new Func<string, uint>(uint.Parse);
        public static Func<string, short> ToInt16 = new Func<string, short>(short.Parse);
        public static Func<string, ushort> ToUInt16 = new Func<string, ushort>(ushort.Parse);
        public static Func<string, sbyte> ToInt8 = new Func<string, sbyte>(sbyte.Parse);
        public static Func<string, byte> ToUInt8 = new Func<string, byte>(byte.Parse);
        public static Func<string, bool> ToBool = new Func<string, bool>(bool.Parse);
        public static Func<string, double> ToDouble = new Func<string, double>(double.Parse);
        public static Func<string, long> ToInt64 = new Func<string, long>(long.Parse);
        public static Func<string, ulong> ToUInt64 = new Func<string, ulong>(ulong.Parse);
        public static Func<string, float> ToFloat = new Func<string, float>(float.Parse);

        public PacketStructure(string XmlLoc)
        {
            if (!XmlLoc.EndsWith(".xml"))
                XmlLoc += ".xml";

            if (!System.IO.File.Exists(XmlLoc))
                throw new System.IO.FileLoadException("There was a problem locating the xml file ('" + XmlLoc + "')");

            Reader = new XmlTextReader(XmlLoc);
            Data = new Dictionary<int, PacketData>();
        }

        public void Read()
        {
            while (Reader.Read())
            {
                string DataType = Reader.Name;

                if (DataType == "Size")
                {
                    Size = ToInt32(Reader.GetAttribute(0));
                }
                else
                {

                    PacketData Data = new PacketData();
                    Data.Offset = ToInt32(Reader.GetAttribute(0));
                    switch (DataType)
                    {
                        #region SByte
                        case "SByte":
                            Data.Default = ToInt8(Reader.Value);
                            break;
                        #endregion

                        #region Int16
                        case "Int16":
                            Data.Default = ToInt16(Reader.Value);
                            break;
                        #endregion

                        #region Int32
                        case "Int32":
                            Data.Default = ToInt32(Reader.Value);
                            break;
                        #endregion

                        #region Int64
                        case "Int64":
                            Data.Default = ToInt64(Reader.Value);
                            break;
                        #endregion

                        #region Byte
                        case "Byte":
                            Data.Default = ToUInt8(Reader.Value);
                            break;
                        #endregion

                        #region UInt16
                        case "UInt16":
                            Data.Default = ToUInt16(Reader.Value);
                            break;
                        #endregion

                        #region UInt32
                        case "UInt32":
                            Data.Default = ToUInt32(Reader.Value);
                            break;
                        #endregion

                        #region UInt64
                        case "UInt64":
                            Data.Default = ToUInt64(Reader.Value);
                            break;
                        #endregion

                        #region Double
                        case "Double":
                            Data.Default = ToDouble(Reader.Value);
                            break;
                        #endregion

                        #region Float
                        case "Float":
                            Data.Default = ToFloat(Reader.Value);
                            break;
                        #endregion

                        #region Bool
                        case "Bool":
                            Data.Default = ToBool(Reader.Value);
                            break;
                        #endregion
                    }
                    Data.Value = Data.Default;
                    this.Data.Add(Data.Offset, Data);
                }
            }
        }

        public static implicit operator PacketData[](PacketStructure Structure)
        {
            return Structure.Data.Values.ToArray();
        }
    }
    public struct PacketData
    {
        public object Value;
        public object Default;
        public int Offset;
    }



BaussHacker is offline  
Old 10/10/2011, 10:25   #2
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,124
Received Thanks: 2,498
Simply put, whats the point? 90% of the time if you have to change a packet you have to change logic aswell, and if an offset is wrong you will naturally open the source to breakpoint test the problem before fixing it, so the source is open anyway =x


Korvacs is offline  
Thanks
1 User
Old 10/10/2011, 10:26   #3
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 754
Quote:
Originally Posted by Korvacs View Post
Simply put, whats the point? 90% of the time if you have to change a packet you have to change logic aswell.
That you do not need to build your server to edit offsets.

True t that tho, but under development it could be nice, because you don't have to rebuild the whole server, because you have one wrong offset.
BaussHacker is offline  
Old 10/10/2011, 10:33   #4
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,124
Received Thanks: 2,498
Sorry just edited the post


Korvacs is offline  
Old 10/10/2011, 10:34   #5
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 754
So it would be rather useless rofl?
BaussHacker is offline  
Old 10/10/2011, 10:43   #6
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,124
Received Thanks: 2,498
Personally i would never use such a thing for packets unless i knew they would never change ever, and even then there would be increased loading time at runtime due to having to grab these using io.
Korvacs is offline  
Old 10/10/2011, 10:44   #7
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 754
Quote:
Originally Posted by Korvacs View Post
Personally i would never use such a thing for packets unless i knew they would never change ever, and even then there would be increased loading time at runtime due to having to grab these using io.
Well you grab it at load time not while using the packetstructures. It's one time load. But I get what you mean, thanks for clearing it up.


BaussHacker is offline  
Reply



« Small things for small rewards. | how to decrease the magic attack for fire tao? »

Similar Threads
[Request] Nobility Packet Structures
Can somebody share Nobility packet structures(5180) with me or the community Please? I need them so bad :( .. Not The Icon (I've got that) But The...
5 Replies - CO2 PServer - Discussions / Questions
[RELEASE] 5293 Packet Structures
Hello :awesome:. Do NOT flame me for releasing this, saying noobs can now get the latest patch to work, because 'noobs' as we like to call them,...
47 Replies - CO2 PServer Guides & Releases
[Opinion] Do you like how these Packet Structures work?
I got my answer, remove this thread.
38 Replies - CO2 PServer - Discussions / Questions
[Q]Packet Structures
any1 can help me with packet structures..? like When I have packet like 0x11 or any other type. Data is for example: 11 00 00 00 4A 58 9A 4A 32...
10 Replies - Kal Online
[Request] Packet Structures
Hello, Could anyone provide me with an adequet resource for looking up packet structures, or provide me on information about where I could find...
0 Replies - CO2 PServer - Discussions / Questions



All times are GMT +2. The time now is 08:00.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.