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




ShadowFlare [Fri, 6 Oct 2006 08:59:29 +0000 (08:59 +0000)]
grpapi/grpapi.cpp

index 0ce1b29..e332505 100644 (file)
@@ -79,6 +79,23 @@ void GRPAPI WINAPI FreeGrpApi()
 {\r
 }\r
 \r
+/*\r
+HANDLE hProcessHeap = NULL;\r
+\r
+void * SFAlloc(size_t nSize)\r
+{\r
+       if (!hProcessHeap) hProcessHeap = GetProcessHeap();\r
+       if (hProcessHeap) return HeapAlloc(hProcessHeap, 0, nSize);\r
+       else return NULL;\r
+}\r
+\r
+void SFFree(void *lpMem)\r
+{\r
+       if (!hProcessHeap) hProcessHeap = GetProcessHeap();\r
+       if (hProcessHeap) HeapFree(hProcessHeap, 0, lpMem);\r
+}\r
+*/\r
+\r
 BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName)\r
 {\r
        if (LoadStorm((char *)lpDllFileName)) return TRUE;\r
@@ -569,6 +586,7 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
        lpFrameData->lpRowSizes = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD));\r
        lpFrameData->lpRowData = (LPBYTE *)malloc(lpFrameHeader->Height * sizeof(LPBYTE));\r
        lpRowBuf = (LPBYTE)malloc(lpFrameHeader->Width * 2);\r
+       nLastOffset = lpFrameHeader->Height * sizeof(WORD);\r
 \r
        for (y = 0; y < lpFrameHeader->Height; y++) {\r
                i = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + y) * lpGrpHeader->wMaxWidth;\r
@@ -608,7 +626,8 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
                                                        lpRowBuf[nBufPos]++;\r
                                                }\r
                                                x--;\r
-                                               nBufPos++;\r
+                                               if (nLastOffset + nBufPos + 1 <= 0xFFFF)\r
+                                                       nBufPos++;\r
                                                continue;\r
                                        }\r
 \r
@@ -619,7 +638,8 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
                                                lpRowBuf[nBufPos] = 0x41 + nRepeat;\r
                                                lpRowBuf[nBufPos+1] = (BYTE)lpImageData[i+x];\r
                                                x += nRepeat;\r
-                                               nBufPos += 2;\r
+                                               if (nLastOffset + nBufPos + 2 <= 0xFFFF)\r
+                                                       nBufPos += 2;\r
                                        }\r
                                        else {\r
                                                lpRowBuf[nBufPos] = 0;\r
@@ -636,18 +656,21 @@ void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHea
                                                        lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)lpImageData[i+x];\r
                                                }\r
                                                x--;\r
-                                               nBufPos += 1 + lpRowBuf[nBufPos];\r
+                                               if (nLastOffset + nBufPos + 1 + lpRowBuf[nBufPos] <= 0xFFFF)\r
+                                                       nBufPos += 1 + lpRowBuf[nBufPos];\r
                                        }\r
                                }\r
                                else {\r
                                        if (lpImageData[i+x] < 0) {\r
                                                lpRowBuf[nBufPos] = 0x81;\r
-                                               nBufPos++;\r
+                                               if (nLastOffset + nBufPos + 1 <= 0xFFFF)\r
+                                                       nBufPos++;\r
                                        }\r
                                        else {\r
                                                lpRowBuf[nBufPos] = 1;\r
                                                lpRowBuf[nBufPos+1] = (BYTE)lpImageData[i+x];\r
-                                               nBufPos += 2;\r
+                                               if (nLastOffset + nBufPos + 2 <= 0xFFFF)\r
+                                                       nBufPos += 2;\r
                                        }\r
                                }\r
                        }\r