示例#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
        private static Overlay[] loadOvTable(File table)
        {
            Overlay[] ovs = new Overlay[table.fileSize / 32];

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());

            int i = 0;

            while (tbl.lengthAvailable(32))
            {
                uint   ovId            = tbl.readUInt();
                uint   ramAddr         = tbl.readUInt();
                uint   ramSize         = tbl.readUInt();
                uint   bssSize         = tbl.readUInt();
                uint   staticInitStart = tbl.readUInt();
                uint   staticInitEnd   = tbl.readUInt();
                ushort fileID          = tbl.readUShort();
                tbl.skip(6); //unused 0's

                ovs[ovId] = new Overlay(FS.getFileById(fileID), table, (uint)i * 32);

                i++;
            }

            return(ovs);
        }
 public override void save(ExportedLevel level)
 {
     ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(strm);
     level.Write(bw);
     copyData(strm.getData());
 }
示例#4
0
        private void importClipboard_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show((LanguageManager.Get("LevelChooser", "replaceclipboard")), (LanguageManager.Get("LevelChooser", "replaceclipboardtitle")), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            try
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith("NSMBeLevel|") && leveltxt.EndsWith("|")))
                {
                    throw new Exception();
                }
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] levelfile          = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(levelfile);
                BinaryReader         br   = new BinaryReader(strm);

                string LevelFilename = (string)levelTreeView.SelectedNode.Tag;
                NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
                NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");
                new ExportedLevel(br).Import(LevelFile, BGFile);
                br.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
            }
        }
示例#5
0
        public override void save(ExportedLevel level)
        {
            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);

            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(strm);
            level.Write(bw);
            copyData(strm.getData());
        }
示例#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
        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);
        }
示例#8
0
        public static void load(Filesystem fs)
        {
            filename = fs.getRomPath();
            FS       = fs;
            if (fs is NitroROMFilesystem)
            {
                romfile = new System.IO.FileInfo(filename);
            }

            arm9binFile = FS.getFileByName("arm9.bin");
            arm9ovFile  = FS.getFileByName("arm9ovt.bin");
            arm9ovs     = loadOvTable(arm9ovFile);
            arm7binFile = FS.getFileByName("arm7.bin");
            arm7ovFile  = FS.getFileByName("arm7ovt.bin");
            arm7ovs     = loadOvTable(arm7ovFile);
            rsaSigFile  = FS.getFileByName("rsasig.bin");
            headerFile  = FS.getFileByName("header.bin");

            arm9RAMAddress = headerFile.getUintAt(0x28);

            ByteArrayInputStream header = new ByteArrayInputStream(headerFile.getContents());

            romInternalName = header.ReadString(12);
            romGamecode     = header.ReadString(4);

            if (romGamecode == "A2DE")
            {
                Region = Origin.US;
            }
            else if (romGamecode == "A2DP")
            {
                Region = Origin.EU;
            }
            else if (romGamecode == "A2DJ")
            {
                Region = Origin.JP;
            }
            else if (romGamecode == "A2DK")
            {
                Region = Origin.KR;
            }
            else
            {
                isNSMBRom = false;
                Region    = Origin.UNK;
            }

            if (isNSMBRom)
            {
                UserInfo = new ROMUserInfo(filename);
                LoadOverlay0();
            }
        }
示例#9
0
        public static NSMBView read(ByteArrayInputStream inp, ByteArrayInputStream cam)
        {
            NSMBView v = new NSMBView();

            v.X      = inp.readUShort();
            v.Y      = inp.readUShort();
            v.Width  = inp.readUShort();
            v.Height = inp.readUShort();
            v.Number = inp.readByte();
            int camID = inp.readByte();

            v.Music      = inp.readByte();
            v.Unknown1   = inp.readByte();
            v.Unknown2   = inp.readByte();
            v.Unknown3   = inp.readByte();
            v.Lighting   = inp.readByte();
            v.FlagpoleID = inp.readByte();

            cam.seek(0);
            int camCount = (int)cam.available / 24;
//            Console.Out.WriteLine("CamCount: " + camCount);
            int goodCam = -1;

            for (int i = 0; i < camCount; i++)
            {
                cam.seek(i * 24 + 16);
                int thisCam = cam.readUShort();
//                Console.Out.WriteLine("Cam ID: " + thisCam);
                if (thisCam == camID)
                {
                    goodCam = i;
                    break;
                }
            }

            if (goodCam == -1)
            {
                Console.Out.WriteLine("Warning: Could not find camera ID " + camID);
            }
            else
            {
                cam.seek(goodCam * 24);
                v.CameraTop        = cam.readInt();
                v.CameraBottom     = cam.readInt();
                v.CameraTopSpin    = cam.readInt();
                v.CameraBottomSpin = cam.readInt();
                cam.skip(2);
                v.CameraBottomStick = cam.readUShort();
            }
            return(v);
        }
示例#10
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            DSFileSystem.File LevelFile = ROM.getLevelFile(LevelFilename);
            DSFileSystem.File BGFile    = ROM.getBGDatFile(LevelFilename);

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter         bw   = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            ClipboardLevelSource.copyData(strm.getData());
            bw.Close();
        }
示例#11
0
        protected virtual void load()
        {
            height = (f.fileSize / 2 + width - 1) / width;
            tiles  = new Tile[width, height];

            ByteArrayInputStream b = new ByteArrayInputStream(f.getContents());

            for (int i = 0; i < f.fileSize / 2; i++)
            {
                int x = i % width;
                int y = i / width;
                tiles[x, y] = shortToTile(b.readUShort());
            }
        }
示例#12
0
        public static NSMBPathPoint read(ByteArrayInputStream inp, NSMBPath parent)
        {
            NSMBPathPoint p = new NSMBPathPoint(parent);

            p.X        = inp.readUShort();
            p.Y        = inp.readUShort();
            p.Unknown1 = inp.readUShort();
            p.Unknown2 = inp.readUShort();
            p.Unknown3 = inp.readUShort();
            p.Unknown4 = inp.readUShort();
            p.Unknown5 = inp.readUShort();
            p.Unknown6 = inp.readUShort();
            return(p);
        }
示例#13
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter         bw   = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            Clipboard.SetText("NSMBeLevel|" + Convert.ToBase64String(ROM.LZ77_Compress(strm.getData())) + "|");
            bw.Close();
        }
示例#14
0
        protected virtual void load()
        {
            height = (f.fileSize / 2 + width-1) /width;
            tiles = new Tile[width, height];

            ByteArrayInputStream b = new ByteArrayInputStream(f.getContents());

            for (int i = 0; i < f.fileSize / 2; i++)
            {
                int x = i % width;
                int y = i / width;
                tiles[x,y] = shortToTile(b.readUShort());
            }
        }
示例#15
0
        public static NSMBView readZone(ByteArrayInputStream inp)
        {
            NSMBView v = new NSMBView();

            v.X      = inp.readUShort();
            v.Y      = inp.readUShort();
            v.Width  = inp.readUShort();
            v.Height = inp.readUShort();
            v.Number = inp.readByte();
            v.isZone = true;
            inp.skip(3);

            return(v);
        }
示例#16
0
        public static NSMBPath read(ByteArrayInputStream inp, ByteArrayInputStream nodes, bool isProgressPath)
        {
            NSMBPath p = new NSMBPath();
            p.isProgressPath = isProgressPath;

            p.id = inp.readUShort();
            int row = inp.readUShort();
            int len = inp.readUShort();
            inp.skip(2); //unused values

            nodes.seek(row*16);
            for (int i = 0; i < len; i++)
                p.points.Add(NSMBPathPoint.read(nodes, p));
            return p;
        }
示例#17
0
        protected override void load()
        {
            height = (f.fileSize / 2 + width - 1) / width;
            tiles = new Tile[width, height];

            ByteArrayInputStream b = new ByteArrayInputStream(f.getContents());

            for (int i = 0; i < f.fileSize / 8; i++)
            {
                int x = (i % (width/2))*2;
                int y = (i / (width/2))*2;
                tiles[x, y] = shortToTile(b.readUShort());
                tiles[x+1, y] = shortToTile(b.readUShort());
                tiles[x, y+1] = shortToTile(b.readUShort());
                tiles[x+1, y+1] = shortToTile(b.readUShort());
            }
        }
示例#18
0
        protected override void load()
        {
            height = (f.fileSize / 2 + width - 1) / width;
            tiles  = new Tile[width, height];

            ByteArrayInputStream b = new ByteArrayInputStream(f.getContents());

            for (int i = 0; i < f.fileSize / 8; i++)
            {
                int x = (i % (width / 2)) * 2;
                int y = (i / (width / 2)) * 2;
                tiles[x, y]         = shortToTile(b.readUShort());
                tiles[x + 1, y]     = shortToTile(b.readUShort());
                tiles[x, y + 1]     = shortToTile(b.readUShort());
                tiles[x + 1, y + 1] = shortToTile(b.readUShort());
            }
        }
示例#19
0
        public override Bitmap render(Palette p)
        {
            int w = getWidth();
            int h = getHeight();

            Bitmap b = new Bitmap(w, h);

            ByteArrayInputStream f5data = new ByteArrayInputStream(f5.getContents());
            ByteArrayInputStream data = new ByteArrayInputStream(f.getContents());

            for (uint y = 0; y < h/4; y++)
                for (uint x = 0; x < w/4; x++)
                {
                    ushort palDat = f5data.readUShort();
                    ushort palOffs = (ushort)((palDat & 0x3FFF) * 2);
                    ushort mode = (ushort)((palDat >> 14) & 3);

                    for (uint yy = 0; yy < 4; yy++)
                    {
                        byte row = data.readByte();
                        for (uint xx = 0; xx < 4; xx++)
                        {
                            byte color = (byte)(row >> (byte)(xx * 2));
                            color &= 3;
                            Color col;
                            col = p.getColorSafe(palOffs + color);
                            switch (mode)
                            {
                                case 0:
                                    if (color == 3) col = Color.Transparent;
                                    break;
                                case 1:
                                    if (color == 2) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 1, 1);
                                    if (color == 3) col = Color.Transparent;
                                    break;
                                case 3:
                                    if (color == 2) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 5, 3);
                                    if (color == 3) col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 3, 5);
                                    break;
                            }
                            b.SetPixel((int)x * 4 + (int)xx, (int)y * 4 + (int)yy, col);
                        }
                    }
                } 
            return b;
        }
