psibaspace | psiba’s notes

Oct/08

11

XBOX 360 Controllers in Adobe Flash

After wanting for many years to be able to get full access to analogue gamepads in flash, a friend showed me the work Thibault Imbert has done to get standard gamepads into flash using a C# socket server and the new ByteArray functionality of actionscript 3.

I took his code and stripped out directx, brought in XNA to grab the XBOX 360 gamepad values and built in support for multiplayer and the ability to specify the polling interval and port number.

I also created an XBOX 360 controller manager class in as3. It manages all the network code for you. Inside the demo flash file you will find four movieclips on the root of the scene and each movieclip is a copy of a nastily hacked together demo showing how to use the manager.

Its quite simple to find out if player 1 has the X button pressed, you simply call
XBOX360Manager.getState(1).X;
To see the data structure of the object passed back by getState, simply check out the com.GamePads.XBOX360GamepadState.

I will work on making an equivalent as2 server, as I myself still like to use as2 for really cheap and nasty gameplay prototypes. Unfortunately without binary socket support in as2, I will need to generate xml, and use an xml socket. This will run slower and will take some time to code… so bare with me or beat me to it!

To download the files check out the projects page.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Add to favorites
  • email
  • FriendFeed
  • LinkedIn
  • MySpace
  • N4G
  • PDF
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

· · ·

