Skip to content

Commit

Permalink
Borderlands 2 now uses the same link system that I used on Left 4 Dead 2
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassislar committed Dec 2, 2015
1 parent a83a66f commit 8e3649a
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 16 deletions.
66 changes: 59 additions & 7 deletions Master/Games/Borderlands2/Borderlands2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using WindowScrape.Static;
using WindowScrape.Constants;
using Nucleus.Gaming.Interop;
using Nucleus;
using Nucleus.Coop.Games.Properties;

namespace Games
{
Expand Down Expand Up @@ -87,7 +89,7 @@ public string Play()
}

var options = profile.Options;
bool playerKeyboard = (bool)profile.Options["keyboardPlayer"];
int playerKeyboard = (int)profile.Options["keyboardPlayer"] - 1;

IniFile file = new IniFile(saveFile);
file.IniWriteValue("SystemSettings", "WindowedFullscreen", "False");
Expand All @@ -103,8 +105,17 @@ public string Play()
//User32.MinimizeEverything();
List<PlayerInfo> players = profile.PlayerData;

string backupDir = GameManager.Instance.GetBackupFolder(this.userGame.Game);
string binFolder = Path.GetDirectoryName(executablePlace);
string rootFolder = Path.GetDirectoryName(
Path.GetDirectoryName(binFolder));

int gamePadId = 0;

for (int i = 0; i < players.Count; i++)
{
string linkFolder = Path.Combine(backupDir, "Instance" + i);

PlayerInfo player = players[i];
// Set Borderlands 2 Resolution and stuff to run

Expand Down Expand Up @@ -152,26 +163,67 @@ public string Play()
file.IniWriteValue("SystemSettings", "ResX", width.ToString(CultureInfo.InvariantCulture));
file.IniWriteValue("SystemSettings", "ResY", height.ToString(CultureInfo.InvariantCulture));

// Link-making
Directory.CreateDirectory(linkFolder);
int exitCode;
CmdUtil.LinkDirectories(rootFolder, linkFolder, out exitCode, "binaries");

string linkBin = Path.Combine(linkFolder, @"Binaries\Win32");
Directory.CreateDirectory(linkBin);
CmdUtil.LinkDirectories(binFolder, linkBin, out exitCode);
CmdUtil.LinkFiles(binFolder, linkBin, out exitCode, "xinput", "borderlands");

string exePath = Path.Combine(linkBin, this.userGame.Game.ExecutableName);
File.Copy(this.executablePlace, exePath, true);
// Link-end


ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = executablePlace;
startInfo.FileName = exePath;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

// NEW
object option = options["saveid" + i];
//object option = 11;
int id = (int)option;

if (playerKeyboard)
if (i == playerKeyboard)
{
startInfo.Arguments = "-AlwaysFocus -NoController -ControllerOffset=" + (i - 1).ToString(CultureInfo.InvariantCulture) + " -SaveDataId=" + id.ToString(CultureInfo.InvariantCulture);
startInfo.Arguments = "-AlwaysFocus -NoController -SaveDataId=" + id.ToString(CultureInfo.InvariantCulture);
}
else
{
startInfo.Arguments = "-AlwaysFocus -ControllerOffset=" + i.ToString(CultureInfo.InvariantCulture) + " -SaveDataId=" + id.ToString(CultureInfo.InvariantCulture);
byte[] xdata = null;
switch (gamePadId)
{
case 0:
xdata = Nucleus.Coop.Games.GamesResources._1_xinput1_3;
break;
case 1:
xdata = Nucleus.Coop.Games.GamesResources._2_xinput1_3;
break;
case 2:
xdata = Nucleus.Coop.Games.GamesResources._3_xinput1_3;
break;
case 3:
xdata = Nucleus.Coop.Games.GamesResources._4_xinput1_3;
break;
default:
xdata = Nucleus.Coop.Games.GamesResources._4_xinput1_3;
break;
}

using (Stream str = File.OpenWrite(Path.Combine(linkBin, "xinput.dll")))
{
str.Write(xdata, 0, xdata.Length);
}

startInfo.Arguments = "-AlwaysFocus -SaveDataId=" + id.ToString(CultureInfo.InvariantCulture);
gamePadId++;
}

startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Path.GetDirectoryName(executablePlace);
startInfo.WorkingDirectory = Path.GetDirectoryName(exePath);

Process proc = Process.Start(startInfo);

Expand Down Expand Up @@ -253,7 +305,7 @@ public void Update(int delayMS)
}
}
}

public bool HasEnded
{
get { return end; }
Expand Down
2 changes: 1 addition & 1 deletion Master/Games/Borderlands2/Borderlands2Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Borderlands2Info()
{
options = new Dictionary<string, GameOption>();

options.Add("keyboardPlayer", new GameOption("Keyboard Player", "If Player 1 should be using keyboard", false));
options.Add("keyboardPlayer", new GameOption("Keyboard Player", "The player that will be playing on keyboard and mouse", 1));
options.Add("delay", new GameOption("Delay Time", "Time to wait for the game to load (in seconds)", 1.0));
options.Add("saveid0", new GameOption("Save ID - Player 1", "Save ID to use for Player 1 (default 0)", 0));
options.Add("saveid1", new GameOption("Save ID - Player 2", "Save ID to use for Player 2 (default 1)", 1));
Expand Down
9 changes: 9 additions & 0 deletions Master/Games/Nucleus.Coop.Games.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<Compile Include="Left4Dead2\SourceCfgFile.cs" />
<Compile Include="PlayerID.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Resident Evil 5\RE5Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -169,6 +174,10 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>L4D2Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resident Evil 5\RE5Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>RE5Resources.Designer.cs</LastGenOutput>
Expand Down
113 changes: 113 additions & 0 deletions Master/Games/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e3649a

Please sign in to comment.