public Bitmap GetMapImage(bool crop = false, bool entity = true, bool sliceArea = false)
        {
            // Load MM
            byte[][] MM = Mini.UnpackMini(File.ReadAllBytes(MapMatrixes[DrawMap]), "MM");
            var      mm = OWSE.mm = new MapMatrix(MM);

            // Unknown
            if (ModifierKeys == Keys.Control)
            {
                Clipboard.SetText(mm.Unk2String());
            }

            // Load GR TileMaps
            for (int i = 0; i < mm.EntryList.Length; i++)
            {
                if (mm.EntryList[i] == 0xFFFF) // Mystery Zone
                {
                    continue;
                }
                byte[][] GR = Mini.UnpackMini(File.ReadAllBytes(MapGRs[mm.EntryList[i]]), "GR");
                mm.Entries[i] = new MapMatrix.Entry(GR[0])
                {
                    coll = new MapMatrix.Collision(GR[2])
                };
            }
            mapScale = Math.Max(1, (int)NUD_Scale.Value);
            Bitmap img = mm.Preview(mapScale, (int)NUD_Flavor.Value);

            baseImage = (Bitmap)img.Clone();

            if (sliceArea && mapScale > 3)
            {
                int area = 40 * mapScale;
                for (int x = 0; x < img.Width; x++)
                {
                    for (int y = 0; y < img.Height; y++)
                    {
                        if (x % area == 0 || y % area == 0)
                        {
                            img.SetPixel(x, y, Color.FromArgb(0x10, 0xFF, 0, 0));
                        }
                    }
                }
            }

            if (entity && mapScale == 8)
            {
                img = OverlayEntities(img);
            }

            if (crop)
            {
                img = WinFormsUtil.TrimBitmap(img);
            }

            return(img);
        }
示例#2
0
            public World(lzGARCFile garc, int worldID)
            {
                int index = worldID * 11;

                _7 = Mini.UnpackMini(garc[index + 7], "ZS");
                _8 = Mini.UnpackMini(garc[index + 8], "ZI");

                ZoneScripts     = HasZS ? _7.Select(arr => new Script(arr)).ToArray() : new Script[0];
                ZoneInfoScripts = HasZI ? _8.Select(arr => new Script(arr)).ToArray() : new Script[0];
            }
示例#3
0
        /// <summary>
        /// Gets an annotated Area array
        /// </summary>
        /// <param name="ed">Encounter Data GARC</param>
        /// <param name="zd">ZoneData GARC</param>
        /// <param name="wd">WorldData GARC</param>
        /// <param name="locationList">Location strings</param>
        /// <returns>Annotated Area Array</returns>
        public static Area7[] GetArray(lzGARCFile ed, lzGARCFile zd, lzGARCFile wd, string[] locationList)
        {
            var Worlds = wd.Files.Select(f => Mini.UnpackMini(f, "WD")[0]).ToArray();

            byte[][] zdfiles   = zd.Files;
            var      worldData = zdfiles[1];
            var      zoneData  = zdfiles[0];
            var      zones     = ZoneData7.GetZoneData7Array(zoneData, worldData, locationList, Worlds);
            var      areas     = GetArray(ed, zones);

            return(areas);
        }
示例#4
0
        public async Task <IEnumerable <Move> > GetMoves(bool edited = false)
        {
            var garcMoves = await this.GetGarc(GarcNames.Moves, edited : edited);

            IList <byte[]> files = await garcMoves.GetFiles();

            if (this.Version.IsORAS() || this.Version.IsGen7())
            {
                files = Mini.UnpackMini(files[0], "WD");
            }

            return(files.Select(file => {
                var m = new Move(this.Version);
                m.Read(file);
                return m;
            }));
        }
示例#5
0
文件: GameConfig.cs 项目: hnjm/pk3DS
        public void InitializeMoves()
        {
            GARCMoves = GetGARCData("move");
            switch (Generation)
            {
            case 6:
                if (XY)
                {
                    Moves = GARCMoves.Files.Select(file => new Move6(file)).ToArray();
                }
                if (ORAS)
                {
                    Moves = Mini.UnpackMini(GARCMoves.getFile(0), "WD").Select(file => new Move6(file)).ToArray();
                }
                break;

            case 7:
                Moves = Mini.UnpackMini(GARCMoves.getFile(0), "WD").Select(file => new Move7(file)).ToArray();
                break;
            }
        }
示例#6
0
        private void GetEntry()
        {
            if (entry < 0)
            {
                return;
            }
            byte[] raw = File.ReadAllBytes(filepaths[entry]);
            locationData = Mini.UnpackMini(raw, "ZO");
            if (locationData == null)
            {
                return;
            }

            // Read master ZD table
            byte[] zd = masterZoneData.Skip(ZoneData.Size * entry).Take(ZoneData.Size).ToArray();
            RTB_ZDMaster.Lines = Scripts.getHexLines(zd, 0x10);

            // Load from location Data.
            CurrentZone = new Zone(locationData);
            // File 0 - ZoneData
            RTB_ZD.Lines = Scripts.getHexLines(locationData[0], 0x10);
            GetZoneData();

            // File 1 - Overworld Setup & Script
            RTB_OWSC.Lines = Scripts.getHexLines(locationData[1], 0x10);
            GetOWSData();

            // File 2 - Map Script
            RTB_MapSC.Lines = Scripts.getHexLines(locationData[2], 0x10);
            GetScriptData();

            // File 3 - Encounters
            RTB_Encounter.Lines = Scripts.getHexLines(locationData[3], 0x10);

            // File 4 - ?? (ORAS Only?)
            RTB_File5.Lines = Scripts.getHexLines(locationData.Length <= 4 ? null : locationData[4], 0x10);
        }