示例#20
0
        public static NSMBPath read(ByteArrayInputStream inp, ByteArrayInputStream nodes, bool isProgressPath)
        {
            NSMBPath p = new NSMBPath();

            p.isProgressPath = isProgressPath;

            p.id = inp.readUShort();
            int row = inp.readUShort();
            int len = inp.readUShort();

            inp.skip(2); //unused values

            nodes.seek(row * 16);
            for (int i = 0; i < len; i++)
            {
                p.points.Add(NSMBPathPoint.read(nodes, p));
            }
            return(p);
        }
 public ClipboardLevelSource(string loadFileName)
 {
     BinaryReader br;
     if (loadFileName == "")
     {
         string leveltxt = Clipboard.GetText();
         if (!(leveltxt.StartsWith(clipboardHeader) && leveltxt.EndsWith(clipboardFooter)))
             throw new Exception();
         leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
         byte[] leveldata = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
         ByteArrayInputStream strm = new ByteArrayInputStream(leveldata);
         br = new BinaryReader(strm);
     }
     else
     {
         FileStream fs = new FileStream(loadFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         br = new BinaryReader(fs);
     }
     level = new ExportedLevel(br);
     br.Close();
 }
示例#22
0
        public void loadObjects()
        {
            ByteArrayInputStream eObjIndexFile = new ByteArrayInputStream(ObjIndexFile.getContents());
            ByteArrayInputStream eObjFile      = new ByteArrayInputStream(ObjFile.getContents());

            Objects = new ObjectDef[objectCount];

            //read object index
            int obj = 0;

            while (eObjIndexFile.lengthAvailable(4) && obj < Objects.Length)
            {
                Objects[obj] = new ObjectDef(this);
                int offset = eObjIndexFile.readUShort();
                Objects[obj].width  = eObjIndexFile.readByte();
                Objects[obj].height = eObjIndexFile.readByte();

                eObjFile.seek(offset);
                Objects[obj].load(eObjFile);
                obj++;
            }
        }
示例#23
0
        public void Save()
        {
            ExportedLevel exlvl = getExport();

            if (isClipboard)
            {
                ByteArrayInputStream   strm = new ByteArrayInputStream(new byte[0]);
                System.IO.BinaryWriter bw   = new System.IO.BinaryWriter(strm);
                exlvl.Write(bw);
                Clipboard.SetText("NSMBeLevel|" + Convert.ToBase64String(ROM.LZ77_Compress(strm.getData())) + "|");
            }
            else if (isExported)
            {
                System.IO.FileStream   fs = new System.IO.FileStream(ExportedFileName, System.IO.FileMode.Create);
                System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
                exlvl.Write(bw);
            }
            else
            {
                LevelFile.replace(exlvl.LevelFile, this);
                BGFile.replace(exlvl.BGFile, this);
            }
        }
示例#24
0
            public void load(ByteArrayInputStream inp)
            {
                tiles = new List <List <ObjectDefTile> >();
                List <ObjectDefTile> row = new List <ObjectDefTile>();

                while (true)
                {
                    ObjectDefTile t = new ObjectDefTile(inp, this.t);
                    if (t.lineBreak)
                    {
                        tiles.Add(row);
                        row = new List <ObjectDefTile>();
                    }
                    else if (t.objectEnd)
                    {
                        break;
                    }
                    else
                    {
                        row.Add(t);
                    }
                }
            }
示例#25
0
        private void loadTileBehaviors()
        {
            byte[] x = null;

            if (TilesetNumber == 0)
            {
                x = ROM.GetInlineFile(ROM.Data.File_Jyotyu_CHK);
            }
            else if (TilesetNumber == 1 || TilesetNumber == 2)
            {
                x = TileBehaviorFile.getContents();
            }

            ByteArrayInputStream inp = new ByteArrayInputStream(x);

            int len = inp.available / 4;

            TileBehaviors = new uint[len];

            for (int i = 0; i < len; i++)
            {
                TileBehaviors[i] = inp.readUInt();
            }
        }
示例#26
0
        private void openClipboard_Click(object sender, EventArgs e)
        {
            try
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith("NSMBeLevel|") && leveltxt.EndsWith("|")))
                {
                    throw new Exception();
                }
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] leveldata          = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(leveldata);
                BinaryReader         br   = new BinaryReader(strm);

                ExportedLevel exlvl     = new ExportedLevel(br);
                LevelEditor   newEditor = new LevelEditor("", "", exlvl.LevelFile, exlvl.BGFile, exlvl.LevelFileID, exlvl.BGFileID);
                newEditor.Show();
                br.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
            }
        }
示例#27
0
        public ClipboardLevelSource(string loadFileName)
        {
            BinaryReader br;

            if (loadFileName == "")
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith(clipboardHeader) && leveltxt.EndsWith(clipboardFooter)))
                {
                    throw new Exception();
                }
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] leveldata          = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(leveldata);
                br = new BinaryReader(strm);
            }
            else
            {
                FileStream fs = new FileStream(loadFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                br = new BinaryReader(fs);
            }
            level = new ExportedLevel(br);
            br.Close();
        }
