Skip to content

Commit 4635ef2

Browse files
Merge pull request #678 from tiltedphoques/dev
V1.6.6
2 parents 81b63d1 + 4670a30 commit 4635ef2

28 files changed

+462
-301
lines changed

Code/client/Games/Fallout4/Actor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct Actor : TESObjectREFR
2525

2626
static GamePtr<Actor> New() noexcept;
2727
static GamePtr<Actor> Create(TESNPC* apNpc) noexcept;
28+
static GamePtr<Actor> Spawn(uint32_t aBaseFormId) noexcept;
2829

2930
virtual void sub_C4();
3031
virtual void sub_C5();

Code/client/Games/References.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ GamePtr<Actor> Actor::Create(TESNPC* apBaseForm) noexcept
591591
return pActor;
592592
}
593593

594+
GamePtr<Actor> Actor::Spawn(uint32_t aBaseFormId) noexcept
595+
{
596+
TESNPC* pNpc = Cast<TESNPC>(TESForm::GetById(aBaseFormId));
597+
return Actor::Create(pNpc);
598+
}
599+
594600
void Actor::SetLevelMod(uint32_t aLevel) noexcept
595601
{
596602
TP_THIS_FUNCTION(TActorSetLevelMod, void, ExtraDataList, uint32_t);

Code/client/Games/Skyrim/Actor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct Actor : TESObjectREFR
3030
static GamePtr<Actor> New() noexcept;
3131
// Places a brand new actor in the world
3232
static GamePtr<Actor> Create(TESNPC* apBaseForm) noexcept;
33+
static GamePtr<Actor> Spawn(uint32_t aBaseFormId) noexcept;
3334

3435
virtual void sub_9C();
3536
virtual void sub_9D();

Code/client/Services/CalendarService.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <DateTime.h>
3+
#include <Structs/TimeModel.h>
44
#include <Events/EventDispatcher.h>
55
#include <Games/Events.h>
66

@@ -32,13 +32,13 @@ class CalendarService final : public BSTEventSink<TESActivateEvent>
3232
entt::scoped_connection m_updateConnection;
3333
entt::scoped_connection m_disconnectedConnection;
3434

35-
DateTime m_onlineTime;
36-
DateTime m_offlineTime;
35+
TimeModel m_onlineTime;
36+
TimeModel m_offlineTime;
3737
float m_fadeTimer = 0.f;
38+
bool m_switchToOffline = false;
3839
static bool s_gameClockLocked;
3940

4041
uint64_t m_lastTick = 0;
41-
uint64_t m_lastLogTick = 0;
4242
World& m_world;
4343
TransportService& m_transport;
4444
};

Code/client/Services/Debug/DebugService.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ static bool g_enableCellWindow{false};
236236
static bool g_enableProcessesWindow{false};
237237
static bool g_enableWeatherWindow{false};
238238
static bool g_enableCombatWindow{false};
239+
static bool g_enableDragonSpawnerWindow{false};
239240

