예제 #1
0
        public static List <Property> getPropList(PCCPackage pcc, PCCPackage.ExportEntry export)
        {
            Application.DoEvents();
            int start = detectStart(pcc, export.Data, (uint)export.ObjectFlags);

            return(ReadProp(pcc, export.Data, start));
        }
예제 #2
0
 public void LoadBaseGameFile(string path)
 {
     if (pcc != null && pcc.Source != null)
         pcc.Source.Close();
     pcc = new PCCPackage(path, true, false);
     interpreter1.Pcc = pcc;
 }
예제 #3
0
 public void LoadFile(string path)
 {
     currfilepath = path;
     this.Text = "Camera Tool - " + Path.GetFileName(path);
     pcc = new PCCPackage(path, true, false, true);
     Indexes = new List<int>();
     for (int i = 0; i < pcc.Exports.Count; i++)
     {
         PCCPackage.ExportEntry e = pcc.Exports[i];
         string c = pcc.GetObject(e.idxClass);
         if (c == "InterpData")
         {
             List<PropertyReader.Property> props = PropertyReader.ReadProp(pcc, e.Data, PropertyReader.detectStart(pcc, e.Data, (uint)e.ObjectFlags));
             bool has = false;
             foreach (PropertyReader.Property p in props)
                 if (pcc.GetName(p.Name) == "InterpGroups")
                 {
                     has = true;
                     break;
                 }
             if (has)
                 Indexes.Add(i);
         }
     }
     FreshList();
 }
예제 #4
0
        public static int? GetValue(PCCPackage p, int index)
        {
            Objectselect prompt = new Objectselect();
            prompt.Init(p, index);

            return prompt.ShowDialog() == DialogResult.OK ? prompt.returnValue() : null;
        }
예제 #5
0
        private static PropertyValue ReadValue(PCCPackage pcc, byte[] raw, int start, int type)
        {
            var v = new PropertyValue();

            switch (pcc.Names[type])
            {
            case "IntProperty":
            case "FloatProperty":
            case "ObjectProperty":
            case "StringRefProperty":
                v.IntValue = BitConverter.ToInt32(raw, start);
                v.len      = 4;
                break;

            case "NameProperty":
                v.IntValue = BitConverter.ToInt32(raw, start);
                v.len      = 8;
                break;

            case "BoolProperty":
                if (start < raw.Length)
                {
                    v.IntValue = raw[start];
                }
                v.len = 1;
                break;
            }
            return(v);
        }
예제 #6
0
        public static List <Property> getPropList(PCCPackage pcc, byte[] raw)
        {
            Application.DoEvents();
            var start = detectStart(pcc, raw);

            return(ReadProp(pcc, raw, start));
        }
예제 #7
0
        private static Type getType(PCCPackage pcc, int type)
        {
            switch (pcc.GetName(type))
            {
            case "None": return(Type.None);

            case "StructProperty": return(Type.StructProperty);

            case "IntProperty": return(Type.IntProperty);

            case "FloatProperty": return(Type.FloatProperty);

            case "ObjectProperty": return(Type.ObjectProperty);

            case "NameProperty": return(Type.NameProperty);

            case "BoolProperty": return(Type.BoolProperty);

            case "ByteProperty": return(Type.ByteProperty);

            case "ArrayProperty": return(Type.ArrayProperty);

            case "DelegateProperty": return(Type.DelegateProperty);

            case "StrProperty": return(Type.StrProperty);

            case "StringRefProperty": return(Type.StringRefProperty);

            default:
                return(Type.Unknown);
            }
        }
예제 #8
0
        public static int GetValue(PCCPackage p, int index)
        {
            Nameselect prompt = new Nameselect();
            prompt.Init(p, index);

            return prompt.ShowDialog() == DialogResult.OK ? prompt.returnValue() : -1;
        }
예제 #9
0
 public void Init(PCCPackage p, int index)
 {
     pcc = p;
     comboBox1.Items.Clear();
     for (int i = 0; i < pcc.Header.NameCount; i++)
         comboBox1.Items.Add(i.ToString("d6") + " : " + pcc.Names[i]);
     comboBox1.SelectedIndex = index;
 }
예제 #10
0
        public static CustomProperty PropertyToGrid(Property p, PCCPackage pcc)
        {
            var            cat = p.TypeVal.ToString();
            CustomProperty pg;

            switch (p.TypeVal)
            {
            case Type.BoolProperty:
                pg = new CustomProperty(pcc.Names[p.Name], cat, (p.Value.IntValue == 1), typeof(bool), false, true);
                break;

            case Type.FloatProperty:
                var buff = BitConverter.GetBytes(p.Value.IntValue);
                var f    = BitConverter.ToSingle(buff, 0);
                pg = new CustomProperty(pcc.Names[p.Name], cat, f, typeof(float), false, true);
                break;

            case Type.ByteProperty:
            case Type.NameProperty:
                var pp = new NameProp();
                pp.name      = pcc.GetName(p.Value.IntValue);
                pp.nameindex = p.Value.IntValue;
                pg           = new CustomProperty(pcc.Names[p.Name], cat, pp, typeof(NameProp), false, true);
                break;

            case Type.ObjectProperty:
                var ppo = new ObjectProp();
                ppo.name      = pcc.GetName(p.Value.IntValue);
                ppo.nameindex = p.Value.IntValue;
                pg            = new CustomProperty(pcc.Names[p.Name], cat, ppo, typeof(ObjectProp), false, true);
                break;

            case Type.StructProperty:
                var ppp = new StructProp();
                ppp.name      = pcc.GetName(p.Value.IntValue);
                ppp.nameindex = p.Value.IntValue;
                var buf = new byte[p.Value.Array.Count()];
                for (var i = 0; i < p.Value.Array.Count(); i++)
                {
                    buf[i] = (byte)p.Value.Array[i].IntValue;
                }
                var buf2 = new List <int>();
                for (var i = 0; i < p.Value.Array.Count() / 4; i++)
                {
                    buf2.Add(BitConverter.ToInt32(buf, i * 4));
                }
                ppp.data = buf2.ToArray();
                pg       = new CustomProperty(pcc.Names[p.Name], cat, ppp, typeof(StructProp), false, true);
                break;

            default:
                pg = new CustomProperty(pcc.Names[p.Name], cat, p.Value.IntValue, typeof(int), false, true);
                break;
            }
            return(pg);
        }
