From 21a1d74a8ba9c59a79ecd2494b0a649a6840d2cf Mon Sep 17 00:00:00 2001 From: Miepee Date: Sun, 12 Nov 2023 01:22:50 +0100 Subject: [PATCH 1/2] Apply some ide warnings --- UndertaleModLib/Models/UndertaleCode.cs | 10 ++++---- .../Models/UndertaleEmbeddedTexture.cs | 6 ++--- UndertaleModLib/Models/UndertaleFunction.cs | 2 +- UndertaleModLib/Models/UndertaleGameObject.cs | 4 ++-- .../Models/UndertaleGeneralInfo.cs | 12 +++++----- UndertaleModLib/Models/UndertaleRoom.cs | 24 +++++++++---------- UndertaleModLib/Models/UndertaleSequence.cs | 16 ++++++------- UndertaleModLib/Models/UndertaleSprite.cs | 10 ++++---- 8 files changed, 40 insertions(+), 44 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleCode.cs b/UndertaleModLib/Models/UndertaleCode.cs index b351b718c..dbedb4abb 100644 --- a/UndertaleModLib/Models/UndertaleCode.cs +++ b/UndertaleModLib/Models/UndertaleCode.cs @@ -876,7 +876,7 @@ public string ToString(UndertaleCode code, List blocks = null) if (Kind == Opcode.Dup || Kind == Opcode.CallV) { sb.Append(' '); - sb.Append(Extra.ToString()); + sb.Append(Extra); if (Kind == Opcode.Dup) { if ((byte)ComparisonKind != 0) @@ -924,7 +924,7 @@ public string ToString(UndertaleCode code, List blocks = null) { // Special scenario - the swap instruction // TODO: Figure out the proper syntax, see #129 - sb.Append(SwapExtra.ToString()); + sb.Append(SwapExtra); sb.Append(" ;;; this is a weird swap instruction, see #129"); } else @@ -954,7 +954,7 @@ public string ToString(UndertaleCode code, List blocks = null) sb.Append(' '); sb.Append(Function); sb.Append("(argc="); - sb.Append(ArgumentsCount.ToString()); + sb.Append(ArgumentsCount); sb.Append(')'); break; @@ -962,12 +962,12 @@ public string ToString(UndertaleCode code, List blocks = null) sb.Append("." + Type1.ToOpcodeParam()); if (unknownBreak) { - sb.Append(" "); + sb.Append(' '); sb.Append(Value); } if (Type1 == DataType.Int32) { - sb.Append(" "); + sb.Append(' '); sb.Append(IntArgument); } break; diff --git a/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs b/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs index 2f32ca83c..0bc4b1e92 100644 --- a/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs +++ b/UndertaleModLib/Models/UndertaleEmbeddedTexture.cs @@ -1,14 +1,12 @@ using ICSharpCode.SharpZipLib.BZip2; using System; using System.Buffers.Binary; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Text; using UndertaleModLib.Util; namespace UndertaleModLib.Models; @@ -121,7 +119,7 @@ public void Serialize(UndertaleWriter writer) writer.Write(IndexInGroup); } if (TextureExternal) - writer.Write((int)0); // Ensure null pointer is written with external texture + writer.Write(0); // Ensure null pointer is written with external texture else writer.WriteUndertaleObjectPointer(_textureData); } @@ -246,7 +244,7 @@ public TexData LoadExternalTexture() // Try to find file on disk string path = Path.Combine(_2022_9_GameDirectory, TextureInfo.Directory.Content, - TextureInfo.Name.Content + "_" + IndexInGroup.ToString() + TextureInfo.Extension.Content); + TextureInfo.Name.Content + "_" + IndexInGroup + TextureInfo.Extension.Content); if (!File.Exists(path)) return _placeholderTexture; diff --git a/UndertaleModLib/Models/UndertaleFunction.cs b/UndertaleModLib/Models/UndertaleFunction.cs index 50cb49dc7..ecbf4d4ab 100644 --- a/UndertaleModLib/Models/UndertaleFunction.cs +++ b/UndertaleModLib/Models/UndertaleFunction.cs @@ -52,7 +52,7 @@ public void Serialize(UndertaleWriter writer) writer.Write(addr); } else - writer.Write((int)-1); + writer.Write(-1); } /// diff --git a/UndertaleModLib/Models/UndertaleGameObject.cs b/UndertaleModLib/Models/UndertaleGameObject.cs index 2e93cfa2a..34940aee4 100644 --- a/UndertaleModLib/Models/UndertaleGameObject.cs +++ b/UndertaleModLib/Models/UndertaleGameObject.cs @@ -281,7 +281,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList strg, IList codelist, IList localslist) { - Event subtypeObj = Events[(int)type].Where((x) => x.EventSubtype == subtype).FirstOrDefault(); + Event subtypeObj = Events[(int)type].FirstOrDefault(x => x.EventSubtype == subtype); if (subtypeObj == null) Events[(int)type].Add(subtypeObj = new Event() { EventSubtype = subtype }); EventAction action = subtypeObj.Actions.FirstOrDefault(); @@ -293,7 +293,7 @@ public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList public void Unserialize(UndertaleReader reader) { - NewFormat = reader.ReadInt32() == int.MinValue; + NewFormat = reader.ReadInt32() == Int32.MinValue; reader.Position -= 4; if (NewFormat) { @@ -945,7 +945,7 @@ public void Unserialize(UndertaleReader reader) public static uint UnserializeChildObjectCount(UndertaleReader reader) { uint count = 0; - bool newFormat = reader.ReadInt32() == int.MinValue; + bool newFormat = reader.ReadInt32() == Int32.MinValue; reader.Position -= 4; reader.Position += newFormat ? 60u : 140u; diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 8bd414477..004918884 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -237,11 +237,9 @@ public Layer BGColorLayer { get { - return _layers?.Where(l => l.LayerType is LayerType.Background - && l.BackgroundData.Sprite is null - && l.BackgroundData.Color != 0) - .OrderBy(l => l.LayerDepth) - .FirstOrDefault(); + return (_layers?.Where(l => l.LayerType is LayerType.Background + && l.BackgroundData.Sprite is null + && l.BackgroundData.Color != 0)).MinBy(l => l.LayerDepth); } } @@ -430,7 +428,7 @@ public void Unserialize(UndertaleReader reader) && layer.InstancesData.InstanceIds[0] > GameObjects[^1].InstanceID) { // Make sure it's not a false positive - uint firstLayerInstID = layer.InstancesData.InstanceIds.OrderBy(x => x).First(); + uint firstLayerInstID = layer.InstancesData.InstanceIds.MinBy(x => x); uint lastInstID = GameObjects.OrderBy(x => x.InstanceID).Last().InstanceID; if (firstLayerInstID > lastInstID) { @@ -1212,7 +1210,7 @@ public UndertaleBackground BackgroundDefinition { _backgroundDefinition.Resource = value; OnPropertyChanged(); - OnPropertyChanged("ObjectDefinition"); + OnPropertyChanged(nameof(ObjectDefinition)); } } @@ -1226,7 +1224,7 @@ public UndertaleSprite SpriteDefinition { _spriteDefinition.Resource = value; OnPropertyChanged(); - OnPropertyChanged("ObjectDefinition"); + OnPropertyChanged(nameof(ObjectDefinition)); } } @@ -1467,7 +1465,7 @@ public void UpdateParentRoom() if (TilesData != null) TilesData.ParentLayer = this; } - public void UpdateZIndex() => OnPropertyChanged("LayerDepth"); + public void UpdateZIndex() => OnPropertyChanged(nameof(LayerDepth)); /// public void Serialize(UndertaleWriter writer) @@ -1669,7 +1667,7 @@ public uint TilesY if (_tileData[y] == null) _tileData[y] = new uint[TilesX]; } - OnPropertyChanged("TileData"); + OnPropertyChanged(nameof(TileData)); } } } @@ -2198,7 +2196,7 @@ public void Unserialize(UndertaleReader reader) public static UndertaleString GenerateRandomName(UndertaleData data) { // The same format as in "GameMaker Studio: 2". - return data.Strings.MakeString("graphic_" + ((uint)Random.Shared.Next(-int.MaxValue, int.MaxValue)).ToString("X8")); + return data.Strings.MakeString("graphic_" + ((uint)Random.Shared.Next(-Int32.MaxValue, Int32.MaxValue)).ToString("X8")); } /// @@ -2358,7 +2356,7 @@ public void Unserialize(UndertaleReader reader) public static UndertaleString GenerateRandomName(UndertaleData data) { - return data.Strings.MakeString("particle_" + ((uint)Random.Shared.Next(-int.MaxValue, int.MaxValue)).ToString("X8")); + return data.Strings.MakeString("particle_" + ((uint)Random.Shared.Next(-Int32.MaxValue, Int32.MaxValue)).ToString("X8")); } /// @@ -2388,6 +2386,6 @@ public static class UndertaleRoomExtensions { public static T ByInstanceID(this IList list, uint instance) where T : UndertaleRoom.IRoomObject { - return list.Where((x) => x.InstanceID == instance).FirstOrDefault(); + return list.FirstOrDefault(x => x.InstanceID == instance); } } \ No newline at end of file diff --git a/UndertaleModLib/Models/UndertaleSequence.cs b/UndertaleModLib/Models/UndertaleSequence.cs index 40612b895..34c41f766 100644 --- a/UndertaleModLib/Models/UndertaleSequence.cs +++ b/UndertaleModLib/Models/UndertaleSequence.cs @@ -249,7 +249,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) public class Track : UndertaleObject { - public enum TrackBuiltinName : int + public enum TrackBuiltinName { Gain = 5, Pitch = 6, @@ -273,7 +273,7 @@ public enum TrackBuiltinName : int } [Flags] - public enum TrackTraits : int + public enum TrackTraits { None, ChildrenIgnoreOrigin @@ -657,7 +657,7 @@ public class Data : ResourceData - public static new uint UnserializeChildObjectCount(UndertaleReader reader) + public new static uint UnserializeChildObjectCount(UndertaleReader reader) { uint count = ResourceData>.UnserializeChildObjectCount(reader); @@ -810,7 +810,7 @@ public override void Unserialize(UndertaleReader reader) } /// - public static new uint UnserializeChildObjectCount(UndertaleReader reader) + public new static uint UnserializeChildObjectCount(UndertaleReader reader) { reader.Position += 4; // "Value" @@ -847,7 +847,7 @@ public override void Unserialize(UndertaleReader reader) } /// - public static new uint UnserializeChildObjectCount(UndertaleReader reader) + public new static uint UnserializeChildObjectCount(UndertaleReader reader) { while (reader.AbsPosition % 4 != 0) reader.Position++; @@ -877,7 +877,7 @@ public override void Unserialize(UndertaleReader reader) } /// - public static new uint UnserializeChildObjectCount(UndertaleReader reader) + public new static uint UnserializeChildObjectCount(UndertaleReader reader) { reader.Position += 4; // "Value" @@ -914,7 +914,7 @@ public override void Unserialize(UndertaleReader reader) } /// - public static new uint UnserializeChildObjectCount(UndertaleReader reader) + public new static uint UnserializeChildObjectCount(UndertaleReader reader) { while (reader.AbsPosition % 4 != 0) reader.Position++; diff --git a/UndertaleModLib/Models/UndertaleSprite.cs b/UndertaleModLib/Models/UndertaleSprite.cs index 0cf7ad974..bcad338d2 100644 --- a/UndertaleModLib/Models/UndertaleSprite.cs +++ b/UndertaleModLib/Models/UndertaleSprite.cs @@ -379,11 +379,11 @@ public void Serialize(UndertaleWriter writer) if (SVersion >= 2) { sequencePatchPos = writer.Position; - writer.Write((int)0); + writer.Write(0); if (SVersion >= 3) { nineSlicePatchPos = writer.Position; - writer.Write((int)0); + writer.Write(0); } } } @@ -458,7 +458,7 @@ public void Serialize(UndertaleWriter writer) writer.Position = sequencePatchPos; writer.Write(returnTo); writer.Position = returnTo; - writer.Write((int)1); + writer.Write(1); writer.WriteUndertaleObject(V2Sequence); } if (nineSlicePatchPos != 0 && V3NineSlice != null) @@ -1079,7 +1079,7 @@ public void Unserialize(UndertaleReader reader) } } -public enum UndertaleYYSWFItemType : int +public enum UndertaleYYSWFItemType { ItemInvalid, ItemShape, @@ -1913,7 +1913,7 @@ public void Serialize(UndertaleWriter writer) public void Unserialize(UndertaleReader reader) { reader.Align(4); - int jpeglen = reader.ReadInt32() & (~int.MinValue); // the length is ORed with int.MinValue. + int jpeglen = reader.ReadInt32() & (~Int32.MinValue); // the length is ORed with int.MinValue. Version = reader.ReadInt32(); Util.DebugUtil.Assert(Version == 8 || Version == 7, "Invalid YYSWF version data! Expected 7 or 8, got " + Version); From 2042bfe7946ede051c38ae1ebe6120fc85a914e9 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:36:30 +0100 Subject: [PATCH 2/2] Apply formatting suggestion from Vlad Co-authored-by: Vladislav Stepanov --- UndertaleModLib/Models/UndertaleRoom.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 004918884..1a6af6958 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -239,7 +239,8 @@ public Layer BGColorLayer { return (_layers?.Where(l => l.LayerType is LayerType.Background && l.BackgroundData.Sprite is null - && l.BackgroundData.Color != 0)).MinBy(l => l.LayerDepth); + && l.BackgroundData.Color != 0)) + .MinBy(l => l.LayerDepth); } }