예제 #1
0
            public ObjectDefTile(ByteArrayInputStream inp, NSMBTileset t)
            {
                this.t = t;
                if (inp.available < 1)  //This should never happen. But sometimes, it does.
                {
                    controlByte = 0xFF; //Simulate object end.
                    return;
                }

                controlByte = inp.readByte();

                if (!controlTile)

                {
                    byte a, b;
                    a = inp.readByte();
                    b = inp.readByte();

                    tileID = a + ((b - t.ObjectDefTileOffset) << 8);

                    if ((controlByte & 64) != 0) //OVERRIDES
                    {
                        tileID += 768;
                    }
                    if (a == 0 && b == 0)
                    {
                        tileID = -1;
                    }
                }
            }
예제 #2
0
 public void load(NSMBGraphics g, int TilesetNumber)
 {
     this.tnum = TilesetNumber;
     this.tls  = g.Tilesets[tnum];
     tilePicker1.init(new Bitmap[] { tls.map16.buffer }, 16);
     previewObject = new NSMBObject(0, tnum, 0, 0, 6, 6, g);
 }
예제 #3
0
            public ObjectDef(NSMBTileset t)
            {
                this.t = t;
                tiles  = new List <List <ObjectDefTile> >();
                List <ObjectDefTile> row = new List <ObjectDefTile>();

                tiles.Add(row);
            }
예제 #4
0
 public void SetTileset(NSMBTileset t)
 {
     this.t           = t;
     tileCount        = t.Map16Buffer.Width / 16;
     map16Image       = Image2D.CutImage(t.Map16Buffer, 256, 1);
     pictureBox1.Size = map16Image.Size;
     pictureBox1.Invalidate(true);
 }
예제 #5
0
        public override void save()
        {
            ByteArrayOutputStream oo = new ByteArrayOutputStream();

            for (int i = 0; i < pal.Length; i++)
            {
                oo.writeUShort(NSMBTileset.toRGB15(pal[i]));
            }

            f.replace(oo.getArray(), this);
        }
예제 #6
0
        public static Color[] arrayToPalette(byte[] data)
        {
            ByteArrayInputStream ii = new ByteArrayInputStream(data);

            Color[] pal = new Color[data.Length / 2];
            for (int i = 0; i < pal.Length; i++)
            {
                pal[i] = NSMBTileset.fromRGB15(ii.readUShort());
            }
            return(pal);
        }
예제 #7
0
        private void exportTilesetBtn_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = LanguageManager.Get("Filters", "tileset");
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            NSMBTileset t = loadTileset(getSelectedID());

            t.exportTileset(sfd.FileName);
        }
예제 #8
0
        private void importTilesetBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = LanguageManager.Get("Filters", "tileset");
            ofd.CheckFileExists = true;

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            NSMBTileset t = loadTileset(getSelectedID());

            t.importTileset(ofd.FileName);
        }
예제 #9
0
        public void LoadTileset1(ushort TilesetID)
        {
            File GFXFile          = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_NCG));
            File PalFile          = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_NCL));
            File Map16File        = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_PNL));
            File ObjFile          = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_UNT));
            File ObjIndexFile     = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_UNT_HD));
            File TileBehaviorFile = ROM.FS.getFileById(ROM.GetFileIDFromTable(TilesetID, ROM.Data.Table_TS_CHK));

            Tilesets[1] = new NSMBTileset(GFXFile, PalFile, Map16File, ObjFile, ObjIndexFile, TileBehaviorFile, false, 1);
            if (TilesetID == 1 || TilesetID == 39)
            {
                Tilesets[1].UseOverrides  = true;
                Tilesets[1].Overrides[29] = 149;
                Tilesets[1].Overrides[30] = 146;
                Tilesets[1].Overrides[31] = 155;
                Tilesets[1].Overrides[47] = 152;
                if (TilesetID == 1)
                {
                    Tilesets[1].Overrides[112] = 145;
                    Tilesets[1].Overrides[113] = 147;
                    Tilesets[1].Overrides[114] = 148;
                    Tilesets[1].Overrides[115] = 150;
                    Tilesets[1].Overrides[128] = 151;
                    Tilesets[1].Overrides[129] = 153;
                    Tilesets[1].Overrides[130] = 154;
                    Tilesets[1].Overrides[131] = 156;
                }
                else
                {
                    Tilesets[1].Overrides[128] = 145;
                    Tilesets[1].Overrides[129] = 147;
                    Tilesets[1].Overrides[130] = 148;
                    Tilesets[1].Overrides[131] = 150;
                    Tilesets[1].Overrides[144] = 151;
                    Tilesets[1].Overrides[145] = 153;
                    Tilesets[1].Overrides[146] = 154;
                    Tilesets[1].Overrides[147] = 156;
                }
            }
        }
예제 #10
0
 public void SetTileset(NSMBTileset t)
 {
 }
예제 #11
0
 public ObjectDefTile(NSMBTileset t)
 {
     this.t = t;
 }
예제 #12
0
 public ObjectDef(byte[] data, NSMBTileset t)
 {
     this.t = t;
     load(new ByteArrayInputStream(data));
 }
예제 #13
0
        public void LoadTilesets(ushort TilesetID, int JyotyuPalOverride)
        {
            Tilesets = new NSMBTileset[3];

            Console.WriteLine("JyotyuPalOverride = {0}, JyotyuPal offset = {1}...", JyotyuPalOverride, ROM.Overlay0[ROM.GetOffset(ROM.Data.Table_Jyotyu_NCL) + JyotyuPalOverride]);

            byte JyotyuPalID   = ROM.Overlay0[ROM.GetOffset(ROM.Data.Table_Jyotyu_NCL) + JyotyuPalOverride];
            File JyotyuPalFile = null;

            if (JyotyuPalID == 1)
            {
                JyotyuPalFile = ROM.FS.getFileByName("d_2d_A_J_jyotyu_B_ncl.bin");
            }
            else if (JyotyuPalID == 2)
            {
                JyotyuPalFile = ROM.FS.getFileByName("d_2d_A_J_jyotyu_R_ncl.bin");
            }
            else if (JyotyuPalID == 3)
            {
                JyotyuPalFile = ROM.FS.getFileByName("d_2d_A_J_jyotyu_W_ncl.bin");
            }
            else
            {
                JyotyuPalFile = ROM.FS.getFileByName("d_2d_A_J_jyotyu_ncl.bin");
            }

            Tilesets[0] = new NSMBTileset(
                ROM.FS.getFileByName("d_2d_A_J_jyotyu_ncg.bin"),
                JyotyuPalFile,
                ROM.FS.getFileByName("d_2d_PA_A_J_jyotyu.bin"),
                ROM.FS.getFileByName("A_J_jyotyu.bin"),
                ROM.FS.getFileByName("A_J_jyotyu_hd.bin"),
                null, true, 0);

            LoadTileset1(TilesetID);

            Tilesets[2] = new NSMBTileset(
                ROM.FS.getFileByName("d_2d_I_S_tikei_nohara_ncg.bin"),
                ROM.FS.getFileByName("d_2d_I_S_tikei_nohara_ncl.bin"),
                ROM.FS.getFileByName("d_2d_PA_I_S_nohara.bin"),
                ROM.FS.getFileByName("I_S_nohara.bin"),
                ROM.FS.getFileByName("I_S_nohara_hd.bin"),
                ROM.FS.getFileByName("NoHaRaSubUnitChangeData.bin"), false, 2);

            // Patch in a bunch of overrides to the normal tileset
            // Now works directly on the map16 data
            Tilesets[0].UseOverrides   = true;
            Tilesets[0].Overrides[1]   = 136;
            Tilesets[0].Overrides[2]   = 137;
            Tilesets[0].Overrides[3]   = 138;
            Tilesets[0].Overrides[4]   = 139;
            Tilesets[0].Overrides[5]   = 140;
            Tilesets[0].Overrides[6]   = 141;
            Tilesets[0].Overrides[7]   = 142;
            Tilesets[0].Overrides[8]   = 143;
            Tilesets[0].Overrides[36]  = 135;
            Tilesets[0].Overrides[112] = 26;
            Tilesets[0].Overrides[113] = 27;
            Tilesets[0].Overrides[114] = 53;
            Tilesets[0].Overrides[115] = 55;
            Tilesets[0].Overrides[116] = 28;
            Tilesets[0].Overrides[117] = 57;
            Tilesets[0].Overrides[118] = 144;
            Tilesets[0].Overrides[119] = 1;
            Tilesets[0].Overrides[120] = 4;
            Tilesets[0].Overrides[121] = 5;
            Tilesets[0].Overrides[122] = 30;
            Tilesets[0].Overrides[123] = 31;
            Tilesets[0].Overrides[124] = 8;
            Tilesets[0].Overrides[125] = 9;
            Tilesets[0].Overrides[126] = 20;
            Tilesets[0].Overrides[127] = 21;
            Tilesets[0].Overrides[128] = 24;
            Tilesets[0].Overrides[129] = 25;
            Tilesets[0].Overrides[132] = 29;
            Tilesets[0].Overrides[130] = 54;
            Tilesets[0].Overrides[131] = 56;
            Tilesets[0].Overrides[133] = 58;
            Tilesets[0].Overrides[134] = 2;
            Tilesets[0].Overrides[135] = 3;
            Tilesets[0].Overrides[136] = 6;
            Tilesets[0].Overrides[137] = 7;
            Tilesets[0].Overrides[138] = 12;
            Tilesets[0].Overrides[139] = 13;
            Tilesets[0].Overrides[140] = 10;
            Tilesets[0].Overrides[141] = 11;
            Tilesets[0].Overrides[142] = 22;
            Tilesets[0].Overrides[143] = 23;
            Tilesets[0].Overrides[145] = 32;
            Tilesets[0].Overrides[146] = 19;
            Tilesets[0].Overrides[147] = 17;
            Tilesets[0].Overrides[148] = 18;
            Tilesets[0].Overrides[149] = 14;
            Tilesets[0].Overrides[150] = 22;
            Tilesets[0].Overrides[151] = 23;
            Tilesets[0].Overrides[152] = 71;
            Tilesets[0].Overrides[153] = 72;
            Tilesets[0].Overrides[154] = 15;
            Tilesets[0].Overrides[155] = 16;
            Tilesets[0].Overrides[156] = 20;
            Tilesets[0].Overrides[157] = 21;
            Tilesets[0].Overrides[158] = 28;
            Tilesets[0].Overrides[159] = 29;
            Tilesets[0].Overrides[160] = 71;
            Tilesets[0].Overrides[161] = 72;
            Tilesets[0].Overrides[171] = 53;
            Tilesets[0].Overrides[172] = 57;
            Tilesets[0].Overrides[173] = 55;
            Tilesets[0].Overrides[174] = 26;
            Tilesets[0].Overrides[175] = 27;
            Tilesets[0].Overrides[187] = 54;
            Tilesets[0].Overrides[188] = 58;
            Tilesets[0].Overrides[189] = 56;
            Tilesets[0].Overrides[190] = 24;
            Tilesets[0].Overrides[191] = 25;
            Tilesets[0].Overrides[192] = 59;
            Tilesets[0].Overrides[193] = 63;
            Tilesets[0].Overrides[194] = 61;
            Tilesets[0].Overrides[195] = 65;
            Tilesets[0].Overrides[196] = 69;
            Tilesets[0].Overrides[197] = 67;
            Tilesets[0].Overrides[198] = 33;
            Tilesets[0].Overrides[199] = 34;
            Tilesets[0].Overrides[200] = 41;
            Tilesets[0].Overrides[201] = 42;
            Tilesets[0].Overrides[202] = 37;
            Tilesets[0].Overrides[203] = 38;
            Tilesets[0].Overrides[204] = 47;
            Tilesets[0].Overrides[205] = 48;
            Tilesets[0].Overrides[206] = 51;
            Tilesets[0].Overrides[207] = 52;
            Tilesets[0].Overrides[208] = 60;
            Tilesets[0].Overrides[209] = 64;
            Tilesets[0].Overrides[210] = 62;
            Tilesets[0].Overrides[211] = 66;
            Tilesets[0].Overrides[212] = 70;
            Tilesets[0].Overrides[213] = 68;
            Tilesets[0].Overrides[214] = 35;
            Tilesets[0].Overrides[215] = 36;
            Tilesets[0].Overrides[216] = 43;
            Tilesets[0].Overrides[217] = 44;
            Tilesets[0].Overrides[218] = 39;
            Tilesets[0].Overrides[219] = 40;
            Tilesets[0].Overrides[220] = 49;
            Tilesets[0].Overrides[221] = 50;
            Tilesets[0].Overrides[222] = 45;
            Tilesets[0].Overrides[223] = 46;
            Tilesets[0].Overrides[228] = 41;
            Tilesets[0].Overrides[229] = 42;
            Tilesets[0].Overrides[230] = 45;
            Tilesets[0].Overrides[231] = 65;
            Tilesets[0].Overrides[232] = 69;
            Tilesets[0].Overrides[233] = 67;
            Tilesets[0].Overrides[234] = 47;
            Tilesets[0].Overrides[235] = 48;
            Tilesets[0].Overrides[236] = 52;
            Tilesets[0].Overrides[237] = 59;
            Tilesets[0].Overrides[238] = 63;
            Tilesets[0].Overrides[239] = 61;
            Tilesets[0].Overrides[244] = 43;
            Tilesets[0].Overrides[245] = 44;
            Tilesets[0].Overrides[246] = 46;
            Tilesets[0].Overrides[247] = 66;
            Tilesets[0].Overrides[248] = 70;
            Tilesets[0].Overrides[249] = 68;
            Tilesets[0].Overrides[250] = 49;
            Tilesets[0].Overrides[251] = 50;
            Tilesets[0].Overrides[252] = 51;
            Tilesets[0].Overrides[253] = 60;
            Tilesets[0].Overrides[254] = 64;
            Tilesets[0].Overrides[255] = 62;
//            Tilesets[0].repaintAllMap16();

            RepatchBlocks(Properties.Settings.Default.SmallBlockOverlays);

            // Enable notes for the normal tileset
            Tilesets[0].UseNotes = true;
            if (ROM.UserInfo.descriptions.ContainsKey(65535))
            {
                Tilesets[0].ObjNotes = ROM.UserInfo.descriptions[65535].ToArray();
            }
            else
            {
                Tilesets[0].ObjNotes = GetDescriptions(LanguageManager.GetList("ObjNotes"));
            }
            if (ROM.UserInfo.descriptions.ContainsKey(TilesetID))
            {
                Tilesets[1].ObjNotes = ROM.UserInfo.descriptions[TilesetID].ToArray();;
                Tilesets[1].UseNotes = true;
            }
            if (ROM.UserInfo.descriptions.ContainsKey(65534))
            {
                Tilesets[2].ObjNotes = ROM.UserInfo.descriptions[65534].ToArray();
                Tilesets[2].UseNotes = true;
            }
        }
