void Scan()
        {
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache();

                this.ErrorList = FELint.ScanMAP(this.MapID, ldrmap);
                if (!this.ShowAllError.Checked)
                {
                    this.ErrorList = FELint.HiddenErrorFilter(this.ErrorList);
                }

                this.EventList.DummyAlloc(this.ErrorList.Count, -1);

                if (this.ErrorList.Count > 0)
                {
                    if (this.ShowAllError.Checked)
                    {
                        this.Explain.Text = R._("すべてのエラーを表示しています。非表示にしたエラーを再表示する場合、右クリックしてください。");
                    }
                    else
                    {
                        this.Explain.Text = R._("ダブルクリックでエラーに移動します。誤検出の場合は、右クリックして、エラーを非表示にできます。");
                    }
                }
                else
                {
                    this.Explain.Text = R._("すべてのエラーが解決されました。");

                    if (Program.AsmMapFileAsmCache != null)
                    {//まれにすべてのエラーを解決しても、メインフォームが更新されない時があるので、喝入れを行う.
                        Program.AsmMapFileAsmCache.UpdateFELintCache_NoError();
                    }
                }
            }
        }
        private void ImportAllButton_Click(object sender, EventArgs e)
        {
            string title  = R._("読込むファイル名を選択してください");
            string filter = R._("SkillAssignmentClass|*.SkillAssignmentClass.tsv|All files|*");

            OpenFileDialog open = new OpenFileDialog();

            open.Title  = title;
            open.Filter = filter;

            DialogResult dr = open.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }
            if (open.FileNames.Length <= 0 || !U.CanReadFileRetry(open.FileNames[0]))
            {
                return;
            }
            string filename = open.FileNames[0];

            Program.LastSelectedFilename.Save(this, "", open);

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                bool r = ImportAllData(filename);
                if (!r)
                {
                    R.ShowStopError("インポートに失敗しました。");
                    return;
                }
            }
            U.ReSelectList(this.AddressList);
            R.ShowOK("データのインポートが完了しました。");
        }
        public void InitDiffDebug(InputFormRef.AutoPleaseWait wait, byte[] okData, byte[] ngData, DiffDebugMethod method)
        {
            this.ALabel = "OK ROM ";
            this.BLabel = "NG ROM ";
            this.CLabel = "CURRENT";
            this.CData  = (byte[])Program.ROM.Data.Clone();
            this.BData  = ngData;
            this.AData  = okData;

            this.ChangeDataList = new List <ChangeDataSt>();

            uint length = (uint)this.CData.Length;

            if (length < this.BData.Length)
            {
                length = (uint)this.BData.Length;
            }
            if (length < this.AData.Length)
            {
                length = (uint)this.AData.Length;
            }

            uint nextDoEvents = 0;

            for (uint i = 0; i < length;)
            {
                if (i > nextDoEvents)
                {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                    wait.DoEvents(R._("データ確認中 {0}/{1}", i, length));
                    nextDoEvents = i + 0xfff;
                }

                byte a = U.at(this.AData, i);
                byte b = U.at(this.BData, i);
                if (a == b)
                {//NG ROMとOK ROMが同一なので無視
                    i++;
                    continue;
                }
                byte c = U.at(this.CData, i);
                if (a == c)
                {//現状がOK ROMと同じなので無視
                    i++;
                    continue;
                }

                if (method == DiffDebugMethod.Method1)
                {
                    if (b != c)
                    {//現状がNG ROMと同じではないので無視する.
                        i++;
                        continue;
                    }
                }

                //変更点
                {
                    uint size = find_length_conflict_diffdebug(i, length, method);
                    this.ChangeDataList.Add(new ChangeDataSt(i, size, MargeMethod.NONE));
                    i += size;
                }
            }

            wait.DoEvents(R._("ヒント用にマップファイルを構築しています"));
            MakeWhatIs();

            wait.DoEvents(R._("相違点をリストにまとめています"));
            this.AddressList.DummyAlloc(this.ChangeDataList.Count, 0);
            MakeListboxContextMenuN(AddressList, AddressList_KeyDown);
            UpdateTitle();
        }
Example #4
0
        private void ImportAPButton_Click(object sender, EventArgs e)
        {
            string title  = R._("読込むファイル名を選択してください");
            string filter = R._("AP|*.romtcs.ap.bin|All files|*");

            OpenFileDialog open = new OpenFileDialog();

            open.Title  = title;
            open.Filter = filter;

            string filename;

            if (ImageFormRef.GetDragFilePath(out filename))
            {
            }
            else
            {
                DialogResult dr = open.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }
                if (open.FileNames.Length <= 0 || !U.CanReadFileRetry(open.FileNames[0]))
                {
                    return;
                }
                filename = open.FileNames[0];
                Program.LastSelectedFilename.Save(this, "", open);
            }

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                byte[] ap         = File.ReadAllBytes(filename);
                uint   ap_address = U.toOffset((uint)P4.Value);

                List <uint> pointers = U.GrepPointerAll(Program.ROM.Data, U.toPointer(ap_address), this.InputFormRef.BaseAddress, this.InputFormRef.BaseAddress + this.InputFormRef.BlockSize * this.InputFormRef.DataCount);
                if (pointers.Count >= 2)
                {//他からも参照されているので、上書き禁止
                    ap_address = 0;
                }

                string        undoname = this.Text + " AP:" + U.ToHexString(ap_address);
                Undo.UndoData undodata = Program.Undo.NewUndoData(undoname);

                uint newaddr = InputFormRef.WriteBinaryData(this
                                                            , ap_address
                                                            , ap
                                                            , InputFormRef.get_data_pos_callback_ap
                                                            , undodata
                                                            );
                if (newaddr == U.NOT_FOUND)
                {
                    Program.Undo.Rollback(undodata);
                    return;
                }
                Program.Undo.Push(undodata);

                this.P4.Value = U.toPointer(newaddr);
            }

            //ポインタの書き込み
            this.WriteButton.PerformClick();
        }
        public static void MakeAllDisASMButton(Form self, string store_filename, bool notifyUpdateMessage)
        {
            uint addr = 0x100;

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(self))
                using (StreamWriter writer = new StreamWriter(store_filename))
                {
                    writer.WriteLine("//FEBuilderGBA " + R._("逆アセンブラ"));
                    if (notifyUpdateMessage)
                    {
                        writer.WriteLine("//" + DateTime.Now.ToString("yyyyMMdd") + " " + R._("ソースコードを更新する場合は、このファイル消すか、0バイトの空ファイルにしてください。"));
                    }

                    wait.DoEvents("GrepAllStructPointers");

                    AsmMapFile        asmMapFile   = new AsmMapFile(Program.ROM);
                    DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);

                    List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache();

                    List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体
                    U.AppendAllASMStructPointersList(structlist
                                                     , ldrmap
                                                     , isPatchInstallOnly: false
                                                     , isPatchPointerOnly: false
                                                     , isPatchStructOnly: false
                                                     , isUseOtherGraphics: true
                                                     , isUseOAMSP: true
                                                     );
                    AsmMapFile.InvalidateUNUNSED(structlist);
                    UnpackBINByCode(structlist);
                    MakeFreeData(structlist);
                    asmMapFile.AppendMAP(structlist);

                    //コメントデータ
                    Program.CommentCache.MakeAddressList(structlist);
                    asmMapFile.AppendMAP(structlist);


                    {//設計をミスった。 綺麗なリストを作りたいので、もう一回読みこみなおそう...
                        AsmMapFile asmMapFile2 = new AsmMapFile(Program.ROM);
                        asmMapFile2.MakeAllDataLength(structlist);
                        AsmMapFile.InvalidateUNUNSED(structlist);
                    }

                    uint limit = (uint)Program.ROM.Data.Length;

                    int                     jisage          = 0;                             //字下げする数
                    string                  jisageSpaceData = "";                            //字下げに利用するマージンデータ
                    List <uint>             jmplabel        = new List <uint>();             //ジャンプラベル 字下げに使う
                    Dictionary <uint, uint> ldrtable        = new Dictionary <uint, uint>(); //LDR参照データがある位置を記録します. コードの末尾などにあります. 数が多くなるのでマップする.
                    AsmMapFile.MakeSwitchDataList(ldrtable, 0x100, 0);

                    wait.DoEvents(R._("データを準備中..."));
                    //探索を早くするために、データをアドレスへマッピングする. メモリを大量に使うが早い.
                    Dictionary <uint, Address> lookupStructMap = MakeAllStructMapping(structlist);
                    structlist = null;

                    uint    nextDoEvents = 0;
                    bool    prevPointer  = false; //ひとつ前がポインタだった
                    Address matchAddress;
                    DisassemblerTrumb.VM vm = new DisassemblerTrumb.VM();
                    while (addr < limit)
                    {
                        if (addr > nextDoEvents)
                        {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                            wait.DoEvents(String.Format("{0}/{1}", addr, limit));
                            nextDoEvents = addr + 0xfff;
                        }


                        if (lookupStructMap.TryGetValue(addr, out matchAddress))
                        {
                            if (matchAddress.Pointer <= addr && addr < matchAddress.Pointer + 4)
                            {//ポインタ?
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //POINTER " + matchAddress.Info);
                                addr += 4;
                            }
                            else
                            {//データ
                                uint newaddr = U.Padding2(matchAddress.Addr + matchAddress.Length);
                                uint length  = (newaddr - addr);
                                Debug.Assert(length < 10000000);
                                writer.WriteLine("{0} - {1} //{2} ({3}bytes)", U.toPointer(addr).ToString("X08"), U.toPointer(newaddr).ToString("X08"), matchAddress.Info, length);
                                addr = U.Padding4(newaddr);
                            }
                            prevPointer = true;
                            continue;
                        }

                        //LDR参照とスイッチ参照
                        if (ldrtable.ContainsKey(addr))
                        {//LDR参照のポインタデータが入っている
                            uint ldr = ldrtable[addr];
                            if (ldr == U.NOT_FOUND)
                            {//switch case
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //SWITCH CASE");
                            }
                            else
                            {
                                writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //LDRDATA");
                            }
                            addr       += 4;
                            prevPointer = true;
                            continue;
                        }

                        if (prevPointer)
                        {//ひとつ前がポインタの場合、野生のポインタをチェック
                            uint data = Program.ROM.u32(addr);
                            if (U.isPointer(data))
                            {
                                if (lookupStructMap.TryGetValue(U.toOffset(data), out matchAddress))
                                {
                                    writer.WriteLine(U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, 4) + "   //Wild POINTER " + U.ToHexString8(data) + " " + matchAddress.Info);
                                    addr += 4;
                                    continue;
                                }
                            }
                        }

                        //ひとつ前はポインタではない.
                        prevPointer = false;

                        //Disassembler
                        DisassemblerTrumb.Code code =
                            Disassembler.Disassembler(Program.ROM.Data, addr, limit, vm);
                        if (code.Type == DisassemblerTrumb.CodeType.BXJMP)
                        {//関数の出口なので字下げをすべて取り消す.
                            jisage = 0;
                            jmplabel.Clear();
                            jisageSpaceData = "";
                        }
                        else
                        {
                            for (int i = 0; i < jmplabel.Count;)
                            {
                                if (addr >= jmplabel[i])
                                {
                                    jmplabel.RemoveAt(i);
                                    jisage--;
                                    jisageSpaceData = U.MakeJisageSpace(jisage);
                                    i = 0;
                                    continue;
                                }
                                i++;
                            }
                        }

                        writer.WriteLine(jisageSpaceData + U.toPointer(addr).ToString("X08") + " " + U.MakeOPData(addr, code.GetLength()) + "   " + code.ASM.ToLower() + code.Comment);

                        if (code.Type == DisassemblerTrumb.CodeType.CONDJMP //条件式なので字下げ開始
                            )
                        {
                            uint jumplabel = U.toOffset(code.Data);
                            if (addr < jumplabel)
                            {//とび先が自分より後ろであること. 前方はすでに過ぎてしまったので字下げできない.
                                jisage++;
                                jmplabel.Add(jumplabel);
                                jisageSpaceData = U.MakeJisageSpace(jisage);
                            }
                        }
                        else if (code.Type == DisassemblerTrumb.CodeType.BXJMP)
                        {//関数の終わりなので空行を入れる.
                            writer.WriteLine("");
                        }

                        if (code.Type == DisassemblerTrumb.CodeType.LDR)
                        {//LDR参照位置を記録していく.
                            ldrtable[code.Data2] = addr;
                        }

                        addr += code.GetLength();
                    }
                }

            if (self != null)
            {
                //エクスプローラで選択しよう
                U.SelectFileByExplorer(store_filename);
            }
        }
        public static bool ApplyROMRebuild(InputFormRef.AutoPleaseWait wait, ROM vanilla, string filename, int useFreeArea, uint freeAreaMinimumSize, uint freeAreaStartAddress, string appendFreeAreaFilename, uint useShareSameData)
        {
            ToolROMRebuildApply romRebuildApply = new ToolROMRebuildApply();

            return(romRebuildApply.Apply(wait, vanilla, filename, useFreeArea, freeAreaMinimumSize, freeAreaStartAddress, appendFreeAreaFilename, useShareSameData));
        }
        bool DownloadAndExtract(string download_url, InputFormRef.AutoPleaseWait pleaseWait)
        {
            string romdir   = Path.GetDirectoryName(Program.ROM.Filename);
            string update7z = Path.GetTempFileName();

            //ダウンロード
            try
            {
                U.DownloadFile(update7z, download_url, pleaseWait);
            }
            catch (Exception ee)
            {
                BrokenDownload(R.ExceptionToString(ee));
                return(false);
            }
            if (!File.Exists(update7z))
            {
                BrokenDownload(R._("ダウンロードしたはずのファイルがありません。"));
                return(false);
            }
            if (U.GetFileSize(update7z) <= 256)
            {
                BrokenDownload(R._("ダウンロードしたファイルが小さすぎます。"));
                File.Delete(update7z);
                return(false);
            }

            pleaseWait.DoEvents("Extract...");

            if (UPSUtil.IsUPSFile(update7z))
            {
                string upsName = Path.Combine(romdir, RecomendUPSName(download_url));
                File.Copy(update7z, upsName, true);
            }
            else
            {
                //解凍
                try
                {
                    using (U.MakeTempDirectory t = new U.MakeTempDirectory())
                    {
                        string r = ArchSevenZip.Extract(update7z, t.Dir);
                        if (r != "")
                        {
                            BrokenDownload(R._("ダウンロードしたファイルを解凍できませんでした。") + "\r\n" + r);
                            return(false);
                        }
                        U.CopyDirectory1Trim(t.Dir, romdir);
                    }
                }
                catch (Exception ee)
                {
                    BrokenDownload(R.ExceptionToString(ee));
                    File.Delete(update7z);
                    return(false);
                }
            }
            File.Delete(update7z);
            pleaseWait.DoEvents("Select Vanilla ROM");

            string[] ups_files = U.Directory_GetFiles_Safe(romdir, "*.ups", SearchOption.AllDirectories);
            if (ups_files.Length <= 0)
            {
                BrokenDownload(R._("UPSファイルが見つかりませんでした"));
                return(false);
            }

            ToolWorkSupport_SelectUPSForm f = (ToolWorkSupport_SelectUPSForm)InputFormRef.JumpFormLow <ToolWorkSupport_SelectUPSForm>();

            f.OpenUPS(ups_files[0]);
            if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(false);
            }

            pleaseWait.DoEvents("UPS");
            string orignalROMFilename = f.GetOrignalFilename();

            if (orignalROMFilename == "")
            {
                return(false);
            }

            for (int i = 0; i < ups_files.Length; i++)
            {
                ROM    rom = new ROM();
                string version;
                bool   rr = rom.Load(orignalROMFilename, out version);
                if (!rr)
                {
                    R.ShowStopError("未対応のROMです。\r\ngame version={0}", version);
                    return(false);
                }

                rr = UPSUtil.ApplyUPS(rom, ups_files[i]);
                if (!rr)
                {
                    R.ShowStopError("UPSパッチを適応できませんでした" + "\r\n" + ups_files[i]);
                }

                string savegba = U.ChangeExtFilename(ups_files[i], ".gba");
                rom.Save(savegba, true);
            }

            pleaseWait.DoEvents("ReOpen...");
            MainFormUtil.ForceReopen();
            return(true);
        }
Example #8
0
        private void AutoUpdateButton_Click(object sender, EventArgs e)
        {
            if (InputFormRef.IsPleaseWaitDialog(this))
            {//2重割り込み禁止
                return;
            }

            if (Program.ROM != null && Program.ROM.Modified)
            {
                DialogResult dr = R.ShowQ("未保存の変更があるようです。\r\n保存してもよろしいですか?");
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    MainFormUtil.SaveForce(Program.MainForm());
                }
                else if (dr == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
            }

            //少し時間がかかるので、しばらくお待ちください表示.
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                //実行中のファイルは上書きできないので、アップデーターに処理を引き継がなくてはいけない。

                string updater_org_txt = System.IO.Path.Combine(Program.BaseDirectory, "config", "data", "updater.bat.txt");
                string updater         = Path.Combine(Program.BaseDirectory, "updater.bat");
                if (!File.Exists(updater_org_txt))
                {
                    BrokenDownload(R._("アップデーターのバッチファイルがありません。\r\n{0}", updater_org_txt));
                    this.Close();
                    return;
                }

                try
                {
                    File.Copy(updater_org_txt, updater, true);
                }
                catch (Exception ee)
                {
                    BrokenDownload(R._("アップデーターのバッチファイルをコピーできませんでした。\r\n{0}", ee.ToString()));
                    this.Close();
                    return;
                }

                if (!File.Exists(updater))
                {
                    BrokenDownload(R._("アップデーターのバッチファイルをコピーできませんでした。\r\n{0}", updater));
                    this.Close();
                    return;
                }


                string update7z = Path.Combine(Program.BaseDirectory, "dltemp_" + DateTime.Now.Ticks.ToString() + ".7z");

                //ダウンロード
                try
                {
                    DownloadNewVersion(update7z, this.URL, this.Version, pleaseWait);
                }
                catch (Exception ee)
                {
                    BrokenDownload(ee);
                    this.Close();
                    return;
                }
                if (!File.Exists(update7z))
                {
                    BrokenDownload(R._("ダウンロードしたはずのファイルがありません。"));
                    this.Close();
                    return;
                }
                if (U.GetFileSize(update7z) < 2 * 1024 * 1024)
                {
                    BrokenDownload(R._("ダウンロードしたファイルが小さすぎます。"));
                    this.Close();
                    return;
                }

                pleaseWait.DoEvents("Extract...");

                //解凍
                try
                {
                    string _update = Path.Combine(Program.BaseDirectory, "_update");
                    U.mkdir(_update);
                    string r = ArchSevenZip.Extract(update7z, _update);
                    if (r != "")
                    {
                        BrokenDownload(R._("ダウンロードしたファイルを解凍できませんでした。") + "\r\n" + r);
                        this.Close();
                        return;
                    }
                }
                catch (Exception ee)
                {
                    BrokenDownload(ee);
                    this.Close();
                    return;
                }

                string updateNewVersionFilename = Path.Combine(Program.BaseDirectory, "_update", "FEBuilderGBA.exe");
                if (!File.Exists(updateNewVersionFilename))
                {
                    BrokenDownload(R._("ダウンロードしたファイルを解凍した中に、実行ファイルがありませんでした。"));
                    this.Close();
                    return;
                }
                if (U.GetFileSize(updateNewVersionFilename) < 2 * 1024 * 1024)
                {
                    BrokenDownload(R._("ダウンロードしたファイルを解凍した中にあった、実行ファイルが小さすぎます。"));
                    this.Close();
                    return;
                }

                pleaseWait.DoEvents("GO!");

                int    pid  = Process.GetCurrentProcess().Id;
                string args = pid.ToString();
                try
                {
                    Process p = new Process();
                    p.StartInfo.FileName        = updater;
                    p.StartInfo.Arguments       = args;
                    p.StartInfo.UseShellExecute = false;
                    p.Start();
                }
                catch (Exception ee)
                {
                    BrokenDownload(ee);
                    return;
                }
            }

            Application.Exit();

            this.Close();
            this.DialogResult = System.Windows.Forms.DialogResult.Abort;
        }
