From a0893b68c029009634f1567fd7e4fa295d907a79 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Fri, 23 Apr 2021 20:57:24 -0700 Subject: [PATCH] fix(core): Updates slice with range selectors (#583) - [X] Replaces Span slicing with range selection - [X] Replaces string slicing with range selection --- .../Packets/BenchmarkPacketBroadcast.cs | 4 +- .../Buffers/CircularBufferReaderTests.cs | 8 +- .../Buffers/CircularBufferWriterTests.cs | 8 +- .../Tests/Utility/StringHelperTests.cs | 4 +- Projects/Server/AssemblyHandler.cs | 2 +- Projects/Server/Buffers/CircularBuffer.cs | 2 +- .../Server/Buffers/CircularBufferReader.cs | 34 ++-- .../Server/Buffers/CircularBufferWriter.cs | 42 ++--- Projects/Server/Buffers/SpanReader.cs | 18 +-- Projects/Server/Buffers/SpanWriter.cs | 28 ++-- Projects/Server/Buffers/ValueStringBuilder.cs | 34 ++-- Projects/Server/ClientVersion.cs | 2 +- Projects/Server/Commands.cs | 6 +- Projects/Server/Items/Item.cs | 10 +- Projects/Server/Mobiles/Mobile.cs | 14 +- Projects/Server/Network/PacketUtilities.cs | 6 - .../Network/Packets/OutgoingItemPackets.cs | 2 +- .../Network/Packets/OutgoingMessagePackets.cs | 6 +- .../Network/Packets/OutgoingMobilePackets.cs | 2 +- .../Network/Packets/PacketContainerBuilder.cs | 10 +- Projects/Server/Serialization/BufferReader.cs | 2 +- Projects/Server/Serialization/BufferWriter.cs | 4 +- Projects/Server/Text/StringHelpers.cs | 22 +-- Projects/Server/Utilities/Utility.cs | 16 +- Projects/Server/World/World.cs | 4 +- .../Security/PBKDF2PasswordProtection.cs | 8 +- Projects/UOContent/Commands/Batch.cs | 4 +- .../Compilers/ConditionalCompiler.cs | 2 +- .../UOContent/Commands/Object Creation/Add.cs | 6 +- .../Commands/Object Creation/Decorate.cs | 151 +++++++++--------- .../Commands/Object Creation/DecorateMag.cs | 151 +++++++++--------- Projects/UOContent/Commands/Properties.cs | 4 +- Projects/UOContent/Commands/SignParser.cs | 21 ++- .../Bulk Orders/Books/BulkOrderBook.cs | 2 +- .../Engines/Chat/ChatActionHandlers.cs | 14 +- .../Doom/LeverPuzzle/LeverPuzzleController.cs | 2 +- .../Engines/ML Quests/Mobiles/SirHelper.cs | 2 +- Projects/UOContent/Engines/Party/Party.cs | 8 +- .../Engines/Spawners/EditSpawnCommand.cs | 4 +- .../Gumps/Guilds/GuildAbbrvPrompt.cs | 2 +- .../Gumps/Guilds/GuildCharterPrompt.cs | 2 +- .../UOContent/Gumps/Guilds/GuildNamePrompt.cs | 2 +- .../Gumps/Guilds/GuildTitlePrompt.cs | 2 +- .../Gumps/Guilds/GuildWebsitePrompt.cs | 2 +- Projects/UOContent/Gumps/Props/PropsGump.cs | 4 +- Projects/UOContent/Gumps/Props/SetBodyGump.cs | 2 +- Projects/UOContent/Items/Body Parts/Head.cs | 6 +- .../Bulletin Boards/BulletinBoardPackets.cs | 4 +- Projects/UOContent/Items/Guilds/GuildDeed.cs | 2 +- Projects/UOContent/Items/Misc/Blocker.cs | 6 +- Projects/UOContent/Items/Misc/LOSBlocker.cs | 6 +- .../Items/Misc/PlayerBulletinBoards.cs | 4 +- .../Veteran Rewards/WeaponEngravingTool.cs | 2 +- Projects/UOContent/Misc/Guild.cs | 4 +- Projects/UOContent/Misc/LootPack.cs | 2 +- Projects/UOContent/Misc/Titles.cs | 2 +- Projects/UOContent/Mobiles/PlayerMobile.cs | 2 +- .../Mobiles/Vendors/NPC/AnimalTrainer.cs | 2 +- .../Mobiles/Vendors/PlayerBarkeeper.cs | 6 +- .../UOContent/Mobiles/Vendors/PlayerVendor.cs | 4 +- Projects/UOContent/Multis/Boats/BaseBoat.cs | 6 +- .../UOContent/Multis/Houses/HousePackets.cs | 2 +- 62 files changed, 363 insertions(+), 382 deletions(-) diff --git a/Projects/Benchmarks/Benchmarks/Packets/BenchmarkPacketBroadcast.cs b/Projects/Benchmarks/Benchmarks/Packets/BenchmarkPacketBroadcast.cs index bd2390170..a60b75eb0 100644 --- a/Projects/Benchmarks/Benchmarks/Packets/BenchmarkPacketBroadcast.cs +++ b/Projects/Benchmarks/Benchmarks/Packets/BenchmarkPacketBroadcast.cs @@ -133,7 +133,7 @@ namespace Benchmarks buffer, Serial.MinusOne, -1, MessageType.Regular, 0x3B2, 3, "ENU", "System", text ); - buffer = buffer.SliceToLength(length); + buffer = buffer[..length]; foreach (var pipe in _pipes) { @@ -152,7 +152,7 @@ namespace Benchmarks buffer, Serial.MinusOne, -1, MessageType.Regular, 0x3B2, 3, "ENU", "System", text ); - buffer = buffer.SliceToLength(length); + buffer = buffer[..length]; var result = pipe.Writer.TryGetMemory(); result.CopyFrom(buffer); pipe.Writer.Advance((uint)buffer.Length); diff --git a/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs b/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs index ebed95b1d..45521aef2 100644 --- a/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs +++ b/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs @@ -64,14 +64,14 @@ namespace Server.Tests.Network var strLength = fixedLength > -1 ? Math.Min(value.Length, fixedLength) : value.Length; var chars = value.AsSpan(0, strLength); - encoding.GetBytes(chars, buffer.Slice(offset)); + encoding.GetBytes(chars, buffer[offset..]); - var reader = new CircularBufferReader(buffer.SliceToLength(firstSize), buffer.Slice(firstSize)); + var reader = new CircularBufferReader(buffer[..firstSize], buffer[firstSize..]); reader.Seek(offset, SeekOrigin.Begin); var actual = reader.ReadString(encoding, isSafe, fixedLength); - Assert.Equal(value.Substring(0, strLength), actual); + Assert.Equal(value[..strLength], actual); } [Fact] @@ -82,7 +82,7 @@ namespace Server.Tests.Network expected[1] = 0x1; expected[2] = 0x1; expected[3] = 0x1; - Encoding.ASCII.GetBytes("TestString", expected.Slice(4, 10)); + Encoding.ASCII.GetBytes("TestString", expected[4..14]); expected[14] = 0x0; // Null expected[15] = 0x2; expected[16] = 0x2; diff --git a/Projects/Server.Tests/Tests/Buffers/CircularBufferWriterTests.cs b/Projects/Server.Tests/Tests/Buffers/CircularBufferWriterTests.cs index 7f9f95012..38f627ce8 100644 --- a/Projects/Server.Tests/Tests/Buffers/CircularBufferWriterTests.cs +++ b/Projects/Server.Tests/Tests/Buffers/CircularBufferWriterTests.cs @@ -55,7 +55,7 @@ namespace Server.Tests.Buffers var strLength = fixedLength > -1 ? Math.Min(value.Length, fixedLength) : value.Length; var chars = value.AsSpan(0, strLength); - var writer = new CircularBufferWriter(buffer.SliceToLength(firstSize), buffer.Slice(firstSize)); + var writer = new CircularBufferWriter(buffer[..firstSize], buffer[firstSize..]); writer.Seek(offset, SeekOrigin.Begin); writer.WriteString(chars, encoding); @@ -63,11 +63,11 @@ namespace Server.Tests.Buffers { Span testEmpty = stackalloc byte[offset]; testEmpty.Clear(); - AssertThat.Equal(buffer.SliceToLength(offset), testEmpty); + AssertThat.Equal(buffer[..offset], testEmpty); } Span expectedStr = stackalloc byte[encoding.GetByteCount(chars)]; - encoding.GetBytes(chars, expectedStr.Slice(0)); + encoding.GetBytes(chars, expectedStr[..]); AssertThat.Equal(buffer.Slice(offset, expectedStr.Length), expectedStr); offset += expectedStr.Length; @@ -76,7 +76,7 @@ namespace Server.Tests.Buffers { Span testEmpty = stackalloc byte[buffer.Length - offset]; testEmpty.Clear(); - AssertThat.Equal(buffer.Slice(offset), testEmpty); + AssertThat.Equal(buffer[offset..], testEmpty); } } } diff --git a/Projects/Server.Tests/Tests/Utility/StringHelperTests.cs b/Projects/Server.Tests/Tests/Utility/StringHelperTests.cs index c97ac757e..910962a6d 100644 --- a/Projects/Server.Tests/Tests/Utility/StringHelperTests.cs +++ b/Projects/Server.Tests/Tests/Utility/StringHelperTests.cs @@ -101,14 +101,14 @@ namespace Server.Tests { while (v.Length >= startIndex) { - list.Add(v.Substring(0, startIndex)); + list.Add(v[..startIndex]); if (list.Count == maxLines) { return list; } - v = v.Substring(startIndex); + v = v[startIndex..]; } current = v; diff --git a/Projects/Server/AssemblyHandler.cs b/Projects/Server/AssemblyHandler.cs index 2e14aa654..1fd29ecf9 100644 --- a/Projects/Server/AssemblyHandler.cs +++ b/Projects/Server/AssemblyHandler.cs @@ -262,7 +262,7 @@ namespace Server for (var j = 0; j < alias.Aliases.Length; j++) { var fullName = alias.Aliases[j]; - var name = fullName.Substring(fullName.LastIndexOf('.') + 1); + var name = fullName[(fullName.LastIndexOf('.') + 1)..]; addToRefs(i, fullName, nameMap); addToRefs(i, fullName.ToLower(), nameMapInsensitive); addToRefs(i, name, nameMap); diff --git a/Projects/Server/Buffers/CircularBuffer.cs b/Projects/Server/Buffers/CircularBuffer.cs index 18ad4ae73..540d23a0b 100644 --- a/Projects/Server/Buffers/CircularBuffer.cs +++ b/Projects/Server/Buffers/CircularBuffer.cs @@ -110,7 +110,7 @@ namespace System.Buffers if (_second.Length > 0) { - _second.CopyTo(bytes.Slice(_first.Length)); + _second.CopyTo(bytes[_first.Length..]); } } diff --git a/Projects/Server/Buffers/CircularBufferReader.cs b/Projects/Server/Buffers/CircularBufferReader.cs index 5683ce165..56619c6e0 100644 --- a/Projects/Server/Buffers/CircularBufferReader.cs +++ b/Projects/Server/Buffers/CircularBufferReader.cs @@ -102,13 +102,13 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadInt16BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadInt16BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return (short)((ReadByte() >> 8) | ReadByte()); } } - else if (!BinaryPrimitives.TryReadInt16BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadInt16BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -124,13 +124,13 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadUInt16BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadUInt16BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return (ushort)((ReadByte() >> 8) | ReadByte()); } } - else if (!BinaryPrimitives.TryReadUInt16BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadUInt16BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -146,13 +146,13 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadInt32BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadInt32BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return (ReadByte() >> 24) | (ReadByte() >> 16) | (ReadByte() >> 8) | ReadByte(); } } - else if (!BinaryPrimitives.TryReadInt32BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadInt32BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -168,13 +168,13 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadUInt32BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadUInt32BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return (uint)((ReadByte() >> 24) | (ReadByte() >> 16) | (ReadByte() >> 8) | ReadByte()); } } - else if (!BinaryPrimitives.TryReadUInt32BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadUInt32BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -190,7 +190,7 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadInt64BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadInt64BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return ((long)ReadByte() >> 56) | @@ -203,7 +203,7 @@ namespace Server.Network ReadByte(); } } - else if (!BinaryPrimitives.TryReadInt64BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadInt64BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -219,7 +219,7 @@ namespace Server.Network if (Position < _first.Length) { - if (!BinaryPrimitives.TryReadUInt64BigEndian(_first.Slice(Position), out value)) + if (!BinaryPrimitives.TryReadUInt64BigEndian(_first[Position..], out value)) { // Not enough space. Split the spans return ((ulong)ReadByte() >> 56) | @@ -232,7 +232,7 @@ namespace Server.Network ReadByte(); } } - else if (!BinaryPrimitives.TryReadUInt64BigEndian(_second.Slice(Position - _first.Length), out value)) + else if (!BinaryPrimitives.TryReadUInt64BigEndian(_second[(Position - _first.Length)..], out value)) { throw new OutOfMemoryException(); } @@ -284,15 +284,15 @@ namespace Server.Network } else { - index = _second.SliceToLength(remaining).IndexOfTerminator(sizeT); + index = _second[..remaining].IndexOfTerminator(sizeT); int secondLength = index < 0 ? remaining : index; int length = firstLength + secondLength; // Assume no strings should be too long for the stack Span bytes = stackalloc byte[length]; - _first.Slice(Position).CopyTo(bytes); - _second.SliceToLength(secondLength).CopyTo(bytes.Slice(firstLength)); + _first[Position..].CopyTo(bytes); + _second[..secondLength].CopyTo(bytes[firstLength..]); Position += length + (index >= 0 ? sizeT : 0); return TextEncoding.GetString(bytes, encoding, safeString); @@ -309,7 +309,7 @@ namespace Server.Network if (index >= 0) { - span = span.SliceToLength(index); + span = span[..index]; } else { @@ -388,7 +388,7 @@ namespace Server.Network return false; } - return _second.Length <= 0 || _second.TryCopyTo(bytes.Slice(_first.Length)); + return _second.Length <= 0 || _second.TryCopyTo(bytes[_first.Length..]); } } } diff --git a/Projects/Server/Buffers/CircularBufferWriter.cs b/Projects/Server/Buffers/CircularBufferWriter.cs index 8850ad5f8..85fed6180 100644 --- a/Projects/Server/Buffers/CircularBufferWriter.cs +++ b/Projects/Server/Buffers/CircularBufferWriter.cs @@ -87,7 +87,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteInt16BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteInt16BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -102,7 +102,7 @@ namespace System.Buffers Position += 2; } } - else if (BinaryPrimitives.TryWriteInt16BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteInt16BigEndian(_second[(Position - _first.Length)..], value)) { Position += 2; } @@ -117,7 +117,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteUInt16BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteUInt16BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -132,7 +132,7 @@ namespace System.Buffers Position += 2; } } - else if (BinaryPrimitives.TryWriteUInt16BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteUInt16BigEndian(_second[(Position - _first.Length)..], value)) { Position += 2; } @@ -147,7 +147,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteInt32BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteInt32BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -164,7 +164,7 @@ namespace System.Buffers Position += 4; } } - else if (BinaryPrimitives.TryWriteInt32BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteInt32BigEndian(_second[(Position - _first.Length)..], value)) { Position += 4; } @@ -179,7 +179,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteInt32LittleEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteInt32LittleEndian(_first[Position..], value)) { if (!BitConverter.IsLittleEndian) { @@ -196,7 +196,7 @@ namespace System.Buffers Position += 4; } } - else if (BinaryPrimitives.TryWriteInt32LittleEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteInt32LittleEndian(_second[(Position - _first.Length)..], value)) { Position += 4; } @@ -214,7 +214,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteUInt32BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteUInt32BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -231,7 +231,7 @@ namespace System.Buffers Position += 4; } } - else if (BinaryPrimitives.TryWriteUInt32BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteUInt32BigEndian(_second[(Position - _first.Length)..], value)) { Position += 4; } @@ -246,7 +246,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteUInt32LittleEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteUInt32LittleEndian(_first[Position..], value)) { if (!BitConverter.IsLittleEndian) { @@ -263,7 +263,7 @@ namespace System.Buffers Position += 4; } } - else if (BinaryPrimitives.TryWriteUInt32LittleEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteUInt32LittleEndian(_second[(Position - _first.Length)..], value)) { Position += 4; } @@ -281,7 +281,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteInt64BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteInt64BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -303,7 +303,7 @@ namespace System.Buffers Position += 8; } } - else if (BinaryPrimitives.TryWriteInt64BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteInt64BigEndian(_second[(Position - _first.Length)..], value)) { Position += 8; } @@ -321,7 +321,7 @@ namespace System.Buffers { if (Position < _first.Length) { - if (!BinaryPrimitives.TryWriteUInt64BigEndian(_first.Slice(Position), value)) + if (!BinaryPrimitives.TryWriteUInt64BigEndian(_first[Position..], value)) { if (BitConverter.IsLittleEndian) { @@ -342,7 +342,7 @@ namespace System.Buffers Position += 8; } } - else if (BinaryPrimitives.TryWriteUInt64BigEndian(_second.Slice(Position - _first.Length), value)) + else if (BinaryPrimitives.TryWriteUInt64BigEndian(_second[(Position - _first.Length)..], value)) { Position += 8; } @@ -363,15 +363,15 @@ namespace System.Buffers if (Position < _first.Length) { var sz = Math.Min(buffer.Length, _first.Length - Position); - buffer.SliceToLength(sz).CopyTo(_first.Slice(Position)); + buffer[..sz].CopyTo(_first[Position..]); if (sz < buffer.Length) { - buffer.Slice(sz).CopyTo(_second); + buffer[sz..].CopyTo(_second); } } else if (Position < Length) { - buffer.CopyTo(_second.Slice(Position - _first.Length)); + buffer.CopyTo(_second[(Position - _first.Length)..]); } else { @@ -398,7 +398,7 @@ namespace System.Buffers if (Position < _first.Length) { count = Math.Min(_first.Length - Position, byteCount); - bytes.SliceToLength(count).CopyTo(_first.Slice(Position)); + bytes[..count].CopyTo(_first[Position..]); byteCount -= count; Position += count; } @@ -409,7 +409,7 @@ namespace System.Buffers if (byteCount > 0) { - bytes.Slice(count).CopyTo(_second.Slice(Math.Max(0, Position - _first.Length))); + bytes[count..].CopyTo(_second[Math.Max(0, Position - _first.Length)..]); Position += byteCount; } } diff --git a/Projects/Server/Buffers/SpanReader.cs b/Projects/Server/Buffers/SpanReader.cs index 71faaf5ce..5adc47fa5 100644 --- a/Projects/Server/Buffers/SpanReader.cs +++ b/Projects/Server/Buffers/SpanReader.cs @@ -58,7 +58,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public short ReadInt16() { - if (!BinaryPrimitives.TryReadInt16BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadInt16BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -70,7 +70,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public short ReadInt16LE() { - if (!BinaryPrimitives.TryReadInt16LittleEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadInt16LittleEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -82,7 +82,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public ushort ReadUInt16() { - if (!BinaryPrimitives.TryReadUInt16BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadUInt16BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -94,7 +94,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public ushort ReadUInt16LE() { - if (!BinaryPrimitives.TryReadUInt16LittleEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadUInt16LittleEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -106,7 +106,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public int ReadInt32() { - if (!BinaryPrimitives.TryReadInt32BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadInt32BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -118,7 +118,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public uint ReadUInt32() { - if (!BinaryPrimitives.TryReadUInt32BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadUInt32BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -130,7 +130,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public uint ReadUInt32LE() { - if (!BinaryPrimitives.TryReadUInt32LittleEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadUInt32LittleEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -142,7 +142,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public long ReadInt64() { - if (!BinaryPrimitives.TryReadInt64BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadInt64BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } @@ -154,7 +154,7 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong ReadUInt64() { - if (!BinaryPrimitives.TryReadUInt64BigEndian(_buffer.Slice(Position), out var value)) + if (!BinaryPrimitives.TryReadUInt64BigEndian(_buffer[Position..], out var value)) { throw new OutOfMemoryException(); } diff --git a/Projects/Server/Buffers/SpanWriter.cs b/Projects/Server/Buffers/SpanWriter.cs index feaab3d50..3650e5f0d 100644 --- a/Projects/Server/Buffers/SpanWriter.cs +++ b/Projects/Server/Buffers/SpanWriter.cs @@ -51,7 +51,7 @@ namespace System.Buffers public int Capacity => _buffer.Length; - public ReadOnlySpan Span => _buffer.SliceToLength(Position); + public ReadOnlySpan Span => _buffer[..Position]; public Span RawBuffer => _buffer; @@ -119,7 +119,7 @@ namespace System.Buffers var newSize = Math.Max(BytesWritten + additionalCapacity, _buffer.Length * 2); byte[] poolArray = ArrayPool.Shared.Rent(newSize); - _buffer.SliceToLength(BytesWritten).CopyTo(poolArray); + _buffer[..BytesWritten].CopyTo(poolArray); byte[] toReturn = _arrayToReturnToPool; _buffer = _arrayToReturnToPool = poolArray; @@ -183,7 +183,7 @@ namespace System.Buffers public void Write(short value) { GrowIfNeeded(2); - BinaryPrimitives.WriteInt16BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteInt16BigEndian(_buffer[_position..], value); Position += 2; } @@ -191,7 +191,7 @@ namespace System.Buffers public void WriteLE(short value) { GrowIfNeeded(2); - BinaryPrimitives.WriteInt16LittleEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteInt16LittleEndian(_buffer[_position..], value); Position += 2; } @@ -199,7 +199,7 @@ namespace System.Buffers public void Write(ushort value) { GrowIfNeeded(2); - BinaryPrimitives.WriteUInt16BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteUInt16BigEndian(_buffer[_position..], value); Position += 2; } @@ -207,7 +207,7 @@ namespace System.Buffers public void WriteLE(ushort value) { GrowIfNeeded(2); - BinaryPrimitives.WriteUInt16LittleEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteUInt16LittleEndian(_buffer[_position..], value); Position += 2; } @@ -215,7 +215,7 @@ namespace System.Buffers public void Write(int value) { GrowIfNeeded(4); - BinaryPrimitives.WriteInt32BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteInt32BigEndian(_buffer[_position..], value); Position += 4; } @@ -223,7 +223,7 @@ namespace System.Buffers public void WriteLE(int value) { GrowIfNeeded(4); - BinaryPrimitives.WriteInt32LittleEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteInt32LittleEndian(_buffer[_position..], value); Position += 4; } @@ -231,7 +231,7 @@ namespace System.Buffers public void Write(uint value) { GrowIfNeeded(4); - BinaryPrimitives.WriteUInt32BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteUInt32BigEndian(_buffer[_position..], value); Position += 4; } @@ -239,7 +239,7 @@ namespace System.Buffers public void WriteLE(uint value) { GrowIfNeeded(4); - BinaryPrimitives.WriteUInt32LittleEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteUInt32LittleEndian(_buffer[_position..], value); Position += 4; } @@ -247,7 +247,7 @@ namespace System.Buffers public void Write(long value) { GrowIfNeeded(8); - BinaryPrimitives.WriteInt64BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteInt64BigEndian(_buffer[_position..], value); Position += 8; } @@ -255,7 +255,7 @@ namespace System.Buffers public void Write(ulong value) { GrowIfNeeded(8); - BinaryPrimitives.WriteUInt64BigEndian(_buffer.Slice(_position), value); + BinaryPrimitives.WriteUInt64BigEndian(_buffer[_position..], value); Position += 8; } @@ -264,7 +264,7 @@ namespace System.Buffers { var count = buffer.Length; GrowIfNeeded(count); - buffer.CopyTo(_buffer.Slice(_position)); + buffer.CopyTo(_buffer[_position..]); Position += count; } @@ -293,7 +293,7 @@ namespace System.Buffers GrowIfNeeded(byteCount); - var bytesWritten = encoding.GetBytes(src, _buffer.Slice(_position)); + var bytesWritten = encoding.GetBytes(src, _buffer[_position..]); Position += bytesWritten; if (fixedLength > -1) diff --git a/Projects/Server/Buffers/ValueStringBuilder.cs b/Projects/Server/Buffers/ValueStringBuilder.cs index cb826487d..2ff5be58b 100644 --- a/Projects/Server/Buffers/ValueStringBuilder.cs +++ b/Projects/Server/Buffers/ValueStringBuilder.cs @@ -86,7 +86,7 @@ namespace Server.Buffers public ref char this[int index] => ref _chars[index]; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override string ToString() => _chars.SliceToLength(_length).ToString(); + public override string ToString() => _chars[.._length].ToString(); /// Returns the underlying storage of the builder. public Span RawChars => _chars; @@ -102,14 +102,14 @@ namespace Server.Buffers EnsureCapacity(_length + 1); _chars[_length] = '\0'; } - return _chars.SliceToLength(_length); + return _chars[.._length]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan AsSpan() => _chars.SliceToLength(_length); + public ReadOnlySpan AsSpan() => _chars[.._length]; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan AsSpan(int start) => _chars.Slice(start, _length - start); + public ReadOnlySpan AsSpan(int start) => _chars[start..]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlySpan AsSpan(int start, int length) => _chars.Slice(start, length); @@ -117,7 +117,7 @@ namespace Server.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryCopyTo(Span destination, out int charsWritten) { - if (_chars.SliceToLength(_length).TryCopyTo(destination)) + if (_chars[.._length].TryCopyTo(destination)) { charsWritten = _length; return true; @@ -136,7 +136,7 @@ namespace Server.Buffers } int remaining = _length - index; - _chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count)); + _chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]); _chars.Slice(index, count).Fill(value); _length += count; } @@ -157,8 +157,8 @@ namespace Server.Buffers } int remaining = _length - index; - _chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count)); - s.AsSpan().CopyTo(_chars.Slice(index)); + _chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]); + s.AsSpan().CopyTo(_chars[index..]); _length += count; } @@ -208,7 +208,7 @@ namespace Server.Buffers return; } - fixed (char* buffer = _chars.Slice(pos)) + fixed (char* buffer = _chars[pos..]) { char* p = buffer + bufferLength; do @@ -271,7 +271,7 @@ namespace Server.Buffers Grow(s.Length); } - s.AsSpan().CopyTo(_chars.Slice(pos)); + s.AsSpan().CopyTo(_chars[pos..]); _length += s.Length; } @@ -317,7 +317,7 @@ namespace Server.Buffers Grow(value.Length); } - value.CopyTo(_chars.Slice(_length)); + value.CopyTo(_chars[_length..]); _length += value.Length; } @@ -355,7 +355,7 @@ namespace Server.Buffers { char[] poolArray = ArrayPool.Shared.Rent(Math.Max(_length + additionalCapacityBeyondPos, _chars.Length * 2)); - _chars.SliceToLength(_length).CopyTo(poolArray); + _chars[.._length].CopyTo(poolArray); char[] toReturn = _arrayToReturnToPool; _chars = _arrayToReturnToPool = poolArray; @@ -404,7 +404,7 @@ namespace Server.Buffers var chr = slice[indexOf]; slice[indexOf] = newChars[oldChars.IndexOf(chr)]; - slice = slice.Slice(indexOf + 1); + slice = slice[(indexOf + 1)..]; } } @@ -433,7 +433,7 @@ namespace Server.Buffers } slice[indexOf] = newChar; - slice = slice.Slice(indexOf + 1); + slice = slice[(indexOf + 1)..]; } } @@ -457,16 +457,16 @@ namespace Server.Buffers if (startIndex == 0) { - _chars = _chars.Slice(length); + _chars = _chars[length..]; } else if (startIndex + length == _length) { - _chars = _chars.SliceToLength(startIndex); + _chars = _chars[..startIndex]; } else { // Somewhere in the middle, this will be slow - _chars.Slice(startIndex + length).CopyTo(_chars.Slice(startIndex)); + _chars[(startIndex + length)..].CopyTo(_chars[startIndex..]); } _length -= length; diff --git a/Projects/Server/ClientVersion.cs b/Projects/Server/ClientVersion.cs index af257456f..8325eb06a 100644 --- a/Projects/Server/ClientVersion.cs +++ b/Projects/Server/ClientVersion.cs @@ -42,7 +42,7 @@ namespace Server br3++; } - Major = Utility.ToInt32(fmt.Substring(0, br1)); + Major = Utility.ToInt32(fmt.AsSpan()[..br1]); Minor = Utility.ToInt32(fmt.Substring(br1 + 1, br2 - br1 - 1)); Revision = Utility.ToInt32(fmt.Substring(br2 + 1, br3 - br2 - 1)); diff --git a/Projects/Server/Commands.cs b/Projects/Server/Commands.cs index 29f48bb0a..503b24814 100644 --- a/Projects/Server/Commands.cs +++ b/Projects/Server/Commands.cs @@ -257,7 +257,7 @@ namespace Server if (type != MessageType.Command) { - text = text.Substring(Prefix.Length); + text = text[Prefix.Length..]; } var indexOf = text.IndexOfOrdinal(' '); @@ -268,9 +268,9 @@ namespace Server if (indexOf >= 0) { - argString = text.Substring(indexOf + 1); + argString = text[(indexOf + 1)..]; - command = text.Substring(0, indexOf); + command = text[..indexOf]; args = Split(argString); } else diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index c63a36b50..e21077d3b 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -1150,7 +1150,7 @@ namespace Server var length = OutgoingEntityPackets.CreateWorldEntity(hsWorldItem, this, true); if (length != hsWorldItem.Length) { - hsWorldItem = hsWorldItem.SliceToLength(length); + hsWorldItem = hsWorldItem[..length]; } SendInfoTo(state, hsWorldItem, opl); @@ -1160,7 +1160,7 @@ namespace Server var length = OutgoingEntityPackets.CreateWorldEntity(saWorldItem, this, false); if (length != saWorldItem.Length) { - saWorldItem = saWorldItem.SliceToLength(length); + saWorldItem = saWorldItem[..length]; } SendInfoTo(state, saWorldItem, opl); @@ -1170,7 +1170,7 @@ namespace Server var length = OutgoingItemPackets.CreateWorldItem(oldWorldItem, this); if (length != oldWorldItem.Length) { - oldWorldItem = oldWorldItem.SliceToLength(length); + oldWorldItem = oldWorldItem[..length]; } SendInfoTo(state, oldWorldItem, opl); @@ -3330,7 +3330,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); @@ -3364,7 +3364,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index c63269b57..ab862a642 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -5792,7 +5792,7 @@ namespace Server if (length != regBuffer.Length) { - regBuffer = regBuffer.SliceToLength(length); // Adjust to the actual size + regBuffer = regBuffer[..length]; // Adjust to the actual size } heard.OnSpeech(regArgs); @@ -5806,7 +5806,7 @@ namespace Server if (length != mutBuffer.Length) { - mutBuffer = mutBuffer.SliceToLength(length); // Adjust to the actual size + mutBuffer = mutBuffer[..length]; // Adjust to the actual size } heard.OnSpeech(mutatedArgs); @@ -9155,7 +9155,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); @@ -9186,7 +9186,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); @@ -9220,7 +9220,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); @@ -9268,7 +9268,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); @@ -9299,7 +9299,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); diff --git a/Projects/Server/Network/PacketUtilities.cs b/Projects/Server/Network/PacketUtilities.cs index 33a19ab2e..f6fd7df14 100644 --- a/Projects/Server/Network/PacketUtilities.cs +++ b/Projects/Server/Network/PacketUtilities.cs @@ -40,12 +40,6 @@ namespace Server.Network writer.Seek(0, SeekOrigin.End); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span SliceToLength(this Span span, int length) => span.Slice(0, length); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan SliceToLength(this ReadOnlySpan span, int length) => span.Slice(0, length); - // If LOCAL INIT is off, then stack/heap allocations have garbage data // Initializes the first byte (Packet ID) so it can be used as a flag. [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Projects/Server/Network/Packets/OutgoingItemPackets.cs b/Projects/Server/Network/Packets/OutgoingItemPackets.cs index 20ac036c5..5dff9f4d6 100644 --- a/Projects/Server/Network/Packets/OutgoingItemPackets.cs +++ b/Projects/Server/Network/Packets/OutgoingItemPackets.cs @@ -94,7 +94,7 @@ namespace Server.Network OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.HighSeas) : CreateWorldItem(buffer, item); - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } } } diff --git a/Projects/Server/Network/Packets/OutgoingMessagePackets.cs b/Projects/Server/Network/Packets/OutgoingMessagePackets.cs index a47e58810..a7a8d8e46 100644 --- a/Projects/Server/Network/Packets/OutgoingMessagePackets.cs +++ b/Projects/Server/Network/Packets/OutgoingMessagePackets.cs @@ -46,7 +46,7 @@ namespace Server.Network buffer, serial, graphic, type, hue, font, number, name, args ); - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -102,7 +102,7 @@ namespace Server.Network buffer, serial, graphic, type, hue, font, number, name, affixType, affix, args ); - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -171,7 +171,7 @@ namespace Server.Network text ); - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Projects/Server/Network/Packets/OutgoingMobilePackets.cs b/Projects/Server/Network/Packets/OutgoingMobilePackets.cs index 29acf88f7..f32e89ad4 100644 --- a/Projects/Server/Network/Packets/OutgoingMobilePackets.cs +++ b/Projects/Server/Network/Packets/OutgoingMobilePackets.cs @@ -470,7 +470,7 @@ namespace Server.Network } var length = CreateMobileStatus(buffer, beholder, beheld, version, beheld.CanBeRenamedBy(beholder)); - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } public static int CreateMobileStatus( diff --git a/Projects/Server/Network/Packets/PacketContainerBuilder.cs b/Projects/Server/Network/Packets/PacketContainerBuilder.cs index 7fb49a6a7..deee3e501 100644 --- a/Projects/Server/Network/Packets/PacketContainerBuilder.cs +++ b/Projects/Server/Network/Packets/PacketContainerBuilder.cs @@ -50,11 +50,11 @@ namespace Server.Network { if (!_finished) { - BinaryPrimitives.WriteUInt16BigEndian(_bytes.Slice(1, 2), (ushort)Length); - BinaryPrimitives.WriteUInt16BigEndian(_bytes.Slice(3, 2), (ushort)_count); + BinaryPrimitives.WriteUInt16BigEndian(_bytes[1..3], (ushort)Length); + BinaryPrimitives.WriteUInt16BigEndian(_bytes[3..5], (ushort)_count); } - return _bytes.SliceToLength(Length); + return _bytes[..Length]; } [MethodImpl(MethodImplOptions.NoInlining)] @@ -70,7 +70,7 @@ namespace Server.Network Grow(bytesNeeded); } - return _bytes.Slice(Length); + return _bytes[Length..]; } [MethodImpl(MethodImplOptions.NoInlining)] @@ -91,7 +91,7 @@ namespace Server.Network var newLength = Math.Max(Length + additionalCapacityBeyondPos, _bytes.Length * 2); byte[] poolArray = ArrayPool.Shared.Rent(newLength); - _bytes.SliceToLength(Length).CopyTo(poolArray); + _bytes[..Length].CopyTo(poolArray); byte[] toReturn = _arrayToReturnToPool; _bytes = _arrayToReturnToPool = poolArray; diff --git a/Projects/Server/Serialization/BufferReader.cs b/Projects/Server/Serialization/BufferReader.cs index 7b02f5362..8a494c9a0 100644 --- a/Projects/Server/Serialization/BufferReader.cs +++ b/Projects/Server/Serialization/BufferReader.cs @@ -89,7 +89,7 @@ namespace Server int index = buffer.IndexOfTerminator(sizeT); - var span = buffer.SliceToLength(index < 0 ? size : index); + var span = buffer[..(index < 0 ? size : index)]; _position += isFixedLength || index < 0 ? size : index + sizeT; return TextEncoding.GetString(span, encoding, safeString); } diff --git a/Projects/Server/Serialization/BufferWriter.cs b/Projects/Server/Serialization/BufferWriter.cs index 27bb551fb..33c29cbdb 100644 --- a/Projects/Server/Serialization/BufferWriter.cs +++ b/Projects/Server/Serialization/BufferWriter.cs @@ -225,7 +225,7 @@ namespace Server Span stack = stackalloc byte[16]; value.TryWriteBytes(stack, out var bytesWritten); Write((byte)bytesWritten); - Write(stack.SliceToLength(bytesWritten)); + Write(stack[..bytesWritten]); } public void Write(TimeSpan value) @@ -441,7 +441,7 @@ namespace Server charsLeft -= charCount; current += charCount; - Write(span.SliceToLength(bytesWritten)); + Write(span[..bytesWritten]); } } } diff --git a/Projects/Server/Text/StringHelpers.cs b/Projects/Server/Text/StringHelpers.cs index 46630d7c2..61eaa1283 100644 --- a/Projects/Server/Text/StringHelpers.cs +++ b/Projects/Server/Text/StringHelpers.cs @@ -58,7 +58,7 @@ namespace Server throw new OutOfMemoryException(nameof(buffer)); } - sliced.SliceToLength(indexOf).CopyTo(buffer.Slice(size)); + sliced[..indexOf].CopyTo(buffer[size..]); size += indexOf; if (indexOf == sliced.Length) @@ -66,7 +66,7 @@ namespace Server break; } - sliced = sliced.Slice(indexOf + 1); + sliced = sliced[(indexOf + 1)..]; } } @@ -97,7 +97,7 @@ namespace Server a.Remove(b, comparison, span, out var size); - var str = span.SliceToLength(size).ToString(); + var str = span[..size].ToString(); if (chrs != null) { @@ -138,7 +138,7 @@ namespace Server // Special case for titles - words that don't get capitalized if (sliced.InsensitiveStartsWith("the ")) { - sliced = sliced.Slice(4); + sliced = sliced[4..]; index += 4; continue; } @@ -156,7 +156,7 @@ namespace Server break; } - sliced = sliced.Slice(indexOf + 1); + sliced = sliced[(indexOf + 1)..]; index += indexOf + 1; } @@ -183,7 +183,7 @@ namespace Server while (span.Length > 0) { - var spaceIndex = span.Slice(lineLength).IndexOf(' '); + var spaceIndex = span[lineLength..].IndexOf(' '); if (spaceIndex == -1) { spaceIndex = span.Length; // End of the string @@ -193,13 +193,13 @@ namespace Server if (newLineLength == perLine || newLineLength == span.Length) { - list.Add(span.SliceToLength(newLineLength).ToString()); + list.Add(span[..newLineLength].ToString()); if (list.Count == maxLines || newLineLength == span.Length) { break; } - span = span.Slice(newLineLength + 1); + span = span[(newLineLength + 1)..]; lineLength = 0; } else if (newLineLength < perLine) @@ -208,13 +208,13 @@ namespace Server } else if (lineLength > 0 && lineLength <= perLine) { - list.Add(span.SliceToLength(lineLength - 1).ToString()); + list.Add(span[..(lineLength - 1)].ToString()); if (list.Count == maxLines) { break; } - span = span.Slice(lineLength); + span = span[lineLength..]; lineLength = spaceIndex; } else @@ -236,7 +236,7 @@ namespace Server index += perLine; } - span = span.Slice(newLineLength - lineLength); + span = span[(newLineLength - lineLength)..]; } } diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index b1e908e47..ae1851274 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -387,7 +387,7 @@ namespace Server var sectionStart = 0; var hasCompressor = false; - var num = BinaryPrimitives.ReadUInt16BigEndian(ip.SliceToLength(2)); + var num = BinaryPrimitives.ReadUInt16BigEndian(ip[..2]); for (int i = 0; i < end; i++) { @@ -473,10 +473,10 @@ namespace Server // IPv4 matching at the end if (section == 6 && num == 0xFFFF) { - var ipv4 = val.Slice(i + 1); + var ipv4 = val[(i + 1)..]; if (ipv4.Contains('.')) { - return IPv4Match(ipv4, ip.Slice(ip.Length - 4), out valid); + return IPv4Match(ipv4, ip[^4..], out valid); } } @@ -504,7 +504,7 @@ namespace Server if (i + 1 < end) { - var remainingColons = val.Slice(i + 1).Count(':'); + var remainingColons = val[(i + 1)..].Count(':'); // double colon must be at least 2 sections // we need at least 1 section remaining out of 8 // This means 8 - 2 would be 6 sections (5 colons) @@ -972,7 +972,7 @@ namespace Server #pragma warning disable CA1806 // Do not ignore method results if (value.StartsWithOrdinal("0x")) { - int.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i); + int.TryParse(value[2..], NumberStyles.HexNumber, null, out i); } else { @@ -990,7 +990,7 @@ namespace Server #pragma warning disable CA1806 // Do not ignore method results if (value.InsensitiveStartsWith("0x")) { - uint.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i); + uint.TryParse(value[2..], NumberStyles.HexNumber, null, out i); } else { @@ -1003,12 +1003,12 @@ namespace Server public static bool ToInt32(ReadOnlySpan value, out int i) => value.InsensitiveStartsWith("0x") - ? int.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i) + ? int.TryParse(value[2..], NumberStyles.HexNumber, null, out i) : int.TryParse(value, out i); public static bool ToUInt32(ReadOnlySpan value, out uint i) => value.InsensitiveStartsWith("0x") - ? uint.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i) + ? uint.TryParse(value[2..], NumberStyles.HexNumber, null, out i) : uint.TryParse(value, out i); public static int GetXMLInt32(string intString, int defaultValue) diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index 88818cbd6..6b5c00577 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -183,7 +183,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } ns.Send(buffer); @@ -211,7 +211,7 @@ namespace Server if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } ns.Send(buffer); diff --git a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs index 9086b07c4..7194e7f71 100644 --- a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs @@ -34,11 +34,11 @@ namespace Server.Accounting.Security { Span output = stackalloc byte[m_OutputSize]; var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations); - BinaryPrimitives.WriteUInt16LittleEndian(output.SliceToLength(2), (ushort)iterations); + BinaryPrimitives.WriteUInt16LittleEndian(output[..2], (ushort)iterations); var rfc2898 = new Rfc2898DeriveBytes(plainPassword, m_SaltSize, iterations, HashAlgorithmName.SHA256); rfc2898.Salt.CopyTo(output.Slice(2, m_SaltSize)); - rfc2898.GetBytes(m_HashSize).CopyTo(output.Slice(m_SaltSize + 2)); + rfc2898.GetBytes(m_HashSize).CopyTo(output[(m_SaltSize + 2)..]); return output.ToHexString(); } @@ -48,13 +48,13 @@ namespace Server.Accounting.Security Span encryptedBytes = stackalloc byte[m_OutputSize]; encryptedPassword.GetBytes(encryptedBytes); - var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes.SliceToLength(2)); + var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes[..2]); var salt = encryptedBytes.Slice(2, m_SaltSize); ReadOnlySpan hash = new Rfc2898DeriveBytes(plainPassword, salt.ToArray(), iterations, HashAlgorithmName.SHA256).GetBytes(m_HashSize); - return hash.SequenceEqual(encryptedBytes.Slice(m_SaltSize + 2)); + return hash.SequenceEqual(encryptedBytes[(m_SaltSize + 2)..]); } } } diff --git a/Projects/UOContent/Commands/Batch.cs b/Projects/UOContent/Commands/Batch.cs index aae44e94e..fcc5bdab6 100644 --- a/Projects/UOContent/Commands/Batch.cs +++ b/Projects/UOContent/Commands/Batch.cs @@ -212,9 +212,9 @@ namespace Server.Commands if (indexOf >= 0) { - argString = Command.Substring(indexOf + 1); + argString = Command[(indexOf + 1)..]; - command = Command.Substring(0, indexOf); + command = Command[..indexOf]; args = CommandSystem.Split(argString); } else diff --git a/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs b/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs index a481ff35e..9b86a4ff9 100644 --- a/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs +++ b/Projects/UOContent/Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs @@ -151,7 +151,7 @@ namespace Server.Commands.Generic if (toParse.InsensitiveStartsWith("0x")) { style = NumberStyles.HexNumber; - toParse = toParse.Substring(2); + toParse = toParse[2..]; } parseMethod = parseNumber; diff --git a/Projects/UOContent/Commands/Object Creation/Add.cs b/Projects/UOContent/Commands/Object Creation/Add.cs index 59c091698..34fb42278 100644 --- a/Projects/UOContent/Commands/Object Creation/Add.cs +++ b/Projects/UOContent/Commands/Object Creation/Add.cs @@ -289,15 +289,15 @@ namespace Server.Commands { if (IsSignedNumeric(type)) { - obj = Convert.ToInt64(value.Substring(2), 16); + obj = Convert.ToInt64(value[2..], 16); } else if (IsUnsignedNumeric(type)) { - obj = Convert.ToUInt64(value.Substring(2), 16); + obj = Convert.ToUInt64(value[2..], 16); } else { - obj = Convert.ToInt32(value.Substring(2), 16); + obj = Convert.ToInt32(value[2..], 16); } } diff --git a/Projects/UOContent/Commands/Object Creation/Decorate.cs b/Projects/UOContent/Commands/Object Creation/Decorate.cs index 7f1a8a569..ae808f1a0 100644 --- a/Projects/UOContent/Commands/Object Creation/Decorate.cs +++ b/Projects/UOContent/Commands/Object Creation/Decorate.cs @@ -111,7 +111,7 @@ namespace Server.Commands if (indexOf >= 0) { - labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + labelNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); break; } } @@ -131,7 +131,7 @@ namespace Server.Commands if (indexOf >= 0) { - labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + labelNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); break; } } @@ -179,7 +179,7 @@ namespace Server.Commands if (indexOf >= 0) { - map = Map.Parse(m_Params[i].Substring(++indexOf)); + map = Map.Parse(m_Params[i][++indexOf..]); } } } @@ -208,7 +208,7 @@ namespace Server.Commands if (indexOf >= 0) { - range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("WarningString")) @@ -217,7 +217,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageString = m_Params[i].Substring(++indexOf); + messageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("WarningNumber")) @@ -226,7 +226,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + messageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("HintString")) @@ -235,7 +235,7 @@ namespace Server.Commands if (indexOf >= 0) { - hintString = m_Params[i].Substring(++indexOf); + hintString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("HintNumber")) @@ -244,7 +244,7 @@ namespace Server.Commands if (indexOf >= 0) { - hintNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + hintNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("ResetDelay")) @@ -253,7 +253,7 @@ namespace Server.Commands if (indexOf >= 0) { - resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + resetDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -281,7 +281,7 @@ namespace Server.Commands if (indexOf >= 0) { - range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("WarningString")) @@ -290,7 +290,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageString = m_Params[i].Substring(++indexOf); + messageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("WarningNumber")) @@ -299,7 +299,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + messageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("ResetDelay")) @@ -308,7 +308,7 @@ namespace Server.Commands if (indexOf >= 0) { - resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + resetDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -334,7 +334,7 @@ namespace Server.Commands { direction = (CannonDirection)Enum.Parse( typeof(CannonDirection), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); } @@ -356,7 +356,7 @@ namespace Server.Commands if (indexOf >= 0) { - word = m_Params[i].Substring(++indexOf); + word = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("DestStart")) @@ -365,7 +365,7 @@ namespace Server.Commands if (indexOf >= 0) { - destination.Start = Point2D.Parse(m_Params[i].Substring(++indexOf)); + destination.Start = Point2D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEnd")) @@ -374,7 +374,7 @@ namespace Server.Commands if (indexOf >= 0) { - destination.End = Point2D.Parse(m_Params[i].Substring(++indexOf)); + destination.End = Point2D.Parse(m_Params[i][++indexOf..]); } } } @@ -396,7 +396,7 @@ namespace Server.Commands { content = (BeverageType)Enum.Parse( typeof(BeverageType), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); fill = true; @@ -425,7 +425,7 @@ namespace Server.Commands if (indexOf >= 0) { - facing = (DoorFacing)Enum.Parse(typeof(DoorFacing), m_Params[i].Substring(++indexOf), true); + facing = (DoorFacing)Enum.Parse(typeof(DoorFacing), m_Params[i][++indexOf..], true); break; } } @@ -455,7 +455,7 @@ namespace Server.Commands if (indexOf >= 0) { - coffin.SpawnLocation = Point3D.Parse(m_Params[i].Substring(++indexOf)); + coffin.SpawnLocation = Point3D.Parse(m_Params[i][++indexOf..]); } } } @@ -523,7 +523,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.AddEntry(m_Params[i].Substring(++indexOf)); + sp.AddEntry(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MinDelay")) @@ -532,7 +532,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.MinDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.MinDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MaxDelay")) @@ -541,7 +541,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.MaxDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.MaxDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("NextSpawn")) @@ -550,7 +550,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.NextSpawn = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.NextSpawn = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Count")) @@ -559,7 +559,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Count = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.Count = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); for (var se = 0; se < sp.Entries.Count; se++) { sp.Entries[se].SpawnedMaxCount = sp.Count; @@ -572,7 +572,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Team = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.Team = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("HomeRange")) @@ -581,7 +581,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.HomeRange = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.HomeRange = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Running")) @@ -590,7 +590,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Running = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + sp.Running = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Group")) @@ -599,7 +599,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Group = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + sp.Group = Utility.ToBoolean(m_Params[i][++indexOf..]); } } } @@ -614,7 +614,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Description = m_Params[i].Substring(++indexOf); + rune.Description = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Marked")) @@ -623,7 +623,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Marked = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + rune.Marked = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("TargetMap")) @@ -632,7 +632,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.TargetMap = Map.Parse(m_Params[i].Substring(++indexOf)); + rune.TargetMap = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Target")) @@ -641,7 +641,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Target = Point3D.Parse(m_Params[i].Substring(++indexOf)); + rune.Target = Point3D.Parse(m_Params[i][++indexOf..]); } } } @@ -656,7 +656,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Skill = (SkillName)Enum.Parse(typeof(SkillName), m_Params[i].Substring(++indexOf), true); + st.Skill = (SkillName)Enum.Parse(typeof(SkillName), m_Params[i][++indexOf..], true); } } else if (m_Params[i].StartsWithOrdinal("RequiredFixedPoint")) @@ -665,7 +665,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Required = Utility.ToInt32(m_Params[i].Substring(++indexOf)) * 0.1; + st.Required = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]) * 0.1; } } else if (m_Params[i].StartsWithOrdinal("Required")) @@ -674,7 +674,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Required = Utility.ToDouble(m_Params[i].Substring(++indexOf)); + st.Required = Utility.ToDouble(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MessageString")) @@ -683,7 +683,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MessageString = m_Params[i].Substring(++indexOf); + st.MessageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("MessageNumber")) @@ -692,7 +692,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MessageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + st.MessageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("PointDest")) @@ -701,7 +701,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + st.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -710,7 +710,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + st.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -719,7 +719,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -728,7 +728,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -737,7 +737,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -746,7 +746,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + st.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -755,7 +755,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + st.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -775,7 +775,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Substring = m_Params[i].Substring(++indexOf); + kt.Substring = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Keyword")) @@ -784,7 +784,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Keyword = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.Keyword = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Range")) @@ -793,7 +793,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.Range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("PointDest")) @@ -802,7 +802,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + kt.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -811,7 +811,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + kt.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -820,7 +820,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -829,7 +829,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -838,7 +838,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -847,7 +847,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -856,7 +856,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + kt.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -876,7 +876,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + tp.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -885,7 +885,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + tp.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -894,7 +894,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -903,7 +903,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -912,7 +912,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -921,7 +921,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + tp.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -930,7 +930,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + tp.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -952,7 +952,7 @@ namespace Server.Commands { cont.ContentType = (FillableContentType)Enum.Parse( typeof(FillableContentType), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); } @@ -979,7 +979,7 @@ namespace Server.Commands if (indexOf >= 0) { - item.Light = (LightType)Enum.Parse(typeof(LightType), m_Params[i].Substring(++indexOf), true); + item.Light = (LightType)Enum.Parse(typeof(LightType), m_Params[i][++indexOf..], true); } } else if (m_Params[i].StartsWithOrdinal("Hue")) @@ -988,7 +988,7 @@ namespace Server.Commands if (indexOf >= 0) { - var hue = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + var hue = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); if (item is DyeTub tub) { @@ -1006,7 +1006,7 @@ namespace Server.Commands if (indexOf >= 0) { - item.Name = m_Params[i].Substring(++indexOf); + item.Name = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Amount")) @@ -1020,7 +1020,7 @@ namespace Server.Commands var wasStackable = item.Stackable; item.Stackable = true; - item.Amount = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + item.Amount = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); item.Stackable = wasStackable; } } @@ -1268,25 +1268,20 @@ namespace Server.Commands var indexOf = line.IndexOfOrdinal(' '); - list.m_Type = AssemblyHandler.FindTypeByName(line.Substring(0, indexOf++)); + list.m_Type = AssemblyHandler.FindTypeByName(line[..indexOf++]); if (list.m_Type == null) { throw new ArgumentException($"Type not found for header: '{line}'"); } - line = line.Substring(indexOf); + line = line[indexOf..]; indexOf = line.IndexOfOrdinal('('); if (indexOf >= 0) { - list.m_ItemID = Utility.ToInt32(line.Substring(0, indexOf - 1)); + list.m_ItemID = Utility.ToInt32(line.AsSpan()[..(indexOf - 1)]); - var parms = line.Substring(++indexOf); - - if (line.EndsWithOrdinal(")")) - { - parms = parms.Substring(0, parms.Length - 1); - } + var parms = line[++indexOf..^(line.EndsWithOrdinal(")") ? 1 : 0)]; list.m_Params = parms.Split(';'); @@ -1346,8 +1341,8 @@ namespace Server.Commands if (space >= 0) { - v = line.Substring(0, space++); - line = line.Substring(space); + v = line[..space++]; + line = line[space..]; } else { diff --git a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs index bc9bab697..5a2bb58b1 100644 --- a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs +++ b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs @@ -108,7 +108,7 @@ namespace Server.Commands if (indexOf >= 0) { - labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + labelNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); break; } } @@ -128,7 +128,7 @@ namespace Server.Commands if (indexOf >= 0) { - labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + labelNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); break; } } @@ -176,7 +176,7 @@ namespace Server.Commands if (indexOf >= 0) { - map = Map.Parse(m_Params[i].Substring(++indexOf)); + map = Map.Parse(m_Params[i][++indexOf..]); } } } @@ -205,7 +205,7 @@ namespace Server.Commands if (indexOf >= 0) { - range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("WarningString")) @@ -214,7 +214,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageString = m_Params[i].Substring(++indexOf); + messageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("WarningNumber")) @@ -223,7 +223,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + messageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("HintString")) @@ -232,7 +232,7 @@ namespace Server.Commands if (indexOf >= 0) { - hintString = m_Params[i].Substring(++indexOf); + hintString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("HintNumber")) @@ -241,7 +241,7 @@ namespace Server.Commands if (indexOf >= 0) { - hintNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + hintNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("ResetDelay")) @@ -250,7 +250,7 @@ namespace Server.Commands if (indexOf >= 0) { - resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + resetDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -278,7 +278,7 @@ namespace Server.Commands if (indexOf >= 0) { - range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("WarningString")) @@ -287,7 +287,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageString = m_Params[i].Substring(++indexOf); + messageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("WarningNumber")) @@ -296,7 +296,7 @@ namespace Server.Commands if (indexOf >= 0) { - messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + messageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("ResetDelay")) @@ -305,7 +305,7 @@ namespace Server.Commands if (indexOf >= 0) { - resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + resetDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -331,7 +331,7 @@ namespace Server.Commands { direction = (CannonDirection)Enum.Parse( typeof(CannonDirection), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); } @@ -353,7 +353,7 @@ namespace Server.Commands if (indexOf >= 0) { - word = m_Params[i].Substring(++indexOf); + word = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("DestStart")) @@ -362,7 +362,7 @@ namespace Server.Commands if (indexOf >= 0) { - destination.Start = Point2D.Parse(m_Params[i].Substring(++indexOf)); + destination.Start = Point2D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEnd")) @@ -371,7 +371,7 @@ namespace Server.Commands if (indexOf >= 0) { - destination.End = Point2D.Parse(m_Params[i].Substring(++indexOf)); + destination.End = Point2D.Parse(m_Params[i][++indexOf..]); } } } @@ -393,7 +393,7 @@ namespace Server.Commands { content = (BeverageType)Enum.Parse( typeof(BeverageType), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); fill = true; @@ -422,7 +422,7 @@ namespace Server.Commands if (indexOf >= 0) { - facing = (DoorFacing)Enum.Parse(typeof(DoorFacing), m_Params[i].Substring(++indexOf), true); + facing = (DoorFacing)Enum.Parse(typeof(DoorFacing), m_Params[i][++indexOf..], true); break; } } @@ -452,7 +452,7 @@ namespace Server.Commands if (indexOf >= 0) { - coffin.SpawnLocation = Point3D.Parse(m_Params[i].Substring(++indexOf)); + coffin.SpawnLocation = Point3D.Parse(m_Params[i][++indexOf..]); } } } @@ -520,7 +520,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.AddEntry(m_Params[i].Substring(++indexOf)); + sp.AddEntry(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MinDelay")) @@ -529,7 +529,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.MinDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.MinDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MaxDelay")) @@ -538,7 +538,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.MaxDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.MaxDelay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("NextSpawn")) @@ -547,7 +547,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.NextSpawn = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + sp.NextSpawn = TimeSpan.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Count")) @@ -556,7 +556,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Count = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.Count = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); for (var se = 0; se < sp.Entries.Count; se++) { sp.Entries[se].SpawnedMaxCount = sp.Count; @@ -569,7 +569,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Team = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.Team = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("HomeRange")) @@ -578,7 +578,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.HomeRange = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + sp.HomeRange = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Running")) @@ -587,7 +587,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Running = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + sp.Running = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Group")) @@ -596,7 +596,7 @@ namespace Server.Commands if (indexOf >= 0) { - sp.Group = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + sp.Group = Utility.ToBoolean(m_Params[i][++indexOf..]); } } } @@ -611,7 +611,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Description = m_Params[i].Substring(++indexOf); + rune.Description = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Marked")) @@ -620,7 +620,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Marked = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + rune.Marked = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("TargetMap")) @@ -629,7 +629,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.TargetMap = Map.Parse(m_Params[i].Substring(++indexOf)); + rune.TargetMap = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Target")) @@ -638,7 +638,7 @@ namespace Server.Commands if (indexOf >= 0) { - rune.Target = Point3D.Parse(m_Params[i].Substring(++indexOf)); + rune.Target = Point3D.Parse(m_Params[i][++indexOf..]); } } } @@ -653,7 +653,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Skill = (SkillName)Enum.Parse(typeof(SkillName), m_Params[i].Substring(++indexOf), true); + st.Skill = (SkillName)Enum.Parse(typeof(SkillName), m_Params[i][++indexOf..], true); } } else if (m_Params[i].StartsWithOrdinal("RequiredFixedPoint")) @@ -662,7 +662,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Required = Utility.ToInt32(m_Params[i].Substring(++indexOf)) * 0.1; + st.Required = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]) * 0.1; } } else if (m_Params[i].StartsWithOrdinal("Required")) @@ -671,7 +671,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Required = Utility.ToDouble(m_Params[i].Substring(++indexOf)); + st.Required = Utility.ToDouble(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MessageString")) @@ -680,7 +680,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MessageString = m_Params[i].Substring(++indexOf); + st.MessageString = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("MessageNumber")) @@ -689,7 +689,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MessageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + st.MessageNumber = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("PointDest")) @@ -698,7 +698,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + st.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -707,7 +707,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + st.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -716,7 +716,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -725,7 +725,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -734,7 +734,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + st.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -743,7 +743,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + st.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -752,7 +752,7 @@ namespace Server.Commands if (indexOf >= 0) { - st.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + st.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -772,7 +772,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Substring = m_Params[i].Substring(++indexOf); + kt.Substring = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Keyword")) @@ -781,7 +781,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Keyword = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.Keyword = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Range")) @@ -790,7 +790,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.Range = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("PointDest")) @@ -799,7 +799,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + kt.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -808,7 +808,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + kt.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -817,7 +817,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -826,7 +826,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -835,7 +835,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + kt.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -844,7 +844,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + kt.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -853,7 +853,7 @@ namespace Server.Commands if (indexOf >= 0) { - kt.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + kt.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -873,7 +873,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); + tp.PointDest = Point3D.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("MapDest")) @@ -882,7 +882,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); + tp.MapDest = Map.Parse(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Creatures")) @@ -891,7 +891,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.Creatures = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SourceEffect")) @@ -900,7 +900,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.SourceEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("DestEffect")) @@ -909,7 +909,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); + tp.DestEffect = Utility.ToBoolean(m_Params[i][++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("SoundID")) @@ -918,7 +918,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + tp.SoundID = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); } } else if (m_Params[i].StartsWithOrdinal("Delay")) @@ -927,7 +927,7 @@ namespace Server.Commands if (indexOf >= 0) { - tp.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); + tp.Delay = TimeSpan.Parse(m_Params[i][++indexOf..]); } } } @@ -949,7 +949,7 @@ namespace Server.Commands { cont.ContentType = (FillableContentType)Enum.Parse( typeof(FillableContentType), - m_Params[i].Substring(++indexOf), + m_Params[i][++indexOf..], true ); } @@ -976,7 +976,7 @@ namespace Server.Commands if (indexOf >= 0) { - item.Light = (LightType)Enum.Parse(typeof(LightType), m_Params[i].Substring(++indexOf), true); + item.Light = (LightType)Enum.Parse(typeof(LightType), m_Params[i][++indexOf..], true); } } else if (m_Params[i].StartsWithOrdinal("Hue")) @@ -985,7 +985,7 @@ namespace Server.Commands if (indexOf >= 0) { - var hue = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + var hue = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); if (item is DyeTub tub) { @@ -1003,7 +1003,7 @@ namespace Server.Commands if (indexOf >= 0) { - item.Name = m_Params[i].Substring(++indexOf); + item.Name = m_Params[i][++indexOf..]; } } else if (m_Params[i].StartsWithOrdinal("Amount")) @@ -1017,7 +1017,7 @@ namespace Server.Commands var wasStackable = item.Stackable; item.Stackable = true; - item.Amount = Utility.ToInt32(m_Params[i].Substring(++indexOf)); + item.Amount = Utility.ToInt32(m_Params[i].AsSpan()[++indexOf..]); item.Stackable = wasStackable; } } @@ -1255,25 +1255,20 @@ namespace Server.Commands var indexOf = line.IndexOfOrdinal(' '); - list.m_Type = AssemblyHandler.FindTypeByName(line.Substring(0, indexOf++)); + list.m_Type = AssemblyHandler.FindTypeByName(line[..indexOf++]); if (list.m_Type == null) { throw new ArgumentException($"Type not found for header: '{line}'"); } - line = line.Substring(indexOf); + line = line[indexOf..]; indexOf = line.IndexOfOrdinal('('); if (indexOf >= 0) { - list.m_ItemID = Utility.ToInt32(line.Substring(0, indexOf - 1)); + list.m_ItemID = Utility.ToInt32(line.AsSpan()[..(indexOf - 1)]); - var parms = line.Substring(++indexOf); - - if (line.EndsWithOrdinal(")")) - { - parms = parms.Substring(0, parms.Length - 1); - } + var parms = line[++indexOf..^(line.EndsWithOrdinal(")") ? 1 : 0)]; list.m_Params = parms.Split(';'); @@ -1333,8 +1328,8 @@ namespace Server.Commands if (space >= 0) { - v = line.Substring(0, space++); - line = line.Substring(space); + v = line[..space++]; + line = line[space..]; } else { diff --git a/Projects/UOContent/Commands/Properties.cs b/Projects/UOContent/Commands/Properties.cs index 5fc33d304..4c856850a 100644 --- a/Projects/UOContent/Commands/Properties.cs +++ b/Projects/UOContent/Commands/Properties.cs @@ -223,7 +223,7 @@ namespace Server.Commands if (valueString.StartsWithOrdinal("0x")) { - realValues[i] = Convert.ToInt32(valueString.Substring(2), 16); + realValues[i] = Convert.ToInt32(valueString[2..], 16); } else { @@ -438,7 +438,7 @@ namespace Server.Commands { try { - toSet = Convert.ChangeType(Convert.ToUInt64(value.Substring(2), 16), type); + toSet = Convert.ChangeType(Convert.ToUInt64(value[2..], 16), type); } catch { diff --git a/Projects/UOContent/Commands/SignParser.cs b/Projects/UOContent/Commands/SignParser.cs index 7d1f91bf2..0fba2d29a 100644 --- a/Projects/UOContent/Commands/SignParser.cs +++ b/Projects/UOContent/Commands/SignParser.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using Server.Items; @@ -40,10 +41,8 @@ namespace Server.Commands var split = line.Split(' '); var e = new SignEntry( - line.Substring( - split[0].Length + 1 + split[1].Length + 1 + split[2].Length + 1 + - split[3].Length + 1 + split[4].Length + 1 - ), + line[(split[0].Length + 1 + split[1].Length + 1 + split[2].Length + 1 + + split[3].Length + 1 + split[4].Length + 1)..], new Point3D(Utility.ToInt32(split[2]), Utility.ToInt32(split[3]), Utility.ToInt32(split[4])), Utility.ToInt32(split[1]), Utility.ToInt32(split[0]) @@ -112,7 +111,7 @@ namespace Server.Commands if (name.StartsWithOrdinal("#")) { - sign = new LocalizedSign(itemID, Utility.ToInt32(name.Substring(1))); + sign = new LocalizedSign(itemID, Utility.ToInt32(name.AsSpan()[1..])); } else { @@ -121,14 +120,12 @@ namespace Server.Commands if (map == Map.Malas) { - if (location.X >= 965 && location.Y >= 502 && location.X <= 1012 && location.Y <= 537) + sign.Hue = location.X switch { - sign.Hue = 0x47E; - } - else if (location.X >= 1960 && location.Y >= 1278 && location.X < 2106 && location.Y < 1413) - { - sign.Hue = 0x44E; - } + >= 965 when location.Y >= 502 && location.X <= 1012 && location.Y <= 537 => 0x47E, + >= 1960 when location.Y >= 1278 && location.X < 2106 && location.Y < 1413 => 0x44E, + _ => sign.Hue + }; } sign.MoveToWorld(location, map); diff --git a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs index 9ec460a32..6ad18909a 100644 --- a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs +++ b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs @@ -325,7 +325,7 @@ namespace Server.Engines.BulkOrders { if (text.Length > 40) { - text = text.Substring(0, 40); + text = text[..40]; } if (from.CheckAlive() && m_Book.IsChildOf(from.Backpack)) diff --git a/Projects/UOContent/Engines/Chat/ChatActionHandlers.cs b/Projects/UOContent/Engines/Chat/ChatActionHandlers.cs index 472eb6ce2..309f59af0 100644 --- a/Projects/UOContent/Engines/Chat/ChatActionHandlers.cs +++ b/Projects/UOContent/Engines/Chat/ChatActionHandlers.cs @@ -86,8 +86,8 @@ namespace Server.Engines.Chat { var indexOf = param.IndexOfOrdinal(' '); - var name = param.Substring(0, indexOf); - var text = param.Substring(indexOf + 1); + var name = param[..indexOf]; + var text = param[(indexOf + 1)..]; var target = ChatSystem.SearchForUser(from, name); @@ -180,11 +180,11 @@ namespace Server.Engines.Chat if (end >= 0) { name = param.Substring(start, end - start); - password = param.Substring(++end); + password = param[++end..]; } else { - name = param.Substring(start); + name = param[start..]; } } else @@ -193,8 +193,8 @@ namespace Server.Engines.Chat if (indexOf >= 0) { - name = param.Substring(0, indexOf++); - password = param.Substring(indexOf); + name = param[..indexOf++]; + password = param[indexOf..]; } else { @@ -230,7 +230,7 @@ namespace Server.Engines.Chat if (start >= 0) { - name = param.Substring(0, start++); + name = param[..start++]; var end = param.IndexOf('}', start); diff --git a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs index 7aae32865..fb16c2c5d 100644 --- a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs +++ b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs @@ -529,7 +529,7 @@ namespace Server.Engines.Doom if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } state.Send(buffer); diff --git a/Projects/UOContent/Engines/ML Quests/Mobiles/SirHelper.cs b/Projects/UOContent/Engines/ML Quests/Mobiles/SirHelper.cs index 53243193c..872bbdf2a 100644 --- a/Projects/UOContent/Engines/ML Quests/Mobiles/SirHelper.cs +++ b/Projects/UOContent/Engines/ML Quests/Mobiles/SirHelper.cs @@ -110,7 +110,7 @@ namespace Server.Engines.MLQuests.Mobiles if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); + buffer = buffer[..length]; } state.Send(buffer); diff --git a/Projects/UOContent/Engines/Party/Party.cs b/Projects/UOContent/Engines/Party/Party.cs index fae2d5bad..2c3b1c0bd 100644 --- a/Projects/UOContent/Engines/Party/Party.cs +++ b/Projects/UOContent/Engines/Party/Party.cs @@ -246,7 +246,7 @@ namespace Server.Engines.PartySystem ); // : joined the party. - buffer = buffer.SliceToLength(length); + buffer = buffer[..length]; SendToAll(buffer); SendToAllListeners(buffer); @@ -388,7 +388,7 @@ namespace Server.Engines.PartySystem Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", args ); - buffer = buffer.SliceToLength(length); + buffer = buffer[..length]; SendToAll(buffer); SendToAllListeners(buffer); @@ -438,7 +438,7 @@ namespace Server.Engines.PartySystem if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } ns.Send(buffer); @@ -528,7 +528,7 @@ namespace Server.Engines.PartySystem if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } m.NetState?.Send(buffer); diff --git a/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs index 5a0c9e620..99c6c7da0 100644 --- a/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs +++ b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs @@ -74,8 +74,8 @@ namespace Server.Engines.Spawners if (setIndex > -1) { var start = setIndex + 4; - props = argSpan.Slice(start, argSpan.Length - start); - argSpan = argSpan.SliceToLength(setIndex); + props = argSpan[start..]; + argSpan = argSpan[..setIndex]; } var argStr = argSpan.ToString().DefaultIfNullOrEmpty(null); diff --git a/Projects/UOContent/Gumps/Guilds/GuildAbbrvPrompt.cs b/Projects/UOContent/Gumps/Guilds/GuildAbbrvPrompt.cs index 15dbd3ed9..08fb3a4a0 100644 --- a/Projects/UOContent/Gumps/Guilds/GuildAbbrvPrompt.cs +++ b/Projects/UOContent/Gumps/Guilds/GuildAbbrvPrompt.cs @@ -36,7 +36,7 @@ namespace Server.Gumps if (text.Length > 3) { - text = text.Substring(0, 3); + text = text[..3]; } if (text.Length > 0) diff --git a/Projects/UOContent/Gumps/Guilds/GuildCharterPrompt.cs b/Projects/UOContent/Gumps/Guilds/GuildCharterPrompt.cs index aa1af0613..3c9f3d919 100644 --- a/Projects/UOContent/Gumps/Guilds/GuildCharterPrompt.cs +++ b/Projects/UOContent/Gumps/Guilds/GuildCharterPrompt.cs @@ -36,7 +36,7 @@ namespace Server.Gumps if (text.Length > 50) { - text = text.Substring(0, 50); + text = text[..50]; } if (text.Length > 0) diff --git a/Projects/UOContent/Gumps/Guilds/GuildNamePrompt.cs b/Projects/UOContent/Gumps/Guilds/GuildNamePrompt.cs index 6255f6c09..86e0420a5 100644 --- a/Projects/UOContent/Gumps/Guilds/GuildNamePrompt.cs +++ b/Projects/UOContent/Gumps/Guilds/GuildNamePrompt.cs @@ -36,7 +36,7 @@ namespace Server.Gumps if (text.Length > 40) { - text = text.Substring(0, 40); + text = text[..40]; } if (text.Length > 0) diff --git a/Projects/UOContent/Gumps/Guilds/GuildTitlePrompt.cs b/Projects/UOContent/Gumps/Guilds/GuildTitlePrompt.cs index 80198e22a..b77b97743 100644 --- a/Projects/UOContent/Gumps/Guilds/GuildTitlePrompt.cs +++ b/Projects/UOContent/Gumps/Guilds/GuildTitlePrompt.cs @@ -48,7 +48,7 @@ namespace Server.Gumps if (text.Length > 20) { - text = text.Substring(0, 20); + text = text[..20]; } if (text.Length > 0) diff --git a/Projects/UOContent/Gumps/Guilds/GuildWebsitePrompt.cs b/Projects/UOContent/Gumps/Guilds/GuildWebsitePrompt.cs index b76a4168e..757679db1 100644 --- a/Projects/UOContent/Gumps/Guilds/GuildWebsitePrompt.cs +++ b/Projects/UOContent/Gumps/Guilds/GuildWebsitePrompt.cs @@ -36,7 +36,7 @@ namespace Server.Gumps if (text.Length > 50) { - text = text.Substring(0, 50); + text = text[..50]; } if (text.Length > 0) diff --git a/Projects/UOContent/Gumps/Props/PropsGump.cs b/Projects/UOContent/Gumps/Props/PropsGump.cs index f88c3880a..25c795312 100644 --- a/Projects/UOContent/Gumps/Props/PropsGump.cs +++ b/Projects/UOContent/Gumps/Props/PropsGump.cs @@ -678,10 +678,10 @@ namespace Server.Gumps { if (t == typeof(ulong) || t == typeof(uint) || t == typeof(ushort) || t == typeof(byte)) { - return Convert.ChangeType(Convert.ToUInt64(s.Substring(2), 16), t); + return Convert.ChangeType(Convert.ToUInt64(s[2..], 16), t); } - return Convert.ChangeType(Convert.ToInt64(s.Substring(2), 16), t); + return Convert.ChangeType(Convert.ToInt64(s[2..], 16), t); } return Convert.ChangeType(s, t); diff --git a/Projects/UOContent/Gumps/Props/SetBodyGump.cs b/Projects/UOContent/Gumps/Props/SetBodyGump.cs index de7f07dbe..917616e97 100644 --- a/Projects/UOContent/Gumps/Props/SetBodyGump.cs +++ b/Projects/UOContent/Gumps/Props/SetBodyGump.cs @@ -354,7 +354,7 @@ namespace Server.Gumps { if (DisplayName.StartsWithOrdinal(m_GroupNames[i])) { - DisplayName = DisplayName.Substring(m_GroupNames[i].Length); + DisplayName = DisplayName[m_GroupNames[i].Length..]; break; } } diff --git a/Projects/UOContent/Items/Body Parts/Head.cs b/Projects/UOContent/Items/Body Parts/Head.cs index 7eb019426..1bbba908d 100644 --- a/Projects/UOContent/Items/Body Parts/Head.cs +++ b/Projects/UOContent/Items/Body Parts/Head.cs @@ -81,17 +81,17 @@ namespace Server.Items { if (format.StartsWithOrdinal("the head of ")) { - format = format.Substring(14); // "the head of|..." + format = format[14..]; // "the head of|..." } if (format.EndsWithOrdinal(", taken in a duel")) { - format = format.Substring(0, format.Length - ", taken in a duel".Length); + format = format[..^", taken in a duel".Length]; HeadType = HeadType.Duel; } else if (format.EndsWithOrdinal(", taken in a tournament")) { - format = format.Substring(0, format.Length - ", taken in a tournament".Length); + format = format[..^", taken in a tournament".Length]; HeadType = HeadType.Tournament; } } diff --git a/Projects/UOContent/Items/Bulletin Boards/BulletinBoardPackets.cs b/Projects/UOContent/Items/Bulletin Boards/BulletinBoardPackets.cs index 206e70336..6332e217b 100644 --- a/Projects/UOContent/Items/Bulletin Boards/BulletinBoardPackets.cs +++ b/Projects/UOContent/Items/Bulletin Boards/BulletinBoardPackets.cs @@ -188,7 +188,7 @@ namespace Server.Network // We are ok with the string being cut-off mid character. The alternative is very slow. var byteLength = Math.Min(29, TextEncoding.UTF8.GetBytes(textChars, textBuffer)); - writer.Write(textBuffer.SliceToLength(byteLength)); + writer.Write(textBuffer[..byteLength]); writer.Clear(30 - byteLength); // terminator ns.Send(writer.Span); @@ -281,7 +281,7 @@ namespace Server.Network var tail = pad ? 2 : 1; var length = Math.Min(pad ? 253 : 254, text.GetBytesUtf8(buffer)); writer.Write((byte)(length + tail)); - writer.Write(buffer.SliceToLength(length)); + writer.Write(buffer[..length]); if (pad) { diff --git a/Projects/UOContent/Items/Guilds/GuildDeed.cs b/Projects/UOContent/Items/Guilds/GuildDeed.cs index a28b4d942..4413b4bbc 100644 --- a/Projects/UOContent/Items/Guilds/GuildDeed.cs +++ b/Projects/UOContent/Items/Guilds/GuildDeed.cs @@ -116,7 +116,7 @@ namespace Server.Items if (text.Length > 40) { - text = text.Substring(0, 40); + text = text[..40]; } var guild = new Guild(from, text, "none"); diff --git a/Projects/UOContent/Items/Misc/Blocker.cs b/Projects/UOContent/Items/Misc/Blocker.cs index 0ab6b0d6e..0960d1149 100644 --- a/Projects/UOContent/Items/Misc/Blocker.cs +++ b/Projects/UOContent/Items/Misc/Blocker.cs @@ -39,15 +39,15 @@ namespace Server.Items if (ns.StygianAbyss) { length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas); - BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId); + BinaryPrimitives.WriteUInt16BigEndian(buffer[8..10], GMItemId); } else { length = OutgoingItemPackets.CreateWorldItem(buffer, this); - BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId); + BinaryPrimitives.WriteUInt16BigEndian(buffer[7..9], GMItemId); } - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } public override void Serialize(IGenericWriter writer) diff --git a/Projects/UOContent/Items/Misc/LOSBlocker.cs b/Projects/UOContent/Items/Misc/LOSBlocker.cs index 3fe0cfb5e..2fff4a0bb 100644 --- a/Projects/UOContent/Items/Misc/LOSBlocker.cs +++ b/Projects/UOContent/Items/Misc/LOSBlocker.cs @@ -45,15 +45,15 @@ namespace Server.Items if (ns.StygianAbyss) { length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas); - BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId); + BinaryPrimitives.WriteUInt16BigEndian(buffer[8..10], GMItemId); } else { length = OutgoingItemPackets.CreateWorldItem(buffer, this); - BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId); + BinaryPrimitives.WriteUInt16BigEndian(buffer[7..2], GMItemId); } - ns.Send(buffer.SliceToLength(length)); + ns.Send(buffer[..length]); } public override void Serialize(IGenericWriter writer) diff --git a/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs b/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs index f48fdb506..d1499aabd 100644 --- a/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs +++ b/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs @@ -239,7 +239,7 @@ namespace Server.Items if (text.Length > 255) { - text = text.Substring(0, 255); + text = text[..255]; } if (text.Length > 0) @@ -316,7 +316,7 @@ namespace Server.Items if (text.Length > 255) { - text = text.Substring(0, 255); + text = text[..255]; } if (text.Length > 0) diff --git a/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs b/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs index 878e2876f..a9603d6af 100644 --- a/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs +++ b/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs @@ -302,7 +302,7 @@ namespace Server.Items else { m_Target.EngravedText = - Utility.FixHtml(relay.Text.Length > 64 ? relay.Text.Substring(0, 64) : relay.Text); + Utility.FixHtml(relay.Text.Length > 64 ? relay.Text[..64] : relay.Text); state.Mobile.SendLocalizedMessage(1072361); // You engraved the object. m_Target.InvalidateProperties(); m_Tool.UsesRemaining -= 1; diff --git a/Projects/UOContent/Misc/Guild.cs b/Projects/UOContent/Misc/Guild.cs index 97ce0fedc..b14275b41 100644 --- a/Projects/UOContent/Misc/Guild.cs +++ b/Projects/UOContent/Misc/Guild.cs @@ -353,7 +353,7 @@ namespace Server.Guilds if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } g.Members[j].NetState?.Send(buffer); @@ -1530,7 +1530,7 @@ namespace Server.Guilds if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } Members[i].NetState?.Send(buffer); diff --git a/Projects/UOContent/Misc/LootPack.cs b/Projects/UOContent/Misc/LootPack.cs index 585bc605b..027e1ffb7 100644 --- a/Projects/UOContent/Misc/LootPack.cs +++ b/Projects/UOContent/Misc/LootPack.cs @@ -1092,7 +1092,7 @@ namespace Server return; } - Count = Utility.ToInt32(str.Substring(start, index - start)); + Count = Utility.ToInt32(str.Substring(start, index)); start = index + 1; index = str.IndexOf('+', start); diff --git a/Projects/UOContent/Misc/Titles.cs b/Projects/UOContent/Misc/Titles.cs index cd1738569..16b3316e5 100644 --- a/Projects/UOContent/Misc/Titles.cs +++ b/Projects/UOContent/Misc/Titles.cs @@ -385,7 +385,7 @@ namespace Server.Misc if (mob.Female && skillTitle.EndsWithOrdinal("man")) { - skillTitle = $"{skillTitle.Substring(0, skillTitle.Length - 3)}woman"; + skillTitle = $"{skillTitle[..^3]}woman"; } return $"{skillLevel} {skillTitle}"; diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 5f10144d7..a6a97e5ec 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -2819,7 +2819,7 @@ namespace Server.Mobiles if (length != buffer.Length) { - buffer = buffer.SliceToLength(length); // Adjust to the actual size + buffer = buffer[..length]; // Adjust to the actual size } ns.Send(buffer); diff --git a/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs index 65ff4e537..0a9a02f5a 100644 --- a/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -393,7 +393,7 @@ namespace Server.Mobiles if (index != -1) { - Claim(e.Mobile, e.Speech.Substring(index).Trim()); + Claim(e.Mobile, e.Speech[index..].Trim()); } else { diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs index e8d0c1897..9e4d8c251 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs @@ -29,7 +29,7 @@ namespace Server.Mobiles { if (text.Length > 130) { - text = text.Substring(0, 130); + text = text[..130]; } m_Barkeeper.EndChangeRumor(from, m_RumorIndex, text); @@ -56,7 +56,7 @@ namespace Server.Mobiles { if (text.Length > 130) { - text = text.Substring(0, 130); + text = text[..130]; } m_Barkeeper.EndChangeKeyword(from, m_RumorIndex, text); @@ -78,7 +78,7 @@ namespace Server.Mobiles { if (text.Length > 130) { - text = text.Substring(0, 130); + text = text[..130]; } m_Barkeeper.EndChangeTip(from, text); diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs index 16fa11acf..99f2c8993 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs @@ -1443,13 +1443,13 @@ namespace Server.Mobiles string firstWord; var sep = text.IndexOfAny(new[] { ' ', ',' }); - firstWord = sep >= 0 ? text.Substring(0, sep) : text; + firstWord = sep >= 0 ? text[..sep] : text; string description; if (int.TryParse(firstWord, out var price)) { - description = sep >= 0 ? text.Substring(sep + 1).Trim() : ""; + description = sep >= 0 ? text[(sep + 1)..].Trim() : ""; } else { diff --git a/Projects/UOContent/Multis/Boats/BaseBoat.cs b/Projects/UOContent/Multis/Boats/BaseBoat.cs index 78c7178d8..a722b7999 100644 --- a/Projects/UOContent/Multis/Boats/BaseBoat.cs +++ b/Projects/UOContent/Multis/Boats/BaseBoat.cs @@ -858,7 +858,7 @@ namespace Server.Multis if (e.Speech.Length > 8) { - Rename(e.Speech.Substring(8).Trim().DefaultIfNullOrEmpty(null)); + Rename(e.Speech[8..].Trim().DefaultIfNullOrEmpty(null)); } } @@ -871,7 +871,7 @@ namespace Server.Multis if (newName?.Length > 40) { - newName = newName.Substring(0, 40); + newName = newName[..40]; } if (m_ShipName == newName) @@ -1005,7 +1005,7 @@ namespace Server.Multis if (start != -1) { - var sNumber = navPoint.Substring(start); + var sNumber = navPoint[start..]; if (!int.TryParse(sNumber, out number)) { diff --git a/Projects/UOContent/Multis/Houses/HousePackets.cs b/Projects/UOContent/Multis/Houses/HousePackets.cs index 0741d440d..3346758f8 100644 --- a/Projects/UOContent/Multis/Houses/HousePackets.cs +++ b/Projects/UOContent/Multis/Houses/HousePackets.cs @@ -250,7 +250,7 @@ namespace Server.Multis private static void WritePacked(ReadOnlySpan source, ref SpanWriter writer, out int length) { var size = source.Length; - var dest = writer.RawBuffer.Slice(writer.Position + 3); + var dest = writer.RawBuffer[(writer.Position + 3)..]; length = dest.Length; var ce = Zlib.Pack(dest, ref length, source, ZlibQuality.Default);