Пример #1
0
        internal void CheckNamePresence(GpkPackage package)
        {
            package.GetStringIndex(ObjectName);

            foreach (IProperty iProp in Properties)
            {
                GpkBaseProperty baseProperty = (GpkBaseProperty)iProp;
                package.GetStringIndex(baseProperty.name);
                package.GetStringIndex(baseProperty.type);

                iProp.CheckAndAddNames(package);
            }
        }
Пример #2
0
        private void WriteExportsData(BinaryWriter writer, GpkPackage package)
        {
            //puffer, seems random in many files, we use 10 empty bytes
            writer.Write(new byte[package.datapuffer]);

            foreach (GpkExport export in package.ExportList.Values)
            {
                if (export.SerialSize == 0)
                {
                    logger.Trace("skipping export data for " + export.ObjectName);
                }
                else
                {
                    logger.Trace("export data for " + export.ObjectName);
                }

                long data_start = writer.BaseStream.Position;

                if (export.SerialOffset != data_start)
                {
                    //if we have diffrent layout of the data then teh orginal file we need to fix the data pointers
                    logger.Trace(string.Format("fixing export {0} offset old:{1} new:{2}", export.ObjectName, export.SerialOffset, data_start));


                    export.SerialOffset = (int)data_start;
                    writer.BaseStream.Seek(export.SerialOffsetPosition, SeekOrigin.Begin);
                    writer.Write(export.SerialOffset);
                    writer.BaseStream.Seek(data_start, SeekOrigin.Begin);
                }

                if (export.NetIndexName != null)
                {
                    writer.Write((int)package.GetObjectIndex(export.NetIndexName));
                }
                else
                {
                    writer.Write(export.NetIndex);
                }

                if (export.PropertyPadding != null)
                {
                    writer.Write(export.PropertyPadding);
                }

                foreach (IProperty iProp in export.Properties)
                {
                    GpkBaseProperty baseProperty = (GpkBaseProperty)iProp;
                    writer.Write(package.GetStringIndex(baseProperty.name));
                    writer.Write(package.GetStringIndex(baseProperty.type));
                    writer.Write(baseProperty.size);
                    writer.Write(baseProperty.arrayIndex);

                    iProp.WriteData(writer, package);
                }

                //end with a none nameindex
                writer.Write(package.GetStringIndex("None"));


                //check
                long propRealSize = (writer.BaseStream.Position - data_start);
                if (Settings.Default.Debug && propRealSize != export.PropertySize)
                {
                    logger.Trace("Compu Prop Size: {0}, Diff {1} -", export.PropertySize, propRealSize - export.PropertySize);
                }


                if (export.DataPadding != null)
                {
                    writer.Write((export.DataPadding));
                }

                //finally our data
                if (export.Payload != null)
                {
                    //pos is important. we cant be sure that the data is acurate.
                    export.Payload.WriteData(writer, package, export);
                }
                else if (export.Data != null)
                {
                    writer.Write(export.Data);
                }

                long data_end  = writer.BaseStream.Position;
                int  data_size = (int)(data_end - data_start);
                if (data_size != export.SerialSize)
                {
                    //maybe replaced data OR some property errors. write new data size.

                    logger.Trace(string.Format("fixing export {0} size old:{1} new:{2}", export.ObjectName, export.SerialSize, data_size));
                    export.SerialSize = data_size;
                    writer.BaseStream.Seek(export.SerialOffsetPosition - 4, SeekOrigin.Begin);
                    writer.Write(export.SerialSize);
                    writer.BaseStream.Seek(data_end, SeekOrigin.Begin);
                }

                logger.Trace("wrote export data for " + export.ObjectName + " end pos " + writer.BaseStream.Position);
                stat.progress++;
            }

            logger.Debug("Wrote export data pos " + writer.BaseStream.Position);
        }
Пример #3
0
        private Boolean ReadPropertyDetails(BinaryReader reader, GpkPackage package, GpkExport export)
        {
            GpkBaseProperty baseProp = new GpkBaseProperty();

            long nameindex = reader.ReadInt64();


            if (!package.NameList.ContainsKey(nameindex))
            {
                logger.Fatal("name not found " + nameindex);
                if (export.Properties.Count > 0)
                {
                    logger.Fatal("prev " + export.Properties[export.Properties.Count - 1]);
                }
            }

            baseProp.name = package.GetString(nameindex);
            if (baseProp.name.ToLower() == "none")
            {
                return(false);
            }

            long typeindex = reader.ReadInt64();

            if (!package.NameList.ContainsKey(typeindex))
            {
                logger.Fatal("type not found " + typeindex);
            }
            baseProp.type = package.GetString(typeindex);

            baseProp.size       = reader.ReadInt32();
            baseProp.arrayIndex = reader.ReadInt32();

            IProperty iProp;

            switch (baseProp.type)
            {
            case "StructProperty":
                iProp = new GpkStructProperty(baseProp);
                break;

            case "ArrayProperty":
                iProp = new GpkArrayProperty(baseProp);
                break;

            case "BoolProperty":
                iProp = new GpkBoolProperty(baseProp);
                break;

            case "ByteProperty":
                iProp = new GpkByteProperty(baseProp);
                break;

            case "NameProperty":
                iProp = new GpkNameProperty(baseProp);
                break;

            case "IntProperty":
                iProp = new GpkIntProperty(baseProp);
                break;

            case "FloatProperty":
                iProp = new GpkFloatProperty(baseProp);
                break;

            case "StrProperty":
                iProp = new GpkStringProperty(baseProp);
                break;

            case "ObjectProperty":
                iProp = new GpkObjectProperty(baseProp);
                break;

            default:
                throw new Exception(
                          string.Format(
                              "Unknown Property Type {0}, Position {1}, Prop_Name {2}, Export_Name {3}",
                              baseProp.type, reader.BaseStream.Position, baseProp.name, export.ObjectName));
            }

            iProp.ReadData(reader, package);
            iProp.RecalculateSize();
            export.Properties.Add(iProp);

            //logger.Trace(String.Format("Property Type {0}, Position after {1}, Prop_Name {2}, Export_Name {3}", baseProp.type, reader.BaseStream.Position, baseProp.ObjectName, export.ObjectName));

            return(true);
        }
Пример #4
0
        private IProperty readProperty(DataGridViewRow row)
        {
            GpkBaseProperty baseProp = new GpkBaseProperty(row.Cells["name"].Value.ToString(), row.Cells["type"].Value.ToString(), 0, Convert.ToInt32(row.Cells["aIndex"].Value.ToString()));
            IProperty       iProp;

            //Check & Add name to our namelist
            selectedPackage.AddString(baseProp.name);

            string cellValue = row.Cells["value"].Value.ToString();


            switch (baseProp.type)
            {
            case "StructProperty":
                GpkStructProperty tmpStruct = new GpkStructProperty(baseProp);
                tmpStruct.innerType = row.Cells["iType"].Value.ToString();
                tmpStruct.value     = (cellValue).ToBytes();
                iProp = tmpStruct;
                break;

            case "ArrayProperty":
                GpkArrayProperty tmpArray = new GpkArrayProperty(baseProp);
                if (cellValue == "[##TOO_LONG##]")
                {
                    //use row embeeded property instead
                    tmpArray.value = ((GpkArrayProperty)row.Tag).value;
                }
                else
                {
                    tmpArray.value = (cellValue).ToBytes();
                }

                iProp = tmpArray;
                break;

            case "ByteProperty":
                GpkByteProperty tmpByte = new GpkByteProperty(baseProp);

                if (cellValue.Length > 2)
                {
                    selectedPackage.AddString(cellValue);     //just in case

                    tmpByte.nameValue = cellValue;
                }
                else
                {
                    tmpByte.byteValue = Convert.ToByte(cellValue);
                }
                iProp = tmpByte;
                break;

            case "NameProperty":
                GpkNameProperty tmpName = new GpkNameProperty(baseProp);
                selectedPackage.AddString(cellValue);     //just in case
                tmpName.value = cellValue;
                iProp         = tmpName;
                break;

            case "ObjectProperty":
                GpkObjectProperty tmpObj = new GpkObjectProperty(baseProp);
                selectedPackage.GetObjectByUID(cellValue);     //throws ex if uid is not present
                tmpObj.objectName = cellValue;
                iProp             = tmpObj;
                break;

            case "BoolProperty":
                GpkBoolProperty tmpBool = new GpkBoolProperty(baseProp);
                tmpBool.value = Convert.ToBoolean(row.Cells[5].Value);
                iProp         = tmpBool;
                break;

            case "IntProperty":
                GpkIntProperty tmpInt = new GpkIntProperty(baseProp);
                tmpInt.value = Convert.ToInt32(row.Cells[5].Value);
                iProp        = tmpInt;
                break;

            case "FloatProperty":
                GpkFloatProperty tmpFloat = new GpkFloatProperty(baseProp);
                tmpFloat.value = Convert.ToSingle(row.Cells[5].Value);
                iProp          = tmpFloat;
                break;

            case "StrProperty":
                GpkStringProperty tmpStr = new GpkStringProperty(baseProp);
                tmpStr.value = (row.Cells[5].Value.ToString());
                iProp        = tmpStr;
                break;

            case "":
                //new line, nothing selected
                throw new Exception(
                          string.Format("You need to select a Property Type for {0}!", baseProp.name));

            default:
                throw new Exception(
                          string.Format("Unknown Property Type {0}, Prop_Name {1}", baseProp.type, baseProp.name));
            }

            iProp.RecalculateSize();
            return(iProp);
        }
