Skip to content

Commit 7a84f07

Browse files
committed
Functional update
1 parent a03fc68 commit 7a84f07

13 files changed

Lines changed: 1196 additions & 50 deletions

File tree

Causality-0.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,22 @@
7474
<Compile Include="Core\InteractFrame.cs" />
7575
<Compile Include="Core\DamageData.cs" />
7676
<Compile Include="Core\LifecycleEvent.cs" />
77+
<Compile Include="Core\WorldData.cs" />
7778
<Compile Include="Core\DummyInputWrapper.cs" />
7879
<Compile Include="Core\DummyMotorWrapper.cs" />
7980
<Compile Include="Core\Timeline.cs" />
8081
<Compile Include="Core\Serializer.cs" />
8182
<Compile Include="Event\PlayerEvent\Verified.cs" />
8283
<Compile Include="Event\PlayerEvent\Shooting.cs" />
8384
<Compile Include="Event\PlayerEvent\Reloading.cs" />
85+
<Compile Include="Event\PlayerEvent\Lockers.cs" />
8486
<Compile Include="Event\PlayerEvent\Using.cs" />
8587
<Compile Include="Event\PlayerEvent\VoiceChat.cs" />
8688
<Compile Include="Event\PlayerEvent\Throwing.cs" />
8789
<Compile Include="Event\PlayerEvent\Interacting.cs" />
8890
<Compile Include="Event\PlayerEvent\Lifecycle.cs" />
8991
<Compile Include="Event\ServerEvent\MapGenerating.cs" />
92+
<Compile Include="Event\ServerEvent\Pickups.cs" />
9093
<Compile Include="Command\RemoteAdmin\Causality.cs" />
9194
<Compile Include="Properties\AssemblyInfo.cs" />
9295
</ItemGroup>

Causality0.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public sealed class Causality0 : Plugin
1212

1313
public MapGenerating ServerEvent { get; } = new();
1414

15+
public Pickups PickupEvent { get; } = new();
16+
1517
public Verified VerifiedEvent { get; } = new();
1618

1719
public Shooting ShootingEvent { get; } = new();
@@ -26,6 +28,8 @@ public sealed class Causality0 : Plugin
2628

2729
public Interacting InteractingEvent { get; } = new();
2830

31+
public Lockers LockersEvent { get; } = new();
32+
2933
public Lifecycle LifecycleEvent { get; } = new();
3034

3135
public override string Name { get; } = "Causality-0";
@@ -42,26 +46,30 @@ public override void Enable()
4246
{
4347
Instance = this;
4448
ServerEvent.Enable();
49+
PickupEvent.Enable();
4550
VerifiedEvent.Enable();
4651
ShootingEvent.Enable();
4752
ReloadingEvent.Enable();
4853
UsingEvent.Enable();
4954
VoiceChatEvent.Enable();
5055
ThrowingEvent.Enable();
5156
InteractingEvent.Enable();
57+
LockersEvent.Enable();
5258
LifecycleEvent.Enable();
5359
}
5460

