Skip to content

Commit

Permalink
Netplay Refactor and UPnP
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianCassar committed Nov 16, 2023
1 parent 5eb0d3a commit 9a024f9
Show file tree
Hide file tree
Showing 32 changed files with 3,228 additions and 2,320 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,16 @@ jobs:
- name: Setup
run: .\xb setup
- name: Build
run: .\xb build --config=Release --target=src\xenia-app --target=src\xenia-vfs-dump
run: .\xb build --config=Release --target=src\xenia-app
- name: Prepare artifacts
run: |
robocopy . build\bin\${{ runner.os }}\Release LICENSE /r:0 /w:0
robocopy build\bin\${{ runner.os }}\Release artifacts\xenia_canary_netplay xenia_canary_netplay.exe xenia_canary_netplay.pdb LICENSE /r:0 /w:0
robocopy build\bin\${{ runner.os }}\Release artifacts\xenia-vfs-dump xenia-vfs-dump.exe xenia-vfs-dump.pdb LICENSE /r:0 /w:0
robocopy build\bin\${{ runner.os }}\Release artifacts\xenia_canary_netplay xenia_canary_netplay.exe LICENSE /r:0 /w:0
If ($LastExitCode -le 7) { echo "LastExitCode = $LastExitCode";$LastExitCode = 0 }
- name: Upload xenia-vfs-dump artifacts
uses: actions/upload-artifact@v3
with:
name: xenia-vfs-dump_canary_${{ matrix.config.vsver }}
path: artifacts\xenia-vfs-dump
if-no-files-found: error
- name: Upload xenia artifacts
uses: actions/upload-artifact@v3
with:
name: xenia_canary_${{ matrix.config.vsver }}
name: xenia_canary_netplay_${{ matrix.config.vsver }}
path: artifacts\xenia_canary_netplay
if-no-files-found: error
- name: Create release
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@
[submodule "third_party/libcurl"]
path = third_party/libcurl
url = https://github.com/curl/curl.git
[submodule "third_party/miniupnp"]
path = third_party/miniupnp
url = https://github.com/miniupnp/miniupnp.git
[submodule "third_party/wolfssl"]
path = third_party/wolfssl
url = https://github.com/wolfssl/wolfssl.git
99 changes: 94 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Netplay Fork