240241
void DebugService::DrawServerView() noexcept
241242
{
@@ -335,6 +336,7 @@ void DebugService::OnDraw() noexcept
335336
ImGui::MenuItem("Entities", nullptr, &g_enableEntitiesWindow);
336337
ImGui::MenuItem("Server", nullptr, &g_enableServerWindow);
337338
ImGui::MenuItem("Party", nullptr, &g_enablePartyWindow);
339+
ImGui::MenuItem("Dragon spawner", nullptr, &g_enableDragonSpawnerWindow);
338340

339341
#if (!IS_MASTER)
340342
ImGui::MenuItem("Network", nullptr, &g_enableNetworkWindow);
@@ -378,6 +380,8 @@ void DebugService::OnDraw() noexcept
378380
DrawServerView();
379381
if (g_enablePartyWindow)
380382
DrawPartyView();
383+
if (g_enableDragonSpawnerWindow)
384+
DrawDragonSpawnerView();
381385

382386
#if (!IS_MASTER)
383387
if (g_enableNetworkWindow)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <imgui.h>
2+
#include <inttypes.h>
3+
4+
void DebugService::DrawDragonSpawnerView()
5+
{
6+
#if TP_SKYRIM64
7+
ImGui::Begin("Dragon spawner");
8+
9+
if (ImGui::CollapsingHeader("Dragons (level 10)"))
10+
{
11+
if (ImGui::Button("Brown (fire)"))
12+
{
13+
Actor::Spawn(0x1CA03);
14+
}
15+
if (ImGui::Button("Brown (frost)"))
16+
{
17+
Actor::Spawn(0xF80FA);
18+
}
19+
if (ImGui::Button("White (frost)"))
20+
{
21+
Actor::Spawn(0x8BC7F);
22+
}
23+
if (ImGui::Button("Bronze (frost)"))
24+
{
25+
Actor::Spawn(0x8BC7E);
26+
}
27+
}
28+
29+
if (ImGui::CollapsingHeader("Blood dragons (level 20)"))
30+
{
31+
if (ImGui::Button("Blood (fire)"))
32+
{
33+
Actor::Spawn(0xF80FD);
34+
}
35+
if (ImGui::Button("Blood (frost)"))
36+
{
37+
Actor::Spawn(0xF77F8);
38+
}
39+
}
40+
41+
if (ImGui::CollapsingHeader("Frost dragons (level 27-35)"))
42+
{
43+
if (ImGui::Button("Frost"))
44+
{
45+
Actor::Spawn(0x351C3);
46+
}
47+
}
48+
49+
if (ImGui::CollapsingHeader("Elder dragons (level 36-44)"))
50+
{
51+
if (ImGui::Button("Elder (fire)"))
52+
{
53+
Actor::Spawn(0xF811B);
54+
}
55+
if (ImGui::Button("Elder (frost)"))
56+
{
57+
Actor::Spawn(0xF811A);
58+
}
59+
}
60+
61+
if (ImGui::CollapsingHeader("Ancient dragons (level 45-54)"))
62+
{
63+
if (ImGui::Button("Ancient (fire)"))
64+
{
65+
Actor::Spawn(0xF811C);
66+
}
67+
if (ImGui::Button("Ancient (frost)"))
68+
{
69+
Actor::Spawn(0xF811E);
70+
}
71+
}
72+
73+
if (ImGui::CollapsingHeader("Serpentine dragons (level 55-58)"))
74+
{
75+
if (ImGui::Button("Serpentine (fire)"))
76+
{
77+
Actor::Spawn(0x04036134);
78+
}
79+
if (ImGui::Button("Serpentine (frost)"))
80+
{
81+
Actor::Spawn(0x04036133);
82+
}
83+
}
84+
85+
if (ImGui::CollapsingHeader("Revered dragons (level 62)"))
86+
{
87+
if (ImGui::Button("Revered (fire)"))
88+
{
89+
Actor::Spawn(0x02008431);
90+
}
91+
}
92+
93+
if (ImGui::CollapsingHeader("Legendary dragons (level 75)"))
94+
{
95+
if (ImGui::Button("Legendary (fire)"))
96+
{
97+
Actor::Spawn(0x0200C5F5);
98+
}
99+
if (ImGui::Button("Legendary (frost)"))
100+
{
101+
Actor::Spawn(0x0200C5FD);
102+
}
103+
}
104+
105+
if (ImGui::CollapsingHeader("Skeletal dragons (warning: very scary)"))
106+
{
107+
if (ImGui::Button("Skeletal (frost)"))
108+
{
109+
Actor::Spawn(0x9192C);
110+
}
111+
}
112+
113+
ImGui::End();
114+
#endif
115+
}

Code/client/Services/DebugService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct DebugService
5858
void DrawProcessView();
5959
void DrawWeatherView();
6060
void DrawCombatView();
61+
void DrawDragonSpawnerView();
6162

6263
public:
6364
bool m_showDebugStuff = false;
Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <Services/CalendarService.h>
22

3-
#include <Events/DisconnectedEvent.h>
3+
#include <World.h>
44
#include <Events/UpdateEvent.h>
5+
#include <Events/DisconnectedEvent.h>
56
#include <Messages/ServerTimeSettings.h>
6-
#include <World.h>
77

8-
#include <Forms/TESObjectCELL.h>
9-
#include <PlayerCharacter.h>
108
#include <TimeManager.h>
9+
#include <PlayerCharacter.h>
10+
#include <Forms/TESObjectCELL.h>
1111

1212
constexpr float kTransitionSpeed = 5.f;
1313

@@ -19,7 +19,8 @@ bool CalendarService::AllowGameTick() noexcept
1919
}
2020

