Esempio n. 1
0
 public void ImportProperty(PCCPackage pcc, PCCPackage importpcc, PropertyReader.Property p, MemoryStream m)
 {
     string name = importpcc.GetName(p.Name);
     int idxname = pcc.FindNameOrAdd(name);
     m.Write(BitConverter.GetBytes(idxname), 0, 4);
     m.Write(new byte[4], 0, 4);
     if (name == "None")
         return;
     string type = importpcc.GetName(BitConverter.ToInt32(p.raw, 8));
     int idxtype = pcc.FindNameOrAdd(type);
     m.Write(BitConverter.GetBytes(idxtype), 0, 4);
     m.Write(new byte[4], 0, 4);
     string name2;
     int idxname2;
     int size, count, pos;
     List<PropertyReader.Property> Props;
     switch (type)
     {
         case "IntProperty":
         case "FloatProperty":
         case "ObjectProperty":
         case "StringRefProperty":
             m.Write(BitConverter.GetBytes(4), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
             break;
         case "NameProperty":
             m.Write(BitConverter.GetBytes(8), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
             m.Write(new byte[4], 0, 4);
             break;
         case "BoolProperty":
             m.Write(new byte[8], 0, 8);
             m.WriteByte((byte)p.Value.IntValue);
             break;
         case "ByteProperty": 
             name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
             idxname2 = pcc.FindNameOrAdd(name2);
             m.Write(BitConverter.GetBytes(8), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(idxname2), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
             m.Write(new byte[4], 0, 4);
             break;
         case "DelegateProperty":                    
             size = BitConverter.ToInt32(p.raw, 16);
             if (size == 0xC)
             {
                 name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 28));
                 idxname2 = pcc.FindNameOrAdd(name2);
                 m.Write(BitConverter.GetBytes(0xC), 0, 4);
                 m.Write(new byte[4], 0, 4);
                 m.Write(new byte[4], 0, 4);
                 m.Write(BitConverter.GetBytes(idxname2), 0, 4);
                 m.Write(new byte[4], 0, 4);
             }
             else
             {
                 m.Write(BitConverter.GetBytes(size), 0, 4);
                 m.Write(new byte[4], 0, 4);
                 for (int i = 0; i < size; i++)
                     m.WriteByte(p.raw[24 + i]);
             }
             break;
         case "StrProperty":
             name2 = p.Value.StringValue;
             m.Write(BitConverter.GetBytes(4 + name2.Length * 2), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(-name2.Length), 0, 4);
             foreach (char c in name2)
             {
                 m.WriteByte((byte)c);
                 m.WriteByte(0);
             }
             break;
         case "StructProperty":
             size = BitConverter.ToInt32(p.raw, 16);
             name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
             idxname2 = pcc.FindNameOrAdd(name2);
             pos = 32;
             Props = new List<PropertyReader.Property>();
             try
             {
                 Props = PropertyReader.ReadProp(importpcc, p.raw, pos);
             }
             catch (Exception)
             {
             }
             m.Write(BitConverter.GetBytes(size), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(idxname2), 0, 4);
             m.Write(new byte[4], 0, 4);
             if (Props.Count == 0)
             {
                 for (int i = 0; i < size; i++)
                     m.WriteByte(p.raw[32 + i]);
             }
             else if (Props[0].TypeVal == PropertyReader.Type.Unknown)
             {
                 for (int i = 0; i < size; i++)
                     m.WriteByte(p.raw[32 + i]);
             }
             else
             {
                 foreach (PropertyReader.Property pp in Props)
                     ImportProperty(pcc, importpcc, pp, m);
             }
             break;
         case "ArrayProperty":
             size = BitConverter.ToInt32(p.raw, 16);
             count = BitConverter.ToInt32(p.raw, 24);
             pos = 28;
             List<PropertyReader.Property> AllProps = new List<PropertyReader.Property>();
             for (int i = 0; i < count; i++)
             {
                 Props = new List<PropertyReader.Property>();
                 int test1 = BitConverter.ToInt32(p.raw, pos);
                 int test2 = BitConverter.ToInt32(p.raw, pos + 4);
                 if (!importpcc.isName(test1) || test2 != 0)
                     break;
                 if (importpcc.GetName(test1) != "None")
                     if (BitConverter.ToInt32(p.raw, pos + 12) != 0)
                         break;
                 try
                 {
                     Props = PropertyReader.ReadProp(importpcc, p.raw, pos);
                 }
                 catch (Exception)
                 {
                 }
                 AllProps.AddRange(Props);
                 if (Props.Count != 0)
                 {
                     pos = Props[Props.Count - 1].offend;
                 }
             }
             m.Write(BitConverter.GetBytes(size), 0, 4);
             m.Write(new byte[4], 0, 4);
             m.Write(BitConverter.GetBytes(count), 0, 4);
             if (AllProps.Count != 0)
                 foreach (PropertyReader.Property pp in AllProps)
                     ImportProperty(pcc, importpcc, pp, m);
             else
                 m.Write(p.raw, 28, size - 4);
             break;
         default:
             throw new Exception(type);
     }
 }
Esempio n. 2
0
 public TreeNode MakeDefaultPropNode(PropertyReader.Property p)
 {
     string tp = PropertyReader.TypeToString((int)p.TypeVal);
     switch (tp)
     {
         case "Byte Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : (" + pcc.GetName(BitConverter.ToInt32(p.raw, 24)) + ") " + pcc.GetName(BitConverter.ToInt32(p.raw, 32)));
         case "Bool Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + (p.Value.IntValue == 1));
         case "Object Property":
             string s = " ";
             if (p.Value.IntValue != 0)
                 s = pcc.GetObject(p.Value.IntValue);
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + p.Value.IntValue + s);
         case "Integer Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + p.Value.IntValue);
         case "Name Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + pcc.GetName(p.Value.IntValue));
         case "Float Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + BitConverter.ToSingle(p.raw, 24));
         case "String Property":
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ") : " + p.Value.StringValue);
         default:
             return new TreeNode(pcc.GetName(p.Name) + " (" + tp + ")");
     }
 }
Esempio n. 3
0
 public static byte[] getDefaultClassValue(PCCPackage pcc, string className, bool fullProps = false)
 {
     if (Structs.ContainsKey(className))
     {
         bool       isImmutable = ImmutableStructs.Contains(className);
         ClassInfo  info        = Structs[className];
         PCCPackage importPCC   = new PCCPackage(Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath));
         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.GetName(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);
                 }
             }
         }
         importPCC.Source.Close();
         return(m.ToArray());
     }
     else if (Classes.ContainsKey(className))
     {
         ClassInfo                      info      = Structs[className];
         PCCPackage                     importPCC = new PCCPackage(Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath));
         PCCPackage.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.GetName(p.Name)))
             {
                 //property is transient
                 continue;
             }
             PropertyReader.ImportProperty(pcc, importPCC, p, className, m);
         }
         return(m.ToArray());
     }
     return(null);
 }