Bob-Z / AIRoR

Apache License 2.0
1 stars 0 forks source link

Compatibility with the release version of RoR (Windows) #2

Open WillyB1337 opened 3 years ago

WillyB1337 commented 3 years ago

Hey there. I remember seeing your repo on the Rigs of Rods Discord.

It was mentionned that you were using a custom version of RoR where it outputs the coordinates every frame to console or something like that. Is it still true?

Could I like run the python code in the current version of RoR without modification needed?

WillyB1337 commented 3 years ago

Also, you do instruct commands to run under Linux. Is the script compatible with Windows Python environnent?

Bob-Z commented 3 years ago

I have always used stock RoR. Either release (https://rigs-of-rods.itch.io/rigs-of-rods#download) or develop build (https://rigs-of-rods.itch.io/rigs-of-rods-dev). It outputs coordinate every 200 ms (more or less) on my PC. I didn't dig in source code to understand why.

It works with Linux only because I use a python lib called libevdev which AFAIK is not available on Windows.

WillyB1337 commented 3 years ago

Would there be an alternative to libvdev on Windows? I'm not a coder myself but pip do install libevdev on Windows but it gives an error about "libevdev.so.2 not found" Don't know if pip just ignores the what OS it installs to but would be useful to check it out.

I should ask the current devs to try your thing out to see if it works on their end.

WillyB1337 commented 3 years ago

I could jump in the code base if the work required to make it Windows compatible is not too hard. I would like to add you on Discord. Mine is WillyB1337#1337

Bob-Z commented 3 years ago

libevdev uses evdev which is an Xorg generic driver. It won't work on Windows. An equivalent lib on Windows should be able to plug a "virtual joystick" at system level and control it (this is what is done by libevdev). Anyway, I have no Windows based machine available so I won't be able to integrate it myself.

I have no Discord account, we can continue on this topic if you want

WillyB1337 commented 3 years ago

Ok then. I did find this module for Windows. PyWinUSB Also this : Inputs

If your libevdev/evdev just hooks on the keyboard to send inputs (or a virtual controller for more precise inputs), these modules might work.

Inputs is cross-platform so it might be even a replacement if his integration is not too hard. I'll get the Python kit for VS Code to get started on it,

If you do have a better way to communicate (telegram maybe), let me know.

WillyB1337 commented 3 years ago

Right now, my initial goal is to remove libevdev and replace this module with a Windows equivalent. Looking at it, you are creating a virtual Xbox 360 controller.

Under Windows, there's software to emulate input of anything to an XBOX controller. I could remove the part of the creation of the device and just uses a device made externally. Will try. https://github.com/Bob-Z/AIRoR/blob/00bfb2b67aaad72d7e279fffb640c3eec93d5b66/Command.py#L7

Bob-Z commented 3 years ago

If you find python code to control this emulated controller, it may works !

WillyB1337 commented 3 years ago

Got to install vJoy for Windows as well as the pyvjoy module for interacting with its API. I might just be an easy job to do.

Test code

import pyvjoy

#Pythonic API, item-at-a-time

j = pyvjoy.VJoyDevice(1)

#turn button number 15 on
j.set_button(15,1)

#Notice the args are (buttonID,state) whereas vJoy's native API is the other way around.

#turn button 15 off again
j.set_button(15,0)

#Set X axis to fully left
j.set_axis(pyvjoy.HID_USAGE_X, 0x1)

#Set X axis to fully right
j.set_axis(pyvjoy.HID_USAGE_X, 0x8000)

#Also implemented:

j.reset()
j.reset_buttons()
j.reset_povs()

#The 'efficient' method as described in vJoy's docs - set multiple values at once

j.data
>>> <pyvjoy._sdk._JOYSTICK_POSITION_V2 at 0x....>

j.data.lButtons = 19 # buttons number 1,2 and 5 (1+2+16)
j.data.wAxisX = 0x2000 
j.data.wAxisY= 0x7500

#send data to vJoy device
j.update()

#Lower-level API just wraps the functions in the DLL as thinly as possible, with some attempt to raise exceptions instead of return codes.
Bob-Z commented 3 years ago

It sounds promising. I have just pushed a wrapper on top of Command.py. So you just have to create CommandWindows.py and fill it will the corresponding set_button, set_axis call (and add "else" to the "if os.name == 'posix':" lines in Command.py)