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 loadedV2_0, 16 } 17 private { 18 SharedLib lib; 19 JSLSupport loadedVersion; 20 } 21 /** 22 * Unloads the JSL library. 23 */ 24 void unloadJLS() { 25 if(lib != invalidHandle) { 26 lib.unload(); 27 } 28 } 29 /** 30 * Returns the currently loaded version of the library, or an error code if the loading failed. 31 */ 32 JSLSupport loadedJSLVersion() { 33 return loadedVersion; 34 } 35 /** 36 * Loads the library. 37 */ 38 JSLSupport loadJSL() { 39 version(Windows) { 40 const(char)[] filename = "JoyShockLibrary.dll"; 41 } else static assert(0, "At the current moment, JoyShockLibrary is Windows only!"); 42 return loadJSL(filename.ptr); 43 } 44 /** 45 * Loads the library from the given path. 46 */ 47 JSLSupport loadJSL(const(char)* libName) { 48 lib = load(libName); 49 if (lib == invalidHandle) return JSLSupport.noLibrary; 50 auto errCnt = errorCount(); 51 lib.bindSymbol(cast(void**)&JslGetSimpleState, "JslGetSimpleState"); 52 lib.bindSymbol(cast(void**)&JslGetIMUState, "JslGetIMUState"); 53 lib.bindSymbol(cast(void**)&JslGetButtons, "JslGetButtons"); 54 lib.bindSymbol(cast(void**)&JslGetLeftX, "JslGetLeftX"); 55 lib.bindSymbol(cast(void**)&JslGetLeftY, "JslGetLeftY"); 56 lib.bindSymbol(cast(void**)&JslGetRightX, "JslGetRightX"); 57 lib.bindSymbol(cast(void**)&JslGetRightY, "JslGetRightY"); 58 lib.bindSymbol(cast(void**)&JslGetLeftTrigger, "JslGetLeftTrigger"); 59 lib.bindSymbol(cast(void**)&JslGetRightTrigger, "JslGetRightTrigger"); 60 lib.bindSymbol(cast(void**)&JslGetGyroX, "JslGetGyroX"); 61 lib.bindSymbol(cast(void**)&JslGetGyroY, "JslGetGyroY"); 62 lib.bindSymbol(cast(void**)&JslGetGyroZ, "JslGetGyroZ"); 63 lib.bindSymbol(cast(void**)&JslGetAccelX, "JslGetAccelX"); 64 lib.bindSymbol(cast(void**)&JslGetAccelY, "JslGetAccelY"); 65 lib.bindSymbol(cast(void**)&JslGetAccelZ, "JslGetAccelZ"); 66 lib.bindSymbol(cast(void**)&JslGetStickStep, "JslGetStickStep"); 67 lib.bindSymbol(cast(void**)&JslGetTriggerStep, "JslGetTriggerStep"); 68 lib.bindSymbol(cast(void**)&JslGetPollRate, "JslGetPollRate"); 69 lib.bindSymbol(cast(void**)&JslResetContinuousCalibration, "JslResetContinuousCalibration"); 70 lib.bindSymbol(cast(void**)&JslStartContinuousCalibration, "JslStartContinuousCalibration"); 71 lib.bindSymbol(cast(void**)&JslPauseContinuousCalibration, "JslPauseContinuousCalibration"); 72 lib.bindSymbol(cast(void**)&JslGetCalibrationOffset, "JslGetCalibrationOffset"); 73 lib.bindSymbol(cast(void**)&JslSetCalibrationOffset, "JslSetCalibrationOffset"); 74 lib.bindSymbol(cast(void**)&JslSetCallback, "JslSetCallback"); 75 lib.bindSymbol(cast(void**)&JslGetControllerType, "JslGetControllerType"); 76 lib.bindSymbol(cast(void**)&JslGetControllerSplitType, "JslGetControllerSplitType"); 77 lib.bindSymbol(cast(void**)&JslGetControllerColour, "JslGetControllerColour"); 78 lib.bindSymbol(cast(void**)&JslSetLightColour, "JslSetLightColour"); 79 lib.bindSymbol(cast(void**)&JslSetRumble, "JslSetRumble"); 80 lib.bindSymbol(cast(void**)&JslSetPlayerNumber, "JslSetPlayerNumber"); 81 if(errCnt != errorCount()) loadedVersion = JSLSupport.badLibrary; 82 else loadedVersion = JSLSupport.loadedV1_1; 83 version(JSLV2_0) { 84 lib.bindSymbol(cast(void**)&JslGetMotionState, "JslGetMotionState"); 85 lib.bindSymbol(cast(void**)&JslGetTouchState, "JslGetTouchState"); 86 if(errCnt == errorCount()) loadedVersion = JSLSupport.loadedV2_0; 87 } 88 return loadedVersion; 89 } 90 }