Example #1
0
        public override void buildNdf(NdfBinary data, ref int i)
        {
            //return;

            string name    = "";
            string ranking = "";

            switch (type)
            {
            case IconType.CV:
                name    = "TGameDesignAddOn_StartingCommandUnit";
                ranking = "StartingCommandUnits";

                break;

            case IconType.FOB:
                name    = "TGameDesignAddOn_StartingFOB";
                ranking = "StartingFOB";
                break;
            }
            var spawnPoint = createNdfObject(data, name);

            /*var nameProperty = getProperty(spawnPoint, "Name");
             * nameProperty.Value = getAutoName(data, i++);
             * var rankingProperty = getProperty(spawnPoint, "Ranking");
             * rankingProperty.Value = getString(data, ranking);
             * var guidProperty = getProperty(spawnPoint, "GUID");
             * rankingProperty.Value = new NdfGuid(Guid.NewGuid());*/
            var allocationProperty = getProperty(spawnPoint, "AllocationPriority");

            //NOT RIGHT
            allocationProperty.Value = new NdfInt32(priority);

            var designItem = createNdfObject(data, "TGameDesignItem");
            var list       = data.Classes.First().Instances.First().PropertyValues.First().Value as NdfCollection;
            var ci         = new CollectionItemValueHolder(new NdfObjectReference(designItem.Class, designItem.Id), data);

            list.Add(ci);

            var positionProperty = getProperty(designItem, "Position");
            var hp = position.getPosition();
            var p  = Geometry.Geometry.convertPoint(hp);

            positionProperty.Value = new NdfVector(p);

            var rotationProperty = getProperty(designItem, "Rotation");

            rotationProperty.Value = new NdfSingle(0f);

            var addOnProperty = getProperty(designItem, "AddOn");

            addOnProperty.Value = new NdfObjectReference(spawnPoint.Class, spawnPoint.Id);
        }
Example #2
0
        private void AddRowOfCommonTypeExecute(object obj)
        {
            var cv = CollectionViewSource.GetDefaultView(Value);

            if (cv == null)
            {
                return;
            }

            NdfType type =
                Value.GroupBy(x => x.Value.Type).OrderByDescending(gp => gp.Count()).Select(x => x.First().Value.Type).
                Single();

            var wrapper =
                new CollectionItemValueHolder(NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(type)], type, NdfbinManager), NdfbinManager);

            if (IsInsertMode)
            {
                if (cv.CurrentItem == null)
                {
                    return;
                }

                var val = cv.CurrentItem as CollectionItemValueHolder;

                if (val == null)
                {
                    return;
                }

                Value.Insert(cv.CurrentPosition + 1, wrapper);
            }
            else
            {
                Value.Add(wrapper);
            }

            cv.MoveCurrentTo(wrapper);
        }
Example #3
0
 private void GetValueForType()
 {
     Wrapper = new CollectionItemValueHolder(NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(Type)], Type, Manager), Manager);
 }
        /// <summary>
        /// Reads the value of a Property inside a object instance.
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="binary"></param>
        /// <returns>A NdfValueWrapper Instance.</returns>
        protected NdfValueWrapper ReadValue(Stream ms, NdfBinary binary)
        {
            uint            contBufferlen;
            NdfValueWrapper value;
            var             buffer = new byte[4];

            ms.Read(buffer, 0, buffer.Length);
            NdfType type = NdfTypeManager.GetType(buffer);

            if (type == NdfType.Unknown)
            {
                throw new InvalidDataException("Unknown datatypes are not supported!");
            }



            if (type == NdfType.Reference)
            {
                ms.Read(buffer, 0, buffer.Length);
                type = NdfTypeManager.GetType(buffer);
            }

            switch (type)
            {
            case NdfType.Unknown:
            case NdfType.WideString:
            case NdfType.List:
            case NdfType.MapList:
            case NdfType.Blob:
            case NdfType.ZipBlob:
                ms.Read(buffer, 0, buffer.Length);
                contBufferlen = BitConverter.ToUInt32(buffer, 0);

                if (type == NdfType.ZipBlob)
                {
                    if (ms.ReadByte() != 1)
                    {
                        throw new InvalidDataException("has to be checked.");
                    }
                }
                break;

            default:
                contBufferlen = NdfTypeManager.SizeofType(type);
                break;
            }

            switch (type)
            {
            case NdfType.MapList:
            case NdfType.List:
                NdfCollection lstValue = type == NdfType.List ? new NdfCollection() : new NdfMapList();

                for (int i = 0; i < contBufferlen; i++)
                {
                    CollectionItemValueHolder res;
                    if (type == NdfType.List)
                    {
                        res = new CollectionItemValueHolder(ReadValue(ms, binary), binary);
                    }
                    else
                    {
                        res = new CollectionItemValueHolder(
                            new NdfMap(
                                new MapValueHolder(ReadValue(ms, binary), binary),
                                new MapValueHolder(ReadValue(ms, binary), binary),
                                binary), binary);
                    }

                    lstValue.Add(res);
                }

                value = lstValue;
                break;

            case NdfType.Map:
                value = new NdfMap(
                    new MapValueHolder(ReadValue(ms, binary), binary),
                    new MapValueHolder(ReadValue(ms, binary), binary),
                    binary);
                break;

            default:
                var contBuffer = new byte[contBufferlen];
                ms.Read(contBuffer, 0, contBuffer.Length);

                value = NdfTypeManager.GetValue(contBuffer, type, binary);
                break;
            }

            return(value);
        }