31 comments

  • Dean · October 16, 2008 at 9:22 pm

    Woooahz!! Thats mega cooL!

  • Smeg · October 17, 2008 at 10:15 am

    Wooo! I love it. Great job!
    Consider the planet hacked!

  • Ricky Haggett · October 23, 2008 at 5:35 am

    This works great in XP.

    However, in Vista, I get error when trying to Run Server:
    “An address incompatible with the requested protocol was used”.

    And above the Run Server button, the Server IP Address seems to be garbage:
    fe80::388f::33bd:3f57:fe9a%12.

    Any chance of a Vista compatible version?

  • Admin comment by psiba · October 23, 2008 at 8:09 pm

    Ricky:

    It seems that Vista breaks the server because Vista defaults to IPV6 and the code isn’t built to support that.

    I’ll resolve this and get back to you.

  • Ricky Haggett · October 24, 2008 at 6:59 pm

    That’d be great – much appreciated!

  • Carsten · December 5, 2008 at 6:34 am

    Thanks, it’s great.
    Is it possible in any way to send data back to the server for rumble?

    That would be amazing :)

  • Joe · March 21, 2009 at 9:09 am

    How did that IPv6 / IPv4 issue turn out? I’m trying to fix it in the source myself, but have little to no idea what I’m doing.

  • Admin comment by psiba · April 1, 2009 at 10:36 am

    Vista is now supported.

    Rumble might be a while off as I have a lot on my plate at the moment. Announcements to come…

  • Ryan · October 22, 2009 at 8:30 am

    Sounds great… Just need to see if I can apply it to a PS3 controller instead!

  • mike boski · December 23, 2009 at 3:08 am

    I still have the Vista problem

    And above the Run Server button, the Server IP Address seems to be garbage:
    fe80::388f::33bd:3f57:fe9a%12.

    are the latest compiled files available.

  • mike boski · December 23, 2009 at 5:36 am

    Also tried on XP with .Net 2.0 sp2 and XNA

    but get an error:

    System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at FlashStick.MainClass.UpdateInputAndSendData(Object sender, EventArgs eArgs)
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3603 (GDR.050727-3600)
    CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    —————————————-
    XBOX360 Gamepad Server
    Assembly Version: 1.0.3369.20792
    Win32 Version: 1.0.3369.20792
    CodeBase: file:///C:/Documents%20and%20Settings/Michael/Desktop/XBOX360inFlash/bin/Release/XBOX360%20Gamepad%20Server.exe
    —————————————-
    System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    —————————————-
    System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    —————————————-
    System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    —————————————-
    System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    —————————————-
    System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    —————————————-

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

  • mike boski · December 23, 2009 at 2:47 pm

    more info

    when compiling in Visula C# 2008

    I get this message
    A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in System.dll

  • mike boski · December 23, 2009 at 4:14 pm

    Tracked down the issue had to do a directX update.

    I read this is a common problem on another webiste.
    only took 8 hours but got it working.

    This is awesome thanks so much.

    Mike

  • Admin comment by psiba · December 24, 2009 at 12:44 am

    If anyone feels like making this into a google code project, adding rumble or AS2 support themselves, i’m all for it.

  • Using XBox360 controllers in the Flash Player « Flash Life · April 7, 2010 at 2:37 pm

    [...] It’s not pretty but it can be done, I wonder what kind of delays it has since the data is being passed around as a Byte Array from C#, check out the blog post. [...]

  • Kirill Rybin · April 26, 2010 at 3:42 am

    Program is impressive!) But what about force feedback?) Is it possible to run from flash?
    And i tested on standalone player and it works!) Code compiled with FlashDevelop and FlexSDK 3.5)

  • Roger · August 20, 2010 at 4:16 am

    Any chance anyone has tried this with Silverlight?

  • Yu-Chung Chen · September 15, 2010 at 7:12 pm

    This is just what I needed, thanks for making this.

    I’m having trouble getting it running under Win7 (Pro 64bit German) though. For an XP machine I had the same problem as mike boski which could be solved by updating DirectX. But on my main Win 7 laptop that doesn’t solve the exception I’m getting when clicking on the RUN button. Supposedly a file or assembly is missing: “Microsoft Xna.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=(…)” Although this was just installed and shows up in the Control Panel in the program list.

    Any idea why this might be and how it could be fixed? I need this running on my main Win7 machine because that’s where my Flash development setup is.

    Thanks in advance…

  • Yu-Chung Chen · September 17, 2010 at 7:22 pm

    XNA Framework on 64 bit Windows is apparently a known problem: http://blogs.msdn.com/b/shawnhar/archive/2008/02/25/xna-framework-on-64-bit-windows.aspx

    I had the server recompiled according to that blogpost, now it works on my 64 Win7 machine. I’ve made it available here http://www.mediafire.com/?cuz249a25h8zm29 but you might want to offer the fixed version (either use this or recompile yourself) in your package, so people can be more certain that it’s the real deal.

  • Ricky · September 19, 2010 at 10:47 pm

    Hey Simon,

    I get a crash in Windows 7, details below.

    I’ve disabled IPv6 and installed XNA redist and xbox pad drivers for Win7 (.net comes with Win7)

    Cheers,

    Ricky

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at FlashStick.MainClass.UpdateInputAndSendData(Object sender, EventArgs eArgs)
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4952 (win7RTMGDR.050727-4900)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    —————————————-
    XBOX360 Gamepad Server
    Assembly Version: 1.0.3369.20792
    Win32 Version: 1.0.3369.20792
    CodeBase: file:///C:/Dev/games/Hoho5/XBOX360%20Gamepad%20Server.exe
    —————————————-
    System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    —————————————-
    System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    —————————————-
    System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    —————————————-
    System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    —————————————-
    System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    —————————————-

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

  • Dan · September 28, 2010 at 12:58 am

    Hey there,

    I was wondering if I could use the xBox state manager with a game I am making and enter it into the 2010 indy game contest sponsored by Gamestop which I am trying to win. It won’t be released to the public just a select few judges.

    Please reply promptly because time is a factor.

    Thanks in advance
    Dan

  • Admin comment by psiba · October 2, 2010 at 9:04 am

    Hi Dan, Hopefully you got my email days ago and you were able to use it in the contest. For anyone else that wants to use it in a comp, its totally fine. We’re currently using it for the 48hr Game Making Comp – http://making-games.net/48 (I’m in the comp right now, unshowered and barely slept)

    I’ve fixed the Windows 7 issues and I posted a temporary solution of it here: http://projects.psibaspace.net.au/XBOX360InFlash/48hr2010_solution.zip. Once this comp is over I’ll clean it up and post the new version properly.

  • Live blogging from The 48hr Game Making Challenge 2010 - The Voxel Agents · October 2, 2010 at 4:58 pm

    [...] Hunt” soon, but unfortunately you need Xbox 360 controllers plugged into your PC plus this tool to play it (it’s not [...]

  • DMG · November 27, 2010 at 1:51 am

    Thank you, Yu-Chung Chen! I was having exactly the same problem, and was about to post asking for help when I saw your comment. I downloaded your version of the server, and it works perfectly (on my 64-bit Windows 7 laptop).

    Thank you for putting that together and making it so easily available, and thanks to the original authors too – this is going to make game prototyping much more straightforward!

  • Yu-Chung Chen · January 27, 2011 at 11:22 pm

    Hi psiba,

    Is it possible to expose L3 and R3 as buttons? I.E. when you press the sticks inwards.

    The programmer who recompiled the x64 version for me (my last post, link expired…) is not available anymore so I can’t offer help this time…

  • kleahcim · February 3, 2011 at 8:51 am

    Hey all,

    This is great stuff for prototyping!

    I was wondering if someone has an updated version
    that works on win7 64-bit and includes the two way communication with flash to enable vibration.

    Maybe without the use of XNA things would work easier on win7?

  • Admin comment by psiba · April 29, 2011 at 8:09 pm

    I’ve added L3 and R3 button support and it *should* work in Windows 7 64-bit. Let me know if there are still issues – I don’t have Windows 7 64-bit to test on.

    Thanks Yu-Chung Chen for linking the 64-bit article.

  • DatapawWolf · August 21, 2011 at 1:16 am

    Is there any way to get this working as a standalone SWF file?
    I just want to make a simple game played with a 360 controller.

  • Admin comment by psiba · August 24, 2011 at 12:14 am

    Hey man, just worked this out. you should be able to export in Flash using the publish settings of “network access” rather than local file access. Then it should run in the browser or standalone player. I made a quick demo and it worked (green means player 1 was connected), see http://blog.psibaspace.net.au/wp-content/uploads/2011/08/FlashDEMO.swf-Google-Chrome_2011-08-24_000007.png, but i did it in flash develop using this setting. http://blog.psibaspace.net.au/wp-content/uploads/2011/08/FlashDEMO-FlashDevelop_2011-08-24_000009.png

  • DatapawWolf · August 24, 2011 at 6:13 am

    Oh cool, thanks for the email and reply. I’ll try it out with your settings as soon as I catch a break from classes. ^-^

  • Craig · September 1, 2011 at 1:09 am

    I’m trying to make use of the BigButton, but I can’t seem to get it to function. Is anyone else experiencing this?

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

<<

>>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes