Beispiel #1
0
    public static void EditVertex(Rectangle ClientRectangle, int Width, int Height, GLControl RenderPanel, Point pt, byte R, byte G, byte B, byte A, bool AlphaOnly)
    {
        byte[] color = new byte[4];
        Renderer.RenderColourBuffer(ClientRectangle, Width, Height, RenderPanel);
        GL.ReadPixels(pt.X, RenderPanel.Height - pt.Y - 1, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, color);
        UInt32 Addr = (UInt32)((color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3]);

        //StatusLabel.Text = Addr.ToString("x");
        if (Addr != 0)
        {
            for (uint i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                if (Addr == Vertex.CurrentVertexList[i])
                {
                    UInt32 colour = (uint)((R << 24) | (G << 16) | (B << 8) | A);
                    if (colour == ROMManager.SM64ROM.ReadFourBytes(Addr + 12))
                    {
                        return;                               //If it's the same, don't do anything
                    }
                    for (uint j = 29; j >= 1 && j <= 29; j--) //Shift all mem back one
                    {
                        Vertex.OriginalVertexMem[j] = Vertex.OriginalVertexMem[j - 1];
                    }
                    Vertex.OriginalVertexMem[0]       = new UInt32[1][]; //Set up new undo level with one combo
                    Vertex.OriginalVertexMem[0][0]    = new UInt32[2];
                    Vertex.OriginalVertexMem[0][0][0] = Addr + 12;
                    Vertex.OriginalVertexMem[0][0][1] = ROMManager.SM64ROM.ReadFourBytes(Addr + 12); //Initial RGBA
                    ROMManager.SetVertRGBA(Vertex.CurrentVertexList[i], colour, AlphaOnly);
                    break;
                }
            }
        }
    }
Beispiel #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;
 }
Beispiel #3
0
 private void LevelArea_SelectedIndexChange(object sender, EventArgs e)
 {
     Renderer.LevelArea = (uint)AreaComboBox.SelectedIndex;
     ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
     UpdateStatusText();
     if (ROMManager.SM64ROM.getSegmentStart(0x0E) >= 0x1200000)
     {
         ROMManager.AdjustCombiners();
     }
 }
Beispiel #4
0
        private void ImportTexture_Click(object sender, EventArgs e)
        {
            int index = TextureNumBox.SelectedIndex;
            // Displays an OpenFileDialog so the user can select a Cursor.
            OpenFileDialog OpenTexture = OFD();

            OpenTexture.Filter = "Image Files|*.png;*.bmp;*.jpg";
            OpenTexture.Title  = "Select a texture image file";
            if (OpenTexture.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Bitmap TextureBMP  = (Bitmap)Image.FromFile(OpenTexture.FileName);
                double widthpower  = Math.Log(TextureBMP.Width, 2);
                double heightpower = Math.Log(TextureBMP.Height, 2);
                if ((widthpower % 1) != 0 || (heightpower % 1) != 0)
                {
                    MessageBox.Show("Only texture sizes in powers of 2 \n(ie 16x16, 32x32, 64x64, 128x64) are supported!", "Invalid texture resolution");
                    return;
                }
                Vector2 originalpowers = Textures.getWidthHeightPowers(index);
                if ((Math.Pow(2, originalpowers.X) * Math.Pow(2, originalpowers.Y)) < (Math.Pow(2, widthpower) * Math.Pow(2, heightpower)))
                {
                    MessageBox.Show("Texture is beyond the max data for this tile! \nTry lowering resolution or bitsize.", "Texture data too large!");
                    return;
                }
                else if (TexFormatBox.SelectedIndex == 2 && ((Math.Pow(2, originalpowers.X) * Math.Pow(2, originalpowers.Y)) < (Math.Pow(2, widthpower + 1) * Math.Pow(2, heightpower)))) //CI4 needs twice data atm for palette
                {
                    MessageBox.Show("Texture is beyond the max data for this tile! \nTry lowering resolution or bitsize.\n(CI needs extra data for palette and commands)", "Texture data too large!");
                    return;
                }
                else if (TexFormatBox.SelectedIndex == 2 && BitsizeBox.SelectedIndex == 0 && Textures.getImageColors(TextureBMP).Length > 16)
                {
                    MessageBox.Show("Texture has too many colours for CI4.\nPlease reduce colour count to 16."); return;
                }
                Textures.ResizeTexture(index, Convert.ToInt32(widthpower), Convert.ToInt32(heightpower));
                Textures.ImportBMPtoTexture(TextureBMP, index);
                UInt32[] F5CMDs = Textures.F5CMDArray[TextureNumBox.SelectedIndex]; ROM SM64ROM = ROMManager.SM64ROM;
                ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
                UpdateTextureNum();
                int    width           = TextureBMP.Width;
                int    selectedbitsize = (int)(4 * Math.Pow(2, BitsizeBox.SelectedIndex));
                ushort linesperword    = Convert.ToUInt16((64d * 2048d) / ((double)TextureBMP.Width * selectedbitsize));
                ushort texelcount      = (ushort)((double)(TextureBMP.Width * TextureBMP.Height) * ((double)selectedbitsize / 16d) - 1);
                for (uint i = 0; i < F5CMDs.Length; i++) //Update F5 scanline width
                {
                    uint F5 = F5CMDs[i];
                    if (SM64ROM.getByte(F5 - 0x10) == 0xF3)
                    {
                        SM64ROM.WriteEightBytes(F5 - 0x10, 0xF300000007000000 | (uint)(texelcount << 12) | linesperword);
                    }
                    SM64ROM.WriteTwoBytes(F5 + 1, (ushort)((SM64ROM.ReadTwoBytes(F5CMDs[i] + 1) & 0xFC00) | ((width * selectedbitsize / 64) << 1)));
                }
                TextureBMP.Dispose();
            }
        }