예제 #11
0
        public static string PropertyToText(Property p, PCCPackage pcc)
        {
            var s = "";

            s  = "Name: " + pcc.Names[p.Name];
            s += " Type: " + TypeToString((int)p.TypeVal);
            s += " Size: " + p.Value.len;
            switch (p.TypeVal)
            {
            case Type.StructProperty:
                s += " \"" + pcc.GetName(p.Value.IntValue) + "\" with " + p.Value.Array.Count + " bytes";
                break;

            case Type.IntProperty:
            case Type.ObjectProperty:
            case Type.BoolProperty:
            case Type.StringRefProperty:
                s += " Value: " + p.Value.IntValue;
                break;

            case Type.FloatProperty:
                var buff = BitConverter.GetBytes(p.Value.IntValue);
                var f    = BitConverter.ToSingle(buff, 0);
                s += " Value: " + f;
                break;

            case Type.NameProperty:
                s += " " + pcc.Names[p.Value.IntValue];
                break;

            case Type.ByteProperty:
                s += " Value: \"" + p.Value.StringValue + "\" with \"" + pcc.GetName(p.Value.IntValue) + "\"";
                break;

            case Type.ArrayProperty:
                s += " bytes";                         //Value: " + p.Value.Array.Count.ToString() + " Elements";
                break;

            case Type.StrProperty:
                if (p.Value.StringValue.Length == 0)
                {
                    break;
                }
                s += " Value: " + p.Value.StringValue.Substring(0, p.Value.StringValue.Length - 1);
                break;
            }
            return(s);
        }
예제 #12
0
        public static int detectStart(PCCPackage pcc, byte[] raw, uint flags)
        {
            if ((flags & 0x02000000) != 0)
            {
                return(30);
            }
            var result = 8;
            var test1  = BitConverter.ToInt32(raw, 4);
            var test2  = BitConverter.ToInt32(raw, 8);

            if (pcc.IsName(test1) && test2 == 0)
            {
                result = 4;
            }
            if (pcc.IsName(test1) && pcc.IsName(test2) && test2 != 0)
            {
                result = 8;
            }
            return(result);
        }
예제 #13
0
 public void Init(PCCPackage pcc, int index)
 {
     comboBox1.Items.Clear();
     comboBox2.Items.Clear();
     for (int i = 0; i < pcc.Header.ExportCount; i++)
         comboBox1.Items.Add(i.ToString("d6") + " : " + pcc.GetObjectPath(i + 1) + pcc.getObjectName(i + 1));
     for (int i = 0; i < pcc.Header.ImportCount; i++)
         comboBox2.Items.Add(i.ToString("d6") + " : " + pcc.GetObjectPath(-i - 1) + pcc.getObjectName(-i - 1));
     comboBox1.SelectedIndex = comboBox2.SelectedIndex = 0;
     if (index == 0)
         r1.Checked = true;
     if (index > 0)
     {
         comboBox1.SelectedIndex = index - 1;
         r2.Checked = true;
     }
     if (index < 0)
     {
         comboBox2.SelectedIndex = -index - 1;
         r3.Checked = true;
     }
 }
예제 #14
0
        private static PropertyValue ReadValue(PCCPackage pcc, byte[] raw, int start, int type)
        {
            PropertyValue v = new PropertyValue();

            switch (pcc.Names[type])
            {
            case "IntProperty":
            case "FloatProperty":
            case "ObjectProperty":
            case "StringRefProperty":
                v.IntValue = BitConverter.ToInt32(raw, start);
                v.len      = 4;
                break;

            case "NameProperty":
                v.IntValue = BitConverter.ToInt32(raw, start);
                var nameRef = new NameReference();
                nameRef.index = v.IntValue;
                nameRef.count = BitConverter.ToInt32(raw, start + 4);
                nameRef.Name  = pcc.GetName(nameRef.index);
                if (nameRef.count > 0)
                {
                    nameRef.Name += "_" + (nameRef.count - 1);
                }
                v.NameValue = nameRef;
                v.len       = 8;
                break;

            case "BoolProperty":
                if (start < raw.Length)
                {
                    v.IntValue = raw[start];
                }
                v.len = 1;
                break;
            }
            return(v);
        }
