Skip to content

Commit 7b1c1ac

Browse files
committed
Add LZMA compression & improve replay world handling
Add configurable replay compression (None/Lzma) and presets, with LZMA save/load support and format auto-detection; expose Serializer.LastErr for better error messages. Improve timeline/playback world handling: more robust pickup spawn/fallback logic, replay-world cleanup, deterministic pickup destruction, seed-fixing for old files, and door interaction spatial matching. Remove legacy locker serialization/handling and related event code. Wire server round events to stop/cleanup timeline on round end/restart/waiting, adjust voice timestamping, and update protocol/version metadata and README. Project file updated with NuGet references and an ILRepack merge target; assembly description bumped to V1.0.1 and added app/packages/release docs.
1 parent 48a6577 commit 7b1c1ac

17 files changed

Lines changed: 713 additions & 498 deletions

Causality-0.csproj

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<FileAlignment>512</FileAlignment>
1414
<Deterministic>true</Deterministic>
1515
<LangVersion>latest</LangVersion>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
1618
</PropertyGroup>
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1820
<DebugSymbols>true</DebugSymbols>
@@ -38,15 +40,40 @@
3840
<Reference Include="Assembly-CSharp-firstpass">
3941
<HintPath>lib\net48\Assembly-CSharp-firstpass.dll</HintPath>
4042
</Reference>
43+
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
44+
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
45+
</Reference>
4146
<Reference Include="Mirror">
4247
<HintPath>lib\net48\Mirror.dll</HintPath>
4348
</Reference>
4449
<Reference Include="Pooling, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
4550
<SpecificVersion>False</SpecificVersion>
4651
<HintPath>lib\net48\Pooling.dll</HintPath>
4752
</Reference>
53+
<Reference Include="SharpCompress, Version=0.47.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
54+
<HintPath>packages\SharpCompress.0.47.0\lib\net48\SharpCompress.dll</HintPath>
55+
</Reference>
4856
<Reference Include="System" />
57+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
58+
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
59+
</Reference>
4960
<Reference Include="System.Core" />
61+
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
62+
<HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.Numerics" />
65+
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
66+
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
67+
</Reference>
68+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
69+
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
70+
</Reference>
71+
<Reference Include="System.Text.Encoding.CodePages, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
72+
<HintPath>packages\System.Text.Encoding.CodePages.8.0.0\lib\net462\System.Text.Encoding.CodePages.dll</HintPath>
73+
</Reference>
74+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
75+
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
76+
</Reference>
5077
<Reference Include="System.Xml.Linq" />
5178
<Reference Include="System.Data.DataSetExtensions" />
5279
<Reference Include="Microsoft.CSharp" />
@@ -83,7 +110,6 @@
83110
<Compile Include="Event\PlayerEvent\Verified.cs" />
84111
<Compile Include="Event\PlayerEvent\Shooting.cs" />
85112
<Compile Include="Event\PlayerEvent\Reloading.cs" />
86-
<Compile Include="Event\PlayerEvent\Lockers.cs" />
87113
<Compile Include="Event\PlayerEvent\Using.cs" />
88114
<Compile Include="Event\PlayerEvent\VoiceChat.cs" />
89115
<Compile Include="Event\PlayerEvent\Throwing.cs" />
@@ -94,5 +120,35 @@
94120
<Compile Include="Command\RemoteAdmin\Causality.cs" />
95121
<Compile Include="Properties\AssemblyInfo.cs" />
96122
</ItemGroup>
123+
<ItemGroup>
124+
<None Include="app.config" />
125+
<None Include="packages.config" />
126+
</ItemGroup>
97127
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
98-
</Project>
128+
<Import Project="packages\ILRepack.Lib.MSBuild.Task.2.0.44.1\build\ILRepack.Lib.MSBuild.Task.targets" Condition="Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.44.1\build\ILRepack.Lib.MSBuild.Task.targets')" />
129+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
130+
<PropertyGroup>
131+
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
132+
</PropertyGroup>
133+
<Error Condition="!Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.44.1\build\ILRepack.Lib.MSBuild.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\ILRepack.Lib.MSBuild.Task.2.0.44.1\build\ILRepack.Lib.MSBuild.Task.targets'))" />
134+
</Target>
135+
<Target Name="MergeDependencies" AfterTargets="Build">
136+
<ItemGroup>
137+
<InputAssemblies Include="$(OutputPath)$(TargetFileName)" />
138+
<InputAssemblies Include="$(OutputPath)SharpCompress.dll" />
139+
<InputAssemblies Include="$(OutputPath)Microsoft.Bcl.AsyncInterfaces.dll" />
140+
<InputAssemblies Include="$(OutputPath)System.Buffers.dll" />
141+
<InputAssemblies Include="$(OutputPath)System.Memory.dll" />
142+
<InputAssemblies Include="$(OutputPath)System.Numerics.Vectors.dll" />
143+
<InputAssemblies Include="$(OutputPath)System.Runtime.CompilerServices.Unsafe.dll" />
144+
<InputAssemblies Include="$(OutputPath)System.Text.Encoding.CodePages.dll" />
145+
<InputAssemblies Include="$(OutputPath)System.Threading.Tasks.Extensions.dll" />
146+
<LibraryPath Include="$(OutputPath)" />
147+
<LibraryPath Include="$(MSBuildProjectDirectory)\lib\net48" />
148+
</ItemGroup>
149+
<ILRepack Parallel="true" DebugInfo="true" AllowDuplicateResources="true" LibraryPath="@(LibraryPath)" InputAssemblies="@(InputAssemblies)" TargetKind="SameAsPrimaryAssembly" OutputFile="$(OutputPath)$(TargetFileName)" />
150+
</Target>
151+
<Target Name="MergeDependenciesClean" AfterTargets="MergeDependencies">
152+
<Delete Files="$(OutputPath)SharpCompress.dll;$(OutputPath)Microsoft.Bcl.AsyncInterfaces.dll;$(OutputPath)System.Buffers.dll;$(OutputPath)System.Memory.dll;$(OutputPath)System.Numerics.Vectors.dll;$(OutputPath)System.Runtime.CompilerServices.Unsafe.dll;$(OutputPath)System.Text.Encoding.CodePages.dll;$(OutputPath)System.Threading.Tasks.Extensions.dll" />
153+
</Target>
154+
</Project>

