Skip to content

Commit

Permalink
Add target to run Cyberpunk directly (#26)
Browse files Browse the repository at this point in the history
* Clean up client, add a Cyberpunk2077 target to debug

* Configurable debug

* Fix path

* Rename option to game

* Update xmake.lua

* Adapt option passing to game's parser

* Document debug process

* Fix install target

* Protect crash when DLL is not loaded correctly

* Update README.md
  • Loading branch information
maximegmd authored Nov 26, 2024
1 parent 4b7a4f4 commit 2972a70
Show file tree
Hide file tree
Showing 59 changed files with 128 additions and 2,048 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ to handle RPC functionality.
If you want visual studio projects execute `xmake project -k vsxmake` and you
will find the sln in the newly created `vsxmake` folder.

In addition, if you want to debug the project directly from with Visual Studio
you can set the game path `xmake f --game="C:/.../Cyberpunk2077.exe"`. In Visual
Studio you will then have a project named `Cyberpunk2077`, debug this target in
`Debug` only, it will not work in other modes.

> [!IMPORTANT]
> On Windows, you'll need to use Windows SDK **below** v10.0.26100.0. An issue
> is currently breaking the build due to package `protobuf-cpp`.
Expand All @@ -46,7 +51,3 @@ will find the sln in the newly created `vsxmake` folder.
- [Codeware](https://github.com/psiberx/cp2077-codeware/releases/)
- [Input Loader](https://github.com/jackhumbert/cyberpunk2077-input-loader/releases)

## Running

From visual studio, just start the Client project with the debugger, it will
ask you to locate the game, once you have everything should run.
4 changes: 2 additions & 2 deletions code/assets/redscript/Ink/MultiplayerGameController.reds
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public class MultiplayerGameController extends inkGameController {
if serverData.m_test {
this.GetUIBlackboard().SetBool(GetAllBlackboardDefs().UIGameData.UIMultiplayerConnectedToServer, true, true);
} else {
GameInstance.GetNetworkWorldSystem().Connect(serverData.m_name);
GameInstance.GetNetworkWorldSystem().Connect();
}
} else {
CMPLog(s"No server selected");
Expand Down Expand Up @@ -957,7 +957,7 @@ public class MultiplayerGameController extends inkGameController {
if !this.m_serverListOpen {
if Equals(actionName, n"UIConnectToServer") && Equals(actionType, gameinputActionType.BUTTON_HOLD_COMPLETE) {
// this.ShowServerList(true);
GameInstance.GetNetworkWorldSystem().Connect(s"");
GameInstance.GetNetworkWorldSystem().Connect();
return true;
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion code/assets/redscript/World/NetworkWorldSystem.reds
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Codeware.*
import CyberpunkMP.*

public native class NetworkWorldSystem extends IGameSystem {
public native func Connect(address: String) -> Void;
public native func Connect() -> Void;
public native func Disconnect() -> Void;
public native func GetEntityIdByServerId(serverId: Uint64) -> EntityID;
public native func GetAppearanceSystem() -> ref<AppearanceSystem>;
Expand Down
30 changes: 30 additions & 0 deletions code/client/App/Settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "Settings.h"
#include <RED4ext/LaunchParameters.hpp>

void Settings::Load()
{
Settings& settings = Get();

auto& launchParameters = RED4ext::GetLaunchParameters();

if (launchParameters.Contains(RED4ext::CString("-online")))
settings.enabled = true;

if (const auto ip = launchParameters.Get("-ip"); ip)
{
if (ip->size > 0)
settings.ip = (*ip)[0].c_str();
}

if (const auto port = launchParameters.Get("-port"); port)
{
if (port->size > 0)
settings.ip = (*port)[0].c_str();
}

if (const auto mods = launchParameters.Get("-mod"); mods)
{
for (const auto& mod : *mods)
settings.mods.push_back(mod.c_str());
}
}
24 changes: 24 additions & 0 deletions code/client/App/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

namespace fs = std::filesystem;

struct Settings
{
static Settings& Get()
{
static Settings instance;
return instance;
}
static void Load();

fs::path exePath{};
fs::path gamePath{};
String Version{};
String ip = "127.0.0.1";
uint16_t port = 11778;
Vector<fs::path> mods = {};
bool enabled = false;

private:
Settings() = default;
};
10 changes: 7 additions & 3 deletions code/client/App/World/NetworkWorldSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "NetworkWorldSystem.h"

#include <App/Settings.h>

#include "App/Network/NetworkService.h"
#include "RED4ext/Scripting/Natives/Generated/game/Puppet.hpp"
#include "RED4ext/Scripting/Natives/Generated/vehicle/BaseObject.hpp"
Expand All @@ -14,7 +16,6 @@
#include "App/Components/InterpolationComponent.h"
#include "Game/Utils.h"
#include "Game/CharacterCustomizationSystem.h"
#include <Launcher/Launcher.h>

#include "ChatSystem.h"

Expand Down Expand Up @@ -364,6 +365,9 @@ void NetworkWorldSystem::OnInitialize(const RED4ext::JobHandle& aJob)

IGameSystem::OnInitialize(aJob);

if (!Settings::Get().enabled)
return;

const auto pNetworkService = Core::Container::Get<NetworkService>();
pNetworkService->RegisterHandler<&NetworkWorldSystem::HandleCharacterLoad>(this);
pNetworkService->RegisterHandler<&NetworkWorldSystem::HandleEntityUnload>(this);
Expand All @@ -387,9 +391,9 @@ void NetworkWorldSystem::OnInitialize(const RED4ext::JobHandle& aJob)
m_vehicleSystem->OnInitialize(aJob);
}

void NetworkWorldSystem::Connect(const Red::CString& aAddress)
void NetworkWorldSystem::Connect()
{
auto address = fmt::format("{}:{}", launcher::GetLaunchContext()->ip, launcher::GetLaunchContext()->port);
auto address = fmt::format("{}:{}", Settings::Get().ip, Settings::Get().port);
Core::Container::Get<NetworkService>()->Connect(address);
}

Expand Down
2 changes: 1 addition & 1 deletion code/client/App/World/NetworkWorldSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct NetworkWorldSystem : RED4ext::IGameSystem, Core::HookingAgent, flecs::wor

void OnInitialize(const RED4ext::JobHandle& aJob) override;

void Connect(const Red::CString& aAddress);
void Connect();
void Disconnect();
void OnConnected();
void OnDisconnected(Client::EDisconnectReason);
Expand Down
1 change: 0 additions & 1 deletion code/client/App/World/VehicleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "NetworkWorldSystem.h"
#include "Game/Utils.h"
#include <Launcher/Launcher.h>
#include "App/Components/EntityComponent.h"
#include "App/Components/AttachedComponent.h"
#include "App/Components/SpawningComponent.h"
Expand Down
115 changes: 0 additions & 115 deletions code/client/Launcher/Launcher.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions code/client/Launcher/Launcher.h

This file was deleted.

29 changes: 0 additions & 29 deletions code/client/Launcher/TargetConfig.h

This file was deleted.

9 changes: 0 additions & 9 deletions code/client/Launcher/loader/ExeCache.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions code/client/Launcher/loader/ExeCache.h

This file was deleted.

Loading

0 comments on commit 2972a70

Please sign in to comment.