예제 #14
0
        public TilesetEditor(ushort TilesetID, string tilesetName)
        {
            InitializeComponent();
            if (Properties.Settings.Default.mdi)
            {
                this.MdiParent = MdiParentForm.instance;
            }
            LanguageManager.ApplyToContainer(this, "TilesetEditor");
            savePNG.Filter     = LanguageManager.Get("Filters", "png");
            openPNG.Filter     = LanguageManager.Get("Filters", "png");
            saveTileset.Filter = LanguageManager.Get("Filters", "tileset");
            openTileset.Filter = LanguageManager.Get("Filters", "tileset");

            Text = string.Format(LanguageManager.Get("TilesetEditor", "_TITLE"), tilesetName);

            g = new NSMBGraphics();

            this.TilesetID = TilesetID;
            if (TilesetID == 65535)
            {
                // load Jyotyu
                g.LoadTilesets(0);
                TilesetNumber = 0;
            }
            else if (TilesetID == 65534)
            {
                // load Nohara_sub
                g.LoadTilesets(2);
                TilesetNumber = 2;
            }
            else
            {
                // load a normal tileset
                g.LoadTilesets(TilesetID);
                TilesetNumber = 1;
            }

            t = g.Tilesets[TilesetNumber];
            t.beginEdit();

            objectPickerControl1.Initialise(g);
            objectPickerControl1.CurrentTileset = TilesetNumber;

            tilesetObjectEditor1.load(g, TilesetNumber);
            tilemapEditor1.load(t.map16);

            imageManager1.addImage(t.graphics);

            for (int i = 0; i < t.palettes.Length; i++)
            {
                imageManager1.addPalette(t.palettes[i]);
            }

            tileBehaviorPicker.init(new Bitmap[] { t.Map16Buffer }, 16);

            //FIXME
//            graphicsEditor1.SaveGraphics += new GraphicsEditor.SaveGraphicsHandler(graphicsEditor1_SaveGraphics);

            descExists = ROM.UserInfo.descriptions.ContainsKey(TilesetID); //Fild in there are descriptions for the tileset
            deleteDescriptions.Visible           = descExists;             //Make the appropriate button visible
            createDescriptions.Visible           = !descExists;
            tilesetObjectEditor1.descBox.Visible = descExists;             //Hide or show the description text box
            tilesetObjectEditor1.descLbl.Visible = descExists;
            if (descExists)
            {
                descriptions = ROM.UserInfo.descriptions[TilesetID]; //Get the descriptions
                tilesetObjectEditor1.descBox.Text = descriptions[0]; //Fill the description box with that of the first object
            }
            this.Icon = Properties.Resources.nsmbe;
        }
