1 |
$snap_numberofkeys = 19; |
2 |
|
3 |
// finds the current settings and puts them in $snap_bindings |
4 |
function snap_get_current_keys() |
5 |
{ |
6 |
$snap_bindings[0] = snap_get_binding(prevWeapon); |
7 |
$snap_bindings[1] = snap_get_binding(nextWeapon); |
8 |
$snap_bindings[2] = snap_get_binding(placeMine); |
9 |
$snap_bindings[3] = snap_get_binding(placeBeacon); |
10 |
$snap_bindings[4] = snap_get_binding(useTargetingLaser); |
11 |
$snap_bindings[5] = snap_get_binding(throwWeapon); |
12 |
$snap_bindings[6] = snap_get_binding(throwPack); |
13 |
$snap_bindings[7] = snap_get_binding(throwFlag); |
14 |
$snap_bindings[8] = snap_get_binding(toggleZoom); |
15 |
$snap_bindings[9] = snap_get_binding(toggleCommanderMap); |
16 |
|
17 |
$snap_bindings[10] = snap_get_binding(jump); |
18 |
$snap_bindings[11] = snap_get_binding(setZoomFOV); |
19 |
$snap_bindings[12] = snap_get_binding(throwGrenade); |
20 |
$snap_bindings[13] = snap_get_binding(useBackPack); |
21 |
$snap_bindings[14] = snap_get_binding(useRepairKit); |
22 |
|
23 |
$snap_bindings[15] = snap_get_binding(moveforward); |
24 |
$snap_bindings[16] = snap_get_binding(movebackward); |
25 |
$snap_bindings[17] = snap_get_binding(moveleft); |
26 |
$snap_bindings[18] = snap_get_binding(moveright); |
27 |
|
28 |
$snap_mousespeed = mfloor(moveMap.getscale(mouse, xaxis) * 8 - 0.5); |
29 |
if ($snap_mousespeed < 0) $snap_mousespeed = 0; |
30 |
$snap_mouseinv = moveMap.isinverted(mouse, yaxis); |
31 |
} |
32 |
|
33 |
// gets the key bound to %action |
34 |
function snap_get_binding(%action) |
35 |
{ |
36 |
return getfield(movemap.getbinding(%action), 1); |
37 |
} |
38 |
|
39 |
|
40 |
|
41 |
// encode reads the bindings in $snap_bindings and returns a short string |
42 |
function snap_encode() |
43 |
{ |
44 |
%code["equals"] = "00000000"; |
45 |
%code["lbracket"] = "00000001"; |
46 |
%code["slash"] = "00000010"; |
47 |
%code["lessthan"] = "00000011"; |
48 |
%code["comma"] = "00000100"; |
49 |
%code["period"] = "00000101"; |
50 |
%code["semicolon"] = "00000110"; |
51 |
%code["apostrophe"] = "00000111"; |
52 |
%code["numpad9"] = "000010000"; |
53 |
%code["numpadmult"] = "000010001"; |
54 |
%code["numpad7"] = "000010010"; |
55 |
%code["numpad8"] = "000010011"; |
56 |
%code["numpadminus"] = "000010100"; |
57 |
%code["numpadadd"] = "0000101010"; |
58 |
%code["numpadsep"] = "0000101011"; |
59 |
%code["numpad5"] = "0000101100"; |
60 |
%code["numpad6"] = "0000101101"; |
61 |
%code["numpad3"] = "0000101110"; |
62 |
%code["numpad4"] = "0000101111"; |
63 |
%code["numpad1"] = "0000110"; |
64 |
%code["numpad2"] = "0000111"; |
65 |
%code["ctrl b"] = "00010000"; |
66 |
%code["ctrl c"] = "00010001"; |
67 |
%code["ctrl numpad5"] = "0001001000000"; |
68 |
%code["ctrl numpad6"] = "0001001000001"; |
69 |
%code["ctrl numpad3"] = "0001001000010"; |
70 |
%code["ctrl numpad4"] = "0001001000011"; |
71 |
%code["ctrl numpad9"] = "0001001000100"; |
72 |
%code["ctrl numpadmult"] = "0001001000101"; |
73 |
%code["ctrl numpad7"] = "0001001000110"; |
74 |
%code["ctrl numpad8"] = "0001001000111"; |
75 |
%code["ctrl numpadminus"] = "0001001001000"; |
76 |
%code["ctrl numpaddecimal"] = "0001001001001"; |
77 |
%code["ctrl numpadadd"] = "0001001001010"; |
78 |
%code["ctrl numpadsep"] = "0001001001011"; |
79 |
%code["ctrl numpad1"] = "0001001001100"; |
80 |
%code["ctrl numpad2"] = "0001001001101"; |
81 |
%code["ctrl *"] = "0001001001110"; |
82 |
%code["ctrl numpaddivide"] = "00010010011110"; |
83 |
%code["ctrl numpadenter"] = "00010010011111"; |
84 |
%code["ctrl a"] = "000100101"; |
85 |
%code["ctrl d"] = "000100110"; |
86 |
%code["ctrl e"] = "000100111"; |
87 |
%code["ctrl f"] = "000101"; |
88 |
%code["ctrl x"] = "00011000"; |
89 |
%code["ctrl y"] = "00011001"; |
90 |
%code["shift space"] = "000110100"; |
91 |
%code["shift o"] = "00011010100"; |
92 |
%code["shift p"] = "00011010101"; |
93 |
%code["shift y"] = "00011010110"; |
94 |
%code["shift z"] = "00011010111"; |
95 |
%code["shift u"] = "00011011000"; |
96 |
%code["shift v"] = "00011011001"; |
97 |
%code["shift q"] = "00011011010"; |
98 |
%code["shift r"] = "00011011011"; |
99 |
%code["shift s"] = "00011011100"; |
100 |
%code["shift t"] = "00011011101"; |
101 |
%code["shift b"] = "000110111100"; |
102 |
%code["shift c"] = "000110111101"; |
103 |
%code["shift *"] = "000110111110"; |
104 |
%code["shift a"] = "000110111111"; |
105 |
%code["ctrl q"] = "00011100"; |
106 |
%code["ctrl o"] = "000111010"; |
107 |
%code["ctrl p"] = "000111011"; |
108 |
%code["ctrl i"] = "000111100"; |
109 |
%code["ctrl j"] = "000111101"; |
110 |
%code["ctrl g"] = "000111110"; |
111 |
%code["ctrl h"] = "000111111"; |
112 |
%code["8"] = "0010000"; |
113 |
%code["9"] = "0010001"; |
114 |
%code["numpadenter"] = "00100100"; |
115 |
%code["*"] = "00100101"; |
116 |
%code["numpaddecimal"] = "00100110"; |
117 |
%code["numpaddivide"] = "00100111"; |
118 |
%code["lcontrol"] = "001010"; |
119 |
%code["rcontrol"] = "001011"; |
120 |
%code["button2"] = "001100"; |
121 |
%code["1"] = "001101"; |
122 |
%code["scrolllock"] = "001110000"; |
123 |
%code["delete"] = "0011100010"; |
124 |
%code["numlock"] = "0011100011"; |
125 |
%code["print"] = "001110010"; |
126 |
%code["insert"] = "001110011"; |
127 |
%code["lshift"] = "0011101"; |
128 |
%code["rshift"] = "001111"; |
129 |
%code["rbracket"] = "01000000"; |
130 |
%code["backslash"] = "01000001"; |
131 |
%code["tilde"] = "01000010"; |
132 |
%code["minus"] = "01000011"; |
133 |
%code["lalt"] = "0100010"; |
134 |
%code["ralt"] = "0100011"; |
135 |
%code["enter"] = "0100100"; |
136 |
%code["pause"] = "0100101"; |
137 |
%code["backspace"] = "01001100"; |
138 |
%code["tab"] = "01001101"; |
139 |
%code["return"] = "0100111"; |
140 |
%code["6"] = "0101000"; |
141 |
%code["7"] = "0101001"; |
142 |
%code["0"] = "0101010"; |
143 |
%code["numpad0"] = "0101011"; |
144 |
%code["y"] = "010110"; |
145 |
%code["z"] = "010111"; |
146 |
%code["o"] = "011000"; |
147 |
%code["p"] = "011001"; |
148 |
%code["m"] = "011010"; |
149 |
%code["n"] = "011011"; |
150 |
%code["u"] = "011100"; |
151 |
%code["v"] = "011101"; |
152 |
%code["q"] = "011110"; |
153 |
%code["r"] = "011111"; |
154 |
%code["g"] = "100000"; |
155 |
%code["h"] = "100001"; |
156 |
%code["e"] = "100010"; |
157 |
%code["f"] = "100011"; |
158 |
%code["k"] = "100100"; |
159 |
%code["l"] = "100101"; |
160 |
%code["i"] = "100110"; |
161 |
%code["j"] = "100111"; |
162 |
%code["home"] = "1010000"; |
163 |
%code["pageup"] = "10100010"; |
164 |
%code["end"] = "10100011"; |
165 |
%code["capslock"] = "1010010"; |
166 |
%code["pagedown"] = "1010011"; |
167 |
%code["ctrl z"] = "101010000"; |
168 |
%code["ctrl left"] = "101010001"; |
169 |
%code["shift f"] = "10101001000"; |
170 |
%code["shift g"] = "10101001001"; |
171 |
%code["shift m"] = "101010010100"; |
172 |
%code["shift n"] = "101010010101"; |
173 |
%code["shift k"] = "101010010110"; |
174 |
%code["shift l"] = "101010010111"; |
175 |
%code["shift e"] = "10101001100"; |
176 |
%code["shift d"] = "101010011010"; |
177 |
%code["shift numpad4"] = "1010100110110000"; |
178 |
%code["shift numpad5"] = "1010100110110001"; |
179 |
%code["shift numpad2"] = "1010100110110010"; |
180 |
%code["shift numpad3"] = "1010100110110011"; |
181 |
%code["shift numpad8"] = "1010100110110100"; |
182 |
%code["shift numpad9"] = "1010100110110101"; |
183 |
%code["shift numpad6"] = "1010100110110110"; |
184 |
%code["shift numpad7"] = "1010100110110111"; |
185 |
%code["shift numpadsep"] = "1010100110111000"; |
186 |
%code["shift numpadminus"] = "1010100110111001"; |
187 |
%code["shift numpadmult"] = "1010100110111010"; |
188 |
%code["shift numpadadd"] = "1010100110111011"; |
189 |
%code["shift numpad0"] = "1010100110111100"; |
190 |
%code["shift numpad1"] = "1010100110111101"; |
191 |
%code["shift numpadenter"] = "1010100110111110"; |
192 |
%code["shift numpaddecimal"] = "10101001101111110"; |
193 |
%code["shift numpaddivide"] = "10101001101111111"; |
194 |
%code["shift j"] = "101010011100"; |
195 |
%code["shift h"] = "1010100111010"; |
196 |
%code["shift i"] = "1010100111011"; |
197 |
%code["shift w"] = "101010011110"; |
198 |
%code["shift x"] = "101010011111"; |
199 |
%code["ctrl down"] = "1010101000"; |
200 |
%code["ctrl space"] = "1010101001"; |
201 |
%code["ctrl up"] = "1010101010"; |
202 |
%code["ctrl right"] = "1010101011"; |
203 |
%code["shift right"] = "1010101100"; |
204 |
%code["shift down"] = "1010101101"; |
205 |
%code["shift left"] = "1010101110"; |
206 |
%code["shift up"] = "1010101111"; |
207 |
%code["ctrl m"] = "101011000"; |
208 |
%code["ctrl n"] = "101011001"; |
209 |
%code["ctrl k"] = "101011010"; |
210 |
%code["ctrl l"] = "101011011"; |
211 |
%code["ctrl r"] = "1010111"; |
212 |
%code["right"] = "101100"; |
213 |
%code["down"] = "101101"; |
214 |
%code["left"] = "101110"; |
215 |
%code["up"] = "101111"; |
216 |
%code["c"] = "110000"; |
217 |
%code["d"] = "110001"; |
218 |
%code["a"] = "110010"; |
219 |
%code["b"] = "110011"; |
220 |
%code["w"] = "110100"; |
221 |
%code["x"] = "110101"; |
222 |
%code["s"] = "110110"; |
223 |
%code["t"] = "110111"; |
224 |
%code["right"] = "111000"; |
225 |
%code["down"] = "111001"; |
226 |
%code["left"] = "111010"; |
227 |
%code["up"] = "111011"; |
228 |
%code["4"] = "1111000"; |
229 |
%code["5"] = "1111001"; |
230 |
%code["2"] = "1111010"; |
231 |
%code["3"] = "1111011"; |
232 |
%code["space"] = "1111100"; |
233 |
%code["ctrl numpad0"] = "1111101"; |
234 |
%code["ctrl u"] = "111111000"; |
235 |
%code["ctrl v"] = "111111001"; |
236 |
%code["ctrl s"] = "111111010"; |
237 |
%code["ctrl t"] = "111111011"; |
238 |
%code["ctrl w"] = "1111111"; |
239 |
|
240 |
%l = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-"; |
241 |
|
242 |
//get bind settings into $snap_bindings |
243 |
snap_get_current_keys(); |
244 |
|
245 |
// build binary string |
246 |
%z = ""; |
247 |
for (%i = 0; %i < $snap_numberofkeys; %i++) |
248 |
%z = %z @ %code[$snap_bindings[%i]]; |
249 |
|
250 |
%z = %z @ snap_int_to_binstr($snap_mousespeed, 4) @ $snap_mouseinv; |
251 |
|
252 |
// pad length to multiple of 6 chars |
253 |
while (strlen(%z) % 6) |
254 |
%z = %z @ "0"; |
255 |
|
256 |
// encode |
257 |
%j = ""; |
258 |
for (%i = 0; %i < strlen(%z); %i += 6) |
259 |
{ |
260 |
%n = snap_binstr_to_int(getsubstr(%z, %i, 6)); |
261 |
%j = %j @ getsubstr(%l, %n, 1); |
262 |
} |
263 |
|
264 |
return %j; |
265 |
} |
266 |
|
267 |
function snapback( %code ) |
268 |
{ |
269 |
snap( $snap_back ); |
270 |
} |
271 |
|
272 |
|
273 |
|
274 |
// convert a snap kode to a set of bindings in $snap_bindings |
275 |
function snap( %j ) |
276 |
{ |
277 |
$snap_back = snap_encode(); |
278 |
|
279 |
|
280 |
if (%j $= "") |
281 |
{ |
282 |
echo("Your current Snap Code is " @ $snap_back); // echo current snap_code tm |
283 |
return $snap_back; |
284 |
} |
285 |
|
286 |
echo("The previous Snap Code is " @ $snap_back); |
287 |
|
288 |
%code["00000000"] = "equals"; |
289 |
%code["00000001"] = "lbracket"; |
290 |
%code["00000010"] = "slash"; |
291 |
%code["00000011"] = "lessthan"; |
292 |
%code["00000100"] = "comma"; |
293 |
%code["00000101"] = "period"; |
294 |
%code["00000110"] = "semicolon"; |
295 |
%code["00000111"] = "apostrophe"; |
296 |
%code["000010000"] = "numpad9"; |
297 |
%code["000010001"] = "numpadmult"; |
298 |
%code["000010010"] = "numpad7"; |
299 |
%code["000010011"] = "numpad8"; |
300 |
%code["000010100"] = "numpadminus"; |
301 |
%code["0000101010"] = "numpadadd"; |
302 |
%code["0000101011"] = "numpadsep"; |
303 |
%code["0000101100"] = "numpad5"; |
304 |
%code["0000101101"] = "numpad6"; |
305 |
%code["0000101110"] = "numpad3"; |
306 |
%code["0000101111"] = "numpad4"; |
307 |
%code["0000110"] = "numpad1"; |
308 |
%code["0000111"] = "numpad2"; |
309 |
%code["00010000"] = "ctrl b"; |
310 |
%code["00010001"] = "ctrl c"; |
311 |
%code["0001001000000"] = "ctrl numpad5"; |
312 |
%code["0001001000001"] = "ctrl numpad6"; |
313 |
%code["0001001000010"] = "ctrl numpad3"; |
314 |
%code["0001001000011"] = "ctrl numpad4"; |
315 |
%code["0001001000100"] = "ctrl numpad9"; |
316 |
%code["0001001000101"] = "ctrl numpadmult"; |
317 |
%code["0001001000110"] = "ctrl numpad7"; |
318 |
%code["0001001000111"] = "ctrl numpad8"; |
319 |
%code["0001001001000"] = "ctrl numpadminus"; |
320 |
%code["0001001001001"] = "ctrl numpaddecimal"; |
321 |
%code["0001001001010"] = "ctrl numpadadd"; |
322 |
%code["0001001001011"] = "ctrl numpadsep"; |
323 |
%code["0001001001100"] = "ctrl numpad1"; |
324 |
%code["0001001001101"] = "ctrl numpad2"; |
325 |
%code["0001001001110"] = "ctrl *"; |
326 |
%code["00010010011110"] = "ctrl numpaddivide"; |
327 |
%code["00010010011111"] = "ctrl numpadenter"; |
328 |
%code["000100101"] = "ctrl a"; |
329 |
%code["000100110"] = "ctrl d"; |
330 |
%code["000100111"] = "ctrl e"; |
331 |
%code["000101"] = "ctrl f"; |
332 |
%code["00011000"] = "ctrl x"; |
333 |
%code["00011001"] = "ctrl y"; |
334 |
%code["000110100"] = "shift space"; |
335 |
%code["00011010100"] = "shift o"; |
336 |
%code["00011010101"] = "shift p"; |
337 |
%code["00011010110"] = "shift y"; |
338 |
%code["00011010111"] = "shift z"; |
339 |
%code["00011011000"] = "shift u"; |
340 |
%code["00011011001"] = "shift v"; |
341 |
%code["00011011010"] = "shift q"; |
342 |
%code["00011011011"] = "shift r"; |
343 |
%code["00011011100"] = "shift s"; |
344 |
%code["00011011101"] = "shift t"; |
345 |
%code["000110111100"] = "shift b"; |
346 |
%code["000110111101"] = "shift c"; |
347 |
%code["000110111110"] = "shift *"; |
348 |
%code["000110111111"] = "shift a"; |
349 |
%code["00011100"] = "ctrl q"; |
350 |
%code["000111010"] = "ctrl o"; |
351 |
%code["000111011"] = "ctrl p"; |
352 |
%code["000111100"] = "ctrl i"; |
353 |
%code["000111101"] = "ctrl j"; |
354 |
%code["000111110"] = "ctrl g"; |
355 |
%code["000111111"] = "ctrl h"; |
356 |
%code["0010000"] = "8"; |
357 |
%code["0010001"] = "9"; |
358 |
%code["00100100"] = "numpadenter"; |
359 |
%code["00100101"] = "*"; |
360 |
%code["00100110"] = "numpaddecimal"; |
361 |
%code["00100111"] = "numpaddivide"; |
362 |
%code["001010"] = "lcontrol"; |
363 |
%code["001011"] = "rcontrol"; |
364 |
%code["001100"] = "button2"; |
365 |
%code["001101"] = "1"; |
366 |
%code["001110000"] = "scrolllock"; |
367 |
%code["0011100010"] = "delete"; |
368 |
%code["0011100011"] = "numlock"; |
369 |
%code["001110010"] = "print"; |
370 |
%code["001110011"] = "insert"; |
371 |
%code["0011101"] = "lshift"; |
372 |
%code["001111"] = "rshift"; |
373 |
%code["01000000"] = "rbracket"; |
374 |
%code["01000001"] = "backslash"; |
375 |
%code["01000010"] = "tilde"; |
376 |
%code["01000011"] = "minus"; |
377 |
%code["0100010"] = "lalt"; |
378 |
%code["0100011"] = "ralt"; |
379 |
%code["0100100"] = "enter"; |
380 |
%code["0100101"] = "pause"; |
381 |
%code["01001100"] = "backspace"; |
382 |
%code["01001101"] = "tab"; |
383 |
%code["0100111"] = "return"; |
384 |
%code["0101000"] = "6"; |
385 |
%code["0101001"] = "7"; |
386 |
%code["0101010"] = "0"; |
387 |
%code["0101011"] = "numpad0"; |
388 |
%code["010110"] = "y"; |
389 |
%code["010111"] = "z"; |
390 |
%code["011000"] = "o"; |
391 |
%code["011001"] = "p"; |
392 |
%code["011010"] = "m"; |
393 |
%code["011011"] = "n"; |
394 |
%code["011100"] = "u"; |
395 |
%code["011101"] = "v"; |
396 |
%code["011110"] = "q"; |
397 |
%code["011111"] = "r"; |
398 |
%code["100000"] = "g"; |
399 |
%code["100001"] = "h"; |
400 |
%code["100010"] = "e"; |
401 |
%code["100011"] = "f"; |
402 |
%code["100100"] = "k"; |
403 |
%code["100101"] = "l"; |
404 |
%code["100110"] = "i"; |
405 |
%code["100111"] = "j"; |
406 |
%code["1010000"] = "home"; |
407 |
%code["10100010"] = "pageup"; |
408 |
%code["10100011"] = "end"; |
409 |
%code["1010010"] = "capslock"; |
410 |
%code["1010011"] = "pagedown"; |
411 |
%code["101010000"] = "ctrl z"; |
412 |
%code["101010001"] = "ctrl left"; |
413 |
%code["10101001000"] = "shift f"; |
414 |
%code["10101001001"] = "shift g"; |
415 |
%code["101010010100"] = "shift m"; |
416 |
%code["101010010101"] = "shift n"; |
417 |
%code["101010010110"] = "shift k"; |
418 |
%code["101010010111"] = "shift l"; |
419 |
%code["10101001100"] = "shift e"; |
420 |
%code["101010011010"] = "shift d"; |
421 |
%code["1010100110110000"] = "shift numpad4"; |
422 |
%code["1010100110110001"] = "shift numpad5"; |
423 |
%code["1010100110110010"] = "shift numpad2"; |
424 |
%code["1010100110110011"] = "shift numpad3"; |
425 |
%code["1010100110110100"] = "shift numpad8"; |
426 |
%code["1010100110110101"] = "shift numpad9"; |
427 |
%code["1010100110110110"] = "shift numpad6"; |
428 |
%code["1010100110110111"] = "shift numpad7"; |
429 |
%code["1010100110111000"] = "shift numpadsep"; |
430 |
%code["1010100110111001"] = "shift numpadminus"; |
431 |
%code["1010100110111010"] = "shift numpadmult"; |
432 |
%code["1010100110111011"] = "shift numpadadd"; |
433 |
%code["1010100110111100"] = "shift numpad0"; |
434 |
%code["1010100110111101"] = "shift numpad1"; |
435 |
%code["1010100110111110"] = "shift numpadenter"; |
436 |
%code["10101001101111110"] = "shift numpaddecimal"; |
437 |
%code["10101001101111111"] = "shift numpaddivide"; |
438 |
%code["101010011100"] = "shift j"; |
439 |
%code["1010100111010"] = "shift h"; |
440 |
%code["1010100111011"] = "shift i"; |
441 |
%code["101010011110"] = "shift w"; |
442 |
%code["101010011111"] = "shift x"; |
443 |
%code["1010101000"] = "ctrl down"; |
444 |
%code["1010101001"] = "ctrl space"; |
445 |
%code["1010101010"] = "ctrl up"; |
446 |
%code["1010101011"] = "ctrl right"; |
447 |
%code["1010101100"] = "shift right"; |
448 |
%code["1010101101"] = "shift down"; |
449 |
%code["1010101110"] = "shift left"; |
450 |
%code["1010101111"] = "shift up"; |
451 |
%code["101011000"] = "ctrl m"; |
452 |
%code["101011001"] = "ctrl n"; |
453 |
%code["101011010"] = "ctrl k"; |
454 |
%code["101011011"] = "ctrl l"; |
455 |
%code["1010111"] = "ctrl r"; |
456 |
%code["101100"] = "right"; |
457 |
%code["101101"] = "down"; |
458 |
%code["101110"] = "left"; |
459 |
%code["101111"] = "up"; |
460 |
%code["110000"] = "c"; |
461 |
%code["110001"] = "d"; |
462 |
%code["110010"] = "a"; |
463 |
%code["110011"] = "b"; |
464 |
%code["110100"] = "w"; |
465 |
%code["110101"] = "x"; |
466 |
%code["110110"] = "s"; |
467 |
%code["110111"] = "t"; |
468 |
%code["111000"] = "right"; |
469 |
%code["111001"] = "down"; |
470 |
%code["111010"] = "left"; |
471 |
%code["111011"] = "up"; |
472 |
%code["1111000"] = "4"; |
473 |
%code["1111001"] = "5"; |
474 |
%code["1111010"] = "2"; |
475 |
%code["1111011"] = "3"; |
476 |
%code["1111100"] = "space"; |
477 |
%code["1111101"] = "ctrl numpad0"; |
478 |
%code["111111000"] = "ctrl u"; |
479 |
%code["111111001"] = "ctrl v"; |
480 |
%code["111111010"] = "ctrl s"; |
481 |
%code["111111011"] = "ctrl t"; |
482 |
%code["1111111"] = "ctrl w"; |
483 |
|
484 |
%l = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-"; |
485 |
|
486 |
%z = ""; |
487 |
for (%i = 0; %i < strlen(%j); %i++) |
488 |
%z = %z @ snap_int_to_binstr(strpos(%l, getsubstr(%j, %i, 1)), 6); |
489 |
|
490 |
for (%i = 0; %i < $snap_numberofkeys; %i++) |
491 |
{ |
492 |
%ll = 1; |
493 |
while (%ll != 100 && %code[getsubstr(%z, 0, %ll)] $= "") |
494 |
%ll++; |
495 |
if (%ll == 100) |
496 |
{ |
497 |
echo("Decode error"); |
498 |
return; |
499 |
} |
500 |
|
501 |
$snap_bindings[%i] = %code[getsubstr(%z, 0, %ll)]; |
502 |
%z = getsubstr(%z, %ll, strlen(%z)); |
503 |
} |
504 |
|
505 |
$snap_mousespeed = snap_binstr_to_int(getsubstr(%z, 0, 4)); |
506 |
$snap_mouseinv = getsubstr(%z, 0, 1); |
507 |
|
508 |
snap_set_keys(); |
509 |
|
510 |
echo("Bindings Snapped"); |
511 |
return $snap_back; |
512 |
} |
513 |
|
514 |
// convert binary string to its value |
515 |
function snap_binstr_to_int(%s) |
516 |
{ |
517 |
%v = 0; |
518 |
for (%i = 0; %i < strlen(%s); %i++) |
519 |
%v = (%v << 1) + getsubstr(%s, %i, 1); |
520 |
return %v; |
521 |
} |
522 |
|
523 |
// convert an integer to fixed length binary string |
524 |
function snap_int_to_binstr(%i, %l) |
525 |
{ |
526 |
%s = ""; |
527 |
while (%i > 0) |
528 |
{ |
529 |
%s = (%i % 2) @ %s; |
530 |
%i >>= 1; |
531 |
} |
532 |
|
533 |
while (strlen(%s) % %l || %s $= "") |
534 |
%s = "0" @ %s; |
535 |
|
536 |
return %s; |
537 |
} |
538 |
|
539 |
// convert an integer to 6 char binary string |
540 |
function snap_int_to_binstr6(%i) |
541 |
{ |
542 |
if (%i == 0) return "000000"; |
543 |
|
544 |
%s = ""; |
545 |
while (%i > 0) |
546 |
{ |
547 |
%s = (%i % 2) @ %s; |
548 |
%i >>= 1; |
549 |
} |
550 |
|
551 |
while (strlen(%s) % 6) |
552 |
%s = "0" @ %s; |
553 |
|
554 |
return %s; |
555 |
} |
556 |
|
557 |
// read bindings from $snap_bindings and apply them |
558 |
function snap_set_keys( ) |
559 |
{ |
560 |
snap_bind($snap_bindings[0], prevWeapon); |
561 |
snap_bind($snap_bindings[1], nextWeapon); |
562 |
snap_bind($snap_bindings[2], placeMine); |
563 |
snap_bind($snap_bindings[3], placeBeacon); |
564 |
snap_bind($snap_bindings[4], useTargetingLaser); |
565 |
snap_bind($snap_bindings[5], throwWeapon); |
566 |
snap_bind($snap_bindings[6], throwPack); |
567 |
snap_bind($snap_bindings[7], throwFlag); |
568 |
snap_bind($snap_bindings[8], toggleZoom); |
569 |
snap_bind($snap_bindings[9], toggleCommanderMap); |
570 |
|
571 |
snap_bind($snap_bindings[10], jump); |
572 |
snap_bind($snap_bindings[11], setZoomFOV); |
573 |
snap_bind($snap_bindings[12], throwGrenade); |
574 |
snap_bind($snap_bindings[13], useBackPack); |
575 |
snap_bind($snap_bindings[14], useRepairKit); |
576 |
|
577 |
snap_bind($snap_bindings[15], moveforward); |
578 |
snap_bind($snap_bindings[16], movebackward); |
579 |
snap_bind($snap_bindings[17], moveleft); |
580 |
snap_bind($snap_bindings[18], moveright); |
581 |
|
582 |
%speed = ($snap_mousespeed + 0.5) / 8; |
583 |
movemap.bind(mouse0, "xaxis", S, %speed, yaw); |
584 |
movemap.bind(mouse0, "yaxis", $snap_mouseinv ? SI : S, %speed, pitch); // SI = inverted, S = uninverted |
585 |
} |
586 |
|
587 |
function snap_bind(%key, %action) |
588 |
{ |
589 |
if (strpos("button2", %key) != -1) |
590 |
movemap.bind(mouse0, %key, %action); |
591 |
else |
592 |
movemap.bind(keyboard, %key, %action); |
593 |
} |
594 |
|