Adventure Game Studio | Forums

AGS Support => Modules & Plugins => Topic started by: Dualnames on 30 Apr 2019, 03:20

Title: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Dualnames on 30 Apr 2019, 03:20
1. Prologue:

I know that Wyz is an incredibly busy man, and has barely managed to maintain the source of the AGS Joystick Plugin, given that, and given that I'm also implementing a version of it with SDL, it seems fitting to disengage the two things between them. A majority of the code has been written/based off code by eri0o and Wyz, so kudos go to them! The inclusion of the SDL library allows for two important things:
1) XInput recognition
2) Cross-platform

2. Instructions/Going through the functions

The only thing u have to do, is make sure u put SDL2.dll inside ur debug and compiled folders, otherwise you'll get error messages. The dll will be provided below.

int ControllerCount ()

This returns the number of gamecontrollers found, from 0 to N controllers.





Controller Properties & Functions

The plugin uses a custom typedef which is 'Controller'. Controller is self-explanatory, and has a couple of functions and attributes.

Code: Adventure Game Studio
  1. Controller*gamepad;
  2. function game_start()
  3. {  
  4.   gamepad = Controller.Open(0);
  5. }
  6.  
  7.  


Code: Adventure Game Studio
  1. if (gamepad.GetAxis(0) < -200)
  2. {
  3. //LEFT
  4. }
  5. else if (gamepad.GetAxis(0) > 200)
  6. {
  7. //RIGHT
  8. }
  9.  


Code: Adventure Game Studio
  1. if (gamepad.GetPOV() == ePOVUp)
  2. {
  3.     cEgo.y--;
  4. }
  5.  


Code: Adventure Game Studio
  1. int i=0;
  2. String app="";
  3. while (i < gamepad.ButtonCount+2)
  4. {
  5.   app = app.Append(String.Format("button %d is %d[",i, gamepad.IsButtonDown(i)));
  6.   i++;
  7. }
  8. cEgo.SayBackground(app);
  9. //this will parse all the buttons' states and print them on the screen.
  10.  


Code: Adventure Game Studio
  1. if (gamepad.IsButtonDownOnce(11))
  2.     {
  3.        //click on UI
  4.     }
  5.  


Code: Adventure Game Studio
  1. if (gamepad.IsButtonDownOnce(11))
  2.     {
  3.       gamepad.Rumble(65535, 65535, 40);    
  4.     }
  5.  

v1.1

-Added two new functions


Code: Adventure Game Studio
  1. lblstatus.Text=String.Format("BATTERY STATUS: %d",gamepad.BatteryStatus());
  2.  


Code: Adventure Game Studio
  1. while (gamepad.PressAnyKey()==-1)
  2.     {
  3.       Wait(1);
  4.     }
  5.     player.Say("Button pressed is button %d",gamepad.PressAnyKey());
  6.  




3. Download links

AGSController.dll (https://github.com/Dualnames1/AGS-Controller/releases/download/1.1.0/AGSController.dll)
SDL2.dll (https://github.com/Dualnames1/AGS-Controller/releases/download/1.1.0/SDL2.dll)

*ZIP file containing both* (http://primordia-game.com/Files0/AGSController.zip)

4. Source

The source files can be found on GITHUB  (https://github.com/Dualnames1/AGS-Controller)
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Vincent on 30 Apr 2019, 08:12
This is really nice Dualnames, fantastic work! Somehow does this revisited version will prevent the error: Joystick is plugged in then you save the game, unplug the joystick and try to restore the game properly fine? Or Joystick is plugged in then you save the game, export the saved game file to another computer with same ags version, unplug the joystick and try to run the game? Because in the version I have of the plugin this will crash. bool isPlugged or bool isValid doesn't seem to fix the problem.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Dualnames on 30 Apr 2019, 09:18
Pretty sure, I can specifically run this test for you!

EDIT: Yep, no crashes!
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Vincent on 30 Apr 2019, 10:03
Alright thanks a lot for testing this! Sorry for the dumb question, so it is AGSController.dll different from agsjoy.dll? I don't think if I just replace the plugin my script would still work.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Dualnames on 30 Apr 2019, 20:28
You need to replace the functions as well. And it is different. Did a minor update for the upcoming release of AGS (which includes SDL and would cause issues)
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Vincent on 30 Apr 2019, 22:22
Alright thanks for the further clarification, I look forward to attempt this plugin on a next time.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE)
Post by: Dualnames on 06 May 2019, 18:05
v1.1

-Added two new functions


Code: Adventure Game Studio
  1. lblstatus.Text=String.Format("BATTERY STATUS: %d",gamepad.BatteryStatus());
  2.  


Code: Adventure Game Studio
  1. while (gamepad.PressAnyKey()==-1)
  2.     {
  3.       Wait(1);
  4.     }
  5.     player.Say("Button pressed is button %d",gamepad.PressAnyKey());
  6.  
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Jack on 06 May 2019, 18:23
Cool, Dualnames!

I also like that you added the value after "wired" called MAX in case the user gets struck by lightning.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Dualnames on 06 May 2019, 21:14
It's what SDL returns, im not sure why they have a 100% and a max, but here it is.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Aaron Best on 14 Oct 2019, 19:13
I'm getting the error there was an error loading plugin 'agscontroller.dll', it may depend on another DLL that is missing.

I have both the files in the correct locations - any ideas?

Thanks in advance.

Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: eri0o on 14 Oct 2019, 19:35
What are the correct locations? Both must also be added on the AGS Editor directory itself.
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Aaron Best on 14 Oct 2019, 19:42
I've placed them into the AGS directory, plus in the specific game's debug and compiled folders.

I'm getting the error message on startup of AGS.

Thanks
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: eri0o on 14 Oct 2019, 19:46
Ah, in this case, there's a chance the build isn't including the redistributable VC stuff - use MT flag on Visual Studio C++ compiler.

Can you try the build here? I am not sure they are correctly configured though. (I briefly read the vcxproj xml file but couldn't find mention of the MT flag... Also the build is suspectly small. It still needs the SDL.dll)

https://github.com/ericoporto/AGS-Controller/releases/tag/1.1.1

If this is the case (the above build doesn't work), I can fix later. (I don't have VS right now and managed to expire my azure connection credentials for this repo, so I can't build things right now)