Skip to content

Commit

Permalink
Further refactoring work for multiple game support.
Browse files Browse the repository at this point in the history
  • Loading branch information
TLeonardUK committed Dec 29, 2023
1 parent 6f029a6 commit 95712ff
Show file tree
Hide file tree
Showing 148 changed files with 1,128 additions and 218,504 deletions.
Binary file added Build/Bin/Loader/Package/Loader.pdb
Binary file not shown.
11 changes: 9 additions & 2 deletions Source/Server.DarkSouls2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
project(DarkSouls2 C CXX)

SET(SOURCES
Protobuf/DarkSouls2/DS2_Frpg2PlayerData.pb.cc
Protobuf/DarkSouls2/DS2_Frpg2RequestMessage.pb.cc
Protobuf/DS2_Protobufs.h
Protobuf/Generated/DS2_Frpg2PlayerData.pb.cc
Protobuf/Generated/DS2_Frpg2RequestMessage.pb.cc

Server/GameService/DarkSouls2/DS2_PlayerState.h

Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessageTypes.inc
Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessage.h

Server/DS2_Game.h
Server/DS2_Game.cpp
)

add_library(${PROJECT_NAME} STATIC ${SOURCES} ${PLATFORM_SOURCES})
Expand Down
22 changes: 22 additions & 0 deletions Source/Server.DarkSouls2/Protobuf/DS2_Protobufs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Dark Souls 3 - Open Server
* Copyright (C) 2021 Tim Leonard
*
* This program is free software; licensed under the MIT license.
* You should have received a copy of the license along with this program.
* If not, see <https://opensource.org/licenses/MIT>.
*/

#pragma once

// The version of protobuf we have to use to support DS3 doesn't generate
// code that compiles without warnings under x64 (lots of size_t truncation).
// To keep things a bit cleaner we import all the files through this header and cpp.
#pragma warning(disable: 4267 4244 4018)

#include "Server.DarkSouls2/Protobuf/Generated/DS2_Frpg2PlayerData.pb.h"
#include "Server.DarkSouls2/Protobuf/Generated/DS2_Frpg2RequestMessage.pb.h"

#include "Server/Protobuf/SharedProtobufs.h"

#pragma warning(default: 4267 4244 4018)
138 changes: 138 additions & 0 deletions Source/Server.DarkSouls2/Server/DS2_Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Dark Souls 3 - Open Server
* Copyright (C) 2021 Tim Leonard
*
* This program is free software; licensed under the MIT license.
* You should have received a copy of the license along with this program.
* If not, see <https://opensource.org/licenses/MIT>.
*/

#include "Server/DS2_Game.h"
#include "Protobuf/DS2_Protobufs.h"
#include "Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessage.h"
#include "Server/GameService/DarkSouls2/DS2_PlayerState.h"

bool DS2_Game::Protobuf_To_ReliableUdpMessageType(google::protobuf::MessageLite* Message, Frpg2ReliableUdpMessageType& Output)
{
#define DEFINE_REQUEST_RESPONSE(OpCode, Type, ProtobufClass, ResponseProtobufClass) \
if (dynamic_cast<DS2_Frpg2RequestMessage::ProtobufClass*>(Message) != nullptr) \
{ \
Output = (Frpg2ReliableUdpMessageType)(int)DS2_Frpg2ReliableUdpMessageType::Type; \
return true; \
}
#define DEFINE_MESSAGE(OpCode, Type, ProtobufClass) \
if (dynamic_cast<DS2_Frpg2RequestMessage::ProtobufClass*>(Message) != nullptr) \
{ \
Output = (Frpg2ReliableUdpMessageType)(int)DS2_Frpg2ReliableUdpMessageType::Type; \
return true; \
}
#define DEFINE_PUSH_MESSAGE(OpCode, Type, ProtobufClass) \
if (dynamic_cast<DS2_Frpg2RequestMessage::ProtobufClass*>(Message) != nullptr) \
{ \
Output = Frpg2ReliableUdpMessageType::Push; /* Not using push */ \
return true; \
}
#include "Server.DarkSouls2/Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessageTypes.inc"
#undef DEFINE_PUSH_MESSAGE
#undef DEFINE_MESSAGE
#undef DEFINE_REQUEST_RESPONSE

return false;
}