예제 #15
0
        public static int detectStart(PCCPackage pcc, byte[] raw)
        {
            var result = 8;
            var test1  = BitConverter.ToInt32(raw, 4);

            if (test1 < 0)
            {
                result = 30;
            }
            else
            {
                var test2 = BitConverter.ToInt32(raw, 8);
                if (pcc.IsName(test1) && test2 == 0)
                {
                    result = 4;
                }
                if (pcc.IsName(test1) && pcc.IsName(test2) && test2 != 0)
                {
                    result = 8;
                }
            }
            return(result);
        }
예제 #16
0
 public static List<Property> getPropList(PCCPackage pcc, byte[] raw)
 {
     Application.DoEvents();
     int start = detectStart(pcc, raw);
     return ReadProp(pcc,raw,start);
 }
예제 #17
0
 public static List<Property> getPropList(PCCPackage pcc, PCCPackage.ExportEntry export)
 {
     Application.DoEvents();
     int start = detectStart(pcc, export.Data, (uint)export.ObjectFlags);
     return ReadProp(pcc, export.Data, start);
 }
예제 #18
0
 private static PropertyValue ReadValue(PCCPackage pcc, byte[] raw, int start, int type)
 {
     PropertyValue v = new PropertyValue();
     switch (pcc.Names[type])
     {
         case "IntProperty":
         case "FloatProperty":
         case "ObjectProperty":
         case "StringRefProperty":
             v.IntValue = BitConverter.ToInt32(raw, start);
             v.len = 4;
             break;
         case "NameProperty":
             v.IntValue = BitConverter.ToInt32(raw, start);
             v.len = 8;
             break;
         case "BoolProperty":
             if(start < raw.Length)
                 v.IntValue = raw[start];
             v.len = 1;
             break;
     }
     return v;
 }
예제 #19
0
 private void button3_Click(object sender, EventArgs e)
 {
     OpenFileDialog d = new OpenFileDialog();
     d.Filter = "*.pcc|*.pcc";
     if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (importpcc != null && importpcc.Source != null)
             importpcc.Source.Close();
         importpcc = new PCCPackage(d.FileName, true);
         listBox6.Items.Clear();
         listBox6.Visible = false;
         for (int i = 0; i < importpcc.Imports.Count; i++)
             listBox6.Items.Add(i.ToString("d6") + " : " + importpcc.GetObjectPath(-i - 1) + importpcc.GetObject(-i - 1));
         listBox6.Visible = true;
     }
 }
예제 #20
0
 private static PropertyValue ReadValue(PCCPackage pcc, byte[] raw, int start, int type)
 {
     PropertyValue v = new PropertyValue();
     switch (pcc.Names[type])
     {
         case "IntProperty":
         case "FloatProperty":
         case "ObjectProperty":
         case "StringRefProperty":
             v.IntValue = BitConverter.ToInt32(raw, start);
             v.len = 4;
             break;
         case "NameProperty":
             v.IntValue = BitConverter.ToInt32(raw, start);
             var nameRef = new NameReference();
             nameRef.index = v.IntValue;
             nameRef.count = BitConverter.ToInt32(raw, start + 4);
             nameRef.Name = pcc.GetName(nameRef.index);
             if (nameRef.count > 0)
                 nameRef.Name += "_" + (nameRef.count - 1);
             v.NameValue = nameRef;
             v.len = 8;
             break;
         case "BoolProperty":
             if(start < raw.Length)
                 v.IntValue = raw[start];
             v.len = 1;
             break;
     }
     return v;
 }
예제 #21
0
        public static List<Property> ReadProp(PCCPackage pcc, byte[] raw, int start)
        {
            Property p;
            PropertyValue v;
            int sname;
            List<Property> result = new List<Property>();
            int pos = start;
            if(raw.Length - pos < 8)
                return result;
            int name = (int)BitConverter.ToInt64(raw, pos);
            if (!pcc.isName(name))
                return result;
            string t = pcc.Names[name];
            if (pcc.Names[name] == "None")
            {
                p = new Property();
                p.Name = name;
                p.TypeVal = Type.None;
                p.i = 0;                
                p.offsetval = pos;
                p.Size = 8;
                p.Value = new PropertyValue();
                p.raw = BitConverter.GetBytes((Int64)name);
                p.offend = pos + 8;
                result.Add(p);
                return result;
            }
            int type = (int)BitConverter.ToInt64(raw, pos + 8);            
            int size = BitConverter.ToInt32(raw, pos + 16);
            int idx = BitConverter.ToInt32(raw, pos + 20);
            if (!pcc.isName(type) || size < 0 || size >= raw.Length)
                return result;
            string tp = pcc.Names[type];
            switch (tp)
            {

                case "DelegateProperty":
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.DelegateProperty;
                    p.i = 0;
                    p.offsetval = pos + 24;
                    v = new PropertyValue();
                    v.IntValue = BitConverter.ToInt32(raw, pos + 28);
                    v.len = size;
                    v.Array = new List<PropertyValue>();
                    pos += 24;
                    for (int i = 0; i < size; i++)
                    {
                        PropertyValue v2 = new PropertyValue();
                        if(pos < raw.Length)
                            v2.IntValue = raw[pos];
                        v.Array.Add(v2);
                        pos ++;
                    }
                    p.Value = v;
                    break;
                case "ArrayProperty":
                    int count = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.ArrayProperty;
                    p.i = 0;
                    p.offsetval = pos + 24;
                    v = new PropertyValue();
                    v.IntValue = type;
                    v.len = size - 4;
                    count = v.len;//TODO can be other objects too
                    v.Array = new List<PropertyValue>();
                    pos += 28;
                    for (int i = 0; i < count; i++)
                    {
                        PropertyValue v2 = new PropertyValue();
                        if(pos < raw.Length)
                            v2.IntValue = raw[pos];
                        v.Array.Add(v2);
                        pos ++;
                    }
                    p.Value = v;
                    break;
                case "StrProperty":
                    count = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.StrProperty;
                    p.i = 0;
                    p.offsetval = pos + 24;
                    count *= -1;
                    v = new PropertyValue();
                    v.IntValue = type;
                    v.len = count;
                    pos += 28;
                    string s = "";
                    for (int i = 0; i < count; i++)
                    {
                        s += (char)raw[pos];
                        pos += 2;
                    }
                    v.StringValue = s;
                    p.Value = v;
                    break;
                case "StructProperty":
                    sname = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.StructProperty;
                    p.i = 0;
                    p.offsetval = pos + 24;
                    v = new PropertyValue();
                    v.IntValue = sname;
                    v.len = size;
                    v.Array = new List<PropertyValue>();
                    pos += 32;
                    for (int i = 0; i < size; i++)
                    {
                        PropertyValue v2 = new PropertyValue();
                        if (pos < raw.Length)
                            v2.IntValue = raw[pos];
                        v.Array.Add(v2);
                        pos++;
                    }
                    p.Value = v;
                    break;
                case "ByteProperty":
                    sname = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.ByteProperty;
                    p.i = 0;
                    p.offsetval = pos + 32;
                    v = new PropertyValue();
                    v.StringValue = pcc.GetName(sname);
                    v.len = size;
                    pos += 32;
                    if (size == 8)
                    {
                        v.IntValue = BitConverter.ToInt32(raw, pos);
                    }
                    else
                    {
                        v.IntValue = raw[pos];
                    }
                    pos += size;
                    p.Value = v;
                    break;
                default:
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = getType(pcc,type);
                    p.i = 0;
                    p.offsetval = pos + 24;
                    p.Value = ReadValue(pcc, raw, pos + 24, type);
                    pos += p.Value.len + 24;
                    break;
            }
            p.Size = size;
            p.raw = new byte[pos - start];
            p.offend = pos;
            if(pos < raw.Length)
                for (int i = 0; i < pos - start; i++) 
                    p.raw[i] = raw[start + i];
            result.Add(p);            
            if(pos!=start) result.AddRange(ReadProp(pcc, raw, pos));
            return result;
        }
예제 #22
0
 public void RefreshImportView()
 {
     listBox5.Items.Clear();
     listBox6.Items.Clear();
     toolStripComboBox2.Items.Clear();
     toolStripComboBox2.Items.Add("Add Import");
     toolStripComboBox2.Items.Add("Write Import over ...");
     toolStripComboBox2.SelectedIndex = 0;
     if (importpcc != null && importpcc.Source != null)
         importpcc.Source.Close();
     if (importpcc != null)
         importpcc = null;
 }
예제 #23
0
 public void LoadDLCFile(string path, int index)
 {
     pcc = new PCCPackage(new DLCPackage(path), index); 
 }
