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)
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Blackthorne on 05 Apr 2020, 16:44
Yep, I'm getting the same error as Aaron.  "error loading plugin 'agscontroller.dll', it may depend on another DLL that is missing."
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: JanetC on 16 Sep 2020, 03:32
Yep, I'm getting the same error as Aaron.  "error loading plugin 'agscontroller.dll', it may depend on another DLL that is missing."

Was this ever resolved? I'm getting the same error. I'm using AGS 3.4.1 Patch 3.

Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: JanetC on 17 Sep 2020, 01:54
OK the solution is to not use the SDL2.dll provided.

Use the 32-bit version from here:

https://www.libsdl.org/download-2.0.php
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Dualnames on 17 Sep 2020, 21:59
Am I supplying a 64bit version of SDL2.dll?
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: morganw on 17 Sep 2020, 22:21
Am I supplying a 64bit version of SDL2.dll?

Yes.

Code: [Select]
$ file SDL2.dll
SDL2.dll: PE32+ executable (DLL) (console) x86-64 (stripped to external PDB), for MS Windows
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Stranga on 23 Oct 2020, 07:10
Hello there! I've managed to get the plugin to work and it works fine with my controller. I am having a little trouble setting it up though. Is there any way to use these in the on_keypress function? A lot of my menu navigation code is in there and I sorta don't want to re do everything in an rep_ex function to control gamepad input(If possible that is!). Any help would be greatly appreciated.

P.S I forgot to mention, the reason I want to use it in the on_keypress function is if I hold a button down in the rep_ex function it loops repeatedly and I'm not sure if there's a way to check if the POV/dpad has only been pressed once?
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Dualnames on 04 Nov 2020, 18:42
I believe there is a function called IsButtonDownOnce, does that not work with pov,dpad?

If not u can set a simple check

Code: Adventure Game Studio
  1. bool LEFT=false;
  2. bool RIGHT=false;
  3. bool UP=false;
  4. bool DOWN=false;
  5.  
  6. function HitNoDirection()
  7. {
  8. LEFT=false;
  9. RIGHT=false;
  10. UP=false;
  11. DOWN=false;
  12. }
  13.  
  14. function repeatedly_execute()
  15. {
  16.  
  17. if (gamepad.GetAxis(0) < -200 && !LEFT)
  18. {
  19.  HitNoDirection();
  20. LEFT=true;
  21. //LEFT
  22. }
  23. else if (gamepad.GetAxis(0) > 200 && !RIGHT)
  24. {
  25.  HitNoDirection();
  26. RIGHT=true;
  27. //RIGHT
  28. }
  29. else if (gamepad.GetAxis(1) > 200 && !DOWN)
  30. {
  31.  HitNoDirection();
  32. DOWN=true;
  33. //DOWN
  34. }
  35. else if (gamepad.GetAxis(1) < -200 && !UP)
  36. {
  37.  HitNoDirection();
  38. UP=true;
  39. //UP
  40. }
  41. else
  42. {
  43.  HitNoDirection();
  44. }
  45. }
  46.  
  47.  
  48.  
Title: Re: [PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1
Post by: Olleh19 on 05 Nov 2020, 12:35
Hi!

I have been trying to use the Rumble feature, but i can't seem to change the values at all. Apart from raising the duration ???
Am i doing something wrong?
All i can change is the durations length but when i try to lower it. It rumbles 4ever instead. So i've deicided to use it as a neckmassage device when my neck hurts after drawing too much pixelart, kidding (laugh)
Is it a bug or am i not understanding the concept, i've tried lowering from 40 to 30 or 35 or such. Should i lower in specific values? If so please write some that you think might work.
I want "fast" short rumbles for an impact, not these 40 game loops rumbles!  (wrong)

Wished i knew what was wrong. This is the only code that works, if i change this a little either it rumbles forever. or if i raise the duration to 100 it will go for 100game loops, etc. But the other values, no

Edit: Should the gamespeed be set to 30 if i want 30 loops to work? :/ Don't want to do that, ofc.

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