Clone of Akilla's acserver @ https://github.com/deregtd/ACServer

calcalgs.txt 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. DWORD GetMagicNumber(BYTE * buf, UINT cb, BOOL bIncludeSize)
  2. {
  3. DWORD dwCS = 0;
  4. UINT i;
  5. if (bIncludeSize) dwCS += cb<<16;
  6. // sum up the DWORDs:
  7. for (i=0; i<(cb>>2); i++) dwCS += ((DWORD *)buf)[i];
  8. // now any remaining bytes are summed in reverse endian
  9. int shift=3;
  10. for (i=(i<<2); i<cb; i++) {dwCS += buf[i]<<(shift*8); shift--;}
  11. return dwCS;
  12. }
  13. void NetworkPipe::GenerateTransportHeader (int len)
  14. {
  15. thdr->dwSeqnum=seqnum;
  16. thdr->dwCRC = 0;
  17. thdr->dwFlags=0x0802;
  18. ulong new_crc=Calc802_CRC((ulong *)send_buffer, (char *)send_buffer) ^ Fetch_XORVAL_SEND()
  19. + CalcTransportCRC((ulong *)send_buffer) + 0x3291975;
  20. }
  21. ulong NetworkPipe::Calc802_CRC (ulong *hex, char *buf)
  22. {
  23. int ofs=20,hofs=5,size,plen;
  24. ulong crc,*woot=hex;
  25. size=(hex[4]&0xFFFF)+20; crc=0;
  26. while (ofs<size)
  27. {
  28. plen=(hex[hofs+2]>>16);
  29. crc+=GetMagicNumber((BYTE *)&hex[hofs], 16, 1);
  30. crc+=GetMagicNumber((BYTE *)&hex[hofs+4], plen-16, 1);
  31. ofs+=plen; hofs=0;
  32. hex=(ulong *)&buf[ofs];
  33. }
  34. return crc;
  35. }
  36. ulong NetworkPipe::CalcTransportCRC (ulong *woot)
  37. {
  38. return GetMagicNumber ( (BYTE *)woot, 20, 1 );
  39. }