|
You last visited: Today at 05:47
Advertisement
Packet Structures From XML
Discussion on Packet Structures From XML within the CO2 Private Server forum part of the Conquer Online 2 category.
10/10/2011, 10:23
|
#1
|
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
|
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;
}
|
|
|
10/10/2011, 10:25
|
#2
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
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
|
|
|
10/10/2011, 10:26
|
#3
|
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
|
Quote:
Originally Posted by Korvacs
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.
|
|
|
10/10/2011, 10:33
|
#4
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
Sorry just edited the post
|
|
|
10/10/2011, 10:34
|
#5
|
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
|
So it would be rather useless rofl?
|
|
|
10/10/2011, 10:43
|
#6
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
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.
|
|
|
10/10/2011, 10:44
|
#7
|
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
|
Quote:
Originally Posted by Korvacs
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.
|
|
|
|
Similar Threads
|
[Request] Nobility Packet Structures
01/26/2011 - CO2 Private Server - 5 Replies
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 Donation and etc.
Thank you.
P.S. Korvacs Please Update CO Wiki.
|
[RELEASE] 5293 Packet Structures
09/06/2010 - CO2 PServer Guides & Releases - 47 Replies
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, need more than simple packet structures. Please if you use these packet structures, do not use them for ready to use sources, that would really, really mess up the private servers gain.
From this moment on I am going to release Packet Structures for the Conquer Client patch 5293.
These might be missing, or incorrect, but work for me, or...
|
[Opinion] Do you like how these Packet Structures work?
08/14/2010 - CO2 Private Server - 38 Replies
I got my answer, remove this thread.
|
[Q]Packet Structures
06/18/2010 - Kal Online - 10 Replies
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 ...
Where 4A 58 represents some WORD (coord, playerid, whatever)
etc.
thanks......
|
[Request] Packet Structures
04/12/2009 - CO2 Private Server - 0 Replies
Hello,
Could anyone provide me with an adequet resource for looking up packet structures, or provide me on information about where I could find them?
I have searched through about 3 CO server sources - they have been a great help but I need more..
Thanks,
Leo (null)
|
All times are GMT +2. The time now is 05:47.
|
|