Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




1 // drawgrp.cpp : Defines the entry point for the console application.\r
2 //\r
3 \r
4 #define _CRT_RAND_S\r
5 #include <stdlib.h>\r
6 #include <stdio.h>\r
7 #include "stdafx.h"\r
8 \r
9 \r
10 /*int qmain(int argc, char* argv[]);\r
11 \r
12 int main(int argc, char* argv[])\r
13 {\r
14         HINSTANCE hStorm = LoadStorm("Storm.dll");\r
15         if (SFileDestroy!=0) SFileDestroy();\r
16         LoadGrpApi();\r
17         int RetVal = qmain(argc,argv);\r
18         FreeGrpApi();\r
19         if (hStorm!=0) FreeLibrary(hStorm);\r
20         return RetVal;\r
21 }*/\r
22 \r
23 struct BufferInfo {\r
24         WORD nWidth;\r
25         WORD nHeight;\r
26         signed short *pBuffer;\r
27         WORD nFrame;\r
28 };\r
29 \r
30 COLORREF WINAPI ReadPixelFromBuffer(BufferInfo *pBI, int X, int Y)\r
31 {\r
32         if (pBI->nFrame == 0xFFFF)\r
33                 return pBI->pBuffer[(Y * pBI->nWidth) + X];\r
34         else\r
35                 return pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X];\r
36 }\r
37 \r
38 void WINAPI WritePixelToBuffer(BufferInfo *pBI, int X, int Y, COLORREF clrColor)\r
39 {\r
40         if (pBI->nFrame == 0xFFFF)\r
41                 pBI->pBuffer[(Y * pBI->nWidth) + X] = (signed short)clrColor;\r
42         else\r
43                 //if (clrColor < 1 || clrColor > 13)\r
44                 //      pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)((BYTE)-clrColor);\r
45                 //else\r
46                         pBI->pBuffer[(pBI->nFrame * pBI->nWidth * pBI->nHeight) + (Y * pBI->nWidth) + X] = (signed short)clrColor;\r
47 }\r
48 \r
49 int main(int argc, char* argv[])\r
50 {\r
51         HANDLE hMPQ=0,hMPQ2=0,hMPQ3=0;\r
52         DWORD *dwPalette = (DWORD *)_alloca(1024);\r
53         memset(dwPalette,0,1024);\r
54         LoadStorm("SFMpq.dll");\r
55         SetMpqDll("SFMpq.dll");\r
56         if (SFileOpenArchive!=0) {\r
57                 char *buffer = (char *)_alloca(13);\r
58                 memcpy(buffer,"StarDat.mpq",12);\r
59                 if (SFileOpenArchive(buffer,1000,0,&hMPQ)==0) return 0;\r
60                 memcpy(buffer,"BrooDat.mpq",12);\r
61                 SFileOpenArchive(buffer,2000,0,&hMPQ2);\r
62                 memcpy(buffer,"Patch_rt.mpq",13);\r
63                 SFileOpenArchive(buffer,3000,0,&hMPQ3);\r
64         }\r
65         BufferInfo BI;\r
66         LoadPalette("tileset\\Jungle.wpe",dwPalette);\r
67         HANDLE hGrp, hGrp2;\r
68         if (argc>1)\r
69                 hGrp = LoadGrp(argv[1]);\r
70         else\r
71                 hGrp = LoadGrp("unit\\zerg\\ultra.grp");\r
72         HDC hDC = GetDC(0);\r
73         GRPHEADER GrpInfo;\r
74         if (GetGrpInfo(hGrp,&GrpInfo)==0) {GrpInfo.nFrames=0;GrpInfo.wMaxWidth=0;GrpInfo.wMaxHeight=0;}\r
75         BI.nWidth = GrpInfo.wMaxWidth;\r
76         BI.nHeight = GrpInfo.wMaxHeight;\r
77         BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r
78         WORD i,x,y;\r
79         DWORD j, nGrpSize;\r
80         unsigned int u,v;\r
81         memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r
82         //for (DWORD j=0;j<16;j++){\r
83         /*for (WORD i=0;i<GrpInfo.nFrames;i++) {\r
84                 DrawGrp(hGrp,hDC,0,0,i,dwPalette,ALPHA_BLEND,0x401020);\r
85         }*/\r
86         signed short clrPixel;\r
87         RECT rect;\r
88         for (i=0;i<GrpInfo.nFrames;i++) {\r
89                 for (j=0;j<8;j++)\r
90                 {\r
91                         rand_s(&u);\r
92                         rand_s(&v);\r
93                         u = u % 800;\r
94                         v = v % 600;\r
95                         //DrawGrp(hGrp,hDC,u,v,i,dwPalette,ALPHA_BLEND,0x404040);\r
96                 }\r
97         }\r
98         SetFunctionGetPixel((GETPIXELPROC)ReadPixelFromBuffer);\r
99         SetFunctionSetPixel((SETPIXELPROC)WritePixelToBuffer);\r
100         for (i=0;i<GrpInfo.nFrames;i++) {\r
101                 BI.nFrame = i;\r
102                 for (y = 0; y < BI.nHeight; y++) {\r
103                         for (x = 0; x < BI.nWidth; x++) {\r
104                                 WritePixelToBuffer(&BI, x, y, -1);\r
105                         }\r
106                 }\r
107                 DrawGrp(hGrp,(HDC)&BI,0,0,i,0,USE_INDEX,0);\r
108         }\r
109         hGrp2 = hGrp;\r
110         hGrp = CreateGrp(BI.pBuffer, GrpInfo.nFrames, GrpInfo.wMaxWidth, GrpInfo.wMaxHeight, FALSE, &nGrpSize);\r
111         /*HANDLE hFile;\r
112         hFile = CreateFile("generated ultralisk.grp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);\r
113         if (hFile != INVALID_HANDLE_VALUE) {\r
114                 WriteFile(hFile, hGrp, nGrpSize, &j, 0);\r
115                 CloseHandle(hFile);\r
116         }*/\r
117         BI.nFrame = 0xFFFF;\r
118         j=0;\r
119         for (i=0;i<GrpInfo.nFrames;i+=1) {\r
120                 rect.left = rect.top = 0;\r
121                 rect.right = rect.left + BI.nWidth;\r
122                 rect.bottom = rect.top + BI.nHeight;\r
123                 for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r
124                         BI.pBuffer[x] = -1;\r
125                 //for (j=0;j<(1 * 1);j++) {\r
126 //                      DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020);\r
127                         //DrawGrp(hGrp2,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020);\r
128                         //u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r
129                         DrawGrp(hGrp,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020);\r
130                         u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r
131                         for (x = 0; x < BI.nWidth; x++)\r
132                                 for (y = 0; y < BI.nHeight; y++) {\r
133                                         clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
134                                         if (clrPixel != -1) SetPixelV(hDC, x, y, dwPalette[clrPixel]);\r
135                                 }\r
136                 //}\r
137                 if (u) {\r
138                         printf("Output of re-encoded graphic for frame %d does not match original!  Total %d\n", i, ++j);\r
139                         //break;\r
140                 }\r
141                 FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
142         }\r
143         for (i=4;i<400;i+=17) {\r
144                 rect.left = rect.top = 400-i;\r
145                 rect.right = rect.left + BI.nWidth;\r
146                 rect.bottom = rect.top + BI.nHeight;\r
147                 for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r
148                         BI.pBuffer[x] = -1;\r
149                 for (j=0;j<32;j++) {\r
150 //                      DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020);\r
151                         DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),0,HORIZONTAL_FLIP|USE_INDEX,0x401020);\r
152                         for (x = 0; x < BI.nWidth; x++)\r
153                                 for (y = 0; y < BI.nHeight; y++) {\r
154                                         clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r
155                                         if (clrPixel != -1) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]);\r
156                                 }\r
157                 }\r
158                 FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r
159         }\r
160         for (i = 0; i < BI.nWidth; i++)\r
161                 for (j = 0; j < BI.nHeight; j++) {\r
162                         clrPixel = BI.pBuffer[(j * BI.nWidth) + i];\r
163                         if (clrPixel != -1) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]);\r
164                 }\r
165         //}\r
166         ReleaseDC(0,hDC);\r
167         free(BI.pBuffer);\r
168     DestroyGrp(hGrp);\r
169     DestroyGrp(hGrp2);\r
170         if (SFileCloseArchive!=0) {\r
171                 if (hMPQ3!=0) SFileCloseArchive(hMPQ3);\r
172                 if (hMPQ2!=0) SFileCloseArchive(hMPQ2);\r
173                 if (hMPQ!=0) SFileCloseArchive(hMPQ);\r
174         }\r
175         return 0;\r
176 }\r
177 \r