SWBFII Split Screen Toolkit

Started by SleepKiller, October 23, 2016, 11:22:37 PM

Previous topic - Next topic
October 23, 2016, 11:22:37 PM Last Edit: November 21, 2016, 07:26:12 PM by SleepKiller
This is a little something I have been working on for fun recently. It enables people to play Star Wars Battlefront II in a split screen mode on PC.

[spoiler=Image][/spoiler]

Requirements
   As many XInput compliant controllers as you wish to have players. PS3 or PS4 controllers will work fine if you use something like SCP Toolkit.

   At least Windows 7, though I haven't tested it provided you have the runtimes below it should work.

   Non-Steam Version of SWBFII, the Steam version will not work unless you replace BattlefrontII.exe with the SWBFSpy version of the client.

   If you're lazy and on Windows 10 only bother downloading them if you get a "Runtime error" or something to that effect, the operating system may very well take care of getting dependencies for you.

   The core application requires Visual C++ Redistributable for Visual Studio 2015
   https://www.microsoft.com/en-nz/download/details.aspx?id=48145

   And the GUI requires .NET Framework 4.6.1 which you can get here.
   https://www.microsoft.com/en-nz/download/details.aspx?id=49981

   Optionally you can also install the SWBFII dedicated server software and use that for lower loading times.
   http://www.swbfgamers.com/index.php?topic=10619.msg106046#msg106046

Installation
   Copy all the contents of zip to the directory where your BattlefrontII.exe is.
   This is usually "C:\Program Files (x86)\LucasArts\Star Wars Battlefront II\GameData"

   Do not get BattlefrontII.exe confused with LaunchBFII.exe, if you don't see BattlefrontII.exe you're in the wrong place.

Usage
   Once installed simply start Split Screen GUI to configure and launch your play session. All the controls should have tooltips to inform you what they do.
   
   The map list supports common Windows controls like Double Clicking to add a single map, holding Control to select multiple items and drag-droping selections.

   The tool uses a pre-created profile to give you controls almost identical to the console version of the game. If you want to rebind them you'll have to set a player's name to SplitScreen using the GUI, or commandline tool, and rebind the controls using that player's screen. Once you've got them how you want exit and start the split screen session again to update the controls across all players.

Technical Overview
[spoiler]The backend console program works to enable splitscreen through a mixture of commandline arguments, memory editing and function hooks.
   
The first thing it does is create a game process in a suspended state to enable hooking and editing of it's memory before the game executes any code.

From there it changes the name SWBFII will use for the window classname and mutex SWBF uses to prevent multiple instances starting up. (Normally a useful safety measure for a program to have but in this case it is holding us back.)

Then it injects a DLL into the process to hook various WinAPI functions. There are three ones of note. The first one hooks RegisterClass to redirect WindowProc to our own callback to filter out loss of focus messages, stopping the Scoreboard coming up when the game loses focus in Multiplayer.

The second hook is one for DirectSound, the main sound buffers created by the game will have global focus enabled on them. Enabling audio for our process to play in the background.

The final hook of major note is the most complex. So far we've taken care of the game's perception of focus and audio focus, leaving us with input focus. DirectInput does have support for background input but due to the API's age setting which controller the game was using was something I didn't want to deal with.

So instead when the game enumerates controllers we supply only one option, a virtual interface mimicking IDirectInputDevice8. This virtual interface uses XInput to present a single connected controller that we can determine to the game. Since XInput has no concept of focus the problem of getting input to the game is solved.
      
After that the process is resumed/started properly, we wait for it to create it's window and once it's done that we set it as a foreground window, putting it above everything else on the desktop, including the taskbar. Although pressing Start + D when not focusing a foreground window will minimize them.

There is more the toolkit does but that is a general overview of how it enables split screen play in SWBFII.
[/spoiler]

Change Log
[spoiler]1.0.1
   -Stopped being lazy and updated Window Classname handling and Mutex Name handling to be dynamic through hooks.
   -Switched over to xinput9_1_0 after mistakenly forgetting to do so.
   -Various bits of refactoring to enable the above change.
1.0.2
   -Fixed a bug preventing SWBFII from correctly configuring the thumbsticks of a controller. As a result controls are much smoother now.
   -Thumbstick deadzone can now be customized from SWBFII as well.
   -Mouse and keyboard support has been disabled for now due to conflicts it was creating with controllers.
1.0.3
   -Removed "Keyboard Player" GUI element as I lack the time to max the changes to support it.
   -Removed XInput controller checking from the GUI due to inconsistent behaviour expressed by the tool due to it.
   -As a result of the above change people are now responsible for making sure the correct number of XInput controllers are connected to the PC.

1.0.4
   -Fixed a potential race condition in the creation and hooking of the game.
[/spoiler]

Download it here! (Current Version 1.0.4)

If you do use it be sure to let me know how it goes and feel free to ask questions, especially if you encounter strange behaviour.

Hey, this looks good!
I'm happy to do some testing of my own if you like.
Does this work by exploiting the localhost IP? Or does it use multiple BFII instances?
This Universe's Captain Falcon. A title I will pass on when I leave this world.

If you want to test it go ahead, it would be nice to know that it works on PCs other than my own.

To answer your question it works by creating multiple instances of the game (one for each player) and positioning their windows accordingly. It optionally also supports creating and managing a server for players to connect to. Bringing the total instance count of the game up to (Number of Players + 1).

