From: ShadowFlare Date: Thu, 10 Jul 2008 09:40:44 +0000 (-0600) Subject: Converted repository to Git, fixed up line endings X-Git-Url: https://sfsrealm.hopto.org/projects/?a=commitdiff_plain;h=09d0556c7d76e364defc92cdee8fc41b808432ba;p=grpapi.git Converted repository to Git, fixed up line endings --- diff --git a/drawgrp/ReadMe.txt b/drawgrp/ReadMe.txt index d071da0..7c6cba8 100644 --- a/drawgrp/ReadMe.txt +++ b/drawgrp/ReadMe.txt @@ -1,34 +1,34 @@ -======================================================================== - CONSOLE APPLICATION : drawgrp -======================================================================== - - -AppWizard has created this drawgrp application for you. - -This file contains a summary of what you will find in each of the files that -make up your drawgrp application. - -drawgrp.dsp - This file (the project file) contains information at the project level and - is used to build a single project or subproject. Other users can share the - project (.dsp) file, but they should export the makefiles locally. - -drawgrp.cpp - This is the main application source file. - - -///////////////////////////////////////////////////////////////////////////// -Other standard files: - -StdAfx.h, StdAfx.cpp - These files are used to build a precompiled header (PCH) file - named drawgrp.pch and a precompiled types file named StdAfx.obj. - - -///////////////////////////////////////////////////////////////////////////// -Other notes: - -AppWizard uses "TODO:" to indicate parts of the source code you -should add to or customize. - -///////////////////////////////////////////////////////////////////////////// +======================================================================== + CONSOLE APPLICATION : drawgrp +======================================================================== + + +AppWizard has created this drawgrp application for you. + +This file contains a summary of what you will find in each of the files that +make up your drawgrp application. + +drawgrp.dsp + This file (the project file) contains information at the project level and + is used to build a single project or subproject. Other users can share the + project (.dsp) file, but they should export the makefiles locally. + +drawgrp.cpp + This is the main application source file. + + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named drawgrp.pch and a precompiled types file named StdAfx.obj. + + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/drawgrp/StdAfx.cpp b/drawgrp/StdAfx.cpp index a6251b8..b9fe822 100644 --- a/drawgrp/StdAfx.cpp +++ b/drawgrp/StdAfx.cpp @@ -1,8 +1,8 @@ -// stdafx.cpp : source file that includes just the standard includes -// drawgrp.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file +// stdafx.cpp : source file that includes just the standard includes +// drawgrp.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/drawgrp/StdAfx.h b/drawgrp/StdAfx.h index 98db2d5..8f72b5f 100644 --- a/drawgrp/StdAfx.h +++ b/drawgrp/StdAfx.h @@ -1,22 +1,22 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#if !defined(AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_) -#define AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - - -// TODO: reference additional headers your program requires here -#include "../grpapi/grpapi_no-lib.h" -#include "../LoadStorm/storm.h" -#include - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_) +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_) +#define AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// TODO: reference additional headers your program requires here +#include "../grpapi/grpapi_no-lib.h" +#include "../LoadStorm/storm.h" +#include + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__6C8ACA66_6D98_11D6_9E06_00A0C9199875__INCLUDED_) diff --git a/drawgrp/drawgrp.cpp b/drawgrp/drawgrp.cpp index 8521822..269e45c 100644 --- a/drawgrp/drawgrp.cpp +++ b/drawgrp/drawgrp.cpp @@ -1,183 +1,183 @@ -// drawgrp.cpp : Defines the entry point for the console application. -// - -#define _CRT_RAND_S -#include -#include -#include "stdafx.h" - - -/*int qmain(int argc, char* argv[]); - -int main(int argc, char* argv[]) -{ - HINSTANCE hStorm = LoadStorm("Storm.dll"); - if (SFileDestroy!=0) SFileDestroy(); - LoadGrpApi(); - int RetVal = qmain(argc,argv); - FreeGrpApi(); - if (hStorm!=0) FreeLibrary(hStorm); - return RetVal; -}*/ - -struct BufferInfo { - WORD nWidth; - WORD nHeight; - signed short *pBuffer; - WORD nFrame; -}; - -COLORREF WINAPI ReadPixelFromBuffer(BufferInfo *pBI, int X, int Y) -{ - if (pBI->nFrame == 0xFFFF) - return pBI->pBuffer[(Y * pBI->nWidth) + X]; - else - return pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X]; -} - -void WINAPI WritePixelToBuffer(BufferInfo *pBI, int X, int Y, COLORREF clrColor) -{ - if (pBI->nFrame == 0xFFFF) - pBI->pBuffer[(Y * pBI->nWidth) + X] = (signed short)clrColor; - else - //if (clrColor < 1 || clrColor > 13) - // pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)((BYTE)-clrColor); - //else - pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)clrColor; -} - -int main(int argc, char* argv[]) -{ - HANDLE hMPQ=0,hMPQ2=0,hMPQ3=0; - DWORD *dwPalette = (DWORD *)_alloca(1024); - memset(dwPalette,0,1024); - LoadStorm("SFMpq.dll"); - SetMpqDll("SFMpq.dll"); - if (SFileOpenArchive!=0) { - char *buffer = (char *)_alloca(13); - memcpy(buffer,"StarDat.mpq",12); - if (SFileOpenArchive(buffer,1000,0,&hMPQ)==0) return 0; - memcpy(buffer,"BrooDat.mpq",12); - SFileOpenArchive(buffer,2000,0,&hMPQ2); - memcpy(buffer,"Patch_rt.mpq",13); - SFileOpenArchive(buffer,3000,0,&hMPQ3); - } - BufferInfo BI; - LoadPalette("tileset\\Platform.wpe",dwPalette); - HANDLE hGrp, hGrp2; - if (argc>1) - hGrp = LoadGrp(argv[1]); - else - hGrp = LoadGrp("unit\\zerg\\zergling.grp"); - HDC hDC = GetDC(0); - GRPHEADER GrpInfo; - if (GetGrpInfo(hGrp,&GrpInfo)==0) {GrpInfo.nFrames=0;GrpInfo.wMaxWidth=0;GrpInfo.wMaxHeight=0;} - BI.nWidth = GrpInfo.wMaxWidth; - BI.nHeight = GrpInfo.wMaxHeight; - //BI.nWidth = 255; - //BI.nHeight = 255; - BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); - WORD i,x,y; - DWORD j, nGrpSize; - unsigned int u,v; - memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); - //for (DWORD j=0;j<16;j++){ - /*for (WORD i=0;i +#include +#include "stdafx.h" + + +/*int qmain(int argc, char* argv[]); + +int main(int argc, char* argv[]) +{ + HINSTANCE hStorm = LoadStorm("Storm.dll"); + if (SFileDestroy!=0) SFileDestroy(); + LoadGrpApi(); + int RetVal = qmain(argc,argv); + FreeGrpApi(); + if (hStorm!=0) FreeLibrary(hStorm); + return RetVal; +}*/ + +struct BufferInfo { + WORD nWidth; + WORD nHeight; + signed short *pBuffer; + WORD nFrame; +}; + +COLORREF WINAPI ReadPixelFromBuffer(BufferInfo *pBI, int X, int Y) +{ + if (pBI->nFrame == 0xFFFF) + return pBI->pBuffer[(Y * pBI->nWidth) + X]; + else + return pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X]; +} + +void WINAPI WritePixelToBuffer(BufferInfo *pBI, int X, int Y, COLORREF clrColor) +{ + if (pBI->nFrame == 0xFFFF) + pBI->pBuffer[(Y * pBI->nWidth) + X] = (signed short)clrColor; + else + //if (clrColor < 1 || clrColor > 13) + // pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)((BYTE)-clrColor); + //else + pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)clrColor; +} + +int main(int argc, char* argv[]) +{ + HANDLE hMPQ=0,hMPQ2=0,hMPQ3=0; + DWORD *dwPalette = (DWORD *)_alloca(1024); + memset(dwPalette,0,1024); + LoadStorm("SFMpq.dll"); + SetMpqDll("SFMpq.dll"); + if (SFileOpenArchive!=0) { + char *buffer = (char *)_alloca(13); + memcpy(buffer,"StarDat.mpq",12); + if (SFileOpenArchive(buffer,1000,0,&hMPQ)==0) return 0; + memcpy(buffer,"BrooDat.mpq",12); + SFileOpenArchive(buffer,2000,0,&hMPQ2); + memcpy(buffer,"Patch_rt.mpq",13); + SFileOpenArchive(buffer,3000,0,&hMPQ3); + } + BufferInfo BI; + LoadPalette("tileset\\Platform.wpe",dwPalette); + HANDLE hGrp, hGrp2; + if (argc>1) + hGrp = LoadGrp(argv[1]); + else + hGrp = LoadGrp("unit\\zerg\\zergling.grp"); + HDC hDC = GetDC(0); + GRPHEADER GrpInfo; + if (GetGrpInfo(hGrp,&GrpInfo)==0) {GrpInfo.nFrames=0;GrpInfo.wMaxWidth=0;GrpInfo.wMaxHeight=0;} + BI.nWidth = GrpInfo.wMaxWidth; + BI.nHeight = GrpInfo.wMaxHeight; + //BI.nWidth = 255; + //BI.nHeight = 255; + BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); + WORD i,x,y; + DWORD j, nGrpSize; + unsigned int u,v; + memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); + //for (DWORD j=0;j<16;j++){ + /*for (WORD i=0;i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/drawgrp/drawgrp.vcproj.vspscc b/drawgrp/drawgrp.vcproj.vspscc index 5d67725..680bbb6 100644 --- a/drawgrp/drawgrp.vcproj.vspscc +++ b/drawgrp/drawgrp.vcproj.vspscc @@ -1,10 +1,10 @@ -"" -{ -"FILE_VERSION" = "9237" -"ENLISTMENT_CHOICE" = "NEVER" -"PROJECT_FILE_RELATIVE_PATH" = "relative:drawgrp" -"NUMBER_OF_EXCLUDED_FILES" = "0" -"ORIGINAL_PROJECT_FILE_PATH" = "" -"NUMBER_OF_NESTED_PROJECTS" = "0" -"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" -} +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "relative:drawgrp" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/grpapi/GrpApi.bas b/grpapi/GrpApi.bas index 5fa2585..5dfca12 100644 --- a/grpapi/GrpApi.bas +++ b/grpapi/GrpApi.bas @@ -1,105 +1,105 @@ -Attribute VB_Name = "GrpApi" -Option Explicit - -' ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2006 - -' Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) - -Type GRPHEADER - nFrames As Integer - wMaxWidth As Integer - wMaxHeight As Integer -End Type - -Public Const HORIZONTAL_FLIP As Long = &H1& ' Flips the graphic horizontally -Public Const VERTICAL_FLIP As Long = &H2& ' Flips the graphic vertically -Public Const SHADOW_COLOR As Long = &H4& ' Causes the graphic to be drawn in one color - ' Second byte of flags is the red component of - ' the shadow's color, third byte is green, - ' fourth byte is blue; like this: - ' 'SHADOW_COLOR Or &HBBGGRR00' -Public Const ALPHA_BLEND As Long = &H8& ' Blends the graphic with what it is being drawn over. - ' The dwAlpha parameter will only be used when this - ' flag is specified. dwAlpha is an RGB value - ' (&HBBGGRR). - ' Note: Because of the extra calculations required, - ' alpha blended graphics take longer to draw -Public Const USE_INDEX As Long = &H10& ' Only valid when used with a custom SetPixel function. - ' This flag cannot be used in combination with - ' ALPHA_BLEND or SHADOW_COLOR - ' When this flag is used, the index to a color in the - ' palette will be passed to your custom SetPixel - ' function instead of the actual color. - -' Palette is an array of 256 Longs. Pass the first element of the array to these functions, -' rather than the actual array -' For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive -' or a file not in an archive -Declare Function LoadPalette Lib "Grpapi.dll" (ByVal lpFileName As String, dwPalette As Long) As Boolean -Declare Function LoadGrp Lib "Grpapi.dll" (ByVal lpFileName As String) As Long -Declare Function DestroyGrp Lib "Grpapi.dll" (ByVal hGrp As Long) As Boolean -Declare Function DrawGrp Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nFrame As Integer, dwPalette As Long, ByVal dwFlags As Long, ByVal dwAlpha As Long) As Boolean -Declare Function GetGrpInfo Lib "Grpapi.dll" (ByVal hGrp As Long, GrpInfo As GRPHEADER) As Boolean -Declare Function GetGrpFrameInfo Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal nFrame As Integer, ByRef nLeft As Long, ByRef nTop As Long, ByRef nWidth As Long, ByRef nHeight As Long) As Boolean - -Declare Function GetDC Lib "User32.dll" (ByVal hWnd As Long) As Long -Declare Function ReleaseDC Lib "User32.dll" (ByVal hWnd As Long, ByVal hDC As Long) As Long - -' An array of the raw image data to encode should be passed to lpImageData. To do this, -' pass the first byte of the array to the function. The size of the buffer containing -' the data should be nFrames * wMaxWidth * wMaxHeight * 2 -' and the values should be arranged row by row of the frame, with the top row first. -' After all the rows of a frame have been put into the buffer, the rows of the next frame -' go after it. For transparent pixels, they should be set to -1. All other pixels should -' have the high order byte set to zero, meaning that they should not be negative and the -' values should not exceed 255 (&HFF). The values used for the colors are indexes into the -' color palette. -' Pass True to bNoCompress if you need an uncompressed GRP. -' Pass a variable to nGrpSize to receive the size in bytes of the resulting encoded GRP. -' The return value of this function is actually a pointer to the GRP data. This is what your -' program should save to a file. The size of this buffer is the value received by nGrpSize. -' When your program is done with the returned buffer, it should call DestroyGrp on the -' buffer that was returned by this function to free up the memory from it. -' The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. -Declare Function CreateGrp Lib "Grpapi.dll" (ByRef lpImageData As Integer, ByVal nFrames As Integer, ByVal wMaxWidth As Integer, ByVal wMaxHeight As Integer, ByVal bNoCompress As Boolean, ByRef nGrpSize As Long) As Long - -' Use this function to make a copy the memory at the location returned by CreateGrp. -' Pass the address ByVal to Source. Pass either a byte array or a string to Destination. -' The size of the array or string must be at least the size of the GRP data before -' attempting to copy it to the array or string. -' To pass a byte array, pass the first byte of the array ByRef. To pass a string, -' pass the string ByVal. -Declare Sub CopyMemory Lib "Kernel32.dll" _ - Alias "RtlMoveMemory" ( _ - ByRef Destination As Any, _ - ByRef Source As Any, _ - ByVal Length As Long) - -' Call these to have DrawGrp use custom functions for reading and drawing pixels -' so that you can have it read from and write to a buffer, for example. -' Requires Visual Basic 5 or higher -' -' The functions must be in this form: -' -' Function GetPixelProc (ByRef value As any_type, X As Long, Y As Long) As Long -' Sub SetPixelProc (ByRef value As any_type, X As Long, Y As Long, clrColor As Long) -' -' or -' -' Function GetPixelProc (ByVal value As any_type, X As Long, Y As Long) As Long -' Sub SetPixelProc (ByVal value As any_type, X As Long, Y As Long, clrColor As Long) -' -' Replace "any_type" with whatever type you want. This parameter gets the data from -' DrawGrp's hdcDest parameter. You can either pass a number to DrawGrp and use the -' "ByVal" versions of the above functions, or you can use AddressOf to get a reference -' to a variable and use it for the "ByRef" versions. -' GetPixelProc should return an RGB color value. -Declare Sub SetFunctionGetPixel Lib "Grpapi.dll" (lpGetPixelProc As Long) -Declare Sub SetFunctionSetPixel Lib "Grpapi.dll" (lpSetPixelProc As Long) - -' Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). -Declare Function SetMpqDll Lib "Grpapi.dll" (ByVal lpDllFileName As String) As Boolean - -' These no longer need to be called -Declare Function LoadGrpApi Lib "Grpapi.dll" () As Boolean -Declare Sub FreeGrpApi Lib "Grpapi.dll" () +Attribute VB_Name = "GrpApi" +Option Explicit + +' ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2006 + +' Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) + +Type GRPHEADER + nFrames As Integer + wMaxWidth As Integer + wMaxHeight As Integer +End Type + +Public Const HORIZONTAL_FLIP As Long = &H1& ' Flips the graphic horizontally +Public Const VERTICAL_FLIP As Long = &H2& ' Flips the graphic vertically +Public Const SHADOW_COLOR As Long = &H4& ' Causes the graphic to be drawn in one color + ' Second byte of flags is the red component of + ' the shadow's color, third byte is green, + ' fourth byte is blue; like this: + ' 'SHADOW_COLOR Or &HBBGGRR00' +Public Const ALPHA_BLEND As Long = &H8& ' Blends the graphic with what it is being drawn over. + ' The dwAlpha parameter will only be used when this + ' flag is specified. dwAlpha is an RGB value + ' (&HBBGGRR). + ' Note: Because of the extra calculations required, + ' alpha blended graphics take longer to draw +Public Const USE_INDEX As Long = &H10& ' Only valid when used with a custom SetPixel function. + ' This flag cannot be used in combination with + ' ALPHA_BLEND or SHADOW_COLOR + ' When this flag is used, the index to a color in the + ' palette will be passed to your custom SetPixel + ' function instead of the actual color. + +' Palette is an array of 256 Longs. Pass the first element of the array to these functions, +' rather than the actual array +' For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive +' or a file not in an archive +Declare Function LoadPalette Lib "Grpapi.dll" (ByVal lpFileName As String, dwPalette As Long) As Boolean +Declare Function LoadGrp Lib "Grpapi.dll" (ByVal lpFileName As String) As Long +Declare Function DestroyGrp Lib "Grpapi.dll" (ByVal hGrp As Long) As Boolean +Declare Function DrawGrp Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nFrame As Integer, dwPalette As Long, ByVal dwFlags As Long, ByVal dwAlpha As Long) As Boolean +Declare Function GetGrpInfo Lib "Grpapi.dll" (ByVal hGrp As Long, GrpInfo As GRPHEADER) As Boolean +Declare Function GetGrpFrameInfo Lib "Grpapi.dll" (ByVal hGrp As Long, ByVal nFrame As Integer, ByRef nLeft As Long, ByRef nTop As Long, ByRef nWidth As Long, ByRef nHeight As Long) As Boolean + +Declare Function GetDC Lib "User32.dll" (ByVal hWnd As Long) As Long +Declare Function ReleaseDC Lib "User32.dll" (ByVal hWnd As Long, ByVal hDC As Long) As Long + +' An array of the raw image data to encode should be passed to lpImageData. To do this, +' pass the first byte of the array to the function. The size of the buffer containing +' the data should be nFrames * wMaxWidth * wMaxHeight * 2 +' and the values should be arranged row by row of the frame, with the top row first. +' After all the rows of a frame have been put into the buffer, the rows of the next frame +' go after it. For transparent pixels, they should be set to -1. All other pixels should +' have the high order byte set to zero, meaning that they should not be negative and the +' values should not exceed 255 (&HFF). The values used for the colors are indexes into the +' color palette. +' Pass True to bNoCompress if you need an uncompressed GRP. +' Pass a variable to nGrpSize to receive the size in bytes of the resulting encoded GRP. +' The return value of this function is actually a pointer to the GRP data. This is what your +' program should save to a file. The size of this buffer is the value received by nGrpSize. +' When your program is done with the returned buffer, it should call DestroyGrp on the +' buffer that was returned by this function to free up the memory from it. +' The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. +Declare Function CreateGrp Lib "Grpapi.dll" (ByRef lpImageData As Integer, ByVal nFrames As Integer, ByVal wMaxWidth As Integer, ByVal wMaxHeight As Integer, ByVal bNoCompress As Boolean, ByRef nGrpSize As Long) As Long + +' Use this function to make a copy the memory at the location returned by CreateGrp. +' Pass the address ByVal to Source. Pass either a byte array or a string to Destination. +' The size of the array or string must be at least the size of the GRP data before +' attempting to copy it to the array or string. +' To pass a byte array, pass the first byte of the array ByRef. To pass a string, +' pass the string ByVal. +Declare Sub CopyMemory Lib "Kernel32.dll" _ + Alias "RtlMoveMemory" ( _ + ByRef Destination As Any, _ + ByRef Source As Any, _ + ByVal Length As Long) + +' Call these to have DrawGrp use custom functions for reading and drawing pixels +' so that you can have it read from and write to a buffer, for example. +' Requires Visual Basic 5 or higher +' +' The functions must be in this form: +' +' Function GetPixelProc (ByRef value As any_type, X As Long, Y As Long) As Long +' Sub SetPixelProc (ByRef value As any_type, X As Long, Y As Long, clrColor As Long) +' +' or +' +' Function GetPixelProc (ByVal value As any_type, X As Long, Y As Long) As Long +' Sub SetPixelProc (ByVal value As any_type, X As Long, Y As Long, clrColor As Long) +' +' Replace "any_type" with whatever type you want. This parameter gets the data from +' DrawGrp's hdcDest parameter. You can either pass a number to DrawGrp and use the +' "ByVal" versions of the above functions, or you can use AddressOf to get a reference +' to a variable and use it for the "ByRef" versions. +' GetPixelProc should return an RGB color value. +Declare Sub SetFunctionGetPixel Lib "Grpapi.dll" (lpGetPixelProc As Long) +Declare Sub SetFunctionSetPixel Lib "Grpapi.dll" (lpSetPixelProc As Long) + +' Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). +Declare Function SetMpqDll Lib "Grpapi.dll" (ByVal lpDllFileName As String) As Boolean + +' These no longer need to be called +Declare Function LoadGrpApi Lib "Grpapi.dll" () As Boolean +Declare Sub FreeGrpApi Lib "Grpapi.dll" () diff --git a/grpapi/grp_static.h b/grpapi/grp_static.h index 5e7cc77..79cbf64 100644 --- a/grpapi/grp_static.h +++ b/grpapi/grp_static.h @@ -1,17 +1,17 @@ -/* - - ShadowFlare GRP Static Library. (c) ShadowFlare Software 2002 - -*/ - -#ifndef GRPLIB_INCLUDED -#define GRPLIB_INCLUDED - -#ifndef GRPAPI_STATIC -#define GRPAPI_STATIC -#endif - -#include "grpapi.h" - -#endif - +/* + + ShadowFlare GRP Static Library. (c) ShadowFlare Software 2002 + +*/ + +#ifndef GRPLIB_INCLUDED +#define GRPLIB_INCLUDED + +#ifndef GRPAPI_STATIC +#define GRPAPI_STATIC +#endif + +#include "grpapi.h" + +#endif + diff --git a/grpapi/grpapi.cpp b/grpapi/grpapi.cpp index b002e12..ad088c3 100644 --- a/grpapi/grpapi.cpp +++ b/grpapi/grpapi.cpp @@ -1,762 +1,762 @@ -#include "grpapi.h" -#include "../LoadStorm/storm.h" -#include - -#ifdef GRPAPI_STATIC -#define DllMain GrpMain - -#include "grp_static.h" - -struct GRPLIBMODULE { - GRPLIBMODULE(); - ~GRPLIBMODULE(); -} GrpLib; - -BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD ul_reason_for_call, LPVOID lpReserved); - -GRPLIBMODULE::GRPLIBMODULE() -{ - GrpMain(0,DLL_PROCESS_ATTACH,0); -} - -GRPLIBMODULE::~GRPLIBMODULE() -{ - GrpMain(0,DLL_PROCESS_DETACH,0); -} - -#endif - -typedef struct { - BYTE Left; - BYTE Top; - BYTE Width; - BYTE Height; - DWORD Offset; -} FRAMEHEADER; - -typedef struct { - WORD *lpRowOffsets; - WORD *lpRowSizes; - LPBYTE *lpRowData; - DWORD Size; -} FRAMEDATA; - -GETPIXELPROC MyGetPixel = GetPixel; -SETPIXELPROC MySetPixel = (SETPIXELPROC)SetPixelV; - -void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); -void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData, BOOL bNoCompress); -BOOL VerifyRow(signed short *lpRawRow, int nWidth, LPBYTE lpEncRow, int nSize, BOOL bNoCompress); - -extern HINSTANCE hStorm; - -BOOL APIENTRY DllMain( HINSTANCE hInstDLL, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - break; - } - - return TRUE; -} - -BOOL GRPAPI WINAPI LoadGrpApi() -{ - if (!hStorm) return FALSE; - else return TRUE; -} - -void GRPAPI WINAPI FreeGrpApi() -{ -} - -/* -HANDLE hProcessHeap = NULL; - -void * SFAlloc(size_t nSize) -{ - if (!hProcessHeap) hProcessHeap = GetProcessHeap(); - if (hProcessHeap) return HeapAlloc(hProcessHeap, 0, nSize); - else return NULL; -} - -void SFFree(void *lpMem) -{ - if (!hProcessHeap) hProcessHeap = GetProcessHeap(); - if (hProcessHeap) HeapFree(hProcessHeap, 0, lpMem); -} -*/ - -BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName) -{ - if (LoadStorm((char *)lpDllFileName)) return TRUE; - else return FALSE; -} - -BOOL GRPAPI WINAPI LoadPalette(LPCSTR lpFileName, DWORD *dwPaletteBuffer) -{ - if (!lpFileName || !dwPaletteBuffer) return FALSE; - HANDLE hFile; - if (SFileOpenFileEx && SFileGetFileSize - && SFileSetFilePointer && SFileReadFile - && SFileCloseFile) { - if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return FALSE; - DWORD fsz = SFileGetFileSize(hFile,0); - SFileSetFilePointer(hFile,0,0,FILE_BEGIN); - if (fsz>=1024) { - memset(dwPaletteBuffer,0,1024); - SFileReadFile(hFile,dwPaletteBuffer,1024,0,0); - } - else if (fsz==768) { - char *buffer = (char *)_alloca(768); - memset(buffer,0,768); - SFileReadFile(hFile,buffer,768,0,0); - for (DWORD i=0;i<256;i++) { - memcpy(&dwPaletteBuffer[i],buffer+i*3,3); - *(((char *)&dwPaletteBuffer[i])+3) = 0; - } - } - else { - memset(dwPaletteBuffer,0,1024); - SFileReadFile(hFile,dwPaletteBuffer,fsz,0,0); - } - SFileCloseFile(hFile); - } - else { - hFile = CreateFile(lpFileName,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0); - if (hFile==INVALID_HANDLE_VALUE) return FALSE; - DWORD fsz = GetFileSize(hFile,0),tsz; - SetFilePointer(hFile,0,0,FILE_BEGIN); - if (fsz>=1024) { - memset(dwPaletteBuffer,0,1024); - ReadFile(hFile,dwPaletteBuffer,1024,&tsz,0); - } - else if (fsz==768) { - char *buffer = (char *)_alloca(768); - memset(buffer,0,768); - ReadFile(hFile,buffer,768,&tsz,0); - for (DWORD i=0;i<256;i++) { - memcpy(&dwPaletteBuffer[i],buffer+i*3,3); - *(((char *)&dwPaletteBuffer[i])+3) = 0; - } - } - else { - memset(dwPaletteBuffer,0,1024); - ReadFile(hFile,dwPaletteBuffer,fsz,&tsz,0); - } - CloseHandle(hFile); - } - return TRUE; -} - -HANDLE GRPAPI WINAPI LoadGrp(LPCSTR lpFileName) -{ - if (!lpFileName) return (HANDLE)-1; - HANDLE hFile; - char *GrpFile; - if (SFileOpenFileEx && SFileGetFileSize - && SFileSetFilePointer && SFileReadFile - && SFileCloseFile) { - if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return (HANDLE)-1; - DWORD fsz = SFileGetFileSize(hFile,0); - if (fsz<6) { - SFileCloseFile(hFile); - return (HANDLE)-1; - } - GrpFile = (char *)malloc(fsz); - if (GrpFile) { - SFileSetFilePointer(hFile,0,0,FILE_BEGIN); - SFileReadFile(hFile,GrpFile,fsz,0,0); - } - else GrpFile=(char *)-1; - SFileCloseFile(hFile); - } - else { - hFile = CreateFile(lpFileName,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0); - if (hFile==INVALID_HANDLE_VALUE) return (HANDLE)-1; - DWORD fsz = GetFileSize(hFile,0),tsz; - if (fsz<6) { - CloseHandle(hFile); - return (HANDLE)-1; - } - GrpFile = (char *)malloc(fsz); - if (GrpFile) { - SetFilePointer(hFile,0,0,FILE_BEGIN); - ReadFile(hFile,GrpFile,fsz,&tsz,0); - } - else GrpFile=(char *)-1; - CloseHandle(hFile); - } - return (HANDLE)GrpFile; -} - -BOOL GRPAPI WINAPI DestroyGrp(HANDLE hGrp) -{ - if (!hGrp || hGrp==INVALID_HANDLE_VALUE) return FALSE; - free(hGrp); - return TRUE; -} - -BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha) -{ - if (!hGrp || hGrp==INVALID_HANDLE_VALUE || hdcDest==0 || (!dwPalette && !(dwFlags&USE_INDEX))) return FALSE; - GRPHEADER *GrpFile = (GRPHEADER *)hGrp; - nFrame %= GrpFile->nFrames; - FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)GrpFile)+6))[nFrame]; - FRAMEHEADER *GrpFrames = &((FRAMEHEADER *)(((char *)GrpFile)+6))[0]; - int FrameSize = 0xFFFFFF; - DWORD Right,Bottom; - if (dwFlags&HORIZONTAL_FLIP) Right = nXDest+GrpFile->wMaxWidth-1-GrpFrame->Left; - if (dwFlags&VERTICAL_FLIP) Bottom = nYDest+GrpFile->wMaxHeight-1-GrpFrame->Top; - nXDest += GrpFrame->Left; - nYDest += GrpFrame->Top; - WORD *GrpOffsets = ((WORD *)(((char *)GrpFile)+GrpFrame->Offset)); - BYTE *GrpRaw = (BYTE *)GrpOffsets; - BYTE *RowData; - WORD x,ofs; - DWORD y, nMaxOffset = 0; - WORD i; - int j, nFirstNonBlankFrame = 0; - for (i = 0; i < GrpFile->nFrames; i++) { - j = GrpFrames[i].Offset - GrpFrame->Offset; - if (j > 0 && j < FrameSize) - FrameSize = j; - if (GrpFrames[i].Offset > nMaxOffset) - nMaxOffset = GrpFrames[i].Offset; - } - if (FrameSize == 0xFFFFFF || FrameSize == GrpFrame->Width * GrpFrame->Height) { - FrameSize = 0xFFFFFF; - for (i = 0; i < GrpFile->nFrames; i++) { - if (GrpFrames[i].Width != 0 && GrpFrames[i].Height != 0 && GrpFrames[i].Offset != GrpFrame->Offset && GrpFrames[i].Offset != nMaxOffset) { - nFirstNonBlankFrame = i; - break; - } - } - if (i == GrpFile->nFrames) - nFirstNonBlankFrame = nFrame; - - for (i = 0; i < GrpFile->nFrames; i++) { - j = GrpFrames[i].Offset - GrpFrames[nFirstNonBlankFrame].Offset; - if (j > 0 && j < FrameSize) - FrameSize = j; - } - if (FrameSize == GrpFrames[nFirstNonBlankFrame].Width * GrpFrames[nFirstNonBlankFrame].Height) - FrameSize = GrpFrame->Width * GrpFrame->Height; - } - if (!(dwFlags&HORIZONTAL_FLIP) && !(dwFlags&VERTICAL_FLIP)) { - if (FrameSize != GrpFrame->Width * GrpFrame->Height) { - for (y=0;yHeight;y++) { - RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); - x=0; ofs=0; - while (xWidth) { - if (!(RowData[ofs] & 0x80)) { - if (!(RowData[ofs] & 0x40)) { - for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=RowData[ofs]+1; - } - else { - for (i=0;iWidth;i++) { - SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=2; - } - } - else { - x+=RowData[ofs]-128; - ofs++; - } - } - } - } - else { - for (y=0;yHeight;y++) { - for (x=0;xWidth;x++) { - SetPix(hdcDest,nXDest+x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); - } - } - } - } - else if (dwFlags&HORIZONTAL_FLIP && !(dwFlags&VERTICAL_FLIP)) { - if (FrameSize != GrpFrame->Width * GrpFrame->Height) { - for (y=0;yHeight;y++) { - RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); - x=0; ofs=0; - while (xWidth) { - if (!(RowData[ofs] & 0x80)) { - if (!(RowData[ofs] & 0x40)) { - for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=RowData[ofs]+1; - } - else { - for (i=0;iWidth;i++) { - SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=2; - } - } - else { - x+=RowData[ofs]-128; - ofs++; - } - } - } - } - else { - for (y=0;yHeight;y++) { - for (x=0;xWidth;x++) { - SetPix(hdcDest,Right-x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); - } - } - } - } - else if (!(dwFlags&HORIZONTAL_FLIP) && dwFlags&VERTICAL_FLIP) { - if (FrameSize != GrpFrame->Width * GrpFrame->Height) { - for (y=0;yHeight;y++) { - RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); - x=0; ofs=0; - while (xWidth) { - if (!(RowData[ofs] & 0x80)) { - if (!(RowData[ofs] & 0x40)) { - for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=RowData[ofs]+1; - } - else { - for (i=0;iWidth;i++) { - SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=2; - } - } - else { - x+=RowData[ofs]-128; - ofs++; - } - } - } - } - else { - for (y=0;yHeight;y++) { - for (x=0;xWidth;x++) { - SetPix(hdcDest,nXDest+x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); - } - } - } - } - else { - if (FrameSize != GrpFrame->Width * GrpFrame->Height) { - for (y=0;yHeight;y++) { - RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); - x=0; ofs=0; - while (xWidth) { - if (!(RowData[ofs] & 0x80)) { - if (!(RowData[ofs] & 0x40)) { - for (i=1;i<=RowData[ofs] && xWidth;i++) { - SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=RowData[ofs]+1; - } - else { - for (i=0;iWidth;i++) { - SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); - x++; - } - ofs+=2; - } - } - else { - x+=RowData[ofs]-128; - ofs++; - } - } - } - } - else { - for (y=0;yHeight;y++) { - for (x=0;xWidth;x++) { - SetPix(hdcDest,Right-x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); - } - } - } - } - return TRUE; -} - -BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo) -{ - if (!hGrp || hGrp==INVALID_HANDLE_VALUE || !GrpInfo) return FALSE; - memcpy(GrpInfo,hGrp,6); - return TRUE; -} - -BOOL GRPAPI WINAPI GetGrpFrameInfo(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight) -{ - if (!hGrp || hGrp==INVALID_HANDLE_VALUE) return FALSE; - FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)hGrp)+6))[nFrame]; - - if (nLeft) *nLeft = GrpFrame->Left; - if (nTop) *nTop = GrpFrame->Top; - if (nWidth) *nWidth = GrpFrame->Width; - if (nHeight) *nHeight = GrpFrame->Height; - - return TRUE; -} - -void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc) -{ - if (!lpGetPixelProc) - MyGetPixel = GetPixel; - else - MyGetPixel = lpGetPixelProc; -} - -void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc) -{ - if (!lpSetPixelProc) - MySetPixel = (SETPIXELPROC)SetPixelV; - else - MySetPixel = lpSetPixelProc; -} - -void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha) -{ - if (!(dwFlags&USE_INDEX)) { - if (dwFlags&SHADOW_COLOR) { - clrColor = (dwFlags >> 8) & 0x00FFFFFF; - } - else { - clrColor = dwPalette[clrColor]; - } - if (dwFlags&ALPHA_BLEND) { - DWORD dwColor = MyGetPixel(hDC,X,Y); - - // Old alpha - /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256); - ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256); - ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256); - ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256; - ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256; - ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256; - ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0]; - ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1]; - ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/ - - /* blendedcolor = - ( ( forecolor * ( 1 - alpha ) ) >> 8 ) - + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */ - ((BYTE *)&clrColor)[0] = - ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 ); - ((BYTE *)&clrColor)[1] = - ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 ); - ((BYTE *)&clrColor)[2] = - ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 ) - + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 ); - } - } - MySetPixel(hDC,X,Y,clrColor); -} - -HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize) -{ - GRPHEADER GrpHeader; - FRAMEHEADER *lpFrameHeaders; - FRAMEDATA *lpFrameData; - LPBYTE lpGrpData; - int i, j, x, y, x1, x2, y1, y2; - DWORD nLastOffset; - - if (!lpImageData || !nGrpSize) return (HANDLE)-1; - - GrpHeader.nFrames = nFrames; - GrpHeader.wMaxWidth = wMaxWidth; - GrpHeader.wMaxHeight = wMaxHeight; - lpFrameHeaders = (FRAMEHEADER *)malloc(nFrames * sizeof(FRAMEHEADER)); - lpFrameData = (FRAMEDATA *)malloc(nFrames * sizeof(FRAMEDATA)); - nLastOffset = sizeof(GRPHEADER) + nFrames * sizeof(FRAMEHEADER); - - for (i = 0; i < nFrames; i++) { - lpFrameHeaders[i].Offset = nLastOffset; - - // Scan frame to find dimensions of used part - x1 = y1 = 0x10000; - x2 = y2 = -1; - for (y = 0; y < wMaxHeight; y++) { - for (x = 0; x < wMaxWidth; x++) { - if (lpImageData[i * wMaxWidth * wMaxHeight + y * wMaxWidth + x] >= 0) { - if (x < x1) x1 = x; - if (x > x2) x2 = x; - if (y < y1) y1 = y; - if (y > y2) y2 = y; - } - } - } - x2 = x2 - x1 + 1; - y2 = y2 - y1 + 1; - if ((WORD)x1 > 255) x1 = 255; - if ((WORD)y1 > 255) y1 = 255; - if ((WORD)x2 > 255) x2 = 255; - if ((WORD)y2 > 255) y2 = 255; - lpFrameHeaders[i].Left = x1; - lpFrameHeaders[i].Top = y1; - lpFrameHeaders[i].Width = x2; - lpFrameHeaders[i].Height = y2; - - // Search for duplicate frames - for (j = 0; j < i; j++) { - if (lpFrameData[j].lpRowOffsets && lpFrameHeaders[i].Width == lpFrameHeaders[j].Width && lpFrameHeaders[i].Height == lpFrameHeaders[j].Height) { - y1 = i * wMaxWidth * wMaxHeight + lpFrameHeaders[i].Top * wMaxWidth + lpFrameHeaders[i].Left; - y2 = j * wMaxWidth * wMaxHeight + lpFrameHeaders[j].Top * wMaxWidth + lpFrameHeaders[j].Left; - - for (y = 0; y < lpFrameHeaders[i].Height; y++) { - if (memcmp(&lpImageData[y1], &lpImageData[y2], lpFrameHeaders[i].Width * sizeof(short)) != 0) - break; - - y1 += wMaxWidth; - y2 += wMaxWidth; - } - - if (y == lpFrameHeaders[i].Height) { - break; - } - } - } - - if (j < i) { - // Duplicate frame found, set offset and flag as duplicate - lpFrameHeaders[i].Offset = lpFrameHeaders[j].Offset; - lpFrameData[i].lpRowOffsets = 0; - lpFrameData[i].lpRowSizes = 0; - lpFrameData[i].lpRowData = 0; - lpFrameData[i].Size = 0; - continue; - } - - EncodeFrameData(lpImageData, i, &GrpHeader, &lpFrameHeaders[i], &lpFrameData[i], bNoCompress); - nLastOffset = lpFrameHeaders[i].Offset + lpFrameData[i].Size; - } - - lpGrpData = (LPBYTE)malloc(nLastOffset); - - // Write completed GRP to buffer - memcpy(lpGrpData, &GrpHeader, sizeof(GRPHEADER)); - memcpy(lpGrpData + sizeof(GRPHEADER), lpFrameHeaders, nFrames * sizeof(FRAMEHEADER)); - - for (i = 0; i < nFrames; i++) { - if (lpFrameData[i].lpRowOffsets) { - if (!bNoCompress) - memcpy(lpGrpData + lpFrameHeaders[i].Offset, lpFrameData[i].lpRowOffsets, lpFrameHeaders[i].Height * sizeof(WORD)); - - for (y = 0; y < lpFrameHeaders[i].Height; y++) { - if (lpFrameData[i].lpRowData[y]) { - memcpy(lpGrpData + lpFrameHeaders[i].Offset + lpFrameData[i].lpRowOffsets[y], lpFrameData[i].lpRowData[y], lpFrameData[i].lpRowSizes[y]); - free(lpFrameData[i].lpRowData[y]); - } - } - - free(lpFrameData[i].lpRowOffsets); - free(lpFrameData[i].lpRowSizes); - free(lpFrameData[i].lpRowData); - } - } - - free(lpFrameHeaders); - free(lpFrameData); - - *nGrpSize = nLastOffset; - return (HANDLE)lpGrpData; -} - -void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData, BOOL bNoCompress) -{ - int x, y, i, j, nBufPos, nRepeat; - LPBYTE lpRowBuf; - WORD nLastOffset = 0; - - lpFrameData->lpRowOffsets = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD)); - lpFrameData->lpRowSizes = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD)); - lpFrameData->lpRowData = (LPBYTE *)malloc(lpFrameHeader->Height * sizeof(LPBYTE)); - lpRowBuf = (LPBYTE)malloc(lpFrameHeader->Width * 2); - - if (!bNoCompress) - nLastOffset = lpFrameHeader->Height * sizeof(WORD); - - for (y = 0; y < lpFrameHeader->Height; y++) { - i = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + y) * lpGrpHeader->wMaxWidth; - - if (!bNoCompress) { - // Search for duplicate rows - for (x = 0; x < y; x++) { - j = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + x) * lpGrpHeader->wMaxWidth; - if (memcmp(&lpImageData[i+lpFrameHeader->Left], - &lpImageData[j+lpFrameHeader->Left], - lpGrpHeader->wMaxWidth * sizeof(short)) == 0) - break; - } - - if (x < y) { - lpFrameData->lpRowOffsets[y] = lpFrameData->lpRowOffsets[x]; - lpFrameData->lpRowSizes[y] = 0; - lpFrameData->lpRowData[y] = 0; - -#ifdef _DEBUG - if (!VerifyRow(&lpImageData[i+lpFrameHeader->Left], lpFrameHeader->Width, lpFrameData->lpRowData[x], lpFrameData->lpRowSizes[x], bNoCompress)) { - nBufPos = nBufPos; - } -#endif - - continue; - } - } - - nBufPos = 0; - if (lpFrameHeader->Width > 0) { - for (x = lpFrameHeader->Left; x < lpFrameHeader->Left + lpFrameHeader->Width; x++) { - if (!bNoCompress) { - if (x < lpFrameHeader->Left + lpFrameHeader->Width - 1) { - if (lpImageData[i+x] < 0) { - lpRowBuf[nBufPos] = 0x80; - for (; lpImageData[i+x] < 0 && x < lpFrameHeader->Left + lpFrameHeader->Width && lpRowBuf[nBufPos] < 0xFF; x++) { - lpRowBuf[nBufPos]++; - } - x--; - if (nLastOffset + nBufPos + 1 <= 0xFFFF) - nBufPos++; - continue; - } - - // Count repeating pixels, nRepeat = number of pixels - 1, ignore if there are less than 4 duplicates - for (nRepeat = 0; lpImageData[i+x+nRepeat] == lpImageData[i+x+nRepeat+1] && x+nRepeat < lpFrameHeader->Left + lpFrameHeader->Width - 1 && nRepeat < 0x3E; nRepeat++) {} - - if (nRepeat > 2) { - lpRowBuf[nBufPos] = 0x41 + nRepeat; - lpRowBuf[nBufPos+1] = (BYTE)(lpImageData[i+x]); - x += nRepeat; - if (nLastOffset + nBufPos + 2 <= 0xFFFF) - nBufPos += 2; - } - else { - lpRowBuf[nBufPos] = 0; - for (; lpImageData[i+x] >= 0 && x < lpFrameHeader->Left + lpFrameHeader->Width && lpRowBuf[nBufPos] < 0x3F; x++) { - // Count repeating pixels, ignore if there are less than 4 duplicates - for (nRepeat = 0; lpImageData[i+x+nRepeat] == lpImageData[i+x+nRepeat+1] && x+nRepeat < lpFrameHeader->Left + lpFrameHeader->Width - 1 && nRepeat < 3; nRepeat++) {} - if (nRepeat > 2) break; - - lpRowBuf[nBufPos]++; - lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)(lpImageData[i+x]); - } - if (lpImageData[i+x] >= 0 && x == lpFrameHeader->Left + lpFrameHeader->Width - 1 && lpRowBuf[nBufPos] < 0x3F) { - lpRowBuf[nBufPos]++; - lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)(lpImageData[i+x]); - } - x--; - if (nLastOffset + nBufPos + 1 + lpRowBuf[nBufPos] <= 0xFFFF) - nBufPos += 1 + lpRowBuf[nBufPos]; - } - } - else { - if (lpImageData[i+x] < 0) { - lpRowBuf[nBufPos] = 0x81; - if (nLastOffset + nBufPos + 1 <= 0xFFFF) - nBufPos++; - } - else { - lpRowBuf[nBufPos] = 1; - lpRowBuf[nBufPos+1] = (BYTE)(lpImageData[i+x]); - if (nLastOffset + nBufPos + 2 <= 0xFFFF) - nBufPos += 2; - } - } - } - else { - lpRowBuf[nBufPos] = (BYTE)(lpImageData[i+x]); - if (nLastOffset + nBufPos + 1 <= 0xFFFF) - nBufPos++; - } - } - } - -#ifdef _DEBUG - if (!VerifyRow(&lpImageData[i+lpFrameHeader->Left], lpFrameHeader->Width, lpRowBuf, nBufPos, bNoCompress)) { - nBufPos = nBufPos; - } -#endif - - lpFrameData->lpRowOffsets[y] = nLastOffset; - nLastOffset = lpFrameData->lpRowOffsets[y] + nBufPos; - - lpFrameData->lpRowSizes[y] = nBufPos; - lpFrameData->lpRowData[y] = (LPBYTE)malloc(nBufPos); - memcpy(lpFrameData->lpRowData[y], lpRowBuf, nBufPos); - } - - lpFrameData->Size = nLastOffset; - - free(lpRowBuf); -} - -#ifdef _DEBUG -BOOL VerifyRow(signed short *lpRawRow, int nWidth, LPBYTE lpEncRow, int nSize, BOOL bNoCompress) -{ - int i,x=0,ofs=0; - while (x < nWidth && ofs < nSize) { - if (!bNoCompress) { - if (!(lpEncRow[ofs] & 0x80)) { - if (!(lpEncRow[ofs] & 0x40)) { - for (i=1;i<=lpEncRow[ofs] && x= 0) return FALSE; - } - x+=lpEncRow[ofs]-128; - ofs++; - } - } - else { - if (lpEncRow[ofs] != (BYTE)lpRawRow[x]) return FALSE; - x++; - ofs++; - } - } - - if (x != nWidth || ofs != nSize) return FALSE; - - return TRUE; -} -#endif +#include "grpapi.h" +#include "../LoadStorm/storm.h" +#include + +#ifdef GRPAPI_STATIC +#define DllMain GrpMain + +#include "grp_static.h" + +struct GRPLIBMODULE { + GRPLIBMODULE(); + ~GRPLIBMODULE(); +} GrpLib; + +BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD ul_reason_for_call, LPVOID lpReserved); + +GRPLIBMODULE::GRPLIBMODULE() +{ + GrpMain(0,DLL_PROCESS_ATTACH,0); +} + +GRPLIBMODULE::~GRPLIBMODULE() +{ + GrpMain(0,DLL_PROCESS_DETACH,0); +} + +#endif + +typedef struct { + BYTE Left; + BYTE Top; + BYTE Width; + BYTE Height; + DWORD Offset; +} FRAMEHEADER; + +typedef struct { + WORD *lpRowOffsets; + WORD *lpRowSizes; + LPBYTE *lpRowData; + DWORD Size; +} FRAMEDATA; + +GETPIXELPROC MyGetPixel = GetPixel; +SETPIXELPROC MySetPixel = (SETPIXELPROC)SetPixelV; + +void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); +void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData, BOOL bNoCompress); +BOOL VerifyRow(signed short *lpRawRow, int nWidth, LPBYTE lpEncRow, int nSize, BOOL bNoCompress); + +extern HINSTANCE hStorm; + +BOOL APIENTRY DllMain( HINSTANCE hInstDLL, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + break; + } + + return TRUE; +} + +BOOL GRPAPI WINAPI LoadGrpApi() +{ + if (!hStorm) return FALSE; + else return TRUE; +} + +void GRPAPI WINAPI FreeGrpApi() +{ +} + +/* +HANDLE hProcessHeap = NULL; + +void * SFAlloc(size_t nSize) +{ + if (!hProcessHeap) hProcessHeap = GetProcessHeap(); + if (hProcessHeap) return HeapAlloc(hProcessHeap, 0, nSize); + else return NULL; +} + +void SFFree(void *lpMem) +{ + if (!hProcessHeap) hProcessHeap = GetProcessHeap(); + if (hProcessHeap) HeapFree(hProcessHeap, 0, lpMem); +} +*/ + +BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName) +{ + if (LoadStorm((char *)lpDllFileName)) return TRUE; + else return FALSE; +} + +BOOL GRPAPI WINAPI LoadPalette(LPCSTR lpFileName, DWORD *dwPaletteBuffer) +{ + if (!lpFileName || !dwPaletteBuffer) return FALSE; + HANDLE hFile; + if (SFileOpenFileEx && SFileGetFileSize + && SFileSetFilePointer && SFileReadFile + && SFileCloseFile) { + if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return FALSE; + DWORD fsz = SFileGetFileSize(hFile,0); + SFileSetFilePointer(hFile,0,0,FILE_BEGIN); + if (fsz>=1024) { + memset(dwPaletteBuffer,0,1024); + SFileReadFile(hFile,dwPaletteBuffer,1024,0,0); + } + else if (fsz==768) { + char *buffer = (char *)_alloca(768); + memset(buffer,0,768); + SFileReadFile(hFile,buffer,768,0,0); + for (DWORD i=0;i<256;i++) { + memcpy(&dwPaletteBuffer[i],buffer+i*3,3); + *(((char *)&dwPaletteBuffer[i])+3) = 0; + } + } + else { + memset(dwPaletteBuffer,0,1024); + SFileReadFile(hFile,dwPaletteBuffer,fsz,0,0); + } + SFileCloseFile(hFile); + } + else { + hFile = CreateFile(lpFileName,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0); + if (hFile==INVALID_HANDLE_VALUE) return FALSE; + DWORD fsz = GetFileSize(hFile,0),tsz; + SetFilePointer(hFile,0,0,FILE_BEGIN); + if (fsz>=1024) { + memset(dwPaletteBuffer,0,1024); + ReadFile(hFile,dwPaletteBuffer,1024,&tsz,0); + } + else if (fsz==768) { + char *buffer = (char *)_alloca(768); + memset(buffer,0,768); + ReadFile(hFile,buffer,768,&tsz,0); + for (DWORD i=0;i<256;i++) { + memcpy(&dwPaletteBuffer[i],buffer+i*3,3); + *(((char *)&dwPaletteBuffer[i])+3) = 0; + } + } + else { + memset(dwPaletteBuffer,0,1024); + ReadFile(hFile,dwPaletteBuffer,fsz,&tsz,0); + } + CloseHandle(hFile); + } + return TRUE; +} + +HANDLE GRPAPI WINAPI LoadGrp(LPCSTR lpFileName) +{ + if (!lpFileName) return (HANDLE)-1; + HANDLE hFile; + char *GrpFile; + if (SFileOpenFileEx && SFileGetFileSize + && SFileSetFilePointer && SFileReadFile + && SFileCloseFile) { + if (!SFileOpenFileEx(0,lpFileName,1,&hFile)) return (HANDLE)-1; + DWORD fsz = SFileGetFileSize(hFile,0); + if (fsz<6) { + SFileCloseFile(hFile); + return (HANDLE)-1; + } + GrpFile = (char *)malloc(fsz); + if (GrpFile) { + SFileSetFilePointer(hFile,0,0,FILE_BEGIN); + SFileReadFile(hFile,GrpFile,fsz,0,0); + } + else GrpFile=(char *)-1; + SFileCloseFile(hFile); + } + else { + hFile = CreateFile(lpFileName,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0); + if (hFile==INVALID_HANDLE_VALUE) return (HANDLE)-1; + DWORD fsz = GetFileSize(hFile,0),tsz; + if (fsz<6) { + CloseHandle(hFile); + return (HANDLE)-1; + } + GrpFile = (char *)malloc(fsz); + if (GrpFile) { + SetFilePointer(hFile,0,0,FILE_BEGIN); + ReadFile(hFile,GrpFile,fsz,&tsz,0); + } + else GrpFile=(char *)-1; + CloseHandle(hFile); + } + return (HANDLE)GrpFile; +} + +BOOL GRPAPI WINAPI DestroyGrp(HANDLE hGrp) +{ + if (!hGrp || hGrp==INVALID_HANDLE_VALUE) return FALSE; + free(hGrp); + return TRUE; +} + +BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha) +{ + if (!hGrp || hGrp==INVALID_HANDLE_VALUE || hdcDest==0 || (!dwPalette && !(dwFlags&USE_INDEX))) return FALSE; + GRPHEADER *GrpFile = (GRPHEADER *)hGrp; + nFrame %= GrpFile->nFrames; + FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)GrpFile)+6))[nFrame]; + FRAMEHEADER *GrpFrames = &((FRAMEHEADER *)(((char *)GrpFile)+6))[0]; + int FrameSize = 0xFFFFFF; + DWORD Right,Bottom; + if (dwFlags&HORIZONTAL_FLIP) Right = nXDest+GrpFile->wMaxWidth-1-GrpFrame->Left; + if (dwFlags&VERTICAL_FLIP) Bottom = nYDest+GrpFile->wMaxHeight-1-GrpFrame->Top; + nXDest += GrpFrame->Left; + nYDest += GrpFrame->Top; + WORD *GrpOffsets = ((WORD *)(((char *)GrpFile)+GrpFrame->Offset)); + BYTE *GrpRaw = (BYTE *)GrpOffsets; + BYTE *RowData; + WORD x,ofs; + DWORD y, nMaxOffset = 0; + WORD i; + int j, nFirstNonBlankFrame = 0; + for (i = 0; i < GrpFile->nFrames; i++) { + j = GrpFrames[i].Offset - GrpFrame->Offset; + if (j > 0 && j < FrameSize) + FrameSize = j; + if (GrpFrames[i].Offset > nMaxOffset) + nMaxOffset = GrpFrames[i].Offset; + } + if (FrameSize == 0xFFFFFF || FrameSize == GrpFrame->Width * GrpFrame->Height) { + FrameSize = 0xFFFFFF; + for (i = 0; i < GrpFile->nFrames; i++) { + if (GrpFrames[i].Width != 0 && GrpFrames[i].Height != 0 && GrpFrames[i].Offset != GrpFrame->Offset && GrpFrames[i].Offset != nMaxOffset) { + nFirstNonBlankFrame = i; + break; + } + } + if (i == GrpFile->nFrames) + nFirstNonBlankFrame = nFrame; + + for (i = 0; i < GrpFile->nFrames; i++) { + j = GrpFrames[i].Offset - GrpFrames[nFirstNonBlankFrame].Offset; + if (j > 0 && j < FrameSize) + FrameSize = j; + } + if (FrameSize == GrpFrames[nFirstNonBlankFrame].Width * GrpFrames[nFirstNonBlankFrame].Height) + FrameSize = GrpFrame->Width * GrpFrame->Height; + } + if (!(dwFlags&HORIZONTAL_FLIP) && !(dwFlags&VERTICAL_FLIP)) { + if (FrameSize != GrpFrame->Width * GrpFrame->Height) { + for (y=0;yHeight;y++) { + RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); + x=0; ofs=0; + while (xWidth) { + if (!(RowData[ofs] & 0x80)) { + if (!(RowData[ofs] & 0x40)) { + for (i=1;i<=RowData[ofs] && xWidth;i++) { + SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=RowData[ofs]+1; + } + else { + for (i=0;iWidth;i++) { + SetPix(hdcDest,nXDest+x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=2; + } + } + else { + x+=RowData[ofs]-128; + ofs++; + } + } + } + } + else { + for (y=0;yHeight;y++) { + for (x=0;xWidth;x++) { + SetPix(hdcDest,nXDest+x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); + } + } + } + } + else if (dwFlags&HORIZONTAL_FLIP && !(dwFlags&VERTICAL_FLIP)) { + if (FrameSize != GrpFrame->Width * GrpFrame->Height) { + for (y=0;yHeight;y++) { + RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); + x=0; ofs=0; + while (xWidth) { + if (!(RowData[ofs] & 0x80)) { + if (!(RowData[ofs] & 0x40)) { + for (i=1;i<=RowData[ofs] && xWidth;i++) { + SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=RowData[ofs]+1; + } + else { + for (i=0;iWidth;i++) { + SetPix(hdcDest,Right-x,nYDest+y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=2; + } + } + else { + x+=RowData[ofs]-128; + ofs++; + } + } + } + } + else { + for (y=0;yHeight;y++) { + for (x=0;xWidth;x++) { + SetPix(hdcDest,Right-x,nYDest+y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); + } + } + } + } + else if (!(dwFlags&HORIZONTAL_FLIP) && dwFlags&VERTICAL_FLIP) { + if (FrameSize != GrpFrame->Width * GrpFrame->Height) { + for (y=0;yHeight;y++) { + RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); + x=0; ofs=0; + while (xWidth) { + if (!(RowData[ofs] & 0x80)) { + if (!(RowData[ofs] & 0x40)) { + for (i=1;i<=RowData[ofs] && xWidth;i++) { + SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=RowData[ofs]+1; + } + else { + for (i=0;iWidth;i++) { + SetPix(hdcDest,nXDest+x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=2; + } + } + else { + x+=RowData[ofs]-128; + ofs++; + } + } + } + } + else { + for (y=0;yHeight;y++) { + for (x=0;xWidth;x++) { + SetPix(hdcDest,nXDest+x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); + } + } + } + } + else { + if (FrameSize != GrpFrame->Width * GrpFrame->Height) { + for (y=0;yHeight;y++) { + RowData = ((BYTE *)(((char *)GrpOffsets)+GrpOffsets[y])); + x=0; ofs=0; + while (xWidth) { + if (!(RowData[ofs] & 0x80)) { + if (!(RowData[ofs] & 0x40)) { + for (i=1;i<=RowData[ofs] && xWidth;i++) { + SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+i],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=RowData[ofs]+1; + } + else { + for (i=0;iWidth;i++) { + SetPix(hdcDest,Right-x,Bottom-y,RowData[ofs+1],dwPalette,dwFlags,dwAlpha); + x++; + } + ofs+=2; + } + } + else { + x+=RowData[ofs]-128; + ofs++; + } + } + } + } + else { + for (y=0;yHeight;y++) { + for (x=0;xWidth;x++) { + SetPix(hdcDest,Right-x,Bottom-y,GrpRaw[y * GrpFrame->Width + x],dwPalette,dwFlags,dwAlpha); + } + } + } + } + return TRUE; +} + +BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo) +{ + if (!hGrp || hGrp==INVALID_HANDLE_VALUE || !GrpInfo) return FALSE; + memcpy(GrpInfo,hGrp,6); + return TRUE; +} + +BOOL GRPAPI WINAPI GetGrpFrameInfo(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight) +{ + if (!hGrp || hGrp==INVALID_HANDLE_VALUE) return FALSE; + FRAMEHEADER *GrpFrame = &((FRAMEHEADER *)(((char *)hGrp)+6))[nFrame]; + + if (nLeft) *nLeft = GrpFrame->Left; + if (nTop) *nTop = GrpFrame->Top; + if (nWidth) *nWidth = GrpFrame->Width; + if (nHeight) *nHeight = GrpFrame->Height; + + return TRUE; +} + +void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc) +{ + if (!lpGetPixelProc) + MyGetPixel = GetPixel; + else + MyGetPixel = lpGetPixelProc; +} + +void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc) +{ + if (!lpSetPixelProc) + MySetPixel = (SETPIXELPROC)SetPixelV; + else + MySetPixel = lpSetPixelProc; +} + +void __inline SetPix(HDC hDC, int X, int Y, COLORREF clrColor, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha) +{ + if (!(dwFlags&USE_INDEX)) { + if (dwFlags&SHADOW_COLOR) { + clrColor = (dwFlags >> 8) & 0x00FFFFFF; + } + else { + clrColor = dwPalette[clrColor]; + } + if (dwFlags&ALPHA_BLEND) { + DWORD dwColor = MyGetPixel(hDC,X,Y); + + // Old alpha + /*((BYTE *)&dwColor)[0]*=1-((float)((BYTE *)&dwAlpha)[0]/256); + ((BYTE *)&dwColor)[1]*=1-((float)((BYTE *)&dwAlpha)[1]/256); + ((BYTE *)&dwColor)[2]*=1-((float)((BYTE *)&dwAlpha)[2]/256); + ((BYTE *)&clrColor)[0]*=(float)((BYTE *)&dwAlpha)[0]/256; + ((BYTE *)&clrColor)[1]*=(float)((BYTE *)&dwAlpha)[1]/256; + ((BYTE *)&clrColor)[2]*=(float)((BYTE *)&dwAlpha)[2]/256; + ((BYTE *)&clrColor)[0]+=((BYTE *)&dwColor)[0]; + ((BYTE *)&clrColor)[1]+=((BYTE *)&dwColor)[1]; + ((BYTE *)&clrColor)[2]+=((BYTE *)&dwColor)[2];*/ + + /* blendedcolor = + ( ( forecolor * ( 1 - alpha ) ) >> 8 ) + + ( ( backcolor * ( 256 - alpha ) ) >> 8 ) */ + ((BYTE *)&clrColor)[0] = + ( ( ((BYTE *)&clrColor)[0] * ( ((BYTE *)&dwAlpha)[0] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[0] * ( 256 - ((BYTE *)&dwAlpha)[0] ) ) >> 8 ); + ((BYTE *)&clrColor)[1] = + ( ( ((BYTE *)&clrColor)[1] * ( ((BYTE *)&dwAlpha)[1] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[1] * ( 256 - ((BYTE *)&dwAlpha)[1] ) ) >> 8 ); + ((BYTE *)&clrColor)[2] = + ( ( ((BYTE *)&clrColor)[2] * ( ((BYTE *)&dwAlpha)[2] + 1 ) ) >> 8 ) + + ( ( ((BYTE *)&dwColor)[2] * ( 256 - ((BYTE *)&dwAlpha)[2] ) ) >> 8 ); + } + } + MySetPixel(hDC,X,Y,clrColor); +} + +HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize) +{ + GRPHEADER GrpHeader; + FRAMEHEADER *lpFrameHeaders; + FRAMEDATA *lpFrameData; + LPBYTE lpGrpData; + int i, j, x, y, x1, x2, y1, y2; + DWORD nLastOffset; + + if (!lpImageData || !nGrpSize) return (HANDLE)-1; + + GrpHeader.nFrames = nFrames; + GrpHeader.wMaxWidth = wMaxWidth; + GrpHeader.wMaxHeight = wMaxHeight; + lpFrameHeaders = (FRAMEHEADER *)malloc(nFrames * sizeof(FRAMEHEADER)); + lpFrameData = (FRAMEDATA *)malloc(nFrames * sizeof(FRAMEDATA)); + nLastOffset = sizeof(GRPHEADER) + nFrames * sizeof(FRAMEHEADER); + + for (i = 0; i < nFrames; i++) { + lpFrameHeaders[i].Offset = nLastOffset; + + // Scan frame to find dimensions of used part + x1 = y1 = 0x10000; + x2 = y2 = -1; + for (y = 0; y < wMaxHeight; y++) { + for (x = 0; x < wMaxWidth; x++) { + if (lpImageData[i * wMaxWidth * wMaxHeight + y * wMaxWidth + x] >= 0) { + if (x < x1) x1 = x; + if (x > x2) x2 = x; + if (y < y1) y1 = y; + if (y > y2) y2 = y; + } + } + } + x2 = x2 - x1 + 1; + y2 = y2 - y1 + 1; + if ((WORD)x1 > 255) x1 = 255; + if ((WORD)y1 > 255) y1 = 255; + if ((WORD)x2 > 255) x2 = 255; + if ((WORD)y2 > 255) y2 = 255; + lpFrameHeaders[i].Left = x1; + lpFrameHeaders[i].Top = y1; + lpFrameHeaders[i].Width = x2; + lpFrameHeaders[i].Height = y2; + + // Search for duplicate frames + for (j = 0; j < i; j++) { + if (lpFrameData[j].lpRowOffsets && lpFrameHeaders[i].Width == lpFrameHeaders[j].Width && lpFrameHeaders[i].Height == lpFrameHeaders[j].Height) { + y1 = i * wMaxWidth * wMaxHeight + lpFrameHeaders[i].Top * wMaxWidth + lpFrameHeaders[i].Left; + y2 = j * wMaxWidth * wMaxHeight + lpFrameHeaders[j].Top * wMaxWidth + lpFrameHeaders[j].Left; + + for (y = 0; y < lpFrameHeaders[i].Height; y++) { + if (memcmp(&lpImageData[y1], &lpImageData[y2], lpFrameHeaders[i].Width * sizeof(short)) != 0) + break; + + y1 += wMaxWidth; + y2 += wMaxWidth; + } + + if (y == lpFrameHeaders[i].Height) { + break; + } + } + } + + if (j < i) { + // Duplicate frame found, set offset and flag as duplicate + lpFrameHeaders[i].Offset = lpFrameHeaders[j].Offset; + lpFrameData[i].lpRowOffsets = 0; + lpFrameData[i].lpRowSizes = 0; + lpFrameData[i].lpRowData = 0; + lpFrameData[i].Size = 0; + continue; + } + + EncodeFrameData(lpImageData, i, &GrpHeader, &lpFrameHeaders[i], &lpFrameData[i], bNoCompress); + nLastOffset = lpFrameHeaders[i].Offset + lpFrameData[i].Size; + } + + lpGrpData = (LPBYTE)malloc(nLastOffset); + + // Write completed GRP to buffer + memcpy(lpGrpData, &GrpHeader, sizeof(GRPHEADER)); + memcpy(lpGrpData + sizeof(GRPHEADER), lpFrameHeaders, nFrames * sizeof(FRAMEHEADER)); + + for (i = 0; i < nFrames; i++) { + if (lpFrameData[i].lpRowOffsets) { + if (!bNoCompress) + memcpy(lpGrpData + lpFrameHeaders[i].Offset, lpFrameData[i].lpRowOffsets, lpFrameHeaders[i].Height * sizeof(WORD)); + + for (y = 0; y < lpFrameHeaders[i].Height; y++) { + if (lpFrameData[i].lpRowData[y]) { + memcpy(lpGrpData + lpFrameHeaders[i].Offset + lpFrameData[i].lpRowOffsets[y], lpFrameData[i].lpRowData[y], lpFrameData[i].lpRowSizes[y]); + free(lpFrameData[i].lpRowData[y]); + } + } + + free(lpFrameData[i].lpRowOffsets); + free(lpFrameData[i].lpRowSizes); + free(lpFrameData[i].lpRowData); + } + } + + free(lpFrameHeaders); + free(lpFrameData); + + *nGrpSize = nLastOffset; + return (HANDLE)lpGrpData; +} + +void EncodeFrameData(signed short *lpImageData, WORD nFrame, GRPHEADER *lpGrpHeader, FRAMEHEADER *lpFrameHeader, FRAMEDATA *lpFrameData, BOOL bNoCompress) +{ + int x, y, i, j, nBufPos, nRepeat; + LPBYTE lpRowBuf; + WORD nLastOffset = 0; + + lpFrameData->lpRowOffsets = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD)); + lpFrameData->lpRowSizes = (WORD *)malloc(lpFrameHeader->Height * sizeof(WORD)); + lpFrameData->lpRowData = (LPBYTE *)malloc(lpFrameHeader->Height * sizeof(LPBYTE)); + lpRowBuf = (LPBYTE)malloc(lpFrameHeader->Width * 2); + + if (!bNoCompress) + nLastOffset = lpFrameHeader->Height * sizeof(WORD); + + for (y = 0; y < lpFrameHeader->Height; y++) { + i = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + y) * lpGrpHeader->wMaxWidth; + + if (!bNoCompress) { + // Search for duplicate rows + for (x = 0; x < y; x++) { + j = nFrame * lpGrpHeader->wMaxWidth * lpGrpHeader->wMaxHeight + (lpFrameHeader->Top + x) * lpGrpHeader->wMaxWidth; + if (memcmp(&lpImageData[i+lpFrameHeader->Left], + &lpImageData[j+lpFrameHeader->Left], + lpGrpHeader->wMaxWidth * sizeof(short)) == 0) + break; + } + + if (x < y) { + lpFrameData->lpRowOffsets[y] = lpFrameData->lpRowOffsets[x]; + lpFrameData->lpRowSizes[y] = 0; + lpFrameData->lpRowData[y] = 0; + +#ifdef _DEBUG + if (!VerifyRow(&lpImageData[i+lpFrameHeader->Left], lpFrameHeader->Width, lpFrameData->lpRowData[x], lpFrameData->lpRowSizes[x], bNoCompress)) { + nBufPos = nBufPos; + } +#endif + + continue; + } + } + + nBufPos = 0; + if (lpFrameHeader->Width > 0) { + for (x = lpFrameHeader->Left; x < lpFrameHeader->Left + lpFrameHeader->Width; x++) { + if (!bNoCompress) { + if (x < lpFrameHeader->Left + lpFrameHeader->Width - 1) { + if (lpImageData[i+x] < 0) { + lpRowBuf[nBufPos] = 0x80; + for (; lpImageData[i+x] < 0 && x < lpFrameHeader->Left + lpFrameHeader->Width && lpRowBuf[nBufPos] < 0xFF; x++) { + lpRowBuf[nBufPos]++; + } + x--; + if (nLastOffset + nBufPos + 1 <= 0xFFFF) + nBufPos++; + continue; + } + + // Count repeating pixels, nRepeat = number of pixels - 1, ignore if there are less than 4 duplicates + for (nRepeat = 0; lpImageData[i+x+nRepeat] == lpImageData[i+x+nRepeat+1] && x+nRepeat < lpFrameHeader->Left + lpFrameHeader->Width - 1 && nRepeat < 0x3E; nRepeat++) {} + + if (nRepeat > 2) { + lpRowBuf[nBufPos] = 0x41 + nRepeat; + lpRowBuf[nBufPos+1] = (BYTE)(lpImageData[i+x]); + x += nRepeat; + if (nLastOffset + nBufPos + 2 <= 0xFFFF) + nBufPos += 2; + } + else { + lpRowBuf[nBufPos] = 0; + for (; lpImageData[i+x] >= 0 && x < lpFrameHeader->Left + lpFrameHeader->Width && lpRowBuf[nBufPos] < 0x3F; x++) { + // Count repeating pixels, ignore if there are less than 4 duplicates + for (nRepeat = 0; lpImageData[i+x+nRepeat] == lpImageData[i+x+nRepeat+1] && x+nRepeat < lpFrameHeader->Left + lpFrameHeader->Width - 1 && nRepeat < 3; nRepeat++) {} + if (nRepeat > 2) break; + + lpRowBuf[nBufPos]++; + lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)(lpImageData[i+x]); + } + if (lpImageData[i+x] >= 0 && x == lpFrameHeader->Left + lpFrameHeader->Width - 1 && lpRowBuf[nBufPos] < 0x3F) { + lpRowBuf[nBufPos]++; + lpRowBuf[nBufPos+lpRowBuf[nBufPos]] = (BYTE)(lpImageData[i+x]); + } + x--; + if (nLastOffset + nBufPos + 1 + lpRowBuf[nBufPos] <= 0xFFFF) + nBufPos += 1 + lpRowBuf[nBufPos]; + } + } + else { + if (lpImageData[i+x] < 0) { + lpRowBuf[nBufPos] = 0x81; + if (nLastOffset + nBufPos + 1 <= 0xFFFF) + nBufPos++; + } + else { + lpRowBuf[nBufPos] = 1; + lpRowBuf[nBufPos+1] = (BYTE)(lpImageData[i+x]); + if (nLastOffset + nBufPos + 2 <= 0xFFFF) + nBufPos += 2; + } + } + } + else { + lpRowBuf[nBufPos] = (BYTE)(lpImageData[i+x]); + if (nLastOffset + nBufPos + 1 <= 0xFFFF) + nBufPos++; + } + } + } + +#ifdef _DEBUG + if (!VerifyRow(&lpImageData[i+lpFrameHeader->Left], lpFrameHeader->Width, lpRowBuf, nBufPos, bNoCompress)) { + nBufPos = nBufPos; + } +#endif + + lpFrameData->lpRowOffsets[y] = nLastOffset; + nLastOffset = lpFrameData->lpRowOffsets[y] + nBufPos; + + lpFrameData->lpRowSizes[y] = nBufPos; + lpFrameData->lpRowData[y] = (LPBYTE)malloc(nBufPos); + memcpy(lpFrameData->lpRowData[y], lpRowBuf, nBufPos); + } + + lpFrameData->Size = nLastOffset; + + free(lpRowBuf); +} + +#ifdef _DEBUG +BOOL VerifyRow(signed short *lpRawRow, int nWidth, LPBYTE lpEncRow, int nSize, BOOL bNoCompress) +{ + int i,x=0,ofs=0; + while (x < nWidth && ofs < nSize) { + if (!bNoCompress) { + if (!(lpEncRow[ofs] & 0x80)) { + if (!(lpEncRow[ofs] & 0x40)) { + for (i=1;i<=lpEncRow[ofs] && x= 0) return FALSE; + } + x+=lpEncRow[ofs]-128; + ofs++; + } + } + else { + if (lpEncRow[ofs] != (BYTE)lpRawRow[x]) return FALSE; + x++; + ofs++; + } + } + + if (x != nWidth || ofs != nSize) return FALSE; + + return TRUE; +} +#endif diff --git a/grpapi/grpapi.def b/grpapi/grpapi.def index 74872fc..2d95f21 100644 --- a/grpapi/grpapi.def +++ b/grpapi/grpapi.def @@ -1,13 +1,13 @@ -EXPORTS - LoadPalette @1 - LoadGrp @2 - DestroyGrp @3 - DrawGrp @4 - GetGrpInfo @5 - LoadGrpApi @6 - FreeGrpApi @7 - SetFunctionGetPixel @8 - SetFunctionSetPixel @9 - SetMpqDll @10 - CreateGrp @11 - GetGrpFrameInfo @12 +EXPORTS + LoadPalette @1 + LoadGrp @2 + DestroyGrp @3 + DrawGrp @4 + GetGrpInfo @5 + LoadGrpApi @6 + FreeGrpApi @7 + SetFunctionGetPixel @8 + SetFunctionSetPixel @9 + SetMpqDll @10 + CreateGrp @11 + GetGrpFrameInfo @12 diff --git a/grpapi/grpapi.h b/grpapi/grpapi.h index 5bdbe94..bd5f6cb 100644 --- a/grpapi/grpapi.h +++ b/grpapi/grpapi.h @@ -1,116 +1,116 @@ -/* - - ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2006 - - Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) -*/ - -#ifndef GRPAPI_INCLUDED -#define GRPAPI_INCLUDED - -#include - -#ifndef GRPAPI_STATIC - -#ifdef GRPAPI_EXPORTS -#define GRPAPI __declspec(dllexport) -#else -#define GRPAPI __declspec(dllimport) -#endif - -#else -#define GRPAPI -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - WORD nFrames; - WORD wMaxWidth; - WORD wMaxHeight; -} GRPHEADER; - -#define HORIZONTAL_FLIP 0x00000001 // Flips the graphic horizontally -#define VERTICAL_FLIP 0x00000002 // Flips the graphic vertically -#define SHADOW_COLOR 0x00000004 // Causes the graphic to be drawn in one color - // Second byte of flags is the red component of - // the shadow's color, third byte is green, - // fourth byte is blue; like this: - // SHADOW_COLOR|0xBBGGRR00 - // This can be accomplished by using the left shift - // operator like this: SHADOW_COLOR|(color << 8) -#define ALPHA_BLEND 0x00000008 // Blends the graphic with what it is being drawn over. - // The dwAlpha parameter will only be used when this - // flag is specified. dwAlpha is an RGB value - // (0xBBGGRR). - // Note: Because of the extra calculations required, - // alpha blended graphics take longer to draw -#define USE_INDEX 0x00000010 // Only valid when used with a custom SetPixel function. - // This flag cannot be used in combination with - // ALPHA_BLEND or SHADOW_COLOR - // When this flag is used, the index to a color in the - // palette will be passed to your custom SetPixel - // function instead of the actual color. - -// Palette is an array of 256 DWORD's -// For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive -// or a file not in an archive -BOOL GRPAPI WINAPI LoadPalette(LPCSTR lpFileName, DWORD *dwPaletteBuffer); -HANDLE GRPAPI WINAPI LoadGrp(LPCSTR lpFileName); -BOOL GRPAPI WINAPI DestroyGrp(HANDLE hGrp); -BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); -BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo); -BOOL GRPAPI WINAPI GetGrpFrameInfo(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight); - -// A pointer to the raw image data to encode should be passed to lpImageData. The size of -// the buffer containing the data should be nFrames * wMaxWidth * wMaxHeight * sizeof(short) -// and the values should be arranged row by row of the frame, with the top row first. -// After all the rows of a frame have been put into the buffer, the rows of the next frame -// go after it. For transparent pixels, they should be set to -1. All other pixels should -// have the high order byte set to zero, meaning that they should not be negative and the -// values should not exceed 255 (0xFF). The values used for the colors are indexes into the -// color palette. -// Pass TRUE to bNoCompress if you need an uncompressed GRP. -// Pass a pointer to a DWORD value to nGrpSize to receive the size in bytes of the resulting encoded GRP. -// The return value of this function is actually a pointer to the GRP data. This is what your -// program should save to a file. The size of this buffer is the value received by nGrpSize. -// When your program is done with the returned buffer, it should call DestroyGrp on the -// buffer that was returned by this function to free up the memory from it. -// The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. -HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize); - -typedef COLORREF (WINAPI* GETPIXELPROC)( - HDC hDC, // same value as hdcDest from DrawGrp, - // does not need to be used as an HDC, - // can be used for any other type of pointer - int X, // x-coordinate of pixel - int Y // y-coordinate of pixel -); -typedef void (WINAPI* SETPIXELPROC)( - HDC hDC, // same value as hdcDest from DrawGrp, - // does not need to be used as an HDC, - // can be used for any other type of pointer - int X, // x-coordinate of pixel - int Y, // y-coordinate of pixel - COLORREF clrColor // new pixel color -); - -// Call these to have DrawGrp use custom functions for reading and drawing pixels -// so that you can have it read from and write to a buffer, for example. -void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc); // Only used with ALPHA_BLEND -void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc); - -// Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). -BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName); - -// These no longer need to be called -BOOL GRPAPI WINAPI LoadGrpApi(); -void GRPAPI WINAPI FreeGrpApi(); - -#ifdef __cplusplus -}; // extern "C" -#endif - -#endif +/* + + ShadowFlare GRP Library. (c) ShadowFlare Software 2002-2006 + + Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) +*/ + +#ifndef GRPAPI_INCLUDED +#define GRPAPI_INCLUDED + +#include + +#ifndef GRPAPI_STATIC + +#ifdef GRPAPI_EXPORTS +#define GRPAPI __declspec(dllexport) +#else +#define GRPAPI __declspec(dllimport) +#endif + +#else +#define GRPAPI +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + WORD nFrames; + WORD wMaxWidth; + WORD wMaxHeight; +} GRPHEADER; + +#define HORIZONTAL_FLIP 0x00000001 // Flips the graphic horizontally +#define VERTICAL_FLIP 0x00000002 // Flips the graphic vertically +#define SHADOW_COLOR 0x00000004 // Causes the graphic to be drawn in one color + // Second byte of flags is the red component of + // the shadow's color, third byte is green, + // fourth byte is blue; like this: + // SHADOW_COLOR|0xBBGGRR00 + // This can be accomplished by using the left shift + // operator like this: SHADOW_COLOR|(color << 8) +#define ALPHA_BLEND 0x00000008 // Blends the graphic with what it is being drawn over. + // The dwAlpha parameter will only be used when this + // flag is specified. dwAlpha is an RGB value + // (0xBBGGRR). + // Note: Because of the extra calculations required, + // alpha blended graphics take longer to draw +#define USE_INDEX 0x00000010 // Only valid when used with a custom SetPixel function. + // This flag cannot be used in combination with + // ALPHA_BLEND or SHADOW_COLOR + // When this flag is used, the index to a color in the + // palette will be passed to your custom SetPixel + // function instead of the actual color. + +// Palette is an array of 256 DWORD's +// For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive +// or a file not in an archive +BOOL GRPAPI WINAPI LoadPalette(LPCSTR lpFileName, DWORD *dwPaletteBuffer); +HANDLE GRPAPI WINAPI LoadGrp(LPCSTR lpFileName); +BOOL GRPAPI WINAPI DestroyGrp(HANDLE hGrp); +BOOL GRPAPI WINAPI DrawGrp(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); +BOOL GRPAPI WINAPI GetGrpInfo(HANDLE hGrp, GRPHEADER *GrpInfo); +BOOL GRPAPI WINAPI GetGrpFrameInfo(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight); + +// A pointer to the raw image data to encode should be passed to lpImageData. The size of +// the buffer containing the data should be nFrames * wMaxWidth * wMaxHeight * sizeof(short) +// and the values should be arranged row by row of the frame, with the top row first. +// After all the rows of a frame have been put into the buffer, the rows of the next frame +// go after it. For transparent pixels, they should be set to -1. All other pixels should +// have the high order byte set to zero, meaning that they should not be negative and the +// values should not exceed 255 (0xFF). The values used for the colors are indexes into the +// color palette. +// Pass TRUE to bNoCompress if you need an uncompressed GRP. +// Pass a pointer to a DWORD value to nGrpSize to receive the size in bytes of the resulting encoded GRP. +// The return value of this function is actually a pointer to the GRP data. This is what your +// program should save to a file. The size of this buffer is the value received by nGrpSize. +// When your program is done with the returned buffer, it should call DestroyGrp on the +// buffer that was returned by this function to free up the memory from it. +// The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. +HANDLE GRPAPI WINAPI CreateGrp(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize); + +typedef COLORREF (WINAPI* GETPIXELPROC)( + HDC hDC, // same value as hdcDest from DrawGrp, + // does not need to be used as an HDC, + // can be used for any other type of pointer + int X, // x-coordinate of pixel + int Y // y-coordinate of pixel +); +typedef void (WINAPI* SETPIXELPROC)( + HDC hDC, // same value as hdcDest from DrawGrp, + // does not need to be used as an HDC, + // can be used for any other type of pointer + int X, // x-coordinate of pixel + int Y, // y-coordinate of pixel + COLORREF clrColor // new pixel color +); + +// Call these to have DrawGrp use custom functions for reading and drawing pixels +// so that you can have it read from and write to a buffer, for example. +void GRPAPI WINAPI SetFunctionGetPixel(GETPIXELPROC lpGetPixelProc); // Only used with ALPHA_BLEND +void GRPAPI WINAPI SetFunctionSetPixel(SETPIXELPROC lpSetPixelProc); + +// Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). +BOOL GRPAPI WINAPI SetMpqDll(LPCSTR lpDllFileName); + +// These no longer need to be called +BOOL GRPAPI WINAPI LoadGrpApi(); +void GRPAPI WINAPI FreeGrpApi(); + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif diff --git a/grpapi/grpapi.rc b/grpapi/grpapi.rc index 11d6327..e330c45 100644 --- a/grpapi/grpapi.rc +++ b/grpapi/grpapi.rc @@ -1,103 +1,103 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,1,6 - PRODUCTVERSION 1,1,1,6 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", "ShadowFlare Software" - VALUE "FileDescription", "ShadowFlare GRP Library" - VALUE "FileVersion", "1.11" - VALUE "InternalName", "grpapi" - VALUE "LegalCopyright", "Copyright © ShadowFlare Software 2002-2007" - VALUE "OriginalFilename", "grpapi.dll" - VALUE "ProductName", "GRP Library" - VALUE "ProductVersion", "1, 1, 1, 6" - VALUE "Web Address", "http://sfsrealm.hopto.org/" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,1,1,6 + PRODUCTVERSION 1,1,1,6 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "ShadowFlare Software" + VALUE "FileDescription", "ShadowFlare GRP Library" + VALUE "FileVersion", "1.11" + VALUE "InternalName", "grpapi" + VALUE "LegalCopyright", "Copyright © ShadowFlare Software 2002-2007" + VALUE "OriginalFilename", "grpapi.dll" + VALUE "ProductName", "GRP Library" + VALUE "ProductVersion", "1, 1, 1, 6" + VALUE "Web Address", "http://sfsrealm.hopto.org/" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/grpapi/grpapi.sln b/grpapi/grpapi.sln index 63329d9..f2413bb 100644 --- a/grpapi/grpapi.sln +++ b/grpapi/grpapi.sln @@ -1,51 +1,51 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "drawgrp", "..\drawgrp\drawgrp.vcproj", "{10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpapi", "grpapi.vcproj", "{08812E9C-7F03-4DCB-8828-F3BDB0728EC7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grplib", "grplib.vcproj", "{66127C6F-39DA-4B7A-9856-789ED0139DCB}" -EndProject -Global - GlobalSection(SourceCodeControl) = preSolution - SccNumberOfProjects = 4 - SccProjectName0 = \u0022$/grpapi_VS2005.root/grpapi\u0022,\u0020IGAAAAAA - SccLocalPath0 = .. - SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe - CanCheckoutShared = false - SccProjectFilePathRelativizedFromConnection0 = grpapi\\ - SccProjectUniqueName1 = ..\\drawgrp\\drawgrp.vcproj - SccLocalPath1 = .. - CanCheckoutShared = false - SccProjectFilePathRelativizedFromConnection1 = drawgrp\\ - SccProjectUniqueName2 = grpapi.vcproj - SccLocalPath2 = .. - CanCheckoutShared = false - SccProjectFilePathRelativizedFromConnection2 = grpapi\\ - SccProjectUniqueName3 = grplib.vcproj - SccLocalPath3 = .. - CanCheckoutShared = false - SccProjectFilePathRelativizedFromConnection3 = grpapi\\ - EndGlobalSection - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Debug|Win32.ActiveCfg = Debug|Win32 - {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Debug|Win32.Build.0 = Debug|Win32 - {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Release|Win32.ActiveCfg = Release|Win32 - {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Release|Win32.Build.0 = Release|Win32 - {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Debug|Win32.ActiveCfg = Debug|Win32 - {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Debug|Win32.Build.0 = Debug|Win32 - {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Release|Win32.ActiveCfg = Release|Win32 - {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Release|Win32.Build.0 = Release|Win32 - {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Debug|Win32.ActiveCfg = Debug|Win32 - {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Debug|Win32.Build.0 = Debug|Win32 - {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Release|Win32.ActiveCfg = Release|Win32 - {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "drawgrp", "..\drawgrp\drawgrp.vcproj", "{10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpapi", "grpapi.vcproj", "{08812E9C-7F03-4DCB-8828-F3BDB0728EC7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grplib", "grplib.vcproj", "{66127C6F-39DA-4B7A-9856-789ED0139DCB}" +EndProject +Global + GlobalSection(SourceCodeControl) = preSolution + SccNumberOfProjects = 4 + SccProjectName0 = \u0022$/grpapi_VS2005.root/grpapi\u0022,\u0020IGAAAAAA + SccLocalPath0 = .. + SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + CanCheckoutShared = false + SccProjectFilePathRelativizedFromConnection0 = grpapi\\ + SccProjectUniqueName1 = ..\\drawgrp\\drawgrp.vcproj + SccLocalPath1 = .. + CanCheckoutShared = false + SccProjectFilePathRelativizedFromConnection1 = drawgrp\\ + SccProjectUniqueName2 = grpapi.vcproj + SccLocalPath2 = .. + CanCheckoutShared = false + SccProjectFilePathRelativizedFromConnection2 = grpapi\\ + SccProjectUniqueName3 = grplib.vcproj + SccLocalPath3 = .. + CanCheckoutShared = false + SccProjectFilePathRelativizedFromConnection3 = grpapi\\ + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Debug|Win32.ActiveCfg = Debug|Win32 + {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Debug|Win32.Build.0 = Debug|Win32 + {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Release|Win32.ActiveCfg = Release|Win32 + {10729DB2-5CEA-41BA-9C6F-B47BE5A3C242}.Release|Win32.Build.0 = Release|Win32 + {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Debug|Win32.ActiveCfg = Debug|Win32 + {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Debug|Win32.Build.0 = Debug|Win32 + {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Release|Win32.ActiveCfg = Release|Win32 + {08812E9C-7F03-4DCB-8828-F3BDB0728EC7}.Release|Win32.Build.0 = Release|Win32 + {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Debug|Win32.ActiveCfg = Debug|Win32 + {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Debug|Win32.Build.0 = Debug|Win32 + {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Release|Win32.ActiveCfg = Release|Win32 + {66127C6F-39DA-4B7A-9856-789ED0139DCB}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/grpapi/grpapi.vcproj b/grpapi/grpapi.vcproj index f5e4d67..5761f2b 100644 --- a/grpapi/grpapi.vcproj +++ b/grpapi/grpapi.vcproj @@ -1,299 +1,299 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/grpapi/grpapi.vcproj.vspscc b/grpapi/grpapi.vcproj.vspscc index 055d30a..d780160 100644 --- a/grpapi/grpapi.vcproj.vspscc +++ b/grpapi/grpapi.vcproj.vspscc @@ -1,10 +1,10 @@ -"" -{ -"FILE_VERSION" = "9237" -"ENLISTMENT_CHOICE" = "NEVER" -"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" -"NUMBER_OF_EXCLUDED_FILES" = "0" -"ORIGINAL_PROJECT_FILE_PATH" = "" -"NUMBER_OF_NESTED_PROJECTS" = "0" -"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" -} +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/grpapi/grpapi.vssscc b/grpapi/grpapi.vssscc index 055d30a..d780160 100644 --- a/grpapi/grpapi.vssscc +++ b/grpapi/grpapi.vssscc @@ -1,10 +1,10 @@ -"" -{ -"FILE_VERSION" = "9237" -"ENLISTMENT_CHOICE" = "NEVER" -"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" -"NUMBER_OF_EXCLUDED_FILES" = "0" -"ORIGINAL_PROJECT_FILE_PATH" = "" -"NUMBER_OF_NESTED_PROJECTS" = "0" -"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" -} +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/grpapi/grpapi_no-lib.cpp b/grpapi/grpapi_no-lib.cpp index 9a63fa8..71018b7 100644 --- a/grpapi/grpapi_no-lib.cpp +++ b/grpapi/grpapi_no-lib.cpp @@ -1,70 +1,70 @@ -#include "grpapi_no-lib.h" - -struct GRPAPIMODULE { - GRPAPIMODULE(); - ~GRPAPIMODULE(); -} GrpApi; - -HINSTANCE hGrpApi = 0; - -funcLoadPalette LoadPalette = 0; -funcLoadGrp LoadGrp = 0; -funcDestroyGrp DestroyGrp = 0; -funcDrawGrp DrawGrp = 0; -funcGetGrpInfo GetGrpInfo = 0; -funcGetGrpFrameInfo GetGrpFrameInfo = 0; -funcCreateGrp CreateGrp = 0; -funcSetFunctionGetPixel SetFunctionGetPixel = 0; -funcSetFunctionSetPixel SetFunctionSetPixel = 0; -funcSetMpqDll SetMpqDll = 0; -funcLoadGrpApi LoadGrpApi = 0; -funcFreeGrpApi FreeGrpApi = 0; - -GRPAPIMODULE::GRPAPIMODULE() -{ - if (hGrpApi!=0) return; - hGrpApi = LoadLibrary("grpapi.dll"); - - if (hGrpApi!=0) { - LoadPalette = (funcLoadPalette)GetProcAddress(hGrpApi,"LoadPalette"); - LoadGrp = (funcLoadGrp)GetProcAddress(hGrpApi,"LoadGrp"); - DestroyGrp = (funcDestroyGrp)GetProcAddress(hGrpApi,"DestroyGrp"); - DrawGrp = (funcDrawGrp)GetProcAddress(hGrpApi,"DrawGrp"); - GetGrpInfo = (funcGetGrpInfo)GetProcAddress(hGrpApi,"GetGrpInfo"); - GetGrpFrameInfo = (funcGetGrpFrameInfo)GetProcAddress(hGrpApi,"GetGrpFrameInfo"); - CreateGrp = (funcCreateGrp)GetProcAddress(hGrpApi,"CreateGrp"); - SetFunctionGetPixel = (funcSetFunctionGetPixel)GetProcAddress(hGrpApi,"SetFunctionGetPixel"); - SetFunctionSetPixel = (funcSetFunctionSetPixel)GetProcAddress(hGrpApi,"SetFunctionSetPixel"); - SetMpqDll = (funcSetMpqDll)GetProcAddress(hGrpApi,"SetMpqDll"); - LoadGrpApi = (funcLoadGrpApi)GetProcAddress(hGrpApi,"LoadGrpApi"); - FreeGrpApi = (funcFreeGrpApi)GetProcAddress(hGrpApi,"FreeGrpApi"); - } -} - -GRPAPIMODULE::~GRPAPIMODULE() -{ - LoadPalette = 0; - LoadGrp = 0; - DestroyGrp = 0; - DrawGrp = 0; - GetGrpInfo = 0; - GetGrpFrameInfo = 0; - CreateGrp = 0; - SetFunctionGetPixel = 0; - SetFunctionSetPixel = 0; - SetMpqDll = 0; - LoadGrpApi = 0; - FreeGrpApi = 0; - - if (hGrpApi==0) return; - FreeLibrary(hGrpApi); - hGrpApi = 0; -} - -void LoadGrpApiLib() -{ -} - -void FreeGrpApiLib() -{ -} +#include "grpapi_no-lib.h" + +struct GRPAPIMODULE { + GRPAPIMODULE(); + ~GRPAPIMODULE(); +} GrpApi; + +HINSTANCE hGrpApi = 0; + +funcLoadPalette LoadPalette = 0; +funcLoadGrp LoadGrp = 0; +funcDestroyGrp DestroyGrp = 0; +funcDrawGrp DrawGrp = 0; +funcGetGrpInfo GetGrpInfo = 0; +funcGetGrpFrameInfo GetGrpFrameInfo = 0; +funcCreateGrp CreateGrp = 0; +funcSetFunctionGetPixel SetFunctionGetPixel = 0; +funcSetFunctionSetPixel SetFunctionSetPixel = 0; +funcSetMpqDll SetMpqDll = 0; +funcLoadGrpApi LoadGrpApi = 0; +funcFreeGrpApi FreeGrpApi = 0; + +GRPAPIMODULE::GRPAPIMODULE() +{ + if (hGrpApi!=0) return; + hGrpApi = LoadLibrary("grpapi.dll"); + + if (hGrpApi!=0) { + LoadPalette = (funcLoadPalette)GetProcAddress(hGrpApi,"LoadPalette"); + LoadGrp = (funcLoadGrp)GetProcAddress(hGrpApi,"LoadGrp"); + DestroyGrp = (funcDestroyGrp)GetProcAddress(hGrpApi,"DestroyGrp"); + DrawGrp = (funcDrawGrp)GetProcAddress(hGrpApi,"DrawGrp"); + GetGrpInfo = (funcGetGrpInfo)GetProcAddress(hGrpApi,"GetGrpInfo"); + GetGrpFrameInfo = (funcGetGrpFrameInfo)GetProcAddress(hGrpApi,"GetGrpFrameInfo"); + CreateGrp = (funcCreateGrp)GetProcAddress(hGrpApi,"CreateGrp"); + SetFunctionGetPixel = (funcSetFunctionGetPixel)GetProcAddress(hGrpApi,"SetFunctionGetPixel"); + SetFunctionSetPixel = (funcSetFunctionSetPixel)GetProcAddress(hGrpApi,"SetFunctionSetPixel"); + SetMpqDll = (funcSetMpqDll)GetProcAddress(hGrpApi,"SetMpqDll"); + LoadGrpApi = (funcLoadGrpApi)GetProcAddress(hGrpApi,"LoadGrpApi"); + FreeGrpApi = (funcFreeGrpApi)GetProcAddress(hGrpApi,"FreeGrpApi"); + } +} + +GRPAPIMODULE::~GRPAPIMODULE() +{ + LoadPalette = 0; + LoadGrp = 0; + DestroyGrp = 0; + DrawGrp = 0; + GetGrpInfo = 0; + GetGrpFrameInfo = 0; + CreateGrp = 0; + SetFunctionGetPixel = 0; + SetFunctionSetPixel = 0; + SetMpqDll = 0; + LoadGrpApi = 0; + FreeGrpApi = 0; + + if (hGrpApi==0) return; + FreeLibrary(hGrpApi); + hGrpApi = 0; +} + +void LoadGrpApiLib() +{ +} + +void FreeGrpApiLib() +{ +} diff --git a/grpapi/grpapi_no-lib.h b/grpapi/grpapi_no-lib.h index 9dc9baa..fef3f6c 100644 --- a/grpapi/grpapi_no-lib.h +++ b/grpapi/grpapi_no-lib.h @@ -1,126 +1,126 @@ -/* - - ShadowFlare GRP Library. (c) ShadowFlare Software 2002 - - Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) -*/ - -#ifndef GRPAPI_INCLUDED -#define GRPAPI_INCLUDED - -#include - -#ifdef GRPAPI_EXPORTS -#define GRPAPI __declspec(dllexport) -#else -#define GRPAPI __declspec(dllimport) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// These no longer need to be called -extern void LoadGrpApiLib(); -extern void FreeGrpApiLib(); - -typedef struct { - WORD nFrames; - WORD wMaxWidth; - WORD wMaxHeight; -} GRPHEADER; - -#define HORIZONTAL_FLIP 0x00000001 // Flips the graphic horizontally -#define VERTICAL_FLIP 0x00000002 // Flips the graphic vertically -#define SHADOW_COLOR 0x00000004 // Causes the graphic to be drawn in one color - // Second byte of flags is the red component of - // the shadow's color, third byte is green, - // fourth byte is blue; like this: - // SHADOW_COLOR|0xBBGGRR00 - // This can be accomplished by using the left shift - // operator like this: SHADOW_COLOR|(color << 8) -#define ALPHA_BLEND 0x00000008 // Blends the graphic with what it is being drawn over. - // The dwAlpha parameter will only be used when this - // flag is specified. dwAlpha is an RGB value - // (0xBBGGRR). - // Note: Because of the extra calculations required, - // alpha blended graphics take longer to draw -#define USE_INDEX 0x00000010 // Only valid when used with a custom SetPixel function. - // This flag cannot be used in combination with - // ALPHA_BLEND or SHADOW_COLOR - // When this flag is used, the index to a color in the - // palette will be passed to your custom SetPixel - // function instead of the actual color. - -// Palette is an array of 256 DWORD's -// For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive -// or a file not in an archive -typedef BOOL (WINAPI* funcLoadPalette)(LPCSTR lpFileName, DWORD *dwPaletteBuffer); -typedef HANDLE (WINAPI* funcLoadGrp)(LPCSTR lpFileName); -typedef BOOL (WINAPI* funcDestroyGrp)(HANDLE hGrp); -typedef BOOL (WINAPI* funcDrawGrp)(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); -typedef BOOL (WINAPI* funcGetGrpInfo)(HANDLE hGrp, GRPHEADER *GrpInfo); -typedef BOOL (WINAPI* funcGetGrpFrameInfo)(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight); -extern funcLoadPalette LoadPalette; -extern funcLoadGrp LoadGrp; -extern funcDestroyGrp DestroyGrp; -extern funcDrawGrp DrawGrp; -extern funcGetGrpInfo GetGrpInfo; -extern funcGetGrpFrameInfo GetGrpFrameInfo; - -// A pointer to the raw image data to encode should be passed to lpImageData. The size of -// the buffer containing the data should be nFrames * wMaxWidth * wMaxHeight * sizeof(short) -// and the values should be arranged row by row of the frame, with the top row first. -// After all the rows of a frame have been put into the buffer, the rows of the next frame -// go after it. For transparent pixels, they should be set to -1. All other pixels should -// have the high order byte set to zero, meaning that they should not be negative and the -// values should not exceed 255 (0xFF). The values used for the colors are indexes into the -// color palette. -// Pass TRUE to bNoCompress if you need an uncompressed GRP. -// Pass a pointer to a DWORD value to nGrpSize to receive the size in bytes of the resulting encoded GRP. -// The return value of this function is actually a pointer to the GRP data. This is what your -// program should save to a file. The size of this buffer is the value received by nGrpSize. -// When your program is done with the returned buffer, it should call DestroyGrp on the -// buffer that was returned by this function to free up the memory from it. -// The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. -typedef HANDLE (WINAPI* funcCreateGrp)(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize); -extern funcCreateGrp CreateGrp; - -typedef COLORREF (WINAPI* GETPIXELPROC)( - HDC hDC, // same value as hdcDest from DrawGrp, - // does not need to be used as an HDC, - // can be used for any other type of pointer - int X, // x-coordinate of pixel - int Y // y-coordinate of pixel -); -typedef void (WINAPI* SETPIXELPROC)( - HDC hDC, // same value as hdcDest from DrawGrp, - // does not need to be used as an HDC, - // can be used for any other type of pointer - int X, // x-coordinate of pixel - int Y, // y-coordinate of pixel - COLORREF clrColor // new pixel color -); - -// Call these to have DrawGrp use custom functions for reading and drawing pixels -// so that you can have it read from and write to a buffer, for example. -typedef void (WINAPI* funcSetFunctionGetPixel)(GETPIXELPROC lpGetPixelProc); -typedef void (WINAPI* funcSetFunctionSetPixel)(SETPIXELPROC lpSetPixelProc); -extern funcSetFunctionGetPixel SetFunctionGetPixel; // Only used with ALPHA_BLEND -extern funcSetFunctionSetPixel SetFunctionSetPixel; - -// Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). -typedef BOOL (WINAPI* funcSetMpqDll)(LPCSTR lpDllFileName); -extern funcSetMpqDll SetMpqDll; - -// These no longer need to be called -typedef BOOL (WINAPI* funcLoadGrpApi)(); -typedef void (WINAPI* funcFreeGrpApi)(); -extern funcLoadGrpApi LoadGrpApi; -extern funcFreeGrpApi FreeGrpApi; - -#ifdef __cplusplus -}; // extern "C" -#endif - -#endif +/* + + ShadowFlare GRP Library. (c) ShadowFlare Software 2002 + + Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare) +*/ + +#ifndef GRPAPI_INCLUDED +#define GRPAPI_INCLUDED + +#include + +#ifdef GRPAPI_EXPORTS +#define GRPAPI __declspec(dllexport) +#else +#define GRPAPI __declspec(dllimport) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// These no longer need to be called +extern void LoadGrpApiLib(); +extern void FreeGrpApiLib(); + +typedef struct { + WORD nFrames; + WORD wMaxWidth; + WORD wMaxHeight; +} GRPHEADER; + +#define HORIZONTAL_FLIP 0x00000001 // Flips the graphic horizontally +#define VERTICAL_FLIP 0x00000002 // Flips the graphic vertically +#define SHADOW_COLOR 0x00000004 // Causes the graphic to be drawn in one color + // Second byte of flags is the red component of + // the shadow's color, third byte is green, + // fourth byte is blue; like this: + // SHADOW_COLOR|0xBBGGRR00 + // This can be accomplished by using the left shift + // operator like this: SHADOW_COLOR|(color << 8) +#define ALPHA_BLEND 0x00000008 // Blends the graphic with what it is being drawn over. + // The dwAlpha parameter will only be used when this + // flag is specified. dwAlpha is an RGB value + // (0xBBGGRR). + // Note: Because of the extra calculations required, + // alpha blended graphics take longer to draw +#define USE_INDEX 0x00000010 // Only valid when used with a custom SetPixel function. + // This flag cannot be used in combination with + // ALPHA_BLEND or SHADOW_COLOR + // When this flag is used, the index to a color in the + // palette will be passed to your custom SetPixel + // function instead of the actual color. + +// Palette is an array of 256 DWORD's +// For LoadPalette and LoadGrp, lpFileName may be a file in an open mpq archive +// or a file not in an archive +typedef BOOL (WINAPI* funcLoadPalette)(LPCSTR lpFileName, DWORD *dwPaletteBuffer); +typedef HANDLE (WINAPI* funcLoadGrp)(LPCSTR lpFileName); +typedef BOOL (WINAPI* funcDestroyGrp)(HANDLE hGrp); +typedef BOOL (WINAPI* funcDrawGrp)(HANDLE hGrp, HDC hdcDest, int nXDest, int nYDest, WORD nFrame, DWORD *dwPalette, DWORD dwFlags, DWORD dwAlpha); +typedef BOOL (WINAPI* funcGetGrpInfo)(HANDLE hGrp, GRPHEADER *GrpInfo); +typedef BOOL (WINAPI* funcGetGrpFrameInfo)(HANDLE hGrp, WORD nFrame, DWORD *nLeft, DWORD *nTop, DWORD *nWidth, DWORD *nHeight); +extern funcLoadPalette LoadPalette; +extern funcLoadGrp LoadGrp; +extern funcDestroyGrp DestroyGrp; +extern funcDrawGrp DrawGrp; +extern funcGetGrpInfo GetGrpInfo; +extern funcGetGrpFrameInfo GetGrpFrameInfo; + +// A pointer to the raw image data to encode should be passed to lpImageData. The size of +// the buffer containing the data should be nFrames * wMaxWidth * wMaxHeight * sizeof(short) +// and the values should be arranged row by row of the frame, with the top row first. +// After all the rows of a frame have been put into the buffer, the rows of the next frame +// go after it. For transparent pixels, they should be set to -1. All other pixels should +// have the high order byte set to zero, meaning that they should not be negative and the +// values should not exceed 255 (0xFF). The values used for the colors are indexes into the +// color palette. +// Pass TRUE to bNoCompress if you need an uncompressed GRP. +// Pass a pointer to a DWORD value to nGrpSize to receive the size in bytes of the resulting encoded GRP. +// The return value of this function is actually a pointer to the GRP data. This is what your +// program should save to a file. The size of this buffer is the value received by nGrpSize. +// When your program is done with the returned buffer, it should call DestroyGrp on the +// buffer that was returned by this function to free up the memory from it. +// The pointer returned by this function can also be directly used by DrawGrp or GetGrpInfo. +typedef HANDLE (WINAPI* funcCreateGrp)(signed short *lpImageData, WORD nFrames, WORD wMaxWidth, WORD wMaxHeight, BOOL bNoCompress, DWORD *nGrpSize); +extern funcCreateGrp CreateGrp; + +typedef COLORREF (WINAPI* GETPIXELPROC)( + HDC hDC, // same value as hdcDest from DrawGrp, + // does not need to be used as an HDC, + // can be used for any other type of pointer + int X, // x-coordinate of pixel + int Y // y-coordinate of pixel +); +typedef void (WINAPI* SETPIXELPROC)( + HDC hDC, // same value as hdcDest from DrawGrp, + // does not need to be used as an HDC, + // can be used for any other type of pointer + int X, // x-coordinate of pixel + int Y, // y-coordinate of pixel + COLORREF clrColor // new pixel color +); + +// Call these to have DrawGrp use custom functions for reading and drawing pixels +// so that you can have it read from and write to a buffer, for example. +typedef void (WINAPI* funcSetFunctionGetPixel)(GETPIXELPROC lpGetPixelProc); +typedef void (WINAPI* funcSetFunctionSetPixel)(SETPIXELPROC lpSetPixelProc); +extern funcSetFunctionGetPixel SetFunctionGetPixel; // Only used with ALPHA_BLEND +extern funcSetFunctionSetPixel SetFunctionSetPixel; + +// Call this to make a different Storm.dll-compatible MPQ library be used (like SFMPQ). +typedef BOOL (WINAPI* funcSetMpqDll)(LPCSTR lpDllFileName); +extern funcSetMpqDll SetMpqDll; + +// These no longer need to be called +typedef BOOL (WINAPI* funcLoadGrpApi)(); +typedef void (WINAPI* funcFreeGrpApi)(); +extern funcLoadGrpApi LoadGrpApi; +extern funcFreeGrpApi FreeGrpApi; + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif diff --git a/grpapi/grplib.vcproj b/grpapi/grplib.vcproj index 38a197b..0c2c8c3 100644 --- a/grpapi/grplib.vcproj +++ b/grpapi/grplib.vcproj @@ -1,239 +1,239 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/grpapi/grplib.vcproj.vspscc b/grpapi/grplib.vcproj.vspscc index 055d30a..d780160 100644 --- a/grpapi/grplib.vcproj.vspscc +++ b/grpapi/grplib.vcproj.vspscc @@ -1,10 +1,10 @@ -"" -{ -"FILE_VERSION" = "9237" -"ENLISTMENT_CHOICE" = "NEVER" -"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" -"NUMBER_OF_EXCLUDED_FILES" = "0" -"ORIGINAL_PROJECT_FILE_PATH" = "" -"NUMBER_OF_NESTED_PROJECTS" = "0" -"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" -} +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "relative:grpapi" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/grpapi/resource.h b/grpapi/resource.h index 82116dd..d934404 100644 --- a/grpapi/resource.h +++ b/grpapi/resource.h @@ -1,15 +1,15 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by grpapi.rc -// - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by grpapi.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/loadstorm/Storm.cpp b/loadstorm/Storm.cpp index c8e6366..02b528f 100644 --- a/loadstorm/Storm.cpp +++ b/loadstorm/Storm.cpp @@ -1,121 +1,121 @@ -/* - Storm.cpp -*/ - -#include "storm.h" - -struct STORMMODULE { - STORMMODULE(); - ~STORMMODULE(); -} Storm; - -void FreeStorm(); - -HINSTANCE hStorm = 0; -BOOL AlreadyLoaded = FALSE; - -// Storm Function Names -funcSFileCloseArchive SFileCloseArchive = 0; -funcSFileCloseFile SFileCloseFile = 0; -funcSFileDestroy SFileDestroy = 0; -funcSFileGetFileArchive SFileGetFileArchive = 0; -funcSFileGetFileSize SFileGetFileSize = 0; -funcSFileOpenArchive SFileOpenArchive = 0; -funcSFileOpenFile SFileOpenFile = 0; -funcSFileOpenFileEx SFileOpenFileEx = 0; -funcSFileReadFile SFileReadFile = 0; -funcSFileSetBasePath SFileSetBasePath = 0; -funcSFileSetFilePointer SFileSetFilePointer = 0; -funcSFileSetLocale SFileSetLocale = 0; -funcSFileGetBasePath SFileGetBasePath = 0; -funcSFileGetArchiveName SFileGetArchiveName = 0; -funcSFileGetFileName SFileGetFileName = 0; - -STORMMODULE::STORMMODULE() -{ - if (hStorm!=0) return; - const char STORM_DLL[] = "Storm.dll"; - hStorm = GetModuleHandle(STORM_DLL); - if (hStorm == NULL) hStorm = LoadLibrary(STORM_DLL); - else AlreadyLoaded=TRUE; - - if (hStorm != NULL) - { - SFileCloseArchive = (funcSFileCloseArchive)GetProcAddress(hStorm, (LPCSTR)0xFC); - SFileCloseFile = (funcSFileCloseFile)GetProcAddress(hStorm, (LPCSTR)0xFD); - SFileDestroy = (funcSFileDestroy)GetProcAddress(hStorm, (LPCSTR)0x106); - SFileGetFileArchive = (funcSFileGetFileArchive)GetProcAddress(hStorm, (LPCSTR)0x108); - SFileGetFileSize = (funcSFileGetFileSize)GetProcAddress(hStorm, (LPCSTR)0x109); - SFileOpenArchive = (funcSFileOpenArchive)GetProcAddress(hStorm, (LPCSTR)0x10A); - SFileOpenFile = (funcSFileOpenFile)GetProcAddress(hStorm, (LPCSTR)0x10B); - SFileOpenFileEx = (funcSFileOpenFileEx)GetProcAddress(hStorm, (LPCSTR)0x10C); - SFileReadFile = (funcSFileReadFile)GetProcAddress(hStorm, (LPCSTR)0x10D); - SFileSetBasePath = (funcSFileSetBasePath)GetProcAddress(hStorm, (LPCSTR)0x10E); - SFileSetFilePointer = (funcSFileSetFilePointer)GetProcAddress(hStorm, (LPCSTR)0x10F); - SFileSetLocale = (funcSFileSetLocale)GetProcAddress(hStorm, (LPCSTR)0x110); - SFileGetBasePath = (funcSFileGetBasePath)GetProcAddress(hStorm, (LPCSTR)0x111); - SFileGetArchiveName = (funcSFileGetArchiveName)GetProcAddress(hStorm, (LPCSTR)0x113); - SFileGetFileName = (funcSFileGetFileName)GetProcAddress(hStorm, (LPCSTR)0x114); - } - if (SFileDestroy && !AlreadyLoaded) SFileDestroy(); -} - -STORMMODULE::~STORMMODULE() -{ - FreeStorm(); -} - -HINSTANCE LoadStorm(char * DllFileName) -{ - FreeStorm(); - if (hStorm!=0) return 0; - hStorm = GetModuleHandle(DllFileName); - if (hStorm == NULL) hStorm = LoadLibrary(DllFileName); - else AlreadyLoaded=TRUE; - - if (hStorm != NULL) - { - SFileCloseArchive = (funcSFileCloseArchive)GetProcAddress(hStorm, (LPCSTR)0xFC); - SFileCloseFile = (funcSFileCloseFile)GetProcAddress(hStorm, (LPCSTR)0xFD); - SFileDestroy = (funcSFileDestroy)GetProcAddress(hStorm, (LPCSTR)0x106); - SFileGetFileArchive = (funcSFileGetFileArchive)GetProcAddress(hStorm, (LPCSTR)0x108); - SFileGetFileSize = (funcSFileGetFileSize)GetProcAddress(hStorm, (LPCSTR)0x109); - SFileOpenArchive = (funcSFileOpenArchive)GetProcAddress(hStorm, (LPCSTR)0x10A); - SFileOpenFile = (funcSFileOpenFile)GetProcAddress(hStorm, (LPCSTR)0x10B); - SFileOpenFileEx = (funcSFileOpenFileEx)GetProcAddress(hStorm, (LPCSTR)0x10C); - SFileReadFile = (funcSFileReadFile)GetProcAddress(hStorm, (LPCSTR)0x10D); - SFileSetBasePath = (funcSFileSetBasePath)GetProcAddress(hStorm, (LPCSTR)0x10E); - SFileSetFilePointer = (funcSFileSetFilePointer)GetProcAddress(hStorm, (LPCSTR)0x10F); - SFileSetLocale = (funcSFileSetLocale)GetProcAddress(hStorm, (LPCSTR)0x110); - SFileGetBasePath = (funcSFileGetBasePath)GetProcAddress(hStorm, (LPCSTR)0x111); - SFileGetArchiveName = (funcSFileGetArchiveName)GetProcAddress(hStorm, (LPCSTR)0x113); - SFileGetFileName = (funcSFileGetFileName)GetProcAddress(hStorm, (LPCSTR)0x114); - } - if (SFileDestroy && !AlreadyLoaded) SFileDestroy(); - if (AlreadyLoaded==TRUE) return 0; - return hStorm; -} - -void FreeStorm() -{ - SFileCloseArchive = 0; - SFileCloseFile = 0; - SFileDestroy = 0; - SFileGetFileArchive = 0; - SFileGetFileSize = 0; - SFileOpenArchive = 0; - SFileOpenFile = 0; - SFileOpenFileEx = 0; - SFileReadFile = 0; - SFileSetBasePath = 0; - SFileSetFilePointer = 0; - SFileSetLocale = 0; - SFileGetBasePath = 0; - SFileGetArchiveName = 0; - SFileGetFileName = 0; - - if (hStorm==0) return; - - if (AlreadyLoaded==FALSE) FreeLibrary(hStorm); - hStorm = 0; -} +/* + Storm.cpp +*/ + +#include "storm.h" + +struct STORMMODULE { + STORMMODULE(); + ~STORMMODULE(); +} Storm; + +void FreeStorm(); + +HINSTANCE hStorm = 0; +BOOL AlreadyLoaded = FALSE; + +// Storm Function Names +funcSFileCloseArchive SFileCloseArchive = 0; +funcSFileCloseFile SFileCloseFile = 0; +funcSFileDestroy SFileDestroy = 0; +funcSFileGetFileArchive SFileGetFileArchive = 0; +funcSFileGetFileSize SFileGetFileSize = 0; +funcSFileOpenArchive SFileOpenArchive = 0; +funcSFileOpenFile SFileOpenFile = 0; +funcSFileOpenFileEx SFileOpenFileEx = 0; +funcSFileReadFile SFileReadFile = 0; +funcSFileSetBasePath SFileSetBasePath = 0; +funcSFileSetFilePointer SFileSetFilePointer = 0; +funcSFileSetLocale SFileSetLocale = 0; +funcSFileGetBasePath SFileGetBasePath = 0; +funcSFileGetArchiveName SFileGetArchiveName = 0; +funcSFileGetFileName SFileGetFileName = 0; + +STORMMODULE::STORMMODULE() +{ + if (hStorm!=0) return; + const char STORM_DLL[] = "Storm.dll"; + hStorm = GetModuleHandle(STORM_DLL); + if (hStorm == NULL) hStorm = LoadLibrary(STORM_DLL); + else AlreadyLoaded=TRUE; + + if (hStorm != NULL) + { + SFileCloseArchive = (funcSFileCloseArchive)GetProcAddress(hStorm, (LPCSTR)0xFC); + SFileCloseFile = (funcSFileCloseFile)GetProcAddress(hStorm, (LPCSTR)0xFD); + SFileDestroy = (funcSFileDestroy)GetProcAddress(hStorm, (LPCSTR)0x106); + SFileGetFileArchive = (funcSFileGetFileArchive)GetProcAddress(hStorm, (LPCSTR)0x108); + SFileGetFileSize = (funcSFileGetFileSize)GetProcAddress(hStorm, (LPCSTR)0x109); + SFileOpenArchive = (funcSFileOpenArchive)GetProcAddress(hStorm, (LPCSTR)0x10A); + SFileOpenFile = (funcSFileOpenFile)GetProcAddress(hStorm, (LPCSTR)0x10B); + SFileOpenFileEx = (funcSFileOpenFileEx)GetProcAddress(hStorm, (LPCSTR)0x10C); + SFileReadFile = (funcSFileReadFile)GetProcAddress(hStorm, (LPCSTR)0x10D); + SFileSetBasePath = (funcSFileSetBasePath)GetProcAddress(hStorm, (LPCSTR)0x10E); + SFileSetFilePointer = (funcSFileSetFilePointer)GetProcAddress(hStorm, (LPCSTR)0x10F); + SFileSetLocale = (funcSFileSetLocale)GetProcAddress(hStorm, (LPCSTR)0x110); + SFileGetBasePath = (funcSFileGetBasePath)GetProcAddress(hStorm, (LPCSTR)0x111); + SFileGetArchiveName = (funcSFileGetArchiveName)GetProcAddress(hStorm, (LPCSTR)0x113); + SFileGetFileName = (funcSFileGetFileName)GetProcAddress(hStorm, (LPCSTR)0x114); + } + if (SFileDestroy && !AlreadyLoaded) SFileDestroy(); +} + +STORMMODULE::~STORMMODULE() +{ + FreeStorm(); +} + +HINSTANCE LoadStorm(char * DllFileName) +{ + FreeStorm(); + if (hStorm!=0) return 0; + hStorm = GetModuleHandle(DllFileName); + if (hStorm == NULL) hStorm = LoadLibrary(DllFileName); + else AlreadyLoaded=TRUE; + + if (hStorm != NULL) + { + SFileCloseArchive = (funcSFileCloseArchive)GetProcAddress(hStorm, (LPCSTR)0xFC); + SFileCloseFile = (funcSFileCloseFile)GetProcAddress(hStorm, (LPCSTR)0xFD); + SFileDestroy = (funcSFileDestroy)GetProcAddress(hStorm, (LPCSTR)0x106); + SFileGetFileArchive = (funcSFileGetFileArchive)GetProcAddress(hStorm, (LPCSTR)0x108); + SFileGetFileSize = (funcSFileGetFileSize)GetProcAddress(hStorm, (LPCSTR)0x109); + SFileOpenArchive = (funcSFileOpenArchive)GetProcAddress(hStorm, (LPCSTR)0x10A); + SFileOpenFile = (funcSFileOpenFile)GetProcAddress(hStorm, (LPCSTR)0x10B); + SFileOpenFileEx = (funcSFileOpenFileEx)GetProcAddress(hStorm, (LPCSTR)0x10C); + SFileReadFile = (funcSFileReadFile)GetProcAddress(hStorm, (LPCSTR)0x10D); + SFileSetBasePath = (funcSFileSetBasePath)GetProcAddress(hStorm, (LPCSTR)0x10E); + SFileSetFilePointer = (funcSFileSetFilePointer)GetProcAddress(hStorm, (LPCSTR)0x10F); + SFileSetLocale = (funcSFileSetLocale)GetProcAddress(hStorm, (LPCSTR)0x110); + SFileGetBasePath = (funcSFileGetBasePath)GetProcAddress(hStorm, (LPCSTR)0x111); + SFileGetArchiveName = (funcSFileGetArchiveName)GetProcAddress(hStorm, (LPCSTR)0x113); + SFileGetFileName = (funcSFileGetFileName)GetProcAddress(hStorm, (LPCSTR)0x114); + } + if (SFileDestroy && !AlreadyLoaded) SFileDestroy(); + if (AlreadyLoaded==TRUE) return 0; + return hStorm; +} + +void FreeStorm() +{ + SFileCloseArchive = 0; + SFileCloseFile = 0; + SFileDestroy = 0; + SFileGetFileArchive = 0; + SFileGetFileSize = 0; + SFileOpenArchive = 0; + SFileOpenFile = 0; + SFileOpenFileEx = 0; + SFileReadFile = 0; + SFileSetBasePath = 0; + SFileSetFilePointer = 0; + SFileSetLocale = 0; + SFileGetBasePath = 0; + SFileGetArchiveName = 0; + SFileGetFileName = 0; + + if (hStorm==0) return; + + if (AlreadyLoaded==FALSE) FreeLibrary(hStorm); + hStorm = 0; +} diff --git a/loadstorm/Storm.h b/loadstorm/Storm.h index 31a5eac..cfadd7f 100644 --- a/loadstorm/Storm.h +++ b/loadstorm/Storm.h @@ -1,59 +1,59 @@ -#ifndef STORM_H_INCLUDED -#define STORM_H_INCLUDED - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// This no longer needs to be called -extern HINSTANCE LoadStorm(char * DllFileName); - -#define SFILE_OPEN_HARD_DISK_FILE 0x0000 //Open archive without regard to the drive type it resides on -#define SFILE_OPEN_CD_ROM_FILE 0x0001 //Open the archive only if it is on a CD-ROM - -#define SFILE_SEARCH_CURRENT_ONLY 0x00 //Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file -#define SFILE_SEARCH_ALL_OPEN 0x01 //SFileOpenFileEx will look through all open archives for the file - -#define MPQHANDLE HANDLE - -// Storm Function Prototypes -typedef BOOL (WINAPI* funcSFileOpenArchive)(LPCSTR lpFilename, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); -typedef BOOL (WINAPI* funcSFileCloseArchive)(MPQHANDLE hMPQ); -typedef BOOL (WINAPI* funcSFileOpenFile)(LPCSTR lpFileName, MPQHANDLE *hFile); -typedef BOOL (WINAPI* funcSFileOpenFileEx)(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile); -typedef BOOL (WINAPI* funcSFileCloseFile)(MPQHANDLE hFile); -typedef DWORD (WINAPI* funcSFileGetFileSize)(MPQHANDLE hFile, LPDWORD lpFileSizeHigh); -typedef DWORD (WINAPI* funcSFileSetFilePointer)(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod); -typedef BOOL (WINAPI* funcSFileReadFile)(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); -typedef LCID (WINAPI* funcSFileSetLocale)(LCID nNewLocale); -typedef BOOL (WINAPI* funcSFileDestroy)(); -typedef BOOL (WINAPI* funcSFileGetArchiveName)(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength); -typedef BOOL (WINAPI* funcSFileGetFileName)(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength); -typedef BOOL (WINAPI* funcSFileGetFileArchive)(MPQHANDLE hFile, MPQHANDLE *hMPQ); -typedef BOOL (WINAPI* funcSFileGetBasePath)(LPCSTR lpBuffer, DWORD dwBufferLength); -typedef BOOL (WINAPI* funcSFileSetBasePath)(LPCSTR lpNewBasePath); - -// Storm Function Names -extern funcSFileCloseArchive SFileCloseArchive; -extern funcSFileCloseFile SFileCloseFile; -extern funcSFileDestroy SFileDestroy; -extern funcSFileGetFileArchive SFileGetFileArchive; -extern funcSFileGetFileSize SFileGetFileSize; -extern funcSFileOpenArchive SFileOpenArchive; -extern funcSFileOpenFile SFileOpenFile; -extern funcSFileOpenFileEx SFileOpenFileEx; -extern funcSFileReadFile SFileReadFile; -extern funcSFileSetBasePath SFileSetBasePath; -extern funcSFileSetFilePointer SFileSetFilePointer; -extern funcSFileSetLocale SFileSetLocale; -extern funcSFileGetBasePath SFileGetBasePath; -extern funcSFileGetArchiveName SFileGetArchiveName; -extern funcSFileGetFileName SFileGetFileName; - -#ifdef __cplusplus -}; // extern "C" -#endif - -#endif +#ifndef STORM_H_INCLUDED +#define STORM_H_INCLUDED + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// This no longer needs to be called +extern HINSTANCE LoadStorm(char * DllFileName); + +#define SFILE_OPEN_HARD_DISK_FILE 0x0000 //Open archive without regard to the drive type it resides on +#define SFILE_OPEN_CD_ROM_FILE 0x0001 //Open the archive only if it is on a CD-ROM + +#define SFILE_SEARCH_CURRENT_ONLY 0x00 //Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file +#define SFILE_SEARCH_ALL_OPEN 0x01 //SFileOpenFileEx will look through all open archives for the file + +#define MPQHANDLE HANDLE + +// Storm Function Prototypes +typedef BOOL (WINAPI* funcSFileOpenArchive)(LPCSTR lpFilename, DWORD dwPriority, DWORD dwFlags, MPQHANDLE *hMPQ); +typedef BOOL (WINAPI* funcSFileCloseArchive)(MPQHANDLE hMPQ); +typedef BOOL (WINAPI* funcSFileOpenFile)(LPCSTR lpFileName, MPQHANDLE *hFile); +typedef BOOL (WINAPI* funcSFileOpenFileEx)(MPQHANDLE hMPQ, LPCSTR lpFileName, DWORD dwSearchScope, MPQHANDLE *hFile); +typedef BOOL (WINAPI* funcSFileCloseFile)(MPQHANDLE hFile); +typedef DWORD (WINAPI* funcSFileGetFileSize)(MPQHANDLE hFile, LPDWORD lpFileSizeHigh); +typedef DWORD (WINAPI* funcSFileSetFilePointer)(MPQHANDLE hFile, long lDistanceToMove, PLONG lplDistanceToMoveHigh, DWORD dwMoveMethod); +typedef BOOL (WINAPI* funcSFileReadFile)(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped); +typedef LCID (WINAPI* funcSFileSetLocale)(LCID nNewLocale); +typedef BOOL (WINAPI* funcSFileDestroy)(); +typedef BOOL (WINAPI* funcSFileGetArchiveName)(MPQHANDLE hMPQ, LPCSTR lpBuffer, DWORD dwBufferLength); +typedef BOOL (WINAPI* funcSFileGetFileName)(MPQHANDLE hFile, LPCSTR lpBuffer, DWORD dwBufferLength); +typedef BOOL (WINAPI* funcSFileGetFileArchive)(MPQHANDLE hFile, MPQHANDLE *hMPQ); +typedef BOOL (WINAPI* funcSFileGetBasePath)(LPCSTR lpBuffer, DWORD dwBufferLength); +typedef BOOL (WINAPI* funcSFileSetBasePath)(LPCSTR lpNewBasePath); + +// Storm Function Names +extern funcSFileCloseArchive SFileCloseArchive; +extern funcSFileCloseFile SFileCloseFile; +extern funcSFileDestroy SFileDestroy; +extern funcSFileGetFileArchive SFileGetFileArchive; +extern funcSFileGetFileSize SFileGetFileSize; +extern funcSFileOpenArchive SFileOpenArchive; +extern funcSFileOpenFile SFileOpenFile; +extern funcSFileOpenFileEx SFileOpenFileEx; +extern funcSFileReadFile SFileReadFile; +extern funcSFileSetBasePath SFileSetBasePath; +extern funcSFileSetFilePointer SFileSetFilePointer; +extern funcSFileSetLocale SFileSetLocale; +extern funcSFileGetBasePath SFileGetBasePath; +extern funcSFileGetArchiveName SFileGetArchiveName; +extern funcSFileGetFileName SFileGetFileName; + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif