Skip to content

Commit 3514b97

Browse files
committed
Config update
1 parent 7a84f07 commit 3514b97

6 files changed

Lines changed: 156 additions & 54 deletions

File tree

Causality-0.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
</ItemGroup>
6969
<ItemGroup>
7070
<Compile Include="Causality0.cs" />
71+
<Compile Include="Causality0Config.cs" />
7172
<Compile Include="Core\FrameData.cs" />
7273
<Compile Include="Core\ActorTrack.cs" />
7374
<Compile Include="Core\ProjectileTrack.cs" />

Causality0.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Causality0;
88

9-
public sealed class Causality0 : Plugin
9+
public sealed class Causality0 : Plugin<Causality0Config>
1010
{
1111
public static Causality0 Instance { get; private set; }
1212

@@ -38,13 +38,24 @@ public sealed class Causality0 : Plugin
3838

3939
public override string Author { get; } = "MiaoMiao";
4040

41-
public override Version Version { get; } = new(1, 0, 0);
41+
public override Version Version { get; } = new(1, 0, 1);
4242

4343
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
4444

4545
public override void Enable()
4646
{
4747
Instance = this;
48+
int fps = Config?.DefaultRecordFps ?? 60;
49+
if (fps < 1)
50+
{
51+
fps = 1;
52+
}
53+
else if (fps > 240)
54+
{
55+
fps = 240;
56+
}
57+
58+
Core.Timeline.CurrentFps = fps;
4859
ServerEvent.Enable();
4960
PickupEvent.Enable();
5061
VerifiedEvent.Enable();

Causality0Config.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.ComponentModel;
2+
3+
namespace Causality0;
4+
5+
public sealed class Causality0Config
6+
{
7+
[Description("默认录制帧率 只影响新开始的录制,不影响加载已有回放。推荐 15-120 / Default recording FPS. Only affects new recordings and does not affect loading existing replays. Recommended range: 15-120.")]
8+
public int DefaultRecordFps { get; set; } = 60;
9+
10+
[Description("是否录制玩家语音 关闭时仍可正常录制与回放其他数据,只是不保存语音包 / Whether to record player voice. When disabled, other data can still be recorded and replayed normally, but voice packets will not be saved.")]
11+
public bool RecordVoice { get; set; } = false;
12+
}

Core/Timeline.cs

Lines changed: 126 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public static void TrackActor(ReferenceHub h)
143143
public static void StartRecord(ReferenceHub h)
144144
{
145145
StopRecord();
146+
int fps = global::Causality0.Causality0.Instance?.Config?.DefaultRecordFps ?? 60;
147+
CurrentFps = Mathf.Clamp(fps, 1, 240);
146148
MapSeed = MapGeneration.SeedSynchronizer.Seed;
147149
RecordStartTime = Time.time;
148150
RecFrame = 0;
@@ -524,6 +526,61 @@ private static bool TryGetLockerChamber(Vector3 p, byte id, out LockerChamber c)
524526
return false;
525527
}
526528

529+
private static void MarkLockerFilled(Locker lk)
530+
{
531+
if (lk?.Base == null)
532+
{
533+
return;
534+
}
535+
536+
var f = typeof(MapGeneration.Distributors.Locker).GetField("_serverChambersFilled", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
537+
if (f != null)
538+
{
539+
f.SetValue(lk.Base, true);
540+
}
541+
}
542+
543+
private static void SyncMicroPedestal(Locker lk)
544+
{
545+
if (lk?.Base is not InventorySystem.Items.MicroHID.MicroHIDPedestal mp || lk.Chambers.Count < 1)
546+
{
547+
return;
548+
}
549+
550+
InventorySystem.Items.MicroHID.MicroHIDPickup p = null;
551+
for (int i = 0; i < lk.Chambers[0].Base.Content.Count; i++)
552+
{
553+
if (lk.Chambers[0].Base.Content[i] is InventorySystem.Items.MicroHID.MicroHIDPickup x)
554+
{
555+
p = x;
556+
break;
557+
}
558+
}
559+
560+
var tf = typeof(InventorySystem.Items.MicroHID.MicroHIDPedestal).GetField("_trackedPickup", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
561+
var ff = typeof(InventorySystem.Items.MicroHID.MicroHIDPedestal).GetField("_isTrackingPickup", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
562+
var hf = typeof(InventorySystem.Items.MicroHID.MicroHIDPedestal).GetField("_hasHidDoorOpened", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
563+
tf?.SetValue(mp, p != null ? p.transform : null);
564+
ff?.SetValue(mp, p != null);
565+
hf?.SetValue(mp, false);
566+
if (p == null)
567+
{
568+
return;
569+
}
570+
571+
var m = typeof(InventorySystem.Items.MicroHID.MicroHIDPedestal).GetMethod("ReleaseConnectionWithPickup", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
572+
if (m == null)
573+
{
574+
return;
575+
}
576+
577+
var cb = (System.Action)System.Delegate.CreateDelegate(typeof(System.Action), mp, m, false);
578+
if (cb != null)
579+
{
580+
p.OnSelfDestroyed += cb;
581+
}
582+
}
583+
527584
private static Pickup SpawnWorldPickup(PickupData x)
528585
{
529586
Pickup p = Pickup.Create(x.ItemType, x.Pos, x.Rot);
@@ -539,29 +596,61 @@ private static Pickup SpawnWorldPickup(PickupData x)
539596

540597
private static Pickup SpawnLockerPickup(LockerChamber c, PickupData x, int idx, bool v)
541598
{
542-
c.Base.GetSpawnpoint(x.ItemType, idx, out Vector3 p0, out Quaternion r0, out Transform t0);
543-
Pickup p = Pickup.Create(x.ItemType, p0, r0);
544-
if (p == null)
599+
Pickup p = null;
600+
try
545601
{
546-
return null;
547-
}
602+
object[] a = { x.ItemType, idx, null, null, null };
603+
var m = c.Base.GetType().GetMethod("GetSpawnpoint", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, new[] { typeof(ItemType), typeof(int), typeof(Vector3).MakeByRefType(), typeof(Quaternion).MakeByRefType(), typeof(Transform).MakeByRefType() }, null);
604+
if (m != null && InventoryItemLoader.AvailableItems.TryGetValue(x.ItemType, out ItemBase it))
605+
{
606+
m.Invoke(c.Base, a);
607+
if (a[2] is Vector3 p0 && a[3] is Quaternion r0 && a[4] is Transform t0 && t0 != null)
608+
{
609+
ItemPickupBase b = Object.Instantiate(it.PickupDropModel, p0, r0);
610+
if (b != null)
611+
{
612+
b.transform.SetParent(t0);
613+
b.NetworkInfo = new PickupSyncInfo(x.ItemType, it.Weight, 0, locked: true);
614+
c.Base.Content.Add(b);
615+
if (b is InventorySystem.Items.Pickups.IPickupDistributorTrigger trg)
616+
{
617+
trg.OnDistributed();
618+
}
548619

549-
p.Transform.SetParent(t0);
550-
p.Position = x.Pos;
551-
p.Rotation = x.Rot;
552-
c.Base.Content.Add(p.Base);
553-
if (p.Base is InventorySystem.Items.Pickups.IPickupDistributorTrigger trg)
554-
{
555-
trg.OnDistributed();
556-
}
620+
if (b.TryGetComponent<Rigidbody>(out var rb))
621+
{
622+
rb.isKinematic = true;
623+
rb.transform.ResetLocalPose();
624+
MapGeneration.Distributors.SpawnablesDistributorBase.BodiesToUnfreeze.Add(rb);
625+
}
557626

558-
if (c.Base.SpawnOnFirstChamberOpening && !v)
627+
p = Pickup.Get(b);
628+
if (p != null)
629+
{
630+
if (c.Base.SpawnOnFirstChamberOpening && !v)
631+
{
632+
c.Base.ToBeSpawned.Add(b);
633+
}
634+
else
635+
{
636+
MapGeneration.Distributors.ItemDistributor.SpawnPickup(b);
637+
}
638+
}
639+
}
640+
}
641+
}
642+
}
643+
catch
559644
{
560-
c.Base.ToBeSpawned.Add(p.Base);
561645
}
562-
else
646+
647+
if (p == null)
563648
{
564-
p.Spawn();
649+
p = c.AddItem(x.ItemType);
650+
if (p == null)
651+
{
652+
return null;
653+
}
565654
}
566655

567656
ApplyPickupData(p, x);
@@ -680,6 +769,12 @@ public static void ApplyWorldState()
680769
c.IsOpen = x.Open;
681770
}
682771

772+
foreach (Locker lk in Locker.List)
773+
{
774+
MarkLockerFilled(lk);
775+
SyncMicroPedestal(lk);
776+
}
777+
683778
for (int i = 0; i < WorldPickups.Count; i++)
684779
{
685780
Pickup p = SpawnWorldPickup(WorldPickups[i]);
@@ -1041,12 +1136,12 @@ private static void ReplayInteract(InteractFrame x)
10411136
}
10421137
}
10431138

1044-
if (!Tracks.TryGetValue(x.PlayerId, out var t) || t.Dummy == null)
1139+
if (!x.CanOpen)
10451140
{
10461141
return;
10471142
}
10481143

1049-
d.ServerInteract(t.Dummy, 0);
1144+
d.NetworkTargetState = !d.TargetState;
10501145
}
10511146

10521147
public static void TrackProjectile(ThrownProjectile p, ItemType t, ReferenceHub h)
@@ -1381,6 +1476,18 @@ private static IEnumerator<float> RunPlay()
13811476
live = true;
13821477
}
13831478

1479+
while (d < Interacts.Count && Interacts[d].Timestamp <= e)
1480+
{
1481+
ReplayInteract(Interacts[d]);
1482+
d++;
1483+
live = true;
1484+
}
1485+
1486+
if (d < Interacts.Count)
1487+
{
1488+
live = true;
1489+
}
1490+
13841491
foreach (ActorTrack t in Tracks.Values)
13851492
{
13861493
int sf = t.StartFrame < 0 ? 0 : t.StartFrame;
@@ -1589,18 +1696,6 @@ private static IEnumerator<float> RunPlay()
15891696
live = true;
15901697
}
15911698

1592-
while (d < Interacts.Count && Interacts[d].Timestamp <= e)
1593-
{
1594-
ReplayInteract(Interacts[d]);
1595-
d++;
1596-
live = true;
1597-
}
1598-
1599-
if (d < Interacts.Count)
1600-
{
1601-
live = true;
1602-
}
1603-
16041699
if (!live)
16051700
{
16061701
yield break;

Event/PlayerEvent/VoiceChat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Disable()
2121

2222
private void OnSendingVoice(PlayerSendingVoiceMessageEventArgs ev)
2323
{
24-
if (!Timeline.IsRec)
24+
if (!Timeline.IsRec || global::Causality0.Causality0.Instance?.Config?.RecordVoice != true)
2525
{
2626
return;
2727
}

Properties/AssemblyInfo.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,15 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

5-
// 有关程序集的一般信息由以下
6-
// 控制。更改这些特性值可修改
7-
// 与程序集关联的信息。
85
[assembly: AssemblyTitle("Causality-0")]
9-
[assembly: AssemblyDescription("")]
6+
[assembly: AssemblyDescription("V1.0.1pre")]
107
[assembly: AssemblyConfiguration("")]
118
[assembly: AssemblyCompany("")]
129
[assembly: AssemblyProduct("Causality-0")]
1310
[assembly: AssemblyCopyright("Copyright © 2026")]
1411
[assembly: AssemblyTrademark("")]
1512
[assembly: AssemblyCulture("")]
16-
17-
// 将 ComVisible 设置为 false 会使此程序集中的类型
18-
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19-
//请将此类型的 ComVisible 特性设置为 true。
2013
[assembly: ComVisible(false)]
21-
22-
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
2314
[assembly: Guid("c330cc05-5d74-462c-a029-70c5e535b2cd")]
24-
25-
// 程序集的版本信息由下列四个值组成:
26-
//
27-
// 主版本
28-
// 次版本
29-
// 生成号
30-
// 修订号
31-
//
32-
[assembly: AssemblyVersion("1.0.0.0")]
33-
[assembly: AssemblyFileVersion("1.0.0.0")]
15+
[assembly: AssemblyVersion("1.0.1.0")]
16+
[assembly: AssemblyFileVersion("1.0.1.0")]

0 commit comments

Comments
 (0)