예제 #24
0
        //for debugging purposes. not exposed to user
        private void InterpTrackScan_Click(object sender, EventArgs e)
        {
            KFreonLib.Debugging.DebugOutput.StartDebugger("Main ME3Explorer Form");
            string basepath = KFreonLib.MEDirectories.ME3Directory.cookedPath;
            string[] files = Directory.GetFiles(basepath, "*.pcc");
            List<string> conds = new List<string>();
            List<string> conds1 = new List<string>();

            //string property = Microsoft.VisualBasic.Interaction.InputBox("Please enter property name", "ME3 Explorer");
            string name;
            for (int f = 0; f < files.Length; f++)
            {
                string file = files[f];
                //KFreonLib.Debugging.DebugOutput.PrintLn((f + 1) + " / " + files.Length + " : " + file + " :", true);
                PCCPackage p = new PCCPackage(file, true, false, true);
                for (int i = 0; i < p.Exports.Count; i++)
                {
                    if (p.GetObjectClass(i).StartsWith("InterpTrackVisibility")) //GetObject(p.Exports[i].idxLink).StartsWith("InterpGroup"))
                    {
                        BitConverter.IsLittleEndian = true;
                        List<ME3LibWV.PropertyReader.Property> props = ME3LibWV.PropertyReader.getPropList(p, p.Exports[i].Data);
                        foreach (ME3LibWV.PropertyReader.Property prop in props)
                        {
                            //KFreonLib.Debugging.DebugOutput.PrintLn(p.GetName(prop.Name));
                            if (p.GetName(prop.Name) == "VisibilityTrack")
                            {
                                int pos = 28;
                                int count = BitConverter.ToInt32(prop.raw, 24);
                                for (int j = 0; j < count; j++)
                                {
                                    List<ME3LibWV.PropertyReader.Property> p2 = ME3LibWV.PropertyReader.ReadProp(p, prop.raw, pos);
                                    for (int k = 0; k < p2.Count; k++)
                                    {
                                        name = p.GetName(p2[k].Name);
                                        if (name == "Action")
                                        {
                                            if (!conds.Contains(p.GetName(BitConverter.ToInt32(p2[k].raw, 32))))
                                            {
                                                conds.Add(p.GetName(BitConverter.ToInt32(p2[k].raw, 32)));
                                                KFreonLib.Debugging.DebugOutput.PrintLn("Action " + p.GetName(BitConverter.ToInt32(p2[k].raw, 24)) + ", " + p.GetName(BitConverter.ToInt32(p2[k].raw, 32)) + "               at: #" + i + " " + p.GetObjectPath(i + 1) + p.GetObjectClass(i + 1) + "        in: " + file.Substring(file.LastIndexOf(@"\") + 1), false);
                                            }
                                        }
                                        else if (name == "ActiveCondition")
                                        {
                                            if (!conds1.Contains(p.GetName(BitConverter.ToInt32(p2[k].raw, 32))))
                                            {
                                                conds1.Add(p.GetName(BitConverter.ToInt32(p2[k].raw, 32)));
                                                KFreonLib.Debugging.DebugOutput.PrintLn("ActiveCondition " + p.GetName(BitConverter.ToInt32(p2[k].raw, 24)) + ", " + p.GetName(BitConverter.ToInt32(p2[k].raw, 32)) + "               at: #" + i + " " + p.GetObjectPath(i + 1) + p.GetObjectClass(i + 1) + "        in: " + file.Substring(file.LastIndexOf(@"\") + 1), false);
                                            }
                                        }
                                        pos += p2[k].raw.Length;
                                    }
                                }
                            }
                            //if (p.GetName(prop.Name) == property)
                            //{
                            //    if(!conds.Contains(p.GetName(BitConverter.ToInt32(prop.raw, 32))))
                            //    {
                            //        conds.Add(p.GetName(BitConverter.ToInt32(prop.raw, 32)));
                            //        KFreonLib.Debugging.DebugOutput.PrintLn(p.GetName(BitConverter.ToInt32(prop.raw, 24)) + ", " + p.GetName(BitConverter.ToInt32(prop.raw, 32)) + "               at: #" + i + " " + p.GetObjectPath(i + 1) + p.GetObjectClass(i + 1) + "        in: " + file.Substring(file.LastIndexOf(@"\") + 1), false);
                            //    }
                            //}
                        }
                        //KFreonLib.Debugging.DebugOutput.PrintLn(i + " : " + p.GetObjectClass(i + 1) + "               at: " + p.GetObjectPath(i + 1) + "        in: " + file.Substring(file.LastIndexOf(@"\") + 1), false);
                    }
                }
                Application.DoEvents();
            }
            KFreonLib.Debugging.DebugOutput.PrintLn();
            KFreonLib.Debugging.DebugOutput.PrintLn("*****************");
            KFreonLib.Debugging.DebugOutput.PrintLn("Done");
        }
예제 #25
0
 private void generateFromBasefolderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string basepath = KFreonLib.MEDirectories.ME3Directory.cookedPath;
     if (String.IsNullOrEmpty(basepath))
     {
         MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3");
         return;
     }
     KFreonLib.Debugging.DebugOutput.StartDebugger("Main ME3Explorer Form");
     string[] files = Directory.GetFiles(basepath, "*.pcc");
     OverView = new List<OverViewStruct>();
     for (int f = 0; f < files.Length; f++)
     {
         string file = files[f];
         KFreonLib.Debugging.DebugOutput.PrintLn((f + 1) + " / " + files.Length + " : " + file + " :", true);
         PCCPackage p = new PCCPackage(file, false, false, true);
         OverViewStruct o = new OverViewStruct();
         o.filepath = file;
         o.Indexes = new List<int>();
         int count = 0;
         for (int i = 0; i < p.Exports.Count; i++)
         {
             if (p.GetObject(p.Exports[i].idxClass) == "InterpData")
             {
                 o.Indexes.Add(i);
                 string s = "";
                 if (count++ == 0)
                     s = "\n";
                 KFreonLib.Debugging.DebugOutput.PrintLn(s + "found " + i + " : " + p.GetObjectPath(i + 1) + p.GetObject(i + 1), false);
             }
         }
         if (o.Indexes.Count != 0)
             OverView.Add(o);
         Application.DoEvents();
     }
     FreshOverView();
 }
예제 #26
0
 public static int detectStart(PCCPackage pcc, byte[] raw, uint flags)
 {
     //has stack
     if ((flags & 0x02000000) != 0)
     {
         return 30;
     }
     int result = 8;
     int test1 = BitConverter.ToInt32(raw, 4);
     int test2 = BitConverter.ToInt32(raw, 8);
     if (pcc.isName(test1) && test2 == 0)
         result = 4;
     if (pcc.isName(test1) && pcc.isName(test2) && test2 != 0)
         result = 8;    
     return result;
 }
예제 #27
0
 private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
     int n = listBox2.SelectedIndex;
     if (n == -1)
         return;
     PCCPackage p = new PCCPackage(OverView[n].filepath, false, false, true);
     listBox3.Items.Clear();
     foreach (int i in OverView[n].Indexes)
         listBox3.Items.Add(i + " : " + p.GetObjectPath(i + 1) + p.GetObject(i + 1) + "(" + p.Exports[i].Index + ")");
 }
예제 #28
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;
 }
예제 #29
0
 public static string PropertyToText(Property p,PCCPackage pcc)
 {
     string s = "";
     s = "Name: " + pcc.Names[p.Name];
     s += " Type: " + TypeToString((int)p.TypeVal);
     s += " Size: " + p.Value.len;
     switch (p.TypeVal)
     {
         case Type.StructProperty:
             s += " \"" + pcc.GetName (p.Value.IntValue) + "\" with " + p.Value.Array.Count + " bytes";
             break;
         case Type.IntProperty:                
         case Type.ObjectProperty:
         case Type.BoolProperty:
         case Type.StringRefProperty :
             s += " Value: " + p.Value.IntValue;
             break;
         case Type.FloatProperty:
             byte[] buff = BitConverter.GetBytes(p.Value.IntValue);
             float f = BitConverter.ToSingle(buff,0);
             s += " Value: " + f;
             break;
         case Type.NameProperty:
             s += " " + pcc.Names[p.Value.IntValue];
             break;
         case Type.ByteProperty:
             s += " Value: \"" + p.Value.StringValue + "\" with \"" + pcc.GetName(p.Value.IntValue) + "\"";
             break;
         case Type.ArrayProperty:
             s += " bytes"; //Value: " + p.Value.Array.Count.ToString() + " Elements";
             break;
         case Type.StrProperty:
             if (p.Value.StringValue.Length == 0)
                 break;
             s += " Value: " + p.Value.StringValue.Substring(0,p.Value.StringValue.Length - 1);
             break;
     }
     return s;
 }
예제 #30
0
 public static CustomProperty PropertyToGrid(Property p, PCCPackage pcc)
 {
     string cat = p.TypeVal.ToString();
     CustomProperty pg;
     switch(p.TypeVal)
     {
         case Type.BoolProperty :
             pg = new CustomProperty(pcc.Names[p.Name], cat, (p.Value.IntValue == 1), typeof(bool), false, true);
             break;
         case Type.FloatProperty:
             byte[] buff = BitConverter.GetBytes(p.Value.IntValue);
             float f = BitConverter.ToSingle(buff, 0);
             pg = new CustomProperty(pcc.Names[p.Name], cat, f, typeof(float), false, true);
             break;
         case Type.ByteProperty:
         case Type.NameProperty:
             NameProp pp = new NameProp();
             pp.name = pcc.GetName(p.Value.IntValue);
             pp.nameindex = p.Value.IntValue;
             pg = new CustomProperty(pcc.Names[p.Name], cat, pp, typeof(NameProp), false, true);
             break;
         case Type.ObjectProperty:
             ObjectProp ppo = new ObjectProp();
             ppo.name = pcc.GetName(p.Value.IntValue);
             ppo.nameindex = p.Value.IntValue;
             pg = new CustomProperty(pcc.Names[p.Name], cat, ppo, typeof(ObjectProp), false, true);
             break;
         case Type.StructProperty:
             StructProp ppp = new StructProp();
             ppp.name = pcc.GetName(p.Value.IntValue);
             ppp.nameindex = p.Value.IntValue;
             byte[] buf = new byte[p.Value.Array.Count()];
             for (int i = 0; i < p.Value.Array.Count(); i++)
                 buf[i] = (byte)p.Value.Array[i].IntValue;
             List<int> buf2 = new List<int>();
             for (int i = 0; i < p.Value.Array.Count() / 4; i++)
                 buf2.Add(BitConverter.ToInt32(buf ,i * 4));
             ppp.data = buf2.ToArray();
             pg = new CustomProperty(pcc.Names[p.Name], cat, ppp, typeof(StructProp), false, true);
             break;                    
         default:
             pg = new CustomProperty(pcc.Names[p.Name],cat,p.Value.IntValue,typeof(int),false,true);
             break;
     }
     return pg;
 }
예제 #31
0
        public static List <Property> ReadProp(PCCPackage pcc, byte[] raw, int start)
        {
            Property      p;
            PropertyValue v;
            int           sname;
            var           result = new List <Property>();
            var           pos    = start;

            if (raw.Length - pos < 8)
            {
                return(result);
            }
            var name = (int)BitConverter.ToInt64(raw, pos);

            if (!pcc.IsName(name))
            {
                return(result);
            }
            var t = pcc.Names[name];

            if (pcc.Names[name] == "None")
            {
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.None;
                p.i         = 0;
                p.offsetval = pos;
                p.Size      = 8;
                p.Value     = new PropertyValue();
                p.raw       = BitConverter.GetBytes((Int64)name);
                p.offend    = pos + 8;
                result.Add(p);
                return(result);
            }
            var type = (int)BitConverter.ToInt64(raw, pos + 8);
            var size = BitConverter.ToInt32(raw, pos + 16);
            var idx  = BitConverter.ToInt32(raw, pos + 20);

            if (!pcc.IsName(type) || size < 0 || size >= raw.Length)
            {
                return(result);
            }
            var tp = pcc.Names[type];

            switch (tp)
            {
            case "DelegateProperty":
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.DelegateProperty;
                p.i         = 0;
                p.offsetval = pos + 24;
                v           = new PropertyValue();
                v.IntValue  = BitConverter.ToInt32(raw, pos + 28);
                v.len       = size;
                v.Array     = new List <PropertyValue>();
                pos        += 24;
                for (var i = 0; i < size; i++)
                {
                    var v2 = new PropertyValue();
                    if (pos < raw.Length)
                    {
                        v2.IntValue = raw[pos];
                    }
                    v.Array.Add(v2);
                    pos++;
                }
                p.Value = v;
                break;

            case "ArrayProperty":
                var count = (int)BitConverter.ToInt64(raw, pos + 24);
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.ArrayProperty;
                p.i         = 0;
                p.offsetval = pos + 24;
                v           = new PropertyValue();
                v.IntValue  = type;
                v.len       = size - 4;
                count       = v.len;                   //TODO can be other objects too
                v.Array     = new List <PropertyValue>();
                pos        += 28;
                for (var i = 0; i < count; i++)
                {
                    var v2 = new PropertyValue();
                    if (pos < raw.Length)
                    {
                        v2.IntValue = raw[pos];
                    }
                    v.Array.Add(v2);
                    pos++;
                }
                p.Value = v;
                break;

            case "StrProperty":
                count       = (int)BitConverter.ToInt64(raw, pos + 24);
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.StrProperty;
                p.i         = 0;
                p.offsetval = pos + 24;
                count      *= -1;
                v           = new PropertyValue();
                v.IntValue  = type;
                v.len       = count;
                pos        += 28;
                var s = "";
                for (var i = 0; i < count; i++)
                {
                    s   += (char)raw[pos];
                    pos += 2;
                }
                v.StringValue = s;
                p.Value       = v;
                break;

            case "StructProperty":
                sname       = (int)BitConverter.ToInt64(raw, pos + 24);
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.StructProperty;
                p.i         = 0;
                p.offsetval = pos + 24;
                v           = new PropertyValue();
                v.IntValue  = sname;
                v.len       = size;
                v.Array     = new List <PropertyValue>();
                pos        += 32;
                for (var i = 0; i < size; i++)
                {
                    var v2 = new PropertyValue();
                    if (pos < raw.Length)
                    {
                        v2.IntValue = raw[pos];
                    }
                    v.Array.Add(v2);
                    pos++;
                }
                p.Value = v;
                break;

            case "ByteProperty":
                sname         = (int)BitConverter.ToInt64(raw, pos + 24);
                p             = new Property();
                p.Name        = name;
                p.TypeVal     = Type.ByteProperty;
                p.i           = 0;
                p.offsetval   = pos + 32;
                v             = new PropertyValue();
                v.StringValue = pcc.GetName(sname);
                v.len         = size;
                pos          += 32;
                v.IntValue    = (int)BitConverter.ToInt64(raw, pos);
                pos          += size;
                p.Value       = v;
                break;

            default:
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = getType(pcc, type);
                p.i         = 0;
                p.offsetval = pos + 24;
                p.Value     = ReadValue(pcc, raw, pos + 24, type);
                pos        += p.Value.len + 24;
                break;
            }
            p.raw    = new byte[pos - start];
            p.offend = pos;
            if (pos < raw.Length)
            {
                for (var i = 0; i < pos - start; i++)
                {
                    p.raw[i] = raw[start + i];
                }
            }
            result.Add(p);
            if (pos != start)
            {
                result.AddRange(ReadProp(pcc, raw, pos));
            }
            return(result);
        }
예제 #32
0
 private static Type getType(PCCPackage pcc, int type)
 {
     switch (pcc.GetName(type))
     {
         case "None": return Type.None;
         case "StructProperty": return Type.StructProperty;
         case "IntProperty": return Type.IntProperty;
         case "FloatProperty": return Type.FloatProperty;
         case "ObjectProperty": return Type.ObjectProperty;
         case "NameProperty": return Type.NameProperty;
         case "BoolProperty": return Type.BoolProperty;
         case "ByteProperty": return Type.ByteProperty;
         case "ArrayProperty": return Type.ArrayProperty;
         case "DelegateProperty": return Type.DelegateProperty;
         case "StrProperty": return Type.StrProperty;
         case "StringRefProperty": return Type.StringRefProperty;                    
         default:
             return Type.Unknown;
     }
 }
예제 #33
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);
     }
 }
