diff --git a/build/tools/MasterEditorTWL/MasterEditorTWL.ncb b/build/tools/MasterEditorTWL/MasterEditorTWL.ncb index 058b9ebf..fd4d1e55 100644 Binary files a/build/tools/MasterEditorTWL/MasterEditorTWL.ncb and b/build/tools/MasterEditorTWL/MasterEditorTWL.ncb differ diff --git a/build/tools/MasterEditorTWL/MasterEditorTWL.suo b/build/tools/MasterEditorTWL/MasterEditorTWL.suo index 8834acfd..b6c94fdb 100644 Binary files a/build/tools/MasterEditorTWL/MasterEditorTWL.suo and b/build/tools/MasterEditorTWL/MasterEditorTWL.suo differ diff --git a/build/tools/MasterEditorTWL/MasterEditorTWL/Debug/BuildLog.htm b/build/tools/MasterEditorTWL/MasterEditorTWL/Debug/BuildLog.htm index b1cfbfbe..576ce634 100644 Binary files a/build/tools/MasterEditorTWL/MasterEditorTWL/Debug/BuildLog.htm and b/build/tools/MasterEditorTWL/MasterEditorTWL/Debug/BuildLog.htm differ diff --git a/build/tools/MasterEditorTWL/MasterEditorTWL/srl.cpp b/build/tools/MasterEditorTWL/MasterEditorTWL/srl.cpp index d4d31c17..268bafda 100644 --- a/build/tools/MasterEditorTWL/MasterEditorTWL/srl.cpp +++ b/build/tools/MasterEditorTWL/MasterEditorTWL/srl.cpp @@ -14,6 +14,8 @@ using namespace MasterEditorTWL; +extern const u8 gBannerFont[]; + // // RCSrl クラス // @@ -905,24 +907,36 @@ ECSrlResult RCSrl::mrcNTR( FILE *fp ) } // 予約領域 + System::Boolean bRsv = true; for( i=0; i < 8; i++ ) { if( this->pRomHeader->s.ctrl_reserved_B[i] != 0 ) { - this->hErrorList->Add( gcnew RCMrcError( - "ROM情報予約領域", 0x078, 0x07f, "不正な値が含まれています。この領域をすべて0で埋めてください。", - "Reserved Area for ROM Info.", "Invalid data is included. Please set 0 into this area.", false, true ) ); + bRsv = false; + break; } } + if( !bRsv ) + { + this->hErrorList->Add( gcnew RCMrcError( + "ROM情報予約領域", 0x078, 0x07f, "不正な値が含まれています。この領域をすべて0で埋めてください。", + "Reserved Area for ROM Info.", "Invalid data is included. Please set 0 into this area.", false, true ) ); + } + bRsv = true; for( i=0; i < 32; i++ ) { if( this->pRomHeader->s.reserved_C[i] != 0 ) { - this->hErrorList->Add( gcnew RCMrcError( - "予約領域C", 0x078, 0x07f, "不正な値が含まれています。この領域をすべて0で埋めてください。", - "Reserved Area C", "Invalid data is included. Please set 0 into this area.", false, true ) ); + bRsv = false; + break; } } + if( !bRsv ) + { + this->hErrorList->Add( gcnew RCMrcError( + "予約領域C", 0x078, 0x07f, "不正な値が含まれています。この領域をすべて0で埋めてください。", + "Reserved Area C", "Invalid data is included. Please set 0 into this area.", false, true ) ); + } // ROMヘッダ以外の領域のチェック (ファイルから適宜リードする) @@ -948,6 +962,7 @@ ECSrlResult RCSrl::mrcNTR( FILE *fp ) return ECSrlResult::NOERROR; } // mrcNTR() +// TWL専用 ECSrlResult RCSrl::mrcTWL( FILE *fp ) { System::Int32 i; @@ -995,6 +1010,9 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) "実ファイルサイズ", METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, "中途半端な値です。通常では2のべき乗の値です。", "Actual File Size", "Invalid size. This size is usually power of 2.", false, true ) ); } + // 1Gbit以上のときの最終領域 + this->mrcPadding( fp ); + // セグメント3のCRC u16 crcseg3; BOOL crcret = getSeg3CRCInFp( fp, &crcseg3 ); @@ -1039,24 +1057,36 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) } // 予約領域 + System::Boolean bReserved = true; for( i=0; i < 7; i++ ) { if( this->pRomHeader->s.reserved_A[i] != 0 ) { - this->hErrorList->Add( gcnew RCMrcError( - "予約領域A", 0x015, 0x01b, "不正な値が含まれています。この領域をすべて0で埋めてください。", - "Reserved Area A", "Invalid data is included. Please set 0 into this area.", false, true ) ); + bReserved = false; + break; } } + if( !bReserved ) + { + this->hErrorList->Add( gcnew RCMrcError( + "予約領域A", 0x015, 0x01b, "不正な値が含まれています。この領域をすべて0で埋めてください。", + "Reserved Area A", "Invalid data is included. Please set 0 into this area.", false, true ) ); + } + bReserved = true; for( i=0; i < 39; i++ ) { if( this->pRomHeader->s.reserved_B[i] != 0 ) { - this->hErrorList->Add( gcnew RCMrcError( - "予約領域B", 0x099, 0x0bf, "不正な値が含まれています。この領域をすべて0で埋めてください。", - "Reserved Area B", "Invalid data is included. Please set 0 into this area.", false, true ) ); + bReserved = false; + break; } } + if( !bReserved ) + { + this->hErrorList->Add( gcnew RCMrcError( + "予約領域B", 0x099, 0x0bf, "不正な値が含まれています。この領域をすべて0で埋めてください。", + "Reserved Area B", "Invalid data is included. Please set 0 into this area.", false, true ) ); + } // ROMヘッダのチェック (TWL専用領域) @@ -1192,12 +1222,13 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) "Title ID", "Lower 4 bytes don't match ones of Game Code.", false, true ) ); } - System::Boolean bReserved = true; + bReserved = true; for( i=0; i < (0x2f0 - 0x240); i++ ) { if( this->pRomHeader->s.reserved_ltd_F[i] != 0 ) { bReserved = false; + break; } } if( !bReserved ) @@ -1214,6 +1245,7 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) if( p[ 0x378 + i ] != 0 ) { bReserved = false; + break; } } if( !bReserved ) @@ -1241,6 +1273,8 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) return pctl; } + this->mrcBanner( fp ); + // 追加チェック if( *(this->hMrcSpecialList->hIsCheck) == true ) { @@ -1282,7 +1316,6 @@ ECSrlResult RCSrl::mrcTWL( FILE *fp ) } } } - } //if( *(this->hMrcSpecialList->hIsCheck) ) return ECSrlResult::NOERROR; @@ -1550,3 +1583,215 @@ void RCSrl::clearParentalControl( System::Byte ogn ) this->hArrayParentalEffect[ ogn ] = gcnew System::Boolean( false ); this->hArrayParentalAlways[ ogn ] = gcnew System::Boolean( false ); } + +// パディングのチェック +void RCSrl::mrcPadding(FILE *fp) +{ + u32 romsize = 1 << (this->pRomHeader->s.rom_size); // ROM容量 + u32 padsize = 0; // 単位はByte + System::String ^padstrJ = gcnew System::String(""); + System::String ^padstrE = gcnew System::String(""); + System::String ^romstr = gcnew System::String(""); + + switch( romsize ) + { + case 1024: + padsize = 0x00280000; // 20Mbit = 2.5MB + padstrJ = "最終20Mbit"; + padstrE = "Last 20Mbit"; + romstr = "1Gbit"; + break; + case 2048: + padsize = 0x00500000; // 40Mbit = 5MB + padstrJ = "最終40Mbit"; + padstrE = "Last 40Mbit"; + romstr = "2Gbit"; + break; + case 4096: + padsize = 0x00A60000; // 83Mbit = 10.375MB + padstrJ = "最終83Mbit"; + padstrE = "Last 83Mbit"; + romstr = "4Gbit"; + break; + default: + padsize = 0; + break; + } + if( padsize == 0 ) + { + return; + } + + fseek( fp, 0, SEEK_END ); + u32 filesize = ftell(fp); // 実ファイルサイズ(単位Mbit) + u32 offset = ((romsize / 8) * 1024 * 1024) - padsize; + if( (offset + padsize) > filesize ) + { + this->hErrorList->Add( gcnew RCMrcError( + padstrJ, METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, + "読み出すことができませんでした。", + padstrE, "This area couldn't be read", true, true ) ); + return; + } + + u8 *buf = new u8[ padsize ]; + fseek( fp, offset, SEEK_SET ); + if( padsize != fread( buf, 1, padsize, fp ) ) + { + this->hErrorList->Add( gcnew RCMrcError( + padstrJ, METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, + "読み出すことができませんでした。", + padstrE, "This area couldn't be read", true, true ) ); + delete []buf; + return; + } + + System::Boolean bResult = true; + u32 i; + for( i=0; i < padsize; i++ ) + { + if( buf[i] != 0xff ) + { + bResult = false; + } + } + if( !bResult ) + { + this->hErrorList->Add( gcnew RCMrcError( + padstrJ, METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, + "FFh以外の値が格納されています。 " + romstr + " ROMの容量制限が守られていません。", + padstrE, + "This area includes illegai data. " + romstr + " Volume constraint is violated.", + true, true ) ); + } + delete []buf; +} + +// バナー +void RCSrl::mrcBanner(FILE *fp) +{ + u8 map[ 0x10000 ]; + u32 i; + + // 使用可能な文字のマップをつくる + // 文字コードをインデックスとして使用可能なら 1 が入る + // そうでないなら 0 が入る + for( i=0; i < 0x10000; i++ ) + { + map[i] = 0; + } + for( i=2; ; i+=2 ) // 0個目の要素はマジックコードなので含めない + { + u16 index = (u16)gBannerFont[i+1]; + index = (index << 8) + gBannerFont[i]; + if( index == 0xFEFF ) + { + break; + } + map[ index ] = 1; + } + map[ 0x0000 ] = 1; // 0x0000は許される + + // バナーを読み込む + u32 size = this->pRomHeader->s.banner_size; + u8 *banner = new u8[size]; + System::Diagnostics::Debug::WriteLine( "size: " + size.ToString("X") ); + fseek( fp, this->pRomHeader->s.banner_offset, SEEK_SET ); + if( size != fread( banner, 1, size, fp ) ) + { + this->hErrorList->Add( gcnew RCMrcError( + "バナーファイル", METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, + "読み出すことができませんでした。", + "Banner File", + "The file can't be read.", + true, true ) ); + } + + // バナーの各文字がマップに登録されているかチェック + System::Boolean bResult = true; + u32 start = 0x240; + u32 end = (size < 0x1240)?(size):(0x1240); // NTR互換領域までのときはTWL拡張領域をサーチしない + for( i=0x240; i < end; i+=2 ) + { + u16 index = banner[i+1]; + u16 indexbak = index; + index = (index << 8) + banner[i]; + if( map[ index ] == 0 ) + { + System::Diagnostics::Debug::WriteLine( i.ToString("X") + ":" + index.ToString("X") + ":" + indexbak.ToString("X") ); + bResult = false; + break; + } + } + if( !bResult ) + { + this->hErrorList->Add( gcnew RCMrcError( + "バナーファイル", METWL_ERRLIST_NORANGE, METWL_ERRLIST_NORANGE, + "使用不可能な文字セットが使用されています。", + "Banner File", + "A set of illegal charactor code is used.", + true, true ) ); + } + delete []banner; +} + +// バナーとして使用可能なフォントリスト(u16リトルエンディアン) +const u8 gBannerFont[] = +{ + 0xff, 0xfe, 0x20, 0x00, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, + 0x27, 0x00, 0x28, 0x00, 0x29, 0x00, 0x2a, 0x00, 0x2b, 0x00, 0x2c, 0x00, 0x2d, 0x00, 0x2e, 0x00, + 0x2f, 0x00, 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, + 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x3a, 0x00, 0x3b, 0x00, 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00, + 0x3f, 0x00, 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, + 0x47, 0x00, 0x48, 0x00, 0x49, 0x00, 0x4a, 0x00, 0x4b, 0x00, 0x4c, 0x00, 0x4d, 0x00, 0x4e, 0x00, + 0x4f, 0x00, 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, + 0x57, 0x00, 0x58, 0x00, 0x59, 0x00, 0x5a, 0x00, 0x5b, 0x00, 0x5c, 0x00, 0x5d, 0x00, 0x5e, 0x00, + 0x5f, 0x00, 0x60, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x64, 0x00, 0x65, 0x00, 0x66, 0x00, + 0x67, 0x00, 0x68, 0x00, 0x69, 0x00, 0x6a, 0x00, 0x6b, 0x00, 0x6c, 0x00, 0x6d, 0x00, 0x6e, 0x00, + 0x6f, 0x00, 0x70, 0x00, 0x71, 0x00, 0x72, 0x00, 0x73, 0x00, 0x74, 0x00, 0x75, 0x00, 0x76, 0x00, + 0x77, 0x00, 0x78, 0x00, 0x79, 0x00, 0x7a, 0x00, 0x7b, 0x00, 0x7c, 0x00, 0x7d, 0x00, 0x7e, 0x00, + 0x7f, 0x00, 0xac, 0x20, 0x1a, 0x20, 0x1e, 0x20, 0x26, 0x20, 0xc6, 0x02, 0x52, 0x01, 0x18, 0x20, + 0x19, 0x20, 0x1c, 0x20, 0x1d, 0x20, 0x22, 0x20, 0xdc, 0x02, 0x22, 0x21, 0x3a, 0x20, 0x53, 0x01, + 0xa1, 0x00, 0xa2, 0x00, 0xa3, 0x00, 0xa8, 0x00, 0xa9, 0x00, 0xae, 0x00, 0xb7, 0x00, 0xbf, 0x00, + 0xc0, 0x00, 0xc1, 0x00, 0xc2, 0x00, 0xc3, 0x00, 0xc4, 0x00, 0xc5, 0x00, 0xc6, 0x00, 0xc7, 0x00, + 0xc8, 0x00, 0xc9, 0x00, 0xca, 0x00, 0xcb, 0x00, 0xcc, 0x00, 0xcd, 0x00, 0xce, 0x00, 0xcf, 0x00, + 0xd0, 0x00, 0xd1, 0x00, 0xd2, 0x00, 0xd3, 0x00, 0xd4, 0x00, 0xd5, 0x00, 0xd6, 0x00, 0xd8, 0x00, + 0xd9, 0x00, 0xda, 0x00, 0xdb, 0x00, 0xdc, 0x00, 0xdd, 0x00, 0xdf, 0x00, 0xe0, 0x00, 0xe1, 0x00, + 0xe2, 0x00, 0xe3, 0x00, 0xe4, 0x00, 0xe5, 0x00, 0xe6, 0x00, 0xe7, 0x00, 0xe8, 0x00, 0xe9, 0x00, + 0xea, 0x00, 0xeb, 0x00, 0xec, 0x00, 0xed, 0x00, 0xee, 0x00, 0xef, 0x00, 0xf0, 0x00, 0xf1, 0x00, + 0xf2, 0x00, 0xf3, 0x00, 0xf4, 0x00, 0xf5, 0x00, 0xf6, 0x00, 0xf7, 0x00, 0xf8, 0x00, 0xf9, 0x00, + 0xfa, 0x00, 0xfb, 0x00, 0xfc, 0x00, 0xfd, 0x00, 0x00, 0x30, 0x01, 0x30, 0x02, 0x30, 0x0c, 0xff, + 0x0e, 0xff, 0xfb, 0x30, 0x3a, 0x00, 0x3b, 0x00, 0x1f, 0xff, 0x01, 0xff, 0xfc, 0x30, 0x41, 0x30, + 0x42, 0x30, 0x43, 0x30, 0x44, 0x30, 0x45, 0x30, 0x46, 0x30, 0x47, 0x30, 0x48, 0x30, 0x49, 0x30, + 0x4a, 0x30, 0x4b, 0x30, 0x4c, 0x30, 0x4d, 0x30, 0x4e, 0x30, 0x4f, 0x30, 0x50, 0x30, 0x51, 0x30, + 0x52, 0x30, 0x53, 0x30, 0x54, 0x30, 0x55, 0x30, 0x56, 0x30, 0x57, 0x30, 0x58, 0x30, 0x59, 0x30, + 0x5a, 0x30, 0x5b, 0x30, 0x5c, 0x30, 0x5d, 0x30, 0x5e, 0x30, 0x5f, 0x30, 0x60, 0x30, 0x61, 0x30, + 0x62, 0x30, 0x63, 0x30, 0x64, 0x30, 0x65, 0x30, 0x66, 0x30, 0x67, 0x30, 0x68, 0x30, 0x69, 0x30, + 0x6a, 0x30, 0x6b, 0x30, 0x6c, 0x30, 0x6d, 0x30, 0x6e, 0x30, 0x6f, 0x30, 0x70, 0x30, 0x71, 0x30, + 0x72, 0x30, 0x73, 0x30, 0x74, 0x30, 0x75, 0x30, 0x76, 0x30, 0x77, 0x30, 0x78, 0x30, 0x79, 0x30, + 0x7a, 0x30, 0x7b, 0x30, 0x7c, 0x30, 0x7d, 0x30, 0x7e, 0x30, 0x7f, 0x30, 0x80, 0x30, 0x81, 0x30, + 0x82, 0x30, 0x83, 0x30, 0x84, 0x30, 0x85, 0x30, 0x86, 0x30, 0x87, 0x30, 0x88, 0x30, 0x89, 0x30, + 0x8a, 0x30, 0x8b, 0x30, 0x8c, 0x30, 0x8d, 0x30, 0x8e, 0x30, 0x8f, 0x30, 0x90, 0x30, 0x91, 0x30, + 0x92, 0x30, 0x93, 0x30, 0x9b, 0x30, 0x9c, 0x30, 0x9d, 0x30, 0x9e, 0x30, 0xa1, 0x30, 0xa2, 0x30, + 0xa3, 0x30, 0xa4, 0x30, 0xa5, 0x30, 0xa6, 0x30, 0xa7, 0x30, 0xa8, 0x30, 0xa9, 0x30, 0xaa, 0x30, + 0xab, 0x30, 0xac, 0x30, 0xad, 0x30, 0xae, 0x30, 0xaf, 0x30, 0xb0, 0x30, 0xb1, 0x30, 0xb2, 0x30, + 0xb3, 0x30, 0xb4, 0x30, 0xb5, 0x30, 0xb6, 0x30, 0xb7, 0x30, 0xb8, 0x30, 0xb9, 0x30, 0xba, 0x30, + 0xbb, 0x30, 0xbc, 0x30, 0xbd, 0x30, 0xbe, 0x30, 0xbf, 0x30, 0xc0, 0x30, 0xc1, 0x30, 0xc2, 0x30, + 0xc3, 0x30, 0xc4, 0x30, 0xc5, 0x30, 0xc6, 0x30, 0xc7, 0x30, 0xc8, 0x30, 0xc9, 0x30, 0xca, 0x30, + 0xcb, 0x30, 0xcc, 0x30, 0xcd, 0x30, 0xce, 0x30, 0xcf, 0x30, 0xd0, 0x30, 0xd1, 0x30, 0xd2, 0x30, + 0xd3, 0x30, 0xd4, 0x30, 0xd5, 0x30, 0xd6, 0x30, 0xd7, 0x30, 0xd8, 0x30, 0xd9, 0x30, 0xda, 0x30, + 0xdb, 0x30, 0xdc, 0x30, 0xdd, 0x30, 0xde, 0x30, 0xdf, 0x30, 0xe0, 0x30, 0xe1, 0x30, 0xe2, 0x30, + 0xe3, 0x30, 0xe4, 0x30, 0xe5, 0x30, 0xe6, 0x30, 0xe7, 0x30, 0xe8, 0x30, 0xe9, 0x30, 0xea, 0x30, + 0xeb, 0x30, 0xec, 0x30, 0xed, 0x30, 0xee, 0x30, 0xef, 0x30, 0xf0, 0x30, 0xf1, 0x30, 0xf2, 0x30, + 0xf3, 0x30, 0xf4, 0x30, 0xf5, 0x30, 0xf6, 0x30, 0x01, 0x30, 0x02, 0x30, 0x0c, 0xff, 0x0e, 0xff, + 0xfb, 0x30, 0x1a, 0xff, 0x1b, 0xff, 0x1f, 0xff, 0x01, 0xff, 0x9b, 0x30, 0x9c, 0x30, 0xb4, 0x00, + 0x40, 0xff, 0x3e, 0xff, 0xe3, 0xff, 0x3f, 0xff, 0x05, 0x30, 0xfc, 0x30, 0x15, 0x20, 0x10, 0x20, + 0x0f, 0xff, 0x3c, 0xff, 0x5e, 0xff, 0x5c, 0xff, 0x26, 0x20, 0x18, 0x20, 0x19, 0x20, 0x1c, 0x20, + 0x1d, 0x20, 0x08, 0xff, 0x09, 0xff, 0x14, 0x30, 0x15, 0x30, 0x3b, 0xff, 0x3d, 0xff, 0x5b, 0xff, + 0x5d, 0xff, 0x08, 0x30, 0x09, 0x30, 0x0c, 0x30, 0x0d, 0x30, 0x0b, 0xff, 0x0d, 0xff, 0xb1, 0x00, + 0xd7, 0x00, 0xf7, 0x00, 0x1d, 0xff, 0x1e, 0x22, 0x34, 0x22, 0xb0, 0x00, 0x32, 0x20, 0x33, 0x20, + 0x06, 0xff, 0x06, 0x26, 0x05, 0x26, 0xcb, 0x25, 0xcf, 0x25, 0xce, 0x25, 0xc7, 0x25, 0xc6, 0x25, + 0xa1, 0x25, 0xa0, 0x25, 0xb3, 0x25, 0xb2, 0x25, 0xbd, 0x25, 0xbc, 0x25, 0x3b, 0x20, 0x12, 0x30, + 0x92, 0x21, 0x90, 0x21, 0x91, 0x21, 0x93, 0x21, 0x6f, 0x26, 0x6d, 0x26, 0x6a, 0x26, 0x0a, 0x00, + 0xff, 0xfe, // 終わりを表す意味で0xFEFFを最後につける +}; diff --git a/build/tools/MasterEditorTWL/MasterEditorTWL/srl.h b/build/tools/MasterEditorTWL/MasterEditorTWL/srl.h index 68160d12..000e0305 100644 --- a/build/tools/MasterEditorTWL/MasterEditorTWL/srl.h +++ b/build/tools/MasterEditorTWL/MasterEditorTWL/srl.h @@ -368,6 +368,8 @@ namespace MasterEditorTWL System::Boolean mrcRegion( System::UInt32 region ); // @ret リージョンが正しいかどうか void mrcRegionOrganization( System::UInt32 region ); void mrcRating( System::Byte ogn ); + void mrcPadding( FILE *fp ); + void mrcBanner( FILE *fp ); // utility void clearParentalControl( System::Byte ogn );