static void ExportAll(string filename, InputFormRef ifr, uint mapid, int palette_index) { uint addr = ifr.BaseAddress; if (!U.isSafetyOffset(addr)) { return; } string dir = Path.GetDirectoryName(filename); string file = Path.GetFileNameWithoutExtension(filename); MapSettingForm.PLists plist = MapSettingForm.GetMapPListsWhereMapID(mapid); if (plist.palette_plist == 0) { return; } uint palette = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, plist.palette_plist); if (palette == U.NOT_FOUND) { return; } List <string> lines = new List <string>(); { string line = "//wait\tfilename"; lines.Add(line); } for (int i = 0; i < ifr.DataCount; i++, addr += ifr.BlockSize) { uint w0 = Program.ROM.u16(addr + 0); uint length = Program.ROM.u16(addr + 2); uint p4 = Program.ROM.p32(addr + 4); if (!U.isSafetyOffset(p4)) { continue; } Bitmap bitmap = GetTileAnime1(p4, length, palette, palette_index); string imgfilename = file + "_" + i.ToString("000") + ".png"; bitmap.Save(Path.Combine(dir, imgfilename)); string line = w0 + "\t" + imgfilename + "\t" + length; lines.Add(line); } File.WriteAllLines(filename, lines); }
void SelectMapID(uint mapid) { MapSettingForm.PLists plist = MapSettingForm.GetMapPListsWhereMapID((uint)mapid); uint change_plist_addr = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CHANGE, plist.mapchange_plist); uint selected = InputFormRef.AddrToSelect(this.AddressList, change_plist_addr); if (selected == U.NOT_FOUND) { return; } U.SelectedIndexSafety(this.AddressList, selected); }
//CONFIGの割り当て public static uint PreciseConfigArea(uint mapid) { MapPointerNewPLISTPopupForm f = (MapPointerNewPLISTPopupForm)InputFormRef.JumpFormLow <MapPointerNewPLISTPopupForm>(); f.Init(MapPointerForm.PLIST_TYPE.CONFIG); DialogResult dr = f.ShowDialog(); if (dr != System.Windows.Forms.DialogResult.OK) { return(0); } uint plist = f.GetSelectPLIST(); Undo.UndoData undodata = Program.Undo.NewUndoData("Precise ConfigArea", mapid.ToString("X")); //CONFIG領域を新規に割り当てる. byte[] data = new byte[CHIPSET_MAX_SIZE]; data = LZ77.compress(data); MapSettingForm.PLists plists = MapSettingForm.GetMapPListsWhereMapID(mapid); uint config_addr = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CONFIG, plists.config_plist); if (U.isSafetyOffset(config_addr)) {//既存configがあればコピーする. uint length = LZ77.getCompressedSize(Program.ROM.Data, config_addr); data = Program.ROM.getBinaryData(config_addr, length); } uint write_addr = InputFormRef.AppendBinaryData(data, undodata); if (write_addr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return(0); } bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.CONFIG, plist, write_addr, undodata); if (!r) { Program.Undo.Rollback(undodata); return(0); } Program.Undo.Push(undodata); return(plist); }
//チップセットの読込(マップチップの画像をどう解釈するか定義するデータ) public static byte[] UnLZ77ChipsetData(uint config_plist) { uint config_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CONFIG, config_plist); if (!U.isSafetyOffset(config_offset)) { return(null); } byte[] configUZ = LZ77.decompress(Program.ROM.Data, config_offset); if (configUZ.Length <= 0)//TSA { return(null); } return(configUZ); }
//マップの配置データの読込 public static byte[] UnLZ77MapData(uint mappointer_plist) { uint mappointer_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.MAP, mappointer_plist); if (!U.isSafetyOffset(mappointer_offset)) { return(null); } byte[] mappointerUZ = LZ77.decompress(Program.ROM.Data, mappointer_offset); //tsa if (mappointerUZ.Length <= 0) { return(null); } return(mappointerUZ); }
//パレットの割り当て public static uint PrecisePaletteArea(uint mapid) { MapPointerNewPLISTPopupForm f = (MapPointerNewPLISTPopupForm)InputFormRef.JumpFormLow <MapPointerNewPLISTPopupForm>(); f.Init(MapPointerForm.PLIST_TYPE.PALETTE); DialogResult dr = f.ShowDialog(); if (dr != System.Windows.Forms.DialogResult.OK) { return(0); } uint plist = f.GetSelectPLIST(); Undo.UndoData undodata = Program.Undo.NewUndoData("Precise PaletteArea", mapid.ToString("X")); //パレット領域を新規に割り当てる. byte[] data = new byte[5 * 2 * 16]; MapSettingForm.PLists plists = MapSettingForm.GetMapPListsWhereMapID(mapid); uint palette_addr = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, plists.palette_plist); if (U.isSafetyOffset(palette_addr)) {//既存パレットがあればコピーする. data = Program.ROM.getBinaryData(palette_addr, data.Length); } uint write_addr = InputFormRef.AppendBinaryData(data, undodata); if (write_addr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return(0); } bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.PALETTE, plist, write_addr, undodata); if (!r) { Program.Undo.Rollback(undodata); return(0); } Program.Undo.Push(undodata); return(plist); }
static InputFormRef Init(Form self) { return(new InputFormRef(self , "" , Program.ROM.RomInfo.map_setting_pointer() , Program.ROM.RomInfo.map_setting_datasize() , (int i, uint addr) => { //0 がポインタであればデータがあると考える. return U.isPointer(Program.ROM.u32(addr + 0)); } , (int i, uint addr) => { MapSettingForm.PLists plist = MapSettingForm.GetMapPListsWhereMapID((uint)i); uint change_plist_addr = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CHANGE, plist.mapchange_plist); string name = MapSettingForm.GetMapName((uint)i); return new U.AddrResult(change_plist_addr, name, (uint)i); } )); }
bool WriteMapChipPalette(Bitmap bitmap, bool importObjWithPalette, Undo.UndoData undodata) { const int palette_count = MAX_MAP_PALETTE_COUNT; if (importObjWithPalette) {//パレットもインポートする場合 //パレットの交換 this.MapObjImage = bitmap; U.ForceUpdate(this.PaletteTypeCombo, 0); U.ForceUpdate(this.PaletteCombo, 0); //パレット情報の書き込み. uint palette_plist = this.MapEditConf[this.MapStyle.SelectedIndex].palette_plist; uint palette_address = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist); if (palette_address == 0) {//未割り当てならば新規確保しようか palette_address = InputFormRef.AppendBinaryData(PaletteFormRef.NewNullPalette(palette_count), undodata); } PFR.MakePaletteBitmapToROM(bitmap, palette_address, palette_count, undodata); //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist, palette_address, undodata); if (!r) { Program.Undo.Rollback(undodata); return(false); } PaletteAddress.Value = palette_address; } else {//パレットはインポートしない場合 //パレット情報の継承. bitmap.Palette = this.MapObjImage.Palette; //obj Bitmap交換 this.MapObjImage = bitmap; } return(true); }
private void WriteButton_Click(object sender, EventArgs e) { if (this.MapStyle.SelectedIndex < 0) { return; } uint config_plist = this.MapEditConf[this.MapStyle.SelectedIndex].config_plist; uint chipset_address = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CONFIG, config_plist); Undo.UndoData undodata = Program.Undo.NewUndoData(this); byte[] chipsetConfigZ = LZ77.compress(this.configUZ); uint newaddr = InputFormRef.WriteBinaryData(this, (uint)ChipsetConfigAddress.Value, chipsetConfigZ, InputFormRef.get_data_pos_callback_lz77, undodata); if (newaddr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return; } ChipsetConfigAddress.Value = newaddr; //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.CONFIG, config_plist, newaddr, undodata); if (!r) { Program.Undo.Rollback(undodata); return; } //書き込んだ通知. InputFormRef.ShowWriteNotifyAnimation(this, newaddr); Program.Undo.Push(undodata); InputFormRef.WriteButtonToYellow(this.ConfigWriteButton, false); //マップエディタが開いていれば更新する MapEditorForm.UpdateMapStyleIfOpen(); }
private void AddressList_SelectedIndexChanged(object sender, EventArgs e) { uint mapid = this.MapPictureBox.GetMapID(); if (mapid == U.NOT_FOUND) { return; } MapSettingForm.PLists plist = MapSettingForm.GetMapPListsWhereMapID(mapid); if (plist.palette_plist == 0) { return; } uint palette = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, plist.palette_plist); if (palette == U.NOT_FOUND) { return; } int palette_index = SamplePaletteComboBox.SelectedIndex; if (palette_index < 0) { palette_index = 0; } this.ChangePaletteBitmap = GetTileAnime1((uint)P4.Value, (uint)W2.Value, palette, palette_index); this.X_SAMPLE_BIG_PIC.Image = this.ChangePaletteBitmap; MapSettingForm.MapAnimations anime = new MapSettingForm.MapAnimations(); anime.change_bitmap_bytes = GetTileAnime1((uint)P4.Value, (uint)W2.Value); //マップの再描画 this.MapPictureBox.UpdateAnime(anime); }
private void PaletteWriteButton_Click(object sender, EventArgs e) { if (this.MapStyle.SelectedIndex < 0) { return; } uint palette_plist = this.MapEditConf[this.MapStyle.SelectedIndex].palette_plist; int palette_count = MAX_MAP_PALETTE_COUNT; Undo.UndoData undodata = Program.Undo.NewUndoData(this); //パレット情報の書き込み. uint palette_address = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist); if (palette_address == 0) {//未割り当てならば新規確保しようか palette_address = InputFormRef.AppendBinaryData(PaletteFormRef.NewNullPalette(palette_count), undodata); } PFR.MakePaletteColorPaletteToROM(this.MapObjImage.Palette, palette_address, palette_count, undodata); InputFormRef.WriteButtonToYellow(this.PaletteWriteButton, false); //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist, palette_address, undodata); if (!r) { Program.Undo.Rollback(undodata); return; } Program.Undo.Push(undodata); //マップエディタが開いていれば更新する MapEditorForm.UpdateMapStyleIfOpen(); }
public static void MakeCheckError(uint mapid, List <FELint.ErrorSt> errors) { InputFormRef N_InputFormRef = N_Init(null); MapSettingForm.PLists plists = MapSettingForm.GetMapPListsWhereMapID(mapid); if (plists.mapchange_plist == 0) {//マップ変化がない return; } uint change_addr = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CHANGE, plists.mapchange_plist); if (!U.isSafetyOffset(change_addr)) {//マップ設定の方でトラップするので不要. return; } byte[] configUZ = ImageUtilMap.UnLZ77ChipsetData(plists.config_plist); if (configUZ == null) {//マップ設定の方でトラップするので不要. return; } //マップサイズ int mapwidth; int mapheight; ImageUtilMap.UnLZ77MapDataUShort(plists.mappointer_plist, out mapwidth, out mapheight); bool isFE6 = Program.ROM.RomInfo.version() == 6; N_InputFormRef.ReInit(change_addr); List <uint> useNumber = new List <uint>(); uint addr = N_InputFormRef.BaseAddress; for (int i = 0; i < N_InputFormRef.DataCount; i++, addr += N_InputFormRef.BlockSize) { uint number = Program.ROM.u8(0 + addr); if (useNumber.IndexOf(number) >= 0) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr , R._("マップ変化({0})のIDが重複しています", U.To0xHexString(number)))); continue; } if (number > 0x7f) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr , R._("マップ変化({0})のIDが、0x7Fを超えています。\r\nマップ変化IDは、0x7F以下でなければなりません。", U.To0xHexString(number)))); continue; } uint x = Program.ROM.u8(1 + addr); uint y = Program.ROM.u8(2 + addr); uint width = Program.ROM.u8(3 + addr); uint height = Program.ROM.u8(4 + addr); uint pointer = Program.ROM.u32(8 + addr); //マップ変化を使いまわしているところが軒並みエラーになるのでやめておこう... // if (x + width > mapwidth) // { // errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr // , R._("マップ変化({0})の幅(X:{1} Width:{2})は、マップの幅({3})より大きいです", number, x , width, mapwidth))); // } // if (y + height > mapheight) // { // if (isFE6 && mapid == 0x28 && addr == 0x687A94) // { // //FE6にはマップ変化リストを間違えて指定している場所があるので無視する. // continue; // } // errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr // , R._("マップ変化({0})の高さ(Y:{1} Height:{2})は、マップの高さ({3})より大きいです", U.To0xHexString(number), y, height, mapheight))); // } if (pointer == 0) {//マップ変化ポインタ 0 を容認する. continue; } if (!U.isSafetyPointer(pointer)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr , R._("マップ変化({0})のポインタ({1})が危険です。", U.To0xHexString(number), U.To0xHexString(pointer)))); continue; } //ポインタ先の検証. uint mapAddr = U.toOffset(pointer); uint limitAddr = mapAddr + (2 * width * height); if (!U.isSafetyOffset(limitAddr - 1)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr , R._("マップ変化({0})のポインタ({1})か、マップ変化のサイズの指定が正しくありません。", U.To0xHexString(number), U.To0xHexString(pointer)))); continue; } for (; mapAddr < limitAddr; mapAddr += 2) { int mapData = (int)Program.ROM.u16(mapAddr); if (!ImageUtilMap.IsCorrectMapChip(mapData, configUZ, isFE6)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPCHANGE, addr , R._("マップ変化({0})のポインタ({1})先のデータで、不正なタイルデータ({2})。", U.To0xHexString(number), U.To0xHexString(pointer), U.To0xHexString(mapData)))); break; } } } }
//マップチップだけを描画する public static Bitmap DrawMapChipOnly( uint obj_plist //image , uint palette_plist //palette , MapSettingForm.MapAnimations anime = null ) { uint obj_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.OBJECT, obj_plist & 0xFF); uint obj2_plist = (obj_plist >> 8) & 0xFF; //FE8にはないが FE7は、 plistを2つ設定できることがある. uint obj2_offset = 0; uint palette_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist); if (!U.isSafetyOffset(obj_offset)) { return(null); } if (!U.isSafetyOffset(palette_offset)) { return(null); } if (obj2_plist > 0) {//plist2があれば obj2_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.OBJECT, obj2_plist); if (!U.isSafetyOffset(obj2_offset)) { return(null); } } byte[] objUZ = LZ77.decompress(Program.ROM.Data, obj_offset); //image if (objUZ.Length <= 0) //image { return(null); } if (obj2_plist > 0) { //plist2があれば byte[] obj2UZ = LZ77.decompress(Program.ROM.Data, obj2_offset); if (obj2UZ.Length <= 0) //image { return(null); } objUZ = U.ArrayAppend(objUZ, obj2UZ); } byte[] paletteData = Program.ROM.getBinaryData(palette_offset, (2 * 16) * 16); //マップアニメが定義されていればアニメーション補正する. if (anime != null) { if (anime.change_bitmap_bytes != null) { U.ArrayPatch(anime.change_bitmap_bytes, 0, objUZ, 32 * (8 / 2) * 4 * 16); } if (anime.change_palette_bytes != null) { U.ArrayPatch(anime.change_palette_bytes, 0, paletteData, (anime.change_palette_start_index) * 2); } } //マップチップの読込 int obj_width = 32 * 8; int obj_height = ImageUtil.CalcHeight(obj_width, objUZ.Length); Bitmap obj_image = ImageUtil.ByteToImage16Tile(obj_width, obj_height , objUZ, 0 , paletteData, 0 , 0 ); return(obj_image); }
//エラー検出 public static void MakeCheckErrors(uint mapid, List <FELint.ErrorSt> errors) { uint mapaddr = GetMapAddr(mapid); if (mapaddr == U.NOT_FOUND) { return; } PLists plists = GetMapPListsWhereAddr(mapaddr); { uint obj2_plist = (plists.obj_plist >> 8) & 0xFF; //FE8にはないが FE7は、 plistを2つ設定できることがある. uint obj2_offset = 0; uint obj_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.OBJECT, plists.obj_plist & 0xFF); if (!U.isSafetyOffset(obj_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_OBJECT, mapaddr , R._("PLIST({0})が無効です", plists.obj_plist))); } else { FELint.CheckLZ77ImageErrors(obj_offset, errors, FELint.Type.MAPSETTING_PLIST_OBJECT, mapaddr, 256, 120); } if (obj2_plist > 0) {//plist2があれば obj2_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.OBJECT, obj2_plist); if (!U.isSafetyOffset(obj2_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_OBJECT, mapaddr , R._("PLIST({0})が無効です", obj2_plist))); } else { FELint.CheckLZ77ImageErrors(obj2_offset, errors, FELint.Type.MAPSETTING_PLIST_OBJECT, mapaddr, 256, 120); } } } { uint config_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CONFIG, plists.config_plist); if (!U.isSafetyOffset(config_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_CONFIG, mapaddr , R._("PLIST({0})が無効です", plists.config_plist))); } else { FELint.CheckLZ77(config_offset, errors, FELint.Type.MAPSETTING_PLIST_CONFIG, mapaddr); } } { uint map_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.MAP, plists.mappointer_plist); if (!U.isSafetyOffset(map_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAP, mapaddr , R._("PLIST({0})が無効です", plists.mappointer_plist))); } else { Size mapsize = ImageUtilMap.GetMapSize(plists.obj_plist, plists.palette_plist, plists.config_plist, plists.mappointer_plist); if (mapsize.Width <= 0 || mapsize.Height <= 0) { //LZ77に失敗してそうだからチェックする FELint.CheckLZ77(map_offset, errors, FELint.Type.MAPSETTING_PLIST_MAP, mapaddr); errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAP, mapaddr , R._("マップが破損しています。") , mapid)); } uint limitWidth = ImageUtilMap.GetLimitMapWidth(mapsize.Height); if (mapsize.Width < ImageUtilMap.MAP_MIN_WIDTH || mapsize.Height < ImageUtilMap.MAP_MIN_HEIGHT) { if (IsFreliaCasle(mapid)) { //nop //フレリア城 } else { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAP, mapaddr , R._("マップが狭すぎます。現在のサイズ:({0},{1}) 利用できる最少サイズ:({2},{3})" , mapsize.Width, mapsize.Height, ImageUtilMap.MAP_MIN_WIDTH, ImageUtilMap.MAP_MIN_HEIGHT) , mapid)); } } else if (limitWidth == 0) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAP, mapaddr , R._("マップが広すぎます。\r\n現在のサイズ({0},{1})", mapsize.Width, mapsize.Height, limitWidth) )); } else if (mapsize.Width > limitWidth) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAP, mapaddr , R._("マップが広すぎます。\r\n現在のサイズ({0},{1})\r\nこの幅だと、利用可能な高さは、幅は{2}までです。", mapsize.Width, mapsize.Height, limitWidth) )); } } } { uint pal_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, plists.palette_plist); if (!U.isSafetyOffset(pal_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_PALETTE, mapaddr , R._("PLIST({0})が無効です", plists.palette_plist))); } } if (plists.mapchange_plist != 0) { uint mapchange_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.CHANGE, plists.mapchange_plist); if (!U.isSafetyOffset(mapchange_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_MAPCHANGE, mapaddr , R._("PLIST({0})が無効です", plists.mapchange_plist))); } } if (plists.anime1_plist != 0) { uint anime1_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.ANIMATION, plists.anime1_plist); if (!U.isSafetyOffset(anime1_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_ANIMETION1, mapaddr , R._("PLIST({0})が無効です", plists.anime1_plist))); } } if (plists.anime2_plist != 0) { uint anime2_offset = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.ANIMATION2, plists.anime2_plist); if (!U.isSafetyOffset(anime2_offset)) { errors.Add(new FELint.ErrorSt(FELint.Type.MAPSETTING_PLIST_ANIMETION2, mapaddr , R._("PLIST({0})が無効です", plists.anime2_plist))); } } }
private void ObjImportButton_Click(object sender, EventArgs e) { if (this.MapStyle.SelectedIndex < 0) { return; } uint obj_plist = this.MapEditConf[this.MapStyle.SelectedIndex].obj_plist; uint obj2_plist = (obj_plist >> 8) & 0xFF; //FE8にはないが FE7は、 plistを2つ設定できることがある. Bitmap bitmap = ImageFormRef.ImportFilenameDialog(this); if (bitmap == null) { return; } int width = 32 * 8; int height = 32 * 8; int palette_count = MAX_MAP_PALETTE_COUNT; if (bitmap.Width != width || bitmap.Height < 128) { R.ShowStopError("画像サイズが正しくありません。\r\nWidth:{2} Height:{3} でなければなりません。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", bitmap.Width, bitmap.Height, width, height); return; } height = ImageUtil.CalcHeight(width, width * bitmap.Height / 2); if (ObjImportOption.SelectedIndex == 1) {//パレットもインポートする場合 パレット数のチェック. 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; } bitmap = PaletteSwapper(bitmap); } //画像 byte[] image = ImageUtil.ImageToByte16Tile(bitmap, width, height); //画像等データの書き込み Undo.UndoData undodata = Program.Undo.NewUndoData(this); if (obj2_plist > 0) {//FE7とかあるフィールド画像分割 byte[] image1 = U.subrange(image, 0, (uint)(image.Length / 2)); byte[] image2 = U.subrange(image, (uint)(image.Length / 2), (uint)image.Length); byte[] image1Z = LZ77.compress(image1); byte[] image2Z = LZ77.compress(image2); uint newaddr = InputFormRef.WriteBinaryData(this, (uint)ObjAddress.Value, image1Z, InputFormRef.get_data_pos_callback_lz77, undodata); if (newaddr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return; } ObjAddress.Value = newaddr; //拡張領域に書き込んでいる可能性もあるので plstを更新する. MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.OBJECT, obj_plist, newaddr, undodata); //分割されたデータを書き込み newaddr = InputFormRef.WriteBinaryData(this, (uint)ObjAddress2.Value, image2Z, InputFormRef.get_data_pos_callback_lz77, undodata); if (newaddr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return; } ObjAddress2.Value = newaddr; //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.OBJECT, obj2_plist, newaddr, undodata); if (!r) { Program.Undo.Rollback(undodata); return; } //書き込んだ通知. InputFormRef.ShowWriteNotifyAnimation(this, newaddr); } else { byte[] imageZ = LZ77.compress(image); uint newaddr = InputFormRef.WriteBinaryData(this, (uint)ObjAddress.Value, imageZ, InputFormRef.get_data_pos_callback_lz77, undodata); if (newaddr == U.NOT_FOUND) { Program.Undo.Rollback(undodata); return; } ObjAddress.Value = newaddr; //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.OBJECT, obj_plist, newaddr, undodata); if (!r) { Program.Undo.Rollback(undodata); return; } //書き込んだ通知. InputFormRef.ShowWriteNotifyAnimation(this, newaddr); } if (ObjImportOption.SelectedIndex == 1) {//パレットもインポートする場合 //パレットの交換 MapObjImage = bitmap; U.ForceUpdate(this.PaletteTypeCombo, 0); U.ForceUpdate(this.PaletteCombo, 0); //パレット情報の書き込み. uint palette_plist = this.MapEditConf[this.MapStyle.SelectedIndex].palette_plist; uint palette_address = MapPointerForm.PlistToOffsetAddr(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist); if (palette_address == 0) {//未割り当てならば新規確保しようか palette_address = InputFormRef.AppendBinaryData(PaletteFormRef.NewNullPalette(palette_count), undodata); } PaletteFormRef.MakePaletteBitmapToROM(this, bitmap, palette_address, palette_count, undodata); //拡張領域に書き込んでいる可能性もあるので plstを更新する. bool r = MapPointerForm.Write_Plsit(MapPointerForm.PLIST_TYPE.PALETTE, palette_plist, palette_address, undodata); if (!r) { Program.Undo.Rollback(undodata); return; } PaletteAddress.Value = palette_address; } else {//パレットはインポートしない場合 //パレット情報の継承. bitmap.Palette = this.MapObjImage.Palette; //obj Bitmap交換 this.MapObjImage = bitmap; } Program.Undo.Push(undodata); //チップセットの更新. Chipset_Update(); SelectedChipset_Update(); MapStyle_SelectedIndexChanged(sender, e); InputFormRef.WriteButtonToYellow(this.PaletteWriteButton, false); //マップエディタが開いていれば更新する MapEditorForm.UpdateMapStyleIfOpen(); }