예제 #34
0
 public static int detectStart(PCCPackage pcc, byte[] raw)
 {
     int result = 8;
     int test1 = BitConverter.ToInt32(raw, 4);
     if (test1 < 0)
         result = 30;
     else
     {
         int test2 = BitConverter.ToInt32(raw, 8);
         if (pcc.isName(test1) && test2 == 0)
             result = 4;
         if (pcc.isName(test1) && pcc.isName(test2) && test2 != 0)
             result = 8;
     }
     return result;
 }
예제 #35
0
        public static void ImportImmutableProperty(PCCPackage pcc, PCCPackage importpcc, Property p, string className, System.IO.MemoryStream m, bool inStruct = false)
        {
            string name    = importpcc.GetName(p.Name);
            int    idxname = pcc.FindNameOrAdd(name);

            if (name == "None")
            {
                return;
            }
            string          type    = importpcc.GetName(BitConverter.ToInt32(p.raw, 8));
            int             idxtype = pcc.FindNameOrAdd(type);
            string          name2;
            int             idxname2;
            int             size, count, pos;
            List <Property> Props;

            switch (type)
            {
            case "IntProperty":
            case "FloatProperty":
            case "ObjectProperty":
            case "StringRefProperty":
                m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
                break;

            case "NameProperty":
                m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                //preserve index or whatever the second part of a namereference is
                m.Write(p.raw, 28, 4);
                break;

            case "BoolProperty":
                m.WriteByte((byte)p.Value.IntValue);
                break;

            case "BioMask4Property":
                m.WriteByte((byte)p.Value.IntValue);
                break;

            case "ByteProperty":
                name2    = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
                idxname2 = pcc.FindNameOrAdd(name2);
                if (p.Size == 8)
                {
                    m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                    m.Write(new byte[4], 0, 4);
                }
                else
                {
                    m.WriteByte(p.raw[32]);
                }
                break;

            case "StrProperty":
                name2 = p.Value.StringValue;
                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 <Property>();
                try
                {
                    Props = ReadProp(importpcc, p.raw, pos);
                }
                catch (Exception)
                {
                }
                if (Props.Count == 0 || Props[0].TypeVal == Type.Unknown)
                {
                    for (int i = 0; i < size; i++)
                    {
                        m.WriteByte(p.raw[32 + i]);
                    }
                }
                else
                {
                    foreach (Property pp in Props)
                    {
                        ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                }
                break;

            case "ArrayProperty":
                size  = BitConverter.ToInt32(p.raw, 16);
                count = BitConverter.ToInt32(p.raw, 24);
                UnrealObjectInfo.ArrayType arrayType = UnrealObjectInfo.getArrayType(className, importpcc.GetName(p.Name), inStruct);
                pos = 28;
                List <Property> AllProps = new List <Property>();

                if (arrayType == UnrealObjectInfo.ArrayType.Struct)
                {
                    for (int i = 0; i < count; i++)
                    {
                        Props = new List <Property>();
                        try
                        {
                            Props = ReadProp(importpcc, p.raw, pos);
                        }
                        catch (Exception)
                        {
                        }
                        AllProps.AddRange(Props);
                        if (Props.Count != 0)
                        {
                            pos = Props[Props.Count - 1].offend;
                        }
                    }
                }
                m.Write(BitConverter.GetBytes(count), 0, 4);
                if (AllProps.Count != 0)
                {
                    foreach (Property pp in AllProps)
                    {
                        ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                }
                else if (arrayType == UnrealObjectInfo.ArrayType.Name)
                {
                    for (int i = 0; i < count; i++)
                    {
                        string s = importpcc.GetName(BitConverter.ToInt32(p.raw, 28 + i * 8));
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4);
                        //preserve index or whatever the second part of a namereference is
                        m.Write(p.raw, 32 + i * 8, 4);
                    }
                }
                else
                {
                    m.Write(p.raw, 28, size - 4);
                }
                break;

            default:
            case "DelegateProperty":
                throw new NotImplementedException(type);
            }
        }
예제 #36
0
        public static void ImportImmutableProperty(PCCPackage pcc, PCCPackage importpcc, Property p, string className, System.IO.MemoryStream m, bool inStruct = false)
        {
            string name = importpcc.GetName(p.Name);
            int idxname = pcc.FindNameOrAdd(name);
            if (name == "None")
                return;
            string type = importpcc.GetName(BitConverter.ToInt32(p.raw, 8));
            int idxtype = pcc.FindNameOrAdd(type);
            string name2;
            int idxname2;
            int size, count, pos;
            List<Property> Props;
            switch (type)
            {
                case "IntProperty":
                case "FloatProperty":
                case "ObjectProperty":
                case "StringRefProperty":
                    m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
                    break;
                case "NameProperty":
                    m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                    //preserve index or whatever the second part of a namereference is
                    m.Write(p.raw, 28, 4);
                    break;
                case "BoolProperty":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "BioMask4Property":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "ByteProperty":
                    name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
                    idxname2 = pcc.FindNameOrAdd(name2);
                    if (p.Size == 8)
                    {
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                        m.Write(new byte[4], 0, 4);
                    }
                    else
                    {
                        m.WriteByte(p.raw[32]);
                    }
                    break;
                case "StrProperty":
                    name2 = p.Value.StringValue;
                    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<Property>();
                    try
                    {
                        Props = ReadProp(importpcc, p.raw, pos);
                    }
                    catch (Exception)
                    {
                    }
                    if (Props.Count == 0 || Props[0].TypeVal == Type.Unknown)
                    {
                        for (int i = 0; i < size; i++)
                            m.WriteByte(p.raw[32 + i]);
                    }
                    else
                    {
                        foreach (Property pp in Props)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    break;
                case "ArrayProperty":
                    size = BitConverter.ToInt32(p.raw, 16);
                    count = BitConverter.ToInt32(p.raw, 24);
                    UnrealObjectInfo.ArrayType arrayType = UnrealObjectInfo.getArrayType(className, importpcc.GetName(p.Name), inStruct);
                    pos = 28;
                    List<Property> AllProps = new List<Property>();

                    if (arrayType == UnrealObjectInfo.ArrayType.Struct)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            Props = new List<Property>();
                            try
                            {
                                Props = ReadProp(importpcc, p.raw, pos);
                            }
                            catch (Exception)
                            {
                            }
                            AllProps.AddRange(Props);
                            if (Props.Count != 0)
                            {
                                pos = Props[Props.Count - 1].offend;
                            }
                        }
                    }
                    m.Write(BitConverter.GetBytes(count), 0, 4);
                    if (AllProps.Count != 0)
                    {
                        foreach (Property pp in AllProps)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    else if (arrayType == UnrealObjectInfo.ArrayType.Name)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            string s = importpcc.GetName(BitConverter.ToInt32(p.raw, 28 + i * 8));
                            m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4);
                            //preserve index or whatever the second part of a namereference is
                            m.Write(p.raw, 32 + i * 8, 4);
                        }
                    }
                    else
                    {
                        m.Write(p.raw, 28, size - 4);
                    }
                    break;
                default:
                case "DelegateProperty":
                    throw new NotImplementedException(type);
            }
        }
예제 #37
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);
 }