diff --git a/.gitignore b/.gitignore index 8256849..3c658e1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /EarthboundBattleBackgrounds/.vs/EarthboundBattleBackgrounds /EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/x64/Debug +/.vs/EarthboundBattleBackgrounds/v17 diff --git a/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp b/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp index 967563d..b96d369 100644 --- a/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp +++ b/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp @@ -122,9 +122,57 @@ struct Rom{ uint32_t pos{ptrStart}; uint32_t bpos{}; uint32_t bpos2{}; + char tmp; int read{}; while(data[pos]!=0xFF){ + if (pos >= data.length())return; + char commandType{data[pos]>>5}; + char len{data[pos]&0x1F+1}; + if(commandType==7){ + commandType=(data[pos]&0x1C)>>2; + len=((data[pos]&3)<<8)+data[pos+1]+1; + ++pos; + } + if(bpos+len>maxLength||bpos+len<0)return; + if(commandType>=4) { + bpos2=(data[pos]<<8)+data[pos+1]; + if(bpos2>=maxLength||bpos2<0)return; + pos+=2; + } + switch(commandType) { + case UNCOMPRESSED_BLOCK:{ + while(len--!=0)block[bpos++]=data[pos++]; + }break; + case RUN_LENGTH_ENCODED_BYTE:{ + while(len--!=0)block[bpos++]=data[pos]; + ++pos; + }break; + case RUN_LENGTH_ENCODED_SHORT:{ + if(bpos+2*len>maxLength||bpos<0)return; + while(len--!=0){ + block[bpos++]=data[pos]; + block[bpos++]=data[pos+1]; + } + }break; + case INCREMENTAL_SEQUENCE:{ + tmp=data[pos++]; + while(len--!=0)block[bpos++]=tmp++; + }break; + case REPEAT_PREVIOUS_DATA:{ + if(bpos+2*len>maxLength||bpos<0)return; + for(int i:std::views::iota(0,len))block[bpos++]=block[bpos2+i]; + }break; + case REVERSE_BITS:{ + if(bpos+2*len>maxLength||bpos<0)return; + while(len--!=0)block[bpos++]=Rom::reversedBytes[block[bpos2++]&0xFF]; + }break; + case UNKNOWN_1:{ + }break; + case UNKNOWN_2:{ + + }break; + } } } }; @@ -189,10 +237,24 @@ struct Rom{ } }; std::string data; + inline static std::string reversedBytes; std::vectorbackgrounds; std::vectorpalettes; std::vectorgraphics; Rom(){ + #pragma region Setup Reversed Bytes + reversedBytes.resize(256); + for(int i:std::views::iota(0U,reversedBytes.size())){ + uint8_t newNumb{}; + for(int digit=0;digit<8;digit++){ + uint8_t digitVal{1U<