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




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