示例#28
0
        private void LoadLevel(File levelFile, File bgFile, byte[] eLevelFile, byte[] eBGFile, NSMBGraphics GFX)
        {
            this.LevelFile = levelFile;
            this.BGFile = bgFile;
            this.GFX = GFX;

            int FilePos;

            for(int x = 0; x < 512; x++)
                for (int y = 0; y < 256; y++)
                {
                    levelTilemap[x,y] = (x + y) % 512;
                }

            // Level loading time yay.
            // Since I don't know the format for every block, I will just load them raw.
            Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            FilePos = 0;
            for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++) {
                int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;
                int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;

                Blocks[BlockIdx] = new byte[BlockSize];
                Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize);
            }

            // Now objects.

            int ObjectCount = eBGFile.Length / 10;
            Objects = new List<NSMBObject>(ObjectCount);
            FilePos = 0;
            for (int ObjectIdx = 0; ObjectIdx < ObjectCount; ObjectIdx++) {
                int ObjID = eBGFile[FilePos] | (eBGFile[FilePos + 1] << 8);
                int ObjX = eBGFile[FilePos + 2] | (eBGFile[FilePos + 3] << 8);
                int ObjY = eBGFile[FilePos + 4] | (eBGFile[FilePos + 5] << 8);
                int ObjWidth = eBGFile[FilePos + 6] | (eBGFile[FilePos + 7] << 8);
                int ObjHeight = eBGFile[FilePos + 8] | (eBGFile[FilePos + 9] << 8);
                Objects.Add(new NSMBObject(ObjID & 4095, (ObjID & 61440) >> 12, ObjX, ObjY, ObjWidth, ObjHeight, GFX));
                FilePos += 10;
            }

            /*
             * Sprite struct:
             * Offs Len Dat
             * 0x0   2   Sprite id
             * 0x2   2   X
             * 0x4   2   Y
             * 0x6   6   Dat
             * 0xD   end
             */

            // Sprites
            byte[] SpriteBlock = Blocks[6];
            int SpriteCount = (SpriteBlock.Length - 2) / 12;
            Sprites = new List<NSMBSprite>(SpriteCount);
            FilePos = 0;
            for (int SpriteIdx = 0; SpriteIdx < SpriteCount; SpriteIdx++) {
                NSMBSprite Sprite = new NSMBSprite(this);
                Sprite.Type = SpriteBlock[FilePos] | (SpriteBlock[FilePos + 1] << 8);
                Sprite.X = SpriteBlock[FilePos + 2] | (SpriteBlock[FilePos + 3] << 8);
                Sprite.Y = SpriteBlock[FilePos + 4] | (SpriteBlock[FilePos + 5] << 8);
                Sprite.Data = new byte[6];
                FilePos += 6;
                Sprite.Data[0] = SpriteBlock[FilePos + 1];
                Sprite.Data[1] = SpriteBlock[FilePos + 0];
                Sprite.Data[2] = SpriteBlock[FilePos + 5];
                Sprite.Data[3] = SpriteBlock[FilePos + 4];
                Sprite.Data[4] = SpriteBlock[FilePos + 3];
                Sprite.Data[5] = SpriteBlock[FilePos + 2];
            //                Array.Copy(SpriteBlock, FilePos + 6, Sprite.Data, 0, 6);
                Sprites.Add(Sprite);
                FilePos += 6;
            }

            // Entrances.
            byte[] EntranceBlock = Blocks[5];
            int EntranceCount = EntranceBlock.Length / 20;
            Entrances = new List<NSMBEntrance>(EntranceCount);
            FilePos = 0;
            for (int EntIdx = 0; EntIdx < EntranceCount; EntIdx++) {
                NSMBEntrance Entrance = new NSMBEntrance();
                Entrance.X = EntranceBlock[FilePos] | (EntranceBlock[FilePos + 1] << 8);
                Entrance.Y = EntranceBlock[FilePos + 2] | (EntranceBlock[FilePos + 3] << 8);
                Entrance.CameraX = EntranceBlock[FilePos + 4] | (EntranceBlock[FilePos + 5] << 8);
                Entrance.CameraY = EntranceBlock[FilePos + 6] | (EntranceBlock[FilePos + 7] << 8);
                Entrance.Number = EntranceBlock[FilePos + 8];
                Entrance.DestArea = EntranceBlock[FilePos + 9];
                Entrance.ConnectedPipeID = EntranceBlock[FilePos + 10];
                Entrance.DestEntrance = EntranceBlock[FilePos + 12];
                Entrance.Type = EntranceBlock[FilePos + 14];
                Entrance.Settings = EntranceBlock[FilePos + 15];
                Entrance.Unknown1 = EntranceBlock[FilePos + 16];
                Entrance.EntryView = EntranceBlock[FilePos + 18];
                Entrance.Unknown2 = EntranceBlock[FilePos + 19];
                //Array.Copy(EntranceBlock, FilePos, Entrance.Data, 0, 20);
                Entrances.Add(Entrance);
                FilePos += 20;
            }

            // Views
            ByteArrayInputStream ViewBlock = new ByteArrayInputStream(Blocks[7]);
            ByteArrayInputStream CamBlock = new ByteArrayInputStream(Blocks[1]);
            Views = new List<NSMBView>();
            while (ViewBlock.lengthAvailable(16))
                Views.Add(NSMBView.read(ViewBlock, CamBlock));

            // Zones
            ByteArrayInputStream ZoneBlock = new ByteArrayInputStream(Blocks[8]);
            Zones = new List<NSMBView>();
            while (ZoneBlock.lengthAvailable(12))
                Zones.Add(NSMBView.readZone(ZoneBlock));

            // Paths

            ByteArrayInputStream PathBlock = new ByteArrayInputStream(Blocks[10]);
            ByteArrayInputStream PathNodeBlock = new ByteArrayInputStream(Blocks[12]);

            Paths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                Paths.Add(NSMBPath.read(PathBlock, PathNodeBlock, false));
            }

            PathBlock = new ByteArrayInputStream(Blocks[9]);
            PathNodeBlock = new ByteArrayInputStream(Blocks[11]);

            ProgressPaths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                ProgressPaths.Add(NSMBPath.read(PathBlock, PathNodeBlock, true));
            }

            CalculateSpriteModifiers();
            repaintAllTilemap();
        }