Beispiel #5
0
        private void TPropertiesBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Textures.FirstTexLoad || ROMManager.SM64ROM == null)
            {
                return;
            }
            uint index      = (uint)TextureNumBox.SelectedIndex;
            byte TParamByte = ROMManager.SM64ROM.getByte(Textures.F5CMDArray[index][0] + 5);
            int  Tparam     = ((TParamByte >> 2) & 0x03);
            int  dif        = TPropertiesBox.SelectedIndex - Tparam;

            for (uint i = 0; i < Textures.F5CMDArray[index].Length; i++)
            {
                ROMManager.SM64ROM.changeByte(Textures.F5CMDArray[index][i] + 5, (byte)(TParamByte + (dif * 4)));
            }                                                                                                     //*4 for << 2 with negative carried
            ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
        }
Beispiel #6
0
        private void SPropertiesBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Textures.FirstTexLoad || ROMManager.SM64ROM == null)
            {
                return;
            }
            uint index      = (uint)TextureNumBox.SelectedIndex;
            byte SParamByte = ROMManager.SM64ROM.getByte(Textures.F5CMDArray[index][0] + 6);
            int  Sparam     = (SParamByte & 0x03);
            int  dif        = SPropertiesBox.SelectedIndex - Sparam;

            for (uint i = 0; i < Textures.F5CMDArray[index].Length; i++)
            {
                ROMManager.SM64ROM.changeByte(Textures.F5CMDArray[index][i] + 6, (byte)(SParamByte + dif));
            }
            ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            ROMManager.SetMapper(new Mapper000());

            ROMManager.AddPrgBank(0, (id, bank) => {
                EngineStuff(id, bank);
                Scenes(id, bank);
            });

            ROMManager.AddChrBank(0, (id, bank) => {
                Include.File(@"chr/sp-plain.chr");
            });

            var engine = Module <Engine>();

            ROMManager.SetInterrupts(engine.NMI, engine.Reset, engine.IRQ);
            ROMManager.WriteToFile(@"flicker-test");
        }
Beispiel #8
0
        private void BitsizeBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            BitSizeCheck();
            if (Textures.FirstTexLoad || ROMManager.SM64ROM == null)
            {
                return;
            }
            ROM SM64ROM = ROMManager.SM64ROM;

            UInt32[] F5CMDs      = Textures.F5CMDArray[TextureNumBox.SelectedIndex];
            byte     BitsizeByte = SM64ROM.getByte(F5CMDs[0] + 1);
            int      BitsizePWR  = ((BitsizeByte >> 3) & 0x03);
            int      dif         = BitsizeBox.SelectedIndex - BitsizePWR;
            byte     bitsize     = (byte)(BitsizeByte + (dif * 8)); //*8 for << 3 with negative carried

            for (uint i = 0; i < F5CMDs.Length; i++)
            {
                SM64ROM.changeByte(F5CMDs[i] + 1, bitsize);
            }
            uint[] F5CMD           = Textures.F5CMDArray[(uint)TextureNumBox.SelectedIndex];
            byte   WidthsizeByte   = SM64ROM.getByte(F5CMD[0] + 7);
            ushort HeightsizeShort = SM64ROM.ReadTwoBytes(F5CMD[0] + 5);
            int    ogHeightPower   = (HeightsizeShort >> 6 & 0x0F);
            int    ogWidthPower    = (WidthsizeByte >> 4);

            if (ogWidthPower < ogHeightPower)
            {
                Textures.ResizeTexture(TextureNumBox.SelectedIndex, ogWidthPower - dif, ogHeightPower);
            }
            else
            {
                Textures.ResizeTexture(TextureNumBox.SelectedIndex, ogWidthPower, ogHeightPower - dif);
            }
            if (!WaitToRender)
            {
                ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
            }
            if (!WaitToRender)
            {
                UpdateTextureNum();
            }
        }
Beispiel #9
0
        private void ForceVertRGBAButton_Click(object sender, EventArgs e)
        {
            DialogResult warningchoice = MessageBox.Show("Forcing VertRGBA should only be done on levels imported with SM64e and not modified. This is NOT safe and you" +
                                                         " should back up your ROM in case. Force VertRGBA?", "Warning!", MessageBoxButtons.YesNo);

            if (warningchoice == DialogResult.No)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;
            if (!ForceOpaqueRGBA.Checked)
            {
                ROMManager.ForceVertRGBA(ForceOpaqueRGBA.Checked);
            }
            else
            {
                ROMManager.ForceVertRGBA(ForceOpaqueRGBA.Checked);
            }
            Cursor.Current = Cursors.Default;
        }
Beispiel #10
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);
                }
            }
        }
Beispiel #11
0
        private void TexFormatBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            WaitToRender = true;
            BitSizeCheck();
            if (Textures.FirstTexLoad || ROMManager.SM64ROM == null)
            {
                WaitToRender = false; return;
            }
            uint index      = (uint)TextureNumBox.SelectedIndex;
            byte FormatByte = ROMManager.SM64ROM.getByte(Textures.F5CMDArray[index][0] + 1);
            int  Format     = FormatByte >> 5;
            int  dif        = TexFormatBox.SelectedIndex - Format;

            for (uint i = 0; i < Textures.F5CMDArray[index].Length; i++)
            {
                ROMManager.SM64ROM.changeByte(Textures.F5CMDArray[index][i] + 1, (byte)(FormatByte + (dif * 32)));
            }                                                                                                    //*32 for << 5 with negative carried
            ROMManager.InitialiseModelLoad(ClientRectangle, RenderPanel, Width, Height);
            UpdateTextureNum();
            WaitToRender = false;
        }
Beispiel #12
0
    public static void RevertCI(int index)
    {
        if (!isTextureCI(index))
        {
            return;
        }
        UInt32[] F5CMDs = F5CMDArray[index]; ROM SM64ROM = ROMManager.SM64ROM;
        uint     texaddr = 0;

        for (uint i = 0; i < F5CMDs.Length; i++) //Update F5 scanline width
        {
            uint F5 = F5CMDs[i];
            if (SM64ROM.ReadFourBytes(F5 - 0x28) == 0x06000000)
            {
                UInt32 Jumpaddr = SM64ROM.getSegmentStart(0x0E) + (SM64ROM.ReadFourBytes(F5 - 0x24) & 0xFFFFFF);
                texaddr = SM64ROM.ReadFourBytes(Jumpaddr + 0x2C);
                UInt64 FDCMD = 0xFD10000000000000 | texaddr;
                SM64ROM.WriteEightBytes(F5 - 0x28, FDCMD); //write FD cmd over 06 cmd
                UInt32 NextF3CMD = ROMManager.findu32(F5, 0xF3000000, true);
                if (NextF3CMD != 0 && SM64ROM.ReadFourBytes(NextF3CMD - 8) == 0x06000000)
                {
                    SM64ROM.WriteEightBytes(NextF3CMD - 8, 0xE600000000000000);
                }
            }
        }
        byte   WidthsizeByte   = SM64ROM.getByte(F5CMDs[0] + 7);
        ushort HeightsizeShort = SM64ROM.ReadTwoBytes(F5CMDs[0] + 5);
        int    ogHeightPower   = (HeightsizeShort >> 6 & 0x0F);
        int    ogWidthPower    = (WidthsizeByte >> 4);

        if (ogWidthPower <= ogHeightPower)
        {
            ResizeTexture(index, ogWidthPower + 1, ogHeightPower, out bool isFailedtoResize);                                //double res x
        }
        else
        {
            ResizeTexture(index, ogWidthPower, ogHeightPower + 1, out bool isFailedToResize);  //double res y
        }
    }
        public static void CompileRom(bool useDefaultROM)
        {
            foreach (Form editor in editorTable.Values)
            {
                if (editor is LevelEditor)
                {
                    ((LevelEditor)editor).CurrentLevel.Save();
                }
                else if (editor is WorldEditor)
                {
                    ((WorldEditor)editor).CurrentWorld.Save();
                }
            }

            ROMManager     romMan = new ROMManager();
            SaveFileDialog SFD    = new SaveFileDialog();

            SFD.Filter = "NES ROM Images|*.nes";
            if (useDefaultROM && ProjectController.ProjectManager.CurrentProject.ROMFile.Length > 0 && File.Exists(ProjectController.ProjectManager.CurrentProject.ROMFile))
            {
                int remaining = romMan.CompileRom(ProjectController.ProjectManager.CurrentProject.ROMFile, true);
                MessageBox.Show("ROM successfully compiled.\nLevel space remaining: " + remaining + " bytes");
            }
            else if (SFD.ShowDialog() == DialogResult.OK)
            {
                if (SFD.FileName != ProjectController.ProjectManager.CurrentProject.ROMFile)
                {
                    DialogResult dr = DialogResult.None;
                    dr = MessageBox.Show("Would you like to set this ROM as your project ROM? All compiles will save to this ROM.", "Default ROM", MessageBoxButtons.YesNo);

                    if (dr == DialogResult.Yes)
                    {
                        ProjectController.ProjectManager.CurrentProject.ROMFile = SFD.FileName;
                    }
                }
                romMan.CompileRom(SFD.FileName, true);
            }
        }
Beispiel #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            for (uint j = 29; j >= 1 && j <= 29; j--) //Shift all mem back one
            {
                Vertex.OriginalVertexMem[j] = Vertex.OriginalVertexMem[j - 1];
            }
            Vertex.OriginalVertexMem[0] = new UInt32[Vertex.CurrentVertexList.Length][]; //Set up new undo level with all combos
            for (uint i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                Vertex.OriginalVertexMem[0][i]    = new UInt32[2];
                Vertex.OriginalVertexMem[0][i][0] = Vertex.CurrentVertexList[i] + 12;
                Vertex.OriginalVertexMem[0][i][1] = ROMManager.SM64ROM.ReadFourBytes(Vertex.CurrentVertexList[i] + 12); //Initial RGBA
            }
            byte   R      = (byte)Math.Round(RedNum.Value * ((decimal)Brightness.Value / 100));
            byte   G      = (byte)Math.Round(GreenNum.Value * ((decimal)Brightness.Value / 100));
            byte   B      = (byte)Math.Round(BlueNum.Value * ((decimal)Brightness.Value / 100));
            byte   A      = (byte)AlphaNum.Value;
            UInt32 colour = (uint)((R << 24) | (G << 16) | (B << 8) | A);

            for (int i = 0; i < Vertex.CurrentVertexList.Length; i++)
            {
                ROMManager.SetVertRGBA(Vertex.CurrentVertexList[i], colour);
            }
        }