Example #9
0
        void DownloadNewVersionByGithub(string save_filename, string download_url, string version, InputFormRef.AutoPleaseWait pleaseWait)
        {
            string durl = download_url;

            Log.Notify("download url:{0}", durl);
            U.HttpDownload(save_filename, durl, download_url, pleaseWait);
        }
Example #10
0
        StringBuilder ExportALL(InputFormRef.AutoPleaseWait pleaseWait, string basedir, bool isItemFont, bool isUserFontOnly, Dictionary <uint, string> codeBMap)
        {
            List <Address> list = new List <Address>();

            MakeAllDataLengthInner(isItemFont, ref list, codeBMap);
            PatchUtil.PRIORITY_CODE priorityCode = PatchUtil.SearchPriorityCode();
            Color         bgcolor = GetFontColor(isItemFont);
            StringBuilder sb      = new StringBuilder();

            foreach (Address a in list)
            {
                if (a.DataType != FEBuilderGBA.Address.DataTypeEnum.FONTCN)
                {
                    continue;
                }

                if (isUserFontOnly &&
                    a.Addr <= Program.ROM.RomInfo.font_default_end)
                {//規定のフォント
                    continue;
                }

                int    width;
                byte[] fontbyte = ReadFontDataZH(a.Addr, out width);
                if (width == 0)
                {
                    continue;
                }
                string ch = GetFontCharFromExportName(a.Info);
                if (ch == "")
                {
                    continue;
                }
                uint   hex  = U.ConvertMojiCharToUnitFast(ch, priorityCode);
                string type = (isItemFont ? "item" : "text");

                Bitmap bitmap;
                if (isItemFont)
                {
                    bitmap = ImageUtil.ByteToImage4ZH(width + 1, 0xD, fontbyte, 0, bgcolor);
                    bitmap = ConvertVanillaFontSizeBitmap(bitmap, 2);
                }
                else
                {
                    bitmap = ImageUtil.ByteToImage4ZH(width, 0xD, fontbyte, 0, bgcolor);
                    bitmap = ConvertVanillaFontSizeBitmap(bitmap, 1);
                }

                ImageUtil.BlackOutUnnecessaryColors(bitmap, 1);
                string name          = U.escape_filename(a.Info) + "_" + U.ToHexString(hex);
                string font_filename = Path.Combine(basedir, name + ".png");
                try
                {
                    U.BitmapSave(bitmap, font_filename);
                }
                catch (Exception)
                {//このOSではこの文字のファイル名は使えないので削ります
                    string trimName = U.substr(a.Info, 0, a.Info.Length - 2);
                    name          = trimName + "_" + U.ToHexString(hex);
                    font_filename = Path.Combine(basedir, name + ".png");
                    U.BitmapSave(bitmap, font_filename);
                }

                bitmap.Dispose();

                sb.Append(ch);
                sb.Append("\t");
                sb.Append(type);
                sb.Append("\t");
                sb.Append(width);
                sb.Append("\t");
                sb.AppendLine(Path.GetFileName(font_filename));
            }

            return(sb);
        }
        private void SelectROMButton_Click(object sender, EventArgs e)
        {
            if (this.BackupList.SelectedIndex < 0 || this.BackupList.SelectedIndex >= this.FindBackup.Files.Count)
            {
                return;
            }
            FindBackup.FileInfo ng_rom_info;
            FindBackup.FileInfo ok_rom_info;
            if (this.BackupList.SelectedIndex < 1)
            {
                //R.ShowOK("直前のバックアップだと、現在のROMとの2点DIFFだけとなり、精度が落ちます。");

                ng_rom_info          = new FindBackup.FileInfo();
                ng_rom_info.FilePath = Program.ROM.Filename;
                ng_rom_info.Date     = File.GetLastWriteTime(Program.ROM.Filename);
                if (!CheckOrignalROMIfUPS(ng_rom_info))
                {
                    return;
                }

                ok_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex];
                if (!CheckOrignalROMIfUPS(ok_rom_info))
                {
                    return;
                }
            }
            else
            {
                ng_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex - 1];
                if (!CheckOrignalROMIfUPS(ng_rom_info))
                {
                    return;
                }

                ok_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex];
                if (!CheckOrignalROMIfUPS(ok_rom_info))
                {
                    return;
                }
            }


            ToolDiffDebugSelectMethodPopup q = (ToolDiffDebugSelectMethodPopup)InputFormRef.JumpFormLow <ToolDiffDebugSelectMethodPopup>();

            q.Init(ng_rom_info.FilePath, ok_rom_info.FilePath);
            q.ShowDialog();
            if (q.DialogResult != System.Windows.Forms.DialogResult.Yes)
            {//ユーザーキャンセル.
                return;
            }
            ToolThreeMargeForm.DiffDebugMethod method = q.GetMethod();

            ToolThreeMargeForm f;

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                byte[] ng_rom = MainFormUtil.OpenROMToByte(ng_rom_info.FilePath, this.OrignalFilename.Text);
                byte[] ok_rom = MainFormUtil.OpenROMToByte(ok_rom_info.FilePath, this.OrignalFilename.Text);

                if (ng_rom.Length <= 0)
                {
                    return;
                }
                if (ok_rom.Length <= 0)
                {
                    return;
                }

                f = (ToolThreeMargeForm)InputFormRef.JumpFormLow <ToolThreeMargeForm>();
                f.InitDiffDebug(wait, ok_rom, ng_rom, method);
            }
            if (!f.IsConflictData())
            {
                R.ShowWarning("相違点がありません。\r\n比較条件を変えてください。\r\n比較条件を変えても変わらない場合、比較対象のROMを見直してください。");
                return;
            }
            f.Show();
        }
