static string ReOpen(string romRebuildFilename, string orignalFilename, int useFreeArea, uint freeAreaMinimumSize, uint freeAreaStartAddress, string appendFreeAreaFilename, uint useShareSameData) { ROM rom = new ROM(); string version; bool r = rom.Load(orignalFilename, out version); if (!r) { R.ShowStopError("未対応のROMです。\r\ngame version={0}", version); return(""); } using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait()) { r = ToolROMRebuildForm.ApplyROMRebuild(pleaseWait, rom, romRebuildFilename , useFreeArea , freeAreaMinimumSize , freeAreaStartAddress , appendFreeAreaFilename , useShareSameData); if (!r) { U.SelectFileByExplorer(ToolROMRebuildApply.GetLogFilename(romRebuildFilename)); return(""); } } string newFilename = U.ChangeExtFilename(romRebuildFilename, ".gba"); rom.Save(newFilename, false); return(newFilename); }
static bool LoadROMLow(string fullfilename, string forceversion) { if (!U.CanReadFileRetry(fullfilename)) { return(false); } string version = ""; bool r = false; ROM rom = new ROM(); if (forceversion == "") { r = rom.Load(fullfilename, out version); if (r) { ROM = rom; return(true); } if (U.GetFileSize(fullfilename) >= 1024 * 1024 * 8) {//8MB以上ならROMの可能性あり ErorrUnknownROM f = (ErorrUnknownROM)InputFormRef.JumpFormLow <ErorrUnknownROM>(); f.Init(version); f.ShowDialog(); forceversion = f.GetResultVersion(); } } if (forceversion != "") {//強制バージョン指定 r = rom.LoadForceVersion(fullfilename, forceversion); if (r) { ROM = rom; return(true); } version = forceversion; } R.ShowStopError("未対応のROMです。\r\ngame version={0}\r\nSize={1}" , version , U.To0xHexString((uint)U.GetFileSize(fullfilename)) ); return(false); }
void LoadTargetROM(string filename) { ROM OtherROM = new ROM(); string version; if (OtherROM.Load(filename, out version)) { this.OtherROMASMMap = new AsmMapFile(OtherROM); } this.OtherROMFilename = filename; this.OtherROMData = File.ReadAllBytes(filename); this.OtherLoadName.Text = R._("別ゲームROM:{0}", Path.GetFileNameWithoutExtension(this.OtherROMFilename)); //自分のLDRMAPをここで作る. 相手のROMに探索に利用する this.LDRMAPs = Program.AsmMapFileAsmCache.GetLDRMapCache(); //相手のROMのLDRMAPを作る. this.OtherLDRMAPs = DisassemblerTrumb.MakeLDRMap(this.OtherROMData, 0x100, 0); }
private void ApplyButton_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; } Undo.UndoData undodata = Program.Undo.NewUndoData(this); byte[] bin = rom.getBinaryData(0, 0x100); Program.ROM.write_range(0, bin, undodata); Program.Undo.Push(undodata); R.ShowOK("ROMヘッダーを復旧させました"); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); }
//翻訳用のよくあるテキスト集の作成. public static Dictionary <string, string> LoadTranslateDic(string from, string to, string rom_from, string rom_to) { Dictionary <string, string> dic = new Dictionary <string, string>(); ROM rom_f = new ROM(); string version; if (!rom_f.Load(rom_from, out version)) { return(dic); } ROM rom_t = new ROM(); if (!rom_t.Load(rom_to, out version)) { return(dic); } if (rom_f.RomInfo.version() != rom_t.RomInfo.version()) { return(dic); } SystemTextEncoder from_tbl, to_tbl; int from_n; bool trimEnd1F = true; if (from == "ja") { from_n = 0; from_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.Shift_JIS, rom_f); } else if (from == "en") { from_n = 1; if (rom_f.RomInfo.version() == 6) { from_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.EN_TBL, rom_f); } else { from_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.Shift_JIS, rom_f); } trimEnd1F = false; } else if (from == "zh" || from == "zh-CN") { from_n = 0; from_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.ZH_TBL, rom_f); } else if (from == "ko" || from == "ko-KR") { from_n = 0; from_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.KO_TBL, rom_f); } else {//fromが対応外. return(dic); } int to_n; if (to == "ja") { to_n = 0; to_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.Shift_JIS, rom_t); } else if (to == "en") { to_n = 1; if (rom_t.RomInfo.version() == 6) { to_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.EN_TBL, rom_t); } else { to_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.Shift_JIS, rom_t); } } else if (to == "zh" || to == "zh-CN") { to_n = 0; to_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.ZH_TBL, rom_t); } else if (to == "ko" || to == "ko-KR") { to_n = 0; to_tbl = new SystemTextEncoder(OptionForm.textencoding_enum.KO_TBL, rom_t); } else {//toが対応外. return(dic); } //FE8は、日本語版と英語版で顔画像の並びが違うので補正するかどうかのチェック FE8FaceCode48Fix fe8faceCode48Fix = is_FE8FaceCode48Fix(rom_f, rom_t); string filename = U.ConfigDataFilename("translate_textid_", rom_f); string[] lines = File.ReadAllLines(filename); FETextDecode from_decoder = new FETextDecode(rom_f, from_tbl); FETextDecode to_decoder = new FETextDecode(rom_t, to_tbl); for (int i = 0; i < lines.Length; i++) { if (U.IsComment(lines[i])) { continue; } string line = U.ClipComment(lines[i]); string[] sp = line.Split('\t'); if (sp.Length < 2) { continue; } string from_string, to_string; uint from_key = U.atoh(sp[from_n]); uint orignal_from_key = from_key; if (from_key <= 0) { continue; } if (U.isSafetyPointer(from_key, rom_f)) {//ポインタの場合、実アドレスを求める. from_key = rom_f.u32(U.toOffset(from_key)); if (!U.isSafetyPointer(from_key, rom_f)) { continue; } } from_string = from_decoder.Decode(from_key); from_string = from_string.ToUpper(); uint to_key = U.atoh(sp[to_n]); int change_string_pos = sp[to_n].IndexOf('|'); if (change_string_pos < 0) { if (to_key <= 0) { dic[U.ToHexString(orignal_from_key) + "#NOTFOUND#" + from_string] = ""; continue; } if (U.isSafetyPointer(to_key, rom_t)) {//ポインタの場合、実アドレスを求める. to_key = rom_t.u32(U.toOffset(to_key)); if (!U.isSafetyPointer(to_key, rom_t)) { dic[U.ToHexString(orignal_from_key) + "#NOTFOUND#" + from_string] = ""; continue; } } to_string = to_decoder.Decode(to_key); } else {//長さ当の問題で置換できないものは、代替えテキストを入れます. to_string = sp[to_n].Substring(change_string_pos + 1); } //FE8顔画像の修正. if (fe8faceCode48Fix != FE8FaceCode48Fix.NONE) { to_string = FE8SkipFace48(to_string, fe8faceCode48Fix); } if (trimEnd1F) { //末尾の001Fを消す to_string = Trim001F(to_string); } dic[from_string] = to_string; dic[U.ToHexString(orignal_from_key) + "|" + from_string] = to_string; } return(dic); }
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); }
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); } }