[go: up one dir, main page]

Menu

[r15]: / engine / move.cpp  Maximize  Restore  History

Download this file

211 lines (176 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// IRE Map Section Mover
//
#include <stdio.h>
#include <string.h>
#include <allegro.h>
#include "core.hpp"
#include "ithelib.h"
#include "cookies.h"
extern "C" void read_WORLD(WORLD *curmap, IFILE *fp);
extern "C" void write_WORLD(WORLD *curmap, IFILE *fp);
extern "C" void read_OBJECT(OBJECT *o, IFILE *fp);
extern "C" void write_OBJECT(OBJECT *o, IFILE *fp);
int GetWadEntry(IFILE *fp,char *name);
char filename1[256];
char filename2[256];
char filename3[256];
char filename4[256];
char sigtemp[40];
char *cfa;
int main(int argc, char *argv[])
{
IFILE *fp,*fp2;
char *ptr;
WORLD curmap,newmap;
int mem,map_H,map_W,temp_int,key,cx,cy,xoff,yoff,total,size;
int maxx,minx,maxy,miny;
//unsigned char vbuf[4096]; // God Forbid
OBJECT o;
printf("IRE Map Section Mover 1.0\n");
printf("=========================\n\n");
if(argc<2)
{
printf("mover <mapfile>\n");
exit(1);
}
strcpy(filename1,argv[1]);
ptr = strrchr(filename1,'.');
if(ptr)
{
if(!stricmp(ptr+1,"map"))
*ptr=0;
printf("Filename base is '%s'\n\n",filename1);
}
printf("Enter the X coord for the top-left corner:\n");
fflush(stdin);
scanf("%d",&minx);
printf("Enter the Y coord for the top-left corner:\n");
fflush(stdin);
scanf("%d",&miny);
printf("Enter the X coord for the bottom-right corner:\n");
fflush(stdin);
scanf("%d",&maxx);
printf("Enter the Y coord for the bottom-right corner:\n");
fflush(stdin);
scanf("%d",&maxy);
printf("\n\nMoving all objects in region %d,%d-%d,%d\n\n",minx,miny,maxx,maxy);
printf("Enter the X offset to apply to all objects (- is left, + is right):\n");
fflush(stdin);
scanf("%d",&xoff);
printf("Enter the Y offset to apply to all objects (- is up, + is down):\n");
scanf("%d",&yoff);
printf("Enter the file to save to (without extension):\n");
scanf("%s",filename3);
strcpy(filename2,filename1);
strcat(filename2,".map");
fp = iopen(filename2);
if(!fp)
{
printf("Could not load file '%s'\n",filename2);
exit(1);
}
iread((unsigned char *)sigtemp,40,fp);
if(strcmp(sigtemp,COOKIE_MAP))
{
printf("Unknown file format in map file '%s'\n",filename2);
exit(1);
}
read_WORLD(&curmap,fp);
if((unsigned)curmap.sig != MAPSIG)
{
printf("Current map version is 0x%x, but this is 0x%x\n",MAPSIG,temp_int);
exit(1);
}
curmap.physmap = (unsigned short *)M_get(curmap.w * curmap.h,sizeof(short));
iread((unsigned char *)curmap.physmap,curmap.w*curmap.h*sizeof(short),fp);
map_W = curmap.w;
map_H = curmap.h;
iclose(fp);
printf("Copying Objects..\n");
strcpy(filename2,filename1);
strcat(filename2,".mz1");
strcpy(filename4,filename3);
strcat(filename4,".mz1");
fp=iopen(filename2);
if(!fp)
{
printf("Can't open file '%s'\n",filename2);
exit(1);
}
fp2=iopen_write(filename4);
if(!fp2)
{
printf("Can't write to file '%s'\n",filename4);
exit(1);
}
for(;!ieof(fp);iputc(igetc(fp),fp2));
printf("Patching copy..\n");
cx=GetWadEntry(fp2,"OBJECTS ");
if(!cx)
printf("Bummer.\n");
else
{
total=igetl_i(fp2);
size=igetl_i(fp2);
for(cx=0;cx<total;cx++)
{
// Get current position
temp_int = itell(fp2);
// Read it
read_OBJECT(&o,fp2);
iread((unsigned char *)sigtemp,32,fp2);
if(o.x <= maxx && o.x >= minx)
if(o.y <= maxy && o.y >= miny)
{
// Patch it
o.x = o.x + xoff;
o.y = o.y + yoff;
if(o.x < 0)
o.x = 65535;
if(o.y < 0)
o.y = 65535;
}
// Back up
iseek(fp2,temp_int,SEEK_SET);
// Rewrite
write_OBJECT(&o,fp2);
iread((unsigned char *)sigtemp,32,fp2); // skip name
}
}
iclose(fp);
iclose(fp2);
printf("All done!\n");
}
END_OF_MAIN();
void ithe_userexitfunction()
{
}
int GetWadEntry(IFILE *ifp, char *name)
{
unsigned int sig,num,off,ctr;
char buf[]="nothing!";
iseek(ifp,40,SEEK_SET);
sig = igetl_i(ifp);
if(sig != 0x44415750)
{
printf("sig = %x\n",sig);
ithe_panic("Incorrect WAD substructure in file",ifp->truename);
}
num = igetl_i(ifp);
off = igetl_i(ifp);
iseek(ifp,off+40,SEEK_SET); // Cancel out the signature
for(ctr=0;ctr<num;ctr++)
{
off = igetl_i(ifp);
igetl_i(ifp); // skip length
iread((unsigned char *)buf,8,ifp);
// ilog_quiet("'%s'%s'\n",buf,name);
if(!strcmp(buf,name))
{
iseek(ifp,off+40,SEEK_SET); // Cancel out the signature
return 1;
}
}
return 0;
}