static void Main(string[] args) { GameManager manager = new GameManager(); GameInfo borderlands2 = manager.Games["720CE71B-FCBF-46C8-AC9D-C4B2BF3169E3"]; UserGameInfo borderInfo = manager.AddGame(borderlands2, @"C:\Program Files (x86)\Steam\steamapps\common\Borderlands 2\Binaries\Win32\Borderlands2.exe"); GameProfile profile = new GameProfile(); profile.InitializeDefault(borderlands2); PlayerInfo p1 = new PlayerInfo(); p1.monitorBounds = new Rectangle(0, 0, 960, 540); p1.screenIndex = 0; profile.PlayerData.Add(p1); PlayerInfo p2 = new PlayerInfo(); p2.monitorBounds = new Rectangle(0, 540, 960, 540); p2.screenIndex = 0; profile.PlayerData.Add(p2); borderInfo.Profiles.Add(profile); manager.WaitSave(); // try to play game with custom profile handler = manager.MakeHandler(borderlands2); handler.Initialize(borderInfo, profile); ThreadPool.QueueUserWorkItem(Play); //handler.Play(); for (; ; ) { Thread.Sleep(16); handler.Update(16); if (handler.HasEnded) { break; } } }
private void num_Players_ValueChanged(object sender, EventArgs e) { for (int i = 0; i < Panels.Count; i++) { Panels[i].Dispose(); } for (int i = 0; i < Players.Count; i++) { PlayerInfo p = Players[i]; if (p.Control != null) { p.Control.Dispose(); } } Players.Clear(); int players = (int) this.num_Players.Value; for (int i = 0; i < players; i++) { PlayerInfo p = new PlayerInfo(); Players.Add(p); } for (int z = 0; z < Screens.Count; z++) { ScreenControl scr = Screens[z]; ContextMenu context = new System.Windows.Forms.ContextMenu(); for (int i = 0; i < players; i++) { MenuItem player1 = new MenuItem("Set Player " + (i + 1).ToString(CultureInfo.InvariantCulture)); context.MenuItems.Add(player1); for (int x = 0; x < 5; x++) { ScreenType screen = (ScreenType)x; MenuItem SetPlayer = new MenuItem("To " + screen.ToString()); Holder holder = new Holder(); holder.Player = i; holder.Control = scr; holder.Screen = screen; holder.ScreenIndex = z; SetPlayer.Tag = holder; SetPlayer.Click += new EventHandler(SetPlayer_Click); player1.MenuItems.Add(SetPlayer); } } if (scr.ContextMenu != null) { scr.ContextMenu.Dispose(); } scr.ContextMenu = context; } }
protected void ScreenClick(object sender, EventArgs e) { if (hover == null) { return; } ToolStripDropDownItem item = (ToolStripDropDownItem)sender; ScreenHolder holda = (ScreenHolder)item.Tag; for (int i = 0; i < loaded_screens.Count; i++) { var mscreen = loaded_screens[i]; for (int j = 0; j < mscreen.Controls.Count; j++) { Control con = mscreen.Controls[j]; if (con is PlayerControl) { PlayerControl player = (PlayerControl)con; if (player.Player.Player == holda.Player) { player.Dispose(); hover.Controls.Remove(player); players.Remove(player.Player); } } } } for (int i = 0; i < hover.Controls.Count; i++) { Control con = hover.Controls[i]; if (con is PlayerControl) { PlayerControl player = (PlayerControl)con; PlayerInfo otha = player.Player; // if one coincides with the other, remove the other one if (otha.ScreenType == ScreenType.Fullscreen || otha.ScreenType == holda.Position || holda.Position == ScreenType.HorizontalTop && (otha.ScreenType == ScreenType.TopLeft || otha.ScreenType == ScreenType.TopRight || otha.ScreenType == ScreenType.VerticalLeft || otha.ScreenType == ScreenType.VerticalRight) || holda.Position == ScreenType.HorizontalBottom && (otha.ScreenType == ScreenType.BottomLeft || otha.ScreenType == ScreenType.BottomRight || otha.ScreenType == ScreenType.VerticalLeft || otha.ScreenType == ScreenType.VerticalRight) || holda.Position == ScreenType.VerticalLeft && (otha.ScreenType == ScreenType.TopLeft || otha.ScreenType == ScreenType.BottomLeft || otha.ScreenType == ScreenType.HorizontalTop || otha.ScreenType == ScreenType.HorizontalBottom) || holda.Position == ScreenType.VerticalRight && (otha.ScreenType == ScreenType.TopRight || otha.ScreenType == ScreenType.BottomRight || otha.ScreenType == ScreenType.HorizontalTop || otha.ScreenType == ScreenType.HorizontalBottom)) { // Love boolean Math XD player.Dispose(); hover.Controls.Remove(player); players.Remove(otha); } } } PlayerInfo playa = new PlayerInfo(); playa.ScreenIndex = this.loaded_screens.IndexOf(hover); playa.ScreenType = holda.Position; playa.Player = holda.Player; PlayerControl theplayer = new PlayerControl(playa); theplayer.MouseEnter += scr_MouseEnter; theplayer.ChangeName("Player " + holda.Player); hover.Controls.Add(theplayer); theplayer.BringToFront(); theplayer.Accomodate(); players.Add(playa); }
public void Update(int delayMS) { if (profile == null) { return; } exited = 0; List <PlayerInfo> players = profile.PlayerData; timer += delayMS; for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenData == null || p.Process == null) { continue; } if (p.SteamEmu) { List <int> children = ProcessUtil.GetChildrenProcesses(p.Process); if (children.Count > 0) { for (int j = 0; j < children.Count; j++) { int id = children[j]; Process child = Process.GetProcessById(id); try { if (child.ProcessName.Contains("conhost")) { continue; } } catch { continue; } p.Process = child; p.SteamEmu = child.ProcessName.Contains("SmartSteamLoader") || child.ProcessName.Contains("cmd"); } } } else { ScreenData data = p.screenData; if (data.Set) { if (p.Process.HasExited) { exited++; continue; } if (!p.screenData.KilledMutexes && gen.KillMutex.Length > 0) { StartGameUtil.KillMutex(p.Process, gen.KillMutex); p.screenData.KilledMutexes = true; } uint lStyle = User32Interop.GetWindowLong(data.HWND.Hwnd, User32_WS.GWL_STYLE); if (lStyle != data.RegLong) { uint toRemove = User32_WS.WS_CAPTION; lStyle = lStyle & (~toRemove); User32Interop.SetWindowLong(data.HWND.Hwnd, User32_WS.GWL_STYLE, lStyle); data.RegLong = lStyle; data.HWND.Location = data.Position; } } else { p.Process.Refresh(); if (p.Process.HasExited) { if (p.GotLauncher) { if (p.GotGame) { exited++; } else { List <int> children = ProcessUtil.GetChildrenProcesses(p.Process); if (children.Count > 0) { for (int j = 0; j < children.Count; j++) { int id = children[j]; Process pro = Process.GetProcessById(id); if (!attached.Contains(pro)) { attached.Add(pro); data.HWND = null; p.GotGame = true; p.Process = pro; } } } } } else { // Steam showing a launcher, need to find our game process string launcher = gen.LauncherExe; if (launcher.ToLower().EndsWith(".exe")) { launcher = launcher.Remove(launcher.Length - 4, 4); } Process[] procs = Process.GetProcessesByName(launcher); for (int j = 0; j < procs.Length; j++) { Process pro = procs[j]; if (!attached.Contains(pro)) { attached.Add(pro); p.Process = pro; p.GotLauncher = true; } } } } else { if (data.HWNDRetry || data.HWND == null || data.HWND.Hwnd != p.Process.MainWindowHandle) { data.HWND = new HwndObject(p.Process.MainWindowHandle); Point pos = data.HWND.Location; if (String.IsNullOrEmpty(data.HWND.Title) || pos.X == -32000 || data.HWND.Title.ToLower() == gen.LauncherTitle.ToLower()) { data.HWNDRetry = true; } else { Size s = data.Size; data.Set = true; data.HWND.TopMost = true; data.HWND.Size = data.Size; data.HWND.Location = data.Position; } } } } } if (exited == players.Count) { if (!hasEnded) { hasEnded = true; GameManager.Instance.ExecuteBackup(this.userGame.Game); if (Ended != null) { Ended(); } } } } }
public string Play() { List <PlayerInfo> players = profile.PlayerData; Screen[] all = Screen.AllScreens; string backupDir = GameManager.Instance.GetBackupFolder(this.userGame.Game); string binFolder = Path.GetDirectoryName(userGame.ExePath); string rootFolder = ReplaceCaseInsensitive(binFolder, gen.BinariesFolder, ""); int gamePadId = 0; for (int i = 0; i < players.Count; i++) { PlayerInfo player = players[i]; if (i > 0 && gen.KillMutex.Length > 0) { PlayerInfo before = players[i - 1]; for (;;) { if (exited > 0) { return(""); } Thread.Sleep(100); if (before.screenData.KilledMutexes) { break; } } } Rectangle playerBounds = player.monitorBounds; // find the monitor that has this screen Screen owner = null; for (int j = 0; j < all.Length; j++) { Screen s = all[j]; if (s.Bounds.Contains(playerBounds)) { owner = s; break; } } int width = playerBounds.Width; int height = playerBounds.Height; bool isFullscreen = false; if (owner != null) { Rectangle ob = owner.Bounds; if (playerBounds.X == ob.X && playerBounds.Y == ob.Y && playerBounds.Width == ob.Width && playerBounds.Height == ob.Height) { isFullscreen = true; } } engine.SetValue("Id", i.ToString(CultureInfo.InvariantCulture)); engine.SetValue("Width", width.ToString(CultureInfo.InvariantCulture)); engine.SetValue("Height", height.ToString(CultureInfo.InvariantCulture)); engine.SetValue("IsFullscreen", isFullscreen); // symlink the game folder // find out the folder that contains the game executable string root = GetRootFolder(gen.BinariesFolder); string linkFolder = Path.Combine(backupDir, "Instance" + i); Directory.CreateDirectory(linkFolder); int exitCode; CmdUtil.LinkDirectories(rootFolder, linkFolder, out exitCode, root.ToLower()); string linkBin = Path.Combine(linkFolder, gen.BinariesFolder); if (!string.IsNullOrEmpty(gen.BinariesFolder)) { // this needs fixing, if there are several folder to the exe and they have important files inside, this won't work! TODO Directory.CreateDirectory(linkBin); CmdUtil.LinkDirectories(binFolder, linkBin, out exitCode); } string exePath = Path.Combine(linkBin, this.userGame.Game.ExecutableName); if (gen.SymlinkExe) { CmdUtil.LinkFiles(binFolder, linkBin, out exitCode, "xinput"); } else { CmdUtil.LinkFiles(binFolder, linkBin, out exitCode, "xinput", Path.GetFileNameWithoutExtension(gen.ExecutableName.ToLower())); File.Copy(userGame.ExePath, exePath, true); } // some games have save files inside their game folder, so we need to access them inside the loop this.data[NucleusFolderEnum.GameFolder.ToString()] = linkFolder; string saveFile = ProcessPath(gen.SavePath); IniFile file = new IniFile(saveFile); switch (gen.SaveType) { case GenericGameSaveType.INI: foreach (var modPair in gen.ModifySave) { string key = modPair.Key; string[] keys = key.Split('/'); engine.Execute(modPair.Value); string val = engine.GetCompletionValue().ToString(); file.IniWriteValue(keys[0], keys[1], val); } break; } string startArgs = gen.StartArguments; byte[] xdata = null; if (gen.SupportsKeyboard && i == (int)profile.Options["KeyboardPlayer"]) { engine.SetValue("Keyboard", true); // need to make an xinput that answers to no gamepad? xdata = Properties.Resources.xinput4; } else { engine.SetValue("Keyboard", false); switch (gamePadId) { case 0: xdata = Properties.Resources.xinput1; break; case 1: xdata = Properties.Resources.xinput2; break; case 2: xdata = Properties.Resources.xinput3; break; case 3: xdata = Properties.Resources.xinput4; break; default: xdata = Properties.Resources.xinput4; break; } gamePadId++; } using (Stream str = File.OpenWrite(Path.Combine(linkBin, "xinput1_3.dll"))) { str.Write(xdata, 0, xdata.Length); } if (!string.IsNullOrEmpty(startArgs)) { startArgs = engine.Execute(startArgs).GetCompletionValue().AsString(); } if (gen.NeedsSteamEmulation) { string steamEmu = GameManager.Instance.ExtractSteamEmu(); string emuExe = Path.Combine(steamEmu, "SmartSteamLoader.exe"); string emuIni = Path.Combine(steamEmu, "SmartSteamEmu.ini"); IniFile emu = new IniFile(emuIni); emu.IniWriteValue("Launcher", "Target", exePath); emu.IniWriteValue("Launcher", "StartIn", Path.GetDirectoryName(exePath)); emu.IniWriteValue("Launcher", "CommandLine", startArgs); emu.IniWriteValue("Launcher", "SteamClientPath", Path.Combine(steamEmu, "SmartSteamEmu.dll")); emu.IniWriteValue("Launcher", "SteamClientPath64", Path.Combine(steamEmu, "SmartSteamEmu64.dll")); emu.IniWriteValue("Launcher", "InjectDll", "0"); emu.IniWriteValue("SmartSteamEmu", "AppId", gen.SteamID); Process proc; if (gen.KillMutex.Length > 0) { // to kill the mutexes we need to orphanize the process proc = ProcessUtil.RunOrphanProcess(emuExe); } else { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = emuExe; proc = Process.Start(startInfo); } player.Process = proc; player.SteamEmu = true; } else { Process proc; if (gen.KillMutex.Length > 0) { proc = Process.GetProcessById(StartGameUtil.StartGame(exePath, startArgs)); } else { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = exePath; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.Arguments = startArgs; startInfo.UseShellExecute = true; startInfo.WorkingDirectory = Path.GetDirectoryName(exePath); proc = Process.Start(startInfo); } if (proc == null) { for (int times = 0; times < 200; times++) { Thread.Sleep(50); Process[] procs = Process.GetProcesses(); string proceName = Path.GetFileNameWithoutExtension(gen.ExecutableName).ToLower(); string launcherName = Path.GetFileNameWithoutExtension(gen.LauncherExe).ToLower(); for (int j = 0; j < procs.Length; j++) { Process p = procs[j]; string lowerP = p.ProcessName.ToLower(); if (((lowerP == proceName) || lowerP == launcherName) && !attached.Contains(p)) { attached.Add(p); proc = p; break; } } if (proc != null) { break; } } } else { attached.Add(proc); } player.Process = proc; } ScreenData data = new ScreenData(); data.Position = new Point(playerBounds.X, playerBounds.Y); data.Size = new Size(playerBounds.Width, playerBounds.Height); data.KilledMutexes = gen.KillMutex.Length == 0; player.screenData = data; } return(string.Empty); }
public PlayerControl(PlayerInfo player) { this.player = player; InitializeComponent(); }
public void Initialize(UserGameInfo game, GameProfile profile) { this.profile = profile; profile.PlayerData.Clear();// reset profile playerFont = new Font("Segoe UI", 40); playerTextFont = new Font("Segoe UI", 18); RemoveFlicker(); float playersWidth = this.Width * 0.5f; int playerCount = profile.PlayerCount; float playerWidth = (playersWidth * 0.9f) / (float)playerCount; float playerHeight = playerWidth * 0.5625f; float offset = (playersWidth * 0.1f) / (float)playerCount; playersArea = new RectangleF(50, 100, playersWidth, playerHeight); for (int i = 0; i < playerCount; i++) { Rectangle r = new Rectangle((int)(50 + ((playerWidth + offset) * i)), 100, (int)playerWidth, (int)playerHeight); PlayerInfo playa = new PlayerInfo(); playa.editBounds = r; profile.PlayerData.Add(playa); } screens = ScreensUtil.AllScreens(); Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec()); // see if most screens are either vertical or horizontal int vertical = 0; int horizontal = 0; for (int i = 0; i < screens.Length; i++) { UserScreen s = screens[i]; if (s.bounds.Width > s.bounds.Height) { horizontal++; } else { vertical++; } } if (horizontal > vertical) { // horizontal setup scale = (this.Width * 0.9f) / (float)totalBounds.Width; } else { // vertical setup scale = (this.Height * 0.6f) / (float)totalBounds.Height; //scale = (this.Width * 0.9f) / (float)totalBounds.Width; } totalBounds = new Rectangle( (int)(totalBounds.X * scale), (int)(totalBounds.Y * scale), (int)(totalBounds.Width * scale), (int)(totalBounds.Height * scale)); int offsetViewsX = totalBounds.X; int offsetViewsY = totalBounds.Y; totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f))); for (int i = 0; i < screens.Length; i++) { UserScreen screen = screens[i]; Rectangle s = screen.bounds; int width = (int)(s.Width * scale); int height = (int)(s.Height * scale); int x = (int)(s.X * scale); int y = (int)(s.Y * scale); screen.bounds = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height); screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f)); } }