Regrettably I didn't seem to be able to get auto-joining for LAN working so players must still navigate through the Multiplayer menu to find the server. But SWBFII has no issue locating and joining servers running on the same machine once you are there, it can just take a few seconds for the server to load the map.

A user can pick if the server it creates is hosted by using the client executable or if installed the server executable. Both more or less functionally identical but the dedicated server executable does load smaller game files so it is preferred.

Very nice SK!

Thanks for thinking of us  :cheers:
Quote from: Abraham Lincoln. on November 04, 1971, 12:34:40 PM
Don't believe everything you read on the internet

Great work! I'm going to have to try this with some friends. Now we just need a way to activate two player galactic conquest on the pc.


SO many people have requested this on Steam. Do you mind if I post a link to this topic on there?

Quote from: Jean on October 24, 2016, 01:18:45 PM
SO many people have requested this on Steam. Do you mind if I post a link to this topic on there?
Yes and no. I would love to support the Steam version of the so that people can use this tool regardless of the version of the game they own. But I have no way to verify compatibility with it myself. I would request that before you do post anything about it you test it to make sure it works for people not running with the SWBFSpy executable. (That part is very important, be sure to test using the original Steam executable.)

In the likely event the game crashes then you can still post about it if you want, you would just have to include SWBFSpy as a requirement for it. Something I personally find ugly which is why I didn't reference it in the original post, I would much rather add support for the Steam version directly. But since I don't own it that may be a ways off. (Unless any of you are feeling particularly generous and have a spare copy kicking about.)

I tried it and got error messages saying missing XINPUT1_4.dll

Quote from: Jean on October 25, 2016, 12:13:33 AM
I tried it and got error messages saying missing XINPUT1_4.dll
Ah thanks for testing it. That's the kind of mistake it's easy for me to miss, XInput 1.4 is only included on Windows 8 and above. It is also what Visual Studio links to by default. I had intended to link against the Windows 7 version (XInput 9.1.0) but I completely forget. A new version is in the main post that should address this issue.

Would this be more taxing on graphics cards then too?
Yes i know this shouldn't be a problem for anyone, but hey you never know.

Quote from: Ltin on October 25, 2016, 08:51:05 PM
Would this be more taxing on graphics cards then too?
Yes i know this shouldn't be a problem for anyone, but hey you never know.
A simple answer is yes it probably will be more expensive than running a single instance of the game. That said SWBFII is eleven years old so in the unlikely event someone encounters a performance problem turning down the video settings by editing the SplitScreen profile outside the tool would in all likely hood be all that is needed to make it run smoothly. (Just a quick related note for anyone reading this, do not edit controls outside the tool the buttons the virtual control presents to the game are different from the ones DirectInput presents. If you want to change the controls set Player #1's name to SplitScreen and do it from their screen. Once you're done exit from their screen and restart the session.)

In other news a new version has been posted fixing bugs with thumbstick behaviour.

Hey, first off this is awesome!

I'm trying to get it to work with the steam version, so far I can't get it to work. Right after I set up the map and hit play I get a generic windows error "Split Screen Gui has stopped working". I've installed all the files you listed in the first post. Any other ideas? (windows 8.1 + steam version)

Thanks again!

I put an update in the main post removing some functionality in the GUI relating to XInput that was causing problems. The checkbox for Keyboard Player was also removed as I do not have the time currently to implement keyboard support.

As for Steam support thanks to Dark_Phantom I was able to look into it. And regrettably looks like it doesn't want to work, since circumventing DRM is far beyond the scope of this toolkit I will not be looking into it further. However you should be able to replace Steam's BattlefrontII.exe with the SWBFSpy one and have it work. (You have to rename "BattlefrontII - SWBFSpy.exe" to "BattlefrontII.exe" and replace Steam's version of the executable.)

Much less clean and simple than I would like but it is what it is.

Quote from: flyingDutchman on November 20, 2016, 11:05:30 AM
Hey, first off this is awesome!

I'm trying to get it to work with the steam version, so far I can't get it to work. Right after I set up the map and hit play I get a generic windows error "Split Screen Gui has stopped working". I've installed all the files you listed in the first post. Any other ideas? (windows 8.1 + steam version)

Thanks again!
Hm, I haven't encountered that. The console application should catch most errors and provide some useful form of feedback.

There are a couple things you can do. First is to make sure the entire contents of the "SWBF2 Split Screen" were copied into the directory BattlefrontII.exe lives in. The GUI will fail ungracefully if it can't find "SWBF Split Screen++.exe", which in turn will fail if it can't find the two DLLs it depends on.

If you're sure everything is installed correctly you can try right clicking on the Play button and clicked "Play (Debug)" and see if you get any useful output. (If you do get some form of output other than a generic windows message just take a screen shot and post it for me to look at.)

Hope one of those can help solve it for you!

November 21, 2016, 04:32:06 PM #14 Last Edit: November 21, 2016, 05:17:11 PM by flyingDutchman
progress!

I noticed you mentioned SWBF Split Screen++.exe which wasn't in the folder I downloaded, did some digging around looks like avast was auto deleting it must be a false positive. I added it to the exclusions and I can now run without a generic windows error, but after running it it just opens and closes,

here the error it shows for the debug (ive attached it)

Thanks for the help! this is going to amazing if I can get it to work  :cheer: