1 module bindbc.jsl.dynload;
2 version(BindJSL_Static) {
3 
4 } else {
5 	import bindbc.loader;
6 	import bindbc.jsl.joyshocklibrary;
7 	/**
8 	 * Used as a return value by the loader.
9 	 * Currently doesn't support version checking.
10 	 */
11 	enum JSLSupport {
12 		noLibrary,
13 		badLibrary,
14 		loadedV1_1,
15 	}
16 	private {
17 		SharedLib lib;
18 		JSLSupport loadedVersion;
19 	}
20 	/**
21 	 * Unloads the JSL library.
22 	 */
23 	void unloadJLS() {
24 		if(lib != invalidHandle) {
25 			lib.unload();
26 		}
27 	}
28 	/**
29 	 * Returns the currently loaded version of the library, or an error code if the loading failed.
30 	 */
31 	JSLSupport loadedJSLVersion() {
32 		return loadedVersion;
33 	}
34 	/**
35 	 * Loads the library.
36 	 */
37 	JSLSupport loadJSL() {
38 		version(Windows) {
39 			const(char)[] filename = "JoyShockLibrary.dll";
40 		} else static assert(0, "At the current moment, JoyShockLibrary is Windows only!");
41 		return loadJSL(filename.ptr);
42 	}
43 	/**
44 	 * Loads the library from the given path.
45 	 */
46 	JSLSupport loadJSL(const(char)* libName) {
47 		lib = load(libName);
48 		if (lib == invalidHandle) return JSLSupport.noLibrary;
49 		auto errCnt = errorCount();
50 		lib.bindSymbol(cast(void**)&JslGetSimpleState, "JslGetSimpleState");
51 		lib.bindSymbol(cast(void**)&JslGetIMUState, "JslGetIMUState");
52 		lib.bindSymbol(cast(void**)&JslGetButtons, "JslGetButtons");
53 		lib.bindSymbol(cast(void**)&JslGetLeftX, "JslGetLeftX");
54 		lib.bindSymbol(cast(void**)&JslGetLeftY, "JslGetLeftY");
55 		lib.bindSymbol(cast(void**)&JslGetRightX, "JslGetRightX");
56 		lib.bindSymbol(cast(void**)&JslGetRightY, "JslGetRightY");
57 		lib.bindSymbol(cast(void**)&JslGetLeftTrigger, "JslGetLeftTrigger");
58 		lib.bindSymbol(cast(void**)&JslGetRightTrigger, "JslGetRightTrigger");
59 		lib.bindSymbol(cast(void**)&JslGetGyroX, "JslGetGyroX");
60 		lib.bindSymbol(cast(void**)&JslGetGyroY, "JslGetGyroY");
61 		lib.bindSymbol(cast(void**)&JslGetGyroZ, "JslGetGyroZ");
62 		lib.bindSymbol(cast(void**)&JslGetAccelX, "JslGetAccelX");
63 		lib.bindSymbol(cast(void**)&JslGetAccelY, "JslGetAccelY");
64 		lib.bindSymbol(cast(void**)&JslGetAccelZ, "JslGetAccelZ");
65 		lib.bindSymbol(cast(void**)&JslGetStickStep, "JslGetStickStep");
66 		lib.bindSymbol(cast(void**)&JslGetTriggerStep, "JslGetTriggerStep");
67 		lib.bindSymbol(cast(void**)&JslGetPollRate, "JslGetPollRate");
68 		lib.bindSymbol(cast(void**)&JslResetContinuousCalibration, "JslResetContinuousCalibration");
69 		lib.bindSymbol(cast(void**)&JslStartContinuousCalibration, "JslStartContinuousCalibration");
70 		lib.bindSymbol(cast(void**)&JslPauseContinuousCalibration, "JslPauseContinuousCalibration");
71 		lib.bindSymbol(cast(void**)&JslGetCalibrationOffset, "JslGetCalibrationOffset");
72 		lib.bindSymbol(cast(void**)&JslSetCalibrationOffset, "JslSetCalibrationOffset");
73 		lib.bindSymbol(cast(void**)&JslSetCallback, "JslSetCallback");
74 		lib.bindSymbol(cast(void**)&JslGetControllerType, "JslGetControllerType");
75 		lib.bindSymbol(cast(void**)&JslGetControllerSplitType, "JslGetControllerSplitType");
76 		lib.bindSymbol(cast(void**)&JslGetControllerColour, "JslGetControllerColour");
77 		lib.bindSymbol(cast(void**)&JslSetLightColour, "JslSetLightColour");
78 		lib.bindSymbol(cast(void**)&JslSetRumble, "JslSetRumble");
79 		lib.bindSymbol(cast(void**)&JslSetPlayerNumber, "JslSetPlayerNumber");
80 		if(errCnt != errorCount()) loadedVersion = JSLSupport.badLibrary;
81 		else loadedVersion = JSLSupport.loadedV1_1;
82 		return loadedVersion;
83 	}
84 }