Ejemplo n.º 1
0
        /// <summary>
        /// Loads all currentLevelIndex-specific data for a specific currentLevelIndex in a given ROM image
        /// </summary>
        /// <param name="rom">The Rom object to load data from</param>
        /// <param name="currentLevelIndex">The currentLevelIndex to load</param>
        public Level(MetroidRom rom, LevelIndex level)
        {
            this.rom   = rom;
            data       = rom.data;
            this.index = level;

            Format    = rom.Format.CreateLevelFormat(this);
            this.Bank = rom.Format.Banks[Format.LevelBankIndex];

            Bytes = new ByteIndexer(this);
            PCpu  = new PointerIndexer(this);
            PRom  = new PRomIndexer(this);

            pointers_deprecated = new LevelPointers(rom, this);

            structures = new StructureCollection(this);
            screens    = new ScreenCollection(this);

            patternGroups = new PatternGroupIndexTable(this);
            LoadPatterns();
            LoadPalette();

            combos  = new ComboTable(rom, Format.ComboDataOffset);
            sprites = Graphic.LevelSprites.GetSprites(level);
            itemTable_DEPRECATED = new ItemLoader(this, rom);
            //structures = new StructureCollection(this);
            altMusic = new AlternateMusicRooms(rom, this);

            this.Items = new ItemCollection(this);
            Items.LoadItems();

            TilePhysicsTableLocation = Format.GetTilePhysicsTableLocation();
        }
Ejemplo n.º 2
0
        private void DrawLevelPatterns(LevelIndex level)
        {
            spritePatterns.Clear();
            bgPatterns.Clear();

            PatternGroupIndexTable groups = GetLevelPatterns(level);

            spritePatterns.BeginWrite();
            bgPatterns.BeginWrite();
            for (int i = 0; i < groups.Count; i++)
            {
                PatternGroupOffsets offsets = rom.PatternGroupOffsets[groups[i]];

                if (offsets.IsPage0)
                {
                    spritePatterns.LoadTiles(offsets);
                }
                else
                {
                    bgPatterns.LoadTiles(offsets);
                }
            }
            spritePatterns.EndWrite();
            bgPatterns.EndWrite();

            ApplyPalette(level);

            SpritePatternBox.Image     = spritePatterns.PatternImage;
            BackgroundPatternBox.Image = bgPatterns.PatternImage;
        }
Ejemplo n.º 3
0
        /// <summary>Loads and draws pattern-group-index-table for selected level, and shows the defauls-selected pattern group.</summary>
        void LoadLevelData()
        {
            PatternGroupIndexTableList.Items.Clear();
            PatternGroupIndexTable groups = GetLevelPatterns(SelectedLevel);

            for (int i = 0; i < groups.Count; i++)
            {
                PatternGroupIndexTableList.Items.Add(groups[i].ToString("X"));
            }

            PatternGroupIndexTableList.SelectedIndex = 1;
            LoadSelectedGroupIndex();
            DrawLevelPatterns();
        }
Ejemplo n.º 4
0
 public void LoadPatternGroups(PatternGroupIndexTable table)
 {
     foreach (byte groupIndex in table)
     {
         PatternGroupOffsets offsets = rom.PatternGroupOffsets[groupIndex];
         // Page 0 = sprite pattern mem, 1 = bg.
         if (
             (offsets.IsPage0 && type == PatternTableType.sprite) ||
             (offsets.IsPage1 && type == PatternTableType.background))
         {
             LoadTiles(rom.data, offsets.SourceRomOffset, offsets.DestTileIndex, offsets.TileCount);
         }
     }
 }
Ejemplo n.º 5
0
        private void LoadLevelGroups()
        {
            PatternGroupIndexTableList.Items.Clear();
            PatternGroupIndexTable groups = GetLevelPatterns(SelectedLevel);

            for (int i = 0; i < groups.Count; i++)
            {
                //PatternGroupOffsets offsets = rom.PatternGroupOffsets[groups[i]];

                PatternGroupIndexTableList.Items.Add(groups[i].ToString("X"));
            }

            //PatternGroupIndexTableList.SelectedIndex = 0;
            DrawLevelPatterns();
        }
Ejemplo n.º 6
0
        /// <summary>Loads and draws pattern-group-index-table for selected, ALREADY LOADED level, but does not update the pattern group list or values.
        /// Call this method when the user selects an item in the PatternGroupList.</summary>
        void ReloadLevelValues()
        {
            PatternGroupIndexTable groups = GetLevelPatterns(SelectedLevel);

            if (groups.Count != PatternGroupIndexTableList.Items.Count)
            {
                throw new InvalidOperationException("An invalid call to ReloadLevelValues was made it TileSoucreEditor. The number of items present did not match the number of items to load.");
            }

            for (int i = 0; i < groups.Count; i++)
            {
                PatternGroupIndexTableList.Items[i] = groups[i].ToString("X");
            }

            DrawLevelPatterns();
        }
Ejemplo n.º 7
0
        public PatternTable(bool linear, PatternTableType type, PatternGroupIndexTable globalTiles, PatternGroupIndexTable levelTiles, MetroidRom rom)
        {
            this.type    = type;
            this._Linear = linear;
            if (linear)
            {
                patterns = new Bitmap(2048, 8, PixelFormat.Format8bppIndexed);
            }
            else
            {
                patterns = new Bitmap(128, 128, PixelFormat.Format8bppIndexed);
            }

            this.rom    = rom;
            this.groups = levelTiles;

            this.BeginWrite();
            LoadPatternGroups(globalTiles);
            LoadPatternGroups(levelTiles);
            this.EndWrite();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a Editroid.Rom from a stream
        /// </summary>
        /// <param name="s">T stream that contains a Metroid ROM image</param>
        public MetroidRom(Stream s)
        {
            try {
                // Todo: why are we truncating (overdump from) the ROM here?

                if (s.Length >= MMC3RomSize)
                {
                    data = new byte[MMC3RomSize];
                }
                else if (s.Length >= EnhancedRomSize)
                {
                    data = new byte[EnhancedRomSize];
                }
                else if (s.Length >= ExpandedRomSize)
                {
                    data = new byte[ExpandedRomSize];
                }
                else
                {
                    data = new byte[RomWithMapSize];
                }
                s.Read(data, 0, data.Length);
            }
            catch (Exception Ex) {
                MessageBox.Show("Caught " + Ex.GetType().ToString() + " - " + Ex.Message);
                throw;
            }


            if (data.Length < ExpandedRomSize)
            {
                RomFormat = RomFormats.Standard;
                Format    = new Editroid.ROM.Formats.StandardRomFormat(this);
            }
            else if (data.Length < EnhancedRomSize)
            {
                RomFormat = RomFormats.Expando;
                Format    = new Editroid.ROM.Formats.ExpandoRomFormat(this);
            }
            else if (data.Length < MMC3RomSize)
            {
                RomFormat = RomFormats.Enhanco;
                Format    = new Editroid.ROM.Formats.EnhancedRomFormat(this);
            }
            else
            {
                RomFormat = RomFormats.MMC3;
                Format    = new Editroid.ROM.Formats.Mmc3RomFormat(this);
            }

            Banks     = Format.Banks;
            FixedBank = Banks[Banks.Count - 1];
            ChrUsage  = new ChrUsageTable(this);
            if (Format.HasPrgAllocationTable)
            {
                _bankAllocation = Editroid.ROM.BankAllocation.ReadAllocation(data, Editroid.ROM.BankAllocation.BankAllocationOffset);
            }

            if (Format.HasChrAnimationTable)
            {
                LoadChrAnimationTable();
            }

            patternGroupOffsets = new PatternGroupOffsetTable(this);
            globalPatternGroups = new PatternGroupIndexTable(this);
            //MakeGameItems();
            passwordData = new PasswordData(this);
            titleText    = new TitleText(this);
            LoadLevels();
            LoadEditorData();

            GetDoorTileCounts();



            CacheSavedVersion();
        }