ReStreet: FIFA Street (2012) recompiled for Windows PC, with online play, a launcher with friends, chat and rooms. Bring your own game.
Electron web wrapper
forestcolatc9e130e96441
diff --git a/Launcher/FifaStreetLauncher/BrowserUi.cs b/Launcher/FifaStreetLauncher/BrowserUi.csindex 2e0ba75..1099182 100644--- a/Launcher/FifaStreetLauncher/BrowserUi.cs+++ b/Launcher/FifaStreetLauncher/BrowserUi.cs@@ -20,6 +20,9 @@ public partial class LauncherFormprivate DateTime browserLastSeen = DateTime.UtcNow;private readonly ConcurrentQueue<string> browserOutbox = new();private readonly SemaphoreSlim browserSignal = new(0);+ private DateTime viewerStarted;+ private bool browserPageServed;+ private bool keepHidden;[DllImport("kernel32.dll", CharSet = CharSet.Ansi)] private static extern IntPtr GetModuleHandleA(string name);[DllImport("kernel32.dll", CharSet = CharSet.Ansi)] private static extern IntPtr GetProcAddress(IntPtr module, string name);@@ -59,10 +62,14 @@ public partial class LauncherFormint port = ((IPEndPoint)browserListener.LocalEndpoint).Port;_ = Task.Run(() => AcceptBrowserClients(ui));string url = $"http://127.0.0.1:{port}/{browserSecret}/launcher.html";+ BrowserLog($"Launcher {LauncherVersion} ({Environment.ProcessPath}); wine={RunningOnWine()}; " ++ $"viewer={(File.Exists(Path.Combine(AppContext.BaseDirectory, "Viewer", "ReStreetViewer.exe")) ? "found" : "missing")}");+ bool appWindow = false;try{// A window of its own, the launcher's size, when a Chromium browser is there; otherwise the default browser.- if (!OpenAppWindow(url)) Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });+ appWindow = OpenAppWindow(url);+ if (!appWindow) Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });}catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException){@@ -70,9 +77,18 @@ public partial class LauncherFormbrowserListener.Stop();return;}+ // On Wine/Proton without a Chromium app window the default browser may not open at all (inside Steam's+ // Proton container there is no host browser to reach), and a hidden classic window would leave nothing on+ // screen: keep the classic window visible then. The page still works if a browser does show it.+ if (!appWindow && RunningOnWine())+ {+ BrowserLog("No Chromium app window was opened; the classic window stays visible. " ++ "Set RESTREET_BROWSER to a Chromium-family browser path, or RESTREET_CLASSIC_UI=1 to always use the classic window.");+ Opacity = 1;+ return;+ }// Only the new interface is shown: hide the classic window (it keeps launching the game and restoring the display).- Opacity = 0;- ShowInTaskbar = false;+ HideClassicWindow();var watchdog = new System.Windows.Forms.Timer { Interval = 15000 };watchdog.Tick += (_, _) =>{@@ -81,23 +97,124 @@ public partial class LauncherFormwatchdog.Start();}+ // Viewer\ReStreetViewer.exe: a Windows Electron build placed next to the launcher (see Viewer\README.md). It runs in+ // the same Wine prefix as the launcher, so it needs nothing from the Linux side (no host browser, no Flatpak, nothing+ // Steam's Proton container hides) and its window belongs to the same session as the launcher and the game.+ // RESTREET_VIEWER_ARGS: extra command-line switches for the viewer (for example --in-process-gpu), for trying things.+ private bool OpenViewer(string url)+ {+ string dir = Path.Combine(AppContext.BaseDirectory, "Viewer");+ string exe = Path.Combine(dir, "ReStreetViewer.exe");+ if (!File.Exists(exe))+ {+ BrowserLog("No viewer at " + exe);+ return false;+ }+ try+ {+ var info = new ProcessStartInfo(exe) { UseShellExecute = false, WorkingDirectory = dir };+ info.ArgumentList.Add("--no-sandbox");+ info.ArgumentList.Add("--restreet-url=" + url);+ info.ArgumentList.Add($"--restreet-size={Width},{Height}");+ foreach (string extra in (Environment.GetEnvironmentVariable("RESTREET_VIEWER_ARGS") ?? "").Split(' ', StringSplitOptions.RemoveEmptyEntries))+ info.ArgumentList.Add(extra);+ var process = Process.Start(info);+ if (process == null) return false;+ viewerStarted = DateTime.UtcNow;+ process.EnableRaisingEvents = true;+ FormClosed += (_, _) => KillViewer(process); // an update or exit must not leave the old window open+ process.Exited += (_, _) =>+ {+ try { BeginInvoke(() => OnViewerExited()); }+ catch (Exception ex) when (ex is InvalidOperationException or ObjectDisposedException) { Debug.WriteLine(ex.Message); }+ };+ BrowserLog("Opening the launcher page in the viewer " + exe);+ return true;+ }+ catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException)+ {+ BrowserLog("The viewer could not start: " + ex.Message);+ return false;+ }+ }++ // The viewer window was closed: leave with it, unless a game or an update is running. If it died before it ever+ // loaded the page (a crash under Wine, say), bring the classic window back instead of leaving nothing on screen.+ private void OnViewerExited()+ {+ if (!browserPageServed && DateTime.UtcNow - viewerStarted < TimeSpan.FromSeconds(30))+ {+ BrowserLog("The viewer closed before the page loaded; the classic window is shown instead.");+ ShowClassicWindow();+ return;+ }+ if (!gameRunning && !updating) Close();+ }++ private static void KillViewer(Process process)+ {+ try { if (!process.HasExited) process.Kill(true); }+ catch (Exception ex) when (ex is InvalidOperationException or NotSupportedException or System.ComponentModel.Win32Exception) { Debug.WriteLine(ex.Message); }+ }++ // The classic window is not used while the page has a window of its own. Opacity 0 alone left a transparent window+ // that Wine still gave clicks to (a menu on the desktop, nothing in the taskbar) and that gamescope could pick as the+ // game's window. On Wine the window is really hidden; elsewhere it stays as before. SetVisibleCore keeps it hidden+ // when something calls Show() later.+ private void HideClassicWindow()+ {+ Opacity = 0;+ ShowInTaskbar = false;+ if (!RunningOnWine()) return;+ keepHidden = true;+ Hide();+ }++ private void ShowClassicWindow()+ {+ keepHidden = false;+ ShowInTaskbar = true;+ Opacity = 1;+ Show();+ Activate();+ }++ protected override void SetVisibleCore(bool value) => base.SetVisibleCore(keepHidden ? false : value);+// Chromium-family browsers open a URL as an app window (no tabs, no address bar) with --app; a profile of its own// makes it a new window of the requested size even when the browser is already open.private bool OpenAppWindow(string url){+ // The viewer is for Wine/Proton only. On Windows nothing below changes (RESTREET_VIEWER=1 forces it, for testing).+ if ((RunningOnWine() || Environment.GetEnvironmentVariable("RESTREET_VIEWER") == "1") && OpenViewer(url)) return true;string size = $"--window-size={Width},{Height}";if (RunningOnWine()){- string[] unix =+ var unix = new List<string>();+ // RESTREET_BROWSER: a Linux path to any Chromium-family browser (or a script that starts one with the+ // arguments it is given), tried first.+ string custom = (Environment.GetEnvironmentVariable("RESTREET_BROWSER") ?? "").Trim();+ if (custom.StartsWith('/')) unix.Add(custom);+ unix.AddRange(new[]{"/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome-stable", "/usr/bin/google-chrome","/usr/bin/brave", "/usr/bin/brave-browser", "/usr/bin/microsoft-edge-stable", "/usr/bin/vivaldi-stable",- "/var/lib/flatpak/exports/bin/org.chromium.Chromium", "/var/lib/flatpak/exports/bin/com.google.Chrome",- "/var/lib/flatpak/exports/bin/com.brave.Browser", "/var/lib/flatpak/exports/bin/com.microsoft.Edge",- };+ });+ // Flatpak browsers: system-wide installs, and the user's own (~/.local/share/flatpak), which Discover on+ // SteamOS and "flatpak install --user" use.+ string[] flatpakIds = { "org.chromium.Chromium", "com.google.Chrome", "com.brave.Browser", "com.microsoft.Edge" };+ string home = (Environment.GetEnvironmentVariable("HOME") ?? "").TrimEnd('/');+ foreach (string id in flatpakIds) unix.Add("/var/lib/flatpak/exports/bin/" + id);+ if (home.StartsWith('/'))+ foreach (string id in flatpakIds) unix.Add(home + "/.local/share/flatpak/exports/bin/" + id);// Wine maps the Linux root to Z:, and start.exe /unix runs a Linux program.string? found = unix.FirstOrDefault(p => File.Exists("Z:" + p.Replace('/', '\\')));- if (found == null) return false;+ if (found == null)+ {+ BrowserLog("No Chromium-family browser found. Tried: " + string.Join(", ", unix));+ return false;+ }+ BrowserLog("Opening the launcher page with " + found);Process.Start(new ProcessStartInfo("start.exe"){ArgumentList = { "/unix", found, "--app=" + url, size, "--user-data-dir=/tmp/restreet-launcher-ui" },@@ -124,6 +241,13 @@ public partial class LauncherFormreturn true;}+ // A short diagnostic file next to the launcher (browser-ui.log), so a failed window can be understood.+ private static void BrowserLog(string line)+ {+ try { File.AppendAllText(Path.Combine(AppContext.BaseDirectory, "browser-ui.log"), DateTime.Now.ToString("s") + " " + line + Environment.NewLine); }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { Debug.WriteLine(ex.Message); }+ }+private async Task AcceptBrowserClients(string ui){while (browserActive && browserListener != null)@@ -146,6 +270,7 @@ public partial class LauncherFormif (!path.StartsWith(prefix, StringComparison.Ordinal)) { await Respond(stream, 404, "text/plain", Array.Empty<byte>()); return; }string rest = path[prefix.Length..].Split('?')[0];browserLastSeen = DateTime.UtcNow;+ if (rest == "launcher.html") browserPageServed = true;if (method == "POST" && rest == "msg"){string json = Encoding.UTF8.GetString(body);diff --git a/Launcher/FifaStreetLauncher/Updater.cs b/Launcher/FifaStreetLauncher/Updater.csindex 211bcc7..d638e5b 100644--- a/Launcher/FifaStreetLauncher/Updater.cs+++ b/Launcher/FifaStreetLauncher/Updater.cs@@ -37,6 +37,8 @@ public partial class LauncherFormprivate async Task CheckForUpdateAsync(){if (LoadOnlineConfig() == null) return; // offline installs update with the full installer+ // RESTREET_NO_UPDATE=1: never offer an update (a self-built launcher would be replaced by the official one).+ if (Environment.GetEnvironmentVariable("RESTREET_NO_UPDATE") == "1") return;try{using var doc = JsonDocument.Parse(await UpdateHttp.GetStringAsync(ReleasesApi));diff --git a/Viewer/README.md b/Viewer/README.mdnew file mode 100644index 0000000..047cf8a--- /dev/null+++ b/Viewer/README.md@@ -0,0 +1,31 @@+# ReStreet viewer (for Linux: Wine / Proton / Steam Deck)++On Wine/Proton the launcher cannot use WebView2, so it shows its new page in a browser. Inside Steam's Proton+container that browser is often not reachable, and nothing appears. This viewer is a small Windows (Electron)+program that runs in the SAME Wine prefix as the launcher, so it needs no Linux browser and no Flatpak.++**Windows is not affected.** The launcher only looks for the viewer when it detects Wine, and Windows installs do not+need this folder. If the viewer is missing or fails, the launcher falls back to a Chromium browser and then to the+classic launcher window, so Linux never ends up with a blank screen.++## For the maintainer: make the viewer package++On Windows, with internet:++ powershell -ExecutionPolicy Bypass -File Viewer\build-viewer.ps1++This downloads the current Electron (Windows x64), renames `electron.exe` to `ReStreetViewer.exe`, adds+`resources\app` (main.js + package.json) and writes `ReStreet-Viewer.zip`. Attach it to the release as an+optional Linux download. Do not add it to the Windows installer.++## For Linux players++1. Unzip `ReStreet-Viewer.zip` into the game folder, next to `FifaStreetLauncher.exe`, so you get+ `FIFA Street PC/Viewer/ReStreetViewer.exe`.+2. Run the launcher with Proton as usual (Proton-GE recommended; it needs a prefix that reports Windows 10+).++If the window does not appear, read `browser-ui.log` next to the launcher. Steam launch options to try:++- `RESTREET_VIEWER_ARGS="--in-process-gpu"` (extra switches for the viewer)+- `RESTREET_VIEWER_GPU=1` (hardware acceleration is off in the viewer by default)+- `RESTREET_CLASSIC_UI=1` (always use the classic launcher window instead)diff --git a/Viewer/build-viewer.ps1 b/Viewer/build-viewer.ps1new file mode 100644index 0000000..794ec0e--- /dev/null+++ b/Viewer/build-viewer.ps1@@ -0,0 +1,46 @@+# Builds ReStreet-Viewer.zip: the Windows Electron runtime + the viewer app (resources\app), ready to unzip next to+# FifaStreetLauncher.exe. Run it on Windows (PowerShell 5.1 or 7) with an internet connection:+#+# powershell -ExecutionPolicy Bypass -File Viewer\build-viewer.ps1+# powershell -ExecutionPolicy Bypass -File Viewer\build-viewer.ps1 -Version 33.2.0 (a fixed Electron version)+#+# Publish the zip as an OPTIONAL Linux download. Do not put it in the Windows installer: Windows does not use it.+param(+ [string]$Version = "",+ [string]$Out = "ReStreet-Viewer.zip"+)+$ErrorActionPreference = "Stop"+$here = Split-Path -Parent $MyInvocation.MyCommand.Path+$work = Join-Path ([System.IO.Path]::GetTempPath()) "restreet-viewer-build"+if (Test-Path $work) { Remove-Item $work -Recurse -Force }+New-Item -ItemType Directory $work | Out-Null++if ($Version -eq "") {+ $release = Invoke-RestMethod "https://api.github.com/repos/electron/electron/releases/latest" -Headers @{ "User-Agent" = "restreet-viewer-build" }+ $asset = $release.assets | Where-Object { $_.name -match '^electron-v[\d\.]+-win32-x64\.zip$' } | Select-Object -First 1+ if (-not $asset) { throw "The win32-x64 Electron zip was not found in the latest Electron release." }+ $name = $asset.name+ $link = $asset.browser_download_url+} else {+ $name = "electron-v$Version-win32-x64.zip"+ $link = "https://github.com/electron/electron/releases/download/v$Version/$name"+}++$zip = Join-Path $work $name+Write-Host "Downloading $name ..."+Invoke-WebRequest $link -OutFile $zip -UseBasicParsing++$viewer = Join-Path $work "Viewer"+Expand-Archive $zip -DestinationPath $viewer+Rename-Item (Join-Path $viewer "electron.exe") "ReStreetViewer.exe"+$app = Join-Path $viewer "resources\app"+New-Item -ItemType Directory $app -Force | Out-Null+Copy-Item (Join-Path $here "resources\app\*") $app -Recurse++$dest = Join-Path (Get-Location) $Out+if (Test-Path $dest) { Remove-Item $dest -Force }+# .NET's ZipFile writes forward slashes in the entry names, so the zip also unpacks correctly on Linux+# (PowerShell 5.1's Compress-Archive does not).+Add-Type -AssemblyName System.IO.Compression.FileSystem+[System.IO.Compression.ZipFile]::CreateFromDirectory($viewer, $dest, [System.IO.Compression.CompressionLevel]::Optimal, $true)+Write-Host "Done: $dest ($name)"diff --git a/Viewer/resources/app/main.js b/Viewer/resources/app/main.jsnew file mode 100644index 0000000..b02a1a3--- /dev/null+++ b/Viewer/resources/app/main.js@@ -0,0 +1,75 @@+// ReStreet viewer: opens the launcher page, and only that page, in a window of its own.+// The launcher starts it as: ReStreetViewer.exe --no-sandbox --restreet-url=<url> --restreet-size=<w>,<h>+const { app, BrowserWindow } = require('electron');+const net = require('net');++const arg = (name) => {+ const hit = process.argv.find((a) => a.startsWith(name + '='));+ return hit ? hit.slice(name.length + 1) : '';+};++// Only the launcher's own page is accepted: loopback, a random 32-character secret path, launcher.html.+const url = arg('--restreet-url');+const valid = /^http:\/\/127\.0\.0\.1:\d+\/[0-9a-f]{32}\/launcher\.html$/.test(url);+if (!valid) app.exit(1);++// Wine and Proton: the GPU process is the usual thing that fails, and a launcher page does not need it.+// RESTREET_VIEWER_GPU=1 turns hardware acceleration back on.+if (process.env.RESTREET_VIEWER_GPU !== '1') app.disableHardwareAcceleration();+app.commandLine.appendSwitch('no-sandbox');++const [w, h] = (arg('--restreet-size').split(',').map(Number).filter((n) => n > 0));+const origin = valid ? new URL(url).origin : '';++app.whenReady().then(() => {+ if (!valid) return;+ const win = new BrowserWindow({+ width: Math.max(w || 1250, 900),+ height: Math.max(h || 720, 560),+ minWidth: 900,+ minHeight: 560,+ title: 'ReStreet Launcher',+ backgroundColor: '#0b0c12',+ autoHideMenuBar: true,+ show: false,+ // A normal frame: the page's own drag and minimize buttons are not used when it runs in a browser window.+ webPreferences: { contextIsolation: true, nodeIntegration: false },+ });+ win.removeMenu();+ win.once('ready-to-show', () => win.show());++ // The page never leaves the launcher: no pop-ups, no navigation elsewhere.+ win.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));+ win.webContents.on('will-navigate', (e, target) => { if (!target.startsWith(origin + '/')) e.preventDefault(); });++ // The launcher's server may need a moment: try again a few times before giving up.+ let tries = 0;+ win.webContents.on('did-fail-load', (_e, _code, _desc, _u, isMainFrame) => {+ if (isMainFrame && tries++ < 5) setTimeout(() => win.loadURL(url), 1000);+ });+ win.loadURL(url);+});++// If the launcher goes away (it was closed for an update, or it crashed), close this window too instead of leaving a+// dead page on screen. A plain TCP connect to the launcher's port every few seconds; three misses in a row quit.+function watchLauncher() {+ const port = Number(new URL(url).port);+ let misses = 0;+ setInterval(() => {+ const socket = net.connect({ host: '127.0.0.1', port, timeout: 4000 });+ let done = false;+ const finish = (ok) => {+ if (done) return;+ done = true;+ socket.destroy();+ misses = ok ? 0 : misses + 1;+ if (misses >= 3) app.quit();+ };+ socket.once('connect', () => finish(true));+ socket.once('error', () => finish(false));+ socket.once('timeout', () => finish(false));+ }, 5000);+}+if (valid) app.whenReady().then(() => setTimeout(watchLauncher, 15000));++app.on('window-all-closed', () => app.quit());diff --git a/Viewer/resources/app/package.json b/Viewer/resources/app/package.jsonnew file mode 100644index 0000000..ac7a00e--- /dev/null+++ b/Viewer/resources/app/package.json@@ -0,0 +1,7 @@+{+ "name": "restreet-viewer",+ "productName": "ReStreet Launcher",+ "version": "1.0.0",+ "description": "A plain window for the ReStreet launcher page (served on 127.0.0.1 by the launcher).",+ "main": "main.js"+}