Exemplo n.º 1
0
        byte[] temp3 = new byte[0x800000];//new byte[0x5E3000];
        unsafe private void OpenROM(string filename)
        {
            Properties.Settings.Default.LastRom = filename;
            Properties.Settings.Default.Save();
            //string symtPath = System.IO.Path.GetTempPath() + "yoshimagict\\";
            //System.IO.Directory.CreateDirectory(symtPath);
            //TODO: Perhaps delete all ym temp files if directory aleady exists? And/or analyze them?

            //mainMem.setPath(filename)
            string vstr = "";                          //Dim vstr As String = ""

            if (filename.EndsWith(".gba", true, null)) //Load entire ROM to buffer; GBA ROMs are maxed at 32 MB.
            {
                listBox1.Visible = false; textBox1.Visible = false;
                rom = Bits.OpenFile(filename);
                //rom.seek(0xA0);
                vstr = Bits.GetString(rom, 0xA0, 16);
                if (vstr != "MARIO&LUIGIUA88E")
                {
                    return;
                }
                ram = new byte[0x40000];
                loadEntireMap();
            }
            else if (filename.EndsWith(".nds", true, null))
            {
                nds a = new nds();
                a.openNDS(filename);
            }
            else if (filename.EndsWith(".cia", true, null))     //CIA is good source of unencrypted ROMs(?) (At-least at one site.)
            //M&L:Paper Jam for now.
            //No NCSD? NCCH stuff starts at 00003940.
            //0x3AE0 //exefs offset, size
            {
                byte[] ncch = new byte[0x200];
                using (FileStream a = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    a.Seek(0x3940, System.IO.SeekOrigin.Begin);                  //a.Seek(Bits.GetInt32(ncsd, 0x120) << 9, System.IO.SeekOrigin.Begin);
                    a.Read(ncch, 0, 0x200);
                    byte[] temp1 = new byte[Bits.GetInt32(ncch, 0x1A4) * 0x200]; //Load from ROM. exefs/.code in uncompressed=max 0x03F00000 bytes
                    //byte[] temp2 = new byte[Bits.GetInt32(ncch, 0x1A4) * 0x200]; //Load from Xorpad.
                    //Bits.GetInt32(ncch, 0x1A0);//ExeFS Offset
                    a.Seek(0x3940 + (Bits.GetInt32(ncch, 0x1A0)) * 0x200, SeekOrigin.Begin);
                    a.Read(temp1, 0, Bits.GetInt32(ncch, 0x1A4) * 0x200);
                    //Comp.LZSS_Decompress(temp1, 0x384A18, temp3, 0x5E3000);
                    //41BA00 = exefs size.
                    //6540 = exefs addr.
                    //6740 = .code addr. (66E0 = hashes)
                    //3E6228 = .code size
                    //3EC968 = END
                    Comp.LZSS_Decompress(temp1, 0x3E6228, temp3, 0x800000);
                    //System.IO.File.WriteAllBytes("C:/Users/Tea/Desktop/mlpjexefs.bin", temp3);
                }
            }
            else if (filename.EndsWith(".3ds", true, null))     //3DS cartridge sizes range from 1 GB to 8 GB.
            //System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
            //process.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;

            // Set the current thread to run at 'Highest' Priority
            //Thread thread = System.Threading.Thread.CurrentThread;
            //thread.Priority = ThreadPriority.Highest;

            //System.Diagnostics.Process.Start("explorer", System.IO.Path.GetTempPath() + "yoshimagict\\");
            //Shell("explorer " & System.IO.Path.GetTempPath & "yoshimagict\", AppWinStyle.NormalFocus);
            //DateTime t3, t4, t5;
            //t1 = DateTime.Now;
            //string tempROM = symtPath + "tempROM.3ds";
            //System.IO.File.Delete(tempROM);
            //Bits.fastCopy(filename, tempROM);
            //Bits.CopyFile5(filename, tempROM);
            //t2 = DateTime.Now;
            //System.IO.File.Copy(filename, tempROM);
            //byte[] z = System.IO.File.ReadAllBytes(filename);
            //System.IO.File.WriteAllBytes(tempROM, z);

            {
                byte[] ncsd = new byte[0x4000];
                using (FileStream a = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    a.Seek(0, SeekOrigin.Begin);
                    a.Read(ncsd, 0, 0x4000);// 0x330);
                    //TODO: (0x1150 = CTR-P-AYMP for EUR)
                    //TODO: CHECK IF ENCRYPTED
                    string   romDir = Path.GetDirectoryName(filename) + "\\";
                    string[] xorpad = { romDir + "00040000000D9000.Main.exefs_norm.xorpad", //Might swap this one with next.
                                        romDir + "00040000000D9000.Main.exheader.xorpad",
                                        romDir + "00040000000D9000.Main.romfs.xorpad",
                                        romDir + "00040000000D9000.Manual.romfs.xorpad",
                                        romDir + "00040000000D9000.UpdateData.romfs.xorpad" };
                    if (!File.Exists(xorpad[0]) || !File.Exists(xorpad[1]) || !File.Exists(xorpad[2]))
                    {
                        MessageBox.Show("As this 3DS ROM is encrypted, xorpads are needed to decrypt it. The first three are required for this editor, but the last two are optional.\n"
                                        + xorpad[0] + "\n" + xorpad[1] + "\n" + xorpad[2] + "\n" + xorpad[3] + "\n" + xorpad[4]
                                        );
                        return;
                    }
                    byte[] ncch = new byte[0x200];
                    a.Seek(Bits.GetInt32(ncsd, 0x120) << 9, System.IO.SeekOrigin.Begin);
                    a.Read(ncch, 0, 0x200);
                    byte[] temp1 = new byte[Bits.GetInt32(ncch, 0x1A4) * 0x200]; //Load from ROM. exefs/.code in uncompressed=max 0x03F00000 bytes
                    byte[] temp2 = new byte[Bits.GetInt32(ncch, 0x1A4) * 0x200]; //Load from Xorpad.
                    //Bits.GetInt32(ncch, 0x1A0);//ExeFS Offset
                    a.Seek((Bits.GetInt32(ncsd, 0x120) + Bits.GetInt32(ncch, 0x1A0)) * 0x200, SeekOrigin.Begin);
                    a.Read(temp1, 0, Bits.GetInt32(ncch, 0x1A4) * 0x200);
                    //t3 = DateTime.Now;
                    using (FileStream b = new FileStream(xorpad[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                        //for (int pos1 = 0; pos1 < Bits.GetInt32(ncch, 0x1A4) * 0x200; pos1 += 0x200) {
                        //a.Seek((Bits.GetInt32(ncsd, 0x120) + Bits.GetInt32(ncch, 0x1A0)) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                        ////a.Seek(Bits.GetInt32(ncsd, 0x120) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                        //a.Read(temp1, 0, 0x200);
                        b.Seek(0, SeekOrigin.Begin);
                        b.Read(temp2, 0, Bits.GetInt32(ncch, 0x1A4) * 0x200);
                        b.Close();
                    }

                    //for (int pos2 = pos1; pos2 < pos1 + 0x200; pos2++) {

                    //for (int pos2 = 0; pos2 < Bits.GetInt32(ncch, 0x1A4) * 0x200; pos2++) {
                    //    temp1[pos2] ^= temp2[pos2];
                    //}
                    //t4 = DateTime.Now;
                    //byte[] temp3 = new byte[0x5E3000];
                    fixed(byte *ptemp1 = temp1, ptemp2 = temp2)
                    {
                        byte *pt1     = ptemp1;
                        byte *pt2     = ptemp2;
                        int   pos2end = Bits.GetInt32(ncch, 0x1A4) * 0x200;

                        for (int pos2 = 0; pos2 < pos2end; pos2 += 8)
                        {
                            //TODO: Check ms time of this versus "safe" method. Show progress information on screen.
                            *((long *)(pt1 + pos2)) ^= *((long *)(pt2 + pos2)); //pos2 += 8;
                            //*((long*)(pt1 + pos2)) ^= *((long*)(pt2 + pos2));
                        }

                        //fixed (byte* ptemp3 = temp3) {
                        Comp.LZSS_Decompress(temp1, 0x384A18, temp3, 0x5E3000); //0x5E2000); //0x38437C = (U) from
                        //}
                        //File.WriteAllBytes("C:\\Users\\Tea\\Desktop\\exefstestdump(E).bin", temp3);
                    }

                    //Enemy names
                    byte[] enames  = new byte[0x1000]; //0xFA0
                    byte[] enamesX = new byte[0x1000]; //0xFA0
                    //Going straight to the table; skipping the RomFS tree. Not passing GO!, and not collecting $200.
                    //a.Seek(0x25A6B950, SeekOrigin.Begin);
                    a.Seek(0x25C3E840 - 0x940, SeekOrigin.Begin);
                    //a.Read(enames, 0, 0xFA0);// Bits.GetInt32(ncch, 0x1A4) * 0x200);
                    a.Read(enames, 0, 0x1000);
                    //a.Close();
                    using (FileStream b = new FileStream(xorpad[2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                        //b.Seek(0x25A6B950 - 0x434000, SeekOrigin.Begin); //C290
                        b.Seek(0x25C3E840 - 0x434000 - 0x940, SeekOrigin.Begin);
                        //b.Read(enamesX, 0, 0xFA0); //Bits.GetInt32(ncch, 0x1A4) * 0x200);
                        b.Read(enamesX, 0, 0x1000);
                        b.Close();
                    }

                    fixed(byte *fRom = enames, fXor = enamesX)
                    {
                        //byte* pRom = fRom;
                        //byte* pXor = fXor;
                        //0x25A6B950 - 0x434000
                        //  25A6C8F0 ; FA0
                        int pos2end = 0x1000;// 0xFA0;//Bits.GetInt32(ncch, 0x1A4) * 0x200;

                        for (int pos2 = 0; pos2 < pos2end; pos2 += 8)
                        {
                            *((long *)(fRom + pos2)) ^= *((long *)(fXor + pos2)); //pos2 += 8;
                            //*((long*)(pt1 + pos2)) ^= *((long*)(pt2 + pos2));
                        }
                    }

                    int      amt      = Bits.GetInt32(enames, 0);
                    string[] enemyStr = new string[amt];
                    while (amt-- != 0)
                    {
                        enemyStr[amt] = Bits.GetString16V(enames, Bits.GetInt32(enames, (amt + 1) * 4), 0);
                    }
                    //Enemy Data!
                    StringBuilder str = new StringBuilder(0x200);
                    for (int i = 0; i < 0xB6; i++)
                    {
                        listBox1.Items.Add(enemyStr[Bits.GetInt16(temp3, 0x54CBD8 + (i * 0x3C))]);


                        str.Append("ID #" + i.ToString("X2") + " " + enemyStr[Bits.GetInt16(temp3, 0x54CBD8 + (i * 0x3C))] + "\r\n");
                        string[] desc = { "Name Index", "??? MSBs of Name Index?", "", "",    "",      "",          "??? Seems to match entry #", "",            "",          "",                 "", "", "? (Left); Level (Right)", "HP", "Power", "Defense", "Speed",
                                          "",           "",                        "", "Exp", "Coins", "Coin Rate", "Item",                       "Item Chance", "Rare Item", "Rare Item Chance", "", "", "(Unused?)" };
                        //textBox1.Text = "";
                        for (int j = 0; j < 0x1E; j++)
                        {
                            str.Append(Bits.GetInt16(temp3, 0x54CBD8 + ((j * 2) + (i * 0x3C))).ToString("X4") + " = " + desc[j] + "\r\n");
                        }
                        str.Append("\r\n");
                    }
                    textBox1.Text = str.ToString();
                    //listBox1.SelectedIndexChanged += new System.Windows.Forms.selec;
                    //StringBuilder testt = new StringBuilder(0x4000);
                    //for (int i = 0; i < 0xB6; i++) {
                    //    testt.AppendLine(enemyStr[Bits.GetInt16(temp3, 0x54CBD8 + (i * 0x3C))]);
                    //}
                    //textBox1.Text = testt.ToString();
                    //listBox1.Items.AddRange(enemyStr);
                    //a.Seek((Bits.GetInt32(ncsd, 0x120) + Bits.GetInt32(ncch, 0x1A0)) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                    //a.Write(temp1, 0, 0x200);
                    //}
                    //b.Close();
                    //}
                    //t5 = DateTime.Now;
                    //a.Seek((Bits.GetInt32(ncsd, 0x120) + Bits.GetInt32(ncch, 0x1A0)) * 0x200, System.IO.SeekOrigin.Begin);
                    //a.Write(temp1, 0, Bits.GetInt32(ncch, 0x1A4) * 0x200);
                    a.Close();
                }
                //DateTime t6 = DateTime.Now;//.Ticks;
                //Console.WriteLine("COPY FILE: " + (t2 - t1).ToString() + "\n LOAD EXEFS: " + (t3 - t2).ToString() + "\n LOAD XORPAD: " + (t4 - t3).ToString()
                //    + "\n APPLY XORPAD: " + (t5 - t4).ToString() + "\n WRITE ROM: " + (t6 - t5).ToString() + "\n TOTAL: " + (t6 - t1).ToString());
                //Decryption stuff
                //filename.
            }
            //ElseIf filename.EndsWith(".nds", True, Nothing) Then //DS cartridge sizes range from 8 MB to 512 MB. (0.5 GB)
            //Load 0x200 bytes of header to 0x023FFE00.
            //    mainMem.setBufferSize(&H3FFFFF)
            //    mainMem.openFilePart(0, &H3FFE00, &H200)
            //    mainMem.setPos(&H3FFE00)
            //    vstr = mainMem.getString(16)
            //    'Dim DTCM(&H3FFF) as byte '0x027E0000 in BIS
            //End If
            //Properties.Settings.Default.LastRom = filename;
            //Properties.Settings.Default.Save();
            //' My.Settings.LastRomPath.Add(OpenFileDialog1.FileName)
            //' If My.Settings.LastRomPath.Count > 10 Then My.Settings.LastRomPath.RemoveAt(0)
            //' MsgBox(My.Settings.LastRomPath.ToString())

            //MessageBox.Show(vstr);
            //switch (vstr) {
            //case "MARIO&LUIGIUA88E": //SS(U)
            //    break;
            //case "MARIO&LUIGIPA88P": //SS(E)
            //case "MARIO&LUIGIJA88J": //SS(J)
            //case "M&L DEMO USAB88E": //SS Demo(U)
            //    break;
            //case "MARIO&LUIGI2ARME": //PIT(U)
            //    break;
            //case "MARIO&LUIGI2A58P": //PIT Demo(E)
            //    break;
            //case "MARIO&LUIGI3CLJE": //BIS(U)
            //    break;
            //default:
            //    break;
            //}
            //       Bitmap.p
            //Imaging.PixelFormat.Format16bppRgb555
        }
Exemplo n.º 2
0
        byte[] temp3 =new byte[0x800000];//new byte[0x5E3000];
        unsafe private void OpenROM(string filename) {
            Properties.Settings.Default.LastRom = filename;
            Properties.Settings.Default.Save();
            //string symtPath = System.IO.Path.GetTempPath() + "yoshimagict\\";
            //System.IO.Directory.CreateDirectory(symtPath);
            //TODO: Perhaps delete all ym temp files if directory aleady exists? And/or analyze them?

            //mainMem.setPath(filename)
            string vstr = ""; //Dim vstr As String = ""
            if (filename.EndsWith(".gba", true, null)) { //Load entire ROM to buffer; GBA ROMs are maxed at 32 MB.
                listBox1.Visible = false; textBox1.Visible = false;
                rom = Bits.openFile(filename);
                //rom.seek(0xA0);
                vstr = Bits.getString(rom, 0xA0, 16);
                if (vstr != "MARIO&LUIGIUA88E") { return; }
                ram = new byte[0x40000];
                loadEntireMap();
            } else if (filename.EndsWith(".nds", true, null)) {
                nds a = new nds();
                a.openNDS(filename);
            } else if (filename.EndsWith(".cia", true, null)) { //CIA is good source of unencrypted ROMs(?) (At-least at one site.)
                //M&L:Paper Jam for now.
                //No NCSD? NCCH stuff starts at 00003940.
                //0x3AE0 //exefs offset, size
                byte[] ncch = new byte[0x200];
                using (FileStream a = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    a.Seek(0x3940, System.IO.SeekOrigin.Begin); //a.Seek(Bits.getInt32(ncsd, 0x120) << 9, System.IO.SeekOrigin.Begin);
                    a.Read(ncch, 0, 0x200);
                    byte[] temp1 = new byte[Bits.getInt32(ncch, 0x1A4) * 0x200]; //Load from ROM. exefs/.code in uncompressed=max 0x03F00000 bytes
                    //byte[] temp2 = new byte[Bits.getInt32(ncch, 0x1A4) * 0x200]; //Load from Xorpad.
                    //Bits.getInt32(ncch, 0x1A0);//ExeFS Offset
                    a.Seek(0x3940 +( Bits.getInt32(ncch, 0x1A0)) * 0x200, SeekOrigin.Begin);
                    a.Read(temp1, 0, Bits.getInt32(ncch, 0x1A4) * 0x200);
                    //Comp.LZSS_Decompress(temp1, 0x384A18, temp3, 0x5E3000);
                    //41BA00 = exefs size.
                    //6540 = exefs addr.
                    //6740 = .code addr. (66E0 = hashes)
                    //3E6228 = .code size
                    //3EC968 = END
                    Comp.LZSS_Decompress(temp1, 0x3E6228, temp3, 0x800000);
                    //System.IO.File.WriteAllBytes("C:/Users/Tea/Desktop/mlpjexefs.bin", temp3);
                }
            } else if (filename.EndsWith(".3ds", true, null)) { //3DS cartridge sizes range from 1 GB to 8 GB.
                //System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
                //process.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;

                // Set the current thread to run at 'Highest' Priority
                //Thread thread = System.Threading.Thread.CurrentThread;
                //thread.Priority = ThreadPriority.Highest;

                //System.Diagnostics.Process.Start("explorer", System.IO.Path.GetTempPath() + "yoshimagict\\");
                //Shell("explorer " & System.IO.Path.GetTempPath & "yoshimagict\", AppWinStyle.NormalFocus);
                //DateTime t3, t4, t5;
                //t1 = DateTime.Now;
                //string tempROM = symtPath + "tempROM.3ds";
                //System.IO.File.Delete(tempROM);
                //Bits.fastCopy(filename, tempROM);
                //Bits.CopyFile5(filename, tempROM);
                //t2 = DateTime.Now;
                //System.IO.File.Copy(filename, tempROM);
                //byte[] z = System.IO.File.ReadAllBytes(filename);
                //System.IO.File.WriteAllBytes(tempROM, z);
                
                byte[] ncsd = new byte[0x4000];
                using (FileStream a = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
                    a.Seek(0, SeekOrigin.Begin);
                    a.Read(ncsd, 0, 0x4000);// 0x330);
                    //TODO: (0x1150 = CTR-P-AYMP for EUR)
                    //TODO: CHECK IF ENCRYPTED
                    string romDir = Path.GetDirectoryName(filename) + "\\";
                    string[] xorpad = { romDir + "00040000000D9000.Main.exefs_norm.xorpad", //Might swap this one with next.
                                        romDir + "00040000000D9000.Main.exheader.xorpad",
                                        romDir + "00040000000D9000.Main.romfs.xorpad",
                                        romDir + "00040000000D9000.Manual.romfs.xorpad",
                                        romDir + "00040000000D9000.UpdateData.romfs.xorpad"
                                      };
                    if (!File.Exists(xorpad[0]) || !File.Exists(xorpad[1]) || !File.Exists(xorpad[2])) {
                        MessageBox.Show("As this 3DS ROM is encrypted, xorpads are needed to decrypt it. The first three are required for this editor, but the last two are optional.\n"
                            + xorpad[0] + "\n" + xorpad[1] + "\n" + xorpad[2] + "\n" + xorpad[3] + "\n" + xorpad[4]
                            );
                        return;
                    }
                    byte[] ncch = new byte[0x200];
                    a.Seek(Bits.getInt32(ncsd, 0x120) << 9, System.IO.SeekOrigin.Begin);
                    a.Read(ncch, 0, 0x200);
                    byte[] temp1 = new byte[Bits.getInt32(ncch, 0x1A4) * 0x200]; //Load from ROM. exefs/.code in uncompressed=max 0x03F00000 bytes
                    byte[] temp2 = new byte[Bits.getInt32(ncch, 0x1A4) * 0x200]; //Load from Xorpad.
                    //Bits.getInt32(ncch, 0x1A0);//ExeFS Offset
                    a.Seek((Bits.getInt32(ncsd, 0x120) + Bits.getInt32(ncch, 0x1A0)) * 0x200, SeekOrigin.Begin);
                    a.Read(temp1, 0, Bits.getInt32(ncch, 0x1A4) * 0x200);
                    //t3 = DateTime.Now;
                    using (FileStream b = new FileStream(xorpad[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                        //for (int pos1 = 0; pos1 < Bits.getInt32(ncch, 0x1A4) * 0x200; pos1 += 0x200) {
                        //a.Seek((Bits.getInt32(ncsd, 0x120) + Bits.getInt32(ncch, 0x1A0)) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                        ////a.Seek(Bits.getInt32(ncsd, 0x120) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                        //a.Read(temp1, 0, 0x200);
                        b.Seek(0, SeekOrigin.Begin);
                        b.Read(temp2, 0, Bits.getInt32(ncch, 0x1A4) * 0x200);
                        b.Close();
                    }
                    //for (int pos2 = pos1; pos2 < pos1 + 0x200; pos2++) {

                    //for (int pos2 = 0; pos2 < Bits.getInt32(ncch, 0x1A4) * 0x200; pos2++) {
                    //    temp1[pos2] ^= temp2[pos2];
                    //}
                    //t4 = DateTime.Now;
                    //byte[] temp3 = new byte[0x5E3000];
                    fixed (byte* ptemp1 = temp1, ptemp2 = temp2) {
                        byte* pt1 = ptemp1;
                        byte* pt2 = ptemp2;
                        int pos2end = Bits.getInt32(ncch, 0x1A4) * 0x200;
                        for (int pos2 = 0; pos2 < pos2end; pos2 += 8) {
                            //TODO: Check ms time of this versus "safe" method. Show progress information on screen.
                            *((long*)(pt1 + pos2)) ^= *((long*)(pt2 + pos2)); //pos2 += 8; 
                            //*((long*)(pt1 + pos2)) ^= *((long*)(pt2 + pos2));
                        }
                        
                        //fixed (byte* ptemp3 = temp3) {
                        Comp.LZSS_Decompress(temp1, 0x384A18, temp3, 0x5E3000); //0x5E2000); //0x38437C = (U) from
                        //}
                        //File.WriteAllBytes("C:\\Users\\Tea\\Desktop\\exefstestdump(E).bin", temp3);
                    }
                    
                    //Enemy names
                    byte[] enames = new byte[0x1000];//0xFA0
                    byte[] enamesX = new byte[0x1000];//0xFA0
                    //Going straight to the table; skipping the RomFS tree. Not passing GO!, and not collecting $200.
                    //a.Seek(0x25A6B950, SeekOrigin.Begin);
                    a.Seek(0x25C3E840 - 0x940, SeekOrigin.Begin);
                    //a.Read(enames, 0, 0xFA0);// Bits.getInt32(ncch, 0x1A4) * 0x200);
                    a.Read(enames, 0, 0x1000);
                    //a.Close();
                    using (FileStream b = new FileStream(xorpad[2], FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                        //b.Seek(0x25A6B950 - 0x434000, SeekOrigin.Begin); //C290
                        b.Seek(0x25C3E840 - 0x434000 - 0x940, SeekOrigin.Begin);
                        //b.Read(enamesX, 0, 0xFA0); //Bits.getInt32(ncch, 0x1A4) * 0x200);
                        b.Read(enamesX, 0, 0x1000);
                        b.Close();
                    }
                    fixed (byte* fRom = enames, fXor = enamesX) {
                        //byte* pRom = fRom;
                        //byte* pXor = fXor;
                        //0x25A6B950 - 0x434000
                        //  25A6C8F0 ; FA0
                        int pos2end = 0x1000;// 0xFA0;//Bits.getInt32(ncch, 0x1A4) * 0x200;
                        for (int pos2 = 0; pos2 < pos2end; pos2 += 8) {
                            *((long*)(fRom + pos2)) ^= *((long*)(fXor + pos2)); //pos2 += 8; 
                            //*((long*)(pt1 + pos2)) ^= *((long*)(pt2 + pos2));
                        }
                    }
                    int amt = Bits.getInt32(enames, 0);
                    string[] enemyStr = new string[amt];
                    while (amt-- != 0) {
                        enemyStr[amt] = Bits.getString16V(enames, Bits.getInt32(enames, (amt + 1) * 4), 0);
                    }
                    //Enemy Data!
                    StringBuilder str = new StringBuilder(0x200);
                    for (int i = 0; i < 0xB6; i++) {
                        listBox1.Items.Add(enemyStr[Bits.getInt16(temp3, 0x54CBD8 + (i * 0x3C))]);


                        str.Append("ID #" + i.ToString("X2") + " " + enemyStr[Bits.getInt16(temp3, 0x54CBD8 + (i * 0x3C))] + "\r\n");
                        string[] desc = { "Name Index", "??? MSBs of Name Index?", "", "", "", "", "??? Seems to match entry #", "", "", "", "", "", "? (Left); Level (Right)", "HP", "Power", "Defense", "Speed",
                                "", "", "", "Exp", "Coins", "Coin Rate", "Item", "Item Chance", "Rare Item", "Rare Item Chance", "", "", "(Unused?)" };
                        //textBox1.Text = "";
                        for (int j = 0; j < 0x1E; j++) {
                            str.Append(Bits.getInt16(temp3, 0x54CBD8 + ((j * 2) + (i * 0x3C))).ToString("X4") + " = " + desc[j] + "\r\n");
                        }
                        str.Append("\r\n");
                    }
                    textBox1.Text = str.ToString();
                    //listBox1.SelectedIndexChanged += new System.Windows.Forms.selec;
                    //StringBuilder testt = new StringBuilder(0x4000);
                    //for (int i = 0; i < 0xB6; i++) {
                    //    testt.AppendLine(enemyStr[Bits.getInt16(temp3, 0x54CBD8 + (i * 0x3C))]);
                    //}
                    //textBox1.Text = testt.ToString();
                    //listBox1.Items.AddRange(enemyStr);
                    //a.Seek((Bits.getInt32(ncsd, 0x120) + Bits.getInt32(ncch, 0x1A0)) * 0x200 + pos1, System.IO.SeekOrigin.Begin);
                    //a.Write(temp1, 0, 0x200);
                    //}
                    //b.Close();
                    //}
                    //t5 = DateTime.Now;
                    //a.Seek((Bits.getInt32(ncsd, 0x120) + Bits.getInt32(ncch, 0x1A0)) * 0x200, System.IO.SeekOrigin.Begin);
                    //a.Write(temp1, 0, Bits.getInt32(ncch, 0x1A4) * 0x200);
                    a.Close();
                }
                //DateTime t6 = DateTime.Now;//.Ticks;
                //Console.WriteLine("COPY FILE: " + (t2 - t1).ToString() + "\n LOAD EXEFS: " + (t3 - t2).ToString() + "\n LOAD XORPAD: " + (t4 - t3).ToString()
                //    + "\n APPLY XORPAD: " + (t5 - t4).ToString() + "\n WRITE ROM: " + (t6 - t5).ToString() + "\n TOTAL: " + (t6 - t1).ToString());
                //Decryption stuff
                //filename.
            }
            //ElseIf filename.EndsWith(".nds", True, Nothing) Then //DS cartridge sizes range from 8 MB to 512 MB. (0.5 GB)
            //Load 0x200 bytes of header to 0x023FFE00.
            //    mainMem.setBufferSize(&H3FFFFF)
            //    mainMem.openFilePart(0, &H3FFE00, &H200)
            //    mainMem.setPos(&H3FFE00)
            //    vstr = mainMem.getString(16)
            //    'Dim DTCM(&H3FFF) as byte '0x027E0000 in BIS
            //End If
            //Properties.Settings.Default.LastRom = filename;
            //Properties.Settings.Default.Save();
            //' My.Settings.LastRomPath.Add(OpenFileDialog1.FileName)
            //' If My.Settings.LastRomPath.Count > 10 Then My.Settings.LastRomPath.RemoveAt(0)
            //' MsgBox(My.Settings.LastRomPath.ToString())

            //MessageBox.Show(vstr);
            //switch (vstr) {
            //case "MARIO&LUIGIUA88E": //SS(U)
            //    break;
            //case "MARIO&LUIGIPA88P": //SS(E)
            //case "MARIO&LUIGIJA88J": //SS(J)
            //case "M&L DEMO USAB88E": //SS Demo(U)
            //    break;
            //case "MARIO&LUIGI2ARME": //PIT(U)
            //    break;
            //case "MARIO&LUIGI2A58P": //PIT Demo(E)
            //    break;
            //case "MARIO&LUIGI3CLJE": //BIS(U)
            //    break;
            //default:
            //    break;
            //}
            //       Bitmap.p
            //Imaging.PixelFormat.Format16bppRgb555

        }