Skip to content
2 changes: 1 addition & 1 deletion Code/client/Games/Skyrim/BSGraphics/BSGraphicsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Hook_Renderer_Init(Renderer* self, BSGraphics::RendererInitOSData* aOSData,

Renderer_Init(self, aOSData, aFBData, aOut);

g_sRs = &World::Get().ctx<RenderSystemD3D11>();
g_sRs = &World::Get().ctx().at<RenderSystemD3D11>();
// This how the game does it too
g_RenderWindow = &self->Data.RenderWindowA[0];

Expand Down
5 changes: 2 additions & 3 deletions Code/client/Games/Skyrim/Interface/MenuControls.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

class MenuControls
struct MenuControls
{
public:
static MenuControls* GetInstance();

void SetToggle(bool);

private:
private:
char pad_0000[128]; // 0x0000
bool isProcessing; // 0x0080
bool isBeastForm; // 0x0081
Expand Down
15 changes: 15 additions & 0 deletions Code/client/Games/Skyrim/RTTI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

const VersionDbPtr<internal::TDynamicCast> internal::DynamicCast(109689);

namespace internal
{
template <class T>
RttiLocator<T>::RttiLocator(uint32_t aId)
{
m_pRtti = TiltedPhoques::MakeUnique<VersionDbPtr<void*>>(aId);
}

template <class T>
const void* RttiLocator<T>::Get()
{
return *m_pRtti;
}
} // namespace internal

template struct internal::RttiLocator<IFormFactory>;
internal::RttiLocator<IFormFactory> registerRtti_IFormFactory(392214);
template struct internal::RttiLocator<BaseFormComponent>;
Expand Down
11 changes: 2 additions & 9 deletions Code/client/Games/Skyrim/RTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ namespace internal
template <class T>
struct RttiLocator
{
RttiLocator(uint32_t aId)
{
m_pRtti = TiltedPhoques::MakeUnique<VersionDbPtr<void*>>(aId);
}

static const void* Get()
{
return *m_pRtti;
}
RttiLocator(uint32_t aId);
static const void* Get();

static inline UniquePtr<VersionDbPtr<void*>> m_pRtti;
};
Expand Down
6 changes: 3 additions & 3 deletions Code/client/Services/Generic/InputService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ LRESULT CALLBACK InputService::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPAR
if (!pRenderer)
return 0;

auto &discord = World::Get().ctx<DiscordService>();
auto &discord = World::Get().ctx().at<DiscordService>();
discord.WndProcHandler(hwnd, uMsg, wParam, lParam);

const bool active = s_pOverlay->GetActive();
if (active)
{
auto& imgui = World::Get().ctx<ImguiService>();
auto& imgui = World::Get().ctx().at<ImguiService>();
imgui.WndProcHandler(hwnd, uMsg, wParam, lParam);
}

Expand All @@ -348,7 +348,7 @@ LRESULT CALLBACK InputService::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPAR

if (active)
{
auto& imgui = World::Get().ctx<ImguiService>();
auto& imgui = World::Get().ctx().at<ImguiService>();
imgui.RawInputHandler(input);
}

Expand Down
2 changes: 1 addition & 1 deletion Code/client/Services/Generic/TransportService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void TransportService::OnConnected()

// null if discord is not active
// TODO: think about user opt out
request.DiscordId = m_world.ctx<DiscordService>().GetUser().id;
request.DiscordId = m_world.ctx().at<DiscordService>().GetUser().id;
auto* pNpc = Cast<TESNPC>(PlayerCharacter::Get()->baseForm);
if (pNpc)
{
Expand Down
6 changes: 3 additions & 3 deletions Code/client/Services/PapyrusService.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ template <class Return, class Type, class... Args> struct LatentPapyrusFunction
TFunction m_pFunction;
};

#define PAPYRUS_FUNCTION(returnType, scope, name, ...) static PapyrusFunction<returnType, scope, __VA_ARGS__> s_p##name(World::Get().ctx<PapyrusService>().Get(#scope, #name));
#define GLOBAL_PAPYRUS_FUNCTION(returnType, scope, name, ...) static GlobalPapyrusFunction<returnType, __VA_ARGS__> s_p##name(World::Get().ctx<PapyrusService>().Get(#scope, #name));
#define LATENT_PAPYRUS_FUNCTION(returnType, scope, name, ...) static LatentPapyrusFunction<returnType, scope, __VA_ARGS__> s_p##name(World::Get().ctx<PapyrusService>().Get(#scope, #name));
#define PAPYRUS_FUNCTION(returnType, scope, name, ...) static PapyrusFunction<returnType, scope, __VA_ARGS__> s_p##name(World::Get().ctx().at<PapyrusService>().Get(#scope, #name));
#define GLOBAL_PAPYRUS_FUNCTION(returnType, scope, name, ...) static GlobalPapyrusFunction<returnType, __VA_ARGS__> s_p##name(World::Get().ctx().at<PapyrusService>().Get(#scope, #name));
#define LATENT_PAPYRUS_FUNCTION(returnType, scope, name, ...) static LatentPapyrusFunction<returnType, scope, __VA_ARGS__> s_p##name(World::Get().ctx().at<PapyrusService>().Get(#scope, #name));
4 changes: 2 additions & 2 deletions Code/client/TiltedOnlineApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void* TiltedOnlineApp::GetMainAddress() const
bool TiltedOnlineApp::BeginMain()
{
World::Create();
World::Get().ctx<DiscordService>().Init();
World::Get().set<RenderSystemD3D11>(World::Get().ctx<OverlayService>(), World::Get().ctx<ImguiService>());
World::Get().ctx().at<DiscordService>().Init();
World::Get().ctx().emplace<RenderSystemD3D11>(World::Get().ctx().at<OverlayService>(), World::Get().ctx().at<ImguiService>());

LoadScriptExender();
return true;
Expand Down
40 changes: 20 additions & 20 deletions Code/client/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ World::World()
, m_modSystem(m_dispatcher)
, m_lastFrameTime{ std::chrono::high_resolution_clock::now() }
{
set<ImguiService>();
set<DiscoveryService>(*this, m_dispatcher);
set<OverlayService>(*this, m_transport, m_dispatcher);
set<InputService>(ctx<OverlayService>());
set<CharacterService>(*this, m_dispatcher, m_transport);
set<DebugService>(m_dispatcher, *this, m_transport, ctx<ImguiService>());
set<ScriptService>(*this, m_dispatcher, ctx<ImguiService>(), m_transport);
set<PapyrusService>(m_dispatcher);
set<DiscordService>(m_dispatcher);
set<ObjectService>(*this, m_dispatcher, m_transport);
set<CalendarService>(*this, m_dispatcher, m_transport);
set<QuestService>(*this, m_dispatcher, ctx<ImguiService>());
set<PartyService>(m_dispatcher, m_transport);
set<ActorValueService>(*this, m_dispatcher, m_transport);
set<InventoryService>(*this, m_dispatcher, m_transport);
set<MagicService>(*this, m_dispatcher, m_transport);
set<CommandService>(*this, m_transport, m_dispatcher);
ctx().emplace<ImguiService>();
ctx().emplace<DiscoveryService>(*this, m_dispatcher);
ctx().emplace<OverlayService>(*this, m_transport, m_dispatcher);
ctx().emplace<InputService>(ctx().at<OverlayService>());
ctx().emplace<CharacterService>(*this, m_dispatcher, m_transport);
ctx().emplace<DebugService>(m_dispatcher, *this, m_transport, ctx().at<ImguiService>());
ctx().emplace<ScriptService>(*this, m_dispatcher, ctx().at<ImguiService>(), m_transport);
ctx().emplace<PapyrusService>(m_dispatcher);
ctx().emplace<DiscordService>(m_dispatcher);
ctx().emplace<ObjectService>(*this, m_dispatcher, m_transport);
ctx().emplace<CalendarService>(*this, m_dispatcher, m_transport);
ctx().emplace<QuestService>(*this, m_dispatcher, ctx().at<ImguiService>());
ctx().emplace<PartyService>(m_dispatcher, m_transport);
ctx().emplace<ActorValueService>(*this, m_dispatcher, m_transport);
ctx().emplace<InventoryService>(*this, m_dispatcher, m_transport);
ctx().emplace<MagicService>(*this, m_dispatcher, m_transport);
ctx().emplace<CommandService>(*this, m_transport, m_dispatcher);
}

World::~World() = default;
Expand Down Expand Up @@ -88,13 +88,13 @@ uint64_t World::GetTick() const noexcept

void World::Create() noexcept
{
if(entt::service_locator<World>::empty())
if(entt::locator<World>::has_value())
{
entt::service_locator<World>::set(std::make_shared<World>());
entt::locator<World>::emplace();
}
}

World& World::Get() noexcept
{
return entt::service_locator<World>::ref();
return entt::locator<World>::value();
}
8 changes: 4 additions & 4 deletions Code/client/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ struct World : entt::registry
TransportService& GetTransport() noexcept;
ModSystem& GetModSystem() noexcept;

PartyService& GetPartyService() noexcept { return ctx<PartyService>(); }
const PartyService& GetPartyService() const noexcept { return ctx<const PartyService>(); }
OverlayService& GetOverlayService() noexcept { return ctx<OverlayService>(); }
const OverlayService& GetOverlayService() const noexcept { return ctx<const OverlayService>(); }
PartyService& GetPartyService() noexcept { return ctx().at<PartyService>(); }
const PartyService& GetPartyService() const noexcept { return ctx().at<const PartyService>(); }
OverlayService& GetOverlayService() noexcept { return ctx().at<OverlayService>(); }
const OverlayService& GetOverlayService() const noexcept { return ctx().at<const OverlayService>(); }

auto &GetDispatcher() noexcept
{
Expand Down
1 change: 1 addition & 0 deletions Code/encoding/Structs/GridCellCoords.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <TiltedCore/Buffer.hpp>
#include <limits>

using TiltedPhoques::Buffer;

Expand Down
2 changes: 1 addition & 1 deletion Code/immersive_launcher/TargetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <cstdint>
#include <limits>
#include <BranchInfo.h>
#include <BuildInfo.h>

#define CLIENT_DLL 0

Expand Down
1 change: 0 additions & 1 deletion Code/immersive_launcher/launcher.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "winres.h"
#include "BuildInfo.h"
#include "BranchInfo.h"

VS_VERSION_INFO VERSIONINFO
FILEFLAGSMASK 0x17L
Expand Down
2 changes: 1 addition & 1 deletion Code/server/Components/ModsComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <Components.h>
#include <es_loader/ESLoader.h>
#include <stdafx.h>


uint32_t ModsComponent::AddStandard(const String& acpFilename) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion Code/server/Game/Player.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdafx.h>


#include "Player.h"
#include <GameServer.h>
Expand Down
2 changes: 0 additions & 2 deletions Code/server/Game/PlayerManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <stdafx.h>

#include "PlayerManager.h"

PlayerManager::PlayerManager()
Expand Down
2 changes: 1 addition & 1 deletion Code/server/Game/PlayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PlayerManager
{
Iterator(TMap::iterator aItor) : m_itor(aItor){}
Iterator operator++() { m_itor++; return *this; }
bool operator!=(const Iterator& acRhs){ return m_itor != acRhs.m_itor; }
bool operator!=(const Iterator& acRhs) const { return m_itor != acRhs.m_itor; }
const Player* operator*() const { return m_itor->second.get(); }
Player* operator*() { return m_itor.value().get(); }

Expand Down
21 changes: 9 additions & 12 deletions Code/server/GameServer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

#include <Components.h>
#include <GameServer.h>
#include <Packet.hpp>
#include <stdafx.h>


#include <Events/AdminPacketEvent.h>
#include <Events/CharacterRemoveEvent.h>
Expand Down Expand Up @@ -37,7 +36,7 @@ Console::StringSetting sServerIconURL{"GameServer:sIconUrl", "URL to the image t
Console::StringSetting sTagList{"GameServer:sTagList", "List of tags, separated by a comma (,)", ""};
Console::StringSetting sAdminPassword{"GameServer:sAdminPassword", "Admin authentication password", ""};
Console::StringSetting sToken{"GameServer:sToken", "Admin token", ""};
Console::Setting bBypassMoPo{"ModPolicy:bBypass", "Bypass the mod policy restrictions.", false,
Console::Setting bEnableMoPo{"ModPolicy:bEnabled", "Bypass the mod policy restrictions.", true,
Console::SettingsFlags::kHidden | Console::SettingsFlags::kLocked};
// -- Commands --
Console::Command<bool> TogglePremium("TogglePremium", "Toggle the premium mode",
Expand All @@ -47,13 +46,13 @@ Console::Command<> ShowVersion("version", "Show the version the server was compi
[](Console::ArgStack&) { spdlog::get("ConOut")->info("Server " BUILD_COMMIT); });
Console::Command<> CrashServer("crash", "Crashes the server, don't use!", [](Console::ArgStack&) { int* i = 0; *i = 42; });
Console::Command<> ShowMoPoStatus("isMoPoActive", "Shows if the ModPolicy is active", [](Console::ArgStack&) {
spdlog::get("ConOut")->info("ModPolicy status: {}", bBypassMoPo ? "not active" : "active");
spdlog::get("ConOut")->info("ModPolicy status: {}", bEnableMoPo ? "active" : "not active");
});

// -- Constants --
constexpr char kBypassMoPoWarning[]{
"ModPolicy is disabled. This can lead to desync and other oddities. Make sure you know what you are doing. No "
"support will be provided while this bypass is in place"};
"ModPolicy is disabled. This can lead to desync and other oddities. Make sure you know what you are doing. We "
"may not be able to assist you if ModPolicy is disabled."};

constexpr char kMopoRecordsMissing[]{
"Failed to start: ModPolicy is enabled, but no mods are installed. Players wont be able "
Expand All @@ -68,11 +67,9 @@ static uint16_t GetUserTickRate()

static bool IsMoPoActive()
{
return !bBypassMoPo;
return bEnableMoPo;
}

GameServer* GameServer::s_pInstance = nullptr;

GameServer::GameServer(Console::ConsoleRegistry& aConsole) noexcept
: m_lastFrameTime(std::chrono::high_resolution_clock::now()), m_commands(aConsole), m_requestStop(false)
{
Expand Down Expand Up @@ -122,7 +119,7 @@ void GameServer::Kill()

bool GameServer::CheckMoPo()
{
if (bBypassMoPo)
if (!bEnableMoPo)
spdlog::warn(kBypassMoPoWarning);
// Server is not aware of any installed mods.
else if (!m_pWorld->GetRecordCollection())
Expand Down Expand Up @@ -203,7 +200,7 @@ void GameServer::BindServerCommands()

m_commands.RegisterCommand<>("mods", "List all installed mods on this server", [&](Console::ArgStack&) {
auto out = spdlog::get("ConOut");
auto& mods = m_pWorld->ctx<ModsComponent>().GetServerMods();
auto& mods = m_pWorld->ctx().at<ModsComponent>().GetServerMods();
if (mods.size() == 0)
{
out->warn("No mods installed");
Expand Down Expand Up @@ -472,7 +469,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId,
if (acRequest->Token == sToken.value())
{
Mods& responseList = serverResponse.UserMods;
auto& modsComponent = m_pWorld->ctx<ModsComponent>();
auto& modsComponent = m_pWorld->ctx().at<ModsComponent>();

if (IsMoPoActive())
{
Expand Down
9 changes: 4 additions & 5 deletions Code/server/GameServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ConsoleRegistry;

struct GameServer final : Server
{
public:
// TODO: eventually refactor this.
struct Info
{
Expand Down Expand Up @@ -71,7 +70,7 @@ struct GameServer final : Server
aFunctor(id);
}

protected:
protected:
void HandleAuthenticationRequest(ConnectionId_t aConnectionId, const UniquePtr<AuthenticationRequest>& acRequest);

// Implement TiltedPhoques::Server
Expand All @@ -80,10 +79,10 @@ struct GameServer final : Server
void OnConnection(ConnectionId_t aHandle) override;
void OnDisconnection(ConnectionId_t aConnectionId, EDisconnectReason aReason) override;

private:
private:
void UpdateTitle() const;

private:
private:
std::chrono::high_resolution_clock::time_point m_lastFrameTime;
std::function<void(UniquePtr<ClientMessage>&, ConnectionId_t)> m_messageHandlers[kClientOpcodeMax];
std::function<void(UniquePtr<ClientAdminMessage>&, ConnectionId_t)> m_adminMessageHandlers[kClientAdminOpcodeMax];
Expand All @@ -97,5 +96,5 @@ struct GameServer final : Server

bool m_requestStop;

static GameServer* s_pInstance;
static inline GameServer* s_pInstance = nullptr;
};
2 changes: 1 addition & 1 deletion Code/server/Pch.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#include <stdafx.h>

2 changes: 1 addition & 1 deletion Code/server/Scripts/Base.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdafx.h>


#include <Scripts/Base.h>

Expand Down
2 changes: 1 addition & 1 deletion Code/server/Scripts/EntityHandle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdafx.h>


#include <Scripts/EntityHandle.h>
#include <World.h>
Expand Down
2 changes: 1 addition & 1 deletion Code/server/Scripts/Npc.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdafx.h>


#include <Scripts/Npc.h>

Expand Down
4 changes: 2 additions & 2 deletions Code/server/Scripts/Party.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdafx.h>



#include <World.h>
Expand All @@ -19,7 +19,7 @@ namespace Script
{
Vector<Player> players;

auto& partyService = m_pWorld->ctx<PartyService>();
auto& partyService = m_pWorld->ctx().at<PartyService>();

auto* pParty = partyService.GetById(m_partyId);
if (pParty)
Expand Down
Loading