Quantcast

Jump to content

» «
Photo

Game Input - Xbox 360 Gamepad Support

19 replies to this topic
Billsy93
  • Billsy93

    Player Hater

  • Members
  • Joined: 07 May 2013

#1

Posted 16 May 2013 - 10:13 PM Edited by Billsy93, 16 May 2013 - 10:56 PM.

Hello,

I'm writing some mods for GTA IV in C++ (file format .asi) and I was wondering if it's possible to toggle the input of the xbox 360 controller in order to perform actions within created mods?

Specifically I want the player to be able to teleport when the xbox 360 controller 'A' (green) button is pressed as oppose to a keyboard button.

Edit: I've found this function in scripting.h within the scripthook.sdk directory;

CODE
static b8 IsButtonPressed(u32 padIndex, ePadButton button) { return NativeInvoke::Invoke<NATIVE_IS_BUTTON_PRESSED, b8>(padIndex, button); }


My question now is, how do I find the values for the padIndex and ePadButton parameters?

Thanks,

Billsy

Mordecki
  • Mordecki

    Scripter

  • Members
  • Joined: 10 Jul 2006
  • Poland

#2

Posted 29 May 2013 - 11:19 AM Edited by MOrdecki, 29 May 2013 - 11:29 AM.


Look into ScriptingEnums.h

CODE
enum ePadButton
{
 BUTTON_BACK = 0xD,
 BUTTON_START = 0xC,
 BUTTON_X = 0xE,
 BUTTON_Y = 0xF,
 BUTTON_A = 0x10,
 BUTTON_B = 0x11,
 BUTTON_DPAD_UP = 0x8,
 BUTTON_DPAD_DOWN = 0x9,
 BUTTON_DPAD_LEFT = 0xA,
 BUTTON_DPAD_RIGHT = 0xB,
 BUTTON_TRIGGER_LEFT = 0x5,
 BUTTON_TRIGGER_RIGHT = 0x7,
 BUTTON_BUMPER_LEFT = 0x4,
 BUTTON_BUMPER_RIGHT = 0x6,
 BUTTON_STICK_LEFT = 0x12,
 BUTTON_STICK_RIGHT = 0x13
};



In your case you might use this:
CODE
if(IsButtonPressed(0, BUTTON_A))  // the first 0 depends on controller ID you are using, i suggest you are using only one at time


Have fun!

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#3

Posted 31 May 2013 - 12:16 AM

QUOTE (MOrdecki @ Wednesday, May 29 2013, 11:19)
Look into ScriptingEnums.h

CODE
enum ePadButton
{
 BUTTON_BACK = 0xD,
 BUTTON_START = 0xC,
 BUTTON_X = 0xE,
 BUTTON_Y = 0xF,
 BUTTON_A = 0x10,
 BUTTON_B = 0x11,
 BUTTON_DPAD_UP = 0x8,
 BUTTON_DPAD_DOWN = 0x9,
 BUTTON_DPAD_LEFT = 0xA,
 BUTTON_DPAD_RIGHT = 0xB,
 BUTTON_TRIGGER_LEFT = 0x5,
 BUTTON_TRIGGER_RIGHT = 0x7,
 BUTTON_BUMPER_LEFT = 0x4,
 BUTTON_BUMPER_RIGHT = 0x6,
 BUTTON_STICK_LEFT = 0x12,
 BUTTON_STICK_RIGHT = 0x13
};



In your case you might use this:
CODE
if(IsButtonPressed(0, BUTTON_A))  // the first 0 depends on controller ID you are using, i suggest you are using only one at time


Have fun!

nice, do you know if its possible detect Stick X/Y values with native calls?

Soyeldiablo
  • Soyeldiablo

    Player Hater

  • BUSTED!
  • Joined: 31 May 2013

#4

Posted 31 May 2013 - 01:38 AM Edited by Soyeldiablo, 31 May 2013 - 01:40 AM.

CODE
void GetStickPos(out int a , out int b, out int c, out int d)
{
   GTA.Native.Pointer pA = typeof(Int32);
   GTA.Native.Pointer pB = typeof(Int32);
   GTA.Native.Pointer pC = typeof(Int32);
   GTA.Native.Pointer pD = typeof(Int32);

   GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);

   a = Convert.ToInt32(pA.Value);
   b = Convert.ToInt32(pB.Value);
   c = Convert.ToInt32(pC.Value);
   d = Convert.ToInt32(pD.Value);
}


metadata won't save u ;P

