crc.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  24. #include "Common/CRC.h"
  25. #include "Common/Debug.h"
  26. void CRC::addCRC( UnsignedByte val )
  27. {
  28. int hibit;
  29. //cout << "\t\t" << hex << val;
  30. // val = htonl(val);
  31. //cout << " / " << hex << val <<endl;
  32. if (crc & 0x80000000) {
  33. hibit = 1;
  34. } else {
  35. hibit = 0;
  36. }
  37. crc <<= 1;
  38. crc += val;
  39. crc += hibit;
  40. //cout << hex << (*crc) <<endl;
  41. }
  42. void CRC::computeCRC( const void *buf, Int len )
  43. {
  44. if (!buf || len < 1)
  45. {
  46. return;
  47. }
  48. //crc = 0;
  49. UnsignedByte *uintPtr = (UnsignedByte *)buf;
  50. for (int i=0 ; i<len ; i++) {
  51. addCRC (*(uintPtr++));
  52. }
  53. //crc = htonl(crc);
  54. }
  55. //-------------------------------------------------------------------------------------------------
  56. //-------------------------------------------------------------------------------------------------
  57. UnsignedInt CRC::get( void )
  58. {
  59. UnsignedInt tcrc = crc;
  60. return tcrc;
  61. } // end skip