private static void ReadStreamIntoContainer(BinaryReader reader, PacketProtocolData fieldContainer)
        {
            var mymod = ModHelpersMod.Instance;
            IOrderedEnumerable <FieldInfo> orderedFields = fieldContainer.OrderedFields;
            int i = 0;

            if (mymod.Config.DebugModePacketInfo)
            {
                LogHelpers.Log("  Begun reading packet " + fieldContainer.GetType().Name + " (" + fieldContainer.FieldCount + " fields)");
            }

            foreach (FieldInfo field in orderedFields)
            {
                i++;

                Type   fieldType = field.FieldType;
                object fieldData = PacketProtocolData.ReadStreamValue(reader, fieldType);

                if (Main.netMode == 1)
                {
                    if (Attribute.IsDefined(field, typeof(PacketProtocolWriteIgnoreServerAttribute)))
                    {
                        continue;
                    }
                }
                else if (Main.netMode == 2)
                {
                    if (Attribute.IsDefined(field, typeof(PacketProtocolWriteIgnoreClientAttribute)))
                    {
                        continue;
                    }
                }

                if (mymod.Config.DebugModePacketInfo)
                {
                    LogHelpers.Log("  * Reading packet " + fieldContainer.GetType().Name
                                   + " field (" + i + " of " + fieldContainer.FieldCount + ") " + field.Name
                                   + ": " + DotNetHelpers.Stringify(fieldData, 32));
                }

//LogHelpers.Log( "READ "+ fieldContainer.GetType().Name + " FIELD " + field + " VALUE " + fieldData );
                field.SetValue(fieldContainer, fieldData);
            }
        }
        private static void WriteStreamFromContainer(BinaryWriter writer, PacketProtocolData fieldContainer)
        {
            var mymod = ModHelpersMod.Instance;
            IOrderedEnumerable <FieldInfo> orderedFields = fieldContainer.OrderedFields;
            int i = 0;

            if (!PacketProtocolData.ValidateConstructor(fieldContainer.GetType()))
            {
                throw new HamstarException("Invalid default constructor for " + fieldContainer.GetType().Name);
            }

            if (mymod.Config.DebugModePacketInfo)
            {
                LogHelpers.Log("  Begun writing packet " + fieldContainer.GetType().Name + " (" + fieldContainer.FieldCount + " fields)");
            }

            foreach (FieldInfo field in orderedFields)
            {
                i++;

                if (Main.netMode == 1 && Attribute.IsDefined(field, typeof(PacketProtocolWriteIgnoreClientAttribute)))
                {
                    continue;
                }
                else if (Main.netMode == 2 && Attribute.IsDefined(field, typeof(PacketProtocolWriteIgnoreServerAttribute)))
                {
                    continue;
                }

                object rawFieldVal = field.GetValue(fieldContainer);
                //LogHelpers.Log( "WRITE "+ data.GetType().Name+ " FIELD " + field + " VALUE "+(rawFieldVal??"null"));

                if (mymod.Config.DebugModePacketInfo)
                {
                    LogHelpers.Log("  * Writing packet " + fieldContainer.GetType().Name
                                   + " field (" + i + " of " + fieldContainer.FieldCount + ") "
                                   + field.Name + ": " + DotNetHelpers.Stringify(rawFieldVal, 32));
                }

                PacketProtocolData.WriteStreamValue(writer, field.FieldType, rawFieldVal);
            }
        }