예제 #1
0
        /// <summary>
        /// Load texture info cfg
        /// </summary>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        public void OpenTexture(string path, string filename = "terraintextureinfo.cfg")
        {
            XLog.Write(Levels.Info, $"Loading {filename}...\t");

            var fullname = Path.Combine(path, filename);

            if (!File.Exists(fullname))
            {
                XLog.WriteLine(Levels.Warning, "Introuvable");
                return;
            }

            LoadTexture(File.ReadAllBytes(fullname));
        }
예제 #2
0
        /// <summary>
        /// Load existing nflavor props
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    Sign    = Encoding.Default.GetString(b.ReadBytes(18));
                    Version = b.ReadUInt32();

#if DEBUG == false
                    if (!SupportedVersion.Contains(Version))
                    {
                        XLog.WriteLine(Levels.Error, $"Failed");
                        XLog.WriteLine(Levels.Fatal, "QpfManager::Load<Version> -> Incompatible version {0} is not supported", Version);
                        return;
                    }
#endif

                    var PropCount = b.ReadInt32();

                    for (int i = 0; i < PropCount; i++)
                    {
                        var prop = new Prop();
                        prop.QuestPropID       = b.ReadInt32();
                        prop.X                 = b.ReadSingle();
                        prop.Y                 = b.ReadSingle();
                        prop.OffSet            = b.ReadSingle();
                        prop.RotateX           = b.ReadSingle();
                        prop.RotateY           = b.ReadSingle();
                        prop.RotateZ           = b.ReadSingle();
                        prop.ScaleX            = b.ReadSingle();
                        prop.ScaleY            = (Version >= 3) ? b.ReadSingle() : prop.ScaleX;
                        prop.ScaleZ            = (Version >= 3) ? b.ReadSingle() : prop.ScaleX;
                        prop.PropNum           = b.ReadUInt16();
                        prop.LockedHeight      = (Version >= 3) ? b.ReadBoolean() : false;
                        prop.LockHeight        = (Version >= 3) ? b.ReadSingle() : 0f;
                        prop.TextureGroupIndex = (Version >= 3) ? b.ReadInt16() : (short)-1;
                        Props.Add(prop);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "QpfManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #3
0
        /// <summary>
        /// Load file one by one
        /// </summary>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        /// <param name="action"></param>
        private void Load(string path, string filename, Action <byte[]> action)
        {
            XLog.Write(Levels.Info, $"Loading {filename}...\t");

            var fullname = Path.Combine(path, filename);

            if (!File.Exists(fullname))
            {
                XLog.WriteLine(Levels.Warning, "Introuvable");
                return;
            }

            action(File.ReadAllBytes(fullname));
        }
예제 #4
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Records.Count);

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

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

                            for (int t = 0; t < Records[i].Polygons[p].Points.Count; t++)
                            {
                                b.Write(Records[i].Polygons[p].Points[t].X);
                                b.Write(Records[i].Polygons[p].Points[t].Y);
                                b.Write(Records[i].Polygons[p].Points[t].Z);
                            }
                        }

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

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

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfpManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #5
0
        /// <summary>
        /// Load existing unknown
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    var nfpCount = b.ReadInt32();

                    for (int i = 0; i < nfpCount; i++)
                    {
                        var nfp = new RecordNfp();
                        nfp.Id = b.ReadInt32();
                        var polygonCount = b.ReadInt32();

                        for (int p = 0; p < polygonCount; p++)
                        {
                            var polygon  = new Polygon3();
                            var pointNum = b.ReadInt32();

                            for (int t = 0; t < pointNum; t++)
                            {
                                var point = new K3DPosition(b.ReadSingle(), b.ReadSingle(), b.ReadSingle());
                                polygon.Points.Add(point);
                            }

                            nfp.Polygons.Add(polygon);
                        }

                        var DescriptionCount = b.ReadInt32();
                        nfp.Description = Encoding.Default.GetString(b.ReadBytes(DescriptionCount));

                        Records.Add(nfp);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfpManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #6
0
        /// <summary>
        /// Save all file
        /// </summary>
        /// <param name="folder"></param>
        public void Save(string folder)
        {
            var filename = $"m{X.ToString("000")}_{Y.ToString("000")}";

            XLog.WriteLine(Levels.Info, "Saving map {0} on path {1}...", filename, folder);

            Save(folder + @"\nfa\", $"{filename}.nfa", new Func <byte[]>(Nfa.GetBuffer));
            Save(folder + @"\nfc\", $"{filename}.nfc", new Func <byte[]>(Nfc.GetBuffer));
            Save(folder + @"\nfe\", $"{filename}.nfe", new Func <byte[]>(Nfe.GetBuffer));
            Save(folder + @"\nfl\", $"{filename}.nfl", new Func <byte[]>(Nfl.GetBuffer));
            Save(folder + @"\nfm\", $"{filename}.nfm", new Func <byte[]>(Nfm.GetBuffer));
            Save(folder + @"\nfp\", $"{filename}.nfp", new Func <byte[]>(Nfp.GetBuffer));
            Save(folder + @"\nfs\", $"{filename}.nfs", new Func <byte[]>(Nfs.GetBuffer));
            Save(folder + @"\nfw\", $"{filename}.nfw", new Func <byte[]>(Nfw.GetBuffer));
            Save(folder + @"\pvs\", $"{filename}.pvs", new Func <byte[]>(Pvs.GetBuffer));
            Save(folder + @"\qpf\", $"{filename}.qpf", new Func <byte[]>(Qpf.GetBuffer));

            XLog.WriteLine(Levels.Info, "Map saving completed.");
        }
예제 #7
0
        /// <summary>
        /// Load existing event area
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    var areaCount = b.ReadInt32();

                    for (int i = 0; i < areaCount; i++)
                    {
                        var area = new EventAreaScript();
                        area.AreaId = b.ReadInt32();
                        var polygonCount = b.ReadInt32();

                        for (int p = 0; p < polygonCount; p++)
                        {
                            var polygon  = new Polygon2();
                            var pointNum = b.ReadInt32();

                            for (int n = 0; n < pointNum; n++)
                            {
                                var point = new K2DPosition();
                                point.X = b.ReadInt32();
                                point.Y = b.ReadInt32();
                                polygon.Points.Add(point);
                            }

                            area.Polygons.Add(polygon);
                        }

                        Events.Add(area);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfeManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #8
0
        /// <summary>
        /// Load existing light
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    Direction.X = b.ReadSingle();
                    Direction.Y = b.ReadSingle();
                    Direction.Z = b.ReadSingle();
                    Specular    = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                    Diffuse     = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                    Ambient     = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());

                    var lightCount = b.ReadInt32();

                    for (int i = 0; i < lightCount; i++)
                    {
                        var light = new StructLights();
                        light.Position.X  = b.ReadSingle();
                        light.Position.Y  = b.ReadSingle();
                        light.Position.Z  = b.ReadSingle();
                        light.Height      = b.ReadSingle();
                        light.Direction.X = b.ReadSingle();
                        light.Direction.Y = b.ReadSingle();
                        light.Direction.Z = b.ReadSingle();
                        light.Specular    = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                        light.Diffuse     = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                        light.Ambient     = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                        light.LightType   = (LightsType)b.ReadInt32();
                        Lights.Add(light);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NflManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #9
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Encoding.Default.GetBytes(Sign));
                    b.Write(Version);
                    b.Write(Props.Count);

                    for (int i = 0; i < Props.Count; i++)
                    {
                        b.Write(Props[i].QuestPropID);
                        b.Write(Props[i].X);
                        b.Write(Props[i].Y);
                        b.Write(Props[i].OffSet);
                        b.Write(Props[i].RotateX);
                        b.Write(Props[i].RotateY);
                        b.Write(Props[i].RotateZ);
                        b.Write(Props[i].ScaleX);
                        b.Write(Props[i].ScaleY);
                        b.Write(Props[i].ScaleZ);
                        b.Write(Props[i].PropNum);
                        b.Write(Props[i].LockedHeight);
                        b.Write(Props[i].LockHeight);
                        b.Write(Props[i].TextureGroupIndex);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "QpfManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #10
0
        /// <summary>
        /// Saving all file from data
        /// </summary>
        /// <param name="core"></param>
        /// <param name="folder"></param>
        public void Export(Core core, string folder)
        {
            var filename = $"m{X.ToString("000")}_{Y.ToString("000")}";

            XLog.WriteLine(Levels.Info, "Saving map {0} from DataCore v4...", filename);

            Export(core, $"{filename}.nfa", new Func <byte[]>(Nfa.GetBuffer));
            Export(core, $"{filename}.nfc", new Func <byte[]>(Nfc.GetBuffer));
            Export(core, $"{filename}.nfe", new Func <byte[]>(Nfe.GetBuffer));
            Export(core, $"{filename}.nfl", new Func <byte[]>(Nfl.GetBuffer));
            Export(core, $"{filename}.nfm", new Func <byte[]>(Nfm.GetBuffer));
            Export(core, $"{filename}.nfp", new Func <byte[]>(Nfp.GetBuffer));
            Export(core, $"{filename}.nfs", new Func <byte[]>(Nfs.GetBuffer));
            Export(core, $"{filename}.nfw", new Func <byte[]>(Nfw.GetBuffer));
            Export(core, $"{filename}.pvs", new Func <byte[]>(Pvs.GetBuffer));
            Export(core, $"{filename}.qpf", new Func <byte[]>(Qpf.GetBuffer));
            core.Save(folder);

            XLog.WriteLine(Levels.Info, "Map saving completed.");
        }
예제 #11
0
        /// <summary>
        /// Load a existing project map by file
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="file"></param>
        public void Load(string folder, string file, string encoding)
        {
            Dispose();
            ResolveName(file);

            XLog.WriteLine(Levels.Info, "Loading map {0} from path {1}...", file, folder);

            Cfg.Open(folder + @"\cfg");
            Load(folder + @"\nfa\", $"{file}{encoding}.nfa", new Action <byte[]>(Nfa.Load));
            Load(folder + @"\nfc\", $"{file}{encoding}.nfc", new Action <byte[]>(Nfc.Load));
            Load(folder + @"\nfe\", $"{file}{encoding}.nfe", new Action <byte[]>(Nfe.Load));
            Load(folder + @"\nfl\", $"{file}{encoding}.nfl", new Action <byte[]>(Nfl.Load));
            Load(folder + @"\nfm\", $"{file}{encoding}.nfm", new Action <byte[]>(Nfm.Load));
            Load(folder + @"\nfp\", $"{file}{encoding}.nfp", new Action <byte[]>(Nfp.Load));
            Load(folder + @"\nfs\", $"{file}{encoding}.nfs", new Action <byte[]>(Nfs.Load));
            Load(folder + @"\nfw\", $"{file}{encoding}.nfw", new Action <byte[]>(Nfw.Load));
            Load(folder + @"\pvs\", $"{file}{encoding}.pvs", new Action <byte[]>(Pvs.Load));
            Load(folder + @"\qpf\", $"{file}{encoding}.qpf", new Action <byte[]>(Qpf.Load));

            XLog.WriteLine(Levels.Info, "Map loading completed.");
        }
예제 #12
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Events.Count);

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

                        for (int p = 0; p < Events[i].Polygons.Count; p++)
                        {
                            b.Write(Events[i].Polygons[p].Points.Count);

                            for (int n = 0; n < Events[i].Polygons[p].Points.Count; n++)
                            {
                                b.Write(Events[i].Polygons[p].Points[n].X);
                                b.Write(Events[i].Polygons[p].Points[n].Y);
                            }
                        }
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfeManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #13
0
        /// <summary>
        /// Load a existing project map by data
        /// </summary>
        /// <param name="core"></param>
        /// <param name="folder"></param>
        /// <param name="file"></param>
        public void Import(Core core, string file, string encoding)
        {
            Dispose();
            ResolveName(file);

            XLog.WriteLine(Levels.Info, "Loading map {0} from DataCore v4...", file);

            Import(core, $"terrainpropinfo{encoding}.cfg", new Action <byte[]>(Cfg.LoadProp));
            Import(core, $"terraintextureinfo{encoding}.cfg", new Action <byte[]>(Cfg.LoadTexture));
            Import(core, $"{file}{encoding}.nfa", new Action <byte[]>(Nfa.Load));
            Import(core, $"{file}{encoding}.nfc", new Action <byte[]>(Nfc.Load));
            Import(core, $"{file}{encoding}.nfe", new Action <byte[]>(Nfe.Load));
            Import(core, $"{file}{encoding}.nfl", new Action <byte[]>(Nfl.Load));
            Import(core, $"{file}{encoding}.nfm", new Action <byte[]>(Nfm.Load));
            Import(core, $"{file}{encoding}.nfp", new Action <byte[]>(Nfp.Load));
            Import(core, $"{file}{encoding}.nfs", new Action <byte[]>(Nfs.Load));
            Import(core, $"{file}{encoding}.nfw", new Action <byte[]>(Nfw.Load));
            Import(core, $"{file}{encoding}.pvs", new Action <byte[]>(Pvs.Load));
            Import(core, $"{file}{encoding}.qpf", new Action <byte[]>(Qpf.Load));

            XLog.WriteLine(Levels.Info, "Map loading completed.");
        }
예제 #14
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Waters.Count);

                    for (int i = 0; i < Waters.Count; i++)
                    {
                        b.Write(Waters[i].PointA.X);
                        b.Write(Waters[i].PointA.Y);
                        b.Write(Waters[i].PointA.Z);
                        b.Write(Waters[i].PointB.X);
                        b.Write(Waters[i].PointB.Y);
                        b.Write(Waters[i].PointB.Z);
                        b.Write(Waters[i].Center.X);
                        b.Write(Waters[i].Center.Y);
                        b.Write(Waters[i].Center.Z);
                        b.Write(Waters[i].UseReflect);
                        b.Write(Waters[i].WaterId);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfwManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #15
0
        /// <summary>
        /// Load existing prop
        /// </summary>
        /// <param name="buffer"></param>
        public void LoadProp(byte[] buffer)
        {
            Props = new List <PropInfo>();
            try
            {
                using (StreamReader b = new StreamReader(new MemoryStream(buffer)))
                {
                    string line;

                    string category     = "";
                    string renderType   = "";
                    string lightMapType = "";
                    string visibleRatio = "";

                    while ((line = b.ReadLine()) != null)
                    {
                        line.Trim();

                        var properties = line.Split(new char[] { '=' }, 2);
                        if (!line.StartsWith(";") && properties.Length == 2)
                        {
                            if (properties[0] == "CATEGORY")
                            {
                                category = properties[1].ToString();
                            }
                            else if (properties[0] == "RENDERTYPE")
                            {
                                renderType = properties[1];
                            }
                            else if (properties[0] == "LIGHTMAPTYPE")
                            {
                                lightMapType = properties[1];
                            }
                            else if (properties[0] == "VISIBLE_RATIO")
                            {
                                visibleRatio = properties[1];
                            }
                            else if (properties[0] == "PROPNAME")
                            {
                                var values = properties[1].Split(new char[] { ',' }, 2);
                                if (values.Length == 2)
                                {
                                    var prop = new PropInfo();
                                    prop.Id           = uint.Parse(values[0]);
                                    prop.Category     = category;
                                    prop.PropName     = values[1];
                                    prop.LightMapType = lightMapType;
                                    prop.VisibleRatio = visibleRatio;
                                    prop.RenderType   = renderType;
                                    Props.Add(prop);
                                }
                            }
                        }
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Props = new List <PropInfo>();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "CfgManager::Prop::Load<Exception> -> {0}", exception);
            }
        }
예제 #16
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Direction.X);
                    b.Write(Direction.Y);
                    b.Write(Direction.Z);
                    b.Write(Specular.Color.B);
                    b.Write(Specular.Color.G);
                    b.Write(Specular.Color.R);
                    b.Write(Specular.Color.A);
                    b.Write(Diffuse.Color.B);
                    b.Write(Diffuse.Color.G);
                    b.Write(Diffuse.Color.R);
                    b.Write(Diffuse.Color.A);
                    b.Write(Ambient.Color.B);
                    b.Write(Ambient.Color.G);
                    b.Write(Ambient.Color.R);
                    b.Write(Ambient.Color.A);
                    b.Write(Lights.Count);

                    for (int i = 0; i < Lights.Count; i++)
                    {
                        b.Write(Lights[i].Position.X);
                        b.Write(Lights[i].Position.Y);
                        b.Write(Lights[i].Position.Z);
                        b.Write(Lights[i].Height);
                        b.Write(Lights[i].Direction.X);
                        b.Write(Lights[i].Direction.Y);
                        b.Write(Lights[i].Direction.Z);
                        b.Write(Lights[i].Specular.Color.B);
                        b.Write(Lights[i].Specular.Color.G);
                        b.Write(Lights[i].Specular.Color.R);
                        b.Write(Lights[i].Specular.Color.A);
                        b.Write(Lights[i].Diffuse.Color.B);
                        b.Write(Lights[i].Diffuse.Color.G);
                        b.Write(Lights[i].Diffuse.Color.R);
                        b.Write(Lights[i].Diffuse.Color.A);
                        b.Write(Lights[i].Ambient.Color.B);
                        b.Write(Lights[i].Ambient.Color.G);
                        b.Write(Lights[i].Ambient.Color.R);
                        b.Write(Lights[i].Ambient.Color.A);
                        b.Write((int)Lights[i].LightType);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NflManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #17
0
        /// <summary>
        /// Load the full map
        /// </summary>
        ///
        /// <example>
        /// Version 1 : 2048 % 128 = 16
        /// Version 2 : 2048 % 256 = 8
        /// </example>
        ///
        /// <param name="folder">The location to jpg dump</param>
        /// <param name="name">Associate name file</param>
        public void Load(Core core, string path, string name, string encoding, bool useCore = false)
        {
            New();

            if (!Directory.Exists(path))
            {
                XLog.WriteLine(Levels.Error, $"MapManager::Load<folder>() => Missing folder {path}.");
                return;
            }

            XLog.Write(Levels.Info, $"Loading minimap...\t");

            try
            {
                var error = 0;
                var load  = 0;

                using (var g = Graphics.FromImage(map))
                {
                    int partX;
                    int partY;
                    var partHeight = 128;
                    var partWidth  = 128;
                    var prefix     = string.Empty;

                    var occurence = !useCore?
                                    Directory.GetFiles(path, $"v256_{name}*")
                                        : core.GetEntriesByPartialName($"v256_{name}*").Select(r => r.Name);

                    if (occurence.Count() > 0)
                    {
                        partHeight = 256;
                        partWidth  = 256;
                        prefix     = "v256_";
                    }

                    partX = Width / partWidth;
                    partY = Height / partHeight;

                    g.Clear(Color.FromArgb(255, 120, 146, 173));

                    for (int y = 0; y < partY; y++)
                    {
                        for (int x = 0; x < partX; x++)
                        {
                            var filename = $"{prefix}{name}_{y}_{x}{encoding}.jpg";

                            if (!useCore)
                            {
                                filename = Path.Combine(path, filename);

                                if (!File.Exists(filename))
                                {
                                    filename = encoding != "" ? filename.Replace(encoding, string.Empty) : filename;
                                }
                            }
                            else
                            {
                                if (!occurence.Any(r => r == filename))
                                {
                                    filename = encoding != "" ? filename.Replace(encoding, string.Empty) : filename;
                                }
                            }

                            if (!useCore && !File.Exists(filename) || useCore && !occurence.Any(r => r == filename))
                            {
                                error++;
                                continue;
                            }

                            var buffer = new byte[0];
                            if (useCore)
                            {
                                buffer = core.GetFileBytes(filename);
                            }

                            var image = useCore ? Image.FromStream(new MemoryStream(buffer)) : Image.FromFile(filename);
                            g.DrawImage(image, x * partWidth, y * partHeight, partWidth, partHeight);

                            load++;
                        }
                    }

                    map.RotateFlip(RotateFlipType.Rotate180FlipX);

                    Restore();
                }

                if (error == 0)
                {
                    XLog.WriteLine(Levels.Good, "Ok");
                }
                else if (load > 0)
                {
                    XLog.WriteLine(Levels.Warning, "Partially ok");
                }
                else
                {
                    XLog.WriteLine(Levels.Error, "Failed");
                }

                XLog.WriteLine(Levels.Info, $"Loading the minimap completed. (Error count : {error})");
            }
            catch (Exception exception)
            {
                New();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "MapManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #18
0
        /// <summary>
        /// Load existing potencially visible set
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    Sign    = Encoding.Default.GetString(b.ReadBytes(16));
                    Version = b.ReadUInt16();

#if DEBUG == false
                    if (!SupportedVersion.Contains(Version))
                    {
                        XLog.WriteLine(Levels.Error, $"Failed");
                        XLog.WriteLine(Levels.Fatal, "PvsManager::Load<Version> -> Incompatible version {0} is not supported", Version);
                        return;
                    }
#endif

                    SegmentCountPerMap = b.ReadByte();
                    MapStartPosX       = b.ReadByte();
                    MapStartPosY       = b.ReadByte();

                    var segmentCount = b.ReadUInt16();
                    var propCount    = b.ReadInt32();

                    SegmentLeft   = b.ReadByte();
                    SegmentTop    = b.ReadByte();
                    SegmentRight  = b.ReadByte();
                    SegmentBottom = b.ReadByte();

                    for (int i = 0; i < segmentCount; i++)
                    {
                        var segment = new PVS_SEGMENT_V1();
                        segment.SegmentX = b.ReadByte();
                        segment.SegmentY = b.ReadByte();
                        var includeSegmentCount = b.ReadUInt16();

                        for (int f = 0; f < includeSegmentCount; f++)
                        {
                            var includeSegment = new SEGMENT_DATA_V1();
                            includeSegment.SegmentX = b.ReadByte();
                            includeSegment.SegmentY = b.ReadByte();
                            segment.IncludeSegments.Add(includeSegment);
                        }

                        Segments.Add(segment);
                    }

                    for (int i = 0; i < propCount; i++)
                    {
                        var prop = new PVS_PROP_V1();
                        prop.SegmentX = b.ReadByte();
                        prop.SegmentY = b.ReadByte();
                        var includePropCount = b.ReadInt32();

                        for (int f = 0; f < includePropCount; f++)
                        {
                            var includeProp = new PROP_DATA_V1();
                            includeProp.PropIdx    = b.ReadUInt32();
                            includeProp.SegmentIdx = b.ReadUInt32();
                            prop.IncludeProps.Add(includeProp);
                        }

                        Props.Add(prop);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "PvsManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #19
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Encoding.Default.GetBytes(Sign));
                    b.Write(22);

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

                    b.Write(TileCountPerSegment);
                    b.Write(SegmentCountPerMap);
                    b.Write(TileLenght);

                    #region Properties

                    int dwMapPropertiesOffset = (int)b.BaseStream.Position;

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

                    #endregion

                    #region Terrain segment

                    int dwTerrainSegmentOffset = (int)b.BaseStream.Position;

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

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

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

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

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

                    #endregion

                    #region Prop

                    int dwPropOffset = (int)b.BaseStream.Position;

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

                    int index   = 0;
                    int segment = 0;

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

                            var prop = DwProps.Where(r => r.SegmentId == segment).ToList();

                            b.Write(prop.Count);

                            for (int p = 0; p < prop.Count; p++)
                            {
                                b.Write(index);
                                b.Write(prop[p].X);
                                b.Write(prop[p].Y);
                                b.Write(prop[p].Z);
                                b.Write(prop[p].RotateX);
                                b.Write(prop[p].RotateY);
                                b.Write(prop[p].RotateZ);
                                b.Write(prop[p].ScaleX);
                                b.Write(prop[p].ScaleY);
                                b.Write(prop[p].ScaleZ);
                                b.Write(prop[p].PropNum);
                                b.Write(prop[p].HeightLocked);
                                b.Write(prop[p].LockHeight);
                                b.Write(prop[p].TextureGroup);
                                index++;
                            }

                            var grass = DwGrass.Where(r => r.SegmentId == segment).ToList();

                            b.Write(grass.Count);

                            for (int n = 0; n < grass.Count; n++)
                            {
                                b.Write(grass[n].GrassId);
                                b.Write(grass[n].Props.Count);

                                for (int i = 0; i < grass[n].Props.Count; i++)
                                {
                                    b.Write(grass[n].Props[i].X);
                                    b.Write(grass[n].Props[i].Y);
                                    b.Write(grass[n].Props[i].RotateX);
                                    b.Write(grass[n].Props[i].RotateY);
                                    b.Write(grass[n].Props[i].RotateZ);
                                }
                            }

                            segment++;
                        }
                    }

                    #endregion

                    #region Vector attribute

                    int dwVectorAttrOffset = (int)b.BaseStream.Position;

                    b.Write(Nfa.Instance.Polygons.Count);

                    for (int i = 0; i < Nfa.Instance.Polygons.Count; i++)
                    {
                        b.Write(Nfa.Instance.Polygons[i].Points.Count);

                        for (int p = 0; p < Nfa.Instance.Polygons[i].Points.Count; p++)
                        {
                            b.Write(Nfa.Instance.Polygons[i].Points[p].X);
                            b.Write(Nfa.Instance.Polygons[i].Points[p].Y);
                        }
                    }

                    #endregion

                    #region Water

                    int dwWaterOffset = (int)b.BaseStream.Position;

                    b.Write(DwWater.Count);

                    for (int i = 0; i < DwWater.Count; i++)
                    {
                        b.Write(DwWater[i].PointA.X);
                        b.Write(DwWater[i].PointA.Y);
                        b.Write(DwWater[i].PointA.Z);
                        b.Write(DwWater[i].PointB.X);
                        b.Write(DwWater[i].PointB.Y);
                        b.Write(DwWater[i].PointB.Z);
                        b.Write(DwWater[i].Center.X);
                        b.Write(DwWater[i].Center.Y);
                        b.Write(DwWater[i].Center.Z);
                        b.Write(DwWater[i].UseReflect);
                        b.Write(DwWater[i].WaterId);
                    }

                    #endregion

                    #region Speed grass

                    int dwGrassColonyOffset = (int)b.BaseStream.Position;

                    b.Write(DwGrassColony.Count);

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

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

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

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

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

                    #endregion

                    #region Event area

                    int dwEventAreaOffset = (int)b.BaseStream.Position;

                    b.Write(Nfe.Instance.Events.Count);

                    for (int i = 0; i < Nfe.Instance.Events.Count; i++)
                    {
                        b.Write(Nfe.Instance.Events[i].AreaId);
                        b.Write(Nfe.Instance.Events[i].Polygons.Count);

                        for (int p = 0; p < Nfe.Instance.Events[i].Polygons.Count; p++)
                        {
                            b.Write(Nfe.Instance.Events[i].Polygons[p].Points.Count);

                            for (int n = 0; n < Nfe.Instance.Events[i].Polygons[p].Points.Count; n++)
                            {
                                b.Write(Nfe.Instance.Events[i].Polygons[p].Points[n].X);
                                b.Write(Nfe.Instance.Events[i].Polygons[p].Points[n].Y);
                            }
                        }
                    }

                    #endregion

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

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfmManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #20
0
        /// <summary>
        /// Load existing map
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    Sign    = Encoding.Default.GetString(b.ReadBytes(16));
                    Version = b.ReadInt32();

#if DEBUG == false
                    if (!SupportedVersion.Contains(Version))
                    {
                        XLog.WriteLine(Levels.Error, $"Failed");
                        XLog.WriteLine(Levels.Error, "Incompatible version {0} is not supported or not implemented.", Version);
                        return;
                    }
#endif

                    var dwMapPropertiesOffset  = b.ReadInt32();
                    var dwTerrainSegmentOffset = b.ReadInt32();
                    var dwPropOffset           = b.ReadInt32();
                    var dwVectorAttrOffset     = b.ReadInt32();
                    var dwWaterOffset          = b.ReadInt32();
                    var dwGrassColonyOffset    = (Version >= 17) ? b.ReadInt32() : 0;
                    var dwEventAreaOffset      = (Version >= 22) ? b.ReadInt32() : 0;

                    TileCountPerSegment = b.ReadInt32();
                    SegmentCountPerMap  = b.ReadInt32();
                    TileLenght          = b.ReadSingle();

                    #region Properties

                    MapProperties.Primary.Diffuse        = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.Primary.Specular       = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.Primary.Attenuation0   = b.ReadSingle();
                    MapProperties.Primary.Attenuation1   = b.ReadSingle();
                    MapProperties.Primary.Attenuation2   = b.ReadSingle();
                    MapProperties.Secondary.Diffuse      = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.Secondary.Specular     = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.Secondary.Attenuation0 = b.ReadSingle();
                    MapProperties.Secondary.Attenuation1 = b.ReadSingle();
                    MapProperties.Secondary.Attenuation2 = b.ReadSingle();
                    MapProperties.Sky               = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.Fog               = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), 255);
                    MapProperties.FogNear           = b.ReadSingle();
                    MapProperties.FogFar            = b.ReadSingle();
                    MapProperties.SkyType           = b.ReadUInt32();
                    MapProperties.ShowTerrainInGame = b.ReadBoolean();

                    #endregion

                    #region Terrain segment

                    for (int segmentY = 0; segmentY < SegmentCountPerMap; segmentY++)
                    {
                        for (int segmentX = 0; segmentX < SegmentCountPerMap; segmentX++)
                        {
                            DwTerrainSegment[segmentX, segmentY]         = new KSegment();
                            DwTerrainSegment[segmentX, segmentY].Version = (Version >= 16) ? b.ReadUInt32() : 0;

                            for (int tile = 0; tile < 3; tile++)
                            {
                                DwTerrainSegment[segmentX, segmentY].Tile[tile] = (Version >= 16) ? b.ReadUInt16() : (ushort)0;
                            }

                            DwTerrainSegment[segmentX, segmentY].HsVector = new KVertex[TileCountPerSegment, TileCountPerSegment];

                            for (int tileY = 0; tileY < TileCountPerSegment; tileY++)
                            {
                                for (int tileX = 0; tileX < TileCountPerSegment; tileX++)
                                {
                                    DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY]        = new KVertex();
                                    DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY].Height = b.ReadSingle();

                                    for (int f = 0; f < 2; f++)
                                    {
                                        if (Version >= 16)
                                        {
                                            DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY].FillBits[f] = b.ReadUInt32();
                                        }
                                        if (Version == 15 && f == 0)
                                        {
                                            DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY].FillBits[f] = b.ReadUInt32();
                                        }
                                    }

                                    DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY].Attribute = (Version >= 16) ? b.ReadInt64() : 0;
                                    DwTerrainSegment[segmentX, segmentY].HsVector[tileX, tileY].Color     = new KTripleColor(b.ReadByte(), b.ReadByte(), b.ReadByte());
                                }
                            }
                        }
                    }

                    #endregion

                    #region Prop

                    //Escape offset prop table
                    for (int i = 0; i < SegmentCountPerMap * SegmentCountPerMap; i++)
                    {
                        b.ReadInt32();
                    }

                    // PROP
                    var segment = 0;
                    for (int segmentY = 0; segmentY < SegmentCountPerMap; segmentY++)
                    {
                        for (int segmentX = 0; segmentX < SegmentCountPerMap; segmentX++)
                        {
                            var propcount = b.ReadInt32();

                            for (int p = 0; p < propcount; p++)
                            {
                                var prop = new KProp();
                                /* index */ b.ReadInt32();
                                prop.SegmentId    = segment;
                                prop.X            = b.ReadSingle();
                                prop.Y            = b.ReadSingle();
                                prop.Z            = b.ReadSingle();
                                prop.RotateX      = b.ReadSingle();
                                prop.RotateY      = b.ReadSingle();
                                prop.RotateZ      = b.ReadSingle();
                                prop.ScaleX       = b.ReadSingle();
                                prop.ScaleY       = (Version >= 21) ? b.ReadSingle() : prop.ScaleX;
                                prop.ScaleZ       = (Version >= 21) ? b.ReadSingle() : prop.ScaleX;
                                prop.PropNum      = b.ReadUInt16();
                                prop.HeightLocked = (Version >= 21) ? b.ReadBoolean() : false;
                                prop.LockHeight   = (Version >= 21) ? b.ReadSingle() : 0.0f;
                                prop.TextureGroup = (Version >= 21) ? b.ReadInt16() : (short)-1;
                                DwProps.Add(prop);
                            }

                            if (Version >= 19)
                            {
                                var grassCount = b.ReadInt32();

                                for (int n = 0; n < grassCount; n++)
                                {
                                    var grass = new KGrass();
                                    grass.SegmentId = segment;
                                    grass.GrassId   = b.ReadInt32();
                                    var propCount = b.ReadInt32();

                                    for (int i = 0; i < propCount; i++)
                                    {
                                        var prop = new KGrassProp();
                                        prop.X       = b.ReadSingle();
                                        prop.Y       = b.ReadSingle();
                                        prop.RotateX = b.ReadSingle();
                                        prop.RotateY = b.ReadSingle();
                                        prop.RotateZ = b.ReadSingle();
                                        grass.Props.Add(prop);
                                    }

                                    DwGrass.Add(grass);
                                }
                            }

                            segment++;
                        }
                    }

                    #endregion

                    #region Vector attribute

                    var polygonCount = b.ReadInt32();

                    for (int i = 0; i < polygonCount; i++)
                    {
                        var polygon  = new Polygon2();
                        var pointNum = b.ReadInt32();

                        for (int p = 0; p < pointNum; p++)
                        {
                            var point = new K2DPosition();
                            point.X = b.ReadInt32();
                            point.Y = b.ReadInt32();
                            polygon.Points.Add(point);
                        }

                        DwVectorAttr.Add(polygon);
                    }

                    #endregion

                    #region Water

                    var waterCount = b.ReadInt32();

                    for (int i = 0; i < waterCount; i++)
                    {
                        var water = new Water();
                        water.PointA.X   = b.ReadSingle();
                        water.PointA.Y   = b.ReadSingle();
                        water.PointA.Z   = b.ReadSingle();
                        water.PointB.X   = b.ReadSingle();
                        water.PointB.Y   = b.ReadSingle();
                        water.PointB.Z   = b.ReadSingle();
                        water.Center.X   = b.ReadSingle();
                        water.Center.Y   = b.ReadSingle();
                        water.Center.Z   = b.ReadSingle();
                        water.UseReflect = b.ReadInt32();
                        water.WaterId    = b.ReadInt32();
                        DwWater.Add(water);
                    }

                    #endregion

                    if (Version >= 17)
                    {
                        #region Speed grass

                        var speedGrassCount = b.ReadInt32();

                        for (int i = 0; i < speedGrassCount; i++)
                        {
                            var speedGrass = new SpeedGrassColony();
                            speedGrass.GrassId          = b.ReadInt32();
                            speedGrass.Density          = b.ReadSingle();
                            speedGrass.Distribution     = b.ReadSingle();
                            speedGrass.Size             = b.ReadSingle();
                            speedGrass.HeightP          = b.ReadSingle();
                            speedGrass.HeightM          = b.ReadSingle();
                            speedGrass.Color            = new KColor(b.ReadByte(), b.ReadByte(), b.ReadByte(), b.ReadByte());
                            speedGrass.ColorRatio       = b.ReadSingle();
                            speedGrass.ColorTone        = b.ReadSingle();
                            speedGrass.Chroma           = b.ReadSingle();
                            speedGrass.Brightness       = b.ReadSingle();
                            speedGrass.CombinationRatio = b.ReadSingle();
                            speedGrass.WindReaction     = b.ReadSingle();
                            speedGrass.Filename         = Encoding.Default.GetString(b.ReadBytes(b.ReadInt32()));
                            var polyshCount = b.ReadInt32();

                            for (int p = 0; p < polyshCount; p++)
                            {
                                var polygon    = new Polygon2();
                                var pointCount = b.ReadInt32();
                                for (int n = 0; n < pointCount; n++)
                                {
                                    var point = new K2DPosition();
                                    point.X = b.ReadInt32();
                                    point.Y = b.ReadInt32();
                                    polygon.Points.Add(point);
                                }
                                speedGrass.Polygons.Add(polygon);
                            }
                            DwGrassColony.Add(speedGrass);
                        }

                        #endregion
                    }

                    if (Version >= 22)
                    {
                        #region Event area

                        var eventAreaCount = b.ReadInt32();

                        for (int i = 0; i < eventAreaCount; i++)
                        {
                            var area = new EventAreaScript();
                            area.AreaId = b.ReadInt32();
                            var count = b.ReadInt32();

                            for (int p = 0; p < count; p++)
                            {
                                var polygon  = new Polygon2();
                                var pointNum = b.ReadInt32();

                                for (int n = 0; n < pointNum; n++)
                                {
                                    var point = new K2DPosition();
                                    point.X = b.ReadInt32();
                                    point.Y = b.ReadInt32();
                                    polygon.Points.Add(point);
                                }

                                area.Polygons.Add(polygon);
                            }

                            DwEventArea.Add(area);
                        }

                        #endregion
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfmManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #21
0
        /// <summary>
        /// Load existing nflavor script
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    Sign    = Encoding.Default.GetString(b.ReadBytes(16));
                    Version = b.ReadInt32();

#if DEBUG == false
                    if (!SupportedVersion.Contains(Version))
                    {
                        XLog.WriteLine(Levels.Error, $"Failed");
                        XLog.WriteLine(Levels.Fatal, "NfsManager::Load<Version> -> Incompatible version {0} is not supported", Version);
                        return;
                    }
#endif

                    /* nfs.dwEventLocationOffset = */
                    b.ReadInt32();
                    /* nfs.dwEventScriptOffset = */ b.ReadInt32();
                    /* nfs.dwPropScriptOffset = */ b.ReadInt32();

                    var nLocationCount = b.ReadInt32();
                    Respawns = new List <Location>();

                    for (int i = 0; i < nLocationCount; i++)
                    {
                        var location = new Location();
                        location.Left   = b.ReadInt32();
                        location.Top    = b.ReadInt32();
                        location.Right  = b.ReadInt32();
                        location.Bottom = b.ReadInt32();
                        var stringSize = b.ReadInt32();
                        location.Description = Encoding.Default.GetString(b.ReadBytes(stringSize));
                        Respawns.Add(location);
                    }

                    var nScriptCount = b.ReadInt32();

                    for (int i = 0; i < nScriptCount; i++)
                    {
                        var index          = b.ReadInt32();
                        var nFunctionCount = b.ReadInt32();

                        for (int f = 0; f < nFunctionCount; f++)
                        {
                            var function = new Function();
                            /* function.nTrigger = */ b.ReadInt32();
                            var nStringSize = b.ReadInt32();
                            function.FunctionString = Encoding.Default.GetString(b.ReadBytes(nStringSize));
                            Respawns[index].Scripts.Add(function);
                        }
                    }

                    var nPropCount = b.ReadInt32();
                    Props = new List <PropScriptInfo>();

                    for (int i = 0; i < nPropCount; i++)
                    {
                        var propScript = new PropScriptInfo();
                        propScript.PropId  = b.ReadInt32();
                        propScript.X       = b.ReadSingle();
                        propScript.Y       = b.ReadSingle();
                        propScript.ModelId = b.ReadInt16();
                        var nFunctionCount = b.ReadInt32();

                        for (int f = 0; f < nFunctionCount; f++)
                        {
                            var function = new Function();
                            /* function.nTrigger = */ b.ReadInt32();
                            var nStringSize = b.ReadInt32();
                            function.FunctionString = Encoding.Default.GetString(b.ReadBytes(nStringSize));
                            propScript.Scripts.Add(function);
                        }

                        Props.Add(propScript);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfsManager::Load<Exception> -> {0}", exception);
            }
        }
예제 #22
0
        /// <summary>
        /// get buffer final file
        /// </summary>
        /// <returns></returns>
        public byte[] GetBuffer()
        {
            try
            {
                var stream = new MemoryStream();

                using (BinaryWriter b = new BinaryWriter(stream))
                {
                    b.Write(Encoding.Default.GetBytes(Sign));
                    b.Write(Version);

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

                    int dwEventLocationOffset = (int)b.BaseStream.Position;
                    b.Write(Respawns.Count);

                    for (int i = 0; i < Respawns.Count; i++)
                    {
                        b.Write(Respawns[i].Left);
                        b.Write(Respawns[i].Top);
                        b.Write(Respawns[i].Right);
                        b.Write(Respawns[i].Bottom);
                        b.Write(Respawns[i].Description.Length);
                        b.Write(Encoding.Default.GetBytes(Respawns[i].Description));
                    }

                    int dwEventScriptOffset = (int)b.BaseStream.Position;
                    b.Write(GetScriptCount());

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

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

                    int dwPropScriptOffset = (int)b.BaseStream.Position;
                    b.Write(Props.Count);

                    for (int i = 0; i < Props.Count; i++)
                    {
                        b.Write(Props[i].PropId);
                        b.Write(Props[i].X);
                        b.Write(Props[i].Y);
                        b.Write(Props[i].ModelId);
                        b.Write(Props[i].Scripts.Count);

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

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

                XLog.WriteLine(Levels.Good, "Ok");
                return(stream.ToArray());
            }
            catch (Exception exception)
            {
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfsManager::GetBuffer<Exception> -> {0}", exception);
            }

            return(null);
        }
예제 #23
0
        /// <summary>
        /// Export file one by one from data
        /// </summary>
        /// <param name="core"></param>
        /// <param name="filename"></param>
        /// <param name="action"></param>
        private void Export(Core core, string filename, Func <byte[]> action)
        {
            XLog.Write(Levels.Info, $"Saving {filename}...\t");

            core.ImportFileEntry(filename, action());
        }