From e1d8e9cf38efe64289fc73c5fa102abad86b1a10 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 24 Oct 2011 21:51:22 -0700 Subject: [PATCH 1/4] Fix the horribly broken typedefs. Gettin' upgraded from 32-bit, but will you still love me when I'm 64? --- Sources/Plasma/CoreLib/hsTypes.h | 80 ++++++++++++++------------------ 1 file changed, 34 insertions(+), 46 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsTypes.h b/Sources/Plasma/CoreLib/hsTypes.h index df7209bd..4c0f98dd 100644 --- a/Sources/Plasma/CoreLib/hsTypes.h +++ b/Sources/Plasma/CoreLib/hsTypes.h @@ -46,8 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com /************************** Other Includes *****************************/ -#include -#include +#include +#include #if HS_CAN_USE_FLOAT #include @@ -64,16 +64,24 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com /************************** Basic Types *****************************/ -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned long dword; - #ifdef _MSC_VER -typedef unsigned __int64 qword; + typedef signed __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef signed __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef signed __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; #else -typedef unsigned long long qword; + #include #endif +typedef uint8_t byte; +typedef uint16_t word; +typedef uint32_t dword; +typedef uint64_t qword; + typedef size_t unsigned_ptr; typedef wchar_t wchar; @@ -84,51 +92,31 @@ typedef wchar_t wchar; #define kPosInfinity32 (0x7fffffff) #define kNegInfinity32 (0x80000000) -#if HS_BUILD_FOR_PS2 -typedef int Int32; -#else -typedef long Int32; -#endif +typedef int8_t Int8; +typedef int16_t Int16; +typedef int32_t Int32; +typedef int64_t Int64; -typedef short Int16; -typedef signed char Int8; +typedef uint8_t UInt8; +typedef uint16_t UInt16; +typedef uint32_t UInt32; +typedef uint64_t UInt64; -#if !(HS_BUILD_FOR_MAC) - typedef unsigned char UInt8; - typedef unsigned short UInt16; -#if HS_BUILD_FOR_PS2 - typedef unsigned int UInt32; -#else - typedef unsigned long UInt32; +#ifndef Byte + typedef uint8_t Byte; #endif - #ifndef Byte - typedef UInt8 Byte; - #endif - - #ifndef false - #define false 0 - #endif - #ifndef true - #define true 1 - #endif - #ifndef Boolean - #if HS_BUILD_FOR_UNIX - typedef char Boolean; - #else - typedef UInt8 Boolean; - #endif - #endif +#ifndef false + #define false 0 #endif - -#if HS_BUILD_FOR_WIN32 - typedef __int64 Int64; - typedef unsigned __int64 UInt64; -#else - typedef long long Int64; - typedef unsigned long long UInt64; +#ifndef true + #define true 1 +#endif +#ifndef Boolean + typedef uint8_t Boolean; #endif + typedef Int32 hsFixed; typedef Int32 hsFract; From eb16ed7f9747253a0445c0263c081d366a8f3b58 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 24 Oct 2011 22:12:08 -0700 Subject: [PATCH 2/4] Fix some silly assumptions about types. --- Sources/Plasma/CoreLib/hsMemory.cpp | 4 ++-- Sources/Plasma/CoreLib/hsStream.h | 4 ---- Sources/Plasma/CoreLib/hsTypes.h | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsMemory.cpp b/Sources/Plasma/CoreLib/hsMemory.cpp index dfddc595..99356046 100644 --- a/Sources/Plasma/CoreLib/hsMemory.cpp +++ b/Sources/Plasma/CoreLib/hsMemory.cpp @@ -99,11 +99,11 @@ void HSMemory::Clear(void* m, UInt32 byteLen) UInt8* memStop = mem + byteLen; if (byteLen > 8) - { while (UInt32(mem) & 3) + { while (unsigned_ptr(mem) & 3) *mem++ = 0; UInt32* mem32 = (UInt32*)mem; - UInt32* mem32Stop = (UInt32*)(UInt32(memStop) & ~3); + UInt32* mem32Stop = (UInt32*)(unsigned_ptr(memStop) & ~3); do { *mem32++ = 0; } while (mem32 < mem32Stop); diff --git a/Sources/Plasma/CoreLib/hsStream.h b/Sources/Plasma/CoreLib/hsStream.h index 7788af7a..1582a791 100644 --- a/Sources/Plasma/CoreLib/hsStream.h +++ b/Sources/Plasma/CoreLib/hsStream.h @@ -200,8 +200,6 @@ public: void ReadSwap(int count, Int16 values[]) { this->ReadSwap16(count, (UInt16*)values); } void ReadSwap(Int32* value) { *value = (Int32)this->ReadSwap32(); } void ReadSwap(int count, Int32 values[]) { this->ReadSwap32(count, (UInt32*)values); } - void ReadSwap(int* value) { *value = (Int32)this->ReadSwap32(); } - void ReadSwap(int count, int values[]) { this->ReadSwap32(count, (UInt32*)values); } #ifdef STREAM_LOGGER // Begin LogReadSwaps virtual void LogReadSwap(Int8* value, const char* desc) { this->ReadSwap(value); } @@ -224,8 +222,6 @@ public: void WriteSwap(int count, const Int16 values[]) { this->WriteSwap16(count, (UInt16*)values); } void WriteSwap(Int32 value) { this->WriteSwap32((UInt32)value); } void WriteSwap(int count, const Int32 values[]) { this->WriteSwap32(count, (UInt32*)values); } - void WriteSwap(int value) { this->WriteSwap32((UInt32)value); } - void WriteSwap(int count, const int values[]) { this->WriteSwap32(count, (UInt32*)values); } /* Overloaded End */ diff --git a/Sources/Plasma/CoreLib/hsTypes.h b/Sources/Plasma/CoreLib/hsTypes.h index 4c0f98dd..df2be19b 100644 --- a/Sources/Plasma/CoreLib/hsTypes.h +++ b/Sources/Plasma/CoreLib/hsTypes.h @@ -74,7 +74,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; #else - #include + #include #endif typedef uint8_t byte; @@ -82,7 +82,7 @@ typedef uint16_t word; typedef uint32_t dword; typedef uint64_t qword; -typedef size_t unsigned_ptr; +typedef uintptr_t unsigned_ptr; typedef wchar_t wchar; From 2980fbf53cf9274093d07e2a90b75d08c4a12c23 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 24 Oct 2011 22:17:12 -0700 Subject: [PATCH 3/4] Fix plEncryptedStream. --- Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index 489ed20e..ffbab70f 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp @@ -88,7 +88,7 @@ plEncryptedStream::~plEncryptedStream() // void plEncryptedStream::IEncipher(UInt32* const v) { - register unsigned long y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32; + register UInt32 y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32; while (n-- > 0) { @@ -102,7 +102,7 @@ void plEncryptedStream::IEncipher(UInt32* const v) void plEncryptedStream::IDecipher(UInt32* const v) { - register unsigned long y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32; + register UInt32 y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32; // sum = delta<<5, in general sum = delta * n From 0af3d1877d53d1284d084092ff259ac535aa409c Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Mon, 24 Oct 2011 23:25:20 -0700 Subject: [PATCH 4/4] Fix a few type issues due to typedef updates --- Sources/Plasma/CoreLib/hsSTLStream.cpp | 6 +++--- Sources/Plasma/CoreLib/hsStream.cpp | 6 +++--- .../NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp | 2 +- Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h | 2 -- .../NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp | 10 +--------- .../NucleusLib/pnNetProtocol/Private/pnNpCommon.h | 3 +-- .../Plasma/PubUtilLib/plCompression/plZlibCompress.cpp | 10 ++++++++-- Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp | 2 +- .../Tools/MaxComponent/plMultistageBehComponent.cpp | 6 +++--- 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsSTLStream.cpp b/Sources/Plasma/CoreLib/hsSTLStream.cpp index 4ed08c4c..aa7eb174 100644 --- a/Sources/Plasma/CoreLib/hsSTLStream.cpp +++ b/Sources/Plasma/CoreLib/hsSTLStream.cpp @@ -280,7 +280,7 @@ hsBool hsNamedPipeStream::ICheckOverlappedResult(BOOL result, UInt32 &numTransfe { if (WaitForSingleObject(fOverlap.hEvent, fTimeout) == WAIT_OBJECT_0) { - BOOL oResult = GetOverlappedResult(fPipe, &fOverlap, &numTransferred, FALSE); + BOOL oResult = GetOverlappedResult(fPipe, &fOverlap, (LPDWORD)&numTransferred, FALSE); if (oResult) return true; hsAssert(oResult, "GetOverlappedResult failed"); @@ -300,7 +300,7 @@ hsBool hsNamedPipeStream::IRead(UInt32 byteCount, void *buffer, UInt32 &numRead) if (fPipe != INVALID_HANDLE_VALUE && fReadMode) { - BOOL result = ReadFile(fPipe, buffer, byteCount, &numRead, &fOverlap); + BOOL result = ReadFile(fPipe, buffer, byteCount, (LPDWORD)&numRead, &fOverlap); if (ICheckOverlappedResult(result, numRead)) return true; } @@ -318,7 +318,7 @@ hsBool hsNamedPipeStream::IWrite(UInt32 byteCount, const void *buffer, UInt32 &n if (fPipe != INVALID_HANDLE_VALUE && !fReadMode) { - BOOL result = WriteFile(fPipe, buffer, byteCount, &numWritten, &fOverlap); + BOOL result = WriteFile(fPipe, buffer, byteCount, (LPDWORD)&numWritten, &fOverlap); if (ICheckOverlappedResult(result, numWritten)) return true; } diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 7fc2fe0e..8e0b38d3 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -827,7 +827,7 @@ UInt32 hsFileStream::Read(UInt32 bytes, void* buffer) #elif HS_BUILD_FOR_WIN32 UInt32 rBytes; - ReadFile((HANDLE)fRef, buffer, bytes, &rBytes, nil); + ReadFile((HANDLE)fRef, buffer, bytes, (LPDWORD)&rBytes, nil); if(bytes == rBytes) return bytes; else @@ -867,7 +867,7 @@ UInt32 hsFileStream::Write(UInt32 bytes, const void* buffer) return 0; #elif HS_BUILD_FOR_WIN32 UInt32 wBytes; - WriteFile((HANDLE)fRef, buffer, bytes, &wBytes, nil); + WriteFile((HANDLE)fRef, buffer, bytes, (LPDWORD)&wBytes, nil); if(bytes == wBytes) return bytes; else @@ -904,7 +904,7 @@ hsBool hsFileStream::AtEnd() #elif HS_BUILD_FOR_WIN32 UInt32 bytes; - PeekNamedPipe((void*)fRef, nil, 0, nil, &bytes, nil); + PeekNamedPipe((void*)fRef, nil, 0, nil, (LPDWORD)&bytes, nil); return bytes>0; #else hsAssert(0,"No hsStream::AtEnd() implemented for this stream class"); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp index e80ef064..1dd13f40 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp @@ -251,7 +251,7 @@ static unsigned THREADCALL NtWorkerThreadProc (AsyncThread * thread) { // process I/O operations { - dword bytes; + DWORD bytes; NtObject * ntObj; Operation * op; (void) GetQueuedCompletionStatus( diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h index 1c619c65..ba7f3cb4 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h @@ -113,8 +113,6 @@ public: operator bool() const { return IToBool(); } operator const CharPtr() const { return IToString(); } operator char() const { return IToChar(); } - operator unsigned int() const { return IToUInt(); } - operator int() const { return IToInt(); } void SetType(Types t) { fType=t; } UInt8 GetType( void ) const { return fType; } diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp index 75664efb..113198df 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp @@ -1125,15 +1125,7 @@ void CSrvPackBuffer::AddString (const wchar str[]) { } //============================================================================ -void CSrvPackBuffer::AddDWordArray (const dword * arr, unsigned count) { - // Don't let large counts cause pointer wrap - count &= 0x00ffffff; - AddData(arr, count * sizeof(arr[0])); -} - -//============================================================================ -void CSrvPackBuffer::AddDWordArray (const unsigned * arr, unsigned count) { - COMPILER_ASSERT(sizeof(unsigned) == sizeof(dword)); +void CSrvPackBuffer::AddDWordArray (const UInt32 * arr, unsigned count) { // Don't let large counts cause pointer wrap count &= 0x00ffffff; AddData(arr, count * sizeof(arr[0])); diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h index 4af2d3c7..a461cf44 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h @@ -470,8 +470,7 @@ public: void * Alloc (unsigned bytes); void AddData (const void * ptr, unsigned bytes); void AddString (const wchar str[]); - void AddDWordArray (const dword * arr, unsigned count); - void AddDWordArray (const unsigned * arr, unsigned count); + void AddDWordArray (const UInt32 * arr, unsigned count); // add new "Add..." methods here as needed unsigned Size (); diff --git a/Sources/Plasma/PubUtilLib/plCompression/plZlibCompress.cpp b/Sources/Plasma/PubUtilLib/plCompression/plZlibCompress.cpp index 7c2a807d..0a5eab8a 100644 --- a/Sources/Plasma/PubUtilLib/plCompression/plZlibCompress.cpp +++ b/Sources/Plasma/PubUtilLib/plCompression/plZlibCompress.cpp @@ -46,14 +46,20 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com hsBool plZlibCompress::Uncompress(UInt8* bufOut, UInt32* bufLenOut, const UInt8* bufIn, UInt32 bufLenIn) { - return (uncompress(bufOut, bufLenOut, bufIn, bufLenIn) == Z_OK); + unsigned long buflen_out; + bool result = (uncompress(bufOut, &buflen_out, bufIn, bufLenIn) == Z_OK); + *bufLenOut = buflen_out; + return result; } hsBool plZlibCompress::Compress(UInt8* bufOut, UInt32* bufLenOut, const UInt8* bufIn, UInt32 bufLenIn) { // according to compress doc, the bufOut buffer should be at least .1% larger than source buffer, plus 12 bytes. hsAssert(*bufLenOut>=(int)(bufLenIn*1.1+12), "bufOut compress buffer is not large enough"); - return (compress(bufOut, bufLenOut, bufIn, bufLenIn) == Z_OK); + unsigned long buflen_out; + bool result = (compress(bufOut, &buflen_out, bufIn, bufLenIn) == Z_OK); + *bufLenOut = buflen_out; + return result; } // diff --git a/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp b/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp index 5feefe14..3dd655dc 100644 --- a/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp +++ b/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp @@ -299,7 +299,7 @@ hsBool plJPEG::IWrite( plMipmap *source, hsStream *outStream ) } UInt8 *bufferAddr = jpgBuffer; - UInt32 bufferSize = jpgBufferSize; + unsigned long bufferSize = jpgBufferSize; jpeg_mem_dest( &cinfo, &bufferAddr, &bufferSize ); cinfo.image_width = source->GetWidth(); diff --git a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp index 0da9f929..43ab6b50 100644 --- a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp +++ b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp @@ -492,11 +492,11 @@ public: virtual void Skip(UInt32 deltaByteCount) { hsAssert(0, "Not supported"); } virtual void Rewind() { hsAssert(0, "Not supported"); } - virtual UInt32 GetEOF() { return fLoad->CurChunkLength(); } + virtual UInt32 GetEOF() { return (UInt32)fLoad->CurChunkLength(); } virtual UInt32 Read(UInt32 byteCount, void * buffer) { - UInt32 numRead = 0; + ULONG numRead = 0; hsAssert(fLoad, "No Max ILoad!"); if (fLoad) fLoad->Read(buffer, byteCount, &numRead); @@ -505,7 +505,7 @@ public: } virtual UInt32 Write(UInt32 byteCount, const void* buffer) { - UInt32 numWritten; + ULONG numWritten; hsAssert(fSave, "No Max ISave!"); if (fSave) fSave->Write(buffer, byteCount, &numWritten);