示例#29
0
        private void LoadLevel(byte[] eLevelFile, byte[] eBGFile, NSMBGraphics GFX)
        {
            this.GFX = GFX;

            int FilePos;

            for (int x = 0; x < 512; x++)
            {
                for (int y = 0; y < 256; y++)
                {
                    levelTilemap[x, y] = (x + y) % 512;
                }
            }

            // Level loading time yay.
            // Since I don't know the format for every block, I will just load them raw.
            Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            FilePos = 0;
            for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++)
            {
                int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;
                int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;

                Blocks[BlockIdx] = new byte[BlockSize];
                Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize);
            }

            // Now objects.

            int ObjectCount = eBGFile.Length / 10;

            Objects = new List <NSMBObject>(ObjectCount);
            FilePos = 0;
            for (int ObjectIdx = 0; ObjectIdx < ObjectCount; ObjectIdx++)
            {
                int ObjID     = eBGFile[FilePos] | (eBGFile[FilePos + 1] << 8);
                int ObjX      = eBGFile[FilePos + 2] | (eBGFile[FilePos + 3] << 8);
                int ObjY      = eBGFile[FilePos + 4] | (eBGFile[FilePos + 5] << 8);
                int ObjWidth  = eBGFile[FilePos + 6] | (eBGFile[FilePos + 7] << 8);
                int ObjHeight = eBGFile[FilePos + 8] | (eBGFile[FilePos + 9] << 8);
                Objects.Add(new NSMBObject(ObjID & 4095, (ObjID & 61440) >> 12, ObjX, ObjY, ObjWidth, ObjHeight, GFX));
                FilePos += 10;
            }

            /*
             * Sprite struct:
             * Offs Len Dat
             * 0x0   2   Sprite id
             * 0x2   2   X
             * 0x4   2   Y
             * 0x6   6   Dat
             * 0xD   end
             */

            // Sprites
            byte[] SpriteBlock = Blocks[6];
            int    SpriteCount = (SpriteBlock.Length - 2) / 12;

            Sprites = new List <NSMBSprite>(SpriteCount);
            FilePos = 0;
            for (int SpriteIdx = 0; SpriteIdx < SpriteCount; SpriteIdx++)
            {
                NSMBSprite Sprite = new NSMBSprite(this);
                Sprite.Type    = SpriteBlock[FilePos] | (SpriteBlock[FilePos + 1] << 8);
                Sprite.X       = SpriteBlock[FilePos + 2] | (SpriteBlock[FilePos + 3] << 8);
                Sprite.Y       = SpriteBlock[FilePos + 4] | (SpriteBlock[FilePos + 5] << 8);
                Sprite.Data    = new byte[6];
                FilePos       += 6;
                Sprite.Data[0] = SpriteBlock[FilePos + 1];
                Sprite.Data[1] = SpriteBlock[FilePos + 0];
                Sprite.Data[2] = SpriteBlock[FilePos + 5];
                Sprite.Data[3] = SpriteBlock[FilePos + 4];
                Sprite.Data[4] = SpriteBlock[FilePos + 3];
                Sprite.Data[5] = SpriteBlock[FilePos + 2];
//                Array.Copy(SpriteBlock, FilePos + 6, Sprite.Data, 0, 6);
                Sprites.Add(Sprite);
                FilePos += 6;
            }

            // Entrances.
            byte[] EntranceBlock = Blocks[5];
            int    EntranceCount = EntranceBlock.Length / 20;

            Entrances = new List <NSMBEntrance>(EntranceCount);
            FilePos   = 0;
            for (int EntIdx = 0; EntIdx < EntranceCount; EntIdx++)
            {
                NSMBEntrance Entrance = new NSMBEntrance();
                Entrance.X               = EntranceBlock[FilePos] | (EntranceBlock[FilePos + 1] << 8);
                Entrance.Y               = EntranceBlock[FilePos + 2] | (EntranceBlock[FilePos + 3] << 8);
                Entrance.CameraX         = EntranceBlock[FilePos + 4] | (EntranceBlock[FilePos + 5] << 8);
                Entrance.CameraY         = EntranceBlock[FilePos + 6] | (EntranceBlock[FilePos + 7] << 8);
                Entrance.Number          = EntranceBlock[FilePos + 8];
                Entrance.DestArea        = EntranceBlock[FilePos + 9];
                Entrance.ConnectedPipeID = EntranceBlock[FilePos + 10];
                Entrance.DestEntrance    = EntranceBlock[FilePos + 12];
                Entrance.Type            = EntranceBlock[FilePos + 14];
                Entrance.Settings        = EntranceBlock[FilePos + 15];
                Entrance.Unknown1        = EntranceBlock[FilePos + 16];
                Entrance.EntryView       = EntranceBlock[FilePos + 18];
                Entrance.Unknown2        = EntranceBlock[FilePos + 19];
                //Array.Copy(EntranceBlock, FilePos, Entrance.Data, 0, 20);
                Entrances.Add(Entrance);
                FilePos += 20;
            }

            // Views
            ByteArrayInputStream ViewBlock = new ByteArrayInputStream(Blocks[7]);
            ByteArrayInputStream CamBlock  = new ByteArrayInputStream(Blocks[1]);

            Views = new List <NSMBView>();
            while (ViewBlock.lengthAvailable(16))
            {
                Views.Add(NSMBView.read(ViewBlock, CamBlock));
            }

            // Zones
            ByteArrayInputStream ZoneBlock = new ByteArrayInputStream(Blocks[8]);

            Zones = new List <NSMBView>();
            while (ZoneBlock.lengthAvailable(12))
            {
                Zones.Add(NSMBView.readZone(ZoneBlock));
            }

            // Paths

            ByteArrayInputStream PathBlock     = new ByteArrayInputStream(Blocks[10]);
            ByteArrayInputStream PathNodeBlock = new ByteArrayInputStream(Blocks[12]);

            Paths = new List <NSMBPath>();
            while (!PathBlock.end())
            {
                Paths.Add(NSMBPath.read(PathBlock, PathNodeBlock, false));
            }

            PathBlock     = new ByteArrayInputStream(Blocks[9]);
            PathNodeBlock = new ByteArrayInputStream(Blocks[11]);

            ProgressPaths = new List <NSMBPath>();
            while (!PathBlock.end())
            {
                ProgressPaths.Add(NSMBPath.read(PathBlock, PathNodeBlock, true));
            }


            CalculateSpriteModifiers();
            repaintAllTilemap();
        }
示例#30
0
        public static NSMBView read(ByteArrayInputStream inp, ByteArrayInputStream cam)
        {
            NSMBView v = new NSMBView();

            v.X = inp.readUShort();
            v.Y = inp.readUShort();
            v.Width = inp.readUShort();
            v.Height = inp.readUShort();
            v.Number = inp.readByte();
            int camID = inp.readByte();
            v.Music = inp.readByte();
            v.Unknown1 = inp.readByte();
            v.Unknown2 = inp.readByte();
            v.Unknown3 = inp.readByte();
            v.Lighting = inp.readByte();
            v.FlagpoleID = inp.readByte();

            cam.seek(0);
            int camCount = (int)cam.available / 24;
//            Console.Out.WriteLine("CamCount: " + camCount);
            int goodCam = -1;
            for (int i = 0; i < camCount; i++)
            {
                cam.seek(i * 24 + 16);
                int thisCam = cam.readUShort();
//                Console.Out.WriteLine("Cam ID: " + thisCam);
                if (thisCam == camID)
                {
                    goodCam = i;
                    break;
                }
            }

            if (goodCam == -1)
                Console.Out.WriteLine("Warning: Could not find camera ID " + camID);
            else
            {
                cam.seek(goodCam * 24);
                v.CameraTop = cam.readInt();
                v.CameraBottom = cam.readInt();
                v.CameraTopSpin = cam.readInt();
                v.CameraBottomSpin = cam.readInt();
                cam.skip(2);
                v.CameraBottomStick = cam.readUShort();
            }
            return v;
        }
示例#31
0
        ushort unk;         //Let's save it just in case.

        public Bncd(File f)
        {
            ByteArrayInputStream inp = new ByteArrayInputStream(f.getContents());

            inp.readInt();     //Magic;
            unk = inp.readUShort();
            ushort entryCount       = inp.readUShort();
            uint   entriesOffset    = inp.readUInt();
            uint   subEntriesOffset = inp.readUInt();
            uint   dataOffset       = inp.readUInt();
            uint   dataSize         = inp.readUInt();

            inp.seek(entriesOffset);

            //Stores tilenum, tilecount to imageid
            Dictionary <uint, int> imagesDict = new Dictionary <uint, int> ();

            for (uint entryId = 0; entryId < entryCount; entryId++)
            {
                BncdEntry e = new BncdEntry();
                e.width  = inp.readByte();
                e.height = inp.readByte();

                uint subEntryIdx = inp.readUShort();
                uint subEntryCt  = inp.readUShort();

                inp.savePos();
                inp.seek(subEntriesOffset + subEntryIdx * 12);
                for (int i = 0; i < subEntryCt; i++)
                {
                    BncdSubEntry se = new BncdSubEntry();
                    e.subEntries.Add(se);

                    se.oamAttr0   = inp.readUShort();
                    se.oamAttr1   = inp.readUShort();
                    se.unk        = inp.readUInt();
                    se.tileNumber = inp.readUShort();
                    se.tileCount  = inp.readUShort();

                    uint imageCode = (uint)((se.tileNumber << 16) | se.tileCount);
                    int  imageId   = imagesDict.Count;
                    if (imagesDict.ContainsKey(imageCode))
                    {
                        imageId = imagesDict[imageCode];
                    }
                    else
                    {
                        imagesDict[imageCode] = imageId;
                        BncdImage img = new BncdImage();
                        images.Add(img);
                        img.tileNumber = se.tileNumber;
                        img.tileCount  = se.tileCount;

                        int oamShape = se.oamAttr0 >> 14;
                        int oamSize  = se.oamAttr1 >> 14;

                        img.tileWidth = widths[oamSize, oamShape];
                    }

                    se.imageId = imageId;
                }
                inp.loadPos();
            }

            LevelChooser.showImgMgr();
            int tileLen = 8 * 8 / 2;

            foreach (BncdImage img in images)
            {
                File imgFile = new InlineFile(f, (int)dataOffset + img.tileNumber * tileLen, img.tileCount * tileLen, f.name);
                LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8 * img.tileWidth, true, false));
            }
        }
示例#32
0
            public void load(ByteArrayInputStream inp)
            {
                tiles = new List<List<ObjectDefTile>>();
                List<ObjectDefTile> row = new List<ObjectDefTile>();

                while (true)
                {
                    ObjectDefTile t = new ObjectDefTile(inp, this.t);
                    if (t.lineBreak)
                    {
                        tiles.Add(row);
                        row = new List<ObjectDefTile>();
                    }
                    else if (t.objectEnd)
                        break;
                    else
                        row.Add(t);
                }
            }
示例#33
0
 public static NSMBPathPoint read(ByteArrayInputStream inp, NSMBPath parent)
 {
     NSMBPathPoint p = new NSMBPathPoint(parent);
     p.X = inp.readUShort();
     p.Y = inp.readUShort();
     p.Unknown1 = inp.readUShort();
     p.Unknown2 = inp.readUShort();
     p.Unknown3 = inp.readUShort();
     p.Unknown4 = inp.readUShort();
     p.Unknown5 = inp.readUShort();
     p.Unknown6 = inp.readUShort();
     return p;
 }
