示例#1
0
        private static string DSLinkAdding(InputFileInfo ifiFileMode, FileStream sro)   //DSLink 附加的8k信息
        {
            int x         = ifiFileMode.Buffer.Length;
            int lengthMax = 8 * 1024;

            try
            {
                BinaryWriter w = new BinaryWriter(sro);

                if (x > lengthMax)
                {
                    x = lengthMax;
                }
                w.Write(ifiFileMode.Buffer, 0, x);

                for (int i = x; i < lengthMax; i++)
                {
                    sro.WriteByte(0xff);
                }
                w.Close();

                return(null);
            }
            catch
            {
                return("ED105");
            }
        }
示例#2
0
        private void StartChange()                                                // 判断源存档格式,选取不同的转换方式
        {
            MainFormInfo  mfiMainInfo = GetMainInfo();                            // 获取主界面信息
            InputFileInfo ifiFileMode = new InputFileInfo(mfiMainInfo.InputName); // 获取源存档信息

            if (ifiFileMode.ErrorCode == null)
            {
                myAllControl(false);
                if (mfiMainInfo.PokemonChecked)
                {
                    ShowMessage(MyLanguge.Message.Pokemon + "\n");    //口袋妖怪强制转换:
                    string[] temp = WriteData.PokemonChange(ifiFileMode, mfiMainInfo.OutputName);
                    if (temp[0] == null)
                    {
                        ShowPokemonMessage(temp);
                    }
                    else
                    {
                        ShowErrorMessage(temp[0]);
                    }
                }
                else
                {
                    string[] temp = WriteData.MainChange(ifiFileMode, mfiMainInfo, UsedSize);
                    if (temp[0] == null)
                    {
                        ShowMainMessage(temp);
                    }
                    else
                    {
                        ShowErrorMessage(temp[0]);
                    }
                }
                myAllControl(true);
            }
            else
            {
                ShowErrorMessage(ifiFileMode.ErrorCode); //读取源存档时出现错误
            }
        }
示例#3
0
        private void MainTest()                                                           //2017-01-24
        {
            InputFileInfo testMode = new InputFileInfo(txtSavePath.Text + txtInput.Text); //2017-01-24

            if (testMode.ErrorCode == null)
            {
                ShowTestMap(testMode.TestCode);

                string strTest = testMode.TestString;
                if (cboMode.SelectedIndex == 0)
                {
                    strTest = strTest.Replace("128K", "256K").Replace("256K 256K", "256K");
                }
                ClearMessage();
                ShowMessage(MyLanguge.Message.UsedSize + "\n");     //有用数据可能大小:
                ShowMessage(strTest + "\n");
            }
            else
            {
                ShowErrorMessage(testMode.ErrorCode); //读取源存档时出现错误
            }
        }
示例#4
0
        public static string[] MainChange(InputFileInfo ifiFileMode, MainFormInfo mfiMainInfo, int[] UsedSize)
        {
            //分析源文件,分情况转换
            string[] sReturnStr      = new string[6];
            int      iOutputLenghAdd = new int();                   // 转换后文件附加部分大小
            bool     IsM3Gba1MB      = false;                       // 标记:目标为1M byte大小的M3格式的GBA存档
            int      iOutputLengh    = UsedSize[mfiMainInfo.Size];  // 转换后文件大小(无附加部分)
            int      InputFileSize   = ifiFileMode.Buffer.Length;

            // M3 GBA 1M byte的三个条件:目标大小为1M byte;目标格式为M3;GBA模式。此时,只读取前128K数据
            if ((iOutputLengh == 1024 * 1024) && (mfiMainInfo.CardIs == 1) && (mfiMainInfo.Mode == 1))
            {
                iOutputLengh = 128 * 1024;
                IsM3Gba1MB   = true;
            }

            int CopyFileSize = InputFileSize > iOutputLengh ? iOutputLengh : InputFileSize;

            //将源文件数据写入目标文件
            try
            {
                FileStream   sro = new FileStream(mfiMainInfo.OutputName, FileMode.Create);
                BinaryWriter w   = new BinaryWriter(sro);

                // 写入正常部分
                w.Write(ifiFileMode.Buffer, 0, CopyFileSize);

                // 把目标文件用0xff补全到需要的大小
                for (int i = CopyFileSize; i < iOutputLengh; i++)
                {
                    sro.WriteByte(0xff);
                }

                //	写入M3和DSLINK的附加部分
                if (mfiMainInfo.CardIs == 1)           // 目标存档为M3格式(CardIs=1)时,附加1K
                {
                    iOutputLenghAdd = 1024;

                    if (mfiMainInfo.M3DatChecked)
                    {
                        sReturnStr[0] = WriteData.M3AddingDAT(mfiMainInfo.M3FileName, sro, mfiMainInfo.Mode, IsM3Gba1MB);
                    }
                    else
                    {
                        sReturnStr[0] = WriteData.M3Adding(mfiMainInfo.M3ShortName, mfiMainInfo.M3LongName, sro, mfiMainInfo.Mode, IsM3Gba1MB);
                    }
                }
                else if (mfiMainInfo.CardIs == 2)      // 目标存档为DSLink格式(CardIs=2)时,附加8K
                {
                    iOutputLenghAdd = 8 * 1024;
                    sReturnStr[0]   = WriteData.DSLinkAdding(ifiFileMode, sro);
                }
                else if (mfiMainInfo.CardIs == 3)      // 目标存档为DeSmuME模拟器的dsv格式(CardIs=3)时,附加122字节
                {
                    iOutputLenghAdd = 122;
                    sReturnStr[0]   = WriteData.DeSmuMEAdding(CopyFileSize, sro);
                }
                sro.Close();

                int iTemp = iOutputLengh + iOutputLenghAdd;

                sReturnStr[1] = ifiFileMode.InputFileMode;
                sReturnStr[2] = ifiFileMode.InputFileLength.ToString();
                sReturnStr[3] = ifiFileMode.Buffer.Length.ToString();
                sReturnStr[4] = iTemp.ToString();
                sReturnStr[5] = IsM3Gba1MB.ToString();
            }
            catch
            {
                sReturnStr[0] = "ED001";
            }

            if (ifiFileMode.InputFileMode == "UnKnown")
            {
                sReturnStr[0] = "ED002";
            }

            return(sReturnStr);
        }
示例#5
0
        public static string[]  PokemonChange(InputFileInfo ifiFileMode, string OutputName)             //口袋妖怪存档特殊转换
        {
            string[] PokemonString = new string[6];
            try
            {
                int flag = new int();
                if (ifiFileMode.Buffer.Length >= 512 * 1024)
                {
                    //把数据写入新存档,默认存档为时间靠后的存档,时间靠前的也转换,但加“.old”后缀
                    byte[] buffer1 = new byte[256 * 1024];
                    byte[] buffer2 = new byte[256 * 1024];
                    for (int i = 0; i < 256 * 1024; i++)
                    {
                        buffer1[i] = ifiFileMode.Buffer[i];
                        buffer2[i] = ifiFileMode.Buffer[256 * 1024 + i];
                    }
                    //读取存档次数(4字节读取)
                    int[][] iTestTimes = new int[3][];
                    iTestTimes[0]    = new int[3]; // 最后确定的存档次数
                    iTestTimes[1]    = new int[3]; // 珍珠、钻石的存档次数
                    iTestTimes[2]    = new int[3]; // 白金的存档次数
                    iTestTimes[1][1] = buffer1[0xc0f0] + buffer1[0xc0f1] * 256 + buffer1[0xc0f2] * 256 * 256 + buffer1[0xc0f3] * 256 * 256 * 256;
                    iTestTimes[1][2] = buffer2[0xc0f0] + buffer2[0xc0f1] * 256 + buffer2[0xc0f2] * 256 * 256 + buffer2[0xc0f3] * 256 * 256 * 256;
                    iTestTimes[2][1] = buffer1[0xcf1c] + buffer1[0xcf1d] * 256 + buffer1[0xcf1e] * 256 * 256 + buffer1[0xcf1f] * 256 * 256 * 256;
                    iTestTimes[2][2] = buffer2[0xcf1c] + buffer2[0xcf1d] * 256 + buffer2[0xcf1e] * 256 * 256 + buffer2[0xcf1f] * 256 * 256 * 256;

                    if (Math.Abs(iTestTimes[1][1] - iTestTimes[1][2]) == 1)
                    {
                        PokemonString[1] = "Pokemon Platinum";
                        iTestTimes[0][1] = iTestTimes[1][1];
                        iTestTimes[0][2] = iTestTimes[1][2];
                    }
                    else if (Math.Abs(iTestTimes[2][1] - iTestTimes[2][2]) == 1)
                    {
                        PokemonString[1] = "Pokemon Pearl/Diamond";
                        iTestTimes[0][1] = iTestTimes[2][1];
                        iTestTimes[0][2] = iTestTimes[2][2];
                    }

                    flag = iTestTimes[0][1] >= iTestTimes[0][2] ? 1 : 2;
                    if (PokemonString[1] != null)
                    {
                        FileStream   sro1 = new FileStream(OutputName, FileMode.Create);
                        BinaryWriter w1   = new BinaryWriter(sro1);
                        FileStream   sro2 = new FileStream(OutputName + ".old", FileMode.Create);
                        BinaryWriter w2   = new BinaryWriter(sro2);

                        //按照存档次数判断先后顺序
                        if (flag == 1)
                        {
                            w1.Write(buffer1);
                            w2.Write(buffer2);
                        }
                        else
                        {
                            w2.Write(buffer1);
                            w1.Write(buffer2);
                        }
                        w1.Close();
                        w2.Close();
                    }
                    else
                    {
                        PokemonString[0] = "ED202";
                    }
                    PokemonString[2] = ifiFileMode.InputFileMode;
                    PokemonString[3] = iTestTimes[0][1].ToString();
                    PokemonString[4] = iTestTimes[0][2].ToString();
                    PokemonString[5] = flag.ToString();
                }
                else
                {
                    PokemonString[0] = "ED203";
                }
            }
            catch
            {
                PokemonString[0] = "ED201";
            }
            return(PokemonString);
        }