]> 4ch.mooo.com Git - 16.git/blob - 16/v2/source/UTIL/UNPACK/UNPACK.C
cleaned up the repo from debugging watcom2 ^^
[16.git] / 16 / v2 / source / UTIL / UNPACK / UNPACK.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <stdio.h>\r
18 #include <malloc.h>\r
19 \r
20 #define byte unsigned char\r
21 // ================================= Data ====================================\r
22 \r
23 FILE *pack;\r
24 FILE *src;\r
25 char strbuf[2048],*filebuf;\r
26 int numfiles;\r
27 char headertag[]={ 'V','R','G','P','A','C','K',0 };\r
28 \r
29 struct filestruct\r
30 {\r
31   unsigned char fname[84];            // pathname thingo\r
32   int size;                           // size of the file\r
33   int packofs;                        // where the file can be found in PACK\r
34   int count;                          // internal (engine-runtime) use\r
35   char extractable;                   // can UNPACK .. unpack it?\r
36   char override;                      // should the engine override it w/\r
37                                       // local files?\r
38 };\r
39 \r
40 struct filestruct filetbl[512];\r
41 \r
42 // ================================= Code ====================================\r
43 \r
44 void DecryptHeader()\r
45 { byte lastvalue, precodebyte, *ptr;\r
46 \r
47   ptr=(byte *) filetbl;\r
48   lastvalue=*ptr;\r
49   ptr++;\r
50 \r
51   while (ptr < (byte *) (int) filetbl + (int) 5120)\r
52   {\r
53     precodebyte=*ptr;\r
54     (*ptr)-=lastvalue;\r
55     lastvalue=precodebyte;\r
56     ptr++;\r
57   }\r
58 }\r
59 \r
60 void CheckPackHeader()\r
61 { char a;\r
62 \r
63   fread(strbuf, 1, 7, pack);\r
64   strbuf[8]=0;\r
65   if (strcmp(strbuf,headertag))\r
66   {\r
67     printf("*error* Not a valid VRG packfile. \n");\r
68     exit(-1);\r
69   }\r
70   fread(&a, 1, 1, pack);\r
71   if (a!=1)\r
72   {\r
73     printf("*error* Incorrect VRG packfile version. \n");\r
74     exit(-1);\r
75   }\r
76   fread(&numfiles, 1, 4, pack);\r
77   fread(&filetbl, 100, numfiles, pack);\r
78   DecryptHeader();\r
79 }\r
80 \r
81 void DumpFiles()\r
82 { int i;\r
83 \r
84   printf("UNPACK v.0.1 Copyright (C)1997 BJ Eirich\n");\r
85   for (i=0; i<numfiles; i++)\r
86   {\r
87     filebuf=(char *) malloc(filetbl[i].size);\r
88     fread(filebuf, 1, filetbl[i].size, pack);\r
89     if (filetbl[i].extractable)\r
90     {\r
91       src=fopen(filetbl[i].fname, "wb");\r
92       printf("File: %s \n",filetbl[i].fname);\r
93       fwrite(filebuf, 1, filetbl[i].size, src);\r
94       fclose(src);\r
95     }\r
96     else printf("File: %s unexctractable.\n",filetbl[i].fname);\r
97     free(filebuf);\r
98   }\r
99 }\r
100 \r
101 int main(int argc, char *argv[])\r
102 {\r
103   if (argc<2)\r
104   {\r
105     printf("UNPACK v.0.1 Copyright (C)1997 BJ Eirich \n");\r
106     printf("USAGE: UNPACK <VRG packfile> \n");\r
107     exit(-1);\r
108   }\r
109 \r
110   if (!(pack=fopen(argv[1],"rb")))\r
111   {\r
112     printf("Unable to open file %s. \n",argv[1]);\r
113     exit(-1);\r
114   }\r
115 \r
116   CheckPackHeader();\r
117   DumpFiles();\r
118 \r
119   fclose(pack);\r
120 \r
121   return 0;\r
122 }\r