bool DS2_Game::ReliableUdpMessageType_To_Protobuf(Frpg2ReliableUdpMessageType InType, bool IsResponse, std::shared_ptr<google::protobuf::MessageLite>& Output)
{
#define DEFINE_REQUEST_RESPONSE(OpCode, Type, ProtobufClass, ResponseProtobufClass) \
if ((int)InType == (int)DS2_Frpg2ReliableUdpMessageType::Type) \
{ \
if (IsResponse) \
{ \
Output = std::make_shared<DS2_Frpg2RequestMessage::ResponseProtobufClass>(); \
} \
else \
{ \
Output = std::make_shared<DS2_Frpg2RequestMessage::ProtobufClass>(); \
} \
return true; \
}
#define DEFINE_MESSAGE(OpCode, Type, ProtobufClass) \
if ((int)InType == (int)DS2_Frpg2ReliableUdpMessageType::Type) \
{ \
if (IsResponse) \
{ \
return false; \
} \
else \
{ \
Output = std::make_shared<DS2_Frpg2RequestMessage::ProtobufClass>(); \
return true; \
} \
}
#define DEFINE_PUSH_MESSAGE(OpCode, Type, ProtobufClass) /* Not supported on server, server only sends these */
#include "Server.DarkSouls2/Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessageTypes.inc"
#undef DEFINE_PUSH_MESSAGE
#undef DEFINE_MESSAGE
#undef DEFINE_REQUEST_RESPONSE

return false;
}

bool DS2_Game::ReliableUdpMessageType_Expects_Response(Frpg2ReliableUdpMessageType InType)
{
if ((int)InType == (int)DS2_Frpg2ReliableUdpMessageType::Push)
{
return false;
}

#define DEFINE_REQUEST_RESPONSE(OpCode, Type, ProtobufClass, ResponseProtobufClass) \
if ((int)InType == (int)DS2_Frpg2ReliableUdpMessageType::Type) \
{ \
return true; \
}
#define DEFINE_MESSAGE(OpCode, Type, ProtobufClass) \
if ((int)InType == (int)DS2_Frpg2ReliableUdpMessageType::Type) \
{ \
return false; \
}
#define DEFINE_PUSH_MESSAGE(OpCode, Type, ProtobufClass) /* Not required, gets caught by Push test above */
#include "Server.DarkSouls2/Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessageTypes.inc"
#undef DEFINE_PUSH_MESSAGE
#undef DEFINE_MESSAGE
#undef DEFINE_REQUEST_RESPONSE

return false;
}

std::string DS2_Game::GetBossDiscordThumbnailUrl(uint32_t BossId)
{
// TODO

return "";
}

void DS2_Game::RegisterGameManagers(GameService& Service)
{
// TODO
}

std::unique_ptr<PlayerState> DS2_Game::CreatePlayerState()
{
return std::make_unique<DS2_PlayerState>();
}

std::string DS2_Game::GetAreaName(uint32_t AreaId)
{
// TODO

return "";
}

void DS2_Game::GetStatistics(GameService& Service, std::unordered_map<std::string, std::string>& Stats)
{
// TODO
}

void DS2_Game::SendManagementMessage(Frpg2ReliableUdpMessageStream& stream, const std::string& TextMessage)
{
// TODO
}
33 changes: 33 additions & 0 deletions Source/Server.DarkSouls2/Server/DS2_Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Dark Souls 3 - Open Server
* Copyright (C) 2021 Tim Leonard
*
* This program is free software; licensed under the MIT license.
* You should have received a copy of the license along with this program.
* If not, see <https://opensource.org/licenses/MIT>.
*/

#pragma once

#include "Server/Game.h"