2121
CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, TransportService& aTransport)
22-
: m_world(aWorld), m_transport(aTransport)
22+
: m_world(aWorld)
23+
, m_transport(aTransport)
2324
{
2425
m_timeUpdateConnection = aDispatcher.sink<ServerTimeSettings>().connect<&CalendarService::OnTimeUpdate>(this);
2526
m_updateConnection = aDispatcher.sink<UpdateEvent>().connect<&CalendarService::HandleUpdate>(this);
@@ -29,29 +30,16 @@ CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, T
2930
void CalendarService::OnTimeUpdate(const ServerTimeSettings& acMessage) noexcept
3031
{
3132
// disable the game clock
33+
m_onlineTime.TimeScale = acMessage.TimeScale;
34+
m_onlineTime.Time = acMessage.Time;
3235
ToggleGameClock(false);
33-
m_onlineTime.m_timeModel.TimeScale = acMessage.timeModel.TimeScale;
34-
m_onlineTime.m_timeModel.Time = acMessage.timeModel.Time;
35-
36-
if (m_world.GetServerSettings().SyncPlayerCalendar)
37-
{
38-
m_onlineTime.m_timeModel.Day = acMessage.timeModel.Day;
39-
m_onlineTime.m_timeModel.Month = acMessage.timeModel.Month;
40-
m_onlineTime.m_timeModel.Year = acMessage.timeModel.Year;
41-
}
42-
else
43-
{
44-
m_onlineTime.m_timeModel.Day = m_offlineTime.m_timeModel.Day;
45-
m_onlineTime.m_timeModel.Month = m_offlineTime.m_timeModel.Month;
46-
m_onlineTime.m_timeModel.Year = m_offlineTime.m_timeModel.Year;
47-
}
4836
}
4937

5038
void CalendarService::OnDisconnected(const DisconnectedEvent&) noexcept
5139
{
5240
// signal a time transition
5341
m_fadeTimer = 0.f;
54-
ToggleGameClock(true);
42+
m_switchToOffline = true;
5543
}
5644

5745
float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) const
@@ -72,11 +60,24 @@ float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) c
7260
void CalendarService::ToggleGameClock(bool aEnable)
7361
{
7462
auto* pGameTime = TimeData::Get();
75-
m_offlineTime.m_timeModel.Day = pGameTime->GameDay->f;
76-
m_offlineTime.m_timeModel.Month = pGameTime->GameMonth->f;
77-
m_offlineTime.m_timeModel.Year = pGameTime->GameYear->f;
78-
m_offlineTime.m_timeModel.Time = pGameTime->GameHour->f;
79-
m_offlineTime.m_timeModel.TimeScale = pGameTime->TimeScale->f;
63+
if (aEnable)
64+
{
65+
pGameTime->GameDay->i = m_offlineTime.Day;
66+
pGameTime->GameMonth->i = m_offlineTime.Month;
67+
pGameTime->GameYear->i = m_offlineTime.Year;
68+
pGameTime->TimeScale->f = m_offlineTime.TimeScale;
69+
pGameTime->GameDaysPassed->f = (m_offlineTime.Time * (1.f / 24.f)) + m_offlineTime.Day;
70+
pGameTime->GameHour->f = m_offlineTime.Time;
71+
m_switchToOffline = false;
72+
}
73+
else
74+
{
75+
m_offlineTime.Day = pGameTime->GameDay->i;
76+
m_offlineTime.Month = pGameTime->GameMonth->i;
77+
m_offlineTime.Year = pGameTime->GameYear->i;
78+
m_offlineTime.Time = pGameTime->GameHour->f;
79+
m_offlineTime.TimeScale = pGameTime->TimeScale->f;
80+
}
8081

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

9495
const auto now = m_world.GetTick();
9596

97+
if (m_switchToOffline)
98+
{
99+
// time transition out
100+
if (m_fadeTimer < kTransitionSpeed)
101+
{
102+
pGameTime->GameHour->f = TimeInterpolate(m_onlineTime, m_offlineTime);
103+
// before we quit here we fire this event
104+
if ((m_fadeTimer + updateDelta) > kTransitionSpeed)
105+
{
106+
m_fadeTimer += updateDelta;
107+
ToggleGameClock(true);
108+
}
109+
else
110+
m_fadeTimer += updateDelta;
111+
}
112+
}
113+
96114
// we got disconnected or the client got ahead of us
97115
if (now < m_lastTick)
98116
return;
@@ -101,19 +119,19 @@ void CalendarService::HandleUpdate(const UpdateEvent& aEvent) noexcept
101119
m_lastTick = now;
102120

103121
m_onlineTime.Update(delta);
104-
pGameTime->TimeScale->f = m_onlineTime.m_timeModel.TimeScale;
105-
pGameTime->GameDay->f = m_onlineTime.m_timeModel.Day;
106-
pGameTime->GameMonth->f = m_onlineTime.m_timeModel.Month;
107-
pGameTime->GameYear->f = m_onlineTime.m_timeModel.Year;
108-
pGameTime->GameDaysPassed->f += m_onlineTime.GetDeltaTime(delta);
122+
pGameTime->GameDay->i = m_onlineTime.Day;
123+
pGameTime->GameMonth->i = m_onlineTime.Month;
124+
pGameTime->GameYear->i = m_onlineTime.Year;
125+
pGameTime->TimeScale->f = m_onlineTime.TimeScale;
126+
pGameTime->GameDaysPassed->f = (m_onlineTime.Time * (1.f / 24.f)) + m_onlineTime.Day;
109127

110128
// time transition in
111129
if (m_fadeTimer < kTransitionSpeed)
112130
{
113-
pGameTime->GameHour->f = TimeInterpolate(m_offlineTime.m_timeModel, m_onlineTime.m_timeModel);
131+
pGameTime->GameHour->f = TimeInterpolate(m_offlineTime, m_onlineTime);
114132
m_fadeTimer += updateDelta;
115133
}
116134
else
117-
pGameTime->GameHour->f = m_onlineTime.m_timeModel.Time;
135+
pGameTime->GameHour->f = m_onlineTime.Time;
118136
}
119137
}

Code/client/Services/Generic/TransportService.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <Forms/TESWorldSpace.h>
1212
#include <Forms/TESObjectCELL.h>
1313

14-
#include <TimeManager.h>
15-
1614
#include <Forms/TESNPC.h>
1715
#include <TiltedOnlinePCH.h>
1816
#include <World.h>
@@ -153,13 +151,6 @@ void TransportService::OnConnected()
153151

154152
request.Level = pPlayer->GetLevel();
155153

156-
auto* pGameTime = TimeData::Get();
157-
request.PlayerTime.TimeScale = pGameTime->TimeScale->f;
158-
request.PlayerTime.Time = pGameTime->GameHour->f;
159-
request.PlayerTime.Year = pGameTime->GameYear->f;
160-
request.PlayerTime.Month = pGameTime->GameMonth->f;
161-
request.PlayerTime.Day = pGameTime->GameDay->f;
162-
163154
Send(request);
164155
}
165156

0 commit comments

Comments
 (0)