5561
public override void Disable()
5662
{
5763
LifecycleEvent.Disable();
64+
LockersEvent.Disable();
5865
InteractingEvent.Disable();
5966
ThrowingEvent.Disable();
6067
VoiceChatEvent.Disable();
6168
UsingEvent.Disable();
6269
ReloadingEvent.Disable();
6370
ShootingEvent.Disable();
6471
VerifiedEvent.Disable();
72+
PickupEvent.Disable();
6573
ServerEvent.Disable();
6674
if (ReferenceEquals(Instance, this))
6775
{

Command/RemoteAdmin/Causality.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,42 +126,15 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
126126
int n = 0;
127127
foreach (ActorTrack t in Timeline.Tracks.Values)
128128
{
129-
if (t.Frames.Count <= 0)
129+
if (t.Frames.Count <= 0 || t.StartFrame > 0)
130130
{
131131
continue;
132132
}
133133

134-
ReferenceHub h = DummyUtils.SpawnDummy(t.ActorName);
135-
if (h == null)
134+
if (Timeline.TrySpawnActor(t))
136135
{
137-
continue;
138-
}
139-
140-
Vector3 pos = t.Frames[0].Pos;
141-
Vector2 rot = t.Frames[0].Rot;
142-
RoleTypeId safeRole = (RoleTypeId)(sbyte)t.Role;
143-
for (int i = 0; i < t.LifeEvents.Count; i++)
144-
{
145-
if (t.LifeEvents[i].Type == EventType.RoleChanged)
146-
{
147-
safeRole = (RoleTypeId)t.LifeEvents[i].RoleId;
148-
break;
149-
}
136+
n++;
150137
}
151-
152-
h.roleManager.ServerSetRole(safeRole, RoleChangeReason.RemoteAdmin);
153-
Timing.CallDelayed(0.1f, () =>
154-
{
155-
if (h == null)
156-
{
157-
return;
158-
}
159-
160-
h.TryOverridePosition(pos);
161-
h.TryOverrideRotation(rot);
162-
t.Dummy = h;
163-
});
164-
n++;
165138
}
166139

167140
if (n == 0)
@@ -279,6 +252,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
279252
return true;
280253
}
281254

255+
Timeline.ApplyWorldState();
282256
response = $"Replay loaded: {p}";
283257
return true;
284258
}

Core/ActorTrack.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public sealed class ActorTrack
2727

2828
public sbyte Role { get; set; }
2929

30+
public int StartFrame { get; set; }
31+
3032
public List<FrameData> Frames { get; } = new List<FrameData>();
3133

3234
public List<AudioPacket> AudioFrames { get; } = new List<AudioPacket>();

Core/LifecycleEvent.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace Causality0.Core;
66
public enum EventType : byte
77
{
88
RoleChanged,
9-
Died
9+
Died,
10+
Left
1011
}
1112

1213
public struct LifecycleEvent
@@ -33,4 +34,9 @@ public static LifecycleEvent NewDeath(int f, DamageHandlerBase h)
3334
{
3435
return new LifecycleEvent(f, EventType.Died, 0, DamageData.FromHandler(h));
3536
}
37+
38+
public static LifecycleEvent NewLeft(int f)
39+
{
40+
return new LifecycleEvent(f, EventType.Left, 0, default);
41+
}
3642
}

Core/ProjectileTrack.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public sealed class ProjectileTrack
2323
public List<ProjectileFrame> Frames { get; } = new List<ProjectileFrame>();
2424
public bool HasDetonated { get; set; }
2525
public int StartFrame { get; set; }
26+
public int OwnerId { get; set; }
2627
public Footprint Owner { get; set; }
2728
public ThrownProjectile Live { get; set; }
2829
public ThrownProjectile Puppet { get; set; }

Core/Serializer.cs

Lines changed: 191 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using InventorySystem.Items;
23
using PlayerRoles;
34

