[WIP] GCDAPI (ConsoleTuner) API - Control Consoles with AHK! (Needs $40 hardware)

Post gaming related scripts
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

[WIP] GCDAPI (ConsoleTuner) API - Control Consoles with AHK! (Needs $40 hardware)

14 Sep 2016, 18:50

OK, this post will evolve, I just wanted to share with you something that I managed to get working tonight.

AutoHotkey, running on a PC, controlling a console by emulating a controller via a Titan One USB device plugged into the console.

To use, place gcdapi.dll in the same folder as the script, connect the PC to the Titan One via the PCPROG port, then plug it into the console.

Instantiate the class: titan := new gcdapi()

Then, you can operate buttons using titan.output.SetButtonByIndex(index, state) or titan.output.SetButtonByName(name, state). State is 0 or 1
You can operate axes using titan.output.SetAxisByIndex(index, state) or titan.output.SetAxisByName(name, state). State is 0...100

Currently only supports XBox.
Buttons 1-10: A, B, X, Y, LB, RB, Back, Start, LS, RS
XBox (index 0) is the Xbox button
Axes: LX, LY, RX, RY, LT, RT

Library and sample code that binds F11 to A, and moves LX when you hit F12

Code: Select all

#SingleInstance force
; Horrible hack for now, make the write array super-global
; You only appear to be able to set everything at once
; So storing this allows us to make incremental changes
global GCINPUT
VarSetCapacity(GCINPUT, 36)

titan := new gcdapi()

return

F11::
	titan.output.SetButtonByName("A", 1)
	return

F11 up::
	titan.output.SetButtonByName("A", 0)
	return

F12::
	titan.output.SetAxisByName("LX", 100)
	return

F12 up::
	titan.output.SetAxisByName("LX", 0)
	return

class gcdapi {
	__New(){
		this.hModule := DLLCall("LoadLibrary", "Str", "gcdapi.dll", "Ptr")
		
		; ToDo: Read state of Titan One and instantiate appropriate class.
		; For now, hard-wire to XBox 360
		this.output := new this.gcdapi_xb360()
		DllCall("gcdapi\gcdapi_Load", "Uint")
	}
	
	__Delete(){
		ret := DllCall("gcdapi\gcdapi_Unload")
		DllCall("FreeLibrary", "Ptr", this.hModule)
	}
	
	class gcdapi_xb360 extends gcdapi.output {
		; Maps Buttons to Identifiers. Indexes are same as DI button indexes. XBox button is 0
		ButtonMappings := [19,18,20,17,6,3,1,2,8,5,0]
		; Maps Axes to Identifiers
		AxisMappings := [11,12,9,10,7,4]
		 ; Lookup for Button Indexes -> Name
		ButtonIndex := {0:"XBox", 1:"A", 2:"B", 3:"X", 4:"Y", 5:"LB", 6:"RB", 7:"Back", 8:"Start", 9:"LS", 10:"RS" }
		; Lookup for Name -> Button Index
		ButtonAssoc := {XBox:0, A:1, B:2, X:3, Y:4, LB:5, RB:6, Back:7, Start:8, LS:9, RS:10}
		; Lookup for Axis Index -> Name
		AxisIndex := ["LX", "LY", "RX", "RY", "LT", "RT"]
		; Lookup for Axis Name -> Index
		AxisAssoc := {LX:1, LY:2, RX:3,RY:4,LT:5,RT:6}
	}
	
	class output {
		SetButtonByIndex(btn, state){
			if (btn > 10){
				return 0
			}
			NumPut(state * 100, GCINPUT, this.ButtonMappings[btn], "char")
			ret := DllCall("gcdapi\gcapi_Write", "uint", &GCINPUT)
			return 1
		}
		
		SetButtonByName(btn, state){
			if (ObjHasKey(this.ButtonAssoc, btn)){
				return this.SetButtonByIndex(this.ButtonAssoc[btn], state)
			} else {
				return 0
			}
		}
		
		SetAxisByIndex(axis, state){
			if (axis > 6){
				return 0
			}
			VarSetCapacity(GCINPUT, 36)
			NumPut(state, GCINPUT, this.AxisMappings[axis], "char")
			ret := DllCall("gcdapi\gcapi_Write", "uint", &GCINPUT)
			return 1
		}
		
		SetAxisByName(axis, state){
			if (ObjHasKey(this.AxisAssoc, axis)){
				return this.SetAxisByIndex(this.AxisAssoc[axis], state)
			} else {
				return 0
			}
		}
	}
}
Last edited by evilC on 16 Sep 2016, 19:55, edited 1 time in total.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: [WIP] GCDAPI (ConsoleTuner) API - Control Consoles with AHK! (Needs $40 hardware)

14 Sep 2016, 19:31

Nice. An interesting idea: Intel Galileo (or similar) with this running (WinPE would work, yes? If not, a super-stripped XP/W7), plugged into the Titan One, plugged into the console. Fully portable solution.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: [WIP] GCDAPI (ConsoleTuner) API - Control Consoles with AHK! (Needs $40 hardware)

15 Sep 2016, 04:26

Generally, the limiting factor with these devices is what modes the USB controller is able to run in.
A USB port on the Galileo is likely only going to behave as a USB host (Something you can plug devices into) and not as a USB client (Something you plug in to a USB host).
The Titan One has very interesting applications for pure PC gaming also, because you can plug a controller into it and the host system does not see the controller, but you can still read the controller via the API.
This will potentially allow for true remapping of devices in UCR - just plug the stick into the Titan, read it's value using the API, then create a vJoy stick (Soon vJoy will be supporting virtual DirectInput, XInput and PS controllers) that mimics the behavior you desire.
The game can only see one controller, so no more messing around trying to get the game to bind to the virtual controller.

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 61 guests