Example #1
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Regions.Count);

                    for (int i = 0; i < Regions.Count; i++)
                    {
                        mem.Write(Regions[i].Priority);
                        mem.Write(Regions[i].X);
                        mem.Write(Regions[i].Y);
                        mem.Write(Regions[i].Z);
                        mem.Write(Regions[i].Radius);
                        mem.Write(Regions[i].Description.Length);
                        mem.Write(Encoding.Default.GetBytes(Regions[i].Description));

                        var script = Regions[i].Scripts.Length == 0 ?
                                     Regions[i].Scripts :
                                     Regions[i].Scripts.Replace("\0", "") + '\0';

                        mem.Write(script.Length);
                        mem.Write(Encoding.Default.GetBytes(script));
                        mem.Write(Regions[i].Polygons.Count);

                        for (int p = 0; p < Regions[i].Polygons.Count; p++)
                        {
                            mem.Write(Regions[i].Polygons[p].Count);

                            for (int n = 0; n < Regions[i].Polygons[p].Count; n++)
                            {
                                var vector = Regions[i].Polygons[p][n].Clone();

                                vector.X *= Global.AttrLenght;
                                vector.Y *= Global.AttrLenght;
                                vector    = vector.Rotate180FlipY();

                                mem.Write((int)vector.X);
                                mem.Write((int)vector.Y);
                            }
                        }
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfc::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Encoding.Default.GetBytes(Sign));
                    mem.Write(Version);
                    mem.Write(SegmentCountPerMap);
                    mem.Write(MapStartPosX);
                    mem.Write(MapStartPosY);
                    mem.Write((ushort)Segments.Count);
                    mem.Write(Props.Count);
                    mem.Write(SegmentLeft);
                    mem.Write(SegmentTop);
                    mem.Write(SegmentRight);
                    mem.Write(SegmentBottom);

                    for (int i = 0; i < Segments.Count; i++)
                    {
                        mem.Write(Segments[i].SegmentX);
                        mem.Write(Segments[i].SegmentY);
                        mem.Write((ushort)Segments[i].IncludeSegments.Count);

                        for (int f = 0; f < Segments[i].IncludeSegments.Count; f++)
                        {
                            mem.Write(Segments[i].IncludeSegments[f].SegmentX);
                            mem.Write(Segments[i].IncludeSegments[f].SegmentY);
                        }
                    }

                    for (int i = 0; i < Props.Count; i++)
                    {
                        mem.Write(Props[i].SegmentX);
                        mem.Write(Props[i].SegmentY);
                        mem.Write(Props[i].IncludeProps.Count);

                        for (int f = 0; f < Props[i].IncludeProps.Count; f++)
                        {
                            mem.Write(Props[i].IncludeProps[f].PropIdx);
                            mem.Write(Props[i].IncludeProps[f].SegmentIdx);
                        }
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Pvs::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Records.Count);

                    for (int i = 0; i < Records.Count; i++)
                    {
                        mem.Write(Records[i].Id);
                        mem.Write(Records[i].Polygons.Count);

                        for (int p = 0; p < Records[i].Polygons.Count; p++)
                        {
                            mem.Write(Records[i].Polygons[p].Count);

                            for (int t = 0; t < Records[i].Polygons[p].Count; t++)
                            {
                                var vector = Records[i].Polygons[p][t].Clone();

                                vector.X *= Global.AttrLenght;
                                vector.Y *= Global.AttrLenght;
                                vector    = vector.Rotate180FlipY();

                                mem.Write(vector.X);
                                mem.Write(vector.Y);
                                mem.Write(vector.Z);
                            }
                        }

                        var description = Records[i].Description.Length == 0 ?
                                          Records[i].Description :
                                          Records[i].Description.Replace("\0", "") + '\0';

                        mem.Write(description.Length);
                        mem.Write(Encoding.Default.GetBytes(description));
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfp::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Waters.Count);

                    for (int i = 0; i < Waters.Count; i++)
                    {
                        var rectangle = Waters[i].Rectangle.Clone();

                        rectangle.LeftTop.X *= Global.AttrLenght;
                        rectangle.LeftTop.Y *= Global.AttrLenght;
                        rectangle.LeftTop    = rectangle.LeftTop.Rotate180FlipY();

                        rectangle.RightBottom.X *= Global.AttrLenght;
                        rectangle.RightBottom.Y *= Global.AttrLenght;
                        rectangle.RightBottom    = rectangle.RightBottom.Rotate180FlipY();

                        rectangle.Center.X *= Global.AttrLenght;
                        rectangle.Center.Y *= Global.AttrLenght;
                        rectangle.Center    = rectangle.RightBottom.Rotate180FlipY();

                        mem.Write((int)rectangle.LeftTop.X);
                        mem.Write((int)rectangle.LeftTop.Y);
                        mem.Write((int)rectangle.LeftTop.Z);
                        mem.Write((int)rectangle.RightBottom.X);
                        mem.Write((int)rectangle.RightBottom.Y);
                        mem.Write((int)rectangle.RightBottom.Z);
                        mem.Write((int)rectangle.Center.X);
                        mem.Write((int)rectangle.Center.Y);
                        mem.Write((int)rectangle.Center.Z);
                        mem.Write(Waters[i].UseReflect);
                        mem.Write(Waters[i].WaterId);
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfw::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #5
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Encoding.Default.GetBytes(Sign));
                    mem.Write(Version);
                    mem.Write(Props.Count);

                    for (int i = 0; i < Props.Count; i++)
                    {
                        mem.Write(Props[i].QuestPropID);

                        var vector = Props[i].Position.Clone();

                        vector.X *= 7.875f;
                        vector.Y *= 7.875f;
                        vector    = vector.Rotate180FlipY();

                        mem.Write(vector.X);
                        mem.Write(vector.Y);
                        mem.Write(Props[i].OffSet);
                        mem.Write(Props[i].RotateX);
                        mem.Write(Props[i].RotateY);
                        mem.Write(Props[i].RotateZ);
                        mem.Write(Props[i].ScaleX);
                        mem.Write(Props[i].ScaleY);
                        mem.Write(Props[i].ScaleZ);
                        mem.Write(Props[i].PropNum);
                        mem.Write(Props[i].LockedHeight);
                        mem.Write(Props[i].LockHeight);
                        mem.Write(Props[i].TextureGroupIndex);
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Qpf::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #6
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Areas.Count);

                    for (int i = 0; i < Areas.Count; i++)
                    {
                        mem.Write(Areas[i].AreaId);
                        mem.Write(Areas[i].Polygons.Count);

                        for (int p = 0; p < Areas[i].Polygons.Count; p++)
                        {
                            mem.Write(Areas[i].Polygons[p].Count);

                            for (int n = 0; n < Areas[i].Polygons[p].Count; n++)
                            {
                                var vector = Areas[i].Polygons[p][n].Clone();

                                vector.X *= Global.AttrLenght;
                                vector.Y *= Global.AttrLenght;
                                vector    = vector.Rotate180FlipY();

                                mem.Write((int)vector.X);
                                mem.Write((int)vector.Y);
                            }
                        }
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfe::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            var mem = new MemoryWriter();

            try
            {
                mem.Write(Polygons.Count);

                for (int i = 0; i < Polygons.Count; i++)
                {
                    mem.Write(Polygons[i].Count);

                    for (int p = 0; p < Polygons[i].Count; p++)
                    {
                        var vector = Polygons[i][p].Clone();

                        vector.X = vector.X / Global.AttrLenght;
                        vector.Y = vector.Y / Global.AttrLenght;
                        vector   = vector.Rotate180FlipY();

                        mem.Write((int)vector.X);
                        mem.Write((int)vector.Y);
                    }
                }

                Parent.Log(Levels.Success, "Ok\n");
            }
            catch (Exception exception)
            {
                mem.Clear();
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfa::GetBuffer<Exception> -> {exception}\n");
            }

            return(mem.GetBuffer());
        }