Example #12
0
        private void ApplyUPSPatchButton_Click(object sender, EventArgs e)
        {
            if (InputFormRef.IsPleaseWaitDialog(this))
            {//2重割り込み禁止
                return;
            }

            string errorMessage = MainFormUtil.CheckOrignalROM(OrignalFilename.Text);

            if (errorMessage != "")
            {
                R.ShowStopError("無改造ROMを指定してください。" + "\r\n" + errorMessage);
                OrignalFilename.ErrorMessage = R._("無改造ROMを指定してください。" + "\r\n" + errorMessage);
                return;
            }
            OrignalFilename.ErrorMessage = "";

            ROM    rom = new ROM();
            string version;
            bool   r = rom.Load(OrignalFilename.Text, out version);

            if (!r)
            {
                R.ShowStopError("未対応のROMです。\r\ngame version={0}", version);
                return;
            }

            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                r = UPSUtil.ApplyUPS(rom, this.UPSFilename);
                if (!r)
                {
                    R.ShowStopError("UPSパッチを適応できませんでした");
                    return;
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();

            if (this.UseReOpen)
            {//メインフォームを開きなおさないといけない場合
                MainFormUtil.ReOpenMainForm();
            }

            if (this.IsSaveFileCheckBox.Checked)
            {
                string newFilename = U.ChangeExtFilename(this.UPSFilename, ".gba");
                rom.Save(newFilename, false);

                //エクスプローラで選択しよう
                U.SelectFileByExplorer(newFilename);

                //保存したROMを開く.
                Program.LoadROM(newFilename, this.ForceVersion);
            }
            else
            {
                //保存しない場合、メモリ上の存在になる.
                Program.LoadVirtualROM(rom, this.UPSFilename);
            }
        }
Example #13
0
        void AutoSearch()
        {
            if (InputFormRef.IsPleaseWaitDialog(this))
            {//2重割り込み禁止
                return;
            }
            if (this.OtherROMData == null ||
                this.OtherROMData.Length <= 0)
            {//別のROMを読込んでいないので探索不可能
                SearchCurrentROM();
                return;
            }
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                bool isNearMatch = false;
                int  lastNearMatchSlideComboBox             = -1;
                int  lastNearMatchTestMatchDataSizeComboBox = -1;
                int  lastNearMatchGrepType = -1;
                HideError();

                uint addr = U.atoh(Address.Text);
                if (addr == 0)
                {
                    return;
                }

                bool isCode = (addr % 4) == 1;
                if (isCode)
                {
                    addr = addr - 1;
                    DataType.SelectedIndex = 1;//ASM
                }

                addr = U.ChangeEndian32(addr);
                SearchCurrentROM();

                if (UseASMMAPCheckBox.Checked)
                {
                    if (SearchASMMap())
                    {
                        return;
                    }
                }

                uint autoMatictrackLevel = U.atoh(AutomaticTrackingComboBox.Text);
                if (autoMatictrackLevel == 0)
                {//自動追跡しない
                    Search();

                    if (IsDataFound(out isNearMatch))
                    {//見つかった
                        return;
                    }
                    return;
                }

                //自動追跡のため初期化
                SlideComboBox.SelectedIndex             = 0; //スキップしない.
                TestMatchDataSizeComboBox.SelectedIndex = 0; //ディフォルトは32バイト
                Search();

                if (this.OtherROMData == null)
                {
                    return;
                }

                //自動追跡初期化
                pleaseWait.DoEvents(R._("MakeOtherROMLDRFuncList"));
                {
                    uint address = U.atoh(Address.Text);
                    uint pointer = U.toPointer(address);
                    this.OtherROMLDRFuncList = MakeOtherROMLDRFuncList(pointer);
                }

                int maxDeepSearch = (int)((autoMatictrackLevel >> 8) & 0xF) + 2;
                int maxSkipSearch = (int)(autoMatictrackLevel & 0xF) + 1;
                for (int deepSearch = 1; deepSearch < maxDeepSearch; deepSearch++)
                {
                    pleaseWait.DoEvents(R._("自動追跡 {0}/{1}", deepSearch * maxSkipSearch, maxDeepSearch * maxSkipSearch));

                    TestMatchDataSizeComboBox.SelectedIndex = deepSearch; //マッチサイズを少しだけ下げる.
                    GrepType.SelectedIndex = 0;                           //パターンマッチしない
                    if (IsDataFound(out isNearMatch))
                    {                                                     //見つかった
                        return;
                    }
                    if (isNearMatch && lastNearMatchSlideComboBox == -1)
                    {//惜しいマッチをした場合記録する.
                        lastNearMatchSlideComboBox             = SlideComboBox.SelectedIndex;
                        lastNearMatchTestMatchDataSizeComboBox = TestMatchDataSizeComboBox.SelectedIndex;
                        lastNearMatchGrepType = GrepType.SelectedIndex;
                    }

                    GrepType.SelectedIndex = 1; //パターンマッチ
                    if (IsDataFound(out isNearMatch))
                    {                           //見つかった
                        return;
                    }
                    if (isNearMatch && lastNearMatchSlideComboBox == -1)
                    {//惜しいマッチをした場合記録する.
                        lastNearMatchSlideComboBox             = SlideComboBox.SelectedIndex;
                        lastNearMatchTestMatchDataSizeComboBox = TestMatchDataSizeComboBox.SelectedIndex;
                        lastNearMatchGrepType = GrepType.SelectedIndex;
                    }

                    for (int skipSearch = 1; skipSearch < maxSkipSearch; skipSearch++)
                    {
                        pleaseWait.DoEvents(R._("自動追跡 {0}/{1}", deepSearch * maxSkipSearch + skipSearch, maxDeepSearch * maxSkipSearch));

                        //Nバイトスキップ
                        SlideComboBox.SelectedIndex = skipSearch;
                        if (IsDataFound(out isNearMatch))
                        {//見つかった
                            return;
                        }
                        if (isNearMatch && lastNearMatchSlideComboBox == -1)
                        {//惜しいマッチをした場合記録する.
                            lastNearMatchSlideComboBox             = SlideComboBox.SelectedIndex;
                            lastNearMatchTestMatchDataSizeComboBox = TestMatchDataSizeComboBox.SelectedIndex;
                            lastNearMatchGrepType = GrepType.SelectedIndex;
                        }
                    }
                }

                //どこにもマッチしなかった場合、
                //惜しいマッチをしていた場合、それを復元する.
                if (lastNearMatchSlideComboBox != -1)
                {//惜しいマッチをした場合記録する.
                    SlideComboBox.SelectedIndex             = lastNearMatchSlideComboBox;
                    TestMatchDataSizeComboBox.SelectedIndex = lastNearMatchTestMatchDataSizeComboBox;
                    GrepType.SelectedIndex = lastNearMatchGrepType;
                }
            }
        }
Example #14
0
        public void ExportallText(Form self
                                  , string writeTextFileName
                                  , string tralnslate_from, string tralnslate_to
                                  , string rom_from, string rom_to
                                  , bool isModifiedTextOnly
                                  , bool isOneLiner
                                  )
        {
            //少し時間がかかるので、しばらくお待ちください表示.
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(self))
            {
                FETextDecode decode = new FETextDecode();

                Dictionary <string, string> transDic = TranslateTextUtil.MakeFixedDic(tralnslate_from, tralnslate_to, rom_from, rom_to);
                if (ExportFilterArray != null)
                {
                    using (StreamWriter writer = new StreamWriter(writeTextFileName))
                    {
                        List <U.AddrResult> list = TextForm.MakeItemList();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!ExportFilterArray.ContainsKey(i))
                            {
                                continue;
                            }
                            string text = decode.Decode((uint)i);

                            pleaseWait.DoEvents("Text:" + U.To0xHexString((uint)i));
                            ExportText(writer, (uint)i, text, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                        }
                    }
                    return;
                }

                using (StreamWriter writer = new StreamWriter(writeTextFileName))
                {
                    //テキスト
                    {
                        List <U.AddrResult> list = TextForm.MakeItemList();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (ExportFilterArray != null && ExportFilterArray[i] != false)
                            {
                                continue;
                            }
                            string text = decode.Decode((uint)i);

                            pleaseWait.DoEvents("Text:" + U.To0xHexString((uint)i));
                            ExportText(writer, (uint)i, text, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                        }
                    }

                    //メニュー1
                    if (Program.ROM.RomInfo.is_multibyte)
                    {
                        List <U.AddrResult> menuDefineList = MenuDefinitionForm.MakeListAll();
                        for (int n = 0; n < menuDefineList.Count; n++)
                        {
                            if (!U.isSafetyOffset(menuDefineList[n].addr + 8))
                            {
                                continue;
                            }
                            uint p = menuDefineList[n].addr + 8;
                            if (!U.isSafetyOffset(Program.ROM.p32(p)))
                            {
                                continue;
                            }
                            List <U.AddrResult> list = MenuCommandForm.MakeListPointer(p);
                            for (int i = 0; i < list.Count; i++)
                            {
                                if (!U.isSafetyOffset(list[i].addr))
                                {
                                    continue;
                                }
                                uint   text_pointer = list[i].addr + 0;
                                uint   textid       = Program.ROM.u32(text_pointer);
                                string str          = FETextDecode.Direct(textid);
                                if (str.Trim() == "")
                                {
                                    continue;
                                }

                                pleaseWait.DoEvents("Menu:" + U.To0xHexString(textid));
                                ExportText(writer, U.toPointer(text_pointer), str, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                            }
                        }
                    }

                    //地形
                    if (Program.ROM.RomInfo.is_multibyte)
                    {
                        List <U.AddrResult> list = MapTerrainNameForm.MakeList();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!U.isSafetyOffset(list[i].addr))
                            {
                                continue;
                            }
                            uint   text_pointer = list[i].addr + 0;
                            uint   textid       = Program.ROM.u32(text_pointer);
                            string str          = FETextDecode.Direct(textid);
                            if (str.Trim() == "")
                            {
                                continue;
                            }

                            pleaseWait.DoEvents("Terrain:" + U.To0xHexString(textid));
                            ExportText(writer, U.toPointer(text_pointer), str, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                        }
                    }

                    //サウンドルーム
                    //FE7のサウンドルームは、日本語直地
                    if (Program.ROM.RomInfo.is_multibyte && Program.ROM.RomInfo.version == 7)
                    {
                        List <U.AddrResult> list = SoundRoomForm.MakeList();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!U.isSafetyOffset(list[i].addr))
                            {
                                continue;
                            }
                            uint   text_pointer = list[i].addr + 12;
                            uint   textid       = Program.ROM.u32(text_pointer);
                            string str          = FETextDecode.Direct(textid);
                            if (str.Trim() == "")
                            {
                                continue;
                            }

                            pleaseWait.DoEvents("SoundRoom:" + U.To0xHexString(textid));
                            ExportText(writer, U.toPointer(text_pointer), str, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                        }
                    }
                    //その他文字列
                    {
                        List <U.AddrResult> list = OtherTextForm.MakeList();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!U.isSafetyOffset(list[i].addr))
                            {
                                continue;
                            }
                            uint   text_pointer = list[i].addr + 0;
                            uint   p_str        = Program.ROM.p32(text_pointer);
                            string str          = Program.ROM.getString(p_str);
                            if (str.Trim() == "")
                            {
                                continue;
                            }

                            pleaseWait.DoEvents("Other:" + U.To0xHexString(p_str));
                            ExportText(writer, U.toPointer(text_pointer), str, tralnslate_from, tralnslate_to, transDic, isModifiedTextOnly, isOneLiner);
                        }
                    }
                }
            }
        }
Example #15
0
        public void ImportAllText(Form self, string filename, Undo.UndoData undodata)
        {
            //少し時間がかかるので、しばらくお待ちください表示.
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(self))
            {
                uint     id    = U.NOT_FOUND;
                string[] lines = File.ReadAllLines(filename);

                //上書きするテキスト領域を再利用リストに突っ込む
                List <Address> list = new List <FEBuilderGBA.Address>();
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i];
                    if (U.IsCommentSlashOnly(line) || U.OtherLangLine(line))
                    {
                        continue;
                    }
                    line = U.ClipComment(line);
                    if (line.Length <= 0)
                    {
                        continue;
                    }

                    if (!TranslateTextUtil.IsTextIDCode(line))
                    {
                        continue;
                    }

                    AddRecycle(id, list);

                    //次のテキスト
                    id = U.atoh(U.substr(line, 1));
                }
                this.Recycle.AddRecycle(list);
                this.Recycle.RecycleOptimize();

                id = U.NOT_FOUND;
                string text = "";
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i];
                    if (U.IsCommentSlashOnly(line) || U.OtherLangLine(line))
                    {
                        continue;
                    }
                    line = U.ClipComment(line);
                    if (line.Length <= 0)
                    {
                        continue;
                    }

                    if (!TranslateTextUtil.IsTextIDCode(line))
                    {
                        text += line + "\r\n";
                        continue;
                    }

                    //次の数字があったので、現在のテキストの書き込み.
                    pleaseWait.DoEvents("Write:" + U.To0xHexString(id));
                    WriteText(id, text, undodata);

                    //次のテキスト
                    id   = U.atoh(U.substr(line, 1));
                    text = "";
                }

                //最後のデータ
                WriteText(id, text, undodata);
            }
        }
