コード例 #1
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();
            }
        }
コード例 #2
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;
        }