Пример #5
0
        private void DrawGrid(GpkPackage package, GpkExport export)
        {
            gridProps.Enabled = true;
            gridProps.Rows.Clear();

            IEnumerable <String> nameQuery = from pair in package.NameList.Values.ToList() select pair.name;

            //IEnumerable<String> uidQuery = from pair in package.UidList.Values.ToList() select pair.name;

            foreach (IProperty iProp in export.Properties)
            {
                GpkBaseProperty prop = (GpkBaseProperty)iProp;
                DataGridViewRow row  = new DataGridViewRow();
                row.Tag = iProp;
                row.DefaultCellStyle = gridProps.DefaultCellStyle;

                DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell();
                nameCell.Value = prop.name;
                row.Cells.Add(nameCell);

                DataGridViewComboBoxCell typeCell = new DataGridViewComboBoxCell();
                typeCell.Items.AddRange(((DataGridViewComboBoxColumn)gridProps.Columns["type"]).Items);
                typeCell.ValueType = typeof(string);
                typeCell.Value     = prop.type;
                row.Cells.Add(typeCell);

                DataGridViewTextBoxCell sizeCell = new DataGridViewTextBoxCell();
                sizeCell.Value = iProp.RecalculateSize();
                row.Cells.Add(sizeCell);

                DataGridViewTextBoxCell arrayCell = new DataGridViewTextBoxCell();
                arrayCell.Value = prop.arrayIndex;
                row.Cells.Add(arrayCell);

                DataGridViewComboBoxCell innerCell = new DataGridViewComboBoxCell();
                innerCell.Items.AddRange(nameQuery.ToArray());

                if (prop is GpkStructProperty)
                {
                    GpkStructProperty struc = (GpkStructProperty)prop;
                    innerCell.Value = struc.innerType;
                }
                else
                {
                    innerCell.Value = "None";
                }
                row.Cells.Add(innerCell);

                DataGridViewTextBoxCell  valueCell = new DataGridViewTextBoxCell();
                DataGridViewComboBoxCell comboCell = null;
                if (prop is GpkArrayProperty)
                {
                    GpkArrayProperty tmpArray = (GpkArrayProperty)prop;
                    valueCell.Value = tmpArray.GetValueHex();
                }
                else if (prop is GpkStructProperty)
                {
                    GpkStructProperty tmpStruct = (GpkStructProperty)prop;
                    valueCell.Value = tmpStruct.GetValueHex();
                }
                else if (prop is GpkNameProperty)
                {
                    GpkNameProperty tmpName = (GpkNameProperty)prop;
                    comboCell = new DataGridViewComboBoxCell();
                    comboCell.Items.AddRange(nameQuery.ToArray());
                    comboCell.Value = tmpName.name;
                }
                else if (prop is GpkObjectProperty)
                {
                    GpkObjectProperty tmpObj = (GpkObjectProperty)prop;
                    comboCell = new DataGridViewComboBoxCell();
                    comboCell.Items.AddRange(package.UidList.Keys.ToArray());
                    comboCell.Value = tmpObj.objectName;
                }
                else if (prop is GpkByteProperty)
                {
                    GpkByteProperty tmpByte = (GpkByteProperty)prop;
                    comboCell = new DataGridViewComboBoxCell();
                    if (tmpByte.size == 8)
                    {
                        comboCell.Items.AddRange(nameQuery.ToArray());
                        comboCell.Value = tmpByte.nameValue;
                    }
                    else
                    {
                        comboCell.Value = tmpByte.byteValue;
                    }
                }
                else if (prop is GpkFloatProperty)
                {
                    GpkFloatProperty tmpFloat = (GpkFloatProperty)prop;
                    valueCell.Value = tmpFloat.value;
                }
                else if (prop is GpkIntProperty)
                {
                    GpkIntProperty tmpInt = (GpkIntProperty)prop;
                    valueCell.Value = tmpInt.value;
                }
                else if (prop is GpkStringProperty)
                {
                    GpkStringProperty tmpString = (GpkStringProperty)prop;
                    valueCell.Value = tmpString.value;
                }
                else if (prop is GpkBoolProperty)
                {
                    GpkBoolProperty tmpBool = (GpkBoolProperty)prop;
                    valueCell.Value = tmpBool.value;
                }
                else
                {
                    logger.Info("Unk Prop?!?");
                }

                if (valueCell.Value != null && valueCell.Value.ToString().Length > valueCell.MaxInputLength)
                {
                    valueCell.Value = "[##TOO_LONG##]";
                }
                if (comboCell == null)
                {
                    row.Cells.Add(valueCell);
                }
                else
                {
                    row.Cells.Add(comboCell);
                }


                gridProps.Rows.Add(row);
            }
        }
Пример #6
0
        public IProperty GetIProperty(GpkPackage selectedPackage)
        {
            var       baseProp = new GpkBaseProperty(Name, PropertyType, 0, ArrayIndex);
            IProperty iProp;

            //Check & Add name to our namelist
            selectedPackage.AddString(baseProp.name);

            var cellValue = Value.ToString();//.Cells["value"].Value.ToString();


            switch (baseProp.type)
            {
            case "StructProperty":
                iProp = new GpkStructProperty(baseProp)
                {
                    innerType = InnerType,     //.Cells["iType"].Value.ToString();
                    value     = (cellValue).ToBytes()
                };
                break;

            case "ArrayProperty":
                //if (cellValue == "[##TOO_LONG##]")
                //{
                //    //use row embeeded property instead
                //    tmpArray.value = ((GpkArrayProperty)row.Tag).value;
                //}
                //else
                var tmpArray = new GpkArrayProperty(baseProp)
                {
                    value = (cellValue).ToBytes()
                };
                tmpArray.size = tmpArray.value.Length;
                tmpArray.RecalculateSize();
                iProp = tmpArray;
                break;

            case "ByteProperty":
                var tmpByte = new GpkByteProperty(baseProp);

                if (cellValue.Length > 2)
                {
                    if (selectedPackage.x64)
                    {
                        tmpByte.enumType = InnerType;                //.Cells["iType"].Value.ToString();
                        selectedPackage.AddString(tmpByte.enumType); //just in case
                    }
                    selectedPackage.AddString(cellValue);            //just in case

                    tmpByte.nameValue = cellValue;
                }
                else
                {
                    tmpByte.byteValue = Convert.ToByte(cellValue);
                }
                iProp = tmpByte;
                break;

            case "NameProperty":
                var tmpName = new GpkNameProperty(baseProp);
                selectedPackage.AddString(cellValue);     //just in case
                tmpName.value = cellValue;
                iProp         = tmpName;
                break;

            case "ObjectProperty":
                var tmpObj = new GpkObjectProperty(baseProp);
                selectedPackage.GetObjectByUID(cellValue);     //throws ex if uid is not present
                tmpObj.objectName = cellValue;
                iProp             = tmpObj;
                break;

            case "BoolProperty":
                var tmpBool = new GpkBoolProperty(baseProp)
                {
                    value = Convert.ToBoolean(Value)
                };
                iProp = tmpBool;
                break;

            case "IntProperty":
                var tmpInt = new GpkIntProperty(baseProp)
                {
                    value = Convert.ToInt32(Value)
                };
                iProp = tmpInt;
                break;

            case "FloatProperty":
                var tmpFloat = new GpkFloatProperty(baseProp)
                {
                    value = Convert.ToSingle(Value)
                };
                iProp = tmpFloat;
                break;

            case "StrProperty":
                var tmpStr = new GpkStringProperty(baseProp)
                {
                    value = (Value.ToString())
                };
                iProp = tmpStr;
                break;

            case "":
                //new line, nothing selected
                throw new Exception($"You need to select a Property Type for {baseProp.name}!");

            default:
                throw new Exception($"Unknown Property Type {baseProp.type}, Prop_Name {baseProp.name}");
            }

            iProp.RecalculateSize();
            return(iProp);
        }