Skip to content

Commit

Permalink
Merge pull request #678 from tiltedphoques/dev
Browse files Browse the repository at this point in the history
V1.6.6
  • Loading branch information
RobbeBryssinck authored May 23, 2024
2 parents 81b63d1 + 4670a30 commit 4635ef2
Show file tree
Hide file tree
Showing 28 changed files with 462 additions and 301 deletions.
1 change: 1 addition & 0 deletions Code/client/Games/Fallout4/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Actor : TESObjectREFR

static GamePtr<Actor> New() noexcept;
static GamePtr<Actor> Create(TESNPC* apNpc) noexcept;
static GamePtr<Actor> Spawn(uint32_t aBaseFormId) noexcept;

virtual void sub_C4();
virtual void sub_C5();
Expand Down
6 changes: 6 additions & 0 deletions Code/client/Games/References.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ GamePtr<Actor> Actor::Create(TESNPC* apBaseForm) noexcept
return pActor;
}

GamePtr<Actor> Actor::Spawn(uint32_t aBaseFormId) noexcept
{
TESNPC* pNpc = Cast<TESNPC>(TESForm::GetById(aBaseFormId));
return Actor::Create(pNpc);
}

void Actor::SetLevelMod(uint32_t aLevel) noexcept
{
TP_THIS_FUNCTION(TActorSetLevelMod, void, ExtraDataList, uint32_t);
Expand Down
1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct Actor : TESObjectREFR
static GamePtr<Actor> New() noexcept;
// Places a brand new actor in the world
static GamePtr<Actor> Create(TESNPC* apBaseForm) noexcept;
static GamePtr<Actor> Spawn(uint32_t aBaseFormId) noexcept;

virtual void sub_9C();
virtual void sub_9D();
Expand Down
8 changes: 4 additions & 4 deletions Code/client/Services/CalendarService.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <DateTime.h>
#include <Structs/TimeModel.h>
#include <Events/EventDispatcher.h>
#include <Games/Events.h>

Expand Down Expand Up @@ -32,13 +32,13 @@ class CalendarService final : public BSTEventSink<TESActivateEvent>
entt::scoped_connection m_updateConnection;
entt::scoped_connection m_disconnectedConnection;

DateTime m_onlineTime;
DateTime m_offlineTime;
TimeModel m_onlineTime;
TimeModel m_offlineTime;
float m_fadeTimer = 0.f;
bool m_switchToOffline = false;
static bool s_gameClockLocked;

uint64_t m_lastTick = 0;
uint64_t m_lastLogTick = 0;
World& m_world;
TransportService& m_transport;
};
4 changes: 4 additions & 0 deletions Code/client/Services/Debug/DebugService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static bool g_enableCellWindow{false};
static bool g_enableProcessesWindow{false};
static bool g_enableWeatherWindow{false};
static bool g_enableCombatWindow{false};
static bool g_enableDragonSpawnerWindow{false};

void DebugService::DrawServerView() noexcept
{
Expand Down Expand Up @@ -335,6 +336,7 @@ void DebugService::OnDraw() noexcept
ImGui::MenuItem("Entities", nullptr, &g_enableEntitiesWindow);
ImGui::MenuItem("Server", nullptr, &g_enableServerWindow);
ImGui::MenuItem("Party", nullptr, &g_enablePartyWindow);
ImGui::MenuItem("Dragon spawner", nullptr, &g_enableDragonSpawnerWindow);

#if (!IS_MASTER)
ImGui::MenuItem("Network", nullptr, &g_enableNetworkWindow);
Expand Down Expand Up @@ -378,6 +380,8 @@ void DebugService::OnDraw() noexcept
DrawServerView();
if (g_enablePartyWindow)
DrawPartyView();
if (g_enableDragonSpawnerWindow)
DrawDragonSpawnerView();

#if (!IS_MASTER)
if (g_enableNetworkWindow)
Expand Down
115 changes: 115 additions & 0 deletions Code/client/Services/Debug/Views/DragonSpawnerView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include <imgui.h>
#include <inttypes.h>

void DebugService::DrawDragonSpawnerView()
{
#if TP_SKYRIM64
ImGui::Begin("Dragon spawner");

if (ImGui::CollapsingHeader("Dragons (level 10)"))
{
if (ImGui::Button("Brown (fire)"))
{
Actor::Spawn(0x1CA03);
}
if (ImGui::Button("Brown (frost)"))
{
Actor::Spawn(0xF80FA);
}
if (ImGui::Button("White (frost)"))
{
Actor::Spawn(0x8BC7F);
}
if (ImGui::Button("Bronze (frost)"))
{
Actor::Spawn(0x8BC7E);
}
}

if (ImGui::CollapsingHeader("Blood dragons (level 20)"))
{
if (ImGui::Button("Blood (fire)"))
{
Actor::Spawn(0xF80FD);
}
if (ImGui::Button("Blood (frost)"))
{
Actor::Spawn(0xF77F8);
}
}

if (ImGui::CollapsingHeader("Frost dragons (level 27-35)"))
{
if (ImGui::Button("Frost"))
{
Actor::Spawn(0x351C3);
}
}

if (ImGui::CollapsingHeader("Elder dragons (level 36-44)"))
{
if (ImGui::Button("Elder (fire)"))
{
Actor::Spawn(0xF811B);
}
if (ImGui::Button("Elder (frost)"))
{
Actor::Spawn(0xF811A);
}
}

if (ImGui::CollapsingHeader("Ancient dragons (level 45-54)"))
{
if (ImGui::Button("Ancient (fire)"))
{
Actor::Spawn(0xF811C);
}
if (ImGui::Button("Ancient (frost)"))
{
Actor::Spawn(0xF811E);
}
}

if (ImGui::CollapsingHeader("Serpentine dragons (level 55-58)"))
{
if (ImGui::Button("Serpentine (fire)"))
{
Actor::Spawn(0x04036134);
}
if (ImGui::Button("Serpentine (frost)"))
{
Actor::Spawn(0x04036133);
}
}

if (ImGui::CollapsingHeader("Revered dragons (level 62)"))
{
if (ImGui::Button("Revered (fire)"))
{
Actor::Spawn(0x02008431);
}
}

if (ImGui::CollapsingHeader("Legendary dragons (level 75)"))
{
if (ImGui::Button("Legendary (fire)"))
{
Actor::Spawn(0x0200C5F5);
}
if (ImGui::Button("Legendary (frost)"))
{
Actor::Spawn(0x0200C5FD);
}
}

if (ImGui::CollapsingHeader("Skeletal dragons (warning: very scary)"))
{
if (ImGui::Button("Skeletal (frost)"))
{
Actor::Spawn(0x9192C);
}
}

ImGui::End();
#endif
}
1 change: 1 addition & 0 deletions Code/client/Services/DebugService.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct DebugService
void DrawProcessView();
void DrawWeatherView();
void DrawCombatView();
void DrawDragonSpawnerView();

public:
bool m_showDebugStuff = false;
Expand Down
84 changes: 51 additions & 33 deletions Code/client/Services/Generic/CalendarService.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <Services/CalendarService.h>

#include <Events/DisconnectedEvent.h>
#include <World.h>
#include <Events/UpdateEvent.h>
#include <Events/DisconnectedEvent.h>
#include <Messages/ServerTimeSettings.h>
#include <World.h>

#include <Forms/TESObjectCELL.h>
#include <PlayerCharacter.h>
#include <TimeManager.h>
#include <PlayerCharacter.h>
#include <Forms/TESObjectCELL.h>

constexpr float kTransitionSpeed = 5.f;

Expand All @@ -19,7 +19,8 @@ bool CalendarService::AllowGameTick() noexcept
}

CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, TransportService& aTransport)
: m_world(aWorld), m_transport(aTransport)
: m_world(aWorld)
, m_transport(aTransport)
{
m_timeUpdateConnection = aDispatcher.sink<ServerTimeSettings>().connect<&CalendarService::OnTimeUpdate>(this);
m_updateConnection = aDispatcher.sink<UpdateEvent>().connect<&CalendarService::HandleUpdate>(this);
Expand All @@ -29,29 +30,16 @@ CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, T
void CalendarService::OnTimeUpdate(const ServerTimeSettings& acMessage) noexcept
{
// disable the game clock
m_onlineTime.TimeScale = acMessage.TimeScale;
m_onlineTime.Time = acMessage.Time;
ToggleGameClock(false);
m_onlineTime.m_timeModel.TimeScale = acMessage.timeModel.TimeScale;
m_onlineTime.m_timeModel.Time = acMessage.timeModel.Time;

if (m_world.GetServerSettings().SyncPlayerCalendar)
{
m_onlineTime.m_timeModel.Day = acMessage.timeModel.Day;
m_onlineTime.m_timeModel.Month = acMessage.timeModel.Month;
m_onlineTime.m_timeModel.Year = acMessage.timeModel.Year;
}
else
{
m_onlineTime.m_timeModel.Day = m_offlineTime.m_timeModel.Day;
m_onlineTime.m_timeModel.Month = m_offlineTime.m_timeModel.Month;
m_onlineTime.m_timeModel.Year = m_offlineTime.m_timeModel.Year;
}
}

void CalendarService::OnDisconnected(const DisconnectedEvent&) noexcept
{
// signal a time transition
m_fadeTimer = 0.f;
ToggleGameClock(true);
m_switchToOffline = true;
}

float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) const
Expand All @@ -72,11 +60,24 @@ float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) c
void CalendarService::ToggleGameClock(bool aEnable)
{
auto* pGameTime = TimeData::Get();
m_offlineTime.m_timeModel.Day = pGameTime->GameDay->f;
m_offlineTime.m_timeModel.Month = pGameTime->GameMonth->f;
m_offlineTime.m_timeModel.Year = pGameTime->GameYear->f;
m_offlineTime.m_timeModel.Time = pGameTime->GameHour->f;
m_offlineTime.m_timeModel.TimeScale = pGameTime->TimeScale->f;
if (aEnable)
{
pGameTime->GameDay->i = m_offlineTime.Day;
pGameTime->GameMonth->i = m_offlineTime.Month;
pGameTime->GameYear->i = m_offlineTime.Year;
pGameTime->TimeScale->f = m_offlineTime.TimeScale;
pGameTime->GameDaysPassed->f = (m_offlineTime.Time * (1.f / 24.f)) + m_offlineTime.Day;
pGameTime->GameHour->f = m_offlineTime.Time;
m_switchToOffline = false;
}
else
{
m_offlineTime.Day = pGameTime->GameDay->i;
m_offlineTime.Month = pGameTime->GameMonth->i;
m_offlineTime.Year = pGameTime->GameYear->i;
m_offlineTime.Time = pGameTime->GameHour->f;
m_offlineTime.TimeScale = pGameTime->TimeScale->f;
}

s_gameClockLocked = !aEnable;
}
Expand All @@ -93,6 +94,23 @@ void CalendarService::HandleUpdate(const UpdateEvent& aEvent) noexcept

