예제 #1
0
        private void bsCodeButton_Click(object sender, EventArgs e)
        {
            ulong input = ulong.Parse(bsCode.Text);
            BWL   d0    = (uint)(input >> 32);
            BWL   d1    = (uint)(input & uint.MaxValue);

            d0.w ^= 0x55;
            BWL d2 = d0.w;

            d0.w &= 0x3F;
            d1.l ^= 0xAAAAAAAA;
            d1.RotateLeftL(6);
            BWL d3 = d1.hw;

            d3.w  &= 0xF800;
            d3.w >>= 5;
            d3.w  |= d0.w;
            d3.w  &= 0x7FF;
            d1.l  -= 0x1234567;
            d2.w  &= 0x40;
            if (d2.w != 0)
            {
                d1.l += 0x7654321;
            }
            d1.l &= 0x7FFFFFF;
            BWL  d4 = d1.hw;
            bool c  = (d4.w & 1) == 1;

            d4.w >>= 1;
            if (c)
            {
                d4.w ^= 0x8810;
            }
            d4.w  ^= d1.w;
            c      = (d4.w & 1) == 1;
            d4.w >>= 1;
            if (c)
            {
                d4.w ^= 0x8810;
            }
            d4.w &= 0x7FF;
            if (d4.w != d3.w)
            {
                MessageBox.Show(this, "Invalid code.", "S3SSEdit", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (d2.w != 0)
            {
                d1.l -= 0x7654321;
                d1.l &= 0x7FFFFFF;
            }
            bsLevelNum.Value = d1.l + 1;
            LevelChanged(d1.l);
        }
예제 #2
0
        private void LevelChanged(uint levelnum)
        {
            BSMode = BSMode.Level;
            bsStageChunk1.Value = BSChunks[0] = (byte)(levelnum & 0x7F);
            BWL d0 = levelnum * 3 + 1;
            BWL d2 = new BWL(d0.w, (ushort)(d0.hw % 0x7F));

            bsStageChunk2.Value = BSChunks[1] = (byte)(d0.l % 0x7F);
            d0 = levelnum * 5 + 2;
            d2 = new BWL(d0.w, (ushort)(d0.hw % 0x7E));
            bsStageChunk3.Value = BSChunks[2] = (byte)(d0.l % 0x7E);
            d0 = levelnum * 7 + 3;
            d2 = new BWL(d0.w, (ushort)(d0.hw % 0x7D));
            bsStageChunk4.Value = BSChunks[3] = (byte)(d0.l % 0x7D);
            StageChanged();
        }
예제 #3
0
        private void GenerateCode(uint levelnum, bool lockon)
        {
            BWL a2 = levelnum;

            if (lockon)
            {
                a2.l += 0x7654321;
            }
            a2.l &= 0x7FFFFFF;
            BWL  d4 = a2.hw;
            bool c  = (d4.w & 1) == 1;

            d4.w >>= 1;
            if (c)
            {
                d4.w ^= 0x8810;
            }
            d4.w  ^= a2.w;
            c      = (d4.w & 1) == 1;
            d4.w >>= 1;
            if (c)
            {
                d4.w ^= 0x8810;
            }
            BWL d0 = d4.w;

            d0.w &= 0x3F;
            if (lockon)
            {
                d0.w |= 0x40;
            }
            d0.w ^= 0x55;
            BWL d1 = levelnum;

            d1.l  += 0x1234567;
            d1.l  &= 0x7FFFFFF;
            d4.w <<= 5;
            d4.w  &= 0xF800;
            d1.hw |= d4.w;
            d1.RotateRightL(6);
            d1.l       ^= 0xAAAAAAAA;
            bsCode.Text = (((ulong)d0.l << 32) | d1.l).ToString("000000000000");
        }
예제 #4
0
        private void bsROMButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog()
            {
                DefaultExt = "bin", Filter = "ROM Files|*.bin;*.gen;*.md|All Files|*.*"
            })
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    byte[] fc = File.ReadAllBytes(dlg.FileName);
                    if (fc.Length < 0x1A6)
                    {
                        goto fail;
                    }
                    int bsheader = Array.IndexOf(headerconsoles, Encoding.ASCII.GetString(fc, 0x100, 16));
                    if (bsheader == -1)
                    {
                        goto fail;
                    }
                    BWL serialnum = 0;
                    for (int a1 = 0x180; a1 < 0x18C; a1++)
                    {
                        if (fc[a1] >= '0' && fc[a1] <= '9')
                        {
                            serialnum = serialnum.w * 10 + (fc[a1] - '0');
                        }
                    }
                    serialnum.l &= 0x7FFF;
                    if (serialnum.w == 0)
                    {
                        goto fail;
                    }
                    BWL levelnum = serialnum.w & 0x3F;
                    int month    = Array.IndexOf(headermonths, Encoding.ASCII.GetString(fc, 0x11C, 4));
                    if (month == -1)
                    {
                        month = 0xF;
                    }
                    levelnum.w <<= 4;
                    levelnum.b  |= (byte)month;
                    levelnum.w <<= 4;
                    levelnum.b  |= (byte)((serialnum.w >> 6) & 0xF);
                    levelnum.l <<= 1;
                    levelnum.b  |= (byte)(fc[0x150] & 1);
                    levelnum.l <<= 3;
                    levelnum.b  |= (byte)((((fc[0x11A] - '0') * 10) + (fc[0x11B] - '0') - 88) & 7);
                    serialnum.RotateLeftW(6);
                    serialnum.w &= 0x1F;
                    levelnum.l <<= 5;
                    levelnum.b  |= serialnum.b;
                    levelnum.l <<= 2;
                    levelnum.b  |= (byte)((ByteConverter.ToUInt16(fc, 0x1A4) >> 3) & 3);
                    levelnum.l <<= 1;
                    if (Encoding.ASCII.GetString(fc, 0x114, 2) == "EG")
                    {
                        levelnum.b |= 1;
                    }
                    levelnum.l     <<= 1;
                    levelnum.b      |= (byte)bsheader;
                    levelnum.l      &= 0x7FFFFFF;
                    bsLevelNum.Value = levelnum.l + 1;
                    GenerateCode(levelnum.l, true);
                    LevelChanged(levelnum.l);
                }
            return;

fail:
            MessageBox.Show(this, "File is not a Sega Mega Drive/Genesis ROM.", "S3SSEdit", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }