-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcfiles.c
executable file
·296 lines (271 loc) · 9.16 KB
/
rcfiles.c
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
287
288
289
290
291
292
293
294
295
296
/***********************************************************
* K O U L E S *
*----------------------------------------------------------*
* C1995 JAHUSOFT *
* Jan Hubicka *
* Dukelskych Bojovniku 1944 *
* 390 03 Tabor *
* Czech Republic *
* Phone: 0041-361-32613 *
* eMail: [email protected] *
*----------------------------------------------------------*
* Copyright(c)1995,1996 by Jan Hubicka.See README for *
* licence details. *
*----------------------------------------------------------*
* rcfiles.c saving and loading of rc files *
***********************************************************/
/* Changes for OS/2 Warp with Dive. *
* Copyright(c)1996 by Thomas A. K. Kjaer *
***********************************************************/
/* Changes for joystick "accelerate by deflection" *
* (c) 1997 by Ludvik Tesar (Ludv\'{\i}k Tesa\v{r}) *
************************LT*********************************/
#include <errno.h>
#include "koules.h"
#include "sound.h"
/* DKS
#ifdef XSUPPORT
static CONST char *name = ".xkoules-controls";
#else
#ifdef OS2DIVE
static CONST char *name = "koules.cfg";
#else
static CONST char *name = ".koules.svga-controls";
#endif
#endif
*/
////DKS
//static CONST char *name = ".koules.gp2x-controls";
//
//#ifdef OS2DIVE
//static CONST char *levelsname = "koules.lev";
//#else
static CONST char *levelsname = ".koules-levels";
//#endif
static char * mygetenv(char *name)
{
static char name1[200];
char *var=getenv(name);
int i=strlen(var);
if(i>199) i=199;
memcpy(name1,var,i+1);
name1[199]=0;
return name1;
}
void
save_rc ()
{
//DKS
printf("Saving rc files..\n");
//DKS
// FILE *controls, *levels;
FILE *levels;
// int zeros[] =
// {0, 0, 0, 0, 0, 0, 0, 0};
//DKS
// char fullname[256];
char fullname[1024];
#ifdef NETSUPPORT
if (client || server)
return;
#endif
//#ifdef OS2DIVE
// sprintf (fullname, "%s", name);
//#else
//DKS
//sprintf (fullname, "%s/%s", mygetenv ("HOME"), name);
//DKS - disable saving controls for now
//sprintf (fullname, "%s", name);
//#endif
// if ((controls = fopen (fullname, "w")) == NULL)
// {
// printf ("could not open save file:%s\n"
// "saving of controls skipped\n", fullname);
// perror ("error");
// return;
// }
// fwrite (keys, 1, sizeof (keys), controls); /*save user defined keys */
//#ifdef MOUSE
// fwrite (&mouseplayer, 1, sizeof (int), controls); /*save mouseplayer */
//#else
// fwrite (zeros, 1, sizeof (int), controls);
//#endif
//#ifdef JOYSTICK
// fwrite (joystickplayer, 1, sizeof (joystickplayer), controls);
//#else
// fwrite (zeros, 2, sizeof (int), controls);
//#endif
// fwrite (rotation, 1, sizeof (rotation), controls);
//#ifdef JOYSTICK
// fwrite (joystickmul, 1, sizeof (joystickmul), controls);
//#else
// fwrite (zeros, 2, sizeof (float), controls);
//#endif
// fclose (controls);
//
////DKS
// sync();
//#ifdef OS2DIVE
// sprintf (fullname, "%s", levelsname);
//#else
//DKS
//DKS bringing this back just for Dingoo/GCW dingux environment as you're only supposed to write to $HOME
// //sprintf (fullname, "%s/%s", mygetenv ("HOME"), levelsname);
// sprintf (fullname, "%s", levelsname);
#ifdef GP2X
sprintf (fullname, "%s", levelsname);
#else
sprintf (fullname, "%s/%s", mygetenv ("HOME"), levelsname);
#endif
if ((levels = fopen (fullname, "w")) == NULL)
{
printf ("could not open save file:%s\n"
"saving of controls skipped\n", fullname);
perror ("error");
return;
}
//DANGER DANGER DANGER
//DKS - holy cow, fwrite is being used here with parameters reversed, gotta fix that (how did this ever work originally!?)
// fwrite (&maxlevel, 1, sizeof (int), levels);
// fwrite (&lastlevel, 1, sizeof (int), levels);
// fwrite (&nrockets, 1, sizeof (int), levels);
// fwrite (&gameplan, 1, sizeof (int), levels);
// fwrite (&difficulty, 1, sizeof (int), levels);
fwrite(&maxlevel, sizeof(int), 1, levels);
fwrite(&lastlevel, sizeof(int), 1, levels);
fwrite(&nrockets, sizeof(int), 1, levels);
fwrite(&gameplan, sizeof(int), 1, levels);
fwrite(&difficulty, sizeof(int), 1, levels);
fwrite(&music_enabled, sizeof(int), 1, levels);
fwrite(&analog_enabled, sizeof(int), 1, levels);
fwrite(&gsensor_enabled, sizeof(int), 1, levels);
fwrite(&rumble_enabled, sizeof(int), 1, levels);
int dummy_int=0; // we will add 8 more ints to be written, intended as place-holders for possible future options
//8 dummy values:
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fwrite(&dummy_int, sizeof(int), 1, levels);
fclose (levels);
//DKS
sync();
}
void
load_rc ()
{
//DKS
// FILE *controls, *levels;
// int dummy[8];
FILE *levels;
//DKS
// char fullname[256];
char fullname[1024];
#ifdef NETSUPPORT
if (client || server)
return;
#endif
//DKS - disable saving/loading controls
//#ifdef OS2DIVE
// sprintf (fullname, "%s", name);
//#else
// //DKS
// //sprintf (fullname, "%s/%s", mygetenv ("HOME"), name);
// sprintf (fullname, "%s", name);
//#endif
// if ((controls = fopen (fullname, "r")) == NULL)
// {
// if (errno != ENOENT) {
// perror ("error");
// printf ("could not open save file:%s\n"
// "using default values\n", fullname);
// }
// goto skip;
// }
// fread (keys, 1, sizeof (keys), controls); /*save user defined keys */
//#ifdef MOUSE
// if(!fread (&mouseplayer, 1, sizeof (int), controls)) mouseplayer=-1; /*save mouseplayer */
//#else
// fread (dummy, 1, sizeof (int), controls);
//#endif
//#ifdef JOYSTICK
// if(!fread (joystickplayer, 1, sizeof (joystickplayer), controls)) joystickplayer[0]=joystickplayer[1]=-1;
//#else
// fread (dummy, 2, sizeof (int), controls);
//#endif
// fread (rotation, 1, sizeof (rotation), controls);
//#ifdef JOYSTICK
// fread (joystickmul, 1, sizeof (joystickmul), controls);
//#else
// fread (dummy, 2, sizeof (float), controls);
//#endif
// fclose (controls);
//skip:;
//DKS
//#ifdef OS2DIVE
// sprintf (fullname, "%s", levelsname);
//#else
//DKS
//DKS bringing this back just for Dingoo/GCW dingux environment as you're only supposed to write to $HOME
// //sprintf (fullname, "%s/%s", mygetenv ("HOME"), levelsname);
// sprintf (fullname, "%s", levelsname);
#ifdef GP2X
sprintf (fullname, "%s", levelsname);
#else
sprintf (fullname, "%s/%s", mygetenv ("HOME"), levelsname);
#endif
if ((levels = fopen (fullname, "r")) == NULL)
{
if (errno != ENOENT) {
printf ("could not open save file:%s\n"
"using default values\n", fullname);
perror ("error");
}
return;
}
//DANGER DANGER DANGER
//DKS - holy cow, fread is being used here with parameters reversed, gotta fix that (how did this ever work originally!?)
//DKS - Not only that, but it misinterprets the return result of fread()! Unbelievable..
// fread (&maxlevel, 1, sizeof (int), levels);
// fread (&lastlevel, 1, sizeof (int), levels);
//
// if(maxlevel>=100||maxlevel<0) maxlevel=0;
// if(lastlevel>maxlevel||lastlevel<0) lastlevel=0;
//
// fread (&nrockets, 1, sizeof (int), levels);
// if(nrockets<1) nrockets=1;
// if(nrockets>4) nrockets=1;
// if (fread (&gameplan, 1, sizeof (int), levels) != sizeof (int))
// gameplan = COOPERATIVE;
// if(gameplan<0||gameplan>1) gameplan=COOPERATIVE;
// if (fread (&difficulty, 1, sizeof (int), levels) != sizeof (int))
// difficulty = 2;
fread (&maxlevel, sizeof (int), 1, levels);
fread (&lastlevel, sizeof (int), 1, levels);
if(maxlevel>=100||maxlevel<0) maxlevel=0;
if(lastlevel>maxlevel||lastlevel<0) lastlevel=0;
fread (&nrockets, sizeof (int), 1, levels);
if(nrockets<1) nrockets=1;
if(nrockets>4) nrockets=1;
if (fread (&gameplan, sizeof (int), 1, levels) != 1)
gameplan = COOPERATIVE;
if(gameplan<0||gameplan>1) gameplan=COOPERATIVE;
if (fread (&difficulty, sizeof (int), 1, levels) != 1)
//DKS - default difficulty changed to 1 (hard) , not medium (too slow & easy)
// difficulty = 2;
difficulty = 1;
if(difficulty<0||difficulty>4) difficulty=2;
if (fread (&music_enabled, sizeof (int), 1, levels) != 1)
music_enabled = 1;
if (fread (&analog_enabled, sizeof (int), 1, levels) != 1)
analog_enabled = 0;
if (fread (&gsensor_enabled, sizeof (int), 1, levels) != 1)
gsensor_enabled = 0;
// fwrite(&music_enabled, sizeof(int), 1, levels);
// fwrite(&analog_enabled, sizeof(int), 1, levels);
// fwrite(&rumble_enabled, sizeof(int), 1, levels);
fclose (levels);
}