Cosmo Canyon save patch

  • Thread starter Thread starter mav
  • Start date Start date
Status
Not open for further replies.
M

mav

Guest
I figured that it would be cool to develop patch for Cosmo Canyon so you mustn't see the animation. It would be a simple patch to change plot progression variable (before going to Bugenhaggen it's 0xD5 and after - 0xED). Unfortunetly, I'm not that good in C++ and I'm writing in Delphi, and I have problem with checksum function:

Qhimm's code:

Code: [Select]
Code:
int CFF7File::Checksum( char* b ){ int i = 0, t, d; long r = 0xFFFF, len = 4336; long pbit = 0x8000; while( len-- ) {  t = b[i++];  r ^= t << 8;  for(d=0;d<8;d++) {   if( r & pbit )    r = ( r << 1 ) ^ 0x1021;   else    r <<= 1;  }  r &= ( 1 << 16 ) - 1; } return ~r;}

My code:

Code: [Select]
Code:
  var i, t, d, r, len, pbit: integer;  content: array of char;    i := 0;    while (len >= 0) do begin      len := len - 1;      i := i + 1;      t := ord(content[i]);      r := r xor (t shl 8);      for d := 0 to 7 do begin        if(r and pbit)=0 then          r := ( r shl 1 ) xor $1021        else          r := r shl 1;        r := r and ((1 shl 16) - 1);      end;    end;

Could someone point me what I have done wrong ? Program calculates something, but it's diffrent from the original. Help apprieciated :).
 
This bit made me wonder:

Code: [Select]
Code:
if( r & pbit ) r = ( r << 1 ) ^ 0x1021;

So the r = ( r << 1 ) ^ 0x1021 is run if (r & pbit) is not zero, where as looking at yours you're comparing (r & pbit) to see if it is zero:

Code: [Select]
Code:
if(r and pbit)=0 then r := ( r shl 1 ) xor $1021

Oh and the obvious question since I haven't used Delphi, you have given a value to those variable such as len, p?
 
The only other thing I thought about was that Qhimm uses longs for some variables where you use integers. Not sure what range/size/representation Delphi uses for an integer, but if it's different I thought it might be a problem since you're bitshifting r, so if they're of different sizes for example you would end up with a different result.

Anyway, wait til Qhimm arrives (or Ficedula, if you're lucky  :wink: )
 
Here's what I can see from looking at it (mostly covered by previous posts):

  • God, I wrote ugly code back then.
  • You don't seem to be initializing the variables r, len and pbit.
  • You are pre-incrementing i (before indexing the data) instead of post-incrementing. IIRC Delphi dynamic arrays are zero-based, so this is probably incorrect.
  • You're testing for (r and pbit) = 0, which is the opposite condition of my code. It should be tested for non-zero.
  • I don't think the constriction to 16-bit data size is needed inside the loop, it could probably be moved out to the return statement (ineffective code on my part, not yours).
  • You are not inverting the checksum before returning (i.e. r := r xor $ffff)
Just guessing that this code would work better:

[/list]
Code: [Select]
Code:
  var i, t, d, r, len, pbit: integer;  content: array of char;    i := 0;    r := $ffff;    len := 4336;    while (len >= 0) do begin      len := len - 1;      t := ord(content[i]);      i := i + 1;      r := r xor (t shl 8);      for d := 0 to 7 do begin        if (r and pbit) = 0 then          r := r shl 1        else          r := ( r shl 1 ) xor $1021;      end;    end;    r := (r xor $ffff) and $ffff;
Then again as I'm no Delphi expert... I even had to reverse the if clause since I don't know how to test for value non-zero in Delphi. :P
 
I've tried this, still, something is wrong. I guess I'll wait for Fice, because he's good at translating C++ -> Delphi ;)
 
Status
Not open for further replies.
Back
Top