From 7bcc8edbc6ac7b023c3427b8737d48d9762005b5 Mon Sep 17 00:00:00 2001 From: Virx Date: Wed, 18 Dec 2024 17:11:56 -0500 Subject: [PATCH] Update csharpier --- .config/dotnet-tools.json | 2 +- RLBotCS/Conversion/ColorSwatches.cs | 6 +- RLBotCS/Conversion/FlatToCommand.cs | 42 +++---- RLBotCS/Conversion/FlatToModel.cs | 64 +++++------ RLBotCS/Conversion/GameStateToFlat.cs | 103 +++++++++--------- RLBotCS/Main.cs | 60 +++++----- RLBotCS/ManagerTools/AgentReservation.cs | 24 ++-- RLBotCS/ManagerTools/BallPredictor.cs | 42 +++---- RLBotCS/ManagerTools/ConfigParser.cs | 91 ++++++++-------- RLBotCS/ManagerTools/LaunchManager.cs | 2 +- RLBotCS/ManagerTools/MatchStarter.cs | 8 +- RLBotCS/ManagerTools/PerfMonitor.cs | 2 +- RLBotCS/ManagerTools/QuickChat.cs | 70 ++++++------ RLBotCS/ManagerTools/Rendering.cs | 48 ++++---- RLBotCS/Server/BridgeMessage.cs | 48 ++++---- RLBotCS/Server/FlatBuffersServer.cs | 67 ++++++------ RLBotCS/Server/FlatBuffersSession.cs | 46 ++++---- .../FlatbuffersMessage/DistributeGameState.cs | 8 +- .../FlatbuffersMessage/IServerMessage.cs | 2 +- .../FlatbuffersMessage/SendMatchComm.cs | 4 +- RLBotCS/Server/SocketSpecStreamReader.cs | 2 +- RLBotCS/Types/DataType.cs | 2 +- RLBotCS/Types/TypedPayload.cs | 2 +- RLBotCSTests/FlatbufferTest.cs | 2 +- RLBotCSTests/GameState.cs | 6 +- RLBotCSTests/PlayerMappingTest.cs | 2 +- 26 files changed, 367 insertions(+), 388 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 9e8f278..94b63e2 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.26.7", + "version": "0.30.3", "commands": [ "dotnet-csharpier" ] diff --git a/RLBotCS/Conversion/ColorSwatches.cs b/RLBotCS/Conversion/ColorSwatches.cs index a667532..a2d0447 100644 --- a/RLBotCS/Conversion/ColorSwatches.cs +++ b/RLBotCS/Conversion/ColorSwatches.cs @@ -96,7 +96,7 @@ internal static Color GetSecondary(uint colorId) => { 6, 44, 127 }, { 6, 22, 127 }, { 38, 6, 127 }, - { 48, 6, 127 } + { 48, 6, 127 }, }; private static readonly int[,] OrangeSwatches = @@ -170,7 +170,7 @@ internal static Color GetSecondary(uint colorId) => { 127, 30, 6 }, { 127, 6, 6 }, { 127, 6, 48 }, - { 127, 6, 66 } + { 127, 6, 66 }, }; private static readonly int[,] SecondarySwatches = @@ -279,6 +279,6 @@ internal static Color GetSecondary(uint colorId) => { 18, 0, 51 }, { 40, 0, 51 }, { 51, 0, 32 }, - { 51, 0, 8 } + { 51, 0, 8 }, }; } diff --git a/RLBotCS/Conversion/FlatToCommand.cs b/RLBotCS/Conversion/FlatToCommand.cs index d405863..a6f9d88 100644 --- a/RLBotCS/Conversion/FlatToCommand.cs +++ b/RLBotCS/Conversion/FlatToCommand.cs @@ -19,7 +19,7 @@ private static string MapGameMode(GameMode gameMode) => GameMode.Heatseeker => "?game=TAGame.GameInfo_GodBall_TA", GameMode.Gridiron => "?game=TAGame.GameInfo_Football_TA", GameMode.Knockout => "?game=TAGame.GameInfo_KnockOut_TA", - _ => throw new ArgumentOutOfRangeException(nameof(gameMode), gameMode, null) + _ => throw new ArgumentOutOfRangeException(nameof(gameMode), gameMode, null), }; private static string MapMatchLength(MatchLength matchLength) => @@ -29,7 +29,7 @@ private static string MapMatchLength(MatchLength matchLength) => MatchLength.Ten_Minutes => "10Minutes", MatchLength.Twenty_Minutes => "20Minutes", MatchLength.Unlimited => "UnlimitedTime", - _ => throw new ArgumentOutOfRangeException(nameof(matchLength), matchLength, null) + _ => throw new ArgumentOutOfRangeException(nameof(matchLength), matchLength, null), }; private static string MapMaxScore(MaxScore maxScore) => @@ -41,7 +41,7 @@ private static string MapMaxScore(MaxScore maxScore) => MaxScore.Five_Goals => "Max5", MaxScore.Seven_Goals => "Max7", MaxScore.Unlimited => "UnlimitedScore", - _ => throw new ArgumentOutOfRangeException(nameof(maxScore), maxScore, null) + _ => throw new ArgumentOutOfRangeException(nameof(maxScore), maxScore, null), }; private static string MapMultiBall(MultiBall multiBall) => @@ -51,7 +51,7 @@ private static string MapMultiBall(MultiBall multiBall) => MultiBall.Two => "TwoBalls", MultiBall.Four => "FourBalls", MultiBall.Six => "SixBalls", - _ => throw new ArgumentOutOfRangeException(nameof(multiBall), multiBall, null) + _ => throw new ArgumentOutOfRangeException(nameof(multiBall), multiBall, null), }; private static string MapOvertime(OvertimeOption option) => @@ -60,7 +60,7 @@ private static string MapOvertime(OvertimeOption option) => OvertimeOption.Unlimited => "", OvertimeOption.Five_Max_First_Score => "Overtime5MinutesFirstScore", OvertimeOption.Five_Max_Random_Team => "Overtime5MinutesRandom", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapSeriesLength(SeriesLengthOption option) => @@ -70,7 +70,7 @@ private static string MapSeriesLength(SeriesLengthOption option) => SeriesLengthOption.Three_Games => "3Games", SeriesLengthOption.Five_Games => "5Games", SeriesLengthOption.Seven_Games => "7Games", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapGameSpeed(GameSpeedOption option) => @@ -79,7 +79,7 @@ private static string MapGameSpeed(GameSpeedOption option) => GameSpeedOption.Default => "", GameSpeedOption.Slo_Mo => "SloMoGameSpeed", GameSpeedOption.Time_Warp => "SloMoDistanceBall", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBallMaxSpeed(BallMaxSpeedOption option) => @@ -89,7 +89,7 @@ private static string MapBallMaxSpeed(BallMaxSpeedOption option) => BallMaxSpeedOption.Slow => "SlowBall", BallMaxSpeedOption.Fast => "FastBall", BallMaxSpeedOption.Super_Fast => "SuperFastBall", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBallType(BallTypeOption option) => @@ -104,7 +104,7 @@ private static string MapBallType(BallTypeOption option) => BallTypeOption.Haunted => "Ball_Haunted", BallTypeOption.Ekin => "Ball_Ekin", BallTypeOption.SpookyCube => "Ball_SpookyCube", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBallWeight(BallWeightOption option) => @@ -117,7 +117,7 @@ private static string MapBallWeight(BallWeightOption option) => BallWeightOption.Curve_Ball => "MagnusBall", BallWeightOption.Beach_Ball_Curve => "MagnusBeachBall", BallWeightOption.Magnus_FutBall => "MagnusFutBallTest", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBallSize(BallSizeOption option) => @@ -128,7 +128,7 @@ private static string MapBallSize(BallSizeOption option) => BallSizeOption.Medium => "MediumBall", BallSizeOption.Large => "BigBall", BallSizeOption.Gigantic => "GiantBall", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBallBounciness(BallBouncinessOption option) => @@ -139,7 +139,7 @@ private static string MapBallBounciness(BallBouncinessOption option) => BallBouncinessOption.High => "HighBounciness", BallBouncinessOption.Super_High => "SuperBounciness", BallBouncinessOption.LowishBounciness => "LowishBounciness", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBoost(BoostOption option) => @@ -150,7 +150,7 @@ private static string MapBoost(BoostOption option) => BoostOption.Slow_Recharge => "SlowRecharge", BoostOption.Rapid_Recharge => "RapidRecharge", BoostOption.No_Boost => "NoBooster", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapRumble(RumbleOption option) => @@ -167,7 +167,7 @@ private static string MapRumble(RumbleOption option) => RumbleOption.Haunted_Ball_Beam => "ItemsModeHauntedBallBeam", RumbleOption.Tactical => "ItemsModeSelection", RumbleOption.BatmanRumble => "ItemsMode_BM", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapBoostStrength(BoostStrengthOption option) => @@ -178,7 +178,7 @@ private static string MapBoostStrength(BoostStrengthOption option) => BoostStrengthOption.Two => "BoostMultiplier2x", BoostStrengthOption.Five => "BoostMultiplier5x", BoostStrengthOption.Ten => "BoostMultiplier10x", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapGravity(GravityOption option) => @@ -189,7 +189,7 @@ private static string MapGravity(GravityOption option) => GravityOption.High => "HighGravity", GravityOption.Super_High => "SuperGravity", GravityOption.Reverse => "ReverseGravity", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapDemolish(DemolishOption option) => @@ -200,7 +200,7 @@ private static string MapDemolish(DemolishOption option) => DemolishOption.Friendly_Fire => "DemolishAll", DemolishOption.On_Contact => "AlwaysDemolishOpposing", DemolishOption.On_Contact_FF => "AlwaysDemolish", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapRespawnTime(RespawnTimeOption option) => @@ -210,7 +210,7 @@ private static string MapRespawnTime(RespawnTimeOption option) => RespawnTimeOption.Two_Seconds => "TwoSecondsRespawn", RespawnTimeOption.One_Second => "OneSecondsRespawn", RespawnTimeOption.Disable_Goal_Reset => "DisableGoalDelay", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapMaxTime(MaxTimeOption option) => @@ -218,7 +218,7 @@ private static string MapMaxTime(MaxTimeOption option) => { MaxTimeOption.Default => "", MaxTimeOption.Eleven_Minutes => "MaxTime11Minutes", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapGameEvent(GameEventOption option) => @@ -227,7 +227,7 @@ private static string MapGameEvent(GameEventOption option) => GameEventOption.Default => "", GameEventOption.Rugby => "RugbyGameEventRules", GameEventOption.Haunted => "HauntedGameEventRules", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string MapAudio(AudioOption option) => @@ -235,7 +235,7 @@ private static string MapAudio(AudioOption option) => { AudioOption.Default => "", AudioOption.Haunted => "HauntedAudio", - _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) + _ => throw new ArgumentOutOfRangeException(nameof(option), option, null), }; private static string GetOption(string option) diff --git a/RLBotCS/Conversion/FlatToModel.cs b/RLBotCS/Conversion/FlatToModel.cs index 474fb7b..af32b50 100644 --- a/RLBotCS/Conversion/FlatToModel.cs +++ b/RLBotCS/Conversion/FlatToModel.cs @@ -42,13 +42,12 @@ GameState gameState ) => relative?.Value switch { - rlbot.flat.CarAnchorT { Index: var index, Local: var local } - => new RelativeAnchor( - ToVectorFromT(local), - gameState.PlayerMapping.ActorIdFromPlayerIndex(index) ?? 0 - ), - rlbot.flat.BallAnchorT { Index: var index, Local: var local } - => new RelativeAnchor( + rlbot.flat.CarAnchorT { Index: var index, Local: var local } => new RelativeAnchor( + ToVectorFromT(local), + gameState.PlayerMapping.ActorIdFromPlayerIndex(index) ?? 0 + ), + rlbot.flat.BallAnchorT { Index: var index, Local: var local } => + new RelativeAnchor( ToVectorFromT(local), gameState.GetBallActorIdFromIndex(index) ?? 0 ), @@ -76,18 +75,17 @@ internal static Loadout ToLoadout(rlbot.flat.PlayerLoadoutT l, uint team) var lp = l.LoadoutPaint; - LoadoutPaint loadoutPaint = - new() - { - CarPaintId = (byte)lp.CarPaintId, - DecalPaintId = (byte)lp.DecalPaintId, - WheelsPaintId = (byte)lp.WheelsPaintId, - BoostPaintId = (byte)lp.BoostPaintId, - AntennaPaintId = (byte)lp.AntennaPaintId, - HatPaintId = (byte)lp.HatPaintId, - TrailsPaintId = (byte)lp.TrailsPaintId, - GoalExplosionPaintId = (byte)lp.GoalExplosionPaintId - }; + LoadoutPaint loadoutPaint = new() + { + CarPaintId = (byte)lp.CarPaintId, + DecalPaintId = (byte)lp.DecalPaintId, + WheelsPaintId = (byte)lp.WheelsPaintId, + BoostPaintId = (byte)lp.BoostPaintId, + AntennaPaintId = (byte)lp.AntennaPaintId, + HatPaintId = (byte)lp.HatPaintId, + TrailsPaintId = (byte)lp.TrailsPaintId, + GoalExplosionPaintId = (byte)lp.GoalExplosionPaintId, + }; return new Loadout { @@ -104,7 +102,7 @@ internal static Loadout ToLoadout(rlbot.flat.PlayerLoadoutT l, uint team) WheelsId = (ushort)l.WheelsId, LoadoutPaint = loadoutPaint, PrimaryColorLookup = primaryColor, - SecondaryColorLookup = secondaryColor + SecondaryColorLookup = secondaryColor, }; } @@ -114,13 +112,12 @@ Vector3 defaultVec ) => partVec switch { - not null - => new Vector3( - partVec.X?.Val ?? defaultVec.X, - partVec.Y?.Val ?? defaultVec.Y, - partVec.Z?.Val ?? defaultVec.Z - ), - _ => defaultVec + not null => new Vector3( + partVec.X?.Val ?? defaultVec.X, + partVec.Y?.Val ?? defaultVec.Y, + partVec.Z?.Val ?? defaultVec.Z + ), + _ => defaultVec, }; internal static Rotator DesiredToRotator( @@ -129,13 +126,12 @@ Rotator defaultRot ) => partRot switch { - not null - => new Rotator( - partRot.Pitch?.Val ?? defaultRot.Pitch, - partRot.Yaw?.Val ?? defaultRot.Yaw, - partRot.Roll?.Val ?? defaultRot.Roll - ), - _ => defaultRot + not null => new Rotator( + partRot.Pitch?.Val ?? defaultRot.Pitch, + partRot.Yaw?.Val ?? defaultRot.Yaw, + partRot.Roll?.Val ?? defaultRot.Roll + ), + _ => defaultRot, }; internal static Physics DesiredToPhysics(rlbot.flat.DesiredPhysicsT p, Physics defaultP) => diff --git a/RLBotCS/Conversion/GameStateToFlat.cs b/RLBotCS/Conversion/GameStateToFlat.cs index 9c30a95..44c8780 100644 --- a/RLBotCS/Conversion/GameStateToFlat.cs +++ b/RLBotCS/Conversion/GameStateToFlat.cs @@ -17,7 +17,7 @@ private static Vector3T ToVector3T(this Bridge.Models.Phys.Vector3 vec) => { X = vec.X, Y = vec.Y, - Z = vec.Z + Z = vec.Z, }; private static RotatorT ToRotatorT(this Bridge.Models.Phys.Rotator vec) => @@ -25,7 +25,7 @@ private static RotatorT ToRotatorT(this Bridge.Models.Phys.Rotator vec) => { Pitch = vec.Pitch, Yaw = vec.Yaw, - Roll = vec.Roll + Roll = vec.Roll, }; internal static ushort? GetBallActorIdFromIndex(this GameState gameState, uint index) @@ -46,42 +46,38 @@ public static GamePacketT ToFlatBuffers(this GameState gameState) foreach (var ball in gameState.Balls.Values) { // Create the ball info - PhysicsT ballPhysics = - new() - { - Location = ball.Physics.Location.ToVector3T(), - Rotation = ball.Physics.Rotation.ToRotatorT(), - Velocity = ball.Physics.Velocity.ToVector3T(), - AngularVelocity = ball.Physics.AngularVelocity.ToVector3T() - }; + PhysicsT ballPhysics = new() + { + Location = ball.Physics.Location.ToVector3T(), + Rotation = ball.Physics.Rotation.ToRotatorT(), + Velocity = ball.Physics.Velocity.ToVector3T(), + AngularVelocity = ball.Physics.AngularVelocity.ToVector3T(), + }; CollisionShapeUnion collisionShape = ball.Shape switch { - ICollisionShape.Box boxShape - => CollisionShapeUnion.FromBoxShape( - new() - { - Length = boxShape.Length, - Width = boxShape.Width, - Height = boxShape.Height - } - ), - ICollisionShape.Sphere sphereShape - => CollisionShapeUnion.FromSphereShape( - new() { Diameter = sphereShape.Diameter } - ), - ICollisionShape.Cylinder cylinderShape - => CollisionShapeUnion.FromCylinderShape( + ICollisionShape.Box boxShape => CollisionShapeUnion.FromBoxShape( + new() + { + Length = boxShape.Length, + Width = boxShape.Width, + Height = boxShape.Height, + } + ), + ICollisionShape.Sphere sphereShape => CollisionShapeUnion.FromSphereShape( + new() { Diameter = sphereShape.Diameter } + ), + ICollisionShape.Cylinder cylinderShape => + CollisionShapeUnion.FromCylinderShape( new() { Diameter = cylinderShape.Diameter, - Height = cylinderShape.Height + Height = cylinderShape.Height, } ), - _ - => CollisionShapeUnion.FromSphereShape( - new SphereShapeT { Diameter = 91.25f * 2 } - ) + _ => CollisionShapeUnion.FromSphereShape( + new SphereShapeT { Diameter = 91.25f * 2 } + ), }; balls.Add(new() { Physics = ballPhysics, Shape = collisionShape }); @@ -97,34 +93,35 @@ ICollisionShape.Cylinder cylinderShape GameStatus.Replay => rlbot.flat.GameStatus.Replay, GameStatus.Paused => rlbot.flat.GameStatus.Paused, GameStatus.Ended => rlbot.flat.GameStatus.Ended, - _ => rlbot.flat.GameStatus.Inactive + _ => rlbot.flat.GameStatus.Inactive, }; - GameInfoT gameInfo = - new() - { - SecondsElapsed = gameState.SecondsElapsed, - GameTimeRemaining = gameState.GameTimeRemaining, - IsOvertime = gameState.IsOvertime, - IsUnlimitedTime = gameState.MatchLength == Bridge.Packet.MatchLength.Unlimited, - GameStatus = gameStatus, - WorldGravityZ = gameState.WorldGravityZ, - GameSpeed = gameState.GameSpeed, - FrameNum = gameState.FrameNum - }; + GameInfoT gameInfo = new() + { + SecondsElapsed = gameState.SecondsElapsed, + GameTimeRemaining = gameState.GameTimeRemaining, + IsOvertime = gameState.IsOvertime, + IsUnlimitedTime = gameState.MatchLength == Bridge.Packet.MatchLength.Unlimited, + GameStatus = gameStatus, + WorldGravityZ = gameState.WorldGravityZ, + GameSpeed = gameState.GameSpeed, + FrameNum = gameState.FrameNum, + }; List teams = [ new() { TeamIndex = 0, Score = gameState.TeamScores.blue }, - new() { TeamIndex = 1, Score = gameState.TeamScores.orange } + new() { TeamIndex = 1, Score = gameState.TeamScores.orange }, ]; List boostStates = gameState .BoostPads.Values.OrderBy(boost => boost.SpawnPosition.Y) .ThenBy(boost => boost.SpawnPosition.X) - .Select( - boost => new BoostPadStateT { IsActive = boost.IsActive, Timer = boost.Timer } - ) + .Select(boost => new BoostPadStateT + { + IsActive = boost.IsActive, + Timer = boost.Timer, + }) .ToList(); List players = new(gameState.GameCars.Count); @@ -137,7 +134,7 @@ ICollisionShape.Cylinder cylinderShape CarState.DoubleJumping => AirState.DoubleJumping, CarState.Dodging => AirState.Dodging, CarState.InAir => AirState.InAir, - _ => AirState.OnGround + _ => AirState.OnGround, }; TouchT? lastTouch = null; @@ -158,7 +155,7 @@ ICollisionShape.Cylinder cylinderShape Location = car.Physics.Location.ToVector3T(), Rotation = car.Physics.Rotation.ToRotatorT(), Velocity = car.Physics.Velocity.ToVector3T(), - AngularVelocity = car.Physics.AngularVelocity.ToVector3T() + AngularVelocity = car.Physics.AngularVelocity.ToVector3T(), }, LatestTouch = lastTouch, AirState = airState, @@ -178,13 +175,13 @@ ICollisionShape.Cylinder cylinderShape Assists = car.ScoreInfo.Assists, Saves = car.ScoreInfo.Saves, Shots = car.ScoreInfo.Shots, - Demolitions = car.ScoreInfo.Demolitions + Demolitions = car.ScoreInfo.Demolitions, }, Hitbox = new() { Length = car.Hitbox.Length, Width = car.Hitbox.Width, - Height = car.Hitbox.Height + Height = car.Hitbox.Height, }, HitboxOffset = car.HitboxOffset.ToVector3T(), Accolades = car.Accolades, @@ -197,7 +194,7 @@ ICollisionShape.Cylinder cylinderShape Roll = car.LastInput.Roll, Jump = car.LastInput.Jump, Boost = car.LastInput.Boost, - Handbrake = car.LastInput.Handbrake + Handbrake = car.LastInput.Handbrake, }, LastSpectated = car.LastSpectated, HasJumped = car.HasJumped, @@ -215,7 +212,7 @@ ICollisionShape.Cylinder cylinderShape GameInfo = gameInfo, Teams = teams, BoostPads = boostStates, - Players = players + Players = players, }; } } diff --git a/RLBotCS/Main.cs b/RLBotCS/Main.cs index 62b288c..c6744c3 100644 --- a/RLBotCS/Main.cs +++ b/RLBotCS/Main.cs @@ -46,39 +46,41 @@ var serverChannel = Channel.CreateUnbounded(); var serverWriter = serverChannel.Writer; -Thread rlbotServer = - new(() => +Thread rlbotServer = new(() => +{ + MatchStarter matchStarter = new(bridgeWriter, gamePort, rlbotSocketsPort); + FlatBuffersServer flatBuffersServer = new( + rlbotSocketsPort, + serverChannel, + matchStarter, + bridgeWriter + ); + + try + { + flatBuffersServer.BlockingRun(); + } + finally { - MatchStarter matchStarter = new(bridgeWriter, gamePort, rlbotSocketsPort); - FlatBuffersServer flatBuffersServer = - new(rlbotSocketsPort, serverChannel, matchStarter, bridgeWriter); - - try - { - flatBuffersServer.BlockingRun(); - } - finally - { - flatBuffersServer.Cleanup(); - } - }); + flatBuffersServer.Cleanup(); + } +}); rlbotServer.Start(); -Thread bridgeHandler = - new(() => +Thread bridgeHandler = new(() => +{ + TcpMessenger tcpMessenger = new(gamePort); + BridgeHandler bridgeHandler = new(serverWriter, bridgeChannel.Reader, tcpMessenger); + + try + { + bridgeHandler.BlockingRun(); + } + finally { - TcpMessenger tcpMessenger = new(gamePort); - BridgeHandler bridgeHandler = new(serverWriter, bridgeChannel.Reader, tcpMessenger); - - try - { - bridgeHandler.BlockingRun(); - } - finally - { - bridgeHandler.Cleanup(); - } - }); + bridgeHandler.Cleanup(); + } +}); bridgeHandler.Start(); // Block until everything properly shuts down diff --git a/RLBotCS/ManagerTools/AgentReservation.cs b/RLBotCS/ManagerTools/AgentReservation.cs index 265dc3b..c58fae3 100644 --- a/RLBotCS/ManagerTools/AgentReservation.cs +++ b/RLBotCS/ManagerTools/AgentReservation.cs @@ -55,8 +55,8 @@ public void SetPlayers(MatchSettingsT matchSettings) public (PlayerIdPair, uint)? ReservePlayer(string agentId) { - PlayerMetadata? player = _knownPlayers.FirstOrDefault( - playerMetadata => !playerMetadata.IsReserved && playerMetadata.AgentId == agentId + PlayerMetadata? player = _knownPlayers.FirstOrDefault(playerMetadata => + !playerMetadata.IsReserved && playerMetadata.AgentId == agentId ); if (player != null) { @@ -83,11 +83,10 @@ public void SetPlayers(MatchSettingsT matchSettings) // find other players in the same group & team - var otherPlayers = _knownPlayers.Where( - playerMetadata => - !playerMetadata.IsReserved - && playerMetadata.AgentId == agentId - && playerMetadata.Team == team + var otherPlayers = _knownPlayers.Where(playerMetadata => + !playerMetadata.IsReserved + && playerMetadata.AgentId == agentId + && playerMetadata.Team == team ); foreach (var playerMetadata in otherPlayers) @@ -97,7 +96,7 @@ public void SetPlayers(MatchSettingsT matchSettings) new PlayerIdPair { Index = playerMetadata.Index, - SpawnId = playerMetadata.SpawnId + SpawnId = playerMetadata.SpawnId, } ); } @@ -112,11 +111,10 @@ public void UnreservePlayers(uint team, List players) { foreach (var player in players) { - PlayerMetadata? playerMetadata = _knownPlayers.FirstOrDefault( - playerMetadata => - playerMetadata.Team == team - && playerMetadata.Index == player.Index - && playerMetadata.SpawnId == player.SpawnId + PlayerMetadata? playerMetadata = _knownPlayers.FirstOrDefault(playerMetadata => + playerMetadata.Team == team + && playerMetadata.Index == player.Index + && playerMetadata.SpawnId == player.SpawnId ); if (playerMetadata != null) diff --git a/RLBotCS/ManagerTools/BallPredictor.cs b/RLBotCS/ManagerTools/BallPredictor.cs index dad60f4..c95eb91 100644 --- a/RLBotCS/ManagerTools/BallPredictor.cs +++ b/RLBotCS/ManagerTools/BallPredictor.cs @@ -68,7 +68,7 @@ private static Vector3T ToVector3T(Vec3 vec) => { X = vec.X, Y = vec.Y, - Z = vec.Z + Z = vec.Z, }; public static void SetMode(PredictionMode mode) @@ -114,20 +114,21 @@ public static BallPredictionT Generate( (TouchT, uint)? lastTouch ) { - BallSlice ball = - new() - { - Time = currentTime, - Location = ToVec3(currentBall.Physics.Location), - LinearVelocity = ToVec3(currentBall.Physics.Velocity), - AngularVelocity = ToVec3(currentBall.Physics.AngularVelocity) - }; + BallSlice ball = new() + { + Time = currentTime, + Location = ToVec3(currentBall.Physics.Location), + LinearVelocity = ToVec3(currentBall.Physics.Velocity), + AngularVelocity = ToVec3(currentBall.Physics.AngularVelocity), + }; const ushort numSeconds = 6; const ushort numSlices = numSeconds * 120; - BallPredictionT ballPrediction = - new() { Slices = new List(numSlices) }; + BallPredictionT ballPrediction = new() + { + Slices = new List(numSlices), + }; if (mode == PredictionMode.Heatseeker) { @@ -161,17 +162,16 @@ public static BallPredictionT Generate( { BallSlice rawSlice = ballSlices[i]; - PredictionSliceT slice = - new() + PredictionSliceT slice = new() + { + GameSeconds = rawSlice.Time, + Physics = new PhysicsT { - GameSeconds = rawSlice.Time, - Physics = new PhysicsT - { - Location = ToVector3T(rawSlice.Location), - Velocity = ToVector3T(rawSlice.LinearVelocity), - AngularVelocity = ToVector3T(rawSlice.AngularVelocity) - } - }; + Location = ToVector3T(rawSlice.Location), + Velocity = ToVector3T(rawSlice.LinearVelocity), + AngularVelocity = ToVector3T(rawSlice.AngularVelocity), + }, + }; ballPrediction.Slices.Add(slice); } diff --git a/RLBotCS/ManagerTools/ConfigParser.cs b/RLBotCS/ManagerTools/ConfigParser.cs index 395640e..04a5114 100644 --- a/RLBotCS/ManagerTools/ConfigParser.cs +++ b/RLBotCS/ManagerTools/ConfigParser.cs @@ -196,17 +196,16 @@ List missingValues string agentId = ParseString(scriptSettings, "agent_id", missingValues) ?? $"script/{name}"; - ScriptConfigurationT scriptConfig = - new() - { - Name = name, - Location = CombinePaths( - tomlParent, - ParseString(scriptSettings, "location", missingValues) ?? "" - ), - RunCommand = GetRunCommand(scriptSettings, missingValues), - AgentId = agentId - }; + ScriptConfigurationT scriptConfig = new() + { + Name = name, + Location = CombinePaths( + tomlParent, + ParseString(scriptSettings, "location", missingValues) ?? "" + ), + RunCommand = GetRunCommand(scriptSettings, missingValues), + AgentId = agentId, + }; return scriptConfig; } @@ -217,39 +216,37 @@ List missingValues ) => ParseEnum(table, "type", PlayerClass.RLBot, missingValues) switch { - PlayerClass.RLBot - => GetBotConfig( - table, - PlayerClassUnion.FromRLBot(new RLBotT()), - matchConfigPath, - missingValues - ), - PlayerClass.Human - => GetHumanConfig( - table, - PlayerClassUnion.FromHuman(new HumanT()), - missingValues - ), - PlayerClass.Psyonix - => GetPsyonixConfig( - table, - PlayerClassUnion.FromPsyonix( - new PsyonixT - { - BotSkill = ParseEnum( - table, - "skill", - PsyonixSkill.AllStar, - missingValues - ) - } - ), - matchConfigPath, - missingValues + PlayerClass.RLBot => GetBotConfig( + table, + PlayerClassUnion.FromRLBot(new RLBotT()), + matchConfigPath, + missingValues + ), + PlayerClass.Human => GetHumanConfig( + table, + PlayerClassUnion.FromHuman(new HumanT()), + missingValues + ), + PlayerClass.Psyonix => GetPsyonixConfig( + table, + PlayerClassUnion.FromPsyonix( + new PsyonixT + { + BotSkill = ParseEnum( + table, + "skill", + PsyonixSkill.AllStar, + missingValues + ), + } ), - PlayerClass.PartyMember - => throw new NotImplementedException("PartyMember not implemented"), - _ => throw new NotImplementedException("Unimplemented PlayerClass type") + matchConfigPath, + missingValues + ), + PlayerClass.PartyMember => throw new NotImplementedException( + "PartyMember not implemented" + ), + _ => throw new NotImplementedException("Unimplemented PlayerClass type"), }; private static PlayerConfigurationT GetHumanConfig( @@ -264,7 +261,7 @@ List missingValues Name = "Human", RootDir = "", RunCommand = "", - AgentId = "" + AgentId = "", }; private static PlayerConfigurationT GetPsyonixConfig( @@ -329,7 +326,7 @@ List missingValues RootDir = rootDir, RunCommand = runCommand, Loadout = loadout, - AgentId = agentId + AgentId = agentId, }; } @@ -452,7 +449,7 @@ List missingValues missingValues ), Hivemind = ParseBool(playerSettings, "hivemind", false, missingValues), - AgentId = agentId + AgentId = agentId, }; } @@ -655,7 +652,7 @@ public static MatchSettingsT GetMatchSettings(string path) Freeplay = ParseBool(matchTable, "freeplay", false, missingValues["match"]), MutatorSettings = GetMutatorSettings(mutatorTable, missingValues["mutators"]), PlayerConfigurations = playerConfigs, - ScriptConfigurations = scriptConfigs + ScriptConfigurations = scriptConfigs, }; if (missingValues.Count > 0) diff --git a/RLBotCS/ManagerTools/LaunchManager.cs b/RLBotCS/ManagerTools/LaunchManager.cs index 4f89201..8628b4e 100644 --- a/RLBotCS/ManagerTools/LaunchManager.cs +++ b/RLBotCS/ManagerTools/LaunchManager.cs @@ -88,7 +88,7 @@ private static string[] GetIdealArgs(int gamePort) => "-rlbot", $"RLBot_ControllerURL=127.0.0.1:{gamePort}", "RLBot_PacketSendRate=240", - "-nomovie" + "-nomovie", ]; private static List ParseCommand(string command) diff --git a/RLBotCS/ManagerTools/MatchStarter.cs b/RLBotCS/ManagerTools/MatchStarter.cs index 5e52be9..4051233 100644 --- a/RLBotCS/ManagerTools/MatchStarter.cs +++ b/RLBotCS/ManagerTools/MatchStarter.cs @@ -207,9 +207,9 @@ private void LoadMatch(MatchSettingsT matchSettings) var shouldSpawnNewMap = matchSettings.ExistingMatchBehavior switch { ExistingMatchBehavior.Continue_And_Spawn => false, - ExistingMatchBehavior.Restart_If_Different - => MatchEnded || IsDifferentFromLast(matchSettings), - _ => true + ExistingMatchBehavior.Restart_If_Different => MatchEnded + || IsDifferentFromLast(matchSettings), + _ => true, }; _needsSpawnCars = true; @@ -361,7 +361,7 @@ private bool SpawnCars(MatchSettingsT matchSettings, bool force = false) PsyonixSkill.Beginner => BotSkill.Intro, PsyonixSkill.Rookie => BotSkill.Easy, PsyonixSkill.Pro => BotSkill.Medium, - _ => BotSkill.Hard + _ => BotSkill.Hard, }; bridge.TryWrite( diff --git a/RLBotCS/ManagerTools/PerfMonitor.cs b/RLBotCS/ManagerTools/PerfMonitor.cs index 67800a9..d25b02c 100644 --- a/RLBotCS/ManagerTools/PerfMonitor.cs +++ b/RLBotCS/ManagerTools/PerfMonitor.cs @@ -87,7 +87,7 @@ public void RenderSummary(Rendering rendering, GameState gameState, float deltaT var renderMessages = new List() { - new RenderMessageT() { Variety = RenderTypeUnion.FromString2D(renderText), }, + new RenderMessageT() { Variety = RenderTypeUnion.FromString2D(renderText) }, }; if (shouldRender) diff --git a/RLBotCS/ManagerTools/QuickChat.cs b/RLBotCS/ManagerTools/QuickChat.cs index 73711f9..3020be5 100644 --- a/RLBotCS/ManagerTools/QuickChat.cs +++ b/RLBotCS/ManagerTools/QuickChat.cs @@ -11,30 +11,27 @@ public class QuickChat private const int MaxDisplayMessages = 8; private const int ChatDisplaySeconds = 5; - private static readonly ColorT OrangeColor = - new() - { - A = 255, - R = 255, - G = 200, - B = 80 - }; - private static readonly ColorT BlueColor = - new() - { - A = 255, - R = 120, - G = 200, - B = 255 - }; - private static readonly ColorT BackgroundColor = - new() - { - A = 150, - R = 0, - G = 0, - B = 0 - }; + private static readonly ColorT OrangeColor = new() + { + A = 255, + R = 255, + G = 200, + B = 80, + }; + private static readonly ColorT BlueColor = new() + { + A = 255, + R = 120, + G = 200, + B = 255, + }; + private static readonly ColorT BackgroundColor = new() + { + A = 150, + R = 0, + G = 0, + B = 0, + }; private readonly LinkedList<(float, MatchCommT)> _chats = new(); private bool _hasUpdate = false; @@ -78,21 +75,20 @@ public void RenderChats(Rendering rendering, GameState gameState) { var textColor = chat.Item2.Team == 0 ? BlueColor : OrangeColor; - String2DT message = - new() - { - Text = chat.Item2.Display, - X = 10f / Rendering.ResolutionWidthPixels, - Y = yVal / Rendering.ResolutionHeightPixels, - Scale = 1, - Foreground = textColor, - Background = BackgroundColor, - HAlign = TextHAlign.Left, - VAlign = TextVAlign.Top, - }; + String2DT message = new() + { + Text = chat.Item2.Display, + X = 10f / Rendering.ResolutionWidthPixels, + Y = yVal / Rendering.ResolutionHeightPixels, + Scale = 1, + Foreground = textColor, + Background = BackgroundColor, + HAlign = TextHAlign.Left, + VAlign = TextVAlign.Top, + }; renderMessages.Add( - new RenderMessageT() { Variety = RenderTypeUnion.FromString2D(message), } + new RenderMessageT() { Variety = RenderTypeUnion.FromString2D(message) } ); yVal += Rendering.FontHeightPixels; diff --git a/RLBotCS/ManagerTools/Rendering.cs b/RLBotCS/ManagerTools/Rendering.cs index 21e132b..08af4eb 100644 --- a/RLBotCS/ManagerTools/Rendering.cs +++ b/RLBotCS/ManagerTools/Rendering.cs @@ -25,14 +25,14 @@ public class Rendering(TcpMessenger tcpMessenger) private ushort RenderItem(RenderTypeUnion renderItem, GameState gameState) => renderItem.Value switch { - Line3DT { Start: var start, End: var end, Color: var color } - => _renderingSender.AddLine3D( + Line3DT { Start: var start, End: var end, Color: var color } => + _renderingSender.AddLine3D( FlatToModel.ToRenderAnchor(start, gameState), FlatToModel.ToRenderAnchor(end, gameState), FlatToModel.ToColor(color) ), - PolyLine3DT { Points: var points, Color: var color } - => _renderingSender.AddLine3DSeries( + PolyLine3DT { Points: var points, Color: var color } => + _renderingSender.AddLine3DSeries( points.Select(FlatToModel.ToVectorFromT).ToList(), FlatToModel.ToColor(color) ), @@ -46,17 +46,16 @@ private ushort RenderItem(RenderTypeUnion renderItem, GameState gameState) => HAlign: var hAlign, VAlign: var vAlign, Scale: var scale - } - => _renderingSender.AddText2D( - text, - x, - y, - FlatToModel.ToColor(foreground), - FlatToModel.ToColor(background), - (byte)hAlign, - (byte)vAlign, - scale - ), + } => _renderingSender.AddText2D( + text, + x, + y, + FlatToModel.ToColor(foreground), + FlatToModel.ToColor(background), + (byte)hAlign, + (byte)vAlign, + scale + ), String3DT { Text: var text, @@ -66,16 +65,15 @@ private ushort RenderItem(RenderTypeUnion renderItem, GameState gameState) => HAlign: var hAlign, VAlign: var vAlign, Scale: var scale - } - => _renderingSender.AddText3D( - text, - FlatToModel.ToRenderAnchor(anchor, gameState), - FlatToModel.ToColor(foreground), - FlatToModel.ToColor(background), - (byte)hAlign, - (byte)vAlign, - scale - ), + } => _renderingSender.AddText3D( + text, + FlatToModel.ToRenderAnchor(anchor, gameState), + FlatToModel.ToColor(foreground), + FlatToModel.ToColor(background), + (byte)hAlign, + (byte)vAlign, + scale + ), Rect2DT rect2Dt => SendRect2D(rect2Dt), Rect3DT rect3Dt => SendRect3D(rect3Dt, gameState), _ => throw new NotImplementedException("Unknown RenderMessage"), diff --git a/RLBotCS/Server/BridgeMessage.cs b/RLBotCS/Server/BridgeMessage.cs index b260c11..d013c23 100644 --- a/RLBotCS/Server/BridgeMessage.cs +++ b/RLBotCS/Server/BridgeMessage.cs @@ -25,12 +25,11 @@ public void HandleMessage(BridgeContext context) if (actorId is ushort actorIdValue) { - Bridge.Models.Control.PlayerInput playerInput = - new() - { - ActorId = actorIdValue, - CarInput = FlatToModel.ToCarInput(PlayerInput.ControllerState) - }; + Bridge.Models.Control.PlayerInput playerInput = new() + { + ActorId = actorIdValue, + CarInput = FlatToModel.ToCarInput(PlayerInput.ControllerState), + }; context.PlayerInputSender.SendPlayerInput(playerInput); } else if ( @@ -64,7 +63,7 @@ public void HandleMessage(BridgeContext context) SpawnId = Config.SpawnId, DesiredPlayerIndex = DesiredIndex, IsBot = false, - IsCustomBot = false + IsCustomBot = false, } ); } @@ -106,7 +105,7 @@ public void HandleMessage(BridgeContext context) SpawnId = Config.SpawnId, DesiredPlayerIndex = DesiredIndex, IsCustomBot = IsCustomBot, - IsBot = true + IsBot = true, } ); } @@ -208,12 +207,11 @@ public void HandleMessage(BridgeContext context) MatchLength.Ten_Minutes => 10 * 60, MatchLength.Twenty_Minutes => 20 * 60, MatchLength.Unlimited => 0, - _ - => throw new ArgumentOutOfRangeException( - nameof(MutatorSettings.MatchLength), - MutatorSettings.MatchLength, - null - ) + _ => throw new ArgumentOutOfRangeException( + nameof(MutatorSettings.MatchLength), + MutatorSettings.MatchLength, + null + ), }; context.GameState.MatchLength = MutatorSettings.MatchLength switch @@ -222,12 +220,11 @@ public void HandleMessage(BridgeContext context) MatchLength.Ten_Minutes => Bridge.Packet.MatchLength.TenMinutes, MatchLength.Twenty_Minutes => Bridge.Packet.MatchLength.TwentyMinutes, MatchLength.Unlimited => Bridge.Packet.MatchLength.Unlimited, - _ - => throw new ArgumentOutOfRangeException( - nameof(MutatorSettings.MatchLength), - MutatorSettings.MatchLength, - null - ) + _ => throw new ArgumentOutOfRangeException( + nameof(MutatorSettings.MatchLength), + MutatorSettings.MatchLength, + null + ), }; context.GameState.RespawnTime = MutatorSettings.RespawnTimeOption switch @@ -236,12 +233,11 @@ public void HandleMessage(BridgeContext context) RespawnTimeOption.Two_Seconds => 2, RespawnTimeOption.One_Second => 1, RespawnTimeOption.Disable_Goal_Reset => 3, - _ - => throw new ArgumentOutOfRangeException( - nameof(MutatorSettings.RespawnTimeOption), - MutatorSettings.RespawnTimeOption, - null - ) + _ => throw new ArgumentOutOfRangeException( + nameof(MutatorSettings.RespawnTimeOption), + MutatorSettings.RespawnTimeOption, + null + ), }; } } diff --git a/RLBotCS/Server/FlatBuffersServer.cs b/RLBotCS/Server/FlatBuffersServer.cs index 1aaeca9..3c146e4 100644 --- a/RLBotCS/Server/FlatBuffersServer.cs +++ b/RLBotCS/Server/FlatBuffersServer.cs @@ -13,11 +13,10 @@ internal class FlatBuffersServer( ChannelWriter bridge ) { - private readonly ServerContext _context = - new(incomingMessages, matchStarter, bridge) - { - Server = new TcpListener(new(new byte[] { 0, 0, 0, 0 }), rlbotPort) - }; + private readonly ServerContext _context = new(incomingMessages, matchStarter, bridge) + { + Server = new TcpListener(new(new byte[] { 0, 0, 0, 0 }), rlbotPort), + }; private void AddSession(TcpClient client) { @@ -26,37 +25,35 @@ private void AddSession(TcpClient client) int clientId = client.Client.Handle.ToInt32(); - Thread sessionThread = - new(() => + Thread sessionThread = new(() => + { + FlatBuffersSession session = new( + client, + clientId, + sessionChannel, + _context.IncomingMessagesWriter, + _context.Bridge, + _context.RenderingIsEnabled, + _context.StateSettingIsEnabled + ); + + try { - FlatBuffersSession session = - new( - client, - clientId, - sessionChannel, - _context.IncomingMessagesWriter, - _context.Bridge, - _context.RenderingIsEnabled, - _context.StateSettingIsEnabled - ); - - try - { - session.BlockingRun(); - } - catch (IOException) - { - _context.Logger.LogWarning("Session suddenly terminated the connection?"); - } - catch (Exception e) - { - _context.Logger.LogError($"Error in session: {e}"); - } - finally - { - session.Cleanup(); - } - }); + session.BlockingRun(); + } + catch (IOException) + { + _context.Logger.LogWarning("Session suddenly terminated the connection?"); + } + catch (Exception e) + { + _context.Logger.LogError($"Error in session: {e}"); + } + finally + { + session.Cleanup(); + } + }); sessionThread.Start(); _context.Sessions.Add(clientId, (sessionChannel.Writer, sessionThread, 0)); diff --git a/RLBotCS/Server/FlatBuffersSession.cs b/RLBotCS/Server/FlatBuffersSession.cs index a20ee09..e4fd315 100644 --- a/RLBotCS/Server/FlatBuffersSession.cs +++ b/RLBotCS/Server/FlatBuffersSession.cs @@ -113,8 +113,8 @@ await _rlbotServer.WriteAsync( // ensure the provided index is a bot we control, // and map the index to the spawn id - PlayerIdPair? idPairs = _playerIdPairs.FirstOrDefault( - idPair => idPair.Index == setLoadout.Index + PlayerIdPair? idPairs = _playerIdPairs.FirstOrDefault(idPair => + idPair.Index == setLoadout.Index ); if (idPairs is PlayerIdPair info && info.SpawnId is int spawnId) @@ -158,8 +158,8 @@ await _rlbotServer.WriteAsync( // ensure the provided index is a bot we control if ( - !_playerIdPairs.Any( - playerInfo => playerInfo.Index == playerInputMsg.PlayerIndex + !_playerIdPairs.Any(playerInfo => + playerInfo.Index == playerInputMsg.PlayerIndex ) ) break; @@ -176,8 +176,8 @@ await _rlbotServer.WriteAsync( // ensure the provided index is a bot we control, // and map the index to the spawn id - PlayerIdPair? playerIdPair = _playerIdPairs.FirstOrDefault( - idPair => idPair.Index == matchComms.Index + PlayerIdPair? playerIdPair = _playerIdPairs.FirstOrDefault(idPair => + idPair.Index == matchComms.Index ); if (playerIdPair is PlayerIdPair pInfo && pInfo.SpawnId is int pSpawnId) @@ -288,20 +288,19 @@ await SendPayloadToClientAsync( _team = m.Team; _playerIdPairs = m.IdMaps; - List controllables = - new( - _playerIdPairs.Select( - playerInfo => - new ControllableInfoT() - { - Index = playerInfo.Index, - SpawnId = playerInfo.SpawnId, - } - ) - ); - - ControllableTeamInfoT playerMappings = - new() { Team = m.Team, Controllables = controllables, }; + List controllables = new( + _playerIdPairs.Select(playerInfo => new ControllableInfoT() + { + Index = playerInfo.Index, + SpawnId = playerInfo.SpawnId, + }) + ); + + ControllableTeamInfoT playerMappings = new() + { + Team = m.Team, + Controllables = controllables, + }; _messageBuilder.Clear(); _messageBuilder.Finish( @@ -432,8 +431,11 @@ public void Cleanup() // try to politely close the connection try { - TypedPayload msg = - new() { Type = DataType.None, Payload = new ArraySegment([1]), }; + TypedPayload msg = new() + { + Type = DataType.None, + Payload = new ArraySegment([1]), + }; SendPayloadToClientAsync(msg).Wait(); } catch (Exception) { } diff --git a/RLBotCS/Server/FlatbuffersMessage/DistributeGameState.cs b/RLBotCS/Server/FlatbuffersMessage/DistributeGameState.cs index 9d5e8b9..e729678 100644 --- a/RLBotCS/Server/FlatbuffersMessage/DistributeGameState.cs +++ b/RLBotCS/Server/FlatbuffersMessage/DistributeGameState.cs @@ -20,7 +20,7 @@ private static void UpdateFieldInfo(ServerContext context, GameState gameState) context.FieldInfo = new FieldInfoT { BoostPads = new List(gameState.BoostPads.Count), - Goals = new List(gameState.Goals.Count) + Goals = new List(gameState.Goals.Count), }; foreach (GoalInfo goal in gameState.Goals) @@ -33,13 +33,13 @@ private static void UpdateFieldInfo(ServerContext context, GameState gameState) { X = goal.Location.X, Y = goal.Location.Y, - Z = goal.Location.Z + Z = goal.Location.Z, }, Direction = new Vector3T { X = goal.Direction.X, Y = goal.Direction.Y, - Z = goal.Direction.Z + Z = goal.Direction.Z, }, Width = goal.Width, Height = goal.Height, @@ -56,7 +56,7 @@ private static void UpdateFieldInfo(ServerContext context, GameState gameState) { X = boostPad.SpawnPosition.X, Y = boostPad.SpawnPosition.Y, - Z = boostPad.SpawnPosition.Z + Z = boostPad.SpawnPosition.Z, }, IsFullBoost = boostPad.IsFullBoost, } diff --git a/RLBotCS/Server/FlatbuffersMessage/IServerMessage.cs b/RLBotCS/Server/FlatbuffersMessage/IServerMessage.cs index 948fb5d..1607693 100644 --- a/RLBotCS/Server/FlatbuffersMessage/IServerMessage.cs +++ b/RLBotCS/Server/FlatbuffersMessage/IServerMessage.cs @@ -3,7 +3,7 @@ internal enum ServerAction { Continue, - Stop + Stop, } internal interface IServerMessage diff --git a/RLBotCS/Server/FlatbuffersMessage/SendMatchComm.cs b/RLBotCS/Server/FlatbuffersMessage/SendMatchComm.cs index ae9eabc..62e058b 100644 --- a/RLBotCS/Server/FlatbuffersMessage/SendMatchComm.cs +++ b/RLBotCS/Server/FlatbuffersMessage/SendMatchComm.cs @@ -28,8 +28,8 @@ public ServerAction Execute(ServerContext context) // team 0 is blue, and 1 is orange // but team 2 means only scripts (so, not players) should receive the message - var player = context.LastTickPacket.Players.Find( - player => player.SpawnId == spawnId + var player = context.LastTickPacket.Players.Find(player => + player.SpawnId == spawnId ); if (message.Message.Team == 2) { diff --git a/RLBotCS/Server/SocketSpecStreamReader.cs b/RLBotCS/Server/SocketSpecStreamReader.cs index 119477a..5b206f2 100644 --- a/RLBotCS/Server/SocketSpecStreamReader.cs +++ b/RLBotCS/Server/SocketSpecStreamReader.cs @@ -42,7 +42,7 @@ internal async IAsyncEnumerable ReadAllAsync() yield return new() { Type = dataType, - Payload = new(_payloadReader, 0, payloadSize) + Payload = new(_payloadReader, 0, payloadSize), }; } } diff --git a/RLBotCS/Types/DataType.cs b/RLBotCS/Types/DataType.cs index 31610f1..2bf5f5f 100644 --- a/RLBotCS/Types/DataType.cs +++ b/RLBotCS/Types/DataType.cs @@ -49,5 +49,5 @@ public enum DataType : ushort /// Indicates that a connection is ready to receive `GameTickPacket`s /// InitComplete, - ControllableTeamInfo + ControllableTeamInfo, } diff --git a/RLBotCS/Types/TypedPayload.cs b/RLBotCS/Types/TypedPayload.cs index d260db6..abd8f65 100644 --- a/RLBotCS/Types/TypedPayload.cs +++ b/RLBotCS/Types/TypedPayload.cs @@ -15,7 +15,7 @@ public static TypedPayload FromFlatBufferBuilder(DataType type, FlatBufferBuilde Payload = builder.DataBuffer.ToArraySegment( builder.DataBuffer.Position, builder.DataBuffer.Length - builder.DataBuffer.Position - ) + ), }; } } diff --git a/RLBotCSTests/FlatbufferTest.cs b/RLBotCSTests/FlatbufferTest.cs index 71ee45d..e5e087e 100644 --- a/RLBotCSTests/FlatbufferTest.cs +++ b/RLBotCSTests/FlatbufferTest.cs @@ -32,7 +32,7 @@ public static List RandomPlayerConfigurations() AgentId = RandomString(64), RootDir = RandomString(64), RunCommand = RandomString(64), - Loadout = new PlayerLoadoutT() { LoadoutPaint = new LoadoutPaintT(), }, + Loadout = new PlayerLoadoutT() { LoadoutPaint = new LoadoutPaintT() }, } ); } diff --git a/RLBotCSTests/GameState.cs b/RLBotCSTests/GameState.cs index fcabaa7..9b7f8d1 100644 --- a/RLBotCSTests/GameState.cs +++ b/RLBotCSTests/GameState.cs @@ -24,7 +24,7 @@ public void Test() new BoostPadInfo { SpawnPosition = new Bridge.Models.Phys.Vector3(1, 1, 0), - IsActive = true + IsActive = true, } ); @@ -33,7 +33,7 @@ public void Test() new BoostPadInfo { SpawnPosition = new Bridge.Models.Phys.Vector3(0, 0, 0), - IsActive = true + IsActive = true, } ); @@ -42,7 +42,7 @@ public void Test() new BoostPadInfo { SpawnPosition = new Bridge.Models.Phys.Vector3(0, 1, 0), - IsActive = true + IsActive = true, } ); diff --git a/RLBotCSTests/PlayerMappingTest.cs b/RLBotCSTests/PlayerMappingTest.cs index 5e3ab29..16d5f8c 100644 --- a/RLBotCSTests/PlayerMappingTest.cs +++ b/RLBotCSTests/PlayerMappingTest.cs @@ -29,7 +29,7 @@ public void TestSpawnProcess() AgentId = agentId, CommandId = commandId, DesiredPlayerIndex = desiredIndex, - IsBot = true + IsBot = true, }; // add pending spawn