Ejemplo n.º 1
0
        protected override void DoActivate(ZeldaCartridge cartridge, ISeededRandom random)
        {
            var min            = _minimumHitPointsParameter.GetEffectiveValue <int>();
            var max            = _maximumHitPointsParameter.GetEffectiveValue <int>();
            var includeEnemies = _includeEnemiesParameter.GetEffectiveValue <bool>();
            var includeBosses  = _includeBossesParameter.GetEffectiveValue <bool>();
            var includeGanon   = _includeGanonParameter.GetEffectiveValue <bool>();

            if (includeEnemies)
            {
                for (var i = 0x00; i < 0x19; i++)
                {
                    cartridge.HitPointTable[i] = random.GetInt(min, max + 1);
                }
            }

            if (includeBosses)
            {
                for (var i = 0x19; i < 0x25; i++)
                {
                    if (i != 0x1F)
                    {
                        cartridge.HitPointTable[i] = random.GetInt(min, max + 1);
                    }
                }
            }

            if (includeGanon)
            {
                cartridge.HitPointTable[0x1F] = random.GetInt(min, max + 1);
            }
        }
Ejemplo n.º 2
0
 public void Activate(ZeldaCartridge cartridge, ISeededRandom random)
 {
     if (Enabled)
     {
         DoActivate(cartridge, random);
     }
 }
        public void Compile_CompilesOriginalDungeons()
        {
            // Load all data from the original cartridge
            var cart       = new ZeldaCartridge(Source);
            var decompiler = new OverworldRoomDecompiler();
            var inRooms    = decompiler.Decompile(cart.Overworld.ColumnLibraries, cart.Overworld.RoomLayouts);

            // Compile it
            var compiler     = new OverworldRoomCompiler();
            var output       = compiler.Compile(inRooms.Rooms);
            var columnOutput = output.ColumnData.ToArray();
            var roomOutput   = output.RoomData.ToArray();
            var columnMem    = new Source(columnOutput);
            var roomMem      = new Source(roomOutput);

            // Read it out
            var outputLibraryList = new[] { new OverworldColumnLibrary(columnMem, output.ColumnOffsets.Count()) };
            var outputRoomList    = new OverworldRoomLayoutList(roomMem, roomOutput.Length >> 4);
            var decompiledOutput  = decompiler.Decompile(outputLibraryList, outputRoomList);

            // Compare
            foreach (var room in inRooms.Rooms)
            {
                decompiledOutput.Rooms.Should().Contain(v => v.SequenceEqual(room));
            }
        }
Ejemplo n.º 4
0
        public void Test4()
        {
            var cart = new ZeldaCartridge(Source);

            var pathfinder = new Pathfinder(cart.Overworld, cart.Underworld);

            pathfinder.Start();

            //WriteToDesktop(ExportHeaderedRom(), "zelda-test.nes");
        }
Ejemplo n.º 5
0
        public void Decompile_GeneratesCorrectMap()
        {
            // Data.
            var expected00 = new[]
            {
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xE6, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x74, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x74, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x74, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x74, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8,
                0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x74, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8
            };

            var expected36 = new[]
            {
                0x90, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x90,
                0x90, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x90,
                0x90, 0xD8, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0xD8, 0x90,
                0x90, 0xD8, 0x26, 0xB0, 0xAA, 0x26, 0xB0, 0xB4, 0xAA, 0x26, 0xB0, 0xAA, 0x26, 0x26, 0xD8, 0x90,
                0x90, 0xD8, 0x26, 0xAC, 0xB8, 0x26, 0xAC, 0xF3, 0xB8, 0x26, 0xAC, 0xB8, 0x26, 0x26, 0xD8, 0x90,
                0x90, 0xD8, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x76,
                0x90, 0xD8, 0x26, 0x26, 0xB0, 0xAA, 0x26, 0x26, 0x26, 0xB0, 0xAA, 0x26, 0x26, 0x26, 0xCE, 0x90,
                0x90, 0xD8, 0x26, 0x26, 0xAC, 0xB8, 0x26, 0x26, 0x26, 0xAC, 0xB8, 0x26, 0x26, 0x26, 0xD8, 0x90,
                0x90, 0xD8, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0xD8, 0x90,
                0x90, 0xD8, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xCE, 0xD8, 0x90,
                0x90, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x90
            };

            // Arrange.
            var cart    = new ZeldaCartridge(Source);
            var tiles   = cart.Overworld.Tiles;
            var columns = cart.Overworld.ColumnLibraries;
            var rooms   = cart.Overworld.RoomLayouts;

            var overworld      = Subject.Decompile(columns, rooms);
            var overworldRooms = overworld.Rooms.ToArray();

            overworldRooms[0x00].Select(i => tiles[i]).Should().Equal(expected00);
            overworldRooms[0x36].Select(i => tiles[i]).Should().Equal(expected36);
        }
Ejemplo n.º 6
0
        protected override void DoActivate(ZeldaCartridge cartridge, ISeededRandom random)
        {
            var min = _minimumQuantityParameter.GetEffectiveValue <int>();
            var max = _maximumQuantityParameter.GetEffectiveValue <int>();

            foreach (var underworldLevel in cartridge.Underworld.Levels)
            {
                var underworldLength = underworldLevel.EnemyQuantities.Count;
                for (var i = 0; i < underworldLength; i++)
                {
                    underworldLevel.EnemyQuantities[i] = random.GetInt(min, max + 1);
                }
            }

            var overworldLevel  = cartridge.Overworld.Level;
            var overworldLength = overworldLevel.EnemyQuantities.Count;

            for (var i = 0; i < overworldLength; i++)
            {
                overworldLevel.EnemyQuantities[i] = random.GetInt(min, max + 1);
            }
        }
