Exemplo n.º 1
0
        //structs that are serialized down to just their values.
        private void GenerateSpecialStruct(TreeNode t, string structType, int size)
        {
            TreeNode node;

            //have to handle this specially to get the degrees conversion
            if (structType == "Rotator")
            {
                string[] labels = { "Pitch", "Yaw", "Roll" };
                int      val;
                for (int i = 0; i < 3; i++)
                {
                    val       = BitConverter.ToInt32(memory, readerpos);
                    node      = new TreeNode(readerpos.ToString("X4") + ": " + labels[i] + " : " + val + " (" + ((float)val * 360f / 65536f).ToString("0.0######") + " degrees)");
                    node.Name = readerpos.ToString();
                    node.Tag  = nodeType.StructLeafDeg;
                    t.Nodes.Add(node);
                    readerpos += 4;
                }
            }
            else
            {
                if (UnrealObjectInfo.Structs.ContainsKey(structType))
                {
                    List <PropertyReader.Property> props;
                    //memoize
                    if (defaultStructValues.ContainsKey(structType))
                    {
                        props = defaultStructValues[structType];
                    }
                    else
                    {
                        byte[] defaultValue = UnrealObjectInfo.getDefaultClassValue(pcc, structType, true);
                        if (defaultValue == null)
                        {
                            //just prints the raw hex since there's no telling what it actually is
                            node     = new TreeNode(readerpos.ToString("X4") + ": " + memory.Skip(readerpos).Take(size).Aggregate("", (b, s) => b + " " + s.ToString("X2")));
                            node.Tag = nodeType.Unknown;
                            t.Nodes.Add(node);
                            readerpos += size;
                            return;
                        }
                        props = PropertyReader.ReadProp(pcc, defaultValue, 0);
                        defaultStructValues.Add(structType, props);
                    }
                    for (int i = 0; i < props.Count; i++)
                    {
                        string s = readerpos.ToString("X4") + ": " + pcc.getNameEntry(props[i].Name) + " : ";
                        readerpos = GenerateSpecialStructProp(t, s, readerpos, props[i]);
                    }
                }
            }

            #region Old method
            //if (structType == "Vector2d" || structType == "RwVector2")
            //{
            //    string[] labels = { "X", "Y" };
            //    for (int i = 0; i < 2; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafFloat;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "Vector" || structType == "RwVector3")
            //{
            //    string[] labels = { "X", "Y", "Z" };
            //    for (int i = 0; i < 3; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafFloat;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "Rotator")
            //{
            //    string[] labels = { "Pitch", "Yaw", "Roll" };
            //    int val;
            //    for (int i = 0; i < 3; i++)
            //    {
            //        val = BitConverter.ToInt32(memory, pos);
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + val + " (" + ((float)val * 360f / 65536f).ToString("0.0######") + " degrees)");
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafDeg;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "Color")
            //{
            //    string[] labels = { "B", "G", "R", "A" };
            //    for (int i = 0; i < 4; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + memory[pos]);
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafByte;
            //        t.Nodes.Add(node);
            //        pos += 1;
            //    }
            //}
            //else if (structType == "LinearColor")
            //{
            //    string[] labels = { "R", "G", "B", "A" };
            //    for (int i = 0; i < 4; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafFloat;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            ////uses EndsWith to support RwQuat, RwVector4, and RwPlane
            //else if (structType.EndsWith("Quat") || structType.EndsWith("Vector4") || structType.EndsWith("Plane"))
            //{
            //    string[] labels = { "X", "Y", "Z", "W" };
            //    for (int i = 0; i < 4; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafFloat;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "TwoVectors")
            //{
            //    string[] labels = { "X", "Y", "Z", "X", "Y", "Z" };
            //    for (int i = 0; i < 6; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafFloat;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "Matrix" || structType == "RwMatrix44")
            //{
            //    string[] labels = { "X Plane", "Y Plane", "Z Plane", "W Plane" };
            //    string[] labels2 = { "X", "Y", "Z", "W" };
            //    TreeNode node2;
            //    for (int i = 0; i < 3; i++)
            //    {
            //        node2 = new TreeNode(labels[i]);
            //        node2.Name = pos.ToString();
            //        for (int j = 0; j < 4; j++)
            //        {
            //            node = new TreeNode(pos.ToString("X4") + ": " + labels2[j] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //            node.Name = pos.ToString();
            //            node.Tag = nodeType.StructLeafFloat;
            //            node2.Nodes.Add(node);
            //            pos += 4;
            //        }
            //        t.Nodes.Add(node2);
            //    }
            //}
            //else if (structType == "Guid")
            //{
            //    string[] labels = { "A", "B", "C", "D" };
            //    for (int i = 0; i < 4; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToInt32(memory, pos));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafInt;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "IntPoint")
            //{
            //    string[] labels = { "X", "Y" };
            //    for (int i = 0; i < 2; i++)
            //    {
            //        node = new TreeNode(pos.ToString("X4") + ": " + labels[i] + " : " + BitConverter.ToInt32(memory, pos));
            //        node.Name = pos.ToString();
            //        node.Tag = nodeType.StructLeafInt;
            //        t.Nodes.Add(node);
            //        pos += 4;
            //    }
            //}
            //else if (structType == "Box" || structType == "BioRwBox")
            //{
            //    string[] labels = { "Min", "Max" };
            //    string[] labels2 = { "X", "Y", "Z" };
            //    TreeNode node2;
            //    for (int i = 0; i < 2; i++)
            //    {
            //        node2 = new TreeNode(labels[i]);
            //        node2.Name = pos.ToString();
            //        for (int j = 0; j < 3; j++)
            //        {
            //            node = new TreeNode(pos.ToString("X4") + ": " + labels2[j] + " : " + BitConverter.ToSingle(memory, pos).ToString("0.0######"));
            //            node.Name = pos.ToString();
            //            node.Tag = nodeType.StructLeafFloat;
            //            node2.Nodes.Add(node);
            //            pos += 4;
            //        }
            //        t.Nodes.Add(node2);
            //    }
            //    node = new TreeNode(pos.ToString("X4") + ": IsValid : " + memory[pos]);
            //    node.Name = pos.ToString();
            //    node.Tag = nodeType.StructLeafByte;
            //    t.Nodes.Add(node);
            //    pos += 1;
            //}
            //else
            //{
            //    for (int i = 0; i < size / 4; i++)
            //    {
            //        int val = BitConverter.ToInt32(memory, pos);
            //        string s = pos.ToString("X4") + ": " + val.ToString();
            //        t.Nodes.Add(s);
            //        pos += 4;
            //    }
            //}
            //readerpos = pos;
            #endregion
        }