class DS2_Game : public Game
{
public:

virtual bool Protobuf_To_ReliableUdpMessageType(google::protobuf::MessageLite* Message, Frpg2ReliableUdpMessageType& Output) override;
virtual bool ReliableUdpMessageType_To_Protobuf(Frpg2ReliableUdpMessageType Type, bool IsResponse, std::shared_ptr<google::protobuf::MessageLite>& Output) override;
virtual bool ReliableUdpMessageType_Expects_Response(Frpg2ReliableUdpMessageType Type) override;

virtual void RegisterGameManagers(GameService& Service) override;
virtual std::unique_ptr<PlayerState> CreatePlayerState() override;

virtual std::string GetAreaName(uint32_t AreaId) override;

virtual std::string GetBossDiscordThumbnailUrl(uint32_t BossId) override;

virtual void GetStatistics(GameService& Service, std::unordered_map<std::string, std::string>& Stats) override;

virtual void SendManagementMessage(Frpg2ReliableUdpMessageStream& stream, const std::string& TextMessage) override;

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Dark Souls 3 - Open Server
* Copyright (C) 2021 Tim Leonard
*
* This program is free software; licensed under the MIT license.
* You should have received a copy of the license along with this program.
* If not, see <https://opensource.org/licenses/MIT>.
*/

#pragma once

#include <string>

#include "Protobuf/DS2_Protobufs.h"

#include "Server/GameService/PlayerState.h"

struct DS2_PlayerState : public PlayerState
{
public:

virtual uint32_t GetCurrentAreaId() override
{
return 0;
}

virtual bool IsInGame() override
{
return false;
}

virtual size_t GetSoulCount() override
{
return 0;
}

virtual size_t GetSoulMemory() override
{
return 0;
}

virtual size_t GetDeathCount() override
{
return 0;
}

virtual size_t GetMultiplayerSessionCount() override
{
return 0;
}

virtual double GetPlayTime() override
{
return 0.0;
}

virtual std::string GetConvenantStatusDescription() override
{
return "";
}

virtual std::string GetStatusDescription() override
{
return "";
}

};

#undef DEFINE_FIELD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Dark Souls 3 - Open Server
* Copyright (C) 2021 Tim Leonard
*
* This program is free software; licensed under the MIT license.
* You should have received a copy of the license along with this program.
* If not, see <https://opensource.org/licenses/MIT>.
*/

#pragma once

#include "Shared/Core/Utils/Endian.h"
#include "Shared/Game/GameType.h"

#include <vector>
#include <memory>

#include "Protobuf/SharedProtobufs.h"

enum class DS2_Frpg2ReliableUdpMessageType : int
{
Reply = 0x0,
Push = 0x0320,

#define DEFINE_REQUEST_RESPONSE(OpCode, Type, ProtobufClass, ResponseProtobufClass) Type = OpCode,
#define DEFINE_MESSAGE(OpCode, Type, ProtobufClass) Type = OpCode,
#define DEFINE_PUSH_MESSAGE(OpCode, Type, ProtobufClass) /* Do Nothing */
#include "Server.DarkSouls2/Server/Streams/DarkSouls2/DS2_Frpg2ReliableUdpMessageTypes.inc"
#undef DEFINE_PUSH_MESSAGE
#undef DEFINE_MESSAGE
#undef DEFINE_REQUEST_RESPONSE
};
13 changes: 10 additions & 3 deletions Source/Server.DarkSouls3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
project(DarkSouls3 C CXX)

SET(SOURCES
Protobuf/DarkSouls3/DS3_FpdLogMessage.pb.cc
Protobuf/DarkSouls3/DS3_Frpg2PlayerData.pb.cc
Protobuf/DarkSouls3/DS3_Frpg2RequestMessage.pb.cc
Protobuf/DS3_Protobufs.h
Protobuf/Generated/DS3_FpdLogMessage.pb.cc
Protobuf/Generated/DS3_Frpg2PlayerData.pb.cc
Protobuf/Generated/DS3_Frpg2RequestMessage.pb.cc

Server/GameService/DarkSouls3/DS3_PlayerState.h

Server/GameService/DarkSouls3/GameManagers/BloodMessage/BloodMessageManager.cpp
Server/GameService/DarkSouls3/GameManagers/BloodMessage/BloodMessageManager.h
Server/GameService/DarkSouls3/GameManagers/Bloodstain/BloodstainManager.cpp
Expand Down Expand Up @@ -71,6 +74,10 @@ SET(SOURCES
Server/GameService/DarkSouls3/Utils/Data/BloodMessageData.cpp

Server/Streams/DarkSouls3/DS3_Frpg2ReliableUdpMessageTypes.inc
Server/Streams/DarkSouls3/DS3_Frpg2ReliableUdpMessage.h

Server/DS3_Game.h
Server/DS3_Game.cpp
)

add_library(${PROJECT_NAME} STATIC ${SOURCES} ${PLATFORM_SOURCES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
// To keep things a bit cleaner we import all the files through this header and cpp.
#pragma warning(disable: 4267 4244 4018)

#include "Server.DarkSouls3/Protobuf/DarkSouls3/DS3_FpdLogMessage.pb.h"
#include "Server.DarkSouls3/Protobuf/DarkSouls3/DS3_Frpg2PlayerData.pb.h"
#include "Server.DarkSouls3/Protobuf/DarkSouls3/DS3_Frpg2RequestMessage.pb.h"
#include "Server.DarkSouls3/Protobuf/Generated/DS3_FpdLogMessage.pb.h"
#include "Server.DarkSouls3/Protobuf/Generated/DS3_Frpg2PlayerData.pb.h"
#include "Server.DarkSouls3/Protobuf/Generated/DS3_Frpg2RequestMessage.pb.h"

#include "Server.DarkSouls2/Protobuf/DarkSouls2/DS2_Frpg2PlayerData.pb.h"
#include "Server.DarkSouls2/Protobuf/DarkSouls2/DS2_Frpg2RequestMessage.pb.h"

#include "Shared/Shared_FpdLogMessage.pb.h"
#include "Shared/Shared_Frpg2PlayerData.pb.h"
#include "Shared/Shared_Frpg2RequestMessage.pb.h"
#include "Server/Protobuf/SharedProtobufs.h"

#pragma warning(default: 4267 4244 4018)
Loading

0 comments on commit 95712ff

Please sign in to comment.