Example #1
0
    public static void ForceVertRGBA(bool Opaque)
    {
        int addresscount;

        if (Opaque)
        {
            addresscount = GeoLayouts.OpaqueModels.Length;
        }
        else
        {
            addresscount = GeoLayouts.AlphaModels.Length;
        }
        for (int i = 0; i < addresscount; i++)
        {
            if (Opaque)
            {
                ForceVertRGBAJump(GeoLayouts.OpaqueModels[i], true);
            }
            else
            {
                ForceVertRGBAJump(GeoLayouts.AlphaModels[i], false);
            }
            InitialiseModelLoad(Rectangle.Empty, new GLControl()); //init without rendering
            GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.getGeoAddress(Renderer.LevelArea), false);
        }
    }
Example #2
0
 private void Level_SelectedIndexChange(object sender, EventArgs e)
 {
     LevelScripts.SelectedLevel = (uint)LevelComboBox.SelectedIndex;
     LevelScripts.ExitDecode    = false;
     ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel); //init without rendering
     LevelScripts.ParseLevelScripts(ROMManager.SM64ROM, LevelScripts.LVLSCRIPTSTART);
     AreaComboBox.Items.Clear();
     for (int i = 0; i < LevelScripts.GeoLayoutOffsets.Length; i++)
     {
         AreaComboBox.Items.Add(i + 1);
     }
     AreaComboBox.SelectedIndex = 0;
     Renderer.Render(ClientRectangle, Width, Height, RenderPanel);
     if (AreaComboBox.Items.Count > 1)
     {
         AreaComboBox.Enabled = true;
     }
     else
     {
         AreaComboBox.Enabled = false;
     }
     TextureNumBox.Items.Clear();
     UpdateStatusText();
     if (ROMManager.SM64ROM.getSegmentStart(0x0E) < 0x1200000)
     {
         TexturesGroupBox.Visible = false; return;
     }
     groupBoxForce.Visible    = ROMManager.LevelHasLighting();
     TexturesGroupBox.Visible = true;
     for (uint i = 0; i < Textures.TextureArray.Length; i++)
     {
         TextureNumBox.Items.Add("Tex" + (i + 1));
     }
     TextureNumBox.SelectedIndex = 0;
 }
Example #3
0
        private void ConvertALLDLs_Button_Click(object sender, EventArgs e)
        {
            if (SM64ROM == null)
            {
                MessageBox.Show("No ROM loaded"); return;
            }
            UInt32 LevelAddr = UInt32.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber);

            DLConversion.AllAddresses = new uint[0];
            LevelScripts.ParseLevelScripts(SM64ROM, LevelAddr);
            MessageBox.Show("Every Display List traceable from level scripts has been converted! Be sure to only to do this once before saving your ROM.", "Conversion complete!");
        }
Example #4
0
 public static void LayerSwap(byte layer1, byte layer2, uint LevelArea)
 {
     for (uint i = 0; i < GeoLayouts.ExtDLPointers[layer1].Length; i++)
     {
         UInt32 Addr = GeoLayouts.ExtDLPointers[1][i] + 1;
         ROMManager.SM64ROM.changeByte(Addr, layer2);
         if (debug)
         {
             Console.Write("Wrote 0x" + layer2.ToString("x1") + " to ROM addr 0x" + Addr.ToString("x8") + " (GeoLayout LayerSwap)\n");
         }
         GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.getGeoAddress(LevelArea), false);
     }
 }
Example #5
0
 public static void RenderColourBuffer(Rectangle ClientRectangle, int Width, int Height, GLControl RenderPanel)
 {
     GL.Viewport(ClientRectangle.X, ClientRectangle.Y, RenderPanel.Width, RenderPanel.Height);
     projection = cam.GetViewMatrix() * Matrix4.CreatePerspectiveFieldOfView(1.0f, Width / (float)Height, 0.0000001f, 1.0f);
     GL.MatrixMode(MatrixMode.Projection);
     GL.LoadMatrix(ref projection);
     InitialiseView();
     GL.Scale(0.000001, 0.000001, 0.000001);
     if (ROMManager.ReadytoLoad)
     {
         GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
         GL.Scale(0.01, 0.01, 0.01);
         GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.getGeoAddress(LevelArea), true);
     }
     //RenderPanel.SwapBuffers(); //We don't want people to see the vertex selection colour map so don't invalidate here!
 }