Causality-0.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<Solution>
2-
<Project Path="Causality-0.csproj" />
2+
<Project Path="Causality-0.csproj" Id="c330cc05-5d74-462c-a029-70c5e535b2cd" />
33
</Solution>

Causality0.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using Causality0.Event.PlayerEvent;
33
using Causality0.Event.ServerEvent;
4+
using LabApi.Events.Arguments.ServerEvents;
5+
using LabApi.Events.Handlers;
46
using LabApi.Features;
57
using LabApi.Loader.Features.Plugins;
68

@@ -28,8 +30,6 @@ public sealed class Causality0 : Plugin<Causality0Config>
2830

2931
public Interacting InteractingEvent { get; } = new();
3032

31-
public Lockers LockersEvent { get; } = new();
32-
3333
public Lifecycle LifecycleEvent { get; } = new();
3434

3535
public override string Name { get; } = "Causality-0";
@@ -56,6 +56,9 @@ public override void Enable()
5656
}
5757

5858
Core.Timeline.CurrentFps = fps;
59+
ServerEvents.WaitingForPlayers += OnWaitingForPlayers;
60+
ServerEvents.RoundRestarted += OnRoundRestarted;
61+
ServerEvents.RoundEnded += OnRoundEnded;
5962
ServerEvent.Enable();
6063
PickupEvent.Enable();
6164
VerifiedEvent.Enable();
@@ -65,14 +68,14 @@ public override void Enable()
6568
VoiceChatEvent.Enable();
6669
ThrowingEvent.Enable();
6770
InteractingEvent.Enable();
68-
LockersEvent.Enable();
6971
LifecycleEvent.Enable();
7072
}
7173

