Ejemplo n.º 1
0
        private static void ReadAndDumpField(UpdateField uf, StringBuilder sb, GenericReader gr, UpdateTypes updatetype, StreamWriter data, WoWObject obj)
        {
            MemoryStream  ms  = new MemoryStream(gr.ReadBytes(4));
            GenericReader gr2 = new GenericReader(ms);

            if (updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT || updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT2)
            {
                obj.SetUInt32Value(uf.Identifier, gr2.ReadUInt32());
                gr2.BaseStream.Position -= 4;
            }

            switch (uf.Type)
            {
            // TODO: add data writing

            /*case 3:
             *  string val1 = gr.ReadSingle().ToString().Replace(",", ".");
             *  if (updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT || updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT2)
             *      data.WriteLine(uf.Name + " (" + uf.Identifier + "): " + val1);
             *  sb.AppendLine(uf.Name + " (" + index + "): " + val1);
             *  break;
             * default:
             *  uint val2 = gr.ReadUInt32();
             *  if (updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT || updatetype == UpdateTypes.UPDATETYPE_CREATE_OBJECT2)
             *      data.WriteLine(uf.Name + " (" + uf.Identifier + "): " + val2);
             *  sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + val2);
             *  break;*/
            case 1:     // uint32
                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + gr2.ReadUInt32().ToString("X8"));
                break;

            case 2:     // uint16+uint16
                ushort value1 = gr2.ReadUInt16();
                ushort value2 = gr2.ReadUInt16();

                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + "first " + value1.ToString("X4") + ", second " + value2.ToString("X4"));
                if (uf.Name.StartsWith("PLAYER_SKILL_INFO_1_"))
                {
                    int num = uf.Identifier - 858;
                    if ((num % 3) == 0)
                    {
                        ushort skill = value1;
                        ushort flag  = value2;

                        string str = String.Format("skill {0}, flag {1}", skill, (ProfessionFlags)flag);
                        sb.AppendLine(str);
                    }
                    else if (((num - 1) % 3) == 0)
                    {
                        ushort minskill = value1;
                        ushort maxskill = value2;

                        string str = String.Format("minskill {0}, maxskill {1}", minskill, maxskill);
                        sb.AppendLine(str);
                    }
                    else
                    {
                        ushort minbonus = value1;
                        ushort maxbonus = value2;

                        string str = String.Format("minbonus {0}, maxbonus {1}", minbonus, maxbonus);
                        sb.AppendLine(str);
                    }
                }
                break;

            case 3:     // float
                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + gr2.ReadSingle());
                //sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + gr.ReadSingle().ToString().Replace(",", "."));
                break;

            case 4:     // uint64 (can be only low part)
                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + gr2.ReadUInt32().ToString("X8"));
                break;

            case 5:     // bytes
                uint value = gr2.ReadUInt32();
                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + value.ToString("X8"));
                if (uf.Identifier == 36)     // UNIT_FIELD_BYTES_0
                {
                    byte[] bytes     = BitConverter.GetBytes(value);
                    Races  race      = (Races)bytes[0];
                    Class  class_    = (Class)bytes[1];
                    Gender gender    = (Gender)bytes[2];
                    Powers powertype = (Powers)bytes[3];

                    string str = String.Format("Race: {0}, class: {1}, gender: {2}, powertype: {3}", race, class_, gender, powertype);
                    sb.AppendLine(str);
                }
                break;

            default:
                sb.AppendLine(uf.Name + " (" + uf.Identifier + "): " + "unknown type " + gr2.ReadUInt32().ToString("X8"));
                break;
            }

            gr2.Close();
        }