Skip to content

Commit 12ba3d1

Browse files
authored
FastTravelPlugin: switch to DisableCollisions + added admin debug helper (#154)
* FastTravelPlugin: switch to DisableCollisions * added admin only registerOnlineExtra for debugging * losing admin in session isnt possible * teleporting disabled when debug window open * some more clean up
1 parent c01db20 commit 12ba3d1

File tree

5 files changed

+206
-46
lines changed

5 files changed

+206
-46
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using AssettoServer.Server.Configuration;
22
using JetBrains.Annotations;
3-
using YamlDotNet.Core;
43
using YamlDotNet.Serialization;
54

65
namespace FastTravelPlugin;
76

87
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.WithMembers)]
98
public class FastTravelConfiguration : IValidateConfiguration<FastTravelConfigurationValidator>
109
{
11-
[YamlMember(Description = "Requires CSP version 0.2.8 (3424) which fixed disabling collisions online. \nSetting this to false will lower the version requirement to 0.2.0 (2651) but clients on versions below 0.2.3-preview211 will not have disabled collisions")]
12-
public bool RequireCollisionDisable { get; set; } = true;
10+
[YamlMember(Description = "Requires CSP version 0.2.8 (3424) which fixed disabling collisions online. \nSetting this to false will lower the version requirement to 0.2.0 (2651) and clients will not have disabled collisions when teleporting.")]
11+
public bool DisableCollisions { get; set; } = true;
1312

1413
[YamlMember(Description = "Available zoom levels. Last one should show the full track.\nIf map image is shown, prioritize matching the track to the map image.\nDon't change the values if using Shutoko Revival Project")]
1514
public List<int> MapZoomValues = [100, 1000, 4000, 15000];
@@ -18,8 +17,8 @@ public class FastTravelConfiguration : IValidateConfiguration<FastTravelConfigur
1817
public List<int> MapMoveSpeeds = [1, 5, 20, 0];
1918

2019
[YamlMember(Description = "Show the map.png of the track layout when in the last zoom level.\nDon't change if using Shutoko Revival Project")]
21-
public bool ShowMapImage = true;
20+
public bool ShowMapImage { get; set; } = true;
2221

23-
[YamlMember(Description = "Last zoom level has a fixed position, the track should be aligned to the center of the screen.\nIf map image is shown, prioritize aligning the track with the map image.\nDon't change the values if using Shutoko Revival Project")]
22+
[YamlMember(Description = "Last zoom level has a fixed position, the track should be aligned to the center of the screen.\nIf map image is shown, prioritize aligning the track with the map image.\nDon't change the values if using Shutoko Revival Project")]
2423
public List<int> MapFixedTargetPosition = [-2100, 0, 3200];
2524
}

FastTravelPlugin/FastTravelConfigurationValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public FastTravelConfigurationValidator()
1313
.Equal(cfg => cfg.MapZoomValues.Count)
1414
.WithMessage("MapMoveSpeeds and MapZoomValues must contain the same number of values");
1515
RuleFor(cfg => cfg.MapZoomValues)
16-
.Must(x =>x.SequenceEqual(x.Order().ToList()))
16+
.Must(x => x.SequenceEqual(x.Order().ToList()))
1717
.WithMessage("Values should not be lower than previous ones");
1818
RuleFor(cfg => cfg.MapMoveSpeeds)
1919
.Must(x => x[..^1].SequenceEqual(x[..^1].Order().ToList()))

FastTravelPlugin/FastTravelModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protected override void Load(ContainerBuilder builder)
1313

1414
public override FastTravelConfiguration ReferenceConfiguration => new()
1515
{
16+
DisableCollisions = false,
1617
MapZoomValues = [100, 200, 400, 600],
1718
MapMoveSpeeds = [1, 2, 3, 0],
1819
ShowMapImage = false,

FastTravelPlugin/FastTravelPlugin.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,35 @@ public FastTravelPlugin(FastTravelConfiguration configuration,
2222
AiSpline? aiSpline = null)
2323
{
2424
_aiSpline = aiSpline ?? throw new ConfigurationException("FastTravelPlugin does not work with AI traffic disabled");
25-
26-
if (configuration.RequireCollisionDisable && serverConfiguration.CSPTrackOptions.MinimumCSPVersion < CSPVersion.V0_2_8)
25+
26+
if (configuration.DisableCollisions && serverConfiguration.CSPTrackOptions.MinimumCSPVersion < CSPVersion.V0_2_8)
2727
{
2828
throw new ConfigurationException("FastTravelPlugin needs a minimum required CSP version of 0.2.8 (3424)");
2929
}
30-
31-
if (!configuration.RequireCollisionDisable && serverConfiguration.CSPTrackOptions.MinimumCSPVersion < CSPVersion.V0_2_0)
30+
31+
if (!configuration.DisableCollisions && serverConfiguration.CSPTrackOptions.MinimumCSPVersion < CSPVersion.V0_2_0)
3232
{
3333
throw new ConfigurationException("FastTravelPlugin needs a minimum required CSP version of 0.2.0 (2651)");
3434
}
3535

36-
// Include Client Reconnection Script
3736
if (!serverConfiguration.Extra.EnableClientMessages)
3837
{
3938
throw new ConfigurationException("FastTravelPlugin requires ClientMessages to be enabled");
4039
}
41-
40+
4241
var luaPath = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lua", "fasttravel.lua");
43-
42+
4443
using var streamReader = new StreamReader(luaPath);
45-
var reconnectScript = streamReader.ReadToEnd();
46-
scriptProvider.AddScript(reconnectScript, "fasttravel.lua", new Dictionary<string, object>
44+
var fasttravelScript = streamReader.ReadToEnd();
45+
scriptProvider.AddScript(fasttravelScript, "fasttravel.lua", new Dictionary<string, object>
4746
{
4847
["mapFixedTargetPosition"] = $"\"{JsonSerializer.Serialize(configuration.MapFixedTargetPosition)}\"",
4948
["mapZoomValues"] = $"\"{JsonSerializer.Serialize(configuration.MapZoomValues)}\"",
5049
["mapMoveSpeeds"] = $"\"{JsonSerializer.Serialize(configuration.MapMoveSpeeds)}\"",
51-
["showMapImg"] = configuration.ShowMapImage ? "true" : "false"
50+
["showMapImg"] = configuration.ShowMapImage ? "true" : "false",
51+
["disableCollisions"] = configuration.DisableCollisions ? "true" : "false"
5252
});
53-
53+
5454
cspClientMessageTypeManager.RegisterOnlineEvent<FastTravelPacket>(OnFastTravelPacket);
5555
}
5656

@@ -59,11 +59,11 @@ private void OnFastTravelPacket(ACTcpClient client, FastTravelPacket packet)
5959
var (splinePointId, _) = _aiSpline.WorldToSpline(packet.Position);
6060

6161
var splinePoint = _aiSpline.Points[splinePointId];
62-
63-
var direction = - _aiSpline.Operations.GetForwardVector(splinePoint.Id);
62+
63+
var direction = -_aiSpline.Operations.GetForwardVector(splinePoint.Id);
6464
if (direction == Vector3.Zero)
6565
direction = new Vector3(1, 0, 0);
66-
66+
6767
client.SendPacket(new FastTravelPacket
6868
{
6969
Position = packet.Position,

0 commit comments

Comments
 (0)