45
namespace Causality0.Core;
@@ -16,7 +17,7 @@ public static void Save(string path)
1617
using FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
1718
using BinaryWriter w = new BinaryWriter(fs);
1819
w.Write("CAUS");
19-
w.Write((byte)9);
20+
w.Write((byte)13);
2021
w.Write(Timeline.MapSeed);
2122
w.Write(Timeline.CurrentFps);
2223
w.Write(Timeline.Tracks.Count);
@@ -25,6 +26,7 @@ public static void Save(string path)
2526
w.Write(t.PlayerId);
2627
w.Write(t.ActorName ?? string.Empty);
2728
w.Write(t.Role);
29+
w.Write(t.StartFrame);
2830
w.Write(t.Frames.Count);
2931
for (int i = 0; i < t.Frames.Count; i++)
3032
{
@@ -102,6 +104,116 @@ public static void Save(string path)
102104
w.Write(x.Act);
103105
w.Write(x.CanOpen);
104106
}
107+
108+
w.Write(Timeline.HasWorldState);
109+
if (Timeline.HasWorldState)
110+
{
111+
w.Write(Timeline.WorldPickups.Count);
112+
for (int i = 0; i < Timeline.WorldPickups.Count; i++)
113+
{
114+
PickupData x = Timeline.WorldPickups[i];
115+
w.Write(x.Id);
116+
w.Write(x.T);
117+
w.Write(x.Pos.x);
118+
w.Write(x.Pos.y);
119+
w.Write(x.Pos.z);
120+
w.Write(x.Rot.x);
121+
w.Write(x.Rot.y);
122+
w.Write(x.Rot.z);
123+
w.Write(x.Rot.w);
124+
w.Write(x.At);
125+
w.Write(x.Am);
126+
w.Write(x.Locked);
127+
}
128+
129+
w.Write(Timeline.PickupOps.Count);
130+
for (int i = 0; i < Timeline.PickupOps.Count; i++)
131+
{
132+
PickupOp x = Timeline.PickupOps[i];
133+
w.Write(x.Ts);
134+
w.Write((byte)x.Act);
135+
w.Write(x.Id);
136+
if (x.Act != PickupAct.Remove)
137+
{
138+
PickupData pd = x.Data;
139+
w.Write(pd.Id);
140+
w.Write(pd.T);
141+
w.Write(pd.Pos.x);
142+
w.Write(pd.Pos.y);
143+
w.Write(pd.Pos.z);
144+
w.Write(pd.Rot.x);
145+
w.Write(pd.Rot.y);
146+
w.Write(pd.Rot.z);
147+
w.Write(pd.Rot.w);
148+
w.Write(pd.At);
149+
w.Write(pd.Am);
150+
w.Write(pd.Locked);
151+
}
152+
}
153+
154+
w.Write(Timeline.LockerStates.Count);
155+
for (int i = 0; i < Timeline.LockerStates.Count; i++)
156+
{
157+
LockerData x = Timeline.LockerStates[i];
158+
w.Write(x.Pos.x);
159+
w.Write(x.Pos.y);
160+
w.Write(x.Pos.z);
161+
w.Write(x.Id);
162+
w.Write(x.Open);
163+
w.Write(x.WasOpen);
164+
w.Write(x.Items.Count);
165+
for (int j = 0; j < x.Items.Count; j++)
166+
{
167+
PickupData pd = x.Items[j];
168+
w.Write(pd.Id);
169+
w.Write(pd.T);
170+
w.Write(pd.Pos.x);
171+
w.Write(pd.Pos.y);
172+
w.Write(pd.Pos.z);
173+
w.Write(pd.Rot.x);
174+
w.Write(pd.Rot.y);
175+
w.Write(pd.Rot.z);
176+
w.Write(pd.Rot.w);
177+
w.Write(pd.At);
178+
w.Write(pd.Am);
179+
w.Write(pd.Locked);
180+
}
181+
}
182+
183+
w.Write(Timeline.LockerOps.Count);
184+
for (int i = 0; i < Timeline.LockerOps.Count; i++)
185+
{
186+
LockerOp x = Timeline.LockerOps[i];
187+
w.Write(x.Ts);
188+
w.Write(x.Pos.x);
189+
w.Write(x.Pos.y);
190+
w.Write(x.Pos.z);
191+
w.Write(x.Id);
192+
w.Write(x.Open);
193+
w.Write(x.CanOpen);
194+
}
195+
}
196+
197+
w.Write(Timeline.ProjTracks.Count);
198+
for (int i = 0; i < Timeline.ProjTracks.Count; i++)
199+
{
200+
ProjectileTrack x = Timeline.ProjTracks[i];
201+
w.Write((ushort)x.ProjectileType);
202+
w.Write(x.StartFrame);
203+
w.Write(x.OwnerId);
204+
w.Write(x.Frames.Count);
205+
for (int j = 0; j < x.Frames.Count; j++)
206+
{
207+
ProjectileFrame f = x.Frames[j];
208+
w.Write(f.Pos.x);
209+
w.Write(f.Pos.y);
210+
w.Write(f.Pos.z);
211+
w.Write(f.Rot.x);
212+
w.Write(f.Rot.y);
213+
w.Write(f.Rot.z);
214+
w.Write(f.Rot.w);
215+
}
216+
}
105217
}
106218

