mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Fix replay int overflow issues.
This came up while we were configuring stuff for the 24h round.
This commit is contained in:
@@ -34,6 +34,11 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
|
||||
// date format for default replay names. Like the sortable template, but without colons.
|
||||
public const string DefaultReplayNameFormat = "yyyy-MM-dd_HH-mm-ss";
|
||||
|
||||
// Kinda arbitrary but (after multiplying by 1024 cuz it's kB)
|
||||
// needs to be less than (max array size) / 2.
|
||||
// I don't think anybody's gonna write 256 MB of chunk at once yeah?
|
||||
private const int MaxTickBatchSize = 256 * 1024;
|
||||
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] protected readonly INetConfigurationManager NetConf = default!;
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
@@ -50,8 +55,8 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
|
||||
private List<object> _queuedMessages = new();
|
||||
|
||||
// Config variables.
|
||||
private int _maxCompressedSize;
|
||||
private int _maxUncompressedSize;
|
||||
private long _maxCompressedSize;
|
||||
private long _maxUncompressedSize;
|
||||
private int _tickBatchSize;
|
||||
private bool _enabled;
|
||||
|
||||
@@ -63,9 +68,9 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
|
||||
{
|
||||
_sawmill = _logManager.GetSawmill("replay");
|
||||
|
||||
NetConf.OnValueChanged(CVars.ReplayMaxCompressedSize, (v) => _maxCompressedSize = v * 1024, true);
|
||||
NetConf.OnValueChanged(CVars.ReplayMaxUncompressedSize, (v) => _maxUncompressedSize = v * 1024, true);
|
||||
NetConf.OnValueChanged(CVars.ReplayTickBatchSize, (v) => _tickBatchSize = v * 1024, true);
|
||||
NetConf.OnValueChanged(CVars.ReplayMaxCompressedSize, (v) => _maxCompressedSize = SaturatingMultiplyKb(v), true);
|
||||
NetConf.OnValueChanged(CVars.ReplayMaxUncompressedSize, (v) => _maxUncompressedSize = SaturatingMultiplyKb(v), true);
|
||||
NetConf.OnValueChanged(CVars.ReplayTickBatchSize, (v) => _tickBatchSize = Math.Min(v, MaxTickBatchSize) * 1024, true);
|
||||
NetConf.OnValueChanged(CVars.NetPvsCompressLevel, OnCompressionChanged);
|
||||
}
|
||||
|
||||
@@ -450,6 +455,18 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
|
||||
return new ReplayRecordingStats(time, tick, size, altSize);
|
||||
}
|
||||
|
||||
private static long SaturatingMultiplyKb(long kb)
|
||||
{
|
||||
var result = kb * 1024;
|
||||
if (result < kb)
|
||||
{
|
||||
// Overflow
|
||||
return long.MaxValue;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains all state related to an active recording.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user