hardsty1e
  • hardsty1e

    RIP Yeardley Diamond

  • Members
  • Joined: 02 May 2009
  • Philippines

#5

Posted 31 May 2013 - 01:44 AM

CODE

if(protection){
 uint pos[4];
 GET_POSITION_OF_ANALOGUE_STICKS(0,&pos[0],&pos[1],&pos[2],&pos[3]);
 if(pos[0] == 0 && pos[1] == 0)
  FREEZE_CHAR_POSITION(pPlayer,true);
 else
  FREEZE_CHAR_POSITION(pPlayer,false);
}


neat, ill just put this here also

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#6

Posted 31 May 2013 - 11:03 AM

QUOTE (Soyeldiablo @ Friday, May 31 2013, 01:38)
CODE
void GetStickPos(out int a , out int b, out int c, out int d)
{
   GTA.Native.Pointer pA = typeof(Int32);
   GTA.Native.Pointer pB = typeof(Int32);
   GTA.Native.Pointer pC = typeof(Int32);
   GTA.Native.Pointer pD = typeof(Int32);

   GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);

   a = Convert.ToInt32(pA.Value);
   b = Convert.ToInt32(pB.Value);
   c = Convert.ToInt32(pC.Value);
   d = Convert.ToInt32(pD.Value);
}


metadata won't save u ;P

lol, the metadata guy ^^

thx

GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);

damm, this is the only time when i think that is bad idea use VB.Net instead of C# sad.gif

Soyeldiablo
  • Soyeldiablo

    Player Hater

  • BUSTED!
  • Joined: 31 May 2013

#7

Posted 31 May 2013 - 04:06 PM

CODE
GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);


Forgot a comma and yes vb is garbage but y can't u translate this to vb??

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#8

Posted 01 June 2013 - 11:40 AM

QUOTE (Soyeldiablo @ Friday, May 31 2013, 16:06)
CODE
GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);


Forgot a comma and yes vb is garbage but y can't u translate this to vb??

i guess that we cant use pointers like this method needs, but im not sure

Soyeldiablo
  • Soyeldiablo

    Player Hater

  • BUSTED!
  • Joined: 31 May 2013

#9

Posted 03 June 2013 - 03:30 AM Edited by Soyeldiablo, 03 June 2013 - 03:42 AM.

QUOTE (julionib @ Saturday, Jun 1 2013, 11:40)
QUOTE (Soyeldiablo @ Friday, May 31 2013, 16:06)
CODE
GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);


Forgot a comma and yes vb is garbage but y can't u translate this to vb??

i guess that we cant use pointers like this method needs, but im not sure

im pretty sure u can, the Pointer object is in the GTA.Native namespace, just add to your Imports

and btw, i never mentioned... a value is for horizontal axis on left stick and b is vertical axis on left stick, c and d are same but for right stick

example:

values range -100 to 100 (iirc, need to verify)

a = -10 ... left stick little left
b = 50 ... left stick half way forward
c = 30 ... right stick 30% right
d = -40 ... right stick 40% down

please verify

also u should use with this so u dont call unnecessaryily, im sure checking if using controller is more efficient when not using a controller

CODE
Function.Call<bool>("IS_USING_CONTROLLER")

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#10

Posted 03 June 2013 - 12:28 PM

nice

this "IS_USING_CONTROLLER" is very useful


the use of XNA Dll or SlimDX Dll to have access to xbox control input its good but has some side effects like some people that just cant load the mod or bad precision (like i had with slimDx), so its better try to do all with native calls

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#11

Posted 03 June 2013 - 12:48 PM

this is beautiful, thx for the tip, now i can use this same pointer idea for a lot of methods, damm i was stuck with some script ideas because i tought it was impossible to use some native calls in VB.net and i was too lazy to migrate to C# ^^


CODE
Dim P1, P2, P3, P4 As GTA.Native.Pointer

P1 = New GTA.Native.Pointer(GetType(Int32))
P2 = New GTA.Native.Pointer(GetType(Int32))
P3 = New GTA.Native.Pointer(GetType(Int32))
P4 = New GTA.Native.Pointer(GetType(Int32))

Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", 0, P1, P2, P3, P4)

msg("Res: p1: " & P1.ToString & "   p2: " & P2.ToString & "   p3: " & P3.ToString & "   p4: " & P4.ToString, 1500)



the values go from -127 to 127 for each axis in each stick

Soyeldiablo
  • Soyeldiablo

    Player Hater

  • BUSTED!
  • Joined: 31 May 2013

