Exemplo n.º 1
0
        /// <summary>
        /// Creates a empty ready-to-use copy of a given implementation of DBSRVPackets.
        /// </summary>
        public static T CreatePacket <T>(ushort opcode) where T : struct, DBSRVPackets
        {
            MSG_HEADER validHeader = new MSG_HEADER();
            T          packet      = W2Marshal.CreateEmpty <T>();

            // Set the default values to the packet header.
            validHeader.Size      = (ushort)Marshal.SizeOf(packet);
            validHeader.PacketID  = opcode;
            validHeader.Key       = (byte)W2Random.Instance.Next(127);
            validHeader.TimeStamp = (uint)Environment.TickCount;

            packet.Header = validHeader;

            return(packet);
        }
        /// <summary>
        /// Creates a empty ready-to-use copy of a given implementation of IGamePacket.
        /// </summary>
        public static T GetEmptyValid <T>(ushort opcode) where T : struct, IGamePacket
        {
            MPacketHeader validHeader = new MPacketHeader();
            T             packet      = W2Marshal.CreateEmpty <T>();

            // Set the default values to the packet header.
            validHeader.Size      = (ushort)Marshal.SizeOf(packet);
            validHeader.Opcode    = opcode;
            validHeader.Key       = (byte)W2Random.Instance.Next(127);
            validHeader.TimeStamp = (uint)Environment.TickCount;

            packet.Header = validHeader;

            return(packet);
        }
Exemplo n.º 3
0
        public static T memset <T>(T Struct) where T : struct
        {
            byte[]   rawData = W2Marshal.GetBytes <T>(Struct);
            GCHandle gch     = GCHandle.Alloc(rawData, GCHandleType.Pinned);

            Memset(gch.AddrOfPinnedObject(), 0, rawData.Length);
            var pinnedRawData = GCHandle.Alloc(rawData, GCHandleType.Pinned);

            try
            {
                var pinnedRawDataPtr = pinnedRawData.AddrOfPinnedObject();
                return((T)Marshal.PtrToStructure(pinnedRawDataPtr, typeof(T)));
            }
            finally
            {
                pinnedRawData.Free();
            }
        }
Exemplo n.º 4
0
        public static void WritePacket <T>(T Packet) where T : struct
        {
            MSG_HEADER header = W2Marshal.GetStructure <MSG_HEADER>(W2Marshal.GetBytes(Packet));

            try
            {
                string CorrectPatch = $"./PacketDebug/{ header.PacketID} .json";
                if (File.Exists(CorrectPatch))
                {
                    return;
                }

                using (StreamWriter file = File.CreateText(CorrectPatch))
                {
                    string indented = JsonConvert.SerializeObject(Packet, Formatting.Indented);
                    file.Write(indented);
                }
            }
            catch (Exception e)
            {
                return;
            }
            return;
        }