Example #5
0
        public override void buildNdf(NdfBinary data, ref int i)
        {
            string name    = "";
            string ranking = "";

            switch (type)
            {
            case SpawnType.Land:
                name    = "TGameDesignAddOn_ReinforcementLocation";
                ranking = "ReinforcementLocations";

                break;

            case SpawnType.Sea:
                name    = "TGameDesignAddOn_MaritimeCorridor";
                ranking = "MaritimeCorridors";
                break;

            case SpawnType.Air:
                name    = "TGameDesignAddOn_AerialCorridor";
                ranking = "AerialCorridors";
                break;
            }
            var spawnPoint = createNdfObject(data, name);

            /*var nameProperty = getProperty(spawnPoint, "Name");
             * nameProperty.Value = getAutoName(data, i++);
             * var rankingProperty = getProperty(spawnPoint, "Ranking");
             * rankingProperty.Value = getString(data, ranking);
             * var guidProperty = getProperty(spawnPoint, "GUID");
             * rankingProperty.Value = new NdfGuid(Guid.NewGuid());
             * var allianceProperty = getProperty(spawnPoint, "NumAlliance");
             * allianceProperty.Value = new NdfInt32(1);*/

            var designItem = createNdfObject(data, "TGameDesignItem");
            var list       = data.Classes.First().Instances.First().PropertyValues.First().Value as NdfCollection;
            var ci         = new CollectionItemValueHolder(new NdfObjectReference(designItem.Class, designItem.Id), data);

            list.Add(ci);

            var positionProperty = getProperty(designItem, "Position");
            var hp = head.getPosition();
            var p  = Geometry.Geometry.convertPoint(hp);

            positionProperty.Value = new NdfVector(p);

            var rotationProperty = getProperty(designItem, "Rotation");
            var sp  = source.getPosition();
            var rot = Math.Atan2(hp.Y - sp.Y, hp.X - sp.X);

            rotationProperty.Value = new NdfSingle((float)rot);

            var   scaleProperty = getProperty(designItem, "Scale");
            var   length        = Math.Sqrt((hp.Y - sp.Y) * (hp.Y - sp.Y) + (hp.X - sp.X) * (hp.X - sp.X));
            float xScale        = (float)(length * Geometry.Geometry.scaleFactor) / arrowLength;

            scaleProperty.Value = new NdfVector(new System.Windows.Media.Media3D.Point3D(xScale, 1, 1));

            var addOnProperty = getProperty(designItem, "AddOn");

            addOnProperty.Value = new NdfObjectReference(spawnPoint.Class, spawnPoint.Id);
        }
        /// <summary>
        /// Reads the value of a Property inside a object instance.
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="triggerBreak"></param>
        /// <param name="prop"></param>
        /// <returns>A NdfValueWrapper Instance.</returns>
        protected NdfValueWrapper ReadValue(MemoryStream ms, out bool triggerBreak, NdfPropertyValue prop)
        {
            var             buffer = new byte[4];
            uint            contBufferlen;
            NdfValueWrapper value;

            triggerBreak = false;

            ms.Read(buffer, 0, buffer.Length);
            var type = NdfTypeManager.GetType(buffer);

            if (type == NdfType.Reference)
            {
                ms.Read(buffer, 0, buffer.Length);
                type = NdfTypeManager.GetType(buffer);
            }

            switch (type)
            {
            case NdfType.WideString:
            case NdfType.List:
            case NdfType.MapList:
                ms.Read(buffer, 0, buffer.Length);
                contBufferlen = BitConverter.ToUInt32(buffer, 0);
                break;

            default:
                contBufferlen = NdfTypeManager.SizeofType(type);
                break;
            }

            if (type == NdfType.Unknown)
            {
                //var t = _unknownTypes.SingleOrDefault(x => Utils.ByteArrayCompare(x, buffer));

                //if (t == default(byte[]))
                //{
                //    _unknownTypes.Add(buffer);
                //    _unknownTypesCount.Add(1);
                //}
                //else
                //    _unknownTypesCount[_unknownTypes.IndexOf(t)]++;

                triggerBreak = true;
                return(new NdfUnkown(buffer, ms.Position));
            }

            if (type == NdfType.List || type == NdfType.MapList)
            {
                NdfCollection lstValue;

                if (type == NdfType.List)
                {
                    lstValue = new NdfCollection(ms.Position);
                }
                else
                {
                    lstValue = new NdfMapList(ms.Position);
                }

                CollectionItemValueHolder res;

                for (int i = 0; i < contBufferlen; i++)
                {
                    if (type == NdfType.List)
                    {
                        res = new CollectionItemValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset);
                    }
                    else
                    {
                        res = new CollectionItemValueHolder(
                            new NdfMap(
                                new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                                new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                                ms.Position),
                            this, prop.InstanceOffset);
                    }

                    lstValue.Add(res);

                    if (triggerBreak)
                    {
                        break;
                    }
                }

                value = lstValue;
            }
            else if (type == NdfType.Map)
            {
                value = new NdfMap(
                    new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                    new MapValueHolder(ReadValue(ms, out triggerBreak, prop), this, prop.InstanceOffset),
                    ms.Position);
            }
            else
            {
                var contBuffer = new byte[contBufferlen];
                ms.Read(contBuffer, 0, contBuffer.Length);

                if (prop != null)
                {
                    prop.ValueData = contBuffer;
                }

                value = NdfTypeManager.GetValue(contBuffer, type, this, ms.Position - contBuffer.Length);
            }

            return(value);
        }