7274
public override void Disable()
7375
{
76+
Core.Timeline.StopPlay();
77+
Core.Timeline.CleanupReplayWorld();
7478
LifecycleEvent.Disable();
75-
LockersEvent.Disable();
7679
InteractingEvent.Disable();
7780
ThrowingEvent.Disable();
7881
VoiceChatEvent.Disable();
@@ -82,9 +85,30 @@ public override void Disable()
8285
VerifiedEvent.Disable();
8386
PickupEvent.Disable();
8487
ServerEvent.Disable();
88+
ServerEvents.RoundEnded -= OnRoundEnded;
89+
ServerEvents.RoundRestarted -= OnRoundRestarted;
90+
ServerEvents.WaitingForPlayers -= OnWaitingForPlayers;
8591
if (ReferenceEquals(Instance, this))
8692
{
8793
Instance = null;
8894
}
8995
}
96+
97+
private void OnWaitingForPlayers()
98+
{
99+
Core.Timeline.StopPlay();
100+
Core.Timeline.CleanupReplayWorld();
101+
}
102+
103+
private void OnRoundRestarted()
104+
{
105+
Core.Timeline.StopPlay();
106+
Core.Timeline.CleanupReplayWorld();
107+
}
108+
109+
private void OnRoundEnded(RoundEndedEventArgs ev)
110+
{
111+
Core.Timeline.StopPlay();
112+
Core.Timeline.CleanupReplayWorld();
113+
}
90114
}

Causality0Config.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,32 @@
22

33
namespace Causality0;
44

5+
public enum C0CompressionMode
6+
{
7+
None,
8+
Lzma
9+
}
10+
11+
public enum C0CompressionPreset
12+
{
13+
FastestSpeed,
14+
FastSpeed,
15+
Normal,
16+
HighCompression,
17+
MaximumCompression
18+
}
19+
520
public sealed class Causality0Config
621
{
722
[Description("默认录制帧率 只影响新开始的录制,不影响加载已有回放。推荐 15-120 / Default recording FPS. Only affects new recordings and does not affect loading existing replays. Recommended range: 15-120.")]
823
public int DefaultRecordFps { get; set; } = 60;
924

1025
[Description("是否录制玩家语音 关闭时仍可正常录制与回放其他数据,只是不保存语音包 / Whether to record player voice. When disabled, other data can still be recorded and replayed normally, but voice packets will not be saved.")]
1126
public bool RecordVoice { get; set; } = false;
27+
28+
[Description("回放文件压缩模式 可选 None、Lzma。保存时按所选协议写入,加载时会自动识别格式,不影响回放解码 / Replay file compression mode. Available values: None, Lzma. Saving uses the selected format, and loading auto-detects the format so playback decoding remains compatible.")]
29+
public C0CompressionMode ReplayCompression { get; set; } = C0CompressionMode.Lzma;
30+
31+
[Description("回放文件压缩档位 可选 FastestSpeed、FastSpeed、Normal、HighCompression、MaximumCompression。当前仅影响 Lzma / Replay compression preset. Available values: FastestSpeed, FastSpeed, Normal, HighCompression, MaximumCompression. Currently only affects Lzma.")]
32+
public C0CompressionPreset ReplayCompressionPreset { get; set; } = C0CompressionPreset.Normal;
1233
}

Command/RemoteAdmin/Causality.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
237237
string p = Path.Combine("CausalityRecords", arguments.At(0) + ".c0");
238238
if (!Serializer.Load(p))
239239
{
240-
response = "Load failed.";
240+
string s = Serializer.LastErr;
241+
response = string.IsNullOrWhiteSpace(s) ? "Load failed." : $"Load failed: {s}";
241242
return false;
242243
}
243244

Core/InteractFrame.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using UnityEngine;
2+
13
namespace Causality0.Core;
24

35
public struct InteractFrame
@@ -7,13 +9,17 @@ public struct InteractFrame
79
public byte DoorId;
810
public byte Act;
911
public bool CanOpen;
12+
public bool HasPos;
13+
public Vector3 Pos;
1014

11-
public InteractFrame(float timestamp, int playerId, byte doorId, byte act, bool canOpen)
15+
public InteractFrame(float timestamp, int playerId, byte doorId, byte act, bool canOpen, Vector3 pos, bool hasPos)
1216
{
1317
Timestamp = timestamp;
1418
PlayerId = playerId;
1519
DoorId = doorId;
1620
Act = act;
1721
CanOpen = canOpen;
22+
HasPos = hasPos;
23+
Pos = pos;
1824
}
1925
}

0 commit comments

Comments
 (0)