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
#![deny(trivial_casts, trivial_numeric_casts,
unsafe_code, unstable_features,
unused_import_braces, unused_qualifications)]
extern crate byteorder;
use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use std::fs::File;
use std::io::{Read, Write, Seek, SeekFrom};
use std::path::Path;
use std::str;
use std::io;
#[derive(Debug)]
pub enum SettingsResult {
Ok,
IoError(io::Error),
NotValidYet
}
pub struct GtaVcSettings {
pub total_sections: u32,
pub controls: [u8; 352],
pub strings: [u8; 51],
pub unknown: u8,
pub mouse_sensitivity: u32,
pub mouse_invert_y: u8,
pub steer_with_mouse: u8,
pub sfx_volume: u8,
pub music_volume: u8,
pub mp3_volume_boost: u8,
pub current_radio: u8,
pub speakers_configuration: u8,
pub audio_hardware: u8,
pub dynamic_acoustic_mode: u8,
pub brightness: u16,
pub draw_distance: f32,
pub subtitles: u8,
pub widescreen: u8,
pub frame_limiter: u8,
pub video_mode: u8,
pub skin_path: [u8; 256],
pub standard_controls: u8,
pub current_language: u8,
pub hud_mode: u8,
pub radar_mode: u8,
pub map_legend: u8,
}
const NOT_VALID_STR: &'static str = "THIS FILE IS NOT VALID YET";
impl GtaVcSettings {
pub fn new() -> GtaVcSettings {
GtaVcSettings {
total_sections: 3,
controls: [0; 352],
strings: [0; 51],
unknown: 0,
mouse_sensitivity: 0,
mouse_invert_y: 1,
steer_with_mouse: 1,
sfx_volume: 49,
music_volume: 49,
mp3_volume_boost: 0,
current_radio: 0,
speakers_configuration: 0,
audio_hardware: 0,
dynamic_acoustic_mode: 0,
brightness: 256,
draw_distance: 1.20,
subtitles: 0,
widescreen: 0,
frame_limiter: 0,
video_mode: 0,
skin_path: [0; 256],
standard_controls: 0,
current_language: 0,
hud_mode: 0,
radar_mode: 0,
map_legend: 0
}
}
pub fn read<P: AsRef<Path>>(&mut self, path: P) -> SettingsResult {
let mut file = match File::open(path) {
Ok(mut file) => {
let mut buffer = [0; 29];
file.read(&mut buffer).unwrap();
let bufstr = str::from_utf8(&buffer);
let is_not_valid = bufstr == Ok(NOT_VALID_STR);
if is_not_valid {
return SettingsResult::NotValidYet
}
file
},
Err(err) => return SettingsResult::IoError(err)
};
file.seek(SeekFrom::Start(0)).unwrap();
self.total_sections = file.read_u32::<LittleEndian>().unwrap();
if self.total_sections >= 3 {
file.read(&mut self.controls).unwrap();
file.read(&mut self.strings).unwrap();
self.unknown = file.read_u8().unwrap();
self.mouse_sensitivity = file.read_u32::<LittleEndian>().unwrap();
self.mouse_invert_y = file.read_u8().unwrap();
self.steer_with_mouse = file.read_u8().unwrap();
self.sfx_volume = file.read_u8().unwrap();
self.music_volume = file.read_u8().unwrap();
self.mp3_volume_boost = file.read_u8().unwrap();
self.current_radio = file.read_u8().unwrap();
self.speakers_configuration = file.read_u8().unwrap();
self.audio_hardware = file.read_u8().unwrap();
self.dynamic_acoustic_mode = file.read_u8().unwrap();
self.brightness = file.read_u16::<LittleEndian>().unwrap();
self.draw_distance = file.read_f32::<LittleEndian>().unwrap();
self.subtitles = file.read_u8().unwrap();
self.widescreen = file.read_u8().unwrap();
self.frame_limiter = file.read_u8().unwrap();
self.video_mode = file.read_u8().unwrap();
file.read(&mut self.skin_path).unwrap();
self.standard_controls = file.read_u8().unwrap();
self.current_language = file.read_u8().unwrap();
self.hud_mode = file.read_u8().unwrap();
self.radar_mode = file.read_u8().unwrap();
self.map_legend = file.read_u8().unwrap();
}
SettingsResult::Ok
}
pub fn write<P: AsRef<Path>>(&self, path: P) -> SettingsResult {
let mut file = match File::create(path) {
Ok(f) => f,
Err(err) => return SettingsResult::IoError(err)
};
file.write_u32::<LittleEndian>(self.total_sections).unwrap();
file.write(&self.controls).unwrap();
file.write(&self.strings).unwrap();
file.write_u8(self.unknown).unwrap();
file.write_u32::<LittleEndian>(self.mouse_sensitivity).unwrap();
file.write_u8(self.mouse_invert_y).unwrap();
file.write_u8(self.steer_with_mouse).unwrap();
file.write_u8(self.sfx_volume).unwrap();
file.write_u8(self.music_volume).unwrap();
file.write_u8(self.mp3_volume_boost).unwrap();
file.write_u8(self.current_radio).unwrap();
file.write_u8(self.speakers_configuration).unwrap();
file.write_u8(self.audio_hardware).unwrap();
file.write_u8(self.dynamic_acoustic_mode).unwrap();
file.write_u16::<LittleEndian>(self.brightness).unwrap();
file.write_f32::<LittleEndian>(self.draw_distance).unwrap();
file.write_u8(self.subtitles).unwrap();
file.write_u8(self.widescreen).unwrap();
file.write_u8(self.frame_limiter).unwrap();
file.write_u8(self.video_mode).unwrap();
file.write(&self.skin_path).unwrap();
file.write_u8(self.standard_controls).unwrap();
file.write_u8(self.current_language).unwrap();
file.write_u8(self.hud_mode).unwrap();
file.write_u8(self.radar_mode).unwrap();
file.write_u8(self.map_legend).unwrap();
SettingsResult::Ok
}
}