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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
diff -Naur keen.orig/src/Makefile.lnx keen/src/Makefile.lnx
--- keen.orig/src/Makefile.lnx 2005-11-09 22:27:50.000000000 -0500
+++ keen/src/Makefile.lnx 2010-03-26 03:06:24.000000000 -0400
@@ -31,6 +31,7 @@
sdl/keydrv.o sdl/snddrv.o sdl/timedrv.o sdl/viddrv.o \
scale2x/scalebit.o scale2x/scale2x.o scale2x/scale3x.o \
scale2x/pixel.o \
+ unix_fopen_wrapper.o \
keen.h keenext.h sounds.h funcdefs.h latch.h game.h
gcc -g3 -o keen \
main.o fileio.o \
@@ -51,6 +52,7 @@
sdl/keydrv.o sdl/snddrv.o sdl/timedrv.o sdl/viddrv.o \
scale2x/scalebit.o scale2x/scale2x.o scale2x/scale3x.o \
scale2x/pixel.o \
+ unix_fopen_wrapper.o \
`sdl-config --libs`
diff -Naur keen.orig/src/keen.h keen/src/keen.h
--- keen.orig/src/keen.h 2005-11-07 16:39:12.000000000 -0500
+++ keen/src/keen.h 2010-03-26 03:06:24.000000000 -0400
@@ -14,6 +14,10 @@
#include <windows.h>
#endif
+#ifdef TARGET_LNX
+ #include "unix_fopen_wrapper.h"
+#endif
+
#include "sounds.h"
#include "funcdefs.h"
#include "latch.h"
diff -Naur keen.orig/src/main.c keen/src/main.c
--- keen.orig/src/main.c 2005-11-09 23:35:10.000000000 -0500
+++ keen/src/main.c 2010-03-26 03:11:56.000000000 -0400
@@ -75,7 +75,7 @@
char loadinggame, loadslot;
-FILE *log=NULL;
+/* FILE *log=NULL; */
stFade fade;
stMap map;
@@ -161,7 +161,7 @@
SetDefaultOptions();
setoption(OPT_FULLSCREEN, "SDL Fullscreen Mode", 0);
setoption(OPT_ZOOM, "Image Zoom", 1);
- setoption(OPT_FRAMESKIP, "Frameskip", 2);
+ setoption(OPT_FRAMESKIP, "Frameskip", 1);
/* process command line options */
VidDrv_printf("Processing command-line options.\n");
@@ -180,6 +180,7 @@
{
numplayers = 2;
}
+ /*
else if (strcmp(tempbuf, "-3player")==0)
{
numplayers = 3;
@@ -188,6 +189,7 @@
{
numplayers = 4;
}
+ */
else if (strcmp(tempbuf, "-single")==0)
{
numplayers = 1;
@@ -240,6 +242,7 @@
{
showfps = 1;
}
+ /*
else if (strcmp(tempbuf, "-host")==0) // start network server
{
is_server = 1;
@@ -250,6 +253,7 @@
is_client = 1;
localmp = 0;
}
+ */
else if (i!=1 || atoi(argv[i])==0)
{
VidDrv_printf("Wait a minute...what the hell does '%s' mean?\n",tempbuf);
diff -Naur keen.orig/src/misc.c keen/src/misc.c
--- keen.orig/src/misc.c 2005-11-16 20:04:28.000000000 -0500
+++ keen/src/misc.c 2010-03-26 03:15:46.000000000 -0400
@@ -1103,7 +1103,7 @@
{
VidDrv_printf("Usage: keen [lvlnum] [-*player] [-nopk] [-ep*] [-dtm] [-nocheat] [-rec] -[eseq]\n\n");
VidDrv_printf("lvlnum specify a level number (such as 2) to go directly to that level\n");
- VidDrv_printf("-*player select number of players (1-4); defaults to 1\n");
+ VidDrv_printf("-*player select number of players (1-2); defaults to 1\n");
VidDrv_printf("-nopk do not allow players to kill each other in multiplayer games\n");
VidDrv_printf("-ep* select episode 1, 2, or 3; defaults to 1\n");
VidDrv_printf("-dtm go directly to the world map, bypassing intro and title screen\n");
diff -Naur keen.orig/src/sdl/viddrv.c keen/src/sdl/viddrv.c
--- keen.orig/src/sdl/viddrv.c 2005-11-16 20:08:30.000000000 -0500
+++ keen/src/sdl/viddrv.c 2010-03-26 03:06:24.000000000 -0400
@@ -29,8 +29,10 @@
SDL_Rect dstrect;
+#ifndef TARGET_LNX
extern FILE *log;
#define CKLOGFILENAME "ck.log"
+#endif
#define MAX_CONSOLE_MESSAGES 3
#define CONSOLE_MESSAGE_X 3
@@ -222,11 +224,11 @@
// applies all changes to the palette made with pal_set
void pal_apply(void)
{
- SDL_SetColors(screen, &MyPalette, 0, 256);
- SDL_SetColors(ScrollSurface, &MyPalette, 0, 256);
+ SDL_SetColors(screen, MyPalette, 0, 256);
+ SDL_SetColors(ScrollSurface, MyPalette, 0, 256);
if (blitsurface_alloc)
{
- SDL_SetColors(BlitSurface, &MyPalette, 0, 256);
+ SDL_SetColors(BlitSurface, MyPalette, 0, 256);
}
}
@@ -338,9 +340,9 @@
// shuts down the video driver
void VidDrv_Stop(void)
{
- if(screen) { SDL_FreeSurface(screen); VidDrv_printf("freed screen\n"); }
- if(ScrollSurface) { SDL_FreeSurface(ScrollSurface); VidDrv_printf("freed scrollsurface\n"); }
- if(blitsurface_alloc) { blitsurface_alloc = 0; SDL_FreeSurface(BlitSurface); VidDrv_printf("freed blitsurface\n"); }
+ if(screen) { SDL_FreeSurface(screen); screen = NULL; VidDrv_printf("freed screen\n"); }
+ if(ScrollSurface) { SDL_FreeSurface(ScrollSurface); ScrollSurface = NULL; VidDrv_printf("freed scrollsurface\n"); }
+ if(blitsurface_alloc) { blitsurface_alloc = 0; SDL_FreeSurface(BlitSurface); BlitSurface = NULL; VidDrv_printf("freed blitsurface\n"); }
}
// resets graphics to allow changing of resolution or zoom settings
@@ -365,10 +367,12 @@
// SDL-specific, not win32-specific)
void VidDrv_InitConsole(void)
{
+#ifndef TARGET_LNX
FILE *fp;
// erase contents of log file
fp = fopen(CKLOGFILENAME, "wb");
fclose(fp);
+#endif
}
void VidDrv_printf(const char *str, ...)
diff -Naur keen.orig/src/unix_fopen_wrapper.c keen/src/unix_fopen_wrapper.c
--- keen.orig/src/unix_fopen_wrapper.c 1969-12-31 19:00:00.000000000 -0500
+++ keen/src/unix_fopen_wrapper.c 2010-03-26 03:06:24.000000000 -0400
@@ -0,0 +1,123 @@
+
+/* semi-case-insensitive fopen() replacement.
+
+Usage:
+
+#include "unix_fopen_wrapper.h"
+FILE *foo = fopen("bar.baz", "rb");
+
+fopen() gets redefined to unix_fopen() in the header file.
+unix_fopen() attempts to call the real fopen() on:
+
+bar.baz
+BAR.baz
+Bar.baz
+bar.BAZ
+BAR.BAZ
+Bar.BAZ
+bar.Baz
+BAR.Baz
+Bar.Baz
+
+It'll still miss e.g. baR.baz or bAr.baz
+
+If there's no . in the filename (e.g. "bar"), just check
+for bar, BAR, Bar
+*/
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <limits.h>
+
+void lcase_all(char *c) {
+ if(!c || !*c) return;
+ while(*c && *c != '.') {
+ *c = tolower(*c);
+ c++;
+ }
+}
+
+void ucase_all(char *c) {
+ if(!c || !*c) return;
+ while(*c && *c != '.') {
+ *c = toupper(*c);
+ c++;
+ }
+}
+
+void ucase_first(char *c) {
+ if(!c || !*c) return;
+ lcase_all(c);
+ c[0] = toupper(c[0]);
+}
+
+FILE *unix_fopen(const char *path, const char *mode) {
+ FILE *result;
+ char realpath[PATH_MAX], *name, *ext;
+
+/* #define DEBUG_FOPEN */
+
+#ifdef DEBUG_FOPEN
+#define TRY_FOPEN(p, m) { \
+ result = fopen(p, m); \
+ fprintf(stderr, "-- %s:%d: (%s,%s): %s\n", \
+ __FILE__, __LINE__, p, m, (result ? "OK" : "fail")); \
+ if(result) return result; \
+}
+#else
+#define TRY_FOPEN(p, m) { if( (result = fopen(p, m)) ) return result; }
+#endif
+
+ /* try it as-is first */
+ TRY_FOPEN(path, mode);
+
+ /* parse into name and (possible) extension */
+ strcpy(realpath, path);
+ ext = strrchr(realpath, '.');
+ if(ext) {
+ ++ext;
+ if(!ext[0]) ext = NULL;
+ }
+
+ /* skip any directory component(s) */
+ name = strrchr(realpath, '/');
+ if(!name) name = realpath;
+
+ /* permutations... */
+ lcase_all(ext);
+ lcase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_first(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_all(ext);
+ lcase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_first(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_first(ext);
+ lcase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_all(name);
+ TRY_FOPEN(realpath, mode);
+
+ ucase_first(name);
+ TRY_FOPEN(realpath, mode);
+
+#ifdef DEBUG_FOPEN
+ fprintf(stderr, "%s:%s: TRY_FOPEN(%s,%s): Giving up",
+ __FILE__, __LINE__, path, mode);
+#endif
+ return NULL;
+}
diff -Naur keen.orig/src/unix_fopen_wrapper.h keen/src/unix_fopen_wrapper.h
--- keen.orig/src/unix_fopen_wrapper.h 1969-12-31 19:00:00.000000000 -0500
+++ keen/src/unix_fopen_wrapper.h 2010-03-26 03:06:24.000000000 -0400
@@ -0,0 +1,2 @@
+FILE *unix_fopen(const char *path, const char *mode);
+#define fopen(x,y) unix_fopen(x,y)
|