Example #8
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Encoding.Default.GetBytes(Terrain.Sign));
                    mem.Write(22);

                    mem.Write(0);                     /* dwMapPropertiesOffset = */
                    mem.Write(0);                     /* dwTerrainSegmentOffset = */
                    mem.Write(0);                     /* dwPropOffset = */
                    mem.Write(0);                     /* dwVectorAttrOffset = */
                    mem.Write(0);                     /* dwWaterOffset = */
                    mem.Write(0);                     /* dwGrassColonyOffset = */
                    mem.Write(0);                     /* dwEventAreaOffset = */

                    mem.Write(Global.TileCountPerSegment);
                    mem.Write(Global.SegmentCountPerMap);
                    mem.Write(Global.TileLenght);

                    #region Properties

                    int dwMapPropertiesOffset = (int)mem.Position;

                    mem.Write(Terrain.MapProperties.Primary.Diffuse.Color.B);
                    mem.Write(Terrain.MapProperties.Primary.Diffuse.Color.G);
                    mem.Write(Terrain.MapProperties.Primary.Diffuse.Color.R);
                    mem.Write(Terrain.MapProperties.Primary.Specular.Color.B);
                    mem.Write(Terrain.MapProperties.Primary.Specular.Color.G);
                    mem.Write(Terrain.MapProperties.Primary.Specular.Color.R);
                    mem.Write(Terrain.MapProperties.Primary.Attenuation0);
                    mem.Write(Terrain.MapProperties.Primary.Attenuation1);
                    mem.Write(Terrain.MapProperties.Primary.Attenuation2);
                    mem.Write(Terrain.MapProperties.Secondary.Diffuse.Color.B);
                    mem.Write(Terrain.MapProperties.Secondary.Diffuse.Color.G);
                    mem.Write(Terrain.MapProperties.Secondary.Diffuse.Color.R);
                    mem.Write(Terrain.MapProperties.Secondary.Specular.Color.B);
                    mem.Write(Terrain.MapProperties.Secondary.Specular.Color.G);
                    mem.Write(Terrain.MapProperties.Secondary.Specular.Color.R);
                    mem.Write(Terrain.MapProperties.Secondary.Attenuation0);
                    mem.Write(Terrain.MapProperties.Secondary.Attenuation1);
                    mem.Write(Terrain.MapProperties.Secondary.Attenuation2);
                    mem.Write(Terrain.MapProperties.Sky.Color.B);
                    mem.Write(Terrain.MapProperties.Sky.Color.G);
                    mem.Write(Terrain.MapProperties.Sky.Color.R);
                    mem.Write(Terrain.MapProperties.Fog.Color.B);
                    mem.Write(Terrain.MapProperties.Fog.Color.G);
                    mem.Write(Terrain.MapProperties.Fog.Color.R);
                    mem.Write(Terrain.MapProperties.FogNear);
                    mem.Write(Terrain.MapProperties.FogFar);
                    mem.Write(Terrain.MapProperties.SkyType);
                    mem.Write(Terrain.MapProperties.ShowTerrainInGame);

                    #endregion

                    #region Terrain segment

                    int dwTerrainSegmentOffset = (int)mem.Position;

                    for (int segmentY = 0; segmentY < Global.SegmentCountPerMap; segmentY++)
                    {
                        for (int segmentX = 0; segmentX < Global.SegmentCountPerMap; segmentX++)
                        {
                            mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].Version);

                            for (int tile = 0; tile < 3; tile++)
                            {
                                mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].Tile[tile]);
                            }

                            for (int titleY = 0; titleY < Global.TileCountPerSegment; titleY++)
                            {
                                for (int tileX = 0; tileX < Global.TileCountPerSegment; tileX++)
                                {
                                    mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].Height);

                                    for (int f = 0; f < 2; f++)
                                    {
                                        mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].FillBits[f]);
                                    }

                                    mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].Attribute);
                                    mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].Color.Color.B);
                                    mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].Color.Color.G);
                                    mem.Write(Terrain.DwTerrainSegment[segmentX, segmentY].HsVector[tileX, titleY].Color.Color.R);
                                }
                            }
                        }
                    }

                    #endregion

                    #region Prop

                    int dwPropOffset = (int)mem.Position;

                    for (int segmentY = 0; segmentY < Global.SegmentCountPerMap; segmentY++)
                    {
                        for (int segmentX = 0; segmentX < Global.SegmentCountPerMap; segmentX++)
                        {
                            mem.Write(0);
                        }
                    }

                    int index   = 0;
                    int segment = 0;

                    for (int segmentY = 0; segmentY < Global.SegmentCountPerMap; segmentY++)
                    {
                        for (int segmentX = 0; segmentX < Global.SegmentCountPerMap; segmentX++)
                        {
                            var offset = (int)mem.Position;
                            mem.Seek(dwPropOffset + (4 * segment), SeekOrigin.Begin);
                            mem.Write(offset);
                            mem.Seek(offset, SeekOrigin.Begin);

                            var prop = Terrain.DwProps.Where(r => r.Position.GetSegmentId() == segment).ToList();

                            mem.Write(prop.Count);

                            for (int p = 0; p < prop.Count; p++)
                            {
                                mem.Write(index);

                                var vector = prop[p].Position.Clone();

                                vector = vector.GetSegmentCoordonate();

                                mem.Write(vector.X);
                                mem.Write(vector.Y);
                                mem.Write(vector.Z);
                                mem.Write(prop[p].RotateX);
                                mem.Write(prop[p].RotateY);
                                mem.Write(prop[p].RotateZ);
                                mem.Write(prop[p].ScaleX);
                                mem.Write(prop[p].ScaleY);
                                mem.Write(prop[p].ScaleZ);
                                mem.Write(prop[p].PropNum);
                                mem.Write(prop[p].HeightLocked);
                                mem.Write(prop[p].LockHeight);
                                mem.Write(prop[p].TextureGroup);
                                index++;
                            }

                            var grass = Terrain.DwGrass.Where(r => r.Position.GetSegmentId() == segment)
                                        .Select(u => u.GrassId)
                                        .Distinct()
                                        .ToList();

                            mem.Write(grass.Count);

                            for (int n = 0; n < grass.Count; n++)
                            {
                                var props = Terrain.DwGrass.Where(r => r.Position.GetSegmentId() == segment && r.GrassId == grass[n])
                                            .ToList();

                                mem.Write(grass[n]);
                                mem.Write(props.Count);

                                for (int i = 0; i < props.Count; i++)
                                {
                                    mem.Write(props[i].Position.X);
                                    mem.Write(props[i].Position.Y);
                                    mem.Write(props[i].RotateX);
                                    mem.Write(props[i].RotateY);
                                    mem.Write(props[i].RotateZ);
                                }
                            }

                            segment++;
                        }
                    }

                    #endregion

                    #region Vector attribute

                    var dwVectorAttrOffset = (int)mem.Position;
                    var collisions         = Parent == null ? Terrain.DwVectorAttr : Parent._collisionManager.Polygons;

                    mem.Write(collisions.Count);

                    for (int i = 0; i < collisions.Count; i++)
                    {
                        mem.Write(collisions[i].Count);

                        for (int p = 0; p < collisions[i].Count; p++)
                        {
                            var vector = collisions[i][p].Clone();

                            vector.X = vector.X * Global.ScaleRatio * PointRatio / Global.TileLenght;
                            vector.Y = vector.Y * Global.ScaleRatio * PointRatio / Global.TileLenght;
                            vector   = vector.Rotate180FlipY();

                            mem.Write((int)vector.X);
                            mem.Write((int)vector.Y);
                        }
                    }

                    #endregion

                    #region Water

                    int dwWaterOffset = (int)mem.Position;

                    mem.Write(Terrain.DwWater.Count);

                    for (int i = 0; i < Terrain.DwWater.Count; i++)
                    {
                        var rectangle = Terrain.DwWater[i].Rectangle.Clone();

                        rectangle.LeftTop.X = rectangle.LeftTop.X * Global.ScaleRatio;
                        rectangle.LeftTop.Y = rectangle.LeftTop.Y * Global.ScaleRatio;
                        rectangle.LeftTop   = rectangle.LeftTop.Rotate180FlipY();

                        rectangle.RightBottom.X = rectangle.RightBottom.X * Global.ScaleRatio;
                        rectangle.RightBottom.Y = rectangle.RightBottom.Y * Global.ScaleRatio;
                        rectangle.RightBottom   = rectangle.RightBottom.Rotate180FlipY();

                        rectangle.Center.X = rectangle.Center.X * Global.ScaleRatio;
                        rectangle.Center.Y = rectangle.Center.Y * Global.ScaleRatio;
                        rectangle.Center   = rectangle.RightBottom.Rotate180FlipY();

                        mem.Write((int)rectangle.LeftTop.X);
                        mem.Write((int)rectangle.LeftTop.Y);
                        mem.Write((int)rectangle.LeftTop.Z);
                        mem.Write((int)rectangle.RightBottom.X);
                        mem.Write((int)rectangle.RightBottom.Y);
                        mem.Write((int)rectangle.RightBottom.Z);
                        mem.Write((int)rectangle.Center.X);
                        mem.Write((int)rectangle.Center.Y);
                        mem.Write((int)rectangle.Center.Z);

                        mem.Write(Terrain.DwWater[i].UseReflect);
                        mem.Write(Terrain.DwWater[i].WaterId);
                    }

                    #endregion

                    #region Speed grass

                    int dwGrassColonyOffset = (int)mem.Position;

                    mem.Write(Terrain.DwGrassColony.Count);

                    for (int i = 0; i < Terrain.DwGrassColony.Count; i++)
                    {
                        mem.Write(i + 1);
                        mem.Write(Terrain.DwGrassColony[i].Density);
                        mem.Write(Terrain.DwGrassColony[i].Distribution);
                        mem.Write(Terrain.DwGrassColony[i].Size);
                        mem.Write(Terrain.DwGrassColony[i].HeightP);
                        mem.Write(Terrain.DwGrassColony[i].HeightM);
                        mem.Write(Terrain.DwGrassColony[i].Color.Color.B);
                        mem.Write(Terrain.DwGrassColony[i].Color.Color.G);
                        mem.Write(Terrain.DwGrassColony[i].Color.Color.R);
                        mem.Write(Terrain.DwGrassColony[i].Color.Color.A);
                        mem.Write(Terrain.DwGrassColony[i].ColorRatio);
                        mem.Write(Terrain.DwGrassColony[i].ColorTone);
                        mem.Write(Terrain.DwGrassColony[i].Chroma);
                        mem.Write(Terrain.DwGrassColony[i].Brightness);
                        mem.Write(Terrain.DwGrassColony[i].CombinationRatio);
                        mem.Write(Terrain.DwGrassColony[i].WindReaction);

                        var texture = Terrain.DwGrassColony[i].Filename.Length == 0 ?
                                      Terrain.DwGrassColony[i].Filename :
                                      Terrain.DwGrassColony[i].Filename.Replace("\0", "") + '\0';

                        mem.Write(texture.Length);
                        mem.Write(Encoding.Default.GetBytes(texture));
                        mem.Write(Terrain.DwGrassColony[i].Polygons.Count);

                        for (int p = 0; p < Terrain.DwGrassColony[i].Polygons.Count; p++)
                        {
                            mem.Write(Terrain.DwGrassColony[i].Polygons[p].Count);

                            for (int n = 0; n < Terrain.DwGrassColony[i].Polygons[p].Count; n++)
                            {
                                mem.Write((int)Terrain.DwGrassColony[i].Polygons[p][n].X);
                                mem.Write((int)Terrain.DwGrassColony[i].Polygons[p][n].Y);
                            }
                        }
                    }

                    #endregion

                    #region Event area

                    int dwEventAreaOffset = (int)mem.Position;
                    var eventareas        = Parent == null ? Terrain.DwEventArea : Parent._eventAreaManager.Areas;

                    mem.Write(eventareas.Count);

                    for (int i = 0; i < eventareas.Count; i++)
                    {
                        mem.Write(eventareas[i].AreaId);
                        mem.Write(eventareas[i].Polygons.Count);

                        for (int p = 0; p < eventareas[i].Polygons.Count; p++)
                        {
                            mem.Write(eventareas[i].Polygons[p].Count);

                            for (int n = 0; n < eventareas[i].Polygons[p].Count; n++)
                            {
                                var vector = eventareas[i].Polygons[p][n].Clone();

                                vector.X = vector.X * Global.ScaleRatio * PointRatio / Global.TileLenght;
                                vector.Y = vector.Y * Global.ScaleRatio * PointRatio / Global.TileLenght;
                                vector   = vector.Rotate180FlipY();

                                mem.Write((int)vector.X);
                                mem.Write((int)vector.Y);
                            }
                        }
                    }

                    #endregion

                    mem.Seek(20, SeekOrigin.Begin);
                    mem.Write(dwMapPropertiesOffset);
                    mem.Write(dwTerrainSegmentOffset);
                    mem.Write(dwPropOffset);
                    mem.Write(dwVectorAttrOffset);
                    mem.Write(dwWaterOffset);
                    mem.Write(dwGrassColonyOffset);
                    mem.Write(dwEventAreaOffset);

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfm::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #9
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Encoding.Default.GetBytes(Sign));
                    mem.Write(Version);

                    mem.Write(0);                     /* dwEventLocationOffset = */
                    mem.Write(0);                     /* dwEventScriptOffset = */
                    mem.Write(0);                     /* dwPropScriptOffset = */

                    int dwEventLocationOffset = (int)mem.Position;
                    mem.Write(Respawns.Count);

                    for (int i = 0; i < Respawns.Count; i++)
                    {
                        var rectangle = Respawns[i].Rectangle.Clone();

                        rectangle.LeftTop.X = rectangle.LeftTop.X * Global.ScaleRatio / Global.TileLenght;
                        rectangle.LeftTop.Y = rectangle.LeftTop.Y * Global.ScaleRatio / Global.TileLenght;
                        rectangle.LeftTop   = rectangle.LeftTop.Rotate180FlipY();

                        rectangle.RightBottom.X = rectangle.RightBottom.X * Global.ScaleRatio / Global.TileLenght;
                        rectangle.RightBottom.Y = rectangle.RightBottom.Y * Global.ScaleRatio / Global.TileLenght;
                        rectangle.RightBottom   = rectangle.RightBottom.Rotate180FlipY();

                        mem.Write((int)rectangle.LeftTop.X);
                        mem.Write((int)rectangle.LeftTop.Y);
                        mem.Write((int)rectangle.RightBottom.X);
                        mem.Write((int)rectangle.RightBottom.Y);
                        mem.Write(Respawns[i].Description.Length);
                        mem.Write(Encoding.Default.GetBytes(Respawns[i].Description));
                    }

                    int dwEventScriptOffset = (int)mem.Position;
                    mem.Write(GetScriptCount());

                    for (int i = 0; i < Respawns.Count; i++)
                    {
                        if (Respawns[i].Scripts.Count > 0)
                        {
                            mem.Write(i);
                            mem.Write(Respawns[i].Scripts.Count);

                            for (int f = 0; f < Respawns[i].Scripts.Count; f++)
                            {
                                mem.Write(f);
                                mem.Write(Respawns[i].Scripts[f].Length);
                                mem.Write(Encoding.Default.GetBytes(Respawns[i].Scripts[f]));
                            }
                        }
                    }

                    int dwPropScriptOffset = (int)mem.Position;
                    mem.Write(Props.Count);

                    for (int i = 0; i < Props.Count; i++)
                    {
                        mem.Write(Props[i].PropId);

                        var vector = Props[i].Position;

                        vector.X *= 7.875f;
                        vector.Y *= 7.875f;
                        vector    = vector.Rotate180FlipY();

                        mem.Write(vector.X);
                        mem.Write(vector.Y);
                        mem.Write(Props[i].ModelId);
                        mem.Write(Props[i].Scripts.Count);

                        for (int f = 0; f < Props[i].Scripts.Count; f++)
                        {
                            mem.Write(f);
                            mem.Write(Props[i].Scripts[f].Length);
                            mem.Write(Encoding.Default.GetBytes(Props[i].Scripts[f]));
                        }
                    }

                    mem.Seek(20, SeekOrigin.Begin);
                    mem.Write(dwEventLocationOffset);
                    mem.Write(dwEventScriptOffset);
                    mem.Write(dwPropScriptOffset);

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfs::GetBuffer<Exception> -> {exception}\n");
            }

            return(null);
        }
Example #10
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                using (MemoryWriter mem = new MemoryWriter())
                {
                    mem.Write(Direction.X);
                    mem.Write(Direction.Y);
                    mem.Write(Direction.Z);
                    mem.Write(Specular.Color.B);
                    mem.Write(Specular.Color.G);
                    mem.Write(Specular.Color.R);
                    mem.Write(Specular.Color.A);
                    mem.Write(Diffuse.Color.B);
                    mem.Write(Diffuse.Color.G);
                    mem.Write(Diffuse.Color.R);
                    mem.Write(Diffuse.Color.A);
                    mem.Write(Ambient.Color.B);
                    mem.Write(Ambient.Color.G);
                    mem.Write(Ambient.Color.R);
                    mem.Write(Ambient.Color.A);
                    mem.Write(Lights.Count);

                    for (int i = 0; i < Lights.Count; i++)
                    {
                        var vector = Lights[i].Position.Clone();

                        vector.X *= 7.875f;
                        vector.Y *= 7.875f;
                        vector    = vector.Rotate180FlipY();

                        mem.Write(vector.X);
                        mem.Write(vector.Y);
                        mem.Write(vector.Z);
                        mem.Write(Lights[i].Height);
                        mem.Write(Lights[i].Direction.X);
                        mem.Write(Lights[i].Direction.Y);
                        mem.Write(Lights[i].Direction.Z);
                        mem.Write(Lights[i].Specular.Color.B);
                        mem.Write(Lights[i].Specular.Color.G);
                        mem.Write(Lights[i].Specular.Color.R);
                        mem.Write(Lights[i].Specular.Color.A);
                        mem.Write(Lights[i].Diffuse.Color.B);
                        mem.Write(Lights[i].Diffuse.Color.G);
                        mem.Write(Lights[i].Diffuse.Color.R);
                        mem.Write(Lights[i].Diffuse.Color.A);
                        mem.Write(Lights[i].Ambient.Color.B);
                        mem.Write(Lights[i].Ambient.Color.G);
                        mem.Write(Lights[i].Ambient.Color.R);
                        mem.Write(Lights[i].Ambient.Color.A);
                        mem.Write((int)Lights[i].LightType);
                    }

                    Parent.Log(Levels.Success, "Ok\n");
                    return(mem.ToArray());
                }
            }
            catch (Exception exception)
            {
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, string.Format("Nfl::GetBuffer<Exception> -> {0}\n", exception));
            }

            return(null);
        }