Exemplo n.º 1
0
        static void Main(string[] args)
        {
            path  = string.Empty;
            help  = false;
            xLeft = xRight = yTop = yBottom = -1;

            options = new OptionSet()
            {
                { "?|help=|h=", "Prints out the options.", h => help = h != null },
                { "r=|rom=", "The ROM path.", r => path = r },
                { "x1=", "1st X coord. from left, 0 to 63. Default: " + XLEFT + ".", x1 => xLeft = validatePosition("x1", x1, 0, 63) },
                { "x2=", "2nd X coord. from left, 1 to 64. Default: " + XRIGHT + ".", x2 => xRight = validatePosition("x2", x2, 1, 64) },
                { "y1=", "1st Y coord. from top,  0 to 63. Default: " + YTOP + ".", y1 => yTop = validatePosition("y1", y1, 0, 63) },
                { "y2=", "2nd Y coord. from top,  1 to 64. Default: " + YBOTTOM + ".", y2 => yBottom = validatePosition("y2", y2, 1, 64) },
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException)
            {
                ShowHelp("Error - usage is: ");
            }

            if (help)
            {
                ShowHelp("ff6mmgen.exe <[-r|-rom] romname.[smc|sfc]> [-x1 value] [-x2 value] [-y1 value] [-y2 value]. Example: 'ff6mmgen.exe -r ff6.smc -x1 41 -x2 49 -y1 42 -y2 56'.");
            }

            if (path == null || path == string.Empty)
            {
                ShowHelp("Rom path (-r|-rom romanme.[smc|sfc]) is an mandatory argument.");
            }

            if (xLeft == -1 || xRight == -1 || yTop == -1 || yBottom == -1)
            {
                xLeft   = XLEFT;
                xRight  = XRIGHT;
                yTop    = YTOP;
                yBottom = YBOTTOM;
            }
            else if (xLeft >= xRight)
            {
                ShowHelp("x1 must be smaller than x2.");
            }
            else if (yTop >= yBottom)
            {
                ShowHelp("y1 must be smaller than y2.");
            }

            Rom rm = new Rom(path);

            if (rm.ReadRom())
            {
                string gameCode = rm.GetGameCode();

                if (gameCode != GAMECODE)
                {
                    Console.WriteLine("Invalid Game code at $C0FFB0: " + gameCode + ". Game code value must be " + GAMECODE);
                }
                else
                {
                    rom = rm.Content;

                    try
                    {
                        // read the data
                        wobMap       = Decompress(WOB_MAP_PTR);
                        worMap       = Decompress(WOR_MAP_PTR);
                        wobMiniMap   = Decompress(WOB_MINI_MAP_PTR);
                        worMiniMap   = Decompress(WOR_MINI_MAP_PTR);
                        wobTilesProp = ReadTileProperties(WOB_TILE_PROPERTIES);
                        worTilesProp = ReadTileProperties(WOR_TILE_PROPERTIES);
                        wobTriggers  = ReadMapTriggers(0);
                        worTriggers  = ReadMapTriggers(1);

                        // Get data that goes after WOB & WOR Mini-Maps
                        endingPal = ReadBytesFromPointer(ENDING_PAL_PTR, 256);
                        falconGfx = ReadBytesFromPointer(FALCON_GFX_PTR, Bits.GetShort(rom, GetOffsetFromPointer(FALCON_GFX_PTR)));

                        // Generate Mini-Maps
                        byte[] compWob = WriteMiniMap(true);
                        byte[] compWor = WriteMiniMap(false);

                        int wobOff = GetOffsetFromPointer(WOB_MINI_MAP_PTR);
                        int palOff = GetOffsetFromPointer(ENDING_PAL_PTR);

                        int totalSize = compWob.Length + compWor.Length + falconGfx.Length + endingPal.Length;
                        int offset    = wobOff;

                        // Write Data
                        Bits.SetBytes(rm.Content, offset, compWob);
                        offset += compWob.Length;

                        Bits.SetBytes(rm.Content, offset, compWor);
                        int worPtr = AbsToSmc(offset);
                        offset += compWor.Length;

                        Bits.SetBytes(rm.Content, offset, falconGfx);
                        int falconPtr = AbsToSmc(offset);
                        offset += falconGfx.Length;

                        Bits.SetBytes(rm.Content, offset, endingPal);
                        int palPtr = AbsToSmc(offset);

                        // Write Pointers
                        Bits.SetInt24(rm.Content, SmcToAbs(WOR_MINI_MAP_PTR), worPtr);
                        Bits.SetInt24(rm.Content, SmcToAbs(FALCON_GFX_PTR), falconPtr);
                        Bits.SetInt24(rm.Content, SmcToAbs(ENDING_PAL_PTR), palPtr);

                        // Modify palette ASM
                        Bits.SetBytes(rom, SmcToAbs(ASM_CODE_A), asmA);
                        Bits.SetBytes(rom, SmcToAbs(ASM_CODE_B), asmB);

                        // Modify palette
                        offset = SmcToAbs(PALETTE_OFF);

                        for (int i = 0; i < palette.Length; i++)
                        {
                            Bits.SetShort(rom, offset + i * 2, palette[i]);
                        }


                        if (rm.WriteRom())
                        {
                            Console.WriteLine("Operation Completed!");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error! " + e.InnerException.Message);
                    }
                }
            }
        }