Current News Archived News Search News Discussion Forum Old Forum Install Programs More Downloads... Troubleshooting Source Code Format Specs. Misc. Information Non-SF Stuff Links Small banner for links to this site: |
diff --git a/LoadStorm/Storm.cpp b/LoadStorm/Storm.cpp
--- a/LoadStorm/Storm.cpp
+++ b/LoadStorm/Storm.cpp
~STORMMODULE();\r
} Storm;\r
\r
+void FreeStorm();\r
+\r
HINSTANCE hStorm = 0;\r
BOOL AlreadyLoaded = FALSE;\r
\r
\r
STORMMODULE::~STORMMODULE()\r
{\r
- SFileCloseArchive = 0;\r
- SFileCloseFile = 0;\r
- SFileDestroy = 0;\r
- SFileGetFileArchive = 0;\r
- SFileGetFileSize = 0;\r
- SFileOpenArchive = 0;\r
- SFileOpenFile = 0;\r
- SFileOpenFileEx = 0;\r
- SFileReadFile = 0;\r
- SFileSetBasePath = 0;\r
- SFileSetFilePointer = 0;\r
- SFileSetLocale = 0;\r
- SFileGetBasePath = 0;\r
- SFileGetArchiveName = 0;\r
- SFileGetFileName = 0;\r
-\r
- if (hStorm==0) return;\r
-\r
- if (AlreadyLoaded==FALSE) FreeLibrary(hStorm);\r
- hStorm = 0;\r
+ FreeStorm();\r
}\r
\r
HINSTANCE LoadStorm(char * DllFileName)\r
{\r
+ FreeStorm();\r
if (hStorm!=0) return 0;\r
hStorm = GetModuleHandle(DllFileName);\r
if (hStorm == NULL) hStorm = LoadLibrary(DllFileName);\r
return hStorm;\r
}\r
\r
+void FreeStorm()\r
+{\r
+ SFileCloseArchive = 0;\r
+ SFileCloseFile = 0;\r
+ SFileDestroy = 0;\r
+ SFileGetFileArchive = 0;\r
+ SFileGetFileSize = 0;\r
+ SFileOpenArchive = 0;\r
+ SFileOpenFile = 0;\r
+ SFileOpenFileEx = 0;\r
+ SFileReadFile = 0;\r
+ SFileSetBasePath = 0;\r
+ SFileSetFilePointer = 0;\r
+ SFileSetLocale = 0;\r
+ SFileGetBasePath = 0;\r
+ SFileGetArchiveName = 0;\r
+ SFileGetFileName = 0;\r
+\r
+ if (hStorm==0) return;\r
+\r
+ if (AlreadyLoaded==FALSE) FreeLibrary(hStorm);\r
+ hStorm = 0;\r
+}\r
diff --git a/grpapi/grpapi.cpp b/grpapi/grpapi.cpp
--- a/grpapi/grpapi.cpp
+++ b/grpapi/grpapi.cpp
#include "grpapi.h"\r
-#include "..\\LoadStorm\\storm.h"\r
+#include "../LoadStorm/storm.h"\r
#include <malloc.h>\r
\r
#ifdef GRPAPI_STATIC\r
DWORD Offset;\r
} FRAMEHEADER;\r
\r
+GETPIXELPROC MyGetPixel = GetPixel;\r
+SETPIXELPROC MySetPixel = (SETPIXELPROC)SetPixelV;\r
+\r
void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha);\r
\r
extern HINSTANCE hStorm;\r
\r
BOOL GRPAPI WINAPI LoadGrpApi()\r
{\r
- if (hStorm==0) return FALSE;\r
+ if (!hStorm) return FALSE;\r
else return TRUE;\r
}\r
\r
{\r
}\r
\r
+BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName)\r
+{\r
+ if (LoadStorm((char *)lpDllFileName)) return TRUE;\r
+ else return FALSE;\r
+}\r
+\r
BOOL GRPAPI WINAPI LoadPalette(LPCSTR lpFileName, DWORD *dwPaletteBuffer)\r
{\r
- if (lpFileName==0 || dwPaletteBuffer==0) return FALSE;\r
+ if (!lpFileName || !dwPaletteBuffer) return FALSE;\r
HANDLE hFile;\r
- if (SFileOpenFileEx!=0 && SFileGetFileSize!=0\r
- && SFileSetFilePointer!=0 && SFileReadFile!=0\r
- && SFileCloseFile!=0) {\r
- if (SFileOpenFileEx(0,lpFileName,1,&hFile)==0) return FALSE;\r
+ if (SFileOpenFileEx && SFileGetFileSize\r
+ && SFileSetFilePointer && SFileReadFile\r
+ && SFileCloseFile) {\r
+ if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return FALSE;\r
DWORD fsz = SFileGetFileSize(hFile,0);\r
SFileSetFilePointer(hFile,0,0,FILE_BEGIN);\r
if (fsz>=1024) {\r
\r
HANDLE GRPAPI WINAPI LoadGrp(LPCSTR lpFileName)\r
{\r
- if (lpFileName==0) return (HANDLE)-1;\r
+ if (!lpFileName) return (HANDLE)-1;\r
HANDLE hFile;\r
char *GrpFile;\r
- if (SFileOpenFileEx!=0 && SFileGetFileSize!=0\r
- && SFileSetFilePointer!=0 && SFileReadFile!=0\r
- && SFileCloseFile!=0) {\r
- if (SFileOpenFileEx(0,lpFileName,1,&hFile)==0) return (HANDLE)-1;\r
+ if (SFileOpenFileEx && SFileGetFileSize\r
+ && SFileSetFilePointer && SFileReadFile\r
+ && SFileCloseFile) {\r
+ if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return (HANDLE)-1;\r
DWORD fsz = SFileGetFileSize(hFile,0);\r
if (fsz<6) {\r
SFileCloseFile(hFile);\r
return (HANDLE)-1;\r
}\r
GrpFile = (char *)VirtualAlloc(0,fsz,MEM_COMMIT,PAGE_READWRITE);\r
- if (GrpFile!=0) {\r
+ if (GrpFile) {\r
SFileSetFilePointer(hFile,0,0,FILE_BEGIN);\r
SFileReadFile(hFile,GrpFile,fsz,0,0);\r
}\r
return (HANDLE)-1;\r
}\r
GrpFile = (char *)VirtualAlloc(0,fsz,MEM_COMMIT,PAGE_READWRITE);\r
- if (GrpFile!=0) {\r
+ if (GrpFile) {\r
SetFilePointer(hFile,0,0,FILE_BEGIN);\r
ReadFile(hFile,GrpFile,fsz,&tsz,0);\r
}\r
\r
BOOL GRPAPI WINAPI DestroyGrp(HANDLE hGrp)\r
{\r
- if (hGrp==0 || hGrp==INVALID_HANDLE_VALUE) return FALSE;\r
+ if (!hGrp || hGrp==INVALID_HANDLE_VALUE) return FALSE;\r
VirtualFree(hGrp,0,MEM_RELEASE);\r
return TRUE;\r
}\r
\r
BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha)\r
{\r
- if (hGrp==0 || hGrp==INVALID_HANDLE_VALUE || hdcDest==0 || dwPalette==0) return FALSE;\r
+ if (!hGrp || hGrp==INVALID_HANDLE_VALUE || hdcDest==0 || !dwPalette) return FALSE;\r
GRPHEADER *GrpFile = (GRPHEADER *)hGrp;\r
nFrame %= GrpFile->nFrames;\r
FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)GrpFile)+6))[nFrame];\r
@@ -184,67 +193,119 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
nXDest += GrpFrame->Left;\r
nYDest += GrpFrame->Top;\r
WORD *GrpOffsets = ((WORD *)(((char *)GrpFile)+GrpFrame->Offset));\r
- for (DWORD y=0;y<GrpFrame->Height;y++) {\r
- BYTE *RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
- WORD x=0,ofs=0;\r
- while (x<GrpFrame->Width) {\r
- if (RowData[ofs]<=64) {\r
- if ((dwFlags&HORIZONTAL_FLIP)==0 && (dwFlags&VERTICAL_FLIP)==0) {\r
- for (WORD i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
- x++;\r
+ BYTE *RowData;\r
+ WORD x,ofs;\r
+ DWORD y;\r
+ WORD i;\r
+ if (!(dwFlags&HORIZONTAL_FLIP) && !(dwFlags&VERTICAL_FLIP)) {\r
+ for (y=0;y<GrpFrame->Height;y++) {\r
+ RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+ x=0; ofs=0;\r
+ while (x<GrpFrame->Width) {\r
+ if (!(RowData[ofs] & 0x80)) {\r
+ if (!(RowData[ofs] & 0x40)) {\r
+ for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=RowData[ofs]+1;\r
}\r
- }\r
- else if (dwFlags&HORIZONTAL_FLIP && (dwFlags&VERTICAL_FLIP)==0) {\r
- for (WORD i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
- x++;\r
+ else {\r
+ for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=2;\r
}\r
}\r
- else if ((dwFlags&HORIZONTAL_FLIP)==0 && dwFlags&VERTICAL_FLIP) {\r
- for (WORD i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
- x++;\r
+ else {\r
+ x+=RowData[ofs]-128;\r
+ ofs++;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else if (dwFlags&HORIZONTAL_FLIP && !(dwFlags&VERTICAL_FLIP)) {\r
+ for (y=0;y<GrpFrame->Height;y++) {\r
+ RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+ x=0; ofs=0;\r
+ while (x<GrpFrame->Width) {\r
+ if (!(RowData[ofs] & 0x80)) {\r
+ if (!(RowData[ofs] & 0x40)) {\r
+ for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=RowData[ofs]+1;\r
+ }\r
+ else {\r
+ for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=2;\r
}\r
}\r
else {\r
- for (WORD i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
- x++;\r
- }\r
+ x+=RowData[ofs]-128;\r
+ ofs++;\r
}\r
- ofs+=RowData[ofs]+1;\r
}\r
- else if (RowData[ofs]<=128) {\r
- if ((dwFlags&HORIZONTAL_FLIP)==0 && (dwFlags&VERTICAL_FLIP)==0) {\r
- for (WORD i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,nXDest+x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
- x++;\r
+ }\r
+ }\r
+ else if (!(dwFlags&HORIZONTAL_FLIP) && dwFlags&VERTICAL_FLIP) {\r
+ for (y=0;y<GrpFrame->Height;y++) {\r
+ RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+ x=0; ofs=0;\r
+ while (x<GrpFrame->Width) {\r
+ if (!(RowData[ofs] & 0x80)) {\r
+ if (!(RowData[ofs] & 0x40)) {\r
+ for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=RowData[ofs]+1;\r
}\r
- }\r
- else if (dwFlags&HORIZONTAL_FLIP && (dwFlags&VERTICAL_FLIP)==0) {\r
- for (WORD i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,Right-x,nYDest+y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
- x++;\r
+ else {\r
+ for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=2;\r
}\r
}\r
- else if ((dwFlags&HORIZONTAL_FLIP)==0 && dwFlags&VERTICAL_FLIP) {\r
- for (WORD i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,nXDest+x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
- x++;\r
+ else {\r
+ x+=RowData[ofs]-128;\r
+ ofs++;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ for (y=0;y<GrpFrame->Height;y++) {\r
+ RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y]));\r
+ x=0; ofs=0;\r
+ while (x<GrpFrame->Width) {\r
+ if (!(RowData[ofs] & 0x80)) {\r
+ if (!(RowData[ofs] & 0x40)) {\r
+ for (i=1;i<=RowData[ofs] && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+i]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=RowData[ofs]+1;\r
+ }\r
+ else {\r
+ for (i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
+ SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
+ x++;\r
+ }\r
+ ofs+=2;\r
}\r
}\r
else {\r
- for (WORD i=0;i<RowData[ofs]-64 && x<GrpFrame->Width;i++) {\r
- SetPix(hdcDest,Right-x,Bottom-y,dwPalette[RowData[ofs+1]],dwFlags,dwAlpha);\r
- x++;\r
- }\r
+ x+=RowData[ofs]-128;\r
+ ofs++;\r
}\r
- ofs+=2;\r
- }\r
- else {\r
- x+=RowData[ofs]-128;\r
- ofs++;\r
}\r
}\r
}\r
@@ -253,21 +314,28 @@ BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WOR
\r
BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo)\r
{\r
- if (hGrp==0 || hGrp==INVALID_HANDLE_VALUE || GrpInfo==0) return FALSE;\r
+ if (!hGrp || hGrp==INVALID_HANDLE_VALUE || !GrpInfo) return FALSE;\r
memcpy(GrpInfo,hGrp,6);\r
return TRUE;\r
}\r
\r
+void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc)\r
+{\r
+ MyGetPixel = lpGetPixelProc;\r
+}\r
+\r
+void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc)\r
+{\r
+ MySetPixel = lpSetPixelProc;\r
+}\r
+\r
void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DWORD dwAlpha)\r
{\r
if (dwFlags&SHADOW_COLOR) {\r
- ((BYTE *)&clrColor)[0] = ((BYTE *)&dwFlags)[1];\r
- ((BYTE *)&clrColor)[1] = ((BYTE *)&dwFlags)[2];\r
- ((BYTE *)&clrColor)[2] = ((BYTE *)&dwFlags)[3];\r
- ((BYTE *)&clrColor)[3] = 0;\r
+ clrColor = (dwFlags >> 8) & 0x00FFFFFF;\r
}\r
if (dwFlags&ALPHA_BLEND) {\r
- DWORD dwColor = GetPixel(hDC,X,Y);\r
+ DWORD dwColor = MyGetPixel(hDC,X,Y);\r
\r
// Old alpha\r
/*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256);\r
@@ -293,6 +361,5 @@ void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD dwFlags, DW
( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 )\r
+ ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 );\r
}\r
- SetPixelV(hDC,X,Y,clrColor);\r
+ MySetPixel(hDC,X,Y,clrColor);\r
}\r
-\r
diff --git a/grpapi/grpapi.def b/grpapi/grpapi.def
--- a/grpapi/grpapi.def
+++ b/grpapi/grpapi.def
EXPORTS\r
- LoadPalette @1\r
- LoadGrp @2\r
- DestroyGrp @3\r
- DrawGrp @4\r
- GetGrpInfo @5\r
- LoadGrpApi @6\r
- FreeGrpApi @7\r
+ LoadPalette @1\r
+ LoadGrp @2\r
+ DestroyGrp @3\r
+ DrawGrp @4\r
+ GetGrpInfo @5\r
+ LoadGrpApi @6\r
+ FreeGrpApi @7\r
+ SetFunctionGetPixel @8\r
+ SetFunctionSetPixel @9\r
+ SetMpqDll @10\r
diff --git a/grpapi/grpapi.h b/grpapi/grpapi.h
--- a/grpapi/grpapi.h
+++ b/grpapi/grpapi.h
/*\r
\r
- ShadowFlare GRP Library. (c) ShadowFlare Software 2002\r
+ ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2006\r
\r
Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare)\r
*/\r
BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha);\r
BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo);\r
\r
+typedef COLORREF (WINAPI* GETPIXELPROC)(\r
+ HDC hDC, // same value as hdcDest from DrawGrp,\r
+ // does not need to be used as an HDC,\r
+ // can be used for any other type of pointer\r
+ int X, // x-coordinate of pixel\r
+ int Y // y-coordinate of pixel\r
+);\r
+typedef void (WINAPI* SETPIXELPROC)(\r
+ HDC hDC, // same value as hdcDest from DrawGrp,\r
+ // does not need to be used as an HDC,\r
+ // can be used for any other type of pointer\r
+ int X, // x-coordinate of pixel\r
+ int Y, // y-coordinate of pixel\r
+ COLORREF clrColor // new pixel color\r
+);\r
+\r
+// Call these to have DrawGrp use custom functions for reading and drawing pixels\r
+// so that you can have it read from and write to a buffer, for example.\r
+void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc);\r
+void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc);\r
+\r
+// Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ).\r
+BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName);\r
+\r
// These no longer need to be called\r
BOOL GRPAPI WINAPI LoadGrpApi();\r
void GRPAPI WINAPI FreeGrpApi();\r
diff --git a/grpapi/grpapi.vcproj b/grpapi/grpapi.vcproj
--- a/grpapi/grpapi.vcproj
+++ b/grpapi/grpapi.vcproj
<Tool\r
Name="VCCLCompilerTool"\r
Optimization="2"\r
- InlineFunctionExpansion="1"\r
+ GlobalOptimizations="TRUE"\r
+ InlineFunctionExpansion="2"\r
+ FavorSizeOrSpeed="1"\r
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GRPAPI_EXPORTS"\r
StringPooling="TRUE"\r
RuntimeLibrary="0"\r
|