示例#7
0
        public static Area7[] GetArray(lzGARCFile ed, ZoneData7[] zd)
        {
            int fileCount = ed.FileCount;
            var numAreas  = fileCount / 11;
            var areas     = new Area7[numAreas];

            for (int i = 0; i < numAreas; i++)
            {
                areas[i] = new Area7
                {
                    FileNumber = 9 + (11 * i),
                    Zones      = zd.Where(z => z.AreaIndex == i).ToArray()
                };
                var md = ed[areas[i].FileNumber];
                if (md.Length <= 0)
                {
                    areas[i].HasTables = false;
                    continue;
                }

                byte[][] Tables = Mini.UnpackMini(md, PackIdentifier);
                areas[i].HasTables = Tables.Any(t => t.Length > 0);
                if (!areas[i].HasTables)
                {
                    continue;
                }

                foreach (var Table in Tables)
                {
                    var DayTable   = Table.Skip(4).Take(0x164).ToArray();
                    var NightTable = Table.Skip(0x168).ToArray();
                    areas[i].Tables.Add(new EncounterTable(DayTable));
                    areas[i].Tables.Add(new EncounterTable(NightTable));
                }
            }
            return(areas);
        }
示例#8
0
        internal static void OpenARC(string path, ProgressBar pBar1, bool recursing = false)
        {
            string newFolder = "";

            try
            {
                // Pre-check file length to see if it is at least valid.
                FileInfo fi = new FileInfo(path);
                if (fi.Length > (long)2 * (1 << 30))
                {
                    WinFormsUtil.Error("File is too big!"); return;
                }                                                                                      // 2 GB
                string folderPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));

                byte[] first4 = new byte[4];
                try
                {
                    using var fs = new FileStream(path, FileMode.Open);
                    using var bw = new BinaryReader(fs);
                    first4       = bw.ReadBytes(4);
                }
                catch (Exception e)
                {
                    WinFormsUtil.Error("Cannot open file!", e.ToString());
                }

                // Determine if it is a DARC or a Mini
                // Check if Mini first
                string fx = fi.Length > 10 * (1 << 20) ? null : Mini.GetIsMini(path); // no mini is above 10MB
                if (fx != null)                                                       // Is Mini Packed File
                {
                    newFolder = folderPath + "_" + fx;
                    // Fetch Mini File Contents
                    Mini.UnpackMini(path, fx, newFolder, false);
                    // Recurse throught the extracted contents if they extract successfully
                    if (Directory.Exists(newFolder))
                    {
                        foreach (string file in Directory.GetFiles(newFolder))
                        {
                            OpenARC(file, pBar1, true);
                        }
                        BatchRenameExtension(newFolder);
                    }
                }
                else if (first4.SequenceEqual(BitConverter.GetBytes(0x54594C41))) // ALYT
                {
                    if (threads > 0)
                    {
                        WinFormsUtil.Alert("Please wait for all operations to finish first."); return;
                    }
                    new Thread(() =>
                    {
                        Interlocked.Increment(ref threads);
                        var alyt = new ALYT(File.ReadAllBytes(path));
                        var sarc = new SARC(alyt.Data) // rip out sarc
                        {
                            FileName = Path.GetFileNameWithoutExtension(path) + "_sarc",
                            FilePath = Path.GetDirectoryName(path)
                        };
                        if (!sarc.Valid)
                        {
                            return;
                        }
                        var files = sarc.Dump();
                        foreach (var _ in files)
                        {
                            // openARC(file, pBar1, true);
                        }
                        Interlocked.Decrement(ref threads);
                    }).Start();
                }
                else if (first4.SequenceEqual(BitConverter.GetBytes(0x47415243))) // GARC
                {
                    if (threads > 0)
                    {
                        WinFormsUtil.Alert("Please wait for all operations to finish first."); return;
                    }
                    bool SkipDecompression = ModifierKeys == Keys.Control;
                    new Thread(() =>
                    {
                        Interlocked.Increment(ref threads);
                        bool r = GarcUtil.UnpackGARC(path, folderPath + "_g", SkipDecompression, pBar1);
                        Interlocked.Decrement(ref threads);
                        if (r)
                        {
                            BatchRenameExtension(newFolder);
                        }
                        else
                        {
                            WinFormsUtil.Alert("Unpacking failed."); return;
                        }
                        System.Media.SystemSounds.Asterisk.Play();
                    }).Start();
                }
                else if (ARC.Analyze(path).valid) // DARC
                {
                    var data = File.ReadAllBytes(path);
                    int pos  = 0;
                    while (BitConverter.ToUInt32(data, pos) != 0x63726164)
                    {
                        pos += 4;
                        if (pos >= data.Length)
                        {
                            return;
                        }
                    }
                    var darcData = data.Skip(pos).ToArray();
                    newFolder = folderPath + "_d";
                    bool r = Core.CTR.DARC.Darc2files(darcData, newFolder);
                    if (!r)
                    {
                        WinFormsUtil.Alert("Unpacking failed.");
                    }
                }
                else if (ARC.AnalyzeSARC(path).Valid)
                {
                    var sarc = ARC.AnalyzeSARC(path);
                    Console.WriteLine($"New SARC with {sarc.SFAT.EntryCount} files.");
                    foreach (var _ in sarc.Dump(path))
                    {
                    }
                }
                else if (!recursing)
                {
                    WinFormsUtil.Alert("File is not a darc or a mini packed file:" + Environment.NewLine + path);
                }
            }
            catch (Exception e)
            {
                if (!recursing)
                {
                    WinFormsUtil.Error("File error:" + Environment.NewLine + path, e.ToString());
                }
                threads = 0;
            }
        }