Example #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.GetComponent <Player>())
        {
            LevelScripts.SetTriggerNumber(triggerNumber);

            if (CinematicTriggerEnterEvent != null)
            {
                CinematicTriggerEnterEvent();
            }

            if (deactivateAfterTrigger)
            {
                gameObject.SetActive(false);
            }
        }
    }
Example #7
0
        private void OpenROM()
        {
            // Displays an OpenFileDialog so the user can select a Cursor.
            OpenFileDialog OpenROM = OFD();

            OpenROM.Filter = "ROM Files|*.z64;*.rom;*.v64;*.n64";
            OpenROM.Title  = "Select a SM64 ROM File";
            if (OpenROM.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bool isSM64ROM = false;
                using (FileStream fs = new FileStream(OpenROM.FileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] Header = new byte[0x40]; fs.Read(Header, 0, 0x40); //Load header into bytearray
                    if (Header[0x3c] == 0x53 && Header[0x3d] == 0x4D && Header[0x3e] == 0x45 && Header[0x3f] == 0)
                    {
                        isSM64ROM = true;                                                                                            //Check if header is correct
                    }
                    fs.Close();
                }
                if (isSM64ROM)
                {
                    ROMManager.LoadROM(OpenROM.FileName, ClientRectangle, RenderPanel, Width, Height);
                    SaveROMAs.Enabled     = true; SaveROMAs.Enabled = true;
                    currentROMPath        = OpenROM.FileName;
                    LevelComboBox.Enabled = true;
                    String[] LevelList = LevelScripts.getLevelList();
                    LevelComboBox.Items.Clear();
                    for (int i = 0; i < LevelList.Length; i++)
                    {
                        LevelComboBox.Items.Add(LevelList[i]);
                    }
                    LevelComboBox.SelectedIndex = 12;
                    ControlPanel.Visible        = true;
                    ViewMenu.Visible            = true;
                }
                else
                {
                    MessageBox.Show("File is not a SM64 US ROM! Please try again.", "Invalid File!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #8
0
        private void selectLeveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Console.WriteLine("Opening SelectLevelForm!");
            SelectLevelForm newLevel = new SelectLevelForm(level.LevelID);

            newLevel.ShowDialog();
            if (newLevel.changeLevel)
            {
                //Console.WriteLine("Changing Level to " + newLevel.levelID);
                level = new Level(newLevel.levelID, 1);
                camera.setCameraMode(CameraMode.FLY, ref camMtx);
                camera.setLevel(level);
                LevelScripts.parse(ref level, 0x15, 0);
                level.sortAndAddNoModelEntries();
                level.CurrentAreaID = level.Areas[0].AreaID;
                resetObjectVariables();
                refreshObjectsInList();
                glControl1.Invalidate();
                updateAreaButtons();
            }
        }
Example #9
0
        private void loadROM(bool startingUp)
        {
            ROM rom = ROM.Instance;

            if (startingUp && !Globals.pathToAutoLoadROM.Equals(""))
            {
                rom.readFile(Globals.pathToAutoLoadROM);
            }
            else
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();

                openFileDialog1.Filter = "Z64 ROM|*.z64|V64 ROM|*.v64|N64 ROM|*.n64|All Files|*";
                DialogResult result = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK) // Test result.
                {
                    ROM.Instance.readFile(openFileDialog1.FileName);
                }
                else
                {
                    return;
                }
            }
            Globals.objectComboEntries.Clear();
            ModelComboFile.parseObjectCombos(Globals.getDefaultObjectComboPath());

            rom.setSegment(0x15, Globals.seg15_location[0], Globals.seg15_location[1], false);
            rom.setSegment(0x02, Globals.seg02_location[0], Globals.seg02_location[1], rom.isSegmentMIO0(0x02));

            level = new Level(0x10, 1);
            LevelScripts.parse(ref level, 0x15, 0);
            level.sortAndAddNoModelEntries();
            level.CurrentAreaID = level.Areas[0].AreaID;
            refreshObjectsInList();
            glControl1.Enabled = true;
            bgColor            = Color.CornflowerBlue;
            camera.setLevel(level);
            updateAreaButtons();
            glControl1.Invalidate();
        }
Example #10
0
        public override void Initialise()
        {
            // Initialise and
            GameGlobal.InitialiseAssets();

            // DEBUGGING
            #region Debugging
            // Debug text
            new Entity(entity => {
                entity.SortingLayer = 1;
                entity.LayerName    = "Fade";
                entity.Position     = -(Global.Resolution.ToVector2() / 2);
                entity.AddComponent(new Text()).Run <Text>(component => {
                    component.SetSpriteFont("HeartbitXX");
                    component.Color = Color.Yellow;

                    entity.UpdateAction = e => {
                        component.String = "";
                        //component.String = "Entities: " + Global.CountEntities().ToString() + ", Coroutines: " + Coroutines.Count.ToString() + ", FPS: " + Global.FPS.ToString();
                        //component.String = String.Join(", ", GameGlobal.Player.GetComponent<MainCollider>().PrevCollidingTriggers.Select(x => x.Name).ToArray());
                        component.String      += (GameGlobal.DebugString.Length > 0) ? " | " + GameGlobal.DebugString : "";
                        GameGlobal.DebugString = "";
                    };
                });
            });

            // Hotspot tester
            hotspotTest = new Entity(entity => {
                entity.AddComponent(new Sprite()).Run <Sprite>(d => {
                    d.BuildRectangle(new Point(4, 4), Color.Orange);
                });
                entity.SortingLayer = 10;
            });
            CoroutineHelper.Always(() => {
                //hotspotTest.Position = new Vector2(textTest.BoundingBox.Left + textTest.Size.X / 2, textTest.BoundingBox.Bottom);
            });
            #endregion

            // Backgrounds
            #region Backgrounds

            /*
             * new Entity(entity => {
             *  entity.LayerName = "Background";
             *  entity.Position += new Vector2(0, 80);
             *  entity.AddComponent(new Drawable() { Texture2D = Global.Content.Load<Texture2D>("WaterTest") }).Run<Drawable>(component => {
             *      Color[] colorArr = component.Texture2D.To1DArray();
             *      CoroutineHelper.Always(() => {
             *          component.Texture2D.ManipulateColors1D(colors => {
             *              colors = (Color[])colorArr.Clone();
             *              for (int y = 0; y < 100; y++)
             *                  colors.Shift(new Point(256, 100), new Rectangle(0, 1 * y, 256, 1), new Point(-(int)(Global.Camera.Position.X * (y + 1) * 0.005f), 1 * y));
             *              return colors;
             *          });
             *      });
             *  });
             * });*/
            #endregion

            // Player entity
            GameGlobal.Player = new Entity();
            GameGlobal.Player.AddComponent(new PlayerController());

            Global.AudioController.MusicSetThisFrame = false;

            // Temp
            RenderBlender = new RenderBlender(
                Color.Black * 0f,
                new List <RenderBlender.DrawableTexture>()
            {
            }
                );

            // Load level
            LevelLoader levelLoader = new LevelLoader();
            levelLoader.Load(GameData.Get("Level"), (tileset, tiles, entities) => {
                // Create tilemap
                TileMap tileMap = new TileMap(new Point(16, 16), "Tilesets/" + tileset.Substring(0, tileset.LastIndexOf('.')), tiles);
                tileMap.Build(new Point(32, 32));

                // Map collision
                foreach (var tgroup in tileMap.TileGroupEntities)
                {
                    if (tgroup.SortingLayer == GameGlobal.Player.SortingLayer)
                    {
                        tgroup.AddComponent(new Collider()).Run <Collider>(c => { c.ColliderType = Collider.ColliderTypes.Pixel; });
                    }

                    //if (tgroup.SortingLayer == GameGlobal.Player.SortingLayer - 1)
                    //    tgroup.IsPlatform = true;
                }

                // Entities
                new EntityInfoInterpreter(entities);
            });

            // Camera
            CameraController = new CameraController
            {
                Target  = GameGlobal.PlayerGraphicEntity,
                Easing  = 0.08f,
                MaxStep = 1000
            };
            CameraController.SnapOnce();
            CameraController.Mode = CameraController.Modes.LerpToTarget;

            // Level script
            LevelScripts levelScripts = new LevelScripts();
            Type         type         = levelScripts.GetType();
            MethodInfo   method       = type.GetMethod(GameData.Get("Level"));

            if (method != null)
            {
                method.Invoke(levelScripts, new object[0]);
            }

            if (!Global.AudioController.MusicSetThisFrame)
            {
                Global.AudioController.MusicFadeOut();
            }

            if (GameGlobal.Fader.Data["Cancel"] != "true")
            {
                // This delay is currently for the camera repositioning if min / max are applied
                CoroutineHelper.WaitRun(0.5f, () => {
                    GameGlobal.Fader.RunFunction("FadeIn");
                });
            }
        }
Example #11
0
    public static void DecodeLevelScripts(ROM SM64ROM, UInt32 offset)
    {
        ROMManager.ReadytoLoad = false;
        for (UInt32 i = offset; i < SM64ROM.getEndROMAddr();)
        {
            uint increment = SM64ROM.getByte(i + 1);
            if (ROMManager.debug)
            {
                Array.Resize(ref DebugScript, DebugScript.Length + 1);
                DebugScript[DebugScript.Length - 1] = i.ToString("x") + ": ";
                for (uint j = i; j < i + increment; j++)
                {
                    DebugScript[DebugScript.Length - 1] += SM64ROM.getByte(j).ToString("x") + " ";
                }
            }
            if (increment == 0 || SM64ROM.getByte(i) > 0x3C || ExitDecode)
            {
                return;
            }
            switch (SM64ROM.getByte(i))
            {
            case 0x00:
            case 0x01:
                NewSegment = SM64ROM.getByte(i + 3);
                NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                //if (NewSegment != 0x0E) break;
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 12);
                JumpAddr    = SM64ROM.readSegmentAddr(JumpSegAddr);

                //i = JumpAddr -increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, JumpAddr);
                break;

            case 0x02:
                if (!GeoFound)
                {
                    break;
                }
                ExitDecode             = true;
                GeoFound               = false;
                ROMManager.ReadytoLoad = true;
                return;

            case 0x03:
                //delayframes
                break;

            case 0x04:
                //delayframes
                break;

            case 0x05:
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                //i = SM64ROM.readSegmentAddr(JumpSegAddr)-increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                break;

            case 0x06:
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                //i = SM64ROM.readSegmentAddr(JumpSegAddr) - increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                break;

            case 0x07:
                return;

            case 0x0C:
                if (SM64ROM.getByte(i + 7) != SelectedLevel + 4)
                {
                    break;                                                //num is level ID
                }
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 8);
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                return;

            case 0x16:
                //Loads directly to ram, no segment
                break;

            case 0x17:
                NewSegment = SM64ROM.getByte(i + 3);
                NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                if (NewSegment == 0x0E)
                {
                    Ext0EBankEnd = SM64ROM.ReadFourBytes(i + 8);
                    Console.Write("Segment 0x0E Location in ROM:\n0x" + SM64ROM.getSegmentStart(0x0E).ToString("x8"));
                }
                break;

            case 0x18:
            //MIO0 segment
            case 0x1A:
                //MIO0 segment
                NewSegment = SM64ROM.getByte(i + 3);
                BeginMIO0  = SM64ROM.ReadFourBytes(i + 4);
                NewSegAddr = SM64ROM.ReadFourBytes(BeginMIO0 + 12) + BeginMIO0;
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                break;

            case 0x1F:
                //LEVEL MODEL
                uint SegAddr = SM64ROM.ReadFourBytes(i + 4);
                if (SM64ROM.getByte(i + 4) == 0x0E || SM64ROM.getByte(i + 4) == 0x19)     //Level bank
                {
                    Array.Resize(ref GeoLayoutOffsets, GeoLayoutOffsets.Length + 1);
                    GeoLayoutOffsets[SM64ROM.getByte(i + 2) - 1] = SM64ROM.readSegmentAddr(SegAddr);
                    GeoFound = true;
                    if (SelectedLevel == 21)
                    {
                        return;                          // End Cake Loop evasion
                    }
                    break;
                }
                break;

            case 0x21:
                //obj model w/o geolayout
                break;

            case 0x22:
                int seg = SM64ROM.getByte(i + 4);
                Array.Resize(ref ObjectGeoOffsets[seg], ObjectGeoOffsets[seg].Length + 1);
                uint OBJSegAddr = SM64ROM.ReadFourBytes(i + 4);
                ObjectGeoOffsets[seg][ObjectGeoOffsets[seg].Length - 1] = SM64ROM.readSegmentAddr(OBJSegAddr);
                //obj model w/ geolayout
                break;

            case 0x2B:
                //Default Mario Position
                short   YRotation = (short)SM64ROM.ReadTwoBytes(i + 4);
                int     X         = (short)-SM64ROM.ReadTwoBytes(i + 6);
                int     Y         = (short)SM64ROM.ReadTwoBytes(i + 8) + 250; //+250 to be above ground
                int     Z         = (short)-SM64ROM.ReadTwoBytes(i + 10);
                Vector3 location  = new Vector3(X, Y, Z) * Renderer.WorldScale * Renderer.GameScale;
                Renderer.cam.SetCamPosition(location);
                float YRotRadians = Convert.ToSingle(YRotation) / 180f * Convert.ToSingle(Math.PI);
                Renderer.cam.SetCamOrientation(new Vector3(-YRotRadians - Convert.ToSingle(Math.PI / 2), 0f, YRotRadians));
                break;

            case 0x2E:
                ExtCollisionPointer = i;     //Needed to repoint for extended roms
                break;

            default:
                break;
            }
            i += increment;
        }
    }