Example #7
0
        public override void buildNdf(NdfBinary data, ref int i)
        {
            var commandPoint = createNdfObject(data, "TGameDesignAddOn_CommandPoints");

            /*var nameProperty = getProperty(commandPoint, "Name");
             * nameProperty.Value = getAutoName(data, i++);
             * var rankingProperty = getProperty(commandPoint, "Ranking");
             * rankingProperty.Value = getString(data, "CommandPoints");
             * var guidProperty = getProperty(commandPoint, "GUID");
             * rankingProperty.Value = new NdfGuid(Guid.NewGuid());*/
            var pointsProperty = getProperty(commandPoint, "Points");

            pointsProperty.Value = new NdfInt32(value);

            var designItem = createNdfObject(data, "TGameDesignItem");
            var list       = data.Classes.First().Instances.First().PropertyValues.First().Value as NdfCollection;
            var ci         = new CollectionItemValueHolder(new NdfObjectReference(designItem.Class, designItem.Id), data);

            list.Add(ci);

            var positionProperty = getProperty(designItem, "Position");
            var p = Geometry.Geometry.convertPoint(attachPoint.getPosition());

            positionProperty.Value = new NdfVector(p);

            var addOnProperty = getProperty(designItem, "AddOn");

            addOnProperty.Value = new NdfObjectReference(commandPoint.Class, commandPoint.Id);

            if (possession != Possession.Neutral)
            {
                var startPoint = createNdfObject(data, "TGameDesignAddOn_StartingPoint");

                /*var nameProperty = getProperty(startPoint, "Name");
                 * nameProperty.Value = getAutoName(data, i++);
                 *
                 * var rankingProperty = getProperty(startPoint, "Ranking");
                 * rankingProperty.Value = getString(data, "StartingPoints");
                 * var guidProperty = getProperty(startPoint, "GUID");
                 * guidProperty.Value = new NdfGuid(Guid.NewGuid());*/
                if ((int)possession == 1)
                {
                    var allianceProperty = getProperty(startPoint, "AllianceNum");
                    allianceProperty.Value = new NdfInt32(1);

                    allianceProperty       = getProperty(startPoint, "WarmupCamPath");
                    allianceProperty.Value = getString(data, "Camp2");
                }
                else
                {
                    var allianceProperty = getProperty(startPoint, "WarmupCamPath");
                    allianceProperty.Value = getString(data, "Camp1");
                }

                designItem = createNdfObject(data, "TGameDesignItem");
                ci         = new CollectionItemValueHolder(new NdfObjectReference(designItem.Class, designItem.Id), data);
                list.Add(ci);


                positionProperty = getProperty(designItem, "Position");
                p = Geometry.Geometry.convertPoint(attachPoint.getPosition());
                positionProperty.Value = new NdfVector(p);
                var rotationProperty = getProperty(designItem, "Rotation");
                rotationProperty.Value = new NdfSingle(0f);

                addOnProperty       = getProperty(designItem, "AddOn");
                addOnProperty.Value = new NdfObjectReference(startPoint.Class, startPoint.Id);
            }
            //item.Value = NdfTypeManager.GetValue(new byte[NdfTypeManager.SizeofType(type)], type, item.Manager);
            //.Object.Manager.CreateInstanceOf
        }