Ejemplo n.º 7
0
        protected override EndingText GetTestSubject()
        {
            var cart = new ZeldaCartridge(Source);

            return(cart.EndingText as EndingText);
        }
Ejemplo n.º 8
0
 protected abstract void DoActivate(ZeldaCartridge cartridge, ISeededRandom random);
Ejemplo n.º 9
0
        protected override ShopList GetTestSubject()
        {
            var cart = new ZeldaCartridge(Source);

            return(cart.Shops as ShopList);
        }
 public void Test1()
 {
     var cart       = new ZeldaCartridge(Source);
     var decompiled = Subject.Decompile(cart.Overworld.ColumnLibraries, cart.Overworld.RoomLayouts);
 }
Ejemplo n.º 11
0
        protected override MenuText GetTestSubject()
        {
            var cart = new ZeldaCartridge(Source);

            return(cart.MenuText as MenuText);
        }
Ejemplo n.º 12
0
        protected override CharacterText GetTestSubject()
        {
            var cart = new ZeldaCartridge(Source);

            return(cart.CharacterText as CharacterText);
        }
Ejemplo n.º 13
0
        public void Test1()
        {
            var cart        = new ZeldaCartridge(Source);
            var sprites     = cart.Overworld.Sprites;
            var renderer    = new SpriteRenderer();
            var palette     = new NtscNesPalette();
            var columns     = cart.Overworld.ColumnLibraries;
            var rooms       = cart.Overworld.RoomLayouts.ToList();
            var tiles       = cart.Overworld.Tiles;
            var detailTiles = cart.Overworld.DetailTiles;
            var grid        = cart.Overworld.Grid;

            var decompiler      = new OverworldRoomDecompiler();
            var decompiledRooms = decompiler.Decompile(columns, rooms);

            // Grayscale
            renderer.Colors[0] = palette[0x0F];
            renderer.Colors[1] = palette[0x00];
            renderer.Colors[2] = palette[0x10];
            renderer.Colors[3] = palette[0x20];

            // Render out sprites
            var spriteBitmaps = sprites
                                .Select(sprite => renderer.Render(sprite))
                                .ToArray();

            var roomBitmaps = new Dictionary <int, Bitmap>();

            // Render out rooms
            var roomIndex = 0;

            foreach (var room in decompiledRooms.Rooms.Select(r => r.Select(i => tiles[i]).ToArray()))
            {
                var roomBitmap = new Bitmap(256, 168);

                using (var g = Graphics.FromImage(roomBitmap))
                    using (var backgroundBrush = new SolidBrush(renderer.Colors[2]))
                        using (var mem = new MemoryStream())
                        {
                            g.FillRectangle(backgroundBrush, 0, 0, 256, 168);
                            var tileIndex = 0;

                            for (var y = 0; y < 11; y++)
                            {
                                for (var x = 0; x < 16; x++)
                                {
                                    var tile  = room[tileIndex];
                                    var plotX = x << 4;
                                    var plotY = y << 4;
                                    tileIndex++;

                                    var tileIds = tile < 0x10
                                ? detailTiles[tile]
                                : tile >= 0x70 && tile <= 0xF1
                                    ? Enumerable.Range(tile, 4)
                                    : null;

                                    if (tileIds != null)
                                    {
                                        var tileIdArray = tileIds
                                                          .Select(s => s < 0x70 || s > 0xF1 ? 0x7A : s - 0x70)
                                                          .ToArray();

                                        g.DrawImage(spriteBitmaps[tileIdArray[0]], plotX, plotY);
                                        g.DrawImage(spriteBitmaps[tileIdArray[2]], plotX + 8, plotY);
                                        g.DrawImage(spriteBitmaps[tileIdArray[1]], plotX, plotY + 8);
                                        g.DrawImage(spriteBitmaps[tileIdArray[3]], plotX + 8, plotY + 8);
                                    }

                                    if (tile >= 0x85 && tile < 0xE5)
                                    {
                                        g.DrawRectangle(Pens.Red, plotX, plotY, 16, 16);
                                    }
                                }
                            }

                            roomBitmap.Save(mem, ImageFormat.Png);
                            WriteToDesktopPath(room.ToByteArray(), "overworld", $"{roomIndex:X2}.bin");
                            WriteToDesktopPath(mem.ToArray(), "overworld", $"{roomIndex:X2}.png");
                        }

                roomBitmaps[roomIndex] = roomBitmap;
                roomIndex++;
            }

            using (var outputMap = new Bitmap(256 * 16, 168 * 8))
                using (var g = Graphics.FromImage(outputMap))
                    using (var mem = new MemoryStream())
                    {
                        var x = 0;
                        var y = 0;
                        foreach (var i in grid)
                        {
                            while (x >= outputMap.Width)
                            {
                                x -= outputMap.Width;
                                y += 168;
                            }

                            g.DrawImage(roomBitmaps[i.Layout], x, y);
                            x += 256;
                        }

                        outputMap.Save(mem, ImageFormat.Png);
                        WriteToDesktop(mem.ToArray(), "test.png");
                    }

            foreach (var bitmap in roomBitmaps)
            {
                bitmap.Value?.Dispose();
            }
        }