Initial MSVC 2008 projects workspace
This commit is contained in:
72
l2packets/xcpt/L2Packets_xcpt.cpp
Normal file
72
l2packets/xcpt/L2Packets_xcpt.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "stdafx.h"
|
||||
#include "L2Packets_xcpt.h"
|
||||
|
||||
L2P_Exception::~L2P_Exception()
|
||||
{
|
||||
if( m_what )
|
||||
{
|
||||
free( m_what );
|
||||
m_what = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char *L2P_Exception::what() const { return m_what; }
|
||||
|
||||
const L2P_Exception& L2P_Exception::operator=( const L2P_Exception& other )
|
||||
{
|
||||
if( this == &other ) return (*this);
|
||||
if( m_what ) free( m_what );
|
||||
m_what = NULL;
|
||||
if( other.m_what )
|
||||
{
|
||||
size_t ssize = strlen( other.m_what ) + 1;
|
||||
m_what = (char *)malloc( ssize );
|
||||
if( m_what ) strncpy( m_what, other.m_what, ssize-1 );
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
L2P_MemoryError::L2P_MemoryError( const char *comment, size_t bytes )
|
||||
{
|
||||
m_what = (char *)malloc( 256 );
|
||||
if( m_what )
|
||||
{
|
||||
sprintf( m_what, "%s: Tried to allocate: %u bytes", comment, (unsigned int)bytes );
|
||||
}
|
||||
}
|
||||
|
||||
L2P_ReadException::L2P_ReadException( const char *comment, int nBytesTriedToRead, int nPos, int nSize )
|
||||
{
|
||||
m_what = (char *)malloc( 256 );
|
||||
if( m_what )
|
||||
{
|
||||
sprintf( m_what, "%s: Tried to read: %d bytes; pos: %d/%d", comment, nBytesTriedToRead, nPos, nSize );
|
||||
}
|
||||
}
|
||||
|
||||
L2P_WriteException::L2P_WriteException( const char *comment, int nBytesTriedToWrite, int nPos, int nSize )
|
||||
{
|
||||
m_what = (char *)malloc( 256 );
|
||||
if( m_what )
|
||||
{
|
||||
sprintf( m_what, "%s: Tried to write: %d bytes; pos: %d/%d", comment, nBytesTriedToWrite, nPos, nSize );
|
||||
}
|
||||
}
|
||||
|
||||
L2P_ObfuscateException::L2P_ObfuscateException( int size, unsigned int wrong_opcode, int error_code )
|
||||
{
|
||||
m_what = (char *)malloc( 256 );
|
||||
if( m_what )
|
||||
{
|
||||
sprintf( m_what, "Obfuscation failed (%d): opcode 0x%02X (table size %d)", error_code, wrong_opcode, size );
|
||||
}
|
||||
}
|
||||
|
||||
L2P_DeObfuscateException::L2P_DeObfuscateException( int size, unsigned int wrong_opcode, int error_code )
|
||||
{
|
||||
m_what = (char *)malloc( 256 );
|
||||
if( m_what )
|
||||
{
|
||||
sprintf( m_what, "Deobfuscation failed (%d): opcode 0x%02X (table size %d)", error_code, wrong_opcode, size );
|
||||
}
|
||||
}
|
66
l2packets/xcpt/L2Packets_xcpt.h
Normal file
66
l2packets/xcpt/L2Packets_xcpt.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef L2P_XCPT
|
||||
#define L2P_XCPT
|
||||
|
||||
/** \class L2P_Exception
|
||||
* Base class for exceptions that may be thrown from deep inside functions from library
|
||||
* (ByteArray, L2BasePacket) */
|
||||
class L2P_Exception
|
||||
{
|
||||
public:
|
||||
/** Default constructor, no comments */
|
||||
L2P_Exception(): m_what(NULL) {}
|
||||
/** Copy constructor */
|
||||
L2P_Exception( const L2P_Exception& other ): m_what(NULL)
|
||||
{
|
||||
this->operator=( other );
|
||||
}
|
||||
/** Destructor, frees internal string buffer if needed */
|
||||
virtual ~L2P_Exception();
|
||||
/** Returns pointer to string comment buffer
|
||||
\ return pointer to string comment buffer or NULL, if no comment
|
||||
*/
|
||||
virtual const char *what() const;
|
||||
/** Assigns comment from other L2P_Exception object to this
|
||||
* \param other - source to copy from */
|
||||
virtual const L2P_Exception& operator=( const L2P_Exception& other );
|
||||
|
||||
protected:
|
||||
char *m_what; ///< pointer to buffer to keep comment string
|
||||
};
|
||||
|
||||
/** \class L2P_Exception Will be thrown when malloc()/realloc() fails */
|
||||
class L2P_MemoryError: public L2P_Exception
|
||||
{
|
||||
public:
|
||||
L2P_MemoryError( const char *comment, size_t bytes );
|
||||
};
|
||||
|
||||
/** \class L2P_Exception Will be thrown when reading past end of packet OR calling
|
||||
* getByteAt() with index not in range of packet size */
|
||||
class L2P_ReadException: public L2P_Exception
|
||||
{
|
||||
public:
|
||||
L2P_ReadException( const char *comment, int nBytesTriedToRead, int nPos, int nSize );
|
||||
};
|
||||
|
||||
/** \class L2P_Exception Will be thrown when writing past end of packet (almost impossible situation) OR
|
||||
* by calling setByteAt() with index not in range of packet size */
|
||||
class L2P_WriteException: public L2P_Exception
|
||||
{
|
||||
public:
|
||||
L2P_WriteException( const char *comment, int nBytesTriedToWrite, int nPos, int nSize );
|
||||
};
|
||||
|
||||
class L2P_ObfuscateException: public L2P_Exception
|
||||
{
|
||||
public:
|
||||
L2P_ObfuscateException( int size, unsigned int wrong_opcode, int error_code );
|
||||
};
|
||||
|
||||
class L2P_DeObfuscateException: public L2P_Exception
|
||||
{
|
||||
public:
|
||||
L2P_DeObfuscateException( int size, unsigned int wrong_opcode, int error_code );
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user