107219
public static bool Load(string path)
@@ -138,7 +250,8 @@ public static bool Load(string path)
138250
{
139251
PlayerId = r.ReadInt32(),
140252
ActorName = r.ReadString(),
141-
Role = r.ReadSByte()
253+
Role = r.ReadSByte(),
254+
StartFrame = v >= 10 ? r.ReadInt32() : 0
142255
};
143256
int m = r.ReadInt32();
144257
for (int j = 0; j < m; j++)
@@ -224,6 +337,82 @@ public static bool Load(string path)
224337
}
225338
}
226339

340+
if (v >= 11)
341+
{
342+
Timeline.HasWorldState = r.ReadBoolean();
343+
if (Timeline.HasWorldState)
344+
{
345+
int c = r.ReadInt32();
346+
for (int i = 0; i < c; i++)
347+
{
348+
Timeline.WorldPickups.Add(new PickupData(r.ReadInt32(), (ItemType)r.ReadUInt16(), new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), new UnityEngine.Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), r.ReadUInt32(), r.ReadUInt16(), r.ReadBoolean()));
349+
}
350+
351+
c = r.ReadInt32();
352+
for (int i = 0; i < c; i++)
353+
{
354+
float ts = r.ReadSingle();
355+
PickupAct a = (PickupAct)r.ReadByte();
356+
int id = r.ReadInt32();
357+
if (a != PickupAct.Remove)
358+
{
359+
PickupData d = new PickupData(r.ReadInt32(), (ItemType)r.ReadUInt16(), new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), new UnityEngine.Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), r.ReadUInt32(), r.ReadUInt16(), r.ReadBoolean());
360+
Timeline.PickupOps.Add(new PickupOp(ts, a, id, d));
361+
}
362+
else
363+
{
364+
Timeline.PickupOps.Add(PickupOp.NewRemove(ts, id));
365+
}
366+
}
367+
368+
c = r.ReadInt32();
369+
for (int i = 0; i < c; i++)
370+
{
371+
LockerData x = new LockerData
372+
{
373+
Pos = new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()),
374+
Id = r.ReadByte(),
375+
Open = r.ReadBoolean(),
376+
WasOpen = r.ReadBoolean()
377+
};
378+
int n2 = r.ReadInt32();
379+
for (int j = 0; j < n2; j++)
380+
{
381+
x.Items.Add(new PickupData(r.ReadInt32(), (ItemType)r.ReadUInt16(), new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), new UnityEngine.Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), r.ReadUInt32(), r.ReadUInt16(), r.ReadBoolean()));
382+
}
383+
384+
Timeline.LockerStates.Add(x);
385+
}
386+
387+
c = r.ReadInt32();
388+
for (int i = 0; i < c; i++)
389+
{
390+
Timeline.LockerOps.Add(new LockerOp(r.ReadSingle(), new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), r.ReadByte(), r.ReadBoolean(), r.ReadBoolean()));
391+
}
392+
}
393+
}
394+
395+
if (v >= 12)
396+
{
397+
int c = r.ReadInt32();
398+
for (int i = 0; i < c; i++)
399+
{
400+
ProjectileTrack x = new ProjectileTrack
401+
{
402+
ProjectileType = (ItemType)r.ReadUInt16(),
403+
StartFrame = r.ReadInt32(),
404+
OwnerId = r.ReadInt32()
405+
};
406+
int n2 = r.ReadInt32();
407+
for (int j = 0; j < n2; j++)
408+
{
409+
x.Frames.Add(new ProjectileFrame(new UnityEngine.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), new UnityEngine.Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle())));
410+
}
411+
412+
Timeline.ProjTracks.Add(x);
413+
}
414+
}
415+
227416
return true;
228417
}
229418
}

0 commit comments

Comments
 (0)