Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bunch of random OpenDreamRuntime warnings #2136

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenDreamRuntime/DreamValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public override DreamValue Read(ref Utf8JsonReader reader, Type typeToConvert, J

DreamValue value;
switch (type) {
case DreamValue.DreamValueType.String: value = new DreamValue(reader.GetString()); break;
case DreamValue.DreamValueType.String: value = new DreamValue(reader.GetString() ?? string.Empty); break;
case DreamValue.DreamValueType.Float: value = new DreamValue(reader.GetSingle()); break;
case DreamValue.DreamValueType.DreamObject: {
string? objectTypePath = reader.GetString();
Expand Down
6 changes: 5 additions & 1 deletion OpenDreamRuntime/Objects/DreamObjectTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace OpenDreamRuntime.Objects;

public sealed class DreamObjectTree {
// These all get set when the JSON is loaded so just disable the pragma
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public TreeEntry[] Types { get; private set; }
public List<DreamProc> Procs { get; private set; } = new();
public List<string> Strings { get; private set; } //TODO: Store this somewhere else
Expand Down Expand Up @@ -50,6 +52,8 @@ public sealed class DreamObjectTree {
private readonly Dictionary<string, TreeEntry> _pathToType = new();
private Dictionary<string, int> _globalProcIds;

#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.

[Dependency] private readonly AtomManager _atomManager = default!;
[Dependency] private readonly DreamManager _dreamManager = default!;
[Dependency] private readonly IDreamMapManager _dreamMapManager = default!;
Expand Down Expand Up @@ -498,7 +502,7 @@ public sealed class TreeEntry {
public readonly string Path;
public readonly int Id;
public DreamObjectDefinition ObjectDefinition;
public TreeEntry ParentEntry;
public TreeEntry? ParentEntry;
public readonly List<int> InheritingTypes = new();

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamRuntime/Objects/Types/DreamObjectMob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public int SeeInvisible {
get => _sightComponent.SeeInvisibility;
private set {
_sightComponent.SeeInvisibility = (sbyte)value;
EntityManager.Dirty(_sightComponent);
EntityManager.Dirty(Entity, _sightComponent);
}
}

public SightFlags Sight {
get => _sightComponent.Sight;
private set {
_sightComponent.Sight = value;
EntityManager.Dirty(_sightComponent);
EntityManager.Dirty(Entity, _sightComponent);
}
}

Expand Down
4 changes: 3 additions & 1 deletion OpenDreamRuntime/Objects/Types/DreamObjectMovable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

[Virtual]
public class DreamObjectMovable : DreamObjectAtom {
[Dependency] private readonly SharedMapSystem _mapSystem = default!;

Check notice

Code scanning / InspectCode

Prefer using concrete value over 'default' or 'new()' Note

Use 'null' instead of 'default'
public EntityUid Entity;
public readonly DMISpriteComponent SpriteComponent;
public DreamObjectAtom? Loc;
Expand Down Expand Up @@ -198,7 +199,8 @@
TransformSystem.SetLocalPosition(Entity, Vector2.Zero);
break;
case null:
TransformSystem.SetParent(Entity, MapManager.GetMapEntityId(MapId.Nullspace));
_mapSystem.TryGetMap(MapId.Nullspace, out var mapId);
TransformSystem.SetParent(Entity, mapId!.Value);
break;
default:
throw new ArgumentException($"Invalid loc {loc}");
Expand Down
1 change: 1 addition & 0 deletions OpenDreamRuntime/OpenDreamRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Configurations>Debug;Release;Tools</Configurations>
<Platforms>AnyCPU</Platforms>
<NoWarn>NU1507</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DMCompiler\DMCompiler.csproj" />
Expand Down
12 changes: 6 additions & 6 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static ProcStatus CreateObject(DMProcState state) {
if (!loc.TryGetValueAsDreamObject<DreamObjectTurf>(out var turf))
ThrowInvalidTurfLoc(loc);

state.Proc.DreamMapManager.SetTurf(turf, objectDef, newArguments);
state.Proc.DreamMapManager.SetTurf(turf!, objectDef, newArguments);

state.Push(loc);
return ProcStatus.Continue;
Expand Down Expand Up @@ -1414,8 +1414,8 @@ public static ProcStatus Call(DMProcState state) {
DreamReference procRef = state.ReadReference();
var argumentInfo = state.ReadProcArguments();

DreamObject instance;
DreamProc proc;
DreamObject? instance;
DreamProc? proc;
switch (procRef.Type) {
case DMReference.Type.Self: {
instance = state.Instance;
Expand All @@ -1442,8 +1442,8 @@ public static ProcStatus Call(DMProcState state) {
}
case DMReference.Type.SrcProc: {
instance = state.Instance;
if (!instance.TryGetProc(state.ResolveString(procRef.Value), out proc))
throw new Exception($"Type {instance.ObjectDefinition.Type} has no proc called \"{state.ResolveString(procRef.Value)}\"");
if (instance is null || !instance.TryGetProc(state.ResolveString(procRef.Value), out proc))
throw new Exception($"Type {instance?.ObjectDefinition.Type ?? "<unknown type>"} has no proc called \"{state.ResolveString(procRef.Value)}\"");

break;
}
Expand Down Expand Up @@ -2386,7 +2386,7 @@ public static ProcStatus BrowseResource(DMProcState state) {
throw new Exception("Invalid browse_rsc() recipient");
}

connection?.BrowseResource(file, filename.IsNull ? Path.GetFileName(file.ResourcePath) : filename.GetValueAsString());
connection?.BrowseResource(file, (filename.IsNull ? Path.GetFileName(file.ResourcePath) : filename.MustGetValueAsString())!);
return ProcStatus.Continue;
}

Expand Down
13 changes: 8 additions & 5 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace OpenDreamRuntime.Procs.Native;
/// Note that this proc container also includes global procs which are used to create some DM objects,
/// like filter(), matrix(), etc.
/// </remarks>
internal static class DreamProcNativeRoot {
internal static partial class DreamProcNativeRoot {
private static readonly DreamResourceManager _resourceManager = IoCManager.Resolve<DreamResourceManager>();

[DreamProc("alert")]
Expand Down Expand Up @@ -156,7 +156,7 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
return DreamValue.Null;
chainAnim = true;
}

bundle.LastAnimatedObject = new DreamValue(obj);
if(obj.IsSubtypeOf(bundle.ObjectTree.Filter)) {//TODO animate filters
return DreamValue.Null;
Expand Down Expand Up @@ -466,7 +466,7 @@ public static DreamValue NativeProc_ckeyEx(NativeProc.Bundle bundle, DreamObject
return DreamValue.Null;
}

text = Regex.Replace(text, "[\\^]|[^A-z0-9@_-]", ""); //Remove all punctuation except - and _
text = CkeyExRegex().Replace(text, ""); //Remove all punctuation except - and _
return new DreamValue(text);
}

Expand Down Expand Up @@ -3196,8 +3196,8 @@ public static async Task<DreamValue> NativeProc_winget(AsyncNativeProc.State sta
public static DreamValue NativeProc_winset(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) {
DreamValue player = bundle.GetArgument(0, "player");
DreamValue controlId = bundle.GetArgument(1, "control_id");
string? winsetControlId = (!controlId.IsNull) ? controlId.GetValueAsString() : null;
string winsetParams = bundle.GetArgument(2, "params").GetValueAsString();
string? winsetControlId = (!controlId.IsNull) ? controlId.MustGetValueAsString() : null;
string winsetParams = bundle.GetArgument(2, "params").MustGetValueAsString();

DreamConnection? connection = null;
if (player.TryGetValueAsDreamObject<DreamObjectMob>(out var mob)) {
Expand All @@ -3213,4 +3213,7 @@ public static DreamValue NativeProc_winset(NativeProc.Bundle bundle, DreamObject
connection.WinSet(winsetControlId, winsetParams);
return DreamValue.Null;
}

[GeneratedRegex("[\\^]|[^A-z0-9@_-]")]
private static partial Regex CkeyExRegex();
}
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Procs/NativeProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
private readonly Dictionary<string, DreamValue>? _defaultArgumentValues;
private readonly delegate*<Bundle, DreamObject?, DreamObject?, DreamValue> _handler;

public NativeProc(int id, TreeEntry owningType, string name, List<string> argumentNames, Dictionary<string, DreamValue> defaultArgumentValues, HandlerFn handler, DreamManager dreamManager, AtomManager atomManager, IDreamMapManager mapManager, DreamResourceManager resourceManager, WalkManager walkManager, DreamObjectTree objectTree)
public NativeProc(int id, TreeEntry owningType, string name, List<string> argumentNames, Dictionary<string, DreamValue>? defaultArgumentValues, HandlerFn handler, DreamManager dreamManager, AtomManager atomManager, IDreamMapManager mapManager, DreamResourceManager resourceManager, WalkManager walkManager, DreamObjectTree objectTree)
Fixed Show fixed Hide fixed
: base(id, owningType, name, null, ProcAttributes.None, argumentNames, null, null, null, null, null, 0) {
_defaultArgumentValues = defaultArgumentValues;
_handler = (delegate*<Bundle, DreamObject?, DreamObject?, DreamValue>)handler.Method.MethodHandle.GetFunctionPointer();
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Resources/ConsoleOutputResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenDreamRuntime.Resources;
sealed class ConsoleOutputResource : DreamResource {
public ConsoleOutputResource() : base(0, null, null) { }

public override string ReadAsString() {
public override string? ReadAsString() {
return null;
}

Expand Down
Loading