Example #16
0
        string Grep(string filename, string searchFunction, string searchReg, int allowNumber)
        {
            bool resultOptionHideFunctionCall = ResultOptionHideFunctionCallCheckBox.Checked;
            bool resultOptionHideUnknowArg    = ResultOptionHideUnknowArgCheckBox.Checked;

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                wait.DoEvents(R._("データを準備中..."));

                StringBuilder ret          = new StringBuilder();
                int           regLine      = 0;
                int           nextDoEvents = 0;

                //面倒だから全部読む.
                string[] lines = File.ReadAllLines(filename);

                for (int i = 0; i < lines.Length; i++)
                {
                    if (i > nextDoEvents)
                    {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                        wait.DoEvents(String.Format("{0}/{1}", i, lines.Length));
                        nextDoEvents = i + 0xfff;
                    }
                    string line = lines[i];

                    if (regLine <= 0)
                    {
                        if (IsSearchRegister(line, searchReg))
                        {
                            if (resultOptionHideUnknowArg)
                            {
                                if (line.IndexOf('(') > 0)
                                {
                                    continue;
                                }
                            }
                            regLine = i;
                        }
                    }
                    else
                    {
                        if (line.IndexOf(searchFunction) >= 0)
                        {
                            int limit = i;
                            if (resultOptionHideFunctionCall)
                            {
                                limit--;
                            }
                            for (int n = regLine; n <= limit; n++)
                            {
                                ret.AppendLine(lines[n].Trim());
                            }
                            //区切りとして改行をいれる
                            ret.AppendLine();

                            regLine = 0;
                        }
                        else if (IsSearchRegister(line, searchReg))
                        {//もっと近場に 探しているレジスタ参照があった
                            if (resultOptionHideUnknowArg)
                            {
                                if (line.IndexOf('(') > 0)
                                {
                                    regLine = 0;
                                    continue;
                                }
                            }
                            regLine = i;
                        }
                        else if (i - regLine >= allowNumber)
                        {                      //範囲を超えたので没にする
                            i       = regLine; //regのあった次の行に戻る.
                            regLine = 0;
                        }
                    }
                }
                return(ret.ToString());
            }
        }
Example #17
0
 void DownloadNewVersion(string save_filename, string download_url, string version, InputFormRef.AutoPleaseWait pleaseWait)
 {
     if (download_url.IndexOf("getuploader") > 0)
     {
         DownloadNewVersionByGetUploader(save_filename, download_url, version, pleaseWait);
     }
     else
     {
         DownloadNewVersionByGithub(save_filename, download_url, version, pleaseWait);
     }
 }
Example #18
0
        public void ImportFont(Form self, string FontROMTextBox, bool FontAutoGenelateCheckBox, Font ttf)
        {
            string filename = FontROMTextBox;

            this.YourROM = new ROM();

            this.ProcessedFont      = new Dictionary <string, bool>();
            this.MyselfPriorityCode = PatchUtil.SearchPriorityCode();

            string version;

            if (this.YourROM.Load(filename, out version))
            {//フォントを取るようのROM
                this.YourPriorityCode = PatchUtil.SearchPriorityCode(this.YourROM);
            }
            else
            {
                this.YourROM = null;
            }

            if (FontAutoGenelateCheckBox)
            {//自動生成する
                this.UseAutoGenFont = ttf;
            }
            else
            {//自動生成しない
                this.UseAutoGenFont = null;
            }
            FETextDecode decode = new FETextDecode();


            //少し時間がかかるので、しばらくお待ちください表示.
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(self))
            {
                this.UndoData = Program.Undo.NewUndoData("FONT Import");

                //文字列からフォントを探索
                {
                    List <U.AddrResult> list = TextForm.MakeItemList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        string text = decode.Decode((uint)i);
                        pleaseWait.DoEvents("String:" + U.To0xHexString((uint)i));

                        FontImporter(text);
                    }
                }
                //メニュー1
                if (Program.ROM.RomInfo.is_multibyte())
                {
                    List <U.AddrResult> menuDefineList = MenuDefinitionForm.MakeListAll();
                    for (int n = 0; n < menuDefineList.Count; n++)
                    {
                        if (!U.isSafetyOffset(menuDefineList[n].addr + 8))
                        {
                            continue;
                        }
                        uint p = menuDefineList[n].addr + 8;
                        if (!U.isSafetyOffset(Program.ROM.p32(p)))
                        {
                            continue;
                        }
                        List <U.AddrResult> list = MenuCommandForm.MakeListPointer(p);
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (!U.isSafetyOffset(list[i].addr))
                            {
                                continue;
                            }
                            uint   textid = Program.ROM.u32(list[i].addr + 0);
                            string str    = FETextDecode.Direct(textid);

                            pleaseWait.DoEvents("Menu:" + U.To0xHexString(textid));
                            FontImporter(str);
                        }
                    }
                }

                //地形
                if (Program.ROM.RomInfo.is_multibyte())
                {
                    List <U.AddrResult> list = MapTerrainNameForm.MakeList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (!U.isSafetyOffset(list[i].addr))
                        {
                            continue;
                        }
                        uint   textid = Program.ROM.u32(list[i].addr + 0);
                        string str    = FETextDecode.Direct(textid);

                        pleaseWait.DoEvents("Terrain:" + U.To0xHexString(textid));
                        FontImporter(str);
                    }
                }

                //サウンドルーム
                //FE7のサウンドルームは、日本語直地
                if (Program.ROM.RomInfo.is_multibyte() && Program.ROM.RomInfo.version() == 7)
                {
                    List <U.AddrResult> list = SoundRoomForm.MakeList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (!U.isSafetyOffset(list[i].addr))
                        {
                            continue;
                        }
                        uint   textid = Program.ROM.u32(list[i].addr + 12);
                        string str    = FETextDecode.Direct(textid);

                        pleaseWait.DoEvents("SoundRoom:" + U.To0xHexString(textid));
                        FontImporter(str);
                    }
                }
                //その他文字列
                {
                    List <U.AddrResult> list = OtherTextForm.MakeList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (!U.isSafetyOffset(list[i].addr))
                        {
                            continue;
                        }

                        uint   p_str = Program.ROM.p32(list[i].addr);
                        string str   = Program.ROM.getString(p_str);

                        pleaseWait.DoEvents("Other:" + U.To0xHexString(p_str));
                        FontImporter(str);
                    }
                }

                Program.Undo.Push(this.UndoData);
            }
        }
Example #19
0
        void DownloadNewVersionByGetUploader(string save_filename, string download_url, string version, InputFormRef.AutoPleaseWait pleaseWait)
        {
            string url      = download_url;
            string contents = U.HttpGet(url);

            Log.Debug("front page:{0}", contents);
            contents = U.skip(contents, "name=\"token\"");
            string token = U.cut(contents, "value=\"", "\"");

            token = Uri.UnescapeDataString(token);
            token = U.unhtmlspecialchars(token);
            if (token.Length <= 8)
            {
                Log.Error("token NOT FOUND:", token);
                return;
            }

            Dictionary <string, string> args = new Dictionary <string, string>();

            args["token"] = token;
            contents      = U.HttpPost(download_url, args, download_url);
            Log.Debug("download page:{0}", contents);
            contents = U.skip(contents, "http-equiv=\"refresh\"");
            string durl = U.cut(contents, "URL=", "\"");

            durl = Uri.UnescapeDataString(durl);
            durl = U.unhtmlspecialchars(durl);
            if (durl == "" && durl.IndexOf("http") < 0)
            {
                Log.Error("download url NOT FOUND:{0}", durl);
                return;
            }

            Log.Notify("download url:{0}", durl);
            U.HttpDownload(save_filename, durl, download_url, pleaseWait);
        }
        private void ImportButton_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = ImageFormRef.ImportFilenameDialog(this);

            if (bitmap == null)
            {
                return;
            }
            int width         = 480;
            int height        = 320;
            int palette_count = 4;

            if (bitmap.Width != width || bitmap.Height != height)
            {
                R.ShowStopError("画像サイズが正しくありません。\r\nWidth:{2} Height:{3} でなければなりません。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", bitmap.Width, bitmap.Height, width, height);
                return;
            }
            int bitmap_palette_count = ImageUtil.GetPalette16Count(bitmap);

            if (bitmap_palette_count > palette_count)
            {
                R.ShowStopError("パレット数が正しくありません。\r\n{1}種類以下(16色*{1}種類) でなければなりません。\r\n\r\n選択された画像のパレット種類:{0}種類", bitmap_palette_count, palette_count);
                return;
            }

            //画像
            byte[] image = ImageUtil.ImageToByte16Tile(bitmap, width, height);

            //パレットマップの作成
            byte[] palettemap;
            string error_string = ImageUtil.ImageToPaletteMap(bitmap, width, height, palette_count, out palettemap);

            if (error_string != "")
            {
                R.ShowStopError(error_string);
                return;
            }

            //パレット
            byte[] palette = ImageUtil.ImageToPalette(bitmap, palette_count);

            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                //画像等データの書き込み
                Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                ImageFormRef.WriteImageData(this, this.WMImage
                                            , Program.ROM.RomInfo.worldmap_big_image_pointer()
                                            , image, false, undodata);
                ImageFormRef.WriteImageData(this, this.WMPalette
                                            , Program.ROM.RomInfo.worldmap_big_palette_pointer()
                                            , palette, false, undodata);
                ImageFormRef.WriteImageData(this, this.WMPaletteMap
                                            , Program.ROM.RomInfo.worldmap_big_palettemap_pointer()
                                            , palettemap, true, undodata); //パレットマップだけ lz77圧縮
                Program.Undo.Push(undodata);
            }
            //ポインタの書き込み
            this.AllWriteButton.PerformClick();

            WMPictureBox.Image = DrawWorldMap();
        }
