Exemple #1
0
        public bool CheckCRC()
        {
            uint[] crcs = new uint[2];
            if (N64Sums.GetChecksum(crcs, GetAsBytes()))
                return (crcs[0] == _headerDMA.CRC1) && (crcs[1] == _headerDMA.CRC2);

            return false;
        }
Exemple #2
0
        private void ExportRomPayload(object sender, DoWorkEventArgs args)
        {
            //Apply changes here
            MarioKart64ElementHub.Instance.SaveKartInfo();
            MarioKart64ElementHub.Instance.SaveTrackInfo();

            byte[] newRomData = RomProject.Instance.Files[0].GetAsBytes();
            if (N64Sums.FixChecksum(newRomData))     //In the future, save this CRC to the actual project data
            {
                File.WriteAllBytes(((string)args.Argument), newRomData);
            }
            else
            {
                throw new Exception("Could not export rom!");
            }
        }
Exemple #3
0
        public bool FixCRC()
        {
            if (!IsROMLoaded)
                return false;

            //Only apply crc fix to the full rom data container, not to the separated dma table data container
            uint[] crcs = new uint[2];

            if (N64Sums.GetChecksum(crcs, GetAsBytes()))
            {
                _headerDMA.CRC1 = crcs[0];
                _headerDMA.CRC2 = crcs[1];

                HasGoodChecksum = true;

                RomUpdated(RomUpdateType.CRCFixed);

                return true;
            }
            return false;
        }
Exemple #4
0
        private void btnTestImportLevel_Click(object sender, EventArgs e)
        {
            //Step one: decode the selected level MIO0 encoded blocks
            //2: Re-encode the blocks, attach to the end of the rom, fix the table offsets
            //3: Resize rom, fix CRC, save as new one

            if (SelectedCourse == null)
            {
                return;
            }

            byte[] newRomData = new byte[0x1000000];
            Array.Copy(_romData, 0, newRomData, 0, _romData.Length);
            _romData = newRomData;

            //Take the blocks, and export them
            byte[] displayListBlock = new byte[SelectedCourse.DisplayListBlockEnd - SelectedCourse.DisplayListBlockStart];
            Array.Copy(_romData, SelectedCourse.DisplayListBlockStart,
                       displayListBlock, 0, displayListBlock.Length);

            byte[] vertexBlock = new byte[SelectedCourse.VertexBlockEnd - SelectedCourse.VertexBlockStart];
            Array.Copy(_romData, SelectedCourse.VertexBlockStart,
                       vertexBlock, 0, vertexBlock.Length);

            byte[] textureBlock = new byte[SelectedCourse.TextureBlockEnd - SelectedCourse.TextureBlockStart];
            Array.Copy(_romData, SelectedCourse.TextureBlockStart,
                       textureBlock, 0, textureBlock.Length);

            byte[] displayDecoded = Cereal64.Common.Utils.Encoding.MIO0.Decode(displayListBlock);
            byte[] displayRecoded = Cereal64.Common.Utils.Encoding.MIO0.EncodeAsRaw(displayDecoded);
            byte[] vertexDecoded  = Cereal64.Common.Utils.Encoding.MIO0.Decode(vertexBlock);
            byte[] vertexRecoded  = Cereal64.Common.Utils.Encoding.MIO0.EncodeAsRaw(vertexDecoded);

            //0xBE9160 - 0xBFFFFF
            int position = 0xBE9160;

            if (position + displayRecoded.Length < 0xC00000)
            {
                Array.Copy(displayRecoded, 0, _romData, position, displayRecoded.Length);
                SelectedCourse.DisplayListBlockStart = position;
                position += displayRecoded.Length;
                SelectedCourse.DisplayListBlockEnd = position;

                if (position % 0x10 != 0)
                {
                    position += 0x10 - (position % 0x10);
                }

                if (position + vertexBlock.Length < 0xC00000)
                {
                    Array.Copy(vertexBlock, 0, _romData, position, vertexBlock.Length);
                    SelectedCourse.VertexBlockStart = position;
                    position += vertexBlock.Length;
                    SelectedCourse.VertexBlockEnd = position;

                    //   Array.Copy(textureBlock, 0, _romData, position, textureBlock.Length);
                    //  SelectedCourse.TextureBlockStart = position;
                    //  position += textureBlock.Length;
                    //  SelectedCourse.TextureBlockEnd = position;
                }
            }

            Array.Copy(SelectedCourse.RawData, 0, _romData, SelectedCourse.FileOffset, SelectedCourse.RawDataSize);

            if (N64Sums.FixChecksum(_romData))
            {
                File.WriteAllBytes(openFileDialog.FileName + "new.z64", _romData);
            }
        }