public static string Import( string filename //読み込むファイル名 , uint magic_baseaddress //魔法アニメの書き換えるアドレス ) { string basename = Path.GetFileNameWithoutExtension(filename) + "_"; string basedir = Path.GetDirectoryName(filename); List <byte> frameData = new List <byte>(); List <ImageUtilOAM.image_data> bgImagesData = new List <ImageUtilOAM.image_data>(); //変換したアニメの記録 Dictionary <string, ImageUtilOAM.animedata> animeDic = new Dictionary <string, ImageUtilOAM.animedata>(); int lineCount = 0; string[] lines = File.ReadAllLines(filename); uint image_bg_number = 0; uint image_obj_number = 0; ImageUtilOAM.ImportOAM oam = new ImageUtilOAM.ImportOAM(); oam.SetBaseDir(Path.GetDirectoryName(filename)); oam.SetIsMagicOAM(true); BGScaleMode bgScaleMode = BGScaleMode.NO; while (lineCount < lines.Length) { string line = lines[lineCount]; if (U.IsComment(line) || U.OtherLangLine(line)) { lineCount++; continue; } line = U.ClipComment(line); if (line == "") { lineCount++; continue; } InputFormRef.DoEvents(null, "Line:" + lineCount); if (line[0] == '~') { U.append_u32(frameData, 0x80000100); lineCount++; continue; } if (line[0] == 'C') {//85コマンド uint command = U.atoh(line.Substring(1)); if ((command & 0xFF) == 0x53) {//スクリプト側で自動拡大命令を入れている場合 ツールは何もしてはいけないので記録する. bgScaleMode = BGScaleMode.SCRIPT_SCALE_MODE; } uint a = (command & 0x00FFFFFF) | 0x85000000; U.append_u32(frameData, a); lineCount++; continue; } if (line[0] == 'S') {//音楽再生 uint music = U.atoh(line.Substring(1)); uint a = ((music & 0xFFFF) << 8) | 0x85000048; U.append_u32(frameData, a); lineCount++; continue; } if (line[0] != 'O' && line[0] != 'B') { //不明な命令なので無視する. lineCount++; continue; } //O objblank.png //B bg3.png //1 ImageUtilOAM.animedata objAnimeData = null; ImageUtilOAM.animedata bgAnimeData = null; uint frameSec = U.NOT_FOUND; for (int n = 1; n <= 3;) { line = lines[lineCount]; if (U.IsComment(line) || U.OtherLangLine(line)) { lineCount++; continue; } line = U.ClipComment(line); if (line == "") { lineCount++; continue; } if (U.isnum(line[0])) { if (frameSec != U.NOT_FOUND) { return(R.Error("時間指定が連続しています。\r\nO filename\r\nB filename\r\ntime\r\n\r\nFile:{0} Line:{1}\r\n", filename, lineCount + 1)); } frameSec = U.atoi(line); lineCount++; n++; continue; } string imagefilename = ImageUtilOAM.parsePFilename(line); if (imagefilename.Length <= 0) { return(R.Error("ファイル名が見つかりませんでした。\r\nFile: {0} line:{1}\r\n\r\nエラー内容:\r\n{2}", filename, lineCount, oam.ErrorMessage)); } if (line[0] == 'O') { if (objAnimeData != null) { return(R.Error("OBJ指定が連続しています。\r\nO filename\r\nB filename\r\ntime\r\n\r\nFile:{0} Line:{1}\r\n", filename, lineCount + 1)); } string errormessage; objAnimeData = ImportObjImageToData(imagefilename , basedir , animeDic , oam , ref image_obj_number , out errormessage ); if (objAnimeData == null) { return(R.Error("OBJ画像をロードできません。 \r\n{2}\r\nFile:{0} Line:{1}", filename, lineCount + 1, errormessage)); } lineCount++; n++; continue; } if (line[0] == 'B') { if (bgAnimeData != null) { return(R.Error("BG指定が連続しています。\r\nO filename\r\nB filename\r\ntime\r\n\r\nFile:{0} Line:{1}\r\n", filename, lineCount + 1)); } string errormessage; bgAnimeData = ImportBGImageToData(imagefilename , basedir , animeDic , bgImagesData , out errormessage ); if (bgAnimeData == null) { return(R.Error("BG画像をロードできません。 \r\n{2}\r\nFile:{0} Line:{1}", filename, lineCount + 1, errormessage)); } lineCount++; n++; continue; } } if (objAnimeData == null) { return(R.Error("OBJ画像がありません。 \r\nO filename\r\nB filename\r\ntime\r\n\r\nみたいに、セットで登録する必要があります。\r\nFile:{0} Line:{1}", filename, lineCount + 1)); } if (bgAnimeData == null) { return(R.Error(("IMAGE_POINTER or ZIMAGE_POINTER の指定が必要です。BG画像がありません。 \r\nO filename\r\nB filename\r\n"), filename, lineCount + 1)); } if (frameSec == U.NOT_FOUND) { return(R.Error("時間指定がありません。 \r\nO filename\r\nB filename\r\ntime\r\n\r\nみたいに、セットで登録する必要があります。\r\nFile:{0} Line:{1}", filename, lineCount + 1)); } //BGがFEditorの小さい形式だった場合、自動的に拡大命令を追加する. if (bgAnimeData.height == 64) { if (bgScaleMode == BGScaleMode.NO) {//拡大命令を付与. uint a = (0x00000153) | 0x85000000; U.append_u32(frameData, a); bgScaleMode = BGScaleMode.AUTO_SCALE_MODE; } } //0x86コマンド { uint a = (frameSec & 0xFFFF) | ((image_bg_number & 0xFF) << 16) | 0x86000000; U.append_u32(frameData, a); //+0 U.append_u32(frameData, objAnimeData.image_pointer); //+4 U.append_u32(frameData, objAnimeData.oam_pos); //+8 OBJ OAM U.append_u32(frameData, objAnimeData.oam2_pos); //+12 OBJ BG OAM U.append_u32(frameData, bgAnimeData.image_pointer); //+16 U.append_u32(frameData, objAnimeData.palette_pointer); //+20 U.append_u32(frameData, bgAnimeData.palette_pointer); //+24 U.append_u32(frameData, bgAnimeData.tsa_pointer); //+28 TSA image_bg_number++; } } InputFormRef.DoEvents(null, "Term"); if (bgScaleMode == BGScaleMode.AUTO_SCALE_MODE) {//拡大命令を自動付与していた場合、解除する. 解除しないと経験値バーが表示されない. uint a = (0x00000053) | 0x85000000; U.append_u32(frameData, a); } //終端. U.append_u32(frameData, 0x80000000); //登録完了処理 oam.Term(); Undo.UndoData undodata = Program.Undo.NewUndoData("import ", Path.GetFileName(filename)); //上書きされるアニメデータ領域を使いまわす List <Address> recycle = new List <Address>(); RecycleOldAnime(ref recycle, "", false, magic_baseaddress); RecycleAddress ra = new RecycleAddress(recycle); //書き込みます.(魔法アニメはなぜか無圧縮) ra.WriteAndWritePointer(magic_baseaddress + 4, oam.GetRightToLeftOAM(), undodata); ra.WriteAndWritePointer(magic_baseaddress + 8, oam.GetLeftToRightOAM(), undodata); //BG用にダミーのOAMを作成 //byte[] dummyOAM = ImageUtilMagicFEditor.MakeDummyOAM(image_bg_number); ra.WriteAndWritePointer(magic_baseaddress + 12, oam.GetRightToLeftOAMBG(), undodata); ra.WriteAndWritePointer(magic_baseaddress + 16, oam.GetLeftToRightOAMBG(), undodata); //BG for (int i = 0; i < bgImagesData.Count; i++) { bgImagesData[i].write_addr = ra.Write(bgImagesData[i].data, undodata); } //OBJ List <ImageUtilOAM.image_data> objImages = oam.GetImages(); for (int i = 0; i < objImages.Count; i++) { objImages[i].write_addr = ra.Write(objImages[i].data, undodata); } //画像の書き込みアドレスが決定したら、画像ポインタをかかないといけないFrameDataを更新します。 byte[] frameDataUZ = frameData.ToArray(); string errorFrame = updateFrameDataAddress(frameDataUZ, bgImagesData, objImages); if (errorFrame != "") { return(R.Error("OAMフレーム更新中にエラーが発生しました。\r\nこのエラーが頻繁に出る場合は、アニメデータと一緒にreport7zを送ってください。") + "\r\n" + errorFrame); } ra.WriteAndWritePointer(magic_baseaddress + 0, frameDataUZ, undodata); //端数の再利用的ない古いデータは0x00クリア. ra.BlackOut(undodata); Program.Undo.Push(undodata); return(""); }
string Import( string filename //読込むファイル名 ) { string basename = Path.GetFileNameWithoutExtension(filename) + "_"; string basedir = Path.GetDirectoryName(filename); //同じアニメを何度も入力しないように記録する. List <anime> anime_list = new List <anime>(); int imageWidth = this.ImageWidth * 8; int imageHeight = 8 * 16; List <byte> frames = new List <byte>(); string[] lines = File.ReadAllLines(filename); for (uint lineCount = 0; lineCount < lines.Length; lineCount++) { string line = lines[lineCount++]; if (U.IsComment(line) || U.OtherLangLine(line)) { continue; } line = U.ClipComment(line); if (line.Length <= 0) { continue; } InputFormRef.DoEvents(null, "Line:" + lineCount); line = line.Replace("\t", " "); string[] sp = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string command = sp[0]; if (command.Length <= 0) { continue; } if (!(U.isNumString(command) && sp.Length >= 2)) { continue; } uint wait = U.atoi(command); string image = sp[1]; uint id = FindImage(anime_list, image); if (id == U.NOT_FOUND) { id = (uint)anime_list.Count; string fullfilename = Path.Combine(basedir, image); Bitmap bitmap = ImageUtil.OpenBitmap(fullfilename); if (bitmap == null) { return(R.Error("ファイル名が見つかりませんでした。\r\nFile: {0} line:{1}\r\n\r\nエラー内容:\r\n{2}", filename, lineCount, line)); } if (bitmap.Width != imageWidth || bitmap.Height != imageHeight) { bitmap = ImageUtil.Copy(bitmap, 0, 0, imageWidth, imageHeight); } anime a = new anime(); string error = ImageUtil.ImageToBytePackedTSA(bitmap, imageWidth, imageHeight, 0, out a.image, out a.tsa); if (error != "") { return(R.Error("画像をインポートできません。\r\nFile: {0} line:{1}\r\n\r\nエラー内容:\r\n{2}", filename, lineCount, error)); } a.image = LZ77.compress(a.image); a.tsa = LZ77.compress(a.tsa); a.pal = ImageUtil.ImageToPalette(bitmap, 1); a.filename = image; anime_list.Add(a); } U.append_u16(frames, id); U.append_u16(frames, wait); } //term U.append_u16(frames, 0xFFFF); U.append_u16(frames, 0x0); if (anime_list.Count <= 0) { return(R._("書き込むアニメーションがありません")); } Undo.UndoData undodata = Program.Undo.NewUndoData(""); List <Address> recycle = new List <FEBuilderGBA.Address>(); MakeRecycleList(ref recycle, "", false); RecycleAddress ra = new RecycleAddress(recycle); uint p; if (!U.isSafetyOffset(this.FramePointer)) {//固定フレームのアニメ if (this.FramePointer != anime_list.Count) { return(R._("このアニメーションは固定アニメーションです。フレームが{0}個必要です。指定されたアニメには{1}のフレームがあり、数が一致していません。", this.FramePointer, anime_list.Count)); } if (this.TSAList.Count == 1 && this.PaletteList.Count >= 2) {//パレットアニメ List <byte> pal_list = new List <byte>(); for (int i = 0; i < anime_list.Count; i++) { p = ra.Write(anime_list[i].pal, undodata); U.append_u32(pal_list, U.toPointer(p)); } ra.WriteAndWritePointer(this.TSAPointer, anime_list[0].tsa, undodata); ra.WriteAndWritePointer(this.ImagePointer, anime_list[0].image, undodata); ra.WriteAndWritePointer(this.PalettePointer, pal_list.ToArray(), undodata); } else { List <byte> image_list = new List <byte>(); List <byte> tsa_list = new List <byte>(); List <byte> pal_list = new List <byte>(); for (int i = 0; i < anime_list.Count; i++) { p = ra.Write(anime_list[i].image, undodata); U.append_u32(image_list, U.toPointer(p)); p = ra.Write(anime_list[i].tsa, undodata); U.append_u32(tsa_list, U.toPointer(p)); p = ra.Write(anime_list[i].pal, undodata); U.append_u32(pal_list, U.toPointer(p)); } ra.WriteAndWritePointer(this.TSAPointer, tsa_list.ToArray(), undodata); ra.WriteAndWritePointer(this.ImagePointer, image_list.ToArray(), undodata); ra.WriteAndWritePointer(this.PalettePointer, pal_list.ToArray(), undodata); } } else { //フレームを利用するアニメ if (this.TSAList.Count >= 2 && this.PaletteList.Count == 1) { //共通パレット List <byte> image_list = new List <byte>(); List <byte> tsa_list = new List <byte>(); for (int i = 0; i < anime_list.Count; i++) { p = ra.Write(anime_list[i].image, undodata); U.append_u32(image_list, U.toPointer(p)); p = ra.Write(anime_list[i].tsa, undodata); U.append_u32(tsa_list, U.toPointer(p)); } ra.WriteAndWritePointer(this.FramePointer, frames.ToArray(), undodata); ra.WriteAndWritePointer(this.TSAPointer, tsa_list.ToArray(), undodata); ra.WriteAndWritePointer(this.ImagePointer, image_list.ToArray(), undodata); ra.WriteAndWritePointer(this.PalettePointer, anime_list[0].pal, undodata); } else {//複数パレット List <byte> image_list = new List <byte>(); List <byte> tsa_list = new List <byte>(); List <byte> pal_list = new List <byte>(); for (int i = 0; i < anime_list.Count; i++) { p = ra.Write(anime_list[i].image, undodata); U.append_u32(image_list, U.toPointer(p)); p = ra.Write(anime_list[i].tsa, undodata); U.append_u32(tsa_list, U.toPointer(p)); p = ra.Write(anime_list[i].pal, undodata); U.append_u32(pal_list, U.toPointer(p)); } ra.WriteAndWritePointer(this.FramePointer, frames.ToArray(), undodata); ra.WriteAndWritePointer(this.TSAPointer, tsa_list.ToArray(), undodata); ra.WriteAndWritePointer(this.ImagePointer, image_list.ToArray(), undodata); ra.WriteAndWritePointer(this.PalettePointer, pal_list.ToArray(), undodata); } } ra.BlackOut(undodata); Program.Undo.Push(undodata); return(""); }
static string ImportAll(string filename, uint pointer, InputFormRef ifr) { List <Address> recycle = new List <Address>(); //古いデータをリサイクルリストに入れる. FEBuilderGBA.Address.AddAddress(recycle , ifr , "" , new uint[] { 4 }); uint addr = ifr.BaseAddress; if (U.isSafetyOffset(addr)) { for (int i = 0; i < ifr.DataCount; i++, addr += ifr.BlockSize) { uint length = Program.ROM.u16(addr + 2); uint p4 = Program.ROM.p32(addr + 4); if (!U.isSafetyOffset(p4)) { continue; } FEBuilderGBA.Address.AddPointer(recycle , addr + 4 , length , "" , FEBuilderGBA.Address.DataTypeEnum.BIN); } } RecycleAddress ra = new RecycleAddress(recycle); string dir = Path.GetDirectoryName(filename); Undo.UndoData undodata = Program.Undo.NewUndoData("TileAnimation1"); List <byte> writedata = new List <byte>(); string[] lines = File.ReadAllLines(filename); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (U.IsComment(line) || U.OtherLangLine(line)) { continue; } line = U.ClipComment(line); if (line == "") { continue; } string[] sp = line.Split('\t'); if (sp.Length < 2) { continue; } uint wait = U.atoi(sp[0]); string imgFilename = Path.Combine(dir, sp[1]); Bitmap bitmap = ImageUtil.OpenBitmap(imgFilename); if (bitmap == null) { return(R.Error("タイルアニメーション({0})が見つかりません。\r\n\r\nスクリプト:{1}\r\n行数:{2}" , imgFilename, filename, i)); } byte[] bitmapByte = ImageUtil.ImageToByte16Tile(bitmap, bitmap.Width, bitmap.Height); uint length = (uint)bitmapByte.Length; if (sp.Length >= 3) { length = U.atoi(sp[2]); bitmapByte = U.subrange(bitmapByte, 0, length); } uint newaddr = ra.Write(bitmapByte, undodata); if (newaddr == U.NOT_FOUND) { return(R.Error("タイルアニメーション({0})を書き込めませんでした。\r\n\r\nスクリプト:{1}\r\n行数:{2}" , imgFilename, filename, i)); } bitmap.Dispose(); U.append_u16(writedata, wait); //wait U.append_u16(writedata, length); //length U.append_u32(writedata, U.toPointer(newaddr)); //画像ポインタ } //終端データ U.append_u16(writedata, 0); //term U.append_u16(writedata, 0); //length U.append_u32(writedata, 0); //画像ポインタ uint newpointer = ra.WriteAndWritePointer(pointer, writedata.ToArray(), undodata); if (newpointer == U.NOT_FOUND) { return(R.Error("タイルアニメーションのポインタを書き込めませんでした。\r\n\r\nスクリプト:{0}" , filename)); } ra.BlackOut(undodata); Program.Undo.Push(undodata); return(""); }
static string ImportAll(string filename, uint pointer, InputFormRef ifr) { List <Address> recycle = new List <Address>(); //古いデータをリサイクルリストに入れる. FEBuilderGBA.Address.AddAddress(recycle , ifr , "" , new uint[] { 0 }); uint addr = ifr.BaseAddress; if (U.isSafetyOffset(addr)) { for (int i = 0; i < ifr.DataCount; i++, addr += ifr.BlockSize) { uint p0 = Program.ROM.p32(addr + 0); uint wait = Program.ROM.u8(addr + 4); uint count = Program.ROM.u8(addr + 5); uint startindex = Program.ROM.u8(addr + 6); if (!U.isSafetyOffset(p0)) { continue; } FEBuilderGBA.Address.AddPointer(recycle , addr + 0 , count * 2 , "" , FEBuilderGBA.Address.DataTypeEnum.BIN); } } RecycleAddress ra = new RecycleAddress(recycle); string dir = Path.GetDirectoryName(filename); Undo.UndoData undodata = Program.Undo.NewUndoData("TileAnimation2"); List <byte> writedata = new List <byte>(); string[] lines = File.ReadAllLines(filename); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (U.IsComment(line) || U.OtherLangLine(line)) { continue; } line = U.ClipComment(line); if (line == "") { continue; } string[] sp = line.Split('\t'); if (sp.Length < 2) { continue; } uint wait = U.atoi(sp[0]); uint startindex = U.atoi(sp[1]); uint count = 0; List <byte> palByte = new List <byte>(); for (int n = 2; n < sp.Length; n++, count++) { string pal = sp[n]; string[] rgbarray = pal.Split(','); int r = (int)U.atoi0x(U.at(rgbarray, 0)); int g = (int)U.atoi0x(U.at(rgbarray, 1)); int b = (int)U.atoi0x(U.at(rgbarray, 2)); uint gbaRGB = ImageUtil.ColorToGBARGB(Color.FromArgb(r, g, b)); U.append_u16(palByte, gbaRGB); } uint newaddr = ra.Write(palByte.ToArray(), undodata); if (newaddr == U.NOT_FOUND) { return(R.Error("タイルアニメーション2を書き込めませんでした。\r\n\r\nスクリプト:{1}\r\n行数:{2}" , filename, i)); } U.append_u32(writedata, U.toPointer(newaddr)); //パレットポインタ U.append_u8(writedata, wait); //wait U.append_u8(writedata, count); //count U.append_u8(writedata, startindex); //startindex U.append_u8(writedata, 0); //0 } //終端データ U.append_u32(writedata, 0); //パレットポインタ U.append_u8(writedata, 0); //wait U.append_u8(writedata, 0); //count U.append_u8(writedata, 0); //startindex U.append_u8(writedata, 0); //0 uint newpointer = ra.WriteAndWritePointer(pointer, writedata.ToArray(), undodata); if (newpointer == U.NOT_FOUND) { return(R.Error("タイルアニメーションのポインタを書き込めませんでした。\r\n\r\nスクリプト:{0}" , filename)); } ra.BlackOut(undodata); Program.Undo.Push(undodata); return(""); }
public void ImportAllText(Form self, string filename) { //少し時間がかかるので、しばらくお待ちください表示. using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(self)) { Undo.UndoData undodata = Program.Undo.NewUndoData("ImportAllText" + Path.GetFileName(filename) ); uint id = U.NOT_FOUND; string[] lines = File.ReadAllLines(filename); //上書きするテキスト領域を再利用リストに突っ込む List <Address> recycle = 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, recycle); //次のテキスト id = U.atoh(U.substr(line, 1)); } RecycleAddress ra = new RecycleAddress(recycle); 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, ra, undodata); //次のテキスト id = U.atoh(U.substr(line, 1)); text = ""; } //最後のデータ WriteText(id, text, ra, undodata); ra.BlackOut(undodata); Program.Undo.Push(undodata); } }