Qhimm.com Forums

Miscellaneous Forums => Archive => Topic started by: mav on 2005-05-19 22:47:52

Title: Cosmo Canyon save patch
Post by: mav on 2005-05-19 22:47:52
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]
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]
 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 :).
Title: Cosmo Canyon save patch
Post by: Synergy Blades on 2005-05-19 23:00:33
This bit made me wonder:

Code: [Select]
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]

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?
Title: Cosmo Canyon save patch
Post by: mav on 2005-05-19 23:09:32
Thanks for posting. Tried this, still, no luck... :-?
Title: Cosmo Canyon save patch
Post by: Synergy Blades on 2005-05-19 23:24:14
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: )
Title: Cosmo Canyon save patch
Post by: Qhimm on 2005-05-20 04:31:18
Here's what I can see from looking at it (mostly covered by previous posts):
Code: [Select]
 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
Title: Cosmo Canyon save patch
Post by: mav on 2005-05-24 13:22:22
I've tried this, still, something is wrong. I guess I'll wait for Fice, because he's good at translating C++ -> Delphi ;)