/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see .
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: XferCRC.cpp //////////////////////////////////////////////////////////////////////////////
// Author: Matt Campbell, February 2002
// Desc: Xfer CRC implementation
///////////////////////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "Common/XferCRC.h"
#include "Common/XferDeepCRC.h"
#include "Common/CRC.h"
#include "Common/Snapshot.h"
#include "winsock2.h" // for htonl
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
XferCRC::XferCRC( void )
{
m_xferMode = XFER_CRC;
//Added By Sadullah Nader
//Initialization(s) inserted
m_crc = 0;
//
} // end XferCRC
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
XferCRC::~XferCRC( void )
{
} // end ~XferCRC
//-------------------------------------------------------------------------------------------------
/** Open file 'identifier' for writing */
//-------------------------------------------------------------------------------------------------
void XferCRC::open( AsciiString identifier )
{
// call base class
Xfer::open( identifier );
// initialize CRC to brand new one at zero
m_crc = 0;
} // end open
//-------------------------------------------------------------------------------------------------
/** Close our current file */
//-------------------------------------------------------------------------------------------------
void XferCRC::close( void )
{
} // end close
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
Int XferCRC::beginBlock( void )
{
return 0;
} // end beginBlock
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void XferCRC::endBlock( void )
{
} // end endBlock
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void XferCRC::addCRC( UnsignedInt val )
{
int hibit;
val = htonl(val);
if (m_crc & 0x80000000)
{
hibit = 1;
}
else
{
hibit = 0;
}
m_crc <<= 1;
m_crc += val;
m_crc += hibit;
} // end addCRC
// ------------------------------------------------------------------------------------------------
/** Entry point for xfering a snapshot */
// ------------------------------------------------------------------------------------------------
void XferCRC::xferSnapshot( Snapshot *snapshot )
{
if( snapshot == NULL )
{
return;
} // end if
// run the crc function of the snapshot
snapshot->crc( this );
} // end xferSnapshot
//-------------------------------------------------------------------------------------------------
/** Perform a single CRC operation on the data passed in */
//-------------------------------------------------------------------------------------------------
void XferCRC::xferImplementation( void *data, Int dataSize )
{
if (!data || dataSize < 1)
{
return;
}
const UnsignedInt *uintPtr = (const UnsignedInt *) (data);
for (Int i=0 ; igetLength() > 16385 )
{
DEBUG_CRASH(( "XferSave cannot save this ascii string because it's too long. Change the size of the length header (but be sure to preserve save file compatability\n" ));
throw XFER_STRING_ERROR;
} // end if
// save length of string to follow
UnsignedShort len = asciiStringData->getLength();
xferUnsignedShort( &len );
// save string data
if( len > 0 )
xferUser( (void *)asciiStringData->str(), sizeof( Byte ) * len );
} // end xferAsciiString
// ------------------------------------------------------------------------------------------------
/** Save unicodee string */
// ------------------------------------------------------------------------------------------------
void XferDeepCRC::xferUnicodeString( UnicodeString *unicodeStringData )
{
// sanity
if( unicodeStringData->getLength() > 255 )
{
DEBUG_CRASH(( "XferSave cannot save this unicode string because it's too long. Change the size of the length header (but be sure to preserve save file compatability\n" ));
throw XFER_STRING_ERROR;
} // end if
// save length of string to follow
Byte len = unicodeStringData->getLength();
xferByte( &len );
// save string data
if( len > 0 )
xferUser( (void *)unicodeStringData->str(), sizeof( WideChar ) * len );
} // end xferUnicodeString