#12

Posted 03 June 2013 - 04:26 PM

Yeah I was wondering why all these mods are being released using xna stuff when gta already does it

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#13

Posted 03 June 2013 - 08:27 PM

QUOTE (Soyeldiablo @ Monday, Jun 3 2013, 16:26)
Yeah I was wondering why all these mods are being released using xna stuff when gta already does it

yeah, it makes more complicated to install, some people ignore the file and the game just crash at loading screen when script loads
i guess that its indicated to games/programs that cant have direct access to xbox control

now i will upgrade some scripts with this native methods.

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#14

Posted 03 June 2013 - 09:02 PM

Excellent posts on this topic.

And what about the back triggers ? They are also analog inputs. Can they be accessed the same way ?

adsvsdvasdvasdv
  • adsvsdvasdvasdv

    Player Hater

  • BUSTED!
  • Joined: 03 Jun 2013

#15

Posted 03 June 2013 - 11:56 PM Edited by adsvsdvasdvasdv, 04 June 2013 - 12:04 AM.

QUOTE (pedro2555 @ Monday, Jun 3 2013, 21:02)
Excellent posts on this topic.

And what about the back triggers ? They are also analog inputs. Can they be accessed the same way ?

new name... same person haha...

CODE
bool LeftTriggerPressed()
{
   return Function.Call<bool>("IS_CONTROL_PRESSED", 0, 6);
}

Game.isGameKeyPressed(GameKey.Attack)//right trigger


note GameKey.Aim only detects right mouse button and not left trigger so u must wrap the native yourself wink.gif

i suggest u guys actually look at the code ur writing and u would already know this... so get ilspy or whatever and look at the code in the shdn... everything is there wink.gif

or look at the gtaiv game scripts that were decompiled by alexander blade i think

you wont need to ask if u do the research wink.gif

user posted image

adsvsdvasdvasdv
  • adsvsdvasdvasdv

    Player Hater

  • BUSTED!
  • Joined: 03 Jun 2013

#16

Posted 04 June 2013 - 01:20 AM Edited by adsvsdvasdvasdv, 04 June 2013 - 01:27 AM.

This is how u reverse needed parameter for is_control_pressed

CODE
void GetInputPressedValues_Tick(object sender, EventArgs e)
{
   for (int i = 0; i < 1500; i++)
       if (Function.Call<bool>("IS_CONTROL_PRESSED", 0, i)
           Game.DisplayText(i.ToString() + " pressed");
}


Btw I forgot what the max value is but change 1500 to max value + 1

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#17

Posted 04 June 2013 - 10:34 AM

yep, sometimes im just too much lazy to do an search in the SCOCL or scripthook source code ^^

if was looking there now and find an interesting point related to the analogue sticks:

CODE
void Game::GetMovement(int* x, int* y) {
 int x2 = 0; int y2 = 0;
 *x = 0; *y = 0;
 Scripting::GetPositionOfAnalogueSticks(0, x, y, &x2, &y2);
 if ((*x == 0) && (*y == 0)) Scripting::GetKeyboardMoveInput(x, y);
}



this is one side effect of having an "easy" method like XNA or SlimDX, we forget about game natives



but about what pedro asked, i guess that he want to know how much the trigger is pressed, we have this data on SlimDX and XNA but i guess that we dont have with native calls

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#18

Posted 05 June 2013 - 12:19 AM

Just to clarify what buttons I'm talking about, it's AXIS 3. Left and Right Triggers. I think SlimDX returns a byte value 0 to 255.

user posted image

Researching for this just takes too long, I would love to have the time thought.

hellothereyoupieceofshit
  • hellothereyoupieceofshit

    Player Hater

  • BUSTED!
  • Joined: 05 Jun 2013

#19

Posted 05 June 2013 - 05:00 AM

im sure it can be done since vehicle acceleration is based on pressure of triggers, if u cant find a native then i suppose use a 3rd party lib

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#20

Posted 27 July 2013 - 01:42 PM

QUOTE (hellothereyoupieceofsh*t @ Wednesday, Jun 5 2013, 05:00)
im sure it can be done since vehicle acceleration is based on pressure of triggers, if u cant find a native then i suppose use a 3rd party lib

Thats why I used SlimDX with Ultimate Fuel Script, I rely exclusively in AXIS3, which apparently isn't obtainable via natives.

Correct me if I'm wrong ,but vehicle control isn't handled by native calls at all, so there is no reason for AXIS3 to be available via native calls.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users