Hey, ProgrammerGuy2012. Well, I'm trying to write a decompressor for an old SNES game. I already know how the compression scheme works in ASM and I'm basically trying to port it to C++, but I'm running into some problems.
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
usingnamespace std;
int decompressedpointer=decompressedpointer + 0x10;
int pointer=pointer + 0x1E82EA; //1999594=0x1E82EA aka the first compressed byte.
unsignedchar numberofmoves[2]; //The variable known as $28 in the rom.
unsignedchar charbyte[]={0x000000}; //This is where our hex character will be stored.
unsignedchar random[1]={0x000010};
unsignedchar result[2];
unsignedchar result2[2];
int startbuffer=startbuffer + 0x000000;
unsignedchar buffer[100];
int decompressedmoveposition;
int fromposition;
int second();
int main()
{
buffer[0]=0x00;
buffer[1]=0x00;
buffer[2]=0x00;
buffer[3]=0x00;
buffer[4]=0x00;
buffer[5]=0x00;
fstream file("gg4.smc", ios::in| ios::binary); //Read a byte from the rom
file.seekg(pointer);
file.read(reinterpret_cast<char*>(&charbyte), 4);
cout<<hex<<(int)charbyte[0]<<endl;
if (charbyte[0]>0x80){ //If our byte is more than 80...
numberofmoves[0]=(int)charbyte[0]&0x1F;
cout<<hex<<(int)numberofmoves[0]<<endl;
pointer=pointer + 1; //Increase the $pointer variable...
cout<<hex<<pointer<<endl;
result[0]=numberofmoves[0] + random[0]; //Add the numberofmoves variable and the random variable to get the result variable
cout<<hex<<(int)result[0]<<endl;
if (result[0]=0x20){}; //If result=0x20 go to a new routine
result2[0]=(char)startbuffer+random[0]; //Add startbuffer and random 1 to get the second result.
cout<<hex<<(int)result2[0]<<endl;
cout<<hex<<(int)numberofmoves[0]<<endl;
file.seekg(pointer); //Read the uncompressed bytes
file.read(reinterpret_cast<char*>(&buffer), numberofmoves[0]);
cout<<hex<<(int)buffer[0];
fstream file2("gg4uncompressed.smc", ios::in|ios::out| ios::binary);
file2.seekp(decompressedpointer);
file2.write (reinterpret_cast<char*>(&buffer),numberofmoves[0]);
while (numberofmoves[0]>0x00){
numberofmoves[0]=numberofmoves[0]--;
pointer=pointer++;
decompressedpointer=decompressedpointer++;}
cout<<"Congratulations bitches!! Your end pointer is...";
cout<<hex<<pointer<<(int)decompressedpointer;
random[0]=decompressedpointer;
cout<<hex<<(int)buffer[0]<<(int)buffer[1]<<(int)buffer[2];
system("PAUSE");
return main();}
elseif (charbyte[0]<0x80){return second();}
}
int second(){
numberofmoves[0]=charbyte[0]/0x04+0x01+0x01; //Do this to calculate the length of the uncompressed string.
cout<<hex<<(int)numberofmoves[0]<<endl;
decompressedmoveposition = charbyte[1] + (charbyte[0] << 8); //Turn the first 2 bytes of Charbyte into one integer.
decompressedmoveposition = (decompressedmoveposition - 0x03DF)&0x03FF;
cout<<hex<<(int)decompressedmoveposition<<endl;
pointer=pointer + 0x02;
result[0]=numberofmoves[0] + random[0]; //Add the numberofmoves variable and the random variable to get the result variable
cout<<hex<<(int)result[0]<<endl;
if (result[0]=0x20){};
fromposition=startbuffer+decompressedmoveposition;
cout<<hex<<(int)fromposition<<endl;
decompressedpointer=startbuffer + random[0];
cout<<hex<<(int)decompressedpointer<<endl;
cout<<hex<<fromposition;
cout<<hex<<decompressedpointer<<endl;
numberofmoves[0]=numberofmoves[0]+0x02;
fstream file2("gg4uncompressed.smc", ios::in|ios::out| ios::binary);
file2.seekg(fromposition); //Read the uncompressed bytes
file2.read(reinterpret_cast<char*>(&buffer), numberofmoves[0]);
cout<<hex<<(int)buffer[0]<<(int)buffer[1]<<(int)buffer[2]<<(int)buffer[3];
file2.seekp(decompressedpointer);
file2.write (reinterpret_cast<char*>(&buffer),numberofmoves[0]);}