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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
#include "ini.h"
#include "game.h"
#include "PHL.h"
#include <stdio.h>
#include <string.h>
#include "text.h"
//char* getFileLocation();
char* trimString(char* orig);
void screenLoad(char* first, char* second);
void sizeLoad(char* first, char* second);
void blurLoad(char* first, char* second);
void languageLoad(char* first, char* second);
void autosaveLoad(char* first, char* second);
void musicvolumeLoad(char* first, char* second);
void iniInit()
{
//Build filepath
char fullPath[128];
{
#ifdef _SDL
strcpy(fullPath, getenv("HOME"));
strcat(fullPath, "/.hydracastlelabyrinth/");
#else
strcpy(fullPath, "");
#endif
#ifdef _3DS
strcat(fullPath, "sdmc:/3ds/appdata/HydraCastleLabyrinth/");
#endif
strcat(fullPath, "system.ini");
#ifdef DREAMCAST
strcat(fullPath, "/ram/system.ini");
#endif
}
FILE* f;
if ( (f = fopen(fullPath, "rt")) )
{
//File exists - read it
fclose(f);
loadSettings();
}else{
//File does not exists - create it (with default hardcoded settings)
saveSettings();
}
}
void saveSettings()
{
//Build filepath
char fullPath[128];
{
#ifdef _SDL
strcpy(fullPath, getenv("HOME"));
strcat(fullPath, "/.hydracastlelabyrinth/");
#else
strcpy(fullPath, "");
#endif
#ifdef _3DS
strcat(fullPath, "sdmc:/3ds/appdata/HydraCastleLabyrinth/");
#endif
strcat(fullPath, "system.ini");
#ifdef DREAMCAST
strcat(fullPath, "/ram/system.ini");
#endif
}
FILE* f;
if ( (f = fopen(fullPath, "wt")) )
{
fprintf(f, "[disp]");
#ifdef _3DS
//Screen
fprintf(f, "\r\nscreen=");
if (activeScreen->screen == GFX_BOTTOM) {
fprintf(f, "bottom");
}else{
fprintf(f, "top");
}
#endif
#ifdef _PSP
//Screen Size
fprintf(f, "\r\nsize=");
if (getScreenSize() == 1) {
fprintf(f, "1");
}
else if (getScreenSize() == 2) {
fprintf(f, "2");
}
else {
fprintf(f, "0");
}
//Screen Blur
fprintf(f, "\r\nblur=");
if (getBlur() == 1) {
fprintf(f, "on");
}else{
fprintf(f, "off");
}
#endif
fprintf(f, "\r\n[system]");
//Language
fprintf(f, "\r\nlanguage=");
if (getLanguage() == 0) {
fprintf(f, "jp");
}
if (getLanguage() == 1) {
fprintf(f, "en");
}
//Autosave
fprintf(f, "\r\nautosave=");
if (getAutoSave() == 1) {
fprintf(f, "on");
}else{
fprintf(f, "off");
}
#ifdef _SDL
fprintf(f, "\r\n[audio]");
fprintf(f, "\r\nmusic=%d", music_volume);
// Audio
#endif
fclose(f);
}
}
void loadSettings()
{
//Build filepath
char fullPath[128];
{
#ifdef _SDL
strcpy(fullPath, getenv("HOME"));
strcat(fullPath, "/.hydracastlelabyrinth/");
#else
strcpy(fullPath, "");
#endif
#ifdef _3DS
strcat(fullPath, "sdmc:/3ds/appdata/HydraCastleLabyrinth/");
#endif
strcat(fullPath, "system.ini");
#ifdef DREAMCAST
strcat(fullPath, "/ram/system.ini");
#endif
}
FILE* f;
if ( (f = fopen(fullPath, "rt")) )
{
char line[80];
while ( (fgets(line, 80, f) != NULL) )
{
char* lineptr = line;
lineptr = trimString(lineptr);
if (lineptr != NULL) {
//Ignore category lines
if (lineptr[0] != '[')
{
//Check if it has a = delimiter first
int i;
for (i = 0; i < 80; i++) {
if (line[i] == '=')
{
//Begin line splitting
char* half;
if ( (half = strsep(&lineptr, "=")) != NULL)
{
//first half
char* fhalf = half;
if ( (half = strsep(&lineptr, "=")) != NULL) {
//Second half
char* shalf = half;
//Load options
screenLoad(fhalf, shalf);
sizeLoad(fhalf, shalf);
blurLoad(fhalf, shalf);
languageLoad(fhalf, shalf);
autosaveLoad(fhalf, shalf);
musicvolumeLoad(fhalf, shalf);
}
}
//End
i = 81;
}
}
}
}
}
fclose(f);
}
}
//Build file path
/*
char* getFileLocation()
{
char fullPath[128];
strcpy(fullPath, "");
#ifdef _CIA
strcat(fullPath, "sdmc:/3ds/HydraCastleLabyrinth/");
#endif
strcat(fullPath, "system.ini");
return fullPath;
}
*/
char* trimString(char* orig)
{
char* output = orig;
int i, r = 0;
for (i = 0; i < strlen(orig); i++) {
if (orig[i] != ' ' && orig[i] != '\n' && orig[i] != '\r') {
output[r] = orig[i];
r++;
}
}
orig[r] = 0;
return output;
}
void screenLoad(char* first, char* second)
{
#ifdef _3DS
if (strcmp(first, "screen") == 0) {
if (strcmp(second, "top") == 0) {
swapScreen(GFX_TOP, GFX_LEFT);
}
if (strcmp(second, "bottom") == 0) {
swapScreen(GFX_BOTTOM, GFX_LEFT);
}
}
#endif
}
void sizeLoad(char* first, char* second)
{
#ifdef _PSP
if (strcmp(first, "size") == 0) {
if (second[0] == '0') {
//fprintf(debug, "\nsize is 0");
setScreenSize(0);
}
if (second[0] == '1') {
//fprintf(debug, "\nsize is 1");
setScreenSize(1);
}
if (second[0] == '2') {
//fprintf(debug, "\nsize is 2");
setScreenSize(2);
}
}
#endif
}
void blurLoad(char* first, char* second)
{
#ifdef _PSP
if (strcmp(first, "blur") == 0) {
if (strcmp(second, "on") == 0) {
//fprintf(debug, "\nblur is on");
//oslSetBilinearFilter(1);
setBlur(1);
}
if (strcmp(second, "off") == 0) {
//fprintf(debug, "\nblur is off");
//oslSetBilinearFilter(0);
setBlur(0);
}
}
#endif
}
void languageLoad(char* first, char* second)
{
if (strcmp(first, "language") == 0) {
if (strcmp(second, "en") == 0) {
setLanguage(ENGLISH);
}
if (strcmp(second, "jp") == 0) {
setLanguage(JAPANESE);
}
}
}
void autosaveLoad(char* first, char* second)
{
if (strcmp(first, "autosave") == 0) {
if (strcmp(second, "on") == 0) {
//fprintf(debug, "\nautosave is on");
setAutoSave(1);
}
if (strcmp(second, "off") == 0) {
//fprintf(debug, "\nautosave is off");
setAutoSave(0);
}
}
}
void musicvolumeLoad(char* first, char* second)
{
#ifdef _SDL
if (strcmp(first, "music") == 0) {
if (second[0] >= '0' && second[0] <= '4') {
music_volume = second[0]-'0';
PHL_MusicVolume(0.25f * music_volume);
}
}
#endif
}
|