Example #21
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            if (!InputFormRef.CheckWriteProtectionID00())
            {
                return;
            }

            string imagefilename = ImageFormRef.OpenFilenameDialogFullColor(this);

            if (imagefilename == "")
            {
                return;
            }

            Bitmap fullColor = ImageUtil.OpenLowBitmap(imagefilename); //bitmapそのものの色で開く.

            if (fullColor == null)
            {
                return;
            }

            if (fullColor.Width == 128 && fullColor.Height == 112)
            {
                Bitmap seetbitmap;
                if (ImageUtil.Is16ColorBitmap(fullColor))
                {
                    seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                }
                else
                {//取り込めないので提案をする.
                    ImagePortraitImporterForm f = (ImagePortraitImporterForm)InputFormRef.JumpFormLow <ImagePortraitImporterForm>();
                    f.SetOrignalImage(fullColor
                                      , 0, 0, (int)this.B12.Value, (int)this.B13.Value);
                    f.ShowDialog();

                    seetbitmap = f.GetResultBitmap();
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    if (f.IsDetailMode())
                    {
                        U.ForceUpdate(this.B12, f.GetMouthBlockX());
                        U.ForceUpdate(this.B13, f.GetMouthBlockY());
                    }
                }

                Bitmap seet;
                Bitmap map_face;
                BuildPortraitSeetFE6(seetbitmap, out seet, out map_face);

                byte[] seet_image = ImageUtil.ImageToByte16Tile(seet, seet.Width, seet.Height);
                seet_image = U.subrange(seet_image, 0, (uint)(seet_image.Length - (3 * (8 * 8 / 2) * 8))); //FE6の場合データサイズがさらに小さくなる
                byte[] map_face_image = ImageUtil.ImageToByte16Tile(map_face, map_face.Width, map_face.Height);
                byte[] palette        = ImageUtil.ImageToPalette(seet, 1);


                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, seet_image, true, undodata);      //FE6は顔画像も圧縮する
                    this.InputFormRef.WriteImageData(this.D4, map_face_image, false, undodata); //FE6のマップ顔は無圧縮
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else if (fullColor.Width == 80 &&
                     (fullColor.Height == 80 || fullColor.Height == 72))
            {
                Bitmap seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }
                seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }

                byte[] class_image = ImageUtil.ImageToByte16Tile(seetbitmap, seetbitmap.Width, seetbitmap.Height);
                byte[] palette     = ImageUtil.ImageToPalette(seetbitmap, 1);

                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, class_image, true, undodata); //クラス画像は圧縮されている.
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //顔パラメーターは使わないので0を入れる.
                U.ForceUpdate(this.D4, 0);
                U.ForceUpdate(this.B12, 0);
                U.ForceUpdate(this.B13, 0);

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else
            {
                R.ShowStopError("画像サイズが正しくありません。\r\n顔画像ならば、128x112 \r\nクラス画像ならば 80x80 である必要があります。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", fullColor.Width, fullColor.Height, Width, Height);
            }
        }
Example #22
0
        static List <U.AddrResult> ScanWithoutUI(InputFormRef.AutoPleaseWait pleaseWait, bool useIgnoreData)
        {
            List <U.AddrResult> errorMapUI = new List <U.AddrResult>();
            List <U.AddrResult> maps       = MapSettingForm.MakeMapIDList();

            List <DisassemblerTrumb.LDRPointer> ldrmap;

            ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

            //システム全体の問題
            {
                if (pleaseWait != null)
                {
                    pleaseWait.DoEvents(R._("システムチェック中"));
                }

                List <FELint.ErrorSt> errorList = FELint.ScanMAP(FELint.SYSTEM_MAP_ID, ldrmap);
                if (!useIgnoreData)
                {
                    errorList = FELint.HiddenErrorFilter(errorList);
                }

                if (errorList.Count > 0)
                {//エラーがある
                    U.AddrResult ar = new U.AddrResult();
                    ar.addr = FELint.SYSTEM_MAP_ID;
                    ar.name = R._("システム");
                    ar.tag  = (uint)errorList.Count;

                    errorMapUI.Add(ar);
                }
            }

            for (int i = 0; i < maps.Count; i++)
            {
                if (pleaseWait != null)
                {
                    pleaseWait.DoEvents(R._("調査中 {0}/{1}", i, maps.Count));
                }

                uint         mapid = (uint)i;
                U.AddrResult ar    = new U.AddrResult();

                //このマップのエラースキャン
                List <FELint.ErrorSt> errorList = FELint.ScanMAP(mapid, ldrmap);
                if (!useIgnoreData)
                {
                    errorList = FELint.HiddenErrorFilter(errorList);
                }
                if (errorList.Count <= 0)
                {//エラーがない
                    continue;
                }

                ar.addr = mapid;
                ar.name = maps[i].name;
                ar.tag  = (uint)errorList.Count;

                errorMapUI.Add(ar);
            }


            return(errorMapUI);
        }
        public bool Apply(InputFormRef.AutoPleaseWait wait, ROM vanilla, string filename, int useFreeArea)
        {
            this.ApplyLog           = new StringBuilder();
            this.AddressMap         = new Dictionary <uint, uint>();
            this.MissingPointerList = new List <MissingPointer>();
            this.LZ77StructList     = new List <LZ77Struct>();
            this.WriteROMData32MB   = new byte[32 * 1024 * 1024]; //32MB memory reserve
            U.write_range(this.WriteROMData32MB, 0, vanilla.Data);
            this.WriteOffset = (uint)vanilla.Data.Length;

            string dir = Path.GetDirectoryName(filename);

            RemoveLog(filename);

            string[] lines = File.ReadAllLines(filename);
            this.RebuildAddress = GetRebuildAddress(lines);
            if (this.RebuildAddress > this.WriteOffset)
            {
                write_resize_data(this.RebuildAddress);
                this.RebuildAddress = this.WriteOffset;
            }

            //途中でデータを書き込むことがあるので、現在のフリーエリアを見つけてリストに追加.
            //後でROM末尾を超えたら再設定する.
            InitFreeAreaDef();
            //通常のROM末尾を超えた時点で再度スキャンする.
            bool isMakeFreeAreaList = false;

            int nextDoEvents = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                string line    = lines[i];
                string srcline = line;
                line = U.ClipComment(line);
                string[] sp = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (sp.Length < 2)
                {
                    continue;
                }
                if (sp[0] == "@_CRC32" ||
                    sp[0] == "@_REBUILDADDRESS" ||
                    sp[0] == "@_ASSERT")
                {
                    continue;
                }

                uint   vanilla_addr;
                uint   blocksize;
                uint   count;
                string targetfilename;
                uint   addr = ParseLine(sp
                                        , out vanilla_addr
                                        , out targetfilename
                                        , out blocksize
                                        , out count);

                if (sp[0] == "@DEF")
                {
                    DEF(addr, srcline);
                    continue;
                }
                else if (sp[0] == "@BROKENDATA")
                {
                    BrokenData(addr, srcline);
                    continue;
                }
                else if (sp[0] == "@00")
                {
                    Fixed00(addr, blocksize, srcline);
                    continue;
                }

                if (isMakeFreeAreaList == false && addr >= this.RebuildAddress)
                {//リビルドしない領域が終わったら、フリー領域リストを再構築する.
                    isMakeFreeAreaList = true;
                    //フリーエリアの再設定
                    ReInitFreeAreaDef(useFreeArea, this.RebuildAddress, lines);
                }

                if (i > nextDoEvents)
                {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                    wait.DoEvents(i + ":" + line);
                    nextDoEvents = i + 0xff;
                }

                targetfilename = Path.Combine(dir, targetfilename);
                if (!File.Exists(targetfilename))
                {
                    R.ShowStopError("ファイル({1})がありません。\r\n行数:{0}\r\n", i + 1, targetfilename);
                    return(false);
                }

                if (sp[0] == "@IFR")
                {
                    IFR(addr, vanilla_addr, targetfilename, blocksize, count, srcline);
                }
                else if (sp[0] == "@BIN")
                {
                    Bin(addr, targetfilename, srcline);
                }
                else if (sp[0] == "@MIX")
                {
                    Mix(addr, targetfilename, srcline);
                }
                else if (sp[0] == "@MIXLZ77")
                {
                    MixLZ77(addr, targetfilename, blocksize, srcline);
                }
                else
                {
                    continue;
                }
            }
            wait.DoEvents("WriteBackMixLZ77");
            //後回しにしていたLZ77の解決.
            WriteBackMixLZ77();

            wait.DoEvents("CheckSelf");
            bool r = CheckSelf(filename, lines);

            if (!r)
            {
                R.ShowStopError("適応した結果にエラーがあるようです。\r\nログを確認してください。\r\nログ:{0}", GetLogFilename(filename));
            }

            wait.DoEvents("ApplyVanillaROM");
            ApplyVanillaROM(vanilla);
            return(true);
        }