Example #12
0
 public static void Render(Rectangle ClientRectangle, int Width, int Height, GLControl RenderPanel)
 {
     TriCount    = 0;
     VertexCount = 0;
     GL.Viewport(ClientRectangle.X, ClientRectangle.Y, RenderPanel.Width, RenderPanel.Height);
     projection = cam.GetViewMatrix() * Matrix4.CreatePerspectiveFieldOfView(1.0f, Width / (float)Height, 0.00000001f, 0.001f);
     GL.MatrixMode(MatrixMode.Projection);
     GL.LoadMatrix(ref projection);
     InitialiseView();
     if (WireFrameMode)
     {
         GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     }
     else
     {
         GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     }
     GL.Scale(WorldScale);
     if (ROMManager.ReadytoLoad && ROMManager.SM64ROM != null)
     {
         GL.Scale(GameScale);
         if (!ObjectView)
         {
             GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.getGeoAddress(LevelArea), false);
         }
         else
         {
             GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.ObjectGeoOffsets[SelectedSegment][SelectedObject], false);
         }
         if (EdgesOption)
         {
             GL.Disable(EnableCap.CullFace);
             F3D.RenderEdges = true;
             GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
             if (!ObjectView)
             {
                 GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.getGeoAddress(LevelArea), false);
             }
             else
             {
                 GeoLayouts.ParseGeoLayout(ROMManager.SM64ROM, LevelScripts.ObjectGeoOffsets[SelectedSegment][SelectedObject], false);
             }
             F3D.RenderEdges = false;
         }
     }
     else //Rotate cubes for fun idle :)
     {
         if (CubeSampleRotate >= Math.PI * 1.5)
         {
             CubeSampleRotate = Math.PI / 2; CubeSampleColour = new Color4(0f, 0f, 1f, 1f);
         }
         if (CubeSampleScale >= Math.PI * 2)
         {
             CubeSampleScale = 0;
         }
         GL.Scale(1 + 0.25 * Math.Sin(CubeSampleScale), Math.Sin(CubeSampleScale), Math.Sin(CubeSampleScale));
         float rotation = 90 * (float)Math.Sin(CubeSampleRotate);
         CubeRealRotation = rotation;
         float newcolour = Math.Abs(rotation);
         GL.Rotate(rotation, 1, 0, 0);
         CubeSampleColour.R = (newcolour) / 45;
         CubeSampleColour.G = (newcolour) / 45;
         DrawCube();
         GL.Rotate(rotation, 1, 0, 0);
         CubeSampleColour.R = (newcolour) / 45;
         CubeSampleColour.G = (newcolour) / 45;
         DrawCube();
         GL.Rotate(rotation, 1, 0, 0);
         CubeSampleColour.R = (newcolour) / 45;
         CubeSampleColour.G = (newcolour) / 45;
         DrawCube();
         GL.Rotate(rotation, 1, 0, 0);
         CubeSampleColour.R = (newcolour) / 45;
         CubeSampleColour.G = (newcolour) / 45;
         DrawCube();
         KeyboardState state = Keyboard.GetState();
         CubeSampleScale  += 0.015;
         CubeSampleRotate += 0.015;
     }
     RenderPanel.SwapBuffers();
 }
