Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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());
            }
        }
Exemplo n.º 6
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());
            }
        }
Exemplo n.º 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;
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 12
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());
            }
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
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++;
            }
        }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
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));
			}
    	}
Exemplo n.º 18
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;
        }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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));
            }
        }
Exemplo n.º 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++;
            }
        }