示例#34
0
        public override Bitmap render(Palette p)
        {
            int w = getWidth();
            int h = getHeight();

            Bitmap b = new Bitmap(w, h);

            ByteArrayInputStream f5data = new ByteArrayInputStream(f5.getContents());
            ByteArrayInputStream data   = new ByteArrayInputStream(f.getContents());

            for (uint y = 0; y < h / 4; y++)
            {
                for (uint x = 0; x < w / 4; x++)
                {
                    ushort palDat  = f5data.readUShort();
                    ushort palOffs = (ushort)((palDat & 0x3FFF) * 2);
                    ushort mode    = (ushort)((palDat >> 14) & 3);

                    for (uint yy = 0; yy < 4; yy++)
                    {
                        byte row = data.readByte();
                        for (uint xx = 0; xx < 4; xx++)
                        {
                            byte color = (byte)(row >> (byte)(xx * 2));
                            color &= 3;
                            Color col;
                            col = p.getColorSafe(palOffs + color);
                            switch (mode)
                            {
                            case 0:
                                if (color == 3)
                                {
                                    col = Color.Transparent;
                                }
                                break;

                            case 1:
                                if (color == 2)
                                {
                                    col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 1, 1);
                                }
                                if (color == 3)
                                {
                                    col = Color.Transparent;
                                }
                                break;

                            case 3:
                                if (color == 2)
                                {
                                    col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 5, 3);
                                }
                                if (color == 3)
                                {
                                    col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 3, 5);
                                }
                                break;
                            }
                            b.SetPixel((int)x * 4 + (int)xx, (int)y * 4 + (int)yy, col);
                        }
                    }
                }
            }
            return(b);
        }
示例#35
0
        private void importClipboard_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show((LanguageManager.Get("LevelChooser", "replaceclipboard")), (LanguageManager.Get("LevelChooser", "replaceclipboardtitle")), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                return;
            try
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith("NSMBeLevel|") && leveltxt.EndsWith("|")))
                    throw new Exception();
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] levelfile = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(levelfile);
                BinaryReader br = new BinaryReader(strm);

                string LevelFilename = (string)levelTreeView.SelectedNode.Tag;
                NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
                NSMBe4.DSFileSystem.File BGFile = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");
                new ExportedLevel(br).Import(LevelFile, BGFile);
                br.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
            }
        }
示例#36
0
文件: ROM.cs 项目: MCGlux/NSMB-Editor
        private static Overlay[] loadOvTable(File table)
        {
            Overlay[] ovs = new Overlay[table.fileSize/32];

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());

            int i = 0;
            while (tbl.lengthAvailable(32))
            {
                uint ovId = tbl.readUInt();
                uint ramAddr = tbl.readUInt();
                uint ramSize = tbl.readUInt();
                uint bssSize = tbl.readUInt();
                uint staticInitStart = tbl.readUInt();
                uint staticInitEnd = tbl.readUInt();
                ushort fileID = tbl.readUShort();
                tbl.skip(6); //unused 0's

                ovs[ovId] = new Overlay(FS.getFileById(fileID), table, (uint)i*32);

                i++;
            }

            return ovs;
        }
示例#37
0
        public void loadObjects()
        {
            ByteArrayInputStream eObjIndexFile = new ByteArrayInputStream(ObjIndexFile.getContents());
            ByteArrayInputStream eObjFile = new ByteArrayInputStream(ObjFile.getContents());

            Objects = new ObjectDef[objectCount];

            //read object index
            int obj = 0;
            while (eObjIndexFile.lengthAvailable(4) && obj < Objects.Length)
            {
                Objects[obj] = new ObjectDef(this);
                int offset = eObjIndexFile.readUShort();
                Objects[obj].width = eObjIndexFile.readByte();
                Objects[obj].height = eObjIndexFile.readByte();

                eObjFile.seek(offset);
                Objects[obj].load(eObjFile);
                obj++;
            }
        }
示例#38
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;
            DSFileSystem.File LevelFile = ROM.getLevelFile(LevelFilename);
            DSFileSystem.File BGFile = ROM.getBGDatFile(LevelFilename);

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter bw = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            ClipboardLevelSource.copyData(strm.getData());
            bw.Close();
        }
示例#39
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;
                }
            }
示例#40
0
   		ushort unk; //Let's save it just in case.
   		
    	public Bncd(File f)
    	{
    		ByteArrayInputStream inp = new ByteArrayInputStream(f.getContents());
    		inp.readInt(); //Magic;
    		unk = inp.readUShort();
    		ushort entryCount = inp.readUShort();
    		uint entriesOffset = inp.readUInt();
    		uint subEntriesOffset = inp.readUInt();
    		uint dataOffset = inp.readUInt();
    		uint dataSize = inp.readUInt();
    		
    		inp.seek(entriesOffset);
    		
    		//Stores tilenum, tilecount to imageid
    		Dictionary<uint, int> imagesDict = new Dictionary<uint, int> ();
    		
    		for(uint entryId = 0; entryId < entryCount; entryId++)
    		{
    			BncdEntry e = new BncdEntry();
    			e.width = inp.readByte();
    			e.height = inp.readByte();
    			
    			uint subEntryIdx = inp.readUShort();
    			uint subEntryCt = inp.readUShort();
    			
    			inp.savePos();
    			inp.seek(subEntriesOffset + subEntryIdx*12);
    			for(int i = 0; i < subEntryCt; i++)
    			{
    				BncdSubEntry se = new BncdSubEntry();
    				e.subEntries.Add(se);
    				
    				se.oamAttr0 = inp.readUShort();
    				se.oamAttr1 = inp.readUShort();
    				se.unk = inp.readUInt();
    				se.tileNumber = inp.readUShort();
    				se.tileCount = inp.readUShort();
    				
    				uint imageCode = (uint) ((se.tileNumber << 16) | se.tileCount);
    				int imageId = imagesDict.Count;
    				if(imagesDict.ContainsKey(imageCode))
    					imageId = imagesDict[imageCode];
    				else
    				{
    					imagesDict[imageCode] = imageId;
				    	BncdImage img = new BncdImage();
				    	images.Add(img);
				    	img.tileNumber = se.tileNumber;
				    	img.tileCount = se.tileCount;

				    	int oamShape = se.oamAttr0>>14;
				    	int oamSize = se.oamAttr1>>14;

				    	img.tileWidth = widths[oamSize, oamShape];
					}
					    				
    				se.imageId = imageId;
    			}
    			inp.loadPos();
    		}
    		
            LevelChooser.showImgMgr();
			int tileLen = 8*8/2;
			foreach(BncdImage img in images)
			{
		        File imgFile = new InlineFile(f, (int)dataOffset+img.tileNumber*tileLen, img.tileCount*tileLen, f.name);
		        LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8*img.tileWidth, true, false));
			}
    	}
示例#41
0
        public static NSMBView readZone(ByteArrayInputStream inp)
        {
            NSMBView v = new NSMBView();

            v.X = inp.readUShort();
            v.Y = inp.readUShort();
            v.Width = inp.readUShort();
            v.Height = inp.readUShort();
            v.Number = inp.readByte();
            v.isZone = true;
            inp.skip(3);

            return v;
        }
示例#42
0
文件: ROM.cs 项目: Fr33ze/NSMB-Editor
        public static void load(String filename)
        {
            ROM.filename = filename;
            FS = new NitroROMFilesystem(filename);
            romfile = new System.IO.FileInfo(filename);

            ByteArrayInputStream header = new ByteArrayInputStream(FS.headerFile.getContents());
            romInternalName = header.ReadString(12);
            romGamecode = header.ReadString(4);

            if (romGamecode == "A2DE")
                Region = Origin.US;
            else if (romGamecode == "A2DP")
                Region = Origin.EU;
            else if (romGamecode == "A2DJ")
                Region = Origin.JP;
            else if (romGamecode == "A2DK")
                Region = Origin.KR;
            else
            {
                isNSMBRom = false;
                Region = Origin.UNK;
            }

            if (isNSMBRom)
            {
                UserInfo = new ROMUserInfo(filename);
                LoadOverlay0();
            }
        }
示例#43
0
 public void Save()
 {
     ExportedLevel exlvl = getExport();
     if (isClipboard)
     {
         ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
         System.IO.BinaryWriter bw = new System.IO.BinaryWriter(strm);
         exlvl.Write(bw);
         Clipboard.SetText("NSMBeLevel|" + Convert.ToBase64String(ROM.LZ77_Compress(strm.getData())) + "|");
     }
     else if (isExported)
     {
         System.IO.FileStream fs = new System.IO.FileStream(ExportedFileName, System.IO.FileMode.Create);
         System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
         exlvl.Write(bw);
     }
     else
     {
         LevelFile.replace(exlvl.LevelFile, this);
         BGFile.replace(exlvl.BGFile, this);
     }
 }
示例#44
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;
            NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            NSMBe4.DSFileSystem.File BGFile = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter bw = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            Clipboard.SetText("NSMBeLevel|" + Convert.ToBase64String(ROM.LZ77_Compress(strm.getData())) + "|");
            bw.Close();
        }
示例#45
0
        private void loadTileBehaviors()
        {
            byte[] x = null;

            if (TilesetNumber == 0)
                x = ROM.GetInlineFile(ROM.Data.File_Jyotyu_CHK);
            else if (TilesetNumber == 1 || TilesetNumber == 2)
                x = TileBehaviorFile.getContents();

            ByteArrayInputStream inp = new ByteArrayInputStream(x);

            int len = inp.available / 4;
            TileBehaviors = new int[len];

            for (int i = 0; i < len; i++)
                TileBehaviors[i] = inp.readInt();
        }
示例#46
0
        private void openClipboard_Click(object sender, EventArgs e)
        {
            try
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith("NSMBeLevel|") && leveltxt.EndsWith("|")))
                    throw new Exception();
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] leveldata = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(leveldata);
                BinaryReader br = new BinaryReader(strm);

                ExportedLevel exlvl = new ExportedLevel(br);
                LevelEditor newEditor = new LevelEditor("", "", exlvl.LevelFile, exlvl.BGFile, exlvl.LevelFileID, exlvl.BGFileID);
                newEditor.Show();
                br.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
            }
        }
示例#47
0
文件: ROM.cs 项目: MCGlux/NSMB-Editor
        public static void load(Filesystem fs)
        {
            filename = fs.getRomPath();
            FS = fs;
            if(fs is NitroROMFilesystem)
                romfile = new System.IO.FileInfo(filename);

            arm9binFile = FS.getFileByName("arm9.bin");
            arm9ovFile = FS.getFileByName("arm9ovt.bin");
            arm9ovs = loadOvTable(arm9ovFile);
            arm7binFile = FS.getFileByName("arm7.bin");
            arm7ovFile = FS.getFileByName("arm7ovt.bin");
            arm7ovs = loadOvTable(arm7ovFile);
            rsaSigFile = FS.getFileByName("rsasig.bin");
            headerFile = FS.getFileByName("header.bin");

            ByteArrayInputStream header = new ByteArrayInputStream(headerFile.getContents());
            romInternalName = header.ReadString(12);
            romGamecode = header.ReadString(4);

            if (romGamecode == "A2DE")
                Region = Origin.US;
            else if (romGamecode == "A2DP")
                Region = Origin.EU;
            else if (romGamecode == "A2DJ")
                Region = Origin.JP;
            else if (romGamecode == "A2DK")
                Region = Origin.KR;
            else
            {
                isNSMBRom = false;
                Region = Origin.UNK;
            }

            if (isNSMBRom)
            {
                UserInfo = new ROMUserInfo(filename);
                LoadOverlay0();
            }
        }