Example #24
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            if (InputFormRef.IsPleaseWaitDialog(this))
            {//2重割り込み禁止
                return;
            }
            if (AddressList.SelectedIndex <= 0)
            {
                return;
            }
            if (!this.InputFormRef.CheckWriteProtectionID00())
            {
                return;
            }

            string filename;

            if (ImageFormRef.GetDragFilePath(out filename))
            {
            }
            else
            {
                string title  = R._("インポートする音楽ファイルを選択してください");
                string filter = R._("sound|*.s;*.wav;*.mid;*.midi;*.instrument|s|*.s|midi|*.mid;*.midi|wav|*.wav|MusicalInstrument|*.instrument|All files|*");

                OpenFileDialog open = new OpenFileDialog();
                open.Title  = title;
                open.Filter = filter;
                Program.LastSelectedFilename.Load(this, "", open);
                DialogResult dr = open.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }
                if (!U.CanReadFileRetry(open))
                {
                    return;
                }
                Program.LastSelectedFilename.Save(this, "", open);
                filename = open.FileNames[0];
            }

            uint songtable_address = InputFormRef.BaseAddress + (InputFormRef.BlockSize * (uint)AddressList.SelectedIndex);

            string error = "";

            string ext = U.GetFilenameExt(filename);

            if (ext == ".WAV" || ext == ".WAVE")
            {
                SongTrackImportWaveForm f = (SongTrackImportWaveForm)InputFormRef.JumpFormLow <SongTrackImportWaveForm>();
                f.Init(filename);
                DialogResult dr = f.ShowDialog();
                if (dr != System.Windows.Forms.DialogResult.OK)
                {
                    f.Dettach();
                    return;
                }
                error = SongUtil.ImportWave(f.GetFilename(), songtable_address, f.UseLoop());
                f.Dettach();
            }
            else if (ext == ".MID" || ext == ".MIDI")
            {
                //楽器セットとオプションを選択してもらう.
                SongTrackImportMidiForm f = (SongTrackImportMidiForm)InputFormRef.JumpFormLow <SongTrackImportMidiForm>();
                f.Init((uint)P4.Value);
                DialogResult dr = f.ShowDialog();
                if (dr != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                //少し時間がかかるので、しばらくお待ちください表示.
                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    if (f.GetUseMID2AGB() == SongTrackImportMidiForm.ImportMethod.FEBuilderGBA)
                    {//FEBuilderGBAでimport
                        error = SongUtil.ImportMidiFile(filename, songtable_address
                                                        , f.GetInstrumentAddr()
                                                        , f.GetIgnoreMOD()
                                                        , f.GetIgnoreBEND()
                                                        , f.GetIgnoreLFOS()
                                                        , f.GetIgnoreHEAD()
                                                        , f.GetIgnoreBACK()
                                                        );
                    }
                    else
                    {//mid2agbでimport
                        error = SongUtil.ImportMidiFileMID2AGB(filename, songtable_address
                                                               , f.GetInstrumentAddr()
                                                               , f.GetMID2AGB_V()
                                                               , f.GetMID2AGB_R()
                                                               , f.GetIgnoreMOD()
                                                               , f.GetIgnoreBEND()
                                                               , f.GetIgnoreLFOS()
                                                               );
                    }
                }
            }
            else if (ext == ".INSTRUMENT")
            {
                //少し時間がかかるので、しばらくお待ちください表示.
                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    error = SongUtil.ImportInstrument(filename, songtable_address);
                }
            }
            else
            {
                //楽器セットを選択してもらう.
                SongTrackImportSelectInstrumentForm f = (SongTrackImportSelectInstrumentForm)InputFormRef.JumpFormLow <SongTrackImportSelectInstrumentForm>();
                f.Init((uint)P4.Value);
                DialogResult dr = f.ShowDialog();
                if (dr != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                //少し時間がかかるので、しばらくお待ちください表示.
                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    error = SongUtil.ImportS(filename, songtable_address, f.GetInstrumentAddr());
                }
            }


            if (error != "")
            {
                R.ShowStopError(error);
                return;
            }

            int selectedIndex = AddressList.SelectedIndex;

            ReloadListButton.PerformClick();
            AddressList.SelectedIndex = selectedIndex;

            SongTableForm.ReloadList();
            InputFormRef.ShowWriteNotifyAnimation(this, 0);
        }
        public static void AllMakeNoDollSymFile(Form self, string symfilename, InputFormRef.AutoPleaseWait wait)
        {
            Encoding encoding = U.GetSystemDefault();

            using (StreamWriter writer = new StreamWriter(symfilename, false, encoding))
            {
                wait.DoEvents("GrepAllStructPointers");
                AsmMapFile        asmMapFile   = new AsmMapFile(Program.ROM);
                DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);

                List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache();

                List <Address> structlist = new List <Address>(50000);
                //昔のno$gbaは32546lines以上の symを読みこむと落ちるので手加減する.
                U.AppendAllASMStructPointersList(structlist
                                                 , ldrmap
                                                 , isPatchInstallOnly: true
                                                 , isPatchPointerOnly: false
                                                 , isPatchStructOnly: false
                                                 , isUseOtherGraphics: false
                                                 , isUseOAMSP: false
                                                 );
                AsmMapFile.InvalidateUNUNSED(structlist);
                asmMapFile.AppendMAP(structlist);

                //コメントデータ
                Program.CommentCache.MakeAddressList(structlist);
                asmMapFile.AppendMAP(structlist);

                Dictionary <uint, AsmMapFile.AsmMapSt> asmmap = asmMapFile.GetAsmMap();
                foreach (var pair in asmmap)
                {
                    if (pair.Key == 0x0 || pair.Key == U.NOT_FOUND)
                    {
                        continue;
                    }
                    if (pair.Key >= 0x08000000 && pair.Key <= 0x08000200)
                    {
                        continue;
                    }

                    if (pair.Value.IsPointer)
                    {//ポインタデータは不要
                        continue;
                    }

                    //長いと不便なので、名前以外不要.
                    string name = pair.Value.Name;
                    name = ConvertNoDollGBASymName(name);
                    if (name == "")
                    {//名前が空
                        continue;
                    }

                    if (pair.Value.TypeName == "ARM")
                    {
                        string line = string.Format("{0} .arm", U.ToHexString(pair.Key), ".arm");
                        writer.WriteLine(line);
                    }
                    else if (pair.Value.TypeName == "ASM" ||
                             U.toOffset(pair.Key) < Program.ROM.RomInfo.compress_image_borderline_address)
                    {
                        string line = string.Format("{0} .thumb", U.ToHexString(pair.Key));
                        writer.WriteLine(line);
                    }

                    {
                        string line = string.Format("{0} {1}", U.ToHexString(pair.Key), name);
                        writer.WriteLine(line);
                    }
                }
            }
        }
Example #26
0
        private void ExportButton_Click(object sender, EventArgs e)
        {
            string title  = R._("保存するファイル名を選択してください");
            string filter = R._("sound|*.s;*.mid|s|*.s|midi|*.mid|MusicalInstrument|*.instrument|SondFont|*.sf2|All files|*");

            string songname = "song" + U.ToHexString(AddressList.SelectedIndex);

            SaveFileDialog save = new SaveFileDialog();

            save.Title        = title;
            save.Filter       = filter;
            save.AddExtension = true;
            Program.LastSelectedFilename.Load(this, "", save, songname);

            DialogResult dr = save.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }
            if (save.FileNames.Length <= 0 || !U.CanWriteFileRetry(save.FileNames[0]))
            {
                return;
            }
            Program.LastSelectedFilename.Save(this, "", save);
            string filename = save.FileNames[0];

            int  NumBlks         = (int)B1.Value;
            int  Priority        = (int)B2.Value;
            int  Reverb          = (int)B3.Value;
            uint instrument_addr = (uint)P4.Value;

            string ext = U.GetFilenameExt(filename);

            if (ext == ".MID" || ext == ".MIDI")
            {
                if (SongUtil.UseGBAMusRiper())
                {
                    SongUtil.ExportMidiFileByGBAMusRiper(filename, (uint)this.Address.Value);
                }
                else
                {
                    SongUtil.ExportMidiFile(filename, songname
                                            , Tracks, NumBlks, Priority, Reverb, instrument_addr);
                }
            }
            else if (ext == ".SF2")
            {
                SongUtil.ExportSoundFontByGBAMusRiper(filename, (uint)this.Address.Value);
            }
            else if (ext == ".INSTRUMENT")
            {
                //少し時間がかかるので、しばらくお待ちください表示.
                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    SongUtil.ExportInstrument(filename, instrument_addr);
                }
            }
            else
            {
                SongUtil.ExportSFile(filename, songname
                                     , Tracks, NumBlks, Priority, Reverb, instrument_addr);
            }

            //エクスプローラで選択しよう
            U.SelectFileByExplorer(filename);
        }
        public static void RunAllMakeMAPFileButton(Form self)
        {
            if (InputFormRef.IsPleaseWaitDialog(self))
            {//2重割り込み禁止
                return;
            }

            string title  = R._("保存するファイル名を選択してください");
            string filter = R._("MAP|*.map|TEXT|*.txt|All files|*");

            SaveFileDialog save = new SaveFileDialog();

            save.Title  = title;
            save.Filter = filter;
            save.ShowDialog();
            if (save.FileNames.Length <= 0 || !U.CanWriteFileRetry(save.FileNames[0]))
            {
                return;
            }

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(self))
                using (StreamWriter writer = new StreamWriter(save.FileNames[0]))
                {
                    writer.WriteLine(" Start         Length     Name                   Class");

                    wait.DoEvents("GrepAllStructPointers");
                    AsmMapFile        asmMapFile   = new AsmMapFile(Program.ROM);
                    DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);

                    List <DisassemblerTrumb.LDRPointer> ldrmap = Program.AsmMapFileAsmCache.GetLDRMapCache();

                    List <Address> structlist = U.MakeAllStructPointersList(false); //既存の構造体
                    U.AppendAllASMStructPointersList(structlist
                                                     , ldrmap
                                                     , isPatchInstallOnly: false
                                                     , isPatchPointerOnly: false
                                                     , isPatchStructOnly: false
                                                     , isUseOtherGraphics: true
                                                     , isUseOAMSP: true
                                                     );
                    AsmMapFile.InvalidateUNUNSED(structlist);
                    MakeFreeData(structlist);
                    asmMapFile.AppendMAP(structlist);

                    //コメントデータ
                    Program.CommentCache.MakeAddressList(structlist);
                    asmMapFile.AppendMAP(structlist);


                    string line;
                    Dictionary <uint, AsmMapFile.AsmMapSt> asmmap = asmMapFile.GetAsmMap();
                    foreach (var pair in asmmap)
                    {
                        if (pair.Key == 0x0 || pair.Key == U.NOT_FOUND)
                        {
                            continue;
                        }
                        if (pair.Key >= 0x08000000 && pair.Key <= 0x08000200)
                        {
                            continue;
                        }
                        //長いと不便なので、名前以外不要.
                        string name = pair.Value.Name;
                        name = U.term(name, "\t");

                        if (pair.Value.Length > 0)
                        {
                            line = string.Format(" 0000:{0} 0{1}H {2}  DATA", U.ToHexString(pair.Key), pair.Value.Length.ToString("X08"), name);
                        }
                        else
                        {
                            line = string.Format(" 0000:{0}       {1}", U.ToHexString(pair.Key), name);
                        }

                        writer.WriteLine(line);
                    }
                }

            //エクスプローラで選択しよう
            U.SelectFileByExplorer(save.FileNames[0]);
        }
Example #28
0
        public static void AllMakeNoDollSymFile(Form self, string symfilename, InputFormRef.AutoPleaseWait wait)
        {
            Encoding encoding = U.GetSystemDefault();

            using (StreamWriter writer = new StreamWriter(symfilename, false, encoding))
            {
                wait.DoEvents("GrepAllStructPointers");
                AsmMapFile asmMapFile = new AsmMapFile();

                DisassemblerTrumb Disassembler = new DisassemblerTrumb(asmMapFile);


                List <DisassemblerTrumb.LDRPointer> ldrmap = DisassemblerTrumb.MakeLDRMap(Program.ROM.Data, 0x100);

                List <Address> structlist = new List <Address>();
                //no$gbaは32546lines以上の symを読みこむと落ちるので手加減する.
                //                List<Address> structlist = U.MakeAllStructPointersList(); //既存の構造体
                U.AppendAllASMStructPointersList(structlist
                                                 , ldrmap
                                                 , isPatchInstallOnly: true
                                                 , isPatchPointerOnly: false
                                                 , isPatchStructOnly: false
                                                 , isUseOtherGraphics: false
                                                 , isUseOAMSP: false
                                                 );
                asmMapFile.AppendMAP(structlist);

                //コメントデータ
                Program.CommentCache.MakeAddressList(structlist);
                asmMapFile.AppendMAP(structlist);

                uint   lastNumber = 0;
                string line;
                Dictionary <uint, AsmMapFile.AsmMapSt> asmmap = asmMapFile.GetAsmMap();
                foreach (var pair in asmmap)
                {
                    if (pair.Key == 0x0 || pair.Key == U.NOT_FOUND)
                    {
                        continue;
                    }
                    if (pair.Key >= 0x08000000 && pair.Key <= 0x08000200)
                    {
                        continue;
                    }

                    if (pair.Value.IsPointer)
                    {//ポインタデータは不要
                        continue;
                    }

                    //長いと不便なので、名前以外不要.
                    string name = pair.Value.Name;
                    name = U.term(name, "\t");
                    name = name.Replace(" ", "_"); //スペースがあるとダメらしい.

                    if (name.IndexOf("6CStructHeader") >= 0)
                    {//6Cは全部表示する
                    }
                    else
                    {
                        uint arrayNumner = ParseArrayIndex(name);
                        if (arrayNumner >= 10)
                        {//容量削減のため2桁の配列は1つのみ
                            if (lastNumber == arrayNumner)
                            {
                                continue;
                            }
                            lastNumber = arrayNumner;
                        }
                    }

                    line = string.Format("{0} {1}", U.ToHexString(pair.Key), name);

                    writer.WriteLine(line);
                }
            }
        }
Example #29
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = ImageFormRef.ImportFilenameDialog(this);

            if (bitmap == null)
            {
                return;
            }
            int width         = 32 * 8;
            int height        = 20 * 8;
            int palette_count = 8;

            if (bitmap.Width != width || bitmap.Height != height)
            {
                if (bitmap.Width != 30 * 8 || bitmap.Height != height)
                {
                    R.ShowStopError("画像サイズが正しくありません。\r\nWidth:{2} Height:{3} でなければなりません。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", bitmap.Width, bitmap.Height, width, height);
                    return;
                }
                //右側に余白がない場合、自動的に挿入する
                bitmap = ImageUtil.Copy(bitmap, 0, 0, width, height);
            }
            int bitmap_palette_count = ImageUtil.GetPalette16Count(bitmap);

            if (bitmap_palette_count <= 1)
            {                 //16色
                byte[] image; //画像
                byte[] tsa;   //TSA
                string error_string = ImageUtil.ImageToByteHeaderPackedTSA(bitmap, width, height, out image, out tsa);
                if (error_string != "")
                {
                    error_string += "\r\n" + DecreaseColorTSAToolForm.GetExplainDecreaseColor();
                    R.ShowStopError(error_string);
                    return;
                }

                //パレット
                byte[] palette = ImageUtil.ImageToPalette(bitmap, palette_count);

                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.P4, image, true, undodata);
                    this.InputFormRef.WriteImageData(this.P8, tsa, false, undodata);
                    this.InputFormRef.WriteImageData(this.P12, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                B0.Value = 0;  //16色 分割なし

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else if (bitmap_palette_count <= 8)
            {                 //16色*8種類カラー
                byte[] image; //画像
                byte[] tsa;   //TSA
                string error_string = ImageUtil.ImageToByteHeaderPackedTSA(bitmap, width, height, out image, out tsa);
                if (error_string != "")
                {
                    error_string += "\r\n" + DecreaseColorTSAToolForm.GetExplainDecreaseColor();
                    R.ShowStopError(error_string);
                    return;
                }

                //パレット
                byte[] palette = ImageUtil.ImageToPalette(bitmap, palette_count);

                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像データの重複を判定する
                    if (IsImageDuplicate((uint)this.P4.Value, (uint)this.AddressList.SelectedIndex))
                    {
                        this.P4.Value = 0;
                    }
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData10(this.P4, image, undodata);
                    this.InputFormRef.WriteImageData(this.P8, tsa, false, undodata);
                    this.InputFormRef.WriteImageData(this.P12, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }
                B0.Value = 1; //10分割 16色*8種類

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else
            {
                string error = R._("パレット数が正しくありません。\r\n{1}種類以下(16色*{1}種類) でなければなりません。\r\n\r\n選択された画像のパレット種類:{0}種類", bitmap_palette_count, palette_count) + "\r\n" + DecreaseColorTSAToolForm.GetExplainDecreaseColor();
                R.ShowStopError(error);
                return;
            }
        }
        public void InitUPS(InputFormRef.AutoPleaseWait wait, byte[] changeData, byte[] vanillaData)
        {
            this.ALabel = "VANILLA";
            this.BLabel = "UPS    ";
            this.CLabel = "CURRENT";
            this.CData  = (byte[])Program.ROM.Data.Clone();
            this.BData  = changeData;
            this.AData  = vanillaData;

            this.ChangeDataList = new List <ChangeDataSt>();

            uint length = (uint)this.CData.Length;

            if (length < this.BData.Length)
            {
                length = (uint)this.BData.Length;
            }
            if (length < this.AData.Length)
            {
                length = (uint)this.AData.Length;
            }
            Undo.UndoData undodata = Program.Undo.NewUndoData(this, "automarge");
            Program.ROM.write_resize_data((uint)length);

            uint nextDoEvents = 0;

            for (uint i = 0; i < length;)
            {
                if (i > nextDoEvents)
                {//毎回更新するのは無駄なのである程度の間隔で更新して以降
                    wait.DoEvents(R._("データ確認中 {0}/{1}", i, length));
                    nextDoEvents = i + 0xfff;
                }

                byte c = U.at(this.CData, i);
                byte b = U.at(this.BData, i);
                if (c == b)
                {//変更なし
                    i++;
                    continue;
                }
                byte a = U.at(this.AData, i);
                if (b == a)
                {//変更データが無改造ROMと同じなので、無条件に無視できます
                    i++;
                    continue;
                }
                if (c == a)
                {//現行データが無改造ROMと同じなので、無条件にマージできます
                    uint addr = (uint)i;
                    Program.ROM.write_u8(addr, b, undodata);
                    i++;
                    continue;
                }
                //共に違い、無改造ROMとも違うデータ
                {
                    uint size = find_length_conflict_ups(i, length);
                    this.ChangeDataList.Add(new ChangeDataSt(i, size, MargeMethod.NONE));
                    i += size;
                }
            }

            if (undodata.list.Count > 0)
            {
                Program.Undo.Push(undodata);
            }

            if (!IsConflictData())
            {
                return;
            }
            wait.DoEvents(R._("ヒント用にマップファイルを構築しています"));
            MakeWhatIs();

            wait.DoEvents(R._("相違点をリストにまとめています"));
            this.AddressList.DummyAlloc(this.ChangeDataList.Count, 0);

            MakeListboxContextMenuN(AddressList, AddressList_KeyDown);
            UpdateTitle();
        }