예제 #15
0
        private void importPNGButton_Click(object sender, EventArgs e)
        {
            getFiles();

            if (GFXFile == null)
            {
                return;
            }
            if (PalFile == null)
            {
                return;
            }
            if (LayoutFile == null)
            {
                return;
            }

            // Create a local copy because the global variables could be overwritten while the background is importing
            File myGFXFile    = GFXFile;
            File myPalFile    = PalFile;
            File myLayoutFile = LayoutFile;

            int offs    = bg.topLayer ? 256 : 576;
            int palOffs = bg.topLayer ? 8 : 10;

            if (bg.mappedTileset)
            {
                offs    = 192;
                palOffs = 2;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = LanguageManager.Get("Filters", "png");
            ofd.CheckFileExists = true;

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string filename = ofd.FileName;

            Bitmap b = new Bitmap(filename);

            if (b.Size != new Size(512, 512))
            {
                throw new Exception("Wrong image size");
            }

            BgPNGImportPrompt bgPrompt = new BgPNGImportPrompt(bg.topLayer, bg.mappedTileset);

            if (!bgPrompt.finished)
            {
                return;
            }

            ImageTiler ti;

            if (bg.topLayer)
            {
                bgPrompt.bgFirstTileOffset = 0;
                ti = new ImageTiler(b, new Size(256, bgPrompt.fgHeightInPixels), new Size(512, 512), 50);
            }
            else
            {
                ti = new ImageTiler(b, new Size(256, bgPrompt.bgHeightInPixels), new Size(512, 512), 50);
            }

            Color[] palette = ImageIndexer.createPaletteForImage(b);

            ByteArrayOutputStream oo = new ByteArrayOutputStream();

            for (int i = 0; i < palette.Length; i++)
            {
                oo.writeUShort(NSMBTileset.toRGB15(palette[i]));
            }

            ByteArrayOutputStream offsetBitmapData = new ByteArrayOutputStream();

            for (int i = 0; i < 256 * bgPrompt.bgFirstTileOffset; i++)
            {
                offsetBitmapData.writeByte(0);
            }

            //byte[] newBitmapData = ImageIndexer.indexImageWithPalette(ti.tileBuffer, palette);
            byte[] newBitmapData = new byte[offsetBitmapData.getArray().Length + ImageIndexer.indexImageWithPalette(ti.tileBuffer, palette).Length];
            Buffer.BlockCopy(offsetBitmapData.getArray(), 0, newBitmapData, 0, offsetBitmapData.getArray().Length);
            Buffer.BlockCopy(ImageIndexer.indexImageWithPalette(ti.tileBuffer, palette), 0, newBitmapData, offsetBitmapData.getArray().Length, ImageIndexer.indexImageWithPalette(ti.tileBuffer, palette).Length);

            myPalFile.beginEdit(this);
            myPalFile.replace(ROM.LZ77_Compress(oo.getArray()), this);
            myPalFile.endEdit(this);
            myGFXFile.beginEdit(this);
            myGFXFile.replace(ROM.LZ77_Compress(newBitmapData), this);
            myGFXFile.endEdit(this);
            b.Dispose();

            ByteArrayOutputStream layout = new ByteArrayOutputStream();

            for (int y = 0; y < ti.heightTileCount; y++)
            {
                for (int x = 0; x < ti.widthTileCount; x++)
                {
                    layout.writeUShort((ushort)((ti.tileMap[x, y] + offs + (bgPrompt.bgFirstTileOffset * 4)) | (palOffs << 12)));
                }
            }

            myLayoutFile.beginEdit(this);
            myLayoutFile.replace(ROM.LZ77_Compress(layout.getArray()), this);
            myLayoutFile.endEdit(this);
        }