This is a fork of [Xenia-Canary Netplay](https://github.com/craftycodie/sunrise-xenia-canary-netplay) which implements Online Multiplayer features.
It has been built from the ground up and tested primarily with Halo 3, though other games are supported.
In it's current state, the fork is very rough and not PR ready. Check out the [Issues](https://github.com/craftycodie/xenia-canary-netplay/issues) list for more on that.
Please excuse the mess, I don't use C++ often and rushed this together in a couple of restless weeks. The code will improve in future.
This is a fork of [Xenia-Canary Netplay](https://github.com/ahnewark/sunrise-xenia-canary-netplay) which implements online multiplayer features.
It has been built from the ground up and a handful of games found to work, though many games are yet to be tested. Check out the [Issues](https://github.com/ahnewark/sunrise-xenia-canary-netplay/issues) list for more details.

The web API powering this fork can be found [here](https://github.com/craftycodie/Xenia-WebServices)
The REST API powering this fork can be found [here](https://github.com/AdrianCassar/Xenia-WebServices).

Massive thanks to @SarahGreyWolf for testing this fork with me for about a month, couldn't have done it without her.
Also, thank you to @Bo98 for creating the burnout5 xenia fork, I used that as a basis for this, and some of the code is still here I think.
Expand All @@ -16,6 +14,97 @@ Codie

---

## FAQ:

Is UPnP implemented?
- Yes, **UPnP** is now implemented therefore manual port forwarding is no longer required.

Is **Systemlink** or **XLink Kai** supported?

- No, Systemlink and XLink Kai are not supported.

Can I host Xenia Web Services?

- Yes, [Xenia Web Services](https://github.com/AdrianCassar/Xenia-WebServices).

Is there a Netplay mousehook build?

- Yes, download it from [Netplay Mousehook](https://github.com/marinesciencedude/xenia-canary-mousehook/releases?q=Netplay).

Are games dependant on servers?

- Yes a lot of games are dependant on servers therefore will not work, unless a server is developed for that game. For example many games requires EA servers, without them netplay will not work.

Can I use multiple instances for the same game?

- No, you cannot use multiple instances due to the first instance using up ports. You will need to use a VM.

Can I use multiple PCs on the same network?

- No, you currently cannot use different PCs on the same network to connect to a session hosted on the same network. However a VPN will get around this issue.

Where can I **download** the Canary Netplay build?

- You can download it from [releases](https://github.com/AdrianCassar/xenia-canary/releases).

## Config Setup

To connect to a **Xenia WebServices** server you can either privately host it yourself or connect to my server.

```toml
api_address = "https://xenia-netplay-2a0298c0e3f4.herokuapp.com/"
```

UPnP is disabled by default, you can enable it in the config.
```toml
upnp = true
```

## Supported Games

| Game | Notes | Patches/Plugins |
|---|---|---|
| CS:GO | Mousehook support |
| CS:GO Beta | Mousehook support |
| GTA V Beta | [Video 1](https://www.youtube.com/watch?v=nIjZ7sRGZlo), [Video 2](https://www.youtube.com/watch?v=YIBjy5ZJcq4) |
| GTA V TU 2-13 | Very unstable and will crash often |
| Gundam Operation Troy | [English patch](https://github.com/Eight-Mansions/MSGOT/releases)
| Halo 3 ODST v13.2 using [Sunrise Server](https://github.com/ahnewark/Sunrise-Halo3-WebServices) | [Video](https://www.youtube.com/watch?v=amS8OxH3exs), Mousehook support | [Halo 3 Patch](https://github.com/AdrianCassar/Xenia-WebServices/blob/main/patches/4D5307E6%20-%20Halo%203.patch.toml)
| Left 4 Dead 2 | Mousehook support |
| Left 4 Dead 2 Demo |
| Marvel Ultimate Alliance | |
| Marvel Ultimate Alliance 2 | |
| Portal 2 | Mousehook support |
| Saints Row 2 | [Video 1](https://www.youtube.com/watch?v=YTw84keeWfs), [Video 2](https://www.youtube.com/watch?v=nf7TDOtTEIE) |
| Saints Row the Third / The Full Package | Unplayable due to broken graphics. Requires [Online Pass](https://www.xbox.com/en-GB/games/store/online-pass/BS7JTR0MN356) + license_mask|
| Saints Row IV | Unplayable due to broken graphics. Requires Online Pass + license_mask|
| Team Fortress 2 | Mousehook support |
---

### Non-Supported Games

| Game | Description |
|---|---|
| Gears of War 3 | Connects online but cannot play with others. |
| Grand Theft Auto 4 | Connects online but cannot play with others. |
| Minecraft | Requires friend lists to invite friends. |
| Quantum of a Solace | Crashes on start-up. |
| Red Dead Redemption | Connects online but cannot play with others. |
| Saints Row 1 | Unstable to find sessions to join. |

#### Requires Servers
- Activision Games
- EA Games
- Ubisoft Games

---

### [Netplay Mousehook](https://github.com/marinesciencedude/xenia-canary-mousehook/tree/netplay_canary_experimental#mousehook)

Netplay mousehook is a fork of netplay which adds support for playing games with mouse and keyboard.

---

<p align="center">
<a href="https://github.com/xenia-project/xenia/tree/master/assets/icon">
<img height="120px" src="https://raw.githubusercontent.com/xenia-project/xenia/master/assets/icon/128.png" />
Expand Down
3 changes: 2 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ includedirs({
defines({
"_UNICODE",
"UNICODE",
"CURL_STATICLIB",
})

cppdialect("C++17")
Expand Down Expand Up @@ -265,6 +264,8 @@ workspace("xenia")
include("third_party/zarchive.lua")
include("third_party/zstd.lua")
include("third_party/rapidjson.lua")
include("third_party/miniupnp.lua")
include("third_party/wolfssl.lua")

if not os.istarget("android") then
-- SDL2 requires sdl2-config, and as of November 2020 isn't high-quality on
Expand Down
30 changes: 4 additions & 26 deletions src/xenia/app/emulator_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

// Autogenerated by `xb premake`.
#include "build/version.h"
#include <xenia/kernel/XLiveAPI.h>

DECLARE_bool(debug);

Expand Down Expand Up @@ -1536,37 +1537,14 @@ xe::X_STATUS EmulatorWindow::RunTitle(std::filesystem::path path_to_file) {
"Failed to launch title.\n\nCheck xenia.log for technical details.");
} else {
AddRecentlyLaunchedTitle(path_to_file, emulator_->title_name());
DeleteAllSessions();

// Delete sessions on start-up
xe::kernel::XLiveAPI::DeleteAllSessions();
}

return result;
}

void EmulatorWindow::DeleteAllSessions() {
#pragma region CURL, Refactor Out
CURL* curl = curl_easy_init();

if (curl) {
std::stringstream url;
url << cvars::api_address << "/DeleteSessions";

struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "charset: utf-8");

curl_easy_setopt(curl, CURLOPT_URL, url.str().c_str());

curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "xenia");

curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
#pragma endregion
}

void EmulatorWindow::RunPreviouslyPlayedTitle() {
if (recently_launched_titles_.size() >= 1) {
RunTitle(recently_launched_titles_[0].path_to_file);
Expand Down
1 change: 0 additions & 1 deletion src/xenia/app/emulator_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class EmulatorWindow {
void ShutdownGraphicsSystemPresenterPainting();

void OnEmulatorInitialized();
void DeleteAllSessions();

xe::X_STATUS RunTitle(std::filesystem::path path_to_file);
void UpdateTitle();
Expand Down
3 changes: 3 additions & 0 deletions src/xenia/app/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ project("xenia-app")
"snappy",
"xxhash",
"libcurl",
"miniupnp",
})
defines({
"XBYAK_NO_OP_NAMES",
"XBYAK_ENABLE_OMITTED_OPERAND",
"CURL_STATICLIB",
"MINIUPNP_STATICLIB"
})
local_platform_files()
files({
Expand Down
15 changes: 13 additions & 2 deletions src/xenia/app/xenia_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
#endif // XE_PLATFORM_WIN32

#include "third_party/fmt/include/fmt/format.h"
#include "third_party/libcurl/include/curl/curl.h"

#include "xenia/kernel/XLiveAPI.h"

DEFINE_string(apu, "any", "Audio system. Use: [any, nop, sdl, xaudio2]", "APU");
DEFINE_string(gpu, "any", "Graphics system. Use: [any, d3d12, vulkan, null]",
Expand Down Expand Up @@ -103,6 +104,8 @@ DECLARE_bool(debug);

DEFINE_bool(discord, true, "Enable Discord rich presence", "General");

DECLARE_bool(upnp);

namespace xe {
namespace app {

Expand Down Expand Up @@ -478,9 +481,17 @@ void EmulatorApp::OnDestroy() {
// The profiler needs to shut down before the graphics context.
Profiler::Shutdown();

emulator_window_->DeleteAllSessions();
#pragma region NetplayCleanup
// UPnP Shutdown

if (cvars::upnp) {
xe::kernel::XLiveAPI::upnp_handler.~upnp();
}

xe::kernel::XLiveAPI::DeleteAllSessions();

curl_global_cleanup();
#pragma endregion

// Write all cvar overrides to the config.
config::SaveConfig();
Expand Down
5 changes: 0 additions & 5 deletions src/xenia/emulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ DEFINE_bool(allow_game_relative_writes, false,
"generating test data to compare with original hardware. ",
"General");

DEFINE_string(api_address, "127.0.0.1:36000", "Xenia Master Server Address",
"Live");

DEFINE_bool(logging, false, "Log Network Activity", "Live");

DECLARE_int32(user_language);

DECLARE_bool(allow_plugins);
Expand Down
Loading

0 comments on commit 9a024f9

Please sign in to comment.