Skip to content

Commit

Permalink
Apply some ide warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Miepee committed Nov 12, 2023
1 parent 1beac06 commit 21a1d74
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 44 deletions.
10 changes: 5 additions & 5 deletions UndertaleModLib/Models/UndertaleCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ public string ToString(UndertaleCode code, List<uint> 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)
Expand Down Expand Up @@ -924,7 +924,7 @@ public string ToString(UndertaleCode code, List<uint> 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
Expand Down Expand Up @@ -954,20 +954,20 @@ public string ToString(UndertaleCode code, List<uint> blocks = null)
sb.Append(' ');
sb.Append(Function);
sb.Append("(argc=");
sb.Append(ArgumentsCount.ToString());
sb.Append(ArgumentsCount);
sb.Append(')');
break;

case InstructionType.BreakInstruction:
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;
Expand Down
6 changes: 2 additions & 4 deletions UndertaleModLib/Models/UndertaleEmbeddedTexture.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion UndertaleModLib/Models/UndertaleFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Serialize(UndertaleWriter writer)
writer.Write(addr);
}
else
writer.Write((int)-1);
writer.Write(-1);
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions UndertaleModLib/Models/UndertaleGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader)

public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> 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();
Expand All @@ -293,7 +293,7 @@ public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList<Underta
UndertaleCode code = action.CodeId;
if (code == null)
{
var name = strg.MakeString("gml_Object_" + Name.Content + "_" + type.ToString() + "_" + subtype);
var name = strg.MakeString("gml_Object_" + Name.Content + "_" + type + "_" + subtype);
code = new UndertaleCode()
{
Name = name,
Expand Down
12 changes: 6 additions & 6 deletions UndertaleModLib/Models/UndertaleGeneralInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,15 @@ public override string ToString()
else
sb.Append(" (GM ");
sb.Append(Major);
sb.Append(".");
sb.Append('.');
sb.Append(Minor);
if (Release != 0)
{
sb.Append(".");
sb.Append('.');
sb.Append(Release);
if (Build != 0)
{
sb.Append(".");
sb.Append('.');
sb.Append(Build);
}
}
Expand All @@ -608,7 +608,7 @@ public override string ToString()
sb.Append(", bytecode ");
sb.Append(BytecodeVersion);
}
sb.Append(")");
sb.Append(')');
return sb.ToString();
}
}
Expand Down Expand Up @@ -879,7 +879,7 @@ public void Serialize(UndertaleWriter writer)
/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
NewFormat = reader.ReadInt32() == int.MinValue;
NewFormat = reader.ReadInt32() == Int32.MinValue;
reader.Position -= 4;
if (NewFormat)
{
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 11 additions & 13 deletions UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1212,7 +1210,7 @@ public UndertaleBackground BackgroundDefinition
{
_backgroundDefinition.Resource = value;
OnPropertyChanged();
OnPropertyChanged("ObjectDefinition");
OnPropertyChanged(nameof(ObjectDefinition));
}
}

Expand All @@ -1226,7 +1224,7 @@ public UndertaleSprite SpriteDefinition
{
_spriteDefinition.Resource = value;
OnPropertyChanged();
OnPropertyChanged("ObjectDefinition");
OnPropertyChanged(nameof(ObjectDefinition));
}
}

Expand Down Expand Up @@ -1467,7 +1465,7 @@ public void UpdateParentRoom()
if (TilesData != null)
TilesData.ParentLayer = this;
}
public void UpdateZIndex() => OnPropertyChanged("LayerDepth");
public void UpdateZIndex() => OnPropertyChanged(nameof(LayerDepth));

/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
Expand Down Expand Up @@ -1669,7 +1667,7 @@ public uint TilesY
if (_tileData[y] == null)
_tileData[y] = new uint[TilesX];
}
OnPropertyChanged("TileData");
OnPropertyChanged(nameof(TileData));
}
}
}
Expand Down Expand Up @@ -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"));
}

/// <inheritdoc />
Expand Down Expand Up @@ -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"));
}

/// <inheritdoc />
Expand Down Expand Up @@ -2388,6 +2386,6 @@ public static class UndertaleRoomExtensions
{
public static T ByInstanceID<T>(this IList<T> list, uint instance) where T : UndertaleRoom.IRoomObject
{
return list.Where((x) => x.InstanceID == instance).FirstOrDefault();
return list.FirstOrDefault(x => x.InstanceID == instance);
}
}
16 changes: 8 additions & 8 deletions UndertaleModLib/Models/UndertaleSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -273,7 +273,7 @@ public enum TrackBuiltinName : int
}

[Flags]
public enum TrackTraits : int
public enum TrackTraits
{
None,
ChildrenIgnoreOrigin
Expand Down Expand Up @@ -657,7 +657,7 @@ public class Data : ResourceData<UndertaleResourceById<UndertaleSound, Undertale
public override void Serialize(UndertaleWriter writer)
{
base.Serialize(writer);
writer.Write((int)0);
writer.Write(0);
writer.Write(Mode);
}

Expand All @@ -671,7 +671,7 @@ public override void Unserialize(UndertaleReader reader)
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static new uint UnserializeChildObjectCount(UndertaleReader reader)
public new static uint UnserializeChildObjectCount(UndertaleReader reader)
{
uint count = ResourceData<UndertaleResourceById<UndertaleSound, UndertaleChunkSOND>>.UnserializeChildObjectCount(reader);

Expand Down Expand Up @@ -810,7 +810,7 @@ public override void Unserialize(UndertaleReader reader)
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static new uint UnserializeChildObjectCount(UndertaleReader reader)
public new static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 4; // "Value"

Expand Down Expand Up @@ -847,7 +847,7 @@ public override void Unserialize(UndertaleReader reader)
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static new uint UnserializeChildObjectCount(UndertaleReader reader)
public new static uint UnserializeChildObjectCount(UndertaleReader reader)
{
while (reader.AbsPosition % 4 != 0)
reader.Position++;
Expand Down Expand Up @@ -877,7 +877,7 @@ public override void Unserialize(UndertaleReader reader)
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static new uint UnserializeChildObjectCount(UndertaleReader reader)
public new static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 4; // "Value"

Expand Down Expand Up @@ -914,7 +914,7 @@ public override void Unserialize(UndertaleReader reader)
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static new uint UnserializeChildObjectCount(UndertaleReader reader)
public new static uint UnserializeChildObjectCount(UndertaleReader reader)
{
while (reader.AbsPosition % 4 != 0)
reader.Position++;
Expand Down
10 changes: 5 additions & 5 deletions UndertaleModLib/Models/UndertaleSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ public void Unserialize(UndertaleReader reader)
}
}

public enum UndertaleYYSWFItemType : int
public enum UndertaleYYSWFItemType
{
ItemInvalid,
ItemShape,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 21a1d74

Please sign in to comment.