LevelItem FromString(String[] strs, ref int idx)
        {
            switch (strs[idx])
            {
            case "OBJ":
                return(NSMBObject.FromString(strs, ref idx, EdControl.Level.GFX));

            case "SPR":
                return(NSMBSprite.FromString(strs, ref idx, EdControl.Level));

            case "ENT":
                return(NSMBEntrance.FromString(strs, ref idx, EdControl.Level));

            case "VIW":
            case "ZON":
                return(NSMBView.FromString(strs, ref idx, EdControl.Level));

            // TODO: copy and paste with paths/path points
            //case "PTH":
            //    break;
            default:
                idx++;
                return(null);
            }
        }
Esempio n. 2
0
        private void Write(NSMBEntrance e, bool value)
        {
            if (value)
            {
                switch (PropNum)
                {
                case 0: e.Settings |= 128; break;

                case 1: e.Settings |= 16; break;

                case 2: e.Settings |= 8; break;

                case 3: e.Settings |= 1; break;
                }
            }
            else
            {
                switch (PropNum)
                {
                case 0: e.Settings &= 127; break;

                case 1: e.Settings &= 239; break;

                case 2: e.Settings &= 247; break;

                case 3: e.Settings &= 254; break;
                }
            }
        }
Esempio n. 3
0
        public void UpdateInfo()
        {
            UpdateList();

            if (SelectedObjects == null || SelectedObjects.Count == 0)
            {
                tableLayoutPanel5.Visible    = false;
                deleteEntranceButton.Enabled = false;
                return;
            }
            NSMBEntrance en = SelectedObjects[0] as NSMBEntrance;

            deleteEntranceButton.Enabled = true;
            tableLayoutPanel5.Visible    = true;
            DataUpdateFlag = true;

            foreach (LevelItem obj in SelectedObjects)
            {
                entranceListBox.SelectedIndices.Add(EdControl.Level.Entrances.IndexOf(obj as NSMBEntrance));
            }
            entranceCameraXPosUpDown.Value     = en.CameraX;
            entranceCameraYPosUpDown.Value     = en.CameraY;
            entranceNumberUpDown.Value         = en.Number;
            entranceDestAreaUpDown.Value       = en.DestArea;
            entrancePipeIDUpDown.Value         = en.ConnectedPipeID;
            entranceDestEntranceUpDown.Value   = en.DestEntrance;
            entranceTypeComboBox.SelectedIndex = en.Type;
            entranceSetting128.Checked         = (en.Settings & 128) != 0;
            entranceSetting16.Checked          = (en.Settings & 16) != 0;
            entranceSetting8.Checked           = (en.Settings & 8) != 0;
            entranceSetting1.Checked           = (en.Settings & 1) != 0;
            entranceViewUpDown.Value           = en.EntryView;
            DataUpdateFlag = false;
        }
Esempio n. 4
0
        private void addEntranceButton_Click(object sender, EventArgs e)
        {
            Rectangle ViewableBlocks = EdControl.ViewableBlocks;

            NSMBEntrance ne = new NSMBEntrance();

            ne.X      = (ViewableBlocks.X + ViewableBlocks.Width / 2) * 16;
            ne.Y      = (ViewableBlocks.Y + ViewableBlocks.Height / 2) * 16;
            ne.Number = EdControl.Level.getFreeEntranceNumber();
            EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(ne)));
            EdControl.mode.SelectObject(ne);
        }
Esempio n. 5
0
        private bool Read(NSMBEntrance e)
        {
            switch (PropNum)
            {
            case 0: return((e.Settings & 128) != 0);

            case 1: return((e.Settings & 16) != 0);

            case 2: return((e.Settings & 8) != 0);

            case 3: return((e.Settings & 1) != 0);
            }
            return(false);
        }
Esempio n. 6
0
 public NSMBEntrance(NSMBEntrance e)
 {
     X               = e.X;
     Y               = e.Y;
     CameraX         = e.CameraX;
     CameraY         = e.CameraY;
     Number          = e.Number;
     DestArea        = e.DestArea;
     ConnectedPipeID = e.ConnectedPipeID;
     DestEntrance    = e.DestEntrance;
     Type            = e.Type;
     Settings        = e.Settings;
     Unknown1        = e.Unknown1;
     EntryView       = e.EntryView;
     Unknown2        = e.Unknown2;
 }
Esempio n. 7
0
 public NSMBEntrance(NSMBEntrance e)
 {
     X = e.X;
     Y = e.Y;
     CameraX = e.CameraX;
     CameraY = e.CameraY;
     Number = e.Number;
     DestArea = e.DestArea;
     ConnectedPipeID = e.ConnectedPipeID;
     DestEntrance = e.DestEntrance;
     Type = e.Type;
     Settings = e.Settings;
     Unknown1 = e.Unknown1;
     EntryView = e.EntryView;
     Unknown2 = e.Unknown2;
 }
Esempio n. 8
0
        private void Write(NSMBEntrance e, int value)
        {
            switch (PropNum)
            {
            case 0: e.CameraX = value; break;

            case 1: e.CameraY = value; break;

            case 2: e.Number = value; break;

            case 3: e.DestArea = value; break;

            case 4: e.DestEntrance = value; break;

            case 5: e.ConnectedPipeID = value; break;

            case 6: e.EntryView = value; break;

            case 7: e.Type = value; break;

            case 8: e.Settings = value; break;
            }
        }