Example #13
0
    public static void DecodeLevelScripts(ROM SM64ROM, UInt32 offset)
    {
        ROMManager.ReadytoLoad = false;
        for (UInt32 i = offset; i < SM64ROM.getEndROMAddr();)
        {
            uint increment = SM64ROM.getByte(i + 1);

            /*using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"e:\test4.txt", true))
             * {
             *  file.Write(i.ToString("x") + ": ");
             *  for (uint j = i; j < i + increment; j++)
             *  {
             *      file.Write(SM64ROM.getByte(j).ToString("x") + " ");
             *  }
             *  file.WriteLine("\n");
             *  file.Close();
             * }*/
            if (increment == 0 || SM64ROM.getByte(i) > 0x3C || ExitDecode)
            {
                return;
            }
            switch (SM64ROM.getByte(i))
            {
            case 0x00:
            case 0x01:
                NewSegment = SM64ROM.getByte(i + 3);
                NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                //if (NewSegment != 0x0E) break;
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 12);
                JumpAddr    = SM64ROM.readSegmentAddr(JumpSegAddr);

                //i = JumpAddr -increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, JumpAddr);
                break;

            case 0x02:
                if (!GeoFound)
                {
                    break;
                }
                ExitDecode             = true;
                GeoFound               = false;
                ROMManager.ReadytoLoad = true;
                return;

            case 0x03:
                //delayframes
                break;

            case 0x04:
                //delayframes
                break;

            case 0x05:
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                //i = SM64ROM.readSegmentAddr(JumpSegAddr)-increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                break;

            case 0x06:
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                //i = SM64ROM.readSegmentAddr(JumpSegAddr) - increment;
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                break;

            case 0x07:
                return;

            case 0x0C:
                if (SM64ROM.getByte(i + 7) != SelectedLevel + 4)
                {
                    break;                                                //num is level ID
                }
                JumpSegAddr = SM64ROM.ReadFourBytes(i + 8);
                LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                return;

            case 0x16:
                //Loads directly to ram, no segment
                break;

            case 0x17:
                NewSegment = SM64ROM.getByte(i + 3);
                NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                if (NewSegment == 0x0E)
                {
                    Ext0EBankEnd = SM64ROM.ReadFourBytes(i + 8);
                }
                break;

            case 0x18:
            //MIO0 segment
            case 0x1A:
                //MIO0 segment
                NewSegment = SM64ROM.getByte(i + 3);
                BeginMIO0  = SM64ROM.ReadFourBytes(i + 4);
                NewSegAddr = SM64ROM.ReadFourBytes(BeginMIO0 + 12) + BeginMIO0;
                SM64ROM.setSegment(NewSegment, NewSegAddr);
                break;

            case 0x1F:
                //LEVEL MODEL
                uint SegAddr = SM64ROM.ReadFourBytes(i + 4);
                if (SM64ROM.getByte(i + 4) == 0x0E || SM64ROM.getByte(i + 4) == 0x19)     //Level bank
                {
                    Array.Resize(ref GeoLayoutOffsets, GeoLayoutOffsets.Length + 1);
                    GeoLayoutOffsets[SM64ROM.getByte(i + 2) - 1] = SM64ROM.readSegmentAddr(SegAddr);
                    GeoFound = true;
                    if (SelectedLevel == 21)
                    {
                        return;                          // End Cake Loop evasion
                    }
                    break;
                }
                break;

            case 0x21:
                //obj model w/o geolayout
                break;

            case 0x22:
                //obj model w/ geolayout
                break;

            case 0x2E:
                ExtCollisionPointer = i;     //Needed to repoint for extended roms
                break;

            default:
                break;
            }
            i += increment;
        }
    }
Example #14
0
    public static void DecodeLevelScripts(ROM SM64ROM, UInt32 offset)
    {
        for (UInt32 i = offset; i < SM64ROM.getEndROMAddr();)
        {
            if (DebugScript.Length > 10000)
            {
                ExitDecode = true;
            }
            if (ExitDecode)
            {
                return;
            }
            uint increment = SM64ROM.getByte(i + 1);
            if (increment == 0 || SM64ROM.getByte(i) > 0x3C)
            {
                return;
            }
            Array.Resize(ref LevelScripts.DebugScript, LevelScripts.DebugScript.Length + 1);
            uint newindex = (uint)(LevelScripts.DebugScript.Length - 1);
            for (uint j = 0; j < stackcounter; j++)
            {
                LevelScripts.DebugScript[newindex] += "    ";                                     //tab further each stack increase for debug txt
            }
            LevelScripts.DebugScript[newindex] += i.ToString("x") + ": ";
            for (uint j = i; j < i + increment; j++)
            {
                LevelScripts.DebugScript[newindex] += SM64ROM.getByte(j).ToString("x2") + " ";
            }
            SkipCMDDetermination(i); //see if the command has already been processed before
            if (!skipCMD)
            {
                switch (SM64ROM.getByte(i)) //if not skipping command, process it
                {
                case 0x00:                  //Load raw data and jump
                    NewSegment = SM64ROM.getByte(i + 3);
                    NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    SM64ROM.setSegment(NewSegment, NewSegAddr);
                    JumpSegAddr = SM64ROM.ReadFourBytes(i + 12);
                    if (CheckExistingJumps(SM64ROM.readSegmentAddr(JumpSegAddr)))
                    {
                        break;                                                           //Don't jump to a spot previously jumped to
                    }
                    stackcounter++;
                    LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                    break;

                case 0x01: //Load raw data and jump
                    NewSegment = SM64ROM.getByte(i + 3);
                    NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    SM64ROM.setSegment(NewSegment, NewSegAddr);
                    JumpSegAddr = SM64ROM.ReadFourBytes(i + 12);
                    if (CheckExistingJumps(SM64ROM.readSegmentAddr(JumpSegAddr)))
                    {
                        break;                                                           //Don't jump to a spot previously jumped to
                    }
                    LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                    break;

                case 0x02: //End level data
                    return;

                case 0x03:
                    //delayframes
                    break;

                case 0x04:
                    //delayframes
                    break;

                case 0x05: //Jump to addr
                    JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    if (SM64ROM.readSegmentAddr(JumpSegAddr) == (i - 4))
                    {
                        return;                                                  //The cake is a f*****g lie
                    }
                    if (CheckExistingJumps(SM64ROM.readSegmentAddr(JumpSegAddr)))
                    {
                        break;                                                           //Don't jump to a spot previously jumped to
                    }
                    LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                    break;

                case 0x06: //Push stack
                    JumpSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    if (CheckExistingJumps(SM64ROM.readSegmentAddr(JumpSegAddr)))
                    {
                        break;                                                           //Don't jump to a spot previously jumped to
                    }
                    stackcounter++;
                    LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                    break;

                case 0x07: //Pop stack
                    stackcounter--;
                    return;

                case 0x0B: //Conditional Pop
                    break;

                case 0x0C: //Conditional Jump
                    LevelID = SM64ROM.getByte(i + 7);
                    if (LevelID == 0xFF)
                    {
                        break;
                    }
                    //if (LevelID == 0x00) throw new Exception(SM64ROM.getSegmentStart(0x14).ToString("x"));
                    if (LevelID < 5)
                    {
                        SM64ROM.BackupAllSegments();
                    }
                    SM64ROM.LoadBackupSegments();
                    JumpSegAddr = SM64ROM.ReadFourBytes(i + 8);
                    if (CheckExistingJumps(SM64ROM.readSegmentAddr(JumpSegAddr)))
                    {
                        break;                                                           //Don't jump to a spot previously jumped to
                    }
                    LevelScripts.DecodeLevelScripts(SM64ROM, SM64ROM.readSegmentAddr(JumpSegAddr));
                    break;

                case 0x0D: //Conditional Push
                    break;

                case 0x0E: //Conditional Skip
                    break;

                case 0x0F: //Skip next
                    break;

                case 0x10: //No-op
                    break;

                case 0x11: //Set Accumulator From ASM
                    break;

                case 0x12: //Actively set accumulator
                    break;

                case 0x13: //Set accumulator
                    break;

                case 0x16:
                    //Loads directly to ram, no segment
                    break;

                case 0x17:
                    NewSegment = SM64ROM.getByte(i + 3);
                    NewSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    SM64ROM.setSegment(NewSegment, NewSegAddr);
                    break;

                case 0x18:
                //MIO0 segment
                case 0x1A:
                    //MIO0 segment
                    NewSegment = SM64ROM.getByte(i + 3);
                    BeginMIO0  = SM64ROM.ReadFourBytes(i + 4);
                    NewSegAddr = SM64ROM.ReadFourBytes(BeginMIO0 + 12) + BeginMIO0;
                    SM64ROM.setSegment(NewSegment, NewSegAddr);
                    break;

                case 0x1F: //LEVEL MODEL
                    uint SegAddr = SM64ROM.ReadFourBytes(i + 4);
                    GeoLayouts.DecodeGeoLayout(SM64ROM, SM64ROM.readSegmentAddr(SegAddr));
                    break;

                case 0x21:
                    uint DLSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    DLConversion.ConvertDL(SM64ROM, DLSegAddr, false);
                    break;

                case 0x22:
                    uint ModelSegAddr = SM64ROM.ReadFourBytes(i + 4);
                    GeoLayouts.DecodeGeoLayout(SM64ROM, SM64ROM.readSegmentAddr(ModelSegAddr));
                    break;

                case 0x2B:
                    //Default Mario Position
                    break;

                case 0x2E:
                    //Collision
                    break;

                default:
                    break;
                }
            }


            i += increment;
        }
    }