SWBFII Split Screen Toolkit

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

Previous topic - Next topic
Quote from: flyingDutchman on November 21, 2016, 04:32:06 PM
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:
Ah yeah makes sense that it would trip some AV scanners. In the eyes of the AV software it is doing some things that it might expect applications of less than noble intent to be doing. (Editing another processes memory, injecting code into that process, etc.)

As for your current startup problem I've posted a new version in the main post fixing a possible race condition with starting the game processes, from your console output it looks like it may fix the problem you're having. (I hope. If it doesn't just let me know and I'll try to find time to look into it more.)

January 31, 2017, 01:11:08 PM #16 Last Edit: January 31, 2017, 01:14:30 PM by Antstafer
Would this be possible to replicate with the first battlefront? The possibilities....
That being said, this toolkit works surprisingly well. Had some issues with my antivirus but after that I couldn't believe my eyes!

I do however want to point out that it only works if both players are on the same team. If one player chooses the opposing team, the spawn timer goes into a 10-15 second loop for them, and keeps timing out.

I got this error. It starts to work but crashes soon after. I downloaded the newest version and it still doesn't work. Can I have some help?

Sorry about such a long time in between your posts and my replies guys. I often forget or don't have time to check up on this site. If either of you are still wanting to get this working I'll help where I can.

Quote from: Antstafer on January 31, 2017, 01:11:08 PM
Would this be possible to replicate with the first battlefront? The possibilities....
That being said, this toolkit works surprisingly well. Had some issues with my antivirus but after that I couldn't believe my eyes!

I do however want to point out that it only works if both players are on the same team. If one player chooses the opposing team, the spawn timer goes into a 10-15 second loop for them, and keeps timing out.
That is very strange. I've personally used the tool multiple times without any such issues. I can't promise anything since what time I spend on programming is spent on other projects currently but if you can attach a screen shot of the settings you use I might be able to take a look at it.

Quote from: gamewiz198 on February 22, 2017, 10:37:33 AM
I got this error. It starts to work but crashes soon after. I downloaded the newest version and it still doesn't work. Can I have some help?
Hm, what version of Windows and game version are you using? (By game version I mean Steam, GoG, Disc or SWBFII Spy patch.)

SleepKiller,

Would you be so kind as to share the code that you used to create the program? I would love to dive into that code, and see if I can't re-use parts of it, to get other games working as split screen games. I've had luck getting some games to work as split-screen, but this SWBF2 has eluded me.

tbare958--you might want to PM him directly, as Sleepkiller is an infrequent visitor here these days.   :cheers:
Quote from: Abraham Lincoln. on November 04, 1971, 12:34:40 PM
Don't believe everything you read on the internet

Blast I subscribed to the topic for e-mail notifications so I would stop missing replies and it went to Spam. Oh well at least I'm not as late at replying as I have been.

Sorry about the following wall of text, I've tried to thoroughly explain as much as possible so as to be as helpful as possible to anyone else finding this as well. If you just want the source code it is at the bottom of the post.

I'm happy to assist you in your goal of split screen gaming (as it is a goal I share). So onto a description of my code and why I haven't released it. (until now that is) So briefly my front end Gui is in C# but that simply launches a commandline C++ program that does all the heavy lifting, I say C++ but the reason why I haven't released it is I'm so downright ashamed of the quality of code in it that it is effectively (badly written) C with Classes. 

I know I can and should do better so I started rewriting the program from the ground up to support more games, have better structure, etc. Then I started writing a WinSock2 implementation for local communication for the games when I hit a game that needed it and then I decided "Why limit this to Windows? There games on Linux to!" so I started to re-structure the code yet again... See where this is going?  Bottom line I am still working on it but I haven't got really any of the code into a fit for release state. (That is one where I won't want to crawl into a cave in shame from others seeing it.)

Anyway none of that really matters it is just a disclaimer. If you want the source code with all it's flaws you are most certainly welcome to it if you feel it will help you. I'll post a link to it at the end of this post. First I'll give you a hopefully useful overview of what SWBFII needs in order to run multiple instances and have them all get input.

Firstly and this is the simple one both SWBF and SWBFII create a mutex called PlayBF. My tool renames it for each instance when they go to create it by using a hook, but killing it should work as well. nucleuscoop's previous version (Split Screen Tool, I believe) took the route of killing the mutex for L4D.

The game then implements a fairly common convenience measure to also (in an effort to help the user) prevent multiple instances opening. When the game is started it searches for a window with the window class called "Star Wars Battlefront II" (I think it's that, the source code of my tool will say for certain). If it finds a window with that class it maximizes that window, focuses it (after all the user wanted SWBFII and it's already running no need to run two instances) and then exits.

Beating this is fairly simple, you can create the game's process in a suspended state and edit the string used for the class name in the game's memory. (This would also work on mutex names) That isn't very generic however so you can also hook RegisterClass and change it there, or the simplest one would be hook FindWindow and return a not found message.

Then, there is yet another problem caused by the game being clever and useful. "When I'm not the focused Window there is no need for me to be working as hard." SWBFII checks is thankfully simple in this regard, simply using the window messages, WM_KILLFOCUS, WM_ACTIVATE and WM_ACTIVATEAPP. It's been a while but looking at my source code now all I am doing is installing my own [url=https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573]WindowProc in place of SWBFII's, always handling these messages (so returning 0) and then passing any other message onto SWBFII's WindowProc. I did this by hooking RegisterClass but the subject of Window hooking always confused me so there are very possibly better ways.

After all this there still exist two problems. One of which I do not think is necessary if you hook all the Window's the game's process creates and stop them from getting lost focus messages. And that is that the game's sound mutes itself when it is in the background, this is handled automatically by DirectSound , this is something I can not remember much about but I do know I solved it by adding DSBCAPS_GLOBALFOCUS to the sound buffer created by SWBFII. Once again I used hooks but for this problem I'm sure there are better, simpler solutions out there.

Finally the last problem. SWBFII offers no way to select a controller it will either use the system mouse and keyboard and the first DirectInput8 controller it finds. So this is probably the most complex part, somehow you need to make SWBFII use a controller you set and it should always use that controller.

Now when I did the method I did I knew very little about COM. I still know very little, but I know enough to hopefully help point you in the right direction. So DirectInput is just a collection of COM classes right? This means that if you're know what you're doing (or feel like learning it!) it should be possible to write you're own COM classes for it to use instead, in whatever language you like. Then hook the game's call to get DirectInput objects and pass it your's instead. Other methods would be patching the virtual function table of the classes you wanted to hook or what I did (since Visual C++'s vtable's and COM are ABI compatible) simply write C++ classes to implement the class without touching COM. See my code for a (poor) example of doing this.

Any of those options would give you away to always get the game to use any input device you wanted.

So all that will give you a working implementation, there are however two more things I do to deal with oddities/nuisances of SWBFII. So the first is the game has no built in borderless window mode. However changing a window to borderless is fairly trival so I won't go into details like the style flags used. I did however do it in a CreateWindowEx hook so it would happen as soon as possible.

The final thing is SWBFII likes to centre it's window when a new map loads. I hooked SetWindowPos and just never let the game change window positions. There are of course other very simple ways of dealing with this. (Monitoring the window position and changing it if it ever isn't what you want being one of them.)

So here is the source code for anyone interested https://www.dropbox.com/s/1j4vfkv0e3y6yza/SWBF%20Split%20Screen%2B%2B.7z?dl=0, if you have VS2015 or VS2017 it should be ready to build. I have neglected putting a license on it, partly because the quality of the code is so poor that I don't think anyone should re-use large portions of it directly. (If you want or require one for it just let me know and I'll do it.)  That said feel free to use any code from it if it is useful to you; attribution is nice but under no circumstances required. If something there I've made is useful to you then I am pleased to have been of service.

Feel free to contact me if I've left something out, you want something explained better or if you just encounter any issues with something I've said here.

SleepKiller,

Thank you so much for the detailed explanation and the link to the code. I'll look through it, and I'll let you know if it comes as any help.

It's funny that you mention nucleuscoop, because I've been working on a fork of that project. I attempted a few methods of getting hold of the author to get some changed pulled in, but I've had no luck.

As for the project, I haven't worked with hooks before, so I've been looking around for some beginning to end examples of how to install and release hooks from applications(as I learn best with examples), so I'm sure that the code that you provided will be really helpful for me.

When I try to join server with 2nd player, it fails because of cdkey error.

what is your specific error code?

Quote from: xMichael on May 09, 2017, 08:59:23 AM
When I try to join server with 2nd player, it fails because of cdkey error.
Are you trying to join an Internet server? If so this tool won't work because your game install only has one CD key and Internet servers require each client have a unique key.

If you're trying to join a LAN game and it isn't working then I might be able to help, but I'll need to know more about your game install first.

Yeah I thought so. It was internet server.

May 26, 2017, 01:01:23 AM #27 Last Edit: January 07, 2024, 03:49:57 AM by MacMillan11
del

I am not sure if anyone will still post or respond to this. However I have hope. Anyways,  I have installed everything and it all runs. However the problem is getting each screen to recognize proper controllers. I can get into split screen at the main menu and jump around and get all screens into the game but then there is no way to have the screens be controlled at the same time. Additionally while in game I can't aim with my mouse but when accessing the menu I can clearly see and use my mouse cursor. So how do I get multiple controllers to work with this?

Quote from: Eagleninja32 on March 15, 2018, 02:06:47 PM
I am not sure if anyone will still post or respond to this. However I have hope. Anyways,  I have installed everything and it all runs. However the problem is getting each screen to recognize proper controllers. I can get into split screen at the main menu and jump around and get all screens into the game but then there is no way to have the screens be controlled at the same time. Additionally while in game I can't aim with my mouse but when accessing the menu I can clearly see and use my mouse cursor. So how do I get multiple controllers to work with this?
If I remember correctly tool assigns controllers in a linear fashion. So Player 1 gets XInput(Xbox) Controller #1, Player 2 gets XInput Controller #2,  etc.  I can't think of much that would stop this from happening.

If you don't have XInput controllers you should be able to install and use this https://www.x360ce.com/ to let the toolkit use DirectInput only controllers.