Esempio n. 9
0
        private int Read(NSMBEntrance e)
        {
            switch (PropNum)
            {
            case 0: return(e.CameraX);

            case 1: return(e.CameraY);

            case 2: return(e.Number);

            case 3: return(e.DestArea);

            case 4: return(e.DestEntrance);

            case 5: return(e.ConnectedPipeID);

            case 6: return(e.EntryView);

            case 7: return(e.Type);

            case 8: return(e.Settings);
            }
            return(0);
        }
Esempio n. 10
0
        public static NSMBEntrance FromString(string[] strs, ref int idx, NSMBLevel lvl)
        {
            NSMBEntrance e = new NSMBEntrance();

            e.X               = int.Parse(strs[1 + idx]);
            e.Y               = int.Parse(strs[2 + idx]);
            e.CameraX         = int.Parse(strs[3 + idx]);
            e.CameraY         = int.Parse(strs[4 + idx]);
            e.Number          = int.Parse(strs[5 + idx]);
            e.DestArea        = int.Parse(strs[6 + idx]);
            e.ConnectedPipeID = int.Parse(strs[7 + idx]);
            e.DestEntrance    = int.Parse(strs[8 + idx]);
            e.Type            = int.Parse(strs[9 + idx]);
            e.Settings        = int.Parse(strs[10 + idx]);
            e.Unknown1        = int.Parse(strs[11 + idx]);
            e.EntryView       = int.Parse(strs[12 + idx]);
            e.Unknown2        = int.Parse(strs[13 + idx]);
            if (lvl.isEntranceNumberUsed(e.Number))
            {
                e.Number = lvl.getFreeEntranceNumber();
            }
            idx += 14;
            return(e);
        }
Esempio n. 11
0
 private bool Read(NSMBEntrance e)
 {
     switch (PropNum) {
         case 0: return (e.Settings & 128) != 0;
         case 1: return (e.Settings & 16) != 0;
         case 2: return (e.Settings & 8) != 0;
         case 3: return (e.Settings & 1) != 0;
     }
     return false;
 }
Esempio n. 12
0
 private void Write(NSMBEntrance e, int value)
 {
     switch (PropNum) {
         case 0: e.CameraX = value; break;
         case 1: e.CameraY = value; break;
         case 2: e.Number = value; break;
         case 3: e.DestArea = value; break;
         case 4: e.DestEntrance = value; break;
         case 5: e.ConnectedPipeID = value; break;
         case 6: e.EntryView = value; break;
         case 7: e.Type = value; break;
         case 8: e.Settings = value; break;
     }
 }
Esempio n. 13
0
 private int Read(NSMBEntrance e)
 {
     switch (PropNum) {
         case 0: return e.CameraX;
         case 1: return e.CameraY;
         case 2: return e.Number;
         case 3: return e.DestArea;
         case 4: return e.DestEntrance;
         case 5: return e.ConnectedPipeID;
         case 6: return e.EntryView;
         case 7: return e.Type;
         case 8: return e.Settings;
     }
     return 0;
 }
Esempio n. 14
0
 public static NSMBEntrance FromString(string[] strs, ref int idx, NSMBLevel lvl)
 {
     NSMBEntrance e = new NSMBEntrance();
     e.X = int.Parse(strs[1 + idx]);
     e.Y = int.Parse(strs[2 + idx]);
     e.CameraX = int.Parse(strs[3 + idx]);
     e.CameraY = int.Parse(strs[4 + idx]);
     e.Number = int.Parse(strs[5 + idx]);
     e.DestArea = int.Parse(strs[6 + idx]);
     e.ConnectedPipeID = int.Parse(strs[7 + idx]);
     e.DestEntrance = int.Parse(strs[8 + idx]);
     e.Type = int.Parse(strs[9 + idx]);
     e.Settings = int.Parse(strs[10 + idx]);
     e.Unknown1 = int.Parse(strs[11 + idx]);
     e.EntryView = int.Parse(strs[12 + idx]);
     e.Unknown2 = int.Parse(strs[13 + idx]);
     if (lvl.isEntranceNumberUsed(e.Number))
         e.Number = lvl.getFreeEntranceNumber();
     idx += 14;
     return e;
 }
Esempio n. 15
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();
        }
Esempio n. 16
0
 private void Write(NSMBEntrance e, bool value)
 {
     if (value)
         switch (PropNum) {
             case 0: e.Settings |= 128; break;
             case 1: e.Settings |= 16; break;
             case 2: e.Settings |= 8; break;
             case 3: e.Settings |= 1; break;
         }
     else
         switch (PropNum) {
             case 0: e.Settings &= 127; break;
             case 1: e.Settings &= 239; break;
             case 2: e.Settings &= 247; break;
             case 3: e.Settings &= 254; break;
         }
 }
Esempio n. 17
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();
        }
Esempio n. 18
0
        private void addEntranceButton_Click(object sender, EventArgs e)
        {
            Rectangle ViewableBlocks = EdControl.ViewableBlocks;

            NSMBEntrance ne = new NSMBEntrance();
            ne.X = (ViewableBlocks.X + ViewableBlocks.Width / 2) * 16;
            ne.Y = (ViewableBlocks.Y + ViewableBlocks.Height / 2) * 16;
            ne.Number = EdControl.Level.getFreeEntranceNumber();
            EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(ne)));
            EdControl.mode.SelectObject(ne);
        }