Commit | Line | Data |
14362b19 |
1 | // drawgrp.cpp : Defines the entry point for the console application.\r |
2 | //\r |
3 | \r |
c483a082 |
4 | #define _CRT_RAND_S\r |
5 | #include <stdlib.h>\r |
0df81049 |
6 | #include <stdio.h>\r |
14362b19 |
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 |
7f7b4247 |
23 | struct BufferInfo {\r |
24 | WORD nWidth;\r |
25 | WORD nHeight;\r |
c483a082 |
26 | signed short *pBuffer;\r |
27 | WORD nFrame;\r |
7f7b4247 |
28 | };\r |
29 | \r |
30 | COLORREF WINAPI ReadPixelFromBuffer(BufferInfo *pBI, int X, int Y)\r |
31 | {\r |
c483a082 |
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 |
7f7b4247 |
36 | }\r |
37 | \r |
38 | void WINAPI WritePixelToBuffer(BufferInfo *pBI, int X, int Y, COLORREF clrColor)\r |
39 | {\r |
c483a082 |
40 | if (pBI->nFrame == 0xFFFF)\r |
41 | pBI->pBuffer[(Y * pBI->nWidth) + X] = (signed short)clrColor;\r |
42 | else\r |
f497a473 |
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 |
7f7b4247 |
47 | }\r |
48 | \r |
14362b19 |
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 |
7f7b4247 |
54 | LoadStorm("SFMpq.dll");\r |
55 | SetMpqDll("SFMpq.dll");\r |
14362b19 |
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 |
7f7b4247 |
65 | BufferInfo BI;\r |
8e36282a |
66 | LoadPalette("tileset\\Platform.wpe",dwPalette);\r |
c483a082 |
67 | HANDLE hGrp, hGrp2;\r |
14362b19 |
68 | if (argc>1)\r |
69 | hGrp = LoadGrp(argv[1]);\r |
70 | else\r |
20bc40c8 |
71 | hGrp = LoadGrp("unit\\zerg\\zergling.grp");\r |
14362b19 |
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 |
7f7b4247 |
75 | BI.nWidth = GrpInfo.wMaxWidth;\r |
76 | BI.nHeight = GrpInfo.wMaxHeight;\r |
8e36282a |
77 | //BI.nWidth = 255;\r |
78 | //BI.nHeight = 255;\r |
c483a082 |
79 | BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r |
7f7b4247 |
80 | WORD i,x,y;\r |
c483a082 |
81 | DWORD j, nGrpSize;\r |
82 | unsigned int u,v;\r |
83 | memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short));\r |
14362b19 |
84 | //for (DWORD j=0;j<16;j++){\r |
85 | /*for (WORD i=0;i<GrpInfo.nFrames;i++) {\r |
86 | DrawGrp(hGrp,hDC,0,0,i,dwPalette,ALPHA_BLEND,0x401020);\r |
87 | }*/\r |
c483a082 |
88 | signed short clrPixel;\r |
7f7b4247 |
89 | RECT rect;\r |
c483a082 |
90 | for (i=0;i<GrpInfo.nFrames;i++) {\r |
20bc40c8 |
91 | for (j=0;j<16;j++)\r |
c483a082 |
92 | {\r |
93 | rand_s(&u);\r |
94 | rand_s(&v);\r |
95 | u = u % 800;\r |
96 | v = v % 600;\r |
8e36282a |
97 | DrawGrp(hGrp,hDC,u,v,i,dwPalette,ALPHA_BLEND,0x404040);\r |
c483a082 |
98 | }\r |
99 | }\r |
100 | SetFunctionGetPixel((GETPIXELPROC)ReadPixelFromBuffer);\r |
101 | SetFunctionSetPixel((SETPIXELPROC)WritePixelToBuffer);\r |
102 | for (i=0;i<GrpInfo.nFrames;i++) {\r |
103 | BI.nFrame = i;\r |
8e36282a |
104 | u = (BI.nWidth - GrpInfo.wMaxWidth) / 2;\r |
105 | v = (BI.nHeight - GrpInfo.wMaxHeight) / 2;\r |
58a8b78c |
106 | for (y = 0; y < BI.nHeight; y++) {\r |
107 | for (x = 0; x < BI.nWidth; x++) {\r |
20bc40c8 |
108 | WritePixelToBuffer(&BI, x, y, -1);\r |
58a8b78c |
109 | }\r |
110 | }\r |
8e36282a |
111 | DrawGrp(hGrp,(HDC)&BI,u,v,i,0,USE_INDEX,0);\r |
c483a082 |
112 | }\r |
113 | hGrp2 = hGrp;\r |
8e36282a |
114 | hGrp = CreateGrp(BI.pBuffer, GrpInfo.nFrames, BI.nWidth, BI.nHeight, FALSE, &nGrpSize);\r |
0df81049 |
115 | /*HANDLE hFile;\r |
8e36282a |
116 | hFile = CreateFile("generated zergling.grp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);\r |
0df81049 |
117 | if (hFile != INVALID_HANDLE_VALUE) {\r |
118 | WriteFile(hFile, hGrp, nGrpSize, &j, 0);\r |
119 | CloseHandle(hFile);\r |
120 | }*/\r |
c483a082 |
121 | BI.nFrame = 0xFFFF;\r |
0df81049 |
122 | j=0;\r |
8e36282a |
123 | \r |
0df81049 |
124 | for (i=0;i<GrpInfo.nFrames;i+=1) {\r |
125 | rect.left = rect.top = 0;\r |
7f7b4247 |
126 | rect.right = rect.left + BI.nWidth;\r |
127 | rect.bottom = rect.top + BI.nHeight;\r |
128 | for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r |
c483a082 |
129 | BI.pBuffer[x] = -1;\r |
0df81049 |
130 | //for (j=0;j<(1 * 1);j++) {\r |
7f7b4247 |
131 | // DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020);\r |
0df81049 |
132 | //DrawGrp(hGrp2,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020);\r |
133 | //u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r |
134 | DrawGrp(hGrp,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020);\r |
135 | u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short));\r |
7f7b4247 |
136 | for (x = 0; x < BI.nWidth; x++)\r |
137 | for (y = 0; y < BI.nHeight; y++) {\r |
138 | clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r |
0df81049 |
139 | if (clrPixel != -1) SetPixelV(hDC, x, y, dwPalette[clrPixel]);\r |
7f7b4247 |
140 | }\r |
0df81049 |
141 | //}\r |
c483a082 |
142 | if (u) {\r |
0df81049 |
143 | printf("Output of re-encoded graphic for frame %d does not match original! Total %d\n", i, ++j);\r |
144 | //break;\r |
c483a082 |
145 | }\r |
7f7b4247 |
146 | FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r |
14362b19 |
147 | }\r |
ca356bb1 |
148 | for (i=4;i<400;i+=17) {\r |
7f7b4247 |
149 | rect.left = rect.top = 400-i;\r |
150 | rect.right = rect.left + BI.nWidth;\r |
151 | rect.bottom = rect.top + BI.nHeight;\r |
152 | for (x = 0; x < BI.nWidth * BI.nHeight; x++)\r |
c483a082 |
153 | BI.pBuffer[x] = -1;\r |
7f7b4247 |
154 | for (j=0;j<32;j++) {\r |
155 | // DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020);\r |
c483a082 |
156 | DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),0,HORIZONTAL_FLIP|USE_INDEX,0x401020);\r |
7f7b4247 |
157 | for (x = 0; x < BI.nWidth; x++)\r |
158 | for (y = 0; y < BI.nHeight; y++) {\r |
159 | clrPixel = BI.pBuffer[(y * BI.nWidth) + x];\r |
c483a082 |
160 | if (clrPixel != -1) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]);\r |
7f7b4247 |
161 | }\r |
162 | }\r |
163 | FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1));\r |
14362b19 |
164 | }\r |
7f7b4247 |
165 | for (i = 0; i < BI.nWidth; i++)\r |
166 | for (j = 0; j < BI.nHeight; j++) {\r |
167 | clrPixel = BI.pBuffer[(j * BI.nWidth) + i];\r |
c483a082 |
168 | if (clrPixel != -1) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]);\r |
7f7b4247 |
169 | }\r |
14362b19 |
170 | //}\r |
8e36282a |
171 | \r |
14362b19 |
172 | ReleaseDC(0,hDC);\r |
7f7b4247 |
173 | free(BI.pBuffer);\r |
14362b19 |
174 | DestroyGrp(hGrp);\r |
c483a082 |
175 | DestroyGrp(hGrp2);\r |
14362b19 |
176 | if (SFileCloseArchive!=0) {\r |
177 | if (hMPQ3!=0) SFileCloseArchive(hMPQ3);\r |
178 | if (hMPQ2!=0) SFileCloseArchive(hMPQ2);\r |
179 | if (hMPQ!=0) SFileCloseArchive(hMPQ);\r |
180 | }\r |
181 | return 0;\r |
182 | }\r |
183 | \r |