Exemple #1
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);
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
        }
        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);
        }