2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
24 #include "Utils/Folders.h"
28 void DefaultSettings()
32 usermousesensitivity = 1;
33 newscreenwidth = kContextWidth = 1024;
34 newscreenheight = kContextHeight = 768;
57 crouchkey = SDL_SCANCODE_LSHIFT;
58 jumpkey = SDL_SCANCODE_SPACE;
59 leftkey = SDL_SCANCODE_A;
60 forwardkey = SDL_SCANCODE_W;
61 backkey = SDL_SCANCODE_S;
62 rightkey = SDL_SCANCODE_D;
63 drawkey = SDL_SCANCODE_E;
64 throwkey = SDL_SCANCODE_Q;
65 attackkey = MOUSEBUTTON1;
66 consolekey = SDL_SCANCODE_GRAVE;
75 if (newscreenwidth > 3000)
76 newscreenwidth = screenwidth;
77 if (newscreenwidth < 0)
78 newscreenwidth = screenwidth;
79 if (newscreenheight > 3000)
80 newscreenheight = screenheight;
81 if (newscreenheight < 0)
82 newscreenheight = screenheight;
83 ofstream opstream(Folders::getConfigFilePath());
84 opstream << "Screenwidth:\n";
85 opstream << newscreenwidth;
86 opstream << "\nScreenheight:\n";
87 opstream << newscreenheight;
88 opstream << "\nFullscreen:\n";
89 opstream << fullscreen;
90 opstream << "\nMouse sensitivity:\n";
91 opstream << usermousesensitivity;
92 opstream << "\nBlur(0,1):\n";
93 opstream << ismotionblur;
94 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
95 opstream << newdetail;
96 opstream << "\nFloating jump:\n";
97 opstream << floatjump;
98 opstream << "\nMouse jump:\n";
99 opstream << mousejump;
100 opstream << "\nAmbient sound:\n";
101 opstream << ambientsound;
102 opstream << "\nBlood (0,1,2):\n";
103 opstream << bloodtoggle;
104 opstream << "\nAuto slomo:\n";
105 opstream << autoslomo;
106 opstream << "\nFoliage:\n";
108 opstream << "\nMusic:\n";
109 opstream << musictoggle;
110 opstream << "\nTrilinear:\n";
111 opstream << trilinear;
112 opstream << "\nDecals(shadows,blood puddles,etc):\n";
114 opstream << "\nInvert mouse:\n";
115 opstream << invertmouse;
116 opstream << "\nGamespeed:\n";
117 if (oldgamespeed == 0)
119 opstream << oldgamespeed;
120 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
121 opstream << difficulty;
122 opstream << "\nDamage effects(blackout, doublevision):\n";
123 opstream << damageeffects;
124 opstream << "\nText:\n";
125 opstream << texttoggle;
126 opstream << "\nDebug:\n";
127 opstream << debugmode;
128 opstream << "\nShow Points:\n";
129 opstream << showpoints;
130 opstream << "\nAlways Blur:\n";
131 opstream << alwaysblur;
132 opstream << "\nImmediate mode (turn on on G5):\n";
133 opstream << immediate;
134 opstream << "\nVelocity blur:\n";
135 opstream << velocityblur;
136 opstream << "\nVolume:\n";
138 opstream << "\nForward key:\n";
139 opstream << forwardkey;
140 opstream << "\nBack key:\n";
142 opstream << "\nLeft key:\n";
144 opstream << "\nRight key:\n";
145 opstream << rightkey;
146 opstream << "\nJump key:\n";
148 opstream << "\nCrouch key:\n";
149 opstream << crouchkey;
150 opstream << "\nDraw key:\n";
152 opstream << "\nThrow key:\n";
153 opstream << throwkey;
154 opstream << "\nAttack key:\n";
155 opstream << attackkey;
156 opstream << "\nConsole key:\n";
157 opstream << consolekey;
158 opstream << "\nDamage bar:\n";
159 opstream << showdamagebar;
160 opstream << "\nStereoMode:\n";
161 opstream << stereomode;
162 opstream << "\nStereoSeparation:\n";
163 opstream << stereoseparation;
164 opstream << "\nStereoReverse:\n";
165 opstream << stereoreverse;
171 ifstream ipstream(Folders::getConfigFilePath(), std::ios::in);
172 if ( !ipstream || ipstream.fail() ) {
173 printf("Config file not found\n");
179 printf("Loading config\n");
180 while (!ipstream.eof()) {
181 ipstream.getline( setting, sizeof(setting) );
184 // assume lines starting with spaces are all blank
185 if ( strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t')
187 //~ printf("setting : %s\n",setting);
189 if ( ipstream.eof() || ipstream.fail() ) {
190 fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);
196 if ( !strncmp(setting, "Screenwidth", 11) ) {
197 ipstream >> kContextWidth;
198 } else if ( !strncmp(setting, "Screenheight", 12) ) {
199 ipstream >> kContextHeight;
200 } else if ( !strncmp(setting, "Fullscreen", 10) ) {
201 ipstream >> fullscreen;
202 } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) {
203 ipstream >> usermousesensitivity;
204 } else if ( !strncmp(setting, "Blur", 4) ) {
205 ipstream >> ismotionblur;
206 } else if ( !strncmp(setting, "Overall Detail", 14) ) {
208 } else if ( !strncmp(setting, "Floating jump", 13) ) {
209 ipstream >> floatjump;
210 } else if ( !strncmp(setting, "Mouse jump", 10) ) {
211 ipstream >> mousejump;
212 } else if ( !strncmp(setting, "Ambient sound", 13) ) {
213 ipstream >> ambientsound;
214 } else if ( !strncmp(setting, "Blood ", 6) ) {
215 ipstream >> bloodtoggle;
216 } else if ( !strncmp(setting, "Auto slomo", 10) ) {
217 ipstream >> autoslomo;
218 } else if ( !strncmp(setting, "Foliage", 7) ) {
220 } else if ( !strncmp(setting, "Music", 5) ) {
221 ipstream >> musictoggle;
222 } else if ( !strncmp(setting, "Trilinear", 9) ) {
223 ipstream >> trilinear;
224 } else if ( !strncmp(setting, "Decals", 6) ) {
226 } else if ( !strncmp(setting, "Invert mouse", 12) ) {
227 ipstream >> invertmouse;
228 } else if ( !strncmp(setting, "Gamespeed", 9) ) {
229 ipstream >> gamespeed;
230 oldgamespeed = gamespeed;
231 if (oldgamespeed == 0) {
235 } else if ( !strncmp(setting, "Difficulty", 10) ) {
236 ipstream >> difficulty;
237 } else if ( !strncmp(setting, "Damage effects", 14) ) {
238 ipstream >> damageeffects;
239 } else if ( !strncmp(setting, "Text", 4) ) {
240 ipstream >> texttoggle;
241 } else if ( !strncmp(setting, "Debug", 5) ) {
242 ipstream >> debugmode;
243 } else if ( !strncmp(setting, "Show Points", 11) ) {
244 ipstream >> showpoints;
245 } else if ( !strncmp(setting, "Always Blur", 11) ) {
246 ipstream >> alwaysblur;
247 } else if ( !strncmp(setting, "Immediate mode ", 15) ) {
248 ipstream >> immediate;
249 } else if ( !strncmp(setting, "Velocity blur", 13) ) {
250 ipstream >> velocityblur;
251 } else if ( !strncmp(setting, "Volume", 6) ) {
253 } else if ( !strncmp(setting, "Forward key", 11) ) {
254 ipstream >> forwardkey;
255 } else if ( !strncmp(setting, "Back key", 8) ) {
257 } else if ( !strncmp(setting, "Left key", 8) ) {
259 } else if ( !strncmp(setting, "Right key", 9) ) {
260 ipstream >> rightkey;
261 } else if ( !strncmp(setting, "Jump key", 8) ) {
263 } else if ( !strncmp(setting, "Crouch key", 10) ) {
264 ipstream >> crouchkey;
265 } else if ( !strncmp(setting, "Draw key", 8) ) {
267 } else if ( !strncmp(setting, "Throw key", 9) ) {
268 ipstream >> throwkey;
269 } else if ( !strncmp(setting, "Attack key", 10) ) {
270 ipstream >> attackkey;
271 } else if ( !strncmp(setting, "Console key", 11) ) {
272 ipstream >> consolekey;
273 } else if ( !strncmp(setting, "Damage bar", 10) ) {
274 ipstream >> showdamagebar;
275 } else if ( !strncmp(setting, "StereoMode", 10) ) {
278 stereomode = (StereoMode)i;
279 } else if ( !strncmp(setting, "StereoSeparation", 16) ) {
280 ipstream >> stereoseparation;
281 } else if ( !strncmp(setting, "StereoReverse", 13) ) {
282 ipstream >> stereoreverse;
285 fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string);
288 if ( ipstream.fail() ) {
289 fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting);
294 if ( ipstream.bad() ) {
295 fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting);
309 if (screenheight < 0)