Stop the crashes at least.

master
sigonasr2 5 months ago
parent 15e8df7c01
commit 6db778d6a8
  1. 25
      EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp
  2. BIN
      EarthboundBattleBackgrounds/x64/Debug/EarthboundBattleBackgrounds.exe

@ -60,17 +60,17 @@ struct Rom{
int32_t bpos2{};
while(data[pos]!=0xFF){
if(pos>=data.length())throw std::runtime_error{"Unexpected end of data."};
char commandType{data[pos]>>5};
char length{(data[pos]&0x1F)+1};
int commandType{data[pos]>>5};
int length{(data[pos]&0x1F)+1};
if(commandType==7){
commandType=(data[pos]&0x1C)>>2;
length=((data[pos]&3)<<8)+(data[pos+1])+1;
length=((int(data[pos])&3)<<8)+int(data[pos+1])+1;
++pos;
}
if(bpos+length<0)throw std::runtime_error("Length ended up negative.");
pos++;
if(commandType>=4){
bpos2=(data[pos]<<8)+data[pos+1];
bpos2=(int(data[pos])<<8)+int(data[pos+1]);
if(bpos2<0)throw std::runtime_error("Reading negative data.");
pos+=2;
}
@ -127,17 +127,17 @@ struct Rom{
int read{};
while(data[pos]!=0xFF){
if (pos >= data.length())return;
char commandType{data[pos]>>5};
char len{data[pos]&0x1F+1};
int commandType{data[pos]>>5};
int len{data[pos]&0x1F+1};
if(commandType==7){
commandType=(data[pos]&0x1C)>>2;
len=((data[pos]&3)<<8)+data[pos+1]+1;
commandType=(int(data[pos])&0x1C)>>2;
len=((int(data[pos])&3)<<8)+int(data[pos+1])+1;
++pos;
}
if(bpos+len>maxLength||bpos+len<0)return;
++pos;
if(commandType>=4) {
bpos2=(data[pos]<<8)+data[pos+1];
bpos2=(int(data[pos])<<8)+data[pos+1];
if(bpos2>=maxLength||bpos2<0)return;
pos+=2;
}
@ -336,11 +336,16 @@ public:
}
}
void GraphicsDisplayTest(){
}
int yOffset{0};
bool OnUserUpdate(float fElapsedTime) override
{
PaletteDisplayTest();
//PaletteDisplayTest();
GraphicsDisplayTest();
return true;
}
};

Loading…
Cancel
Save