Advertisement
Guest User

Untitled

a guest
Dec 1st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. local ffi = require("ffi")
  2.  
  3. local vjoy = ffi.load("vJoyInterface.dll")
  4.  
  5. ffi.cdef [[
  6. typedef int BOOL;
  7. typedef short SHORT;
  8. typedef unsigned short USHORT;
  9. typedef int INT;
  10. typedef unsigned int UINT;
  11. typedef long LONG;
  12. typedef unsigned short WORD;
  13. typedef unsigned long DWORD;
  14.  
  15. typedef void *PVOID;
  16.  
  17. typedef unsigned char UCHAR;
  18.  
  19. typedef void (__stdcall *RemovalCB)(BOOL, BOOL, PVOID);
  20.  
  21. SHORT GetvJoyVersion(void);
  22. BOOL    vJoyEnabled(void);
  23. PVOID   GetvJoyProductString(void);
  24. PVOID   GetvJoyManufacturerString(void);
  25. PVOID   GetvJoySerialNumberString(void);
  26. BOOL    DriverMatch(WORD * DllVer, WORD * DrvVer);
  27. void    RegisterRemovalCB(RemovalCB cb, PVOID data);
  28. BOOL    vJoyFfbCap(BOOL * Supported);   // Is this version of vJoy capable of FFB?
  29. BOOL    GetvJoyMaxDevices(int * n); // What is the maximum possible number of vJoy devices
  30. BOOL    GetNumberExistingVJD(int * n);  // What is the number of vJoy devices currently enabled
  31.  
  32. enum VjdStat  /* Declares an enumeration data type */
  33. {
  34.     VJD_STAT_OWN,   // The  vJoy Device is owned by this application.
  35.     VJD_STAT_FREE,  // The  vJoy Device is NOT owned by any application (including this one).
  36.     VJD_STAT_BUSY,  // The  vJoy Device is owned by another application. It cannot be acquired by this application.
  37.     VJD_STAT_MISS,  // The  vJoy Device is missing. It either does not exist or the driver is down.
  38.     VJD_STAT_UNKN   // Unknown
  39. };
  40.  
  41. /////   vJoy Device properties
  42. int  GetVJDButtonNumber(UINT rID);  // Get the number of buttons defined in the specified VDJ
  43. int  GetVJDDiscPovNumber(UINT rID); // Get the number of descrete-type POV hats defined in the specified VDJ
  44. int  GetVJDContPovNumber(UINT rID); // Get the number of descrete-type POV hats defined in the specified VDJ
  45. BOOL     GetVJDAxisExist(UINT rID, UINT Axis); // Test if given axis defined in the specified VDJ
  46. BOOL     GetVJDAxisMax(UINT rID, UINT Axis, LONG * Max); // Get logical Maximum value for a given axis defined in the specified VDJ
  47. BOOL     GetVJDAxisMin(UINT rID, UINT Axis, LONG * Min); // Get logical Minimum value for a given axis defined in the specified VDJ
  48. enum VjdStat    GetVJDStatus(UINT rID);         // Get the status of the specified vJoy Device.
  49. // Added in 2.1.6
  50. BOOL    isVJDExists(UINT rID);                  // TRUE if the specified vJoy Device exists                                                                        
  51. // Added in 2.1.8
  52. int GetOwnerPid(UINT rID);                  // Reurn owner's Process ID if the specified vJoy Device exists
  53.  
  54.  
  55. /////   Write access to vJoy Device - Basic
  56. BOOL        AcquireVJD(UINT rID);               // Acquire the specified vJoy Device.
  57. void        RelinquishVJD(UINT rID);            // Relinquish the specified vJoy Device.
  58. BOOL        UpdateVJD(UINT rID, PVOID pData);   // Update the position data of the specified vJoy Device.
  59.  
  60. /////   Write access to vJoy Device - Modifyiers
  61. // This group of functions modify the current value of the position data
  62. // They replace the need to create a structure of position data then call UpdateVJD
  63.  
  64. //// Reset functions
  65. BOOL        ResetVJD(UINT rID);         // Reset all controls to predefined values in the specified VDJ
  66. void        ResetAll(void);             // Reset all controls to predefined values in all VDJ
  67. BOOL        ResetButtons(UINT rID);     // Reset all buttons (To 0) in the specified VDJ
  68. BOOL        ResetPovs(UINT rID);        // Reset all POV Switches (To -1) in the specified VDJ
  69.  
  70. // Write data
  71. BOOL        SetAxis(LONG Value, UINT rID, UINT Axis);       // Write Value to a given axis defined in the specified VDJ
  72. BOOL        SetBtn(BOOL Value, UINT rID, UCHAR nBtn);       // Write Value to a given button defined in the specified VDJ
  73. BOOL        SetDiscPov(int Value, UINT rID, UCHAR nPov);    // Write Value to a given descrete POV defined in the specified VDJ
  74. BOOL        SetContPov(DWORD Value, UINT rID, UCHAR nPov);  // Write Value to a given continuous POV defined in the specified VDJ
  75.  
  76. ]]
  77.  
  78. if vjoy.vJoyEnabled() then
  79.     print(ffi.string(vjoy.GetvJoyManufacturerString()))
  80.     print(ffi.string(vjoy.GetvJoyProductString()))
  81.     print(ffi.string(vjoy.GetvJoySerialNumberString()))
  82.  
  83.     local dllVer = ffi.new("WORD[1]")
  84.     local drvVer = ffi.new("WORD[1]")
  85.  
  86.     local match = vjoy.DriverMatch(dllVer, drvVer)
  87.  
  88.     if match then
  89.         print(string.format("VJOY: Driver version %i matches DLL version %i", tonumber(drvVer[0]), tonumber(dllVer[0])))
  90.     else
  91.         print(string.format("VJOY: Driver version %i MISMATCHES DLL version %i", tonumber(drvVer[0]), tonumber(dllVer[0])))
  92.     end
  93. end
  94.  
  95. return vjoy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement