private static SequenceObjectInfo generateSequenceObjectInfo(int i, PCCObject pcc)
        {
            SequenceObjectInfo info = new SequenceObjectInfo();

            PropertyReader.Property inputLinks = PropertyReader.getPropOrNull(pcc, pcc.Exports[i + 1], "InputLinks");
            if (inputLinks != null)
            {
                int    pos    = 28;
                byte[] global = inputLinks.raw;
                int    count  = BitConverter.ToInt32(global, 24);
                for (int j = 0; j < count; j++)
                {
                    List <PropertyReader.Property> p2 = PropertyReader.ReadProp(pcc, global, pos);

                    info.inputLinks.Add(p2[0].Value.StringValue);
                    for (int k = 0; k < p2.Count(); k++)
                    {
                        pos += p2[k].raw.Length;
                    }
                }
            }
            return(info);
        }
 public static byte[] getDefaultClassValue(PCCObject pcc, string className, bool fullProps = false)
 {
     if (Structs.ContainsKey(className))
     {
         bool      isImmutable   = ImmutableStructs.Contains(className);
         ClassInfo info          = Structs[className];
         String    pccToLoadPath = Path.Combine(TransplanterLib.GamePath, @"BIOGame\" + info.pccPath);
         PCCObject importPCC     = null;
         pccMemoryCache.TryGetValue(pccToLoadPath, out importPCC);
         if (importPCC == null)
         {
             try
             {
                 importPCC = new PCCObject(pccToLoadPath);
                 pccMemoryCache[pccToLoadPath] = importPCC;
             }
             catch (Exception)
             {
                 return(null);
             }
         }
         byte[] buff;
         //Plane and CoverReference inherit from other structs, meaning they don't have default values (who knows why)
         //thus, I have hardcoded what those default values should be
         if (className == "Plane")
         {
             buff = PlaneDefault;
         }
         else if (className == "CoverReference")
         {
             buff = CoverReferenceDefault;
         }
         else
         {
             buff = importPCC.Exports[info.exportIndex].Data.Skip(0x24).ToArray();
         }
         List <PropertyReader.Property> Props = PropertyReader.ReadProp(importPCC, buff, 0);
         MemoryStream m = new MemoryStream();
         foreach (PropertyReader.Property p in Props)
         {
             string propName = importPCC.getNameEntry(p.Name);
             //check if property is transient, if so, skip (neither of the structs that inherit have transient props)
             if (info.properties.ContainsKey(propName) || propName == "None" || info.baseClass != "Class")
             {
                 if (isImmutable && !fullProps)
                 {
                     PropertyReader.ImportImmutableProperty(pcc, importPCC, p, className, m, true);
                 }
                 else
                 {
                     PropertyReader.ImportProperty(pcc, importPCC, p, className, m, true);
                 }
             }
         }
         return(m.ToArray());
     }
     else if (Classes.ContainsKey(className))
     {
         ClassInfo info          = Structs[className];
         String    pccToLoadPath = Path.Combine(TransplanterLib.GamePath, @"BIOGame\" + info.pccPath);
         PCCObject importPCC;
         if (pccMemoryCache[pccToLoadPath] != null)
         {
             importPCC = pccMemoryCache[pccToLoadPath];
         }
         else
         {
             try
             {
                 importPCC = new PCCObject(pccToLoadPath);
                 pccMemoryCache[pccToLoadPath] = importPCC;
             }
             catch (Exception)
             {
                 return(null);
             }
         }
         PCCObject.ExportEntry          entry = pcc.Exports[info.exportIndex + 1];
         List <PropertyReader.Property> Props = PropertyReader.getPropList(importPCC, entry);
         MemoryStream m = new MemoryStream(entry.DataSize - 4);
         foreach (PropertyReader.Property p in Props)
         {
             if (!info.properties.ContainsKey(importPCC.getNameEntry(p.Name)))
             {
                 //property is transient
                 continue;
             }
             PropertyReader.ImportProperty(pcc, importPCC, p, className, m);
         }
         return(m.ToArray());
     }
     return(null);
 }
Пример #3
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
        }