const auto now = m_world.GetTick();

if (m_switchToOffline)
{
// time transition out
if (m_fadeTimer < kTransitionSpeed)
{
pGameTime->GameHour->f = TimeInterpolate(m_onlineTime, m_offlineTime);
// before we quit here we fire this event
if ((m_fadeTimer + updateDelta) > kTransitionSpeed)
{
m_fadeTimer += updateDelta;
ToggleGameClock(true);
}
else
m_fadeTimer += updateDelta;
}
}

// we got disconnected or the client got ahead of us
if (now < m_lastTick)
return;
Expand All @@ -101,19 +119,19 @@ void CalendarService::HandleUpdate(const UpdateEvent& aEvent) noexcept
m_lastTick = now;

m_onlineTime.Update(delta);
pGameTime->TimeScale->f = m_onlineTime.m_timeModel.TimeScale;
pGameTime->GameDay->f = m_onlineTime.m_timeModel.Day;
pGameTime->GameMonth->f = m_onlineTime.m_timeModel.Month;
pGameTime->GameYear->f = m_onlineTime.m_timeModel.Year;
pGameTime->GameDaysPassed->f += m_onlineTime.GetDeltaTime(delta);
pGameTime->GameDay->i = m_onlineTime.Day;
pGameTime->GameMonth->i = m_onlineTime.Month;
pGameTime->GameYear->i = m_onlineTime.Year;
pGameTime->TimeScale->f = m_onlineTime.TimeScale;
pGameTime->GameDaysPassed->f = (m_onlineTime.Time * (1.f / 24.f)) + m_onlineTime.Day;

// time transition in
if (m_fadeTimer < kTransitionSpeed)
{
pGameTime->GameHour->f = TimeInterpolate(m_offlineTime.m_timeModel, m_onlineTime.m_timeModel);
pGameTime->GameHour->f = TimeInterpolate(m_offlineTime, m_onlineTime);
m_fadeTimer += updateDelta;
}
else
pGameTime->GameHour->f = m_onlineTime.m_timeModel.Time;
pGameTime->GameHour->f = m_onlineTime.Time;
}
}
9 changes: 0 additions & 9 deletions Code/client/Services/Generic/TransportService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <Forms/TESWorldSpace.h>
#include <Forms/TESObjectCELL.h>

#include <TimeManager.h>

#include <Forms/TESNPC.h>
#include <TiltedOnlinePCH.h>
#include <World.h>
Expand Down Expand Up @@ -153,13 +151,6 @@ void TransportService::OnConnected()

request.Level = pPlayer->GetLevel();

auto* pGameTime = TimeData::Get();
request.PlayerTime.TimeScale = pGameTime->TimeScale->f;
request.PlayerTime.Time = pGameTime->GameHour->f;
request.PlayerTime.Year = pGameTime->GameYear->f;
request.PlayerTime.Month = pGameTime->GameMonth->f;
request.PlayerTime.Day = pGameTime->GameDay->f;

Send(request);
}

Expand Down
Loading

0 comments on commit 4635ef2

Please sign in to comment.