From: ShadowFlare Date: Fri, 18 Dec 2009 13:18:15 +0000 (-0700) Subject: Fix struct alignment and make SFTypes.h more portable. X-Git-Url: https://sfsrealm.hopto.org/projects/gitweb.cgi?p=SFmpqapi.git;a=commitdiff_plain;h=e0b276afa1dc42629b6eaad3ed578c29371f065e Fix struct alignment and make SFTypes.h more portable. --- diff --git a/SFTypes.h b/SFTypes.h index ec40e07..5758b9a 100644 --- a/SFTypes.h +++ b/SFTypes.h @@ -3,16 +3,48 @@ #ifndef SFTYPES_INCLUDED #define SFTYPES_INCLUDED +#if defined(_WIN32) || defined(_WIN64) + typedef signed char Int8; typedef signed short Int16; typedef signed long Int32; typedef signed __int64 Int64; +#ifdef _WIN64 +typedef signed __int64 IntPtr; +#else +typedef signed int IntPtr; +#endif + typedef unsigned char UInt8; typedef unsigned short UInt16; typedef unsigned long UInt32; typedef unsigned __int64 UInt64; +#ifdef _WIN64 +typedef unsigned __int64 UIntPtr; +#else +typedef unsigned int UIntPtr; +#endif + +#else + +#include + +typedef int8_t Int8; +typedef int16_t Int16; +typedef int32_t Int32; +typedef int64_t Int64; +typedef intptr_t IntPtr; + +typedef uint8_t UInt8; +typedef uint16_t UInt16; +typedef uint32_t UInt32; +typedef uint64_t UInt64; +typedef uintptr_t UIntPtr; + +#endif + union IntConv { Int8 i8[8]; UInt8 ui8[8]; diff --git a/SFmpqapi.cpp b/SFmpqapi.cpp index a0d5a13..bd4164d 100644 --- a/SFmpqapi.cpp +++ b/SFmpqapi.cpp @@ -1073,7 +1073,7 @@ DWORD SFMPQAPI WINAPI SFileGetFileInfo(MPQHANDLE hFile, DWORD dwInfoType) case SFILE_INFO_PRIORITY: return mpqOpenArc->dwPriority; case SFILE_INFO_HASH_INDEX: - return ((INT_PTR)mpqOpenFile->lpHashEntry-(INT_PTR)mpqOpenArc->lpHashTable)/sizeof(HASHTABLEENTRY); + return ((UIntPtr)mpqOpenFile->lpHashEntry-(UIntPtr)mpqOpenArc->lpHashTable)/sizeof(HASHTABLEENTRY); case SFILE_INFO_BLOCK_INDEX: return mpqOpenFile->lpHashEntry->dwBlockTableIndex; default: diff --git a/SFmpqapi.h b/SFmpqapi.h index 9508d61..7cef69b 100644 --- a/SFmpqapi.h +++ b/SFmpqapi.h @@ -295,6 +295,8 @@ long SFMPQAPI __inline SFMpqCompareVersion(); typedef HANDLE MPQHANDLE; +#include + struct FILELISTENTRY { DWORD dwFileExists; // Nonzero if this entry is used LCID lcLocale; // Locale ID of file @@ -322,6 +324,8 @@ struct MPQHEADER { DWORD dwBlockTableSize; // Number of entries in block table }; +#include + //Archive handles may be typecasted to this struct so you can access //some of the archive's properties and the decrypted hash table and //block table directly. This struct is based on Storm's internal @@ -379,6 +383,8 @@ struct MPQFILE { LPSTR lpFileName; }; +#include + struct BLOCKTABLEENTRY { DWORD dwFileOffset; // Offset to file DWORD dwCompressedSize; // Compressed size of file @@ -393,6 +399,8 @@ struct HASHTABLEENTRY { DWORD dwBlockTableIndex; // Index to the block table entry for the file }; +#include + // Defines for backward compatibility with old lmpqapi function names #define MpqAddFileToArcive MpqAddFileToArchive #define MpqOpenArchive SFileOpenArchive