Example #1
0
        /// <summary>
        /// Save file one by one
        /// </summary>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        /// <param name="action"></param>
        private void Save(string path, string filename, Func <byte[]> action)
        {
            var fullname = Path.Combine(path, filename);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            XLog.Write(Levels.Info, $"Saving {filename}...\t");
            File.WriteAllBytes(fullname, action());
        }
Example #2
0
        /// <summary>
        /// Load file one by one by data
        /// </summary>
        /// <param name="core"></param>
        /// <param name="filename"></param>
        /// <param name="action"></param>
        private void Import(Core core, string filename, Action <byte[]> action)
        {
            XLog.Write(Levels.Info, $"Loading {filename}...\t");

            if (!core.GetEntryExists(filename))
            {
                XLog.WriteLine(Levels.Warning, "Introuvable");
                return;
            }

            action(core.GetFileBytes(filename));
        }
Example #3
0
        /// <summary>
        /// Import  prop by data
        /// </summary>
        /// <param name="core"></param>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        private void ImportProp(Core core, string filename = "terrainpropinfo.cfg")
        {
            XLog.Write(Levels.Info, $"Loading {filename}...\t");

            if (!core.GetEntryExists(filename))
            {
                XLog.WriteLine(Levels.Warning, "Introuvable");
                return;
            }

            LoadProp(core.GetFileBytes(filename));
        }
Example #4
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));
        }
Example #5
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));
        }
Example #6
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);
            }
        }
Example #7
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());
        }