diff --git a/Content.Tests/Content.Tests.csproj b/Content.Tests/Content.Tests.csproj index 29f7538883..91e6aa6080 100644 --- a/Content.Tests/Content.Tests.csproj +++ b/Content.Tests/Content.Tests.csproj @@ -1,4 +1,4 @@ - + $(TargetFramework) @@ -24,6 +24,7 @@ + diff --git a/Content.Tests/DummyDreamMapManager.cs b/Content.Tests/DummyDreamMapManager.cs index 76b812bee5..1b23088ed4 100644 --- a/Content.Tests/DummyDreamMapManager.cs +++ b/Content.Tests/DummyDreamMapManager.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using DMCompiler.Json; +using OpenDreamShared.Common.Json; using OpenDreamRuntime.Map; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; diff --git a/Content.Tests/RuntimeTests.cs b/Content.Tests/RuntimeTests.cs index 81e6e9f46e..ea6103c753 100644 --- a/Content.Tests/RuntimeTests.cs +++ b/Content.Tests/RuntimeTests.cs @@ -1,6 +1,6 @@ using System; -using DMCompiler.Bytecode; using NUnit.Framework; +using OpenDreamShared.Common.Bytecode; namespace Content.Tests; diff --git a/DMCompiler/Compiler/DM/AST/DMAST.Expression.cs b/DMCompiler/Compiler/DM/AST/DMAST.Expression.cs index f880bfe587..d3686d1e79 100644 --- a/DMCompiler/Compiler/DM/AST/DMAST.Expression.cs +++ b/DMCompiler/Compiler/DM/AST/DMAST.Expression.cs @@ -1,5 +1,5 @@ using System.Linq; -using DMCompiler.DM; +using OpenDreamShared.Common.DM; namespace DMCompiler.Compiler.DM.AST; diff --git a/DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs b/DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs index c025bcf7e6..c6d58a2a58 100644 --- a/DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs +++ b/DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs @@ -1,4 +1,5 @@ using DMCompiler.DM; +using OpenDreamShared.Common; namespace DMCompiler.Compiler.DM.AST; diff --git a/DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs b/DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs index 37067a9929..4c0892306d 100644 --- a/DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs +++ b/DMCompiler/Compiler/DM/AST/DMAST.ProcStatements.cs @@ -1,4 +1,5 @@ using DMCompiler.DM; +using OpenDreamShared.Common; namespace DMCompiler.Compiler.DM.AST; diff --git a/DMCompiler/Compiler/DM/AST/DMAST.cs b/DMCompiler/Compiler/DM/AST/DMAST.cs index 993e2b28fa..d6909afc67 100644 --- a/DMCompiler/Compiler/DM/AST/DMAST.cs +++ b/DMCompiler/Compiler/DM/AST/DMAST.cs @@ -1,4 +1,5 @@ using DMCompiler.DM; +using OpenDreamShared.Common; namespace DMCompiler.Compiler.DM.AST; diff --git a/DMCompiler/Compiler/DM/DMParser.cs b/DMCompiler/Compiler/DM/DMParser.cs index ec01b396ae..cae417a6c7 100644 --- a/DMCompiler/Compiler/DM/DMParser.cs +++ b/DMCompiler/Compiler/DM/DMParser.cs @@ -2,6 +2,8 @@ using System.Linq; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; namespace DMCompiler.Compiler.DM { internal partial class DMParser(DMCompiler compiler, DMLexer lexer) : Parser(compiler, lexer) { diff --git a/DMCompiler/Compiler/DM/DMParserHelper.cs b/DMCompiler/Compiler/DM/DMParserHelper.cs index 38799187f7..89002e66fb 100644 --- a/DMCompiler/Compiler/DM/DMParserHelper.cs +++ b/DMCompiler/Compiler/DM/DMParserHelper.cs @@ -1,8 +1,8 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; -using DMCompiler.Bytecode; using DMCompiler.Compiler.DM.AST; +using OpenDreamShared.Common.Bytecode; namespace DMCompiler.Compiler.DM; diff --git a/DMCompiler/Compiler/DM/DMPath.cs b/DMCompiler/Compiler/DM/DMPath.cs index d5e2265dd7..8a93946f4b 100644 --- a/DMCompiler/Compiler/DM/DMPath.cs +++ b/DMCompiler/Compiler/DM/DMPath.cs @@ -1,4 +1,6 @@ -namespace DMCompiler.Compiler.DM; +using OpenDreamShared.Common; + +namespace DMCompiler.Compiler.DM; internal abstract class VarDeclInfo { public DreamPath? TypePath; diff --git a/DMCompiler/Compiler/DMM/DMMParser.cs b/DMCompiler/Compiler/DMM/DMMParser.cs index bf089252ed..d834280951 100644 --- a/DMCompiler/Compiler/DMM/DMMParser.cs +++ b/DMCompiler/Compiler/DMM/DMMParser.cs @@ -1,7 +1,8 @@ using DMCompiler.Compiler.DM; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM.Builders; -using DMCompiler.Json; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Json; namespace DMCompiler.Compiler.DMM; diff --git a/DMCompiler/DM/Builders/DMCodeTreeBuilder.cs b/DMCompiler/DM/Builders/DMCodeTreeBuilder.cs index 2bf56a8b6f..6ef8916121 100644 --- a/DMCompiler/DM/Builders/DMCodeTreeBuilder.cs +++ b/DMCompiler/DM/Builders/DMCodeTreeBuilder.cs @@ -1,4 +1,5 @@ using DMCompiler.Compiler.DM.AST; +using OpenDreamShared.Common; namespace DMCompiler.DM.Builders; diff --git a/DMCompiler/DM/Builders/DMExpressionBuilder.cs b/DMCompiler/DM/Builders/DMExpressionBuilder.cs index 68452219d2..6c650fe90a 100644 --- a/DMCompiler/DM/Builders/DMExpressionBuilder.cs +++ b/DMCompiler/DM/Builders/DMExpressionBuilder.cs @@ -4,6 +4,8 @@ using DMCompiler.DM.Expressions; using static DMCompiler.DM.Builders.DMExpressionBuilder.ScopeMode; using String = DMCompiler.DM.Expressions.String; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; namespace DMCompiler.DM.Builders; diff --git a/DMCompiler/DM/Builders/DMProcBuilder.cs b/DMCompiler/DM/Builders/DMProcBuilder.cs index ef305dcfe6..b0c82ef81a 100644 --- a/DMCompiler/DM/Builders/DMProcBuilder.cs +++ b/DMCompiler/DM/Builders/DMProcBuilder.cs @@ -1,9 +1,11 @@ using System.Diagnostics; -using DMCompiler.Bytecode; using DMCompiler.Compiler; using DMCompiler.Compiler.DM; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM.Expressions; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.DM.Builders { internal sealed class DMProcBuilder(DMCompiler compiler, DMObject dmObject, DMProc proc) { diff --git a/DMCompiler/DM/DMCodeTree.Procs.cs b/DMCompiler/DM/DMCodeTree.Procs.cs index 174ff77c9b..0a9cd6ef17 100644 --- a/DMCompiler/DM/DMCodeTree.Procs.cs +++ b/DMCompiler/DM/DMCodeTree.Procs.cs @@ -1,5 +1,6 @@ using DMCompiler.Compiler; using DMCompiler.Compiler.DM.AST; +using OpenDreamShared.Common; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMCodeTree.Vars.cs b/DMCompiler/DM/DMCodeTree.Vars.cs index bc8f31e653..c0c83b3bdf 100644 --- a/DMCompiler/DM/DMCodeTree.Vars.cs +++ b/DMCompiler/DM/DMCodeTree.Vars.cs @@ -1,9 +1,11 @@ using System.Diagnostics.CodeAnalysis; -using DMCompiler.Bytecode; using DMCompiler.Compiler; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM.Builders; using DMCompiler.DM.Expressions; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; using ScopeMode = DMCompiler.DM.Builders.DMExpressionBuilder.ScopeMode; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMCodeTree.cs b/DMCompiler/DM/DMCodeTree.cs index a4a1459b8e..fdb4d0a9fc 100644 --- a/DMCompiler/DM/DMCodeTree.cs +++ b/DMCompiler/DM/DMCodeTree.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using DMCompiler.Compiler; using DMCompiler.DM.Builders; +using OpenDreamShared.Common; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMValueType.cs b/DMCompiler/DM/DMComplexValueType.cs similarity index 61% rename from DMCompiler/DM/DMValueType.cs rename to DMCompiler/DM/DMComplexValueType.cs index 61f23652aa..e522c70911 100644 --- a/DMCompiler/DM/DMValueType.cs +++ b/DMCompiler/DM/DMComplexValueType.cs @@ -1,35 +1,7 @@ -namespace DMCompiler.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; -// If you are modifying this, you must also modify OpenDreamShared.Dream.DreamValueType !! -// Unfortunately the client needs this and it can't reference DMCompiler due to the sandbox - -/// -///Stores any explicit casting done via the "as" keyword. Also stores compiler hints for DMStandard.
-///is a [Flags] enum because it's possible for something to have multiple values (especially with the quirky DMStandard ones) -///
-[Flags] -public enum DMValueType { - Anything = 0x0, - Null = 0x1, - Text = 0x2, - Obj = 0x4, - Mob = 0x8, - Turf = 0x10, - Num = 0x20, - Message = 0x40, - Area = 0x80, - Color = 0x100, - File = 0x200, - CommandText = 0x400, - Sound = 0x800, - Icon = 0x1000, - Path = 0x2000, // For proc return types - - //Byond here be dragons - Unimplemented = 0x4000, // Marks that a method or property is not implemented. Throws a compiler warning if accessed. - CompiletimeReadonly = 0x8000, // Marks that a property can only ever be read from, never written to. This is a const-ier version of const, for certain standard values like list.type - NoConstFold = 0x10000 // Marks that a const var cannot be const-folded during compile -} +namespace DMCompiler.DM; /// /// Allows for more complex things than DMValueType does, such as supporting type paths diff --git a/DMCompiler/DM/DMExpression.cs b/DMCompiler/DM/DMExpression.cs index 73de3895ba..2ce0ee4fc6 100644 --- a/DMCompiler/DM/DMExpression.cs +++ b/DMCompiler/DM/DMExpression.cs @@ -1,7 +1,9 @@ -using DMCompiler.Bytecode; using System.Diagnostics.CodeAnalysis; using DMCompiler.Compiler; using DMCompiler.DM.Expressions; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMObject.cs b/DMCompiler/DM/DMObject.cs index 10834f8433..ae691f11a8 100644 --- a/DMCompiler/DM/DMObject.cs +++ b/DMCompiler/DM/DMObject.cs @@ -1,7 +1,9 @@ using System.Linq; -using DMCompiler.Bytecode; using DMCompiler.DM.Expressions; -using DMCompiler.Json; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common.Json; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMObjectTree.cs b/DMCompiler/DM/DMObjectTree.cs index 1d763352b5..c5d17b70ec 100644 --- a/DMCompiler/DM/DMObjectTree.cs +++ b/DMCompiler/DM/DMObjectTree.cs @@ -1,7 +1,8 @@ using System.Diagnostics.CodeAnalysis; using DMCompiler.Compiler; using DMCompiler.Compiler.DM.AST; -using DMCompiler.Json; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Json; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/DMProc.cs b/DMCompiler/DM/DMProc.cs index 73600868a1..9dd6db7f20 100644 --- a/DMCompiler/DM/DMProc.cs +++ b/DMCompiler/DM/DMProc.cs @@ -1,12 +1,14 @@ -using DMCompiler.Bytecode; using System.Diagnostics.CodeAnalysis; using System.Linq; using DMCompiler.DM.Expressions; using DMCompiler.Compiler; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM.Builders; -using DMCompiler.Json; using DMCompiler.Optimizer; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Json; namespace DMCompiler.DM { internal sealed class DMProc { diff --git a/DMCompiler/DM/DMVariable.cs b/DMCompiler/DM/DMVariable.cs index dc5cd772cc..372176cd56 100644 --- a/DMCompiler/DM/DMVariable.cs +++ b/DMCompiler/DM/DMVariable.cs @@ -1,4 +1,6 @@ -using System.Diagnostics.CodeAnalysis; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; +using System.Diagnostics.CodeAnalysis; namespace DMCompiler.DM; diff --git a/DMCompiler/DM/Expressions/Binary.cs b/DMCompiler/DM/Expressions/Binary.cs index 0d9420faeb..dad19853cf 100644 --- a/DMCompiler/DM/Expressions/Binary.cs +++ b/DMCompiler/DM/Expressions/Binary.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using DMCompiler.Bytecode; using DMCompiler.Compiler; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DM/Expressions/Builtins.cs b/DMCompiler/DM/Expressions/Builtins.cs index 6092ce591d..6af684b8cc 100644 --- a/DMCompiler/DM/Expressions/Builtins.cs +++ b/DMCompiler/DM/Expressions/Builtins.cs @@ -1,7 +1,9 @@ -using DMCompiler.Bytecode; using System.Diagnostics.CodeAnalysis; using DMCompiler.Compiler; -using DMCompiler.Json; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common.Json; namespace DMCompiler.DM.Expressions; @@ -61,7 +63,7 @@ public void EmitPushArglist(ExpressionContext ctx) { internal sealed class New(DMCompiler compiler, Location location, DMExpression expr, ArgumentList arguments) : DMExpression(location) { public override DreamPath? Path => expr.Path; public override bool PathIsFuzzy => Path == null; - public override DMComplexValueType ValType => !expr.ValType.IsAnything ? expr.ValType : (Path?.GetAtomType(compiler) ?? DMValueType.Anything); + public override DMComplexValueType ValType => !expr.ValType.IsAnything ? expr.ValType : (compiler.GetAtomType(Path) ?? DMValueType.Anything); public override void EmitPushValue(ExpressionContext ctx) { var argumentInfo = arguments.EmitArguments(ctx, null); @@ -74,7 +76,7 @@ public override void EmitPushValue(ExpressionContext ctx) { // new /x/y/z (...) internal sealed class NewPath(DMCompiler compiler, Location location, IConstantPath create, ArgumentList arguments) : DMExpression(location) { public override DreamPath? Path => (create is ConstantTypeReference typeReference) ? typeReference.Path : null; - public override DMComplexValueType ValType => Path?.GetAtomType(compiler) ?? DMValueType.Anything; + public override DMComplexValueType ValType => compiler.GetAtomType(Path) ?? DMValueType.Anything; public override void EmitPushValue(ExpressionContext ctx) { DMCallArgumentsType argumentsType; diff --git a/DMCompiler/DM/Expressions/Constant.cs b/DMCompiler/DM/Expressions/Constant.cs index 5b169cce5b..5fdf4e6532 100644 --- a/DMCompiler/DM/Expressions/Constant.cs +++ b/DMCompiler/DM/Expressions/Constant.cs @@ -1,7 +1,9 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using DMCompiler.Compiler; -using DMCompiler.Json; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common.Json; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DM/Expressions/Dereference.cs b/DMCompiler/DM/Expressions/Dereference.cs index 06338f2468..22363a3487 100644 --- a/DMCompiler/DM/Expressions/Dereference.cs +++ b/DMCompiler/DM/Expressions/Dereference.cs @@ -1,7 +1,9 @@ -using DMCompiler.Bytecode; using System.Diagnostics.CodeAnalysis; using System.Linq; using DMCompiler.Compiler; +using OpenDreamShared.Common; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common.Bytecode; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DM/Expressions/LValue.cs b/DMCompiler/DM/Expressions/LValue.cs index afae2566f9..8ed0c15d2f 100644 --- a/DMCompiler/DM/Expressions/LValue.cs +++ b/DMCompiler/DM/Expressions/LValue.cs @@ -1,6 +1,8 @@ using System.Diagnostics.CodeAnalysis; -using DMCompiler.Bytecode; using DMCompiler.Compiler; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DM/Expressions/Procs.cs b/DMCompiler/DM/Expressions/Procs.cs index ba5105dba0..bd19edee0c 100644 --- a/DMCompiler/DM/Expressions/Procs.cs +++ b/DMCompiler/DM/Expressions/Procs.cs @@ -1,6 +1,8 @@ using System.Linq; -using DMCompiler.Bytecode; using DMCompiler.Compiler; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DM/Expressions/Unary.cs b/DMCompiler/DM/Expressions/Unary.cs index f6b07c94fb..e81c6d74a9 100644 --- a/DMCompiler/DM/Expressions/Unary.cs +++ b/DMCompiler/DM/Expressions/Unary.cs @@ -1,5 +1,5 @@ using System.Diagnostics.CodeAnalysis; -using DMCompiler.Bytecode; +using OpenDreamShared.Common.Bytecode; namespace DMCompiler.DM.Expressions; diff --git a/DMCompiler/DMCompiler.cs b/DMCompiler/DMCompiler.cs index 3168999d35..fe607caeff 100644 --- a/DMCompiler/DMCompiler.cs +++ b/DMCompiler/DMCompiler.cs @@ -1,4 +1,3 @@ -using DMCompiler.Bytecode; using DMCompiler.Compiler.DM; using DMCompiler.Compiler.DMM; using DMCompiler.Compiler.DMPreprocessor; @@ -13,8 +12,12 @@ using DMCompiler.Compiler; using DMCompiler.Compiler.DM.AST; using DMCompiler.DM.Builders; -using DMCompiler.Json; using DMCompiler.Optimizer; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Json; +using OpenDreamShared.Common.Bytecode; +using OpenDreamNoClient.Bytecode; namespace DMCompiler; @@ -78,7 +81,7 @@ public bool Compile(DMCompilerSettings settings) { if (ErrorCount > 0) { successfulCompile = false; } else { - var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile); + var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile, new OpcodeVerifier()); if (ErrorCount > 0) { successfulCompile = false; } else { @@ -294,10 +297,10 @@ private List ConvertMaps(DMCompiler compiler, List mapPath return maps; } - private string SaveJson(List maps, string interfaceFile, string outputFile) { + private string SaveJson(List maps, string? interfaceFile, string outputFile, IOpcodeVerifier verifier) { var jsonRep = DMObjectTree.CreateJsonRepresentation(); var compiledDream = new DreamCompiledJson { - Metadata = new DreamCompiledJsonMetadata { Version = OpcodeVerifier.GetOpcodesHash() }, + Metadata = new DreamCompiledJsonMetadata { Version = verifier.GetOpcodesHash() }, Strings = DMObjectTree.StringTable, Resources = DMObjectTree.Resources.ToArray(), Maps = maps, @@ -389,6 +392,26 @@ public ErrorLevel CodeToLevel(WarningCode code) { return ret; } + + public DMValueType? GetAtomType(DreamPath? path) { + if (path == null) { + return null; + } + + if (!DMObjectTree.TryGetDMObject((DreamPath)path, out var dmType)) + return DMValueType.Anything; + + if (dmType.IsSubtypeOf(DreamPath.Obj)) + return DMValueType.Obj; + if (dmType.IsSubtypeOf(DreamPath.Mob)) + return DMValueType.Mob; + if (dmType.IsSubtypeOf(DreamPath.Turf)) + return DMValueType.Turf; + if (dmType.IsSubtypeOf(DreamPath.Area)) + return DMValueType.Area; + + return DMValueType.Anything; + } } public struct DMCompilerSettings { diff --git a/DMCompiler/DMCompiler.csproj b/DMCompiler/DMCompiler.csproj index 77c99f54e8..b2b408eb79 100644 --- a/DMCompiler/DMCompiler.csproj +++ b/DMCompiler/DMCompiler.csproj @@ -13,6 +13,11 @@ + + + + + diff --git a/DMCompiler/Optimizer/AnnotatedByteCodeWriter.cs b/DMCompiler/Optimizer/AnnotatedByteCodeWriter.cs index 7b5b3631a0..16e1371219 100644 --- a/DMCompiler/Optimizer/AnnotatedByteCodeWriter.cs +++ b/DMCompiler/Optimizer/AnnotatedByteCodeWriter.cs @@ -1,6 +1,8 @@ -using DMCompiler.Bytecode; using DMCompiler.Compiler; using DMCompiler.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.Optimizer; diff --git a/DMCompiler/Optimizer/AnnotatedBytecode.cs b/DMCompiler/Optimizer/AnnotatedBytecode.cs index 3bb38adb09..710b0f59ec 100644 --- a/DMCompiler/Optimizer/AnnotatedBytecode.cs +++ b/DMCompiler/Optimizer/AnnotatedBytecode.cs @@ -1,6 +1,7 @@ using System.Diagnostics.Contracts; -using DMCompiler.Bytecode; -using DMCompiler.DM; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace DMCompiler.Optimizer; diff --git a/DMCompiler/Optimizer/AnnotatedBytecodeSerializer.cs b/DMCompiler/Optimizer/AnnotatedBytecodeSerializer.cs index 497a31d558..e36e7ebb0f 100644 --- a/DMCompiler/Optimizer/AnnotatedBytecodeSerializer.cs +++ b/DMCompiler/Optimizer/AnnotatedBytecodeSerializer.cs @@ -1,7 +1,7 @@ using System.IO; -using DMCompiler.Bytecode; using DMCompiler.Compiler; -using DMCompiler.Json; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.Json; namespace DMCompiler.Optimizer; diff --git a/DMCompiler/Optimizer/BytecodeOptimizer.cs b/DMCompiler/Optimizer/BytecodeOptimizer.cs index cfed5be887..fee683e6e7 100644 --- a/DMCompiler/Optimizer/BytecodeOptimizer.cs +++ b/DMCompiler/Optimizer/BytecodeOptimizer.cs @@ -1,3 +1,4 @@ +using OpenDreamShared.Common.Bytecode; using System.Diagnostics.CodeAnalysis; namespace DMCompiler.Optimizer; @@ -54,7 +55,7 @@ private void RemoveUnreferencedLabels(List input) { */ private void RemoveImmediateJumps(List input) { for (int i = input.Count - 2; i >= 0; i--) { - if (input[i] is AnnotatedBytecodeInstruction { Opcode: Bytecode.DreamProcOpcode.Jump } instruction) { + if (input[i] is AnnotatedBytecodeInstruction { Opcode: DreamProcOpcode.Jump } instruction) { if (input[i + 1] is AnnotatedBytecodeLabel followingLabel) { AnnotatedBytecodeLabel jumpLabelName = instruction.GetArg(0); if (jumpLabelName.LabelName == followingLabel.LabelName) { diff --git a/DMCompiler/Optimizer/CompactorOptimizations.cs b/DMCompiler/Optimizer/CompactorOptimizations.cs index 9a6525e2fa..c6402f4484 100644 --- a/DMCompiler/Optimizer/CompactorOptimizations.cs +++ b/DMCompiler/Optimizer/CompactorOptimizations.cs @@ -1,4 +1,4 @@ -using DMCompiler.Bytecode; +using OpenDreamShared.Common.Bytecode; // ReSharper disable UnusedType.Global diff --git a/DMCompiler/Optimizer/OpcodeMetadataCache.cs b/DMCompiler/Optimizer/OpcodeMetadataCache.cs new file mode 100644 index 0000000000..045e61c494 --- /dev/null +++ b/DMCompiler/Optimizer/OpcodeMetadataCache.cs @@ -0,0 +1,24 @@ +using OpenDreamShared.Common.Bytecode; + +namespace DMCompiler.Optimizer; + +/// +/// Automatically builds a cache of the attribute for each opcode +/// +public static class OpcodeMetadataCache { + private static readonly OpcodeMetadata[] MetadataCache = new OpcodeMetadata[256]; + + static OpcodeMetadataCache() { + foreach (DreamProcOpcode opcode in Enum.GetValues(typeof(DreamProcOpcode))) { + var field = typeof(DreamProcOpcode).GetField(opcode.ToString()); + var attribute = Attribute.GetCustomAttribute(field!, typeof(OpcodeMetadataAttribute)); + var metadataAttribute = (OpcodeMetadataAttribute?)attribute; + MetadataCache[(byte)opcode] = metadataAttribute?.Metadata ?? new OpcodeMetadata(); + MetadataCache[(byte)opcode] = metadataAttribute?.Metadata ?? new OpcodeMetadata(); + } + } + + public static OpcodeMetadata GetMetadata(DreamProcOpcode opcode) { + return MetadataCache[(byte)opcode]; + } +} diff --git a/DMCompiler/Optimizer/PeepholeOptimizations.cs b/DMCompiler/Optimizer/PeepholeOptimizations.cs index 9341de9fa4..4e90ba8d43 100644 --- a/DMCompiler/Optimizer/PeepholeOptimizations.cs +++ b/DMCompiler/Optimizer/PeepholeOptimizations.cs @@ -1,4 +1,4 @@ -using DMCompiler.Bytecode; +using OpenDreamShared.Common.Bytecode; // ReSharper disable UnusedType.Global diff --git a/DMCompiler/Optimizer/PeepholeOptimizer.cs b/DMCompiler/Optimizer/PeepholeOptimizer.cs index 73eb36c776..9efa52dee7 100644 --- a/DMCompiler/Optimizer/PeepholeOptimizer.cs +++ b/DMCompiler/Optimizer/PeepholeOptimizer.cs @@ -1,5 +1,5 @@ using System.Runtime.CompilerServices; -using DMCompiler.Bytecode; +using OpenDreamShared.Common.Bytecode; namespace DMCompiler.Optimizer; diff --git a/DMDisassembler/DMDisassembler.csproj b/DMDisassembler/DMDisassembler.csproj index 6e56f0e729..d570979a53 100644 --- a/DMDisassembler/DMDisassembler.csproj +++ b/DMDisassembler/DMDisassembler.csproj @@ -11,6 +11,7 @@ + diff --git a/DMDisassembler/DMProc.cs b/DMDisassembler/DMProc.cs index 44e9d12b0a..35aeaf5df1 100644 --- a/DMDisassembler/DMProc.cs +++ b/DMDisassembler/DMProc.cs @@ -2,9 +2,9 @@ using System; using System.Collections.Generic; using System.Text; -using DMCompiler.DM; -using DMCompiler.Json; using JetBrains.Annotations; +using OpenDreamShared.Common.Json; +using OpenDreamShared.Common.DM; namespace DMDisassembler; diff --git a/DMDisassembler/DMType.cs b/DMDisassembler/DMType.cs index d7a9dd56f4..74688266a7 100644 --- a/DMDisassembler/DMType.cs +++ b/DMDisassembler/DMType.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using DMCompiler.Json; +using OpenDreamShared.Common.Json; +using System.Collections.Generic; namespace DMDisassembler; diff --git a/DMDisassembler/Program.cs b/DMDisassembler/Program.cs index 58be41ff93..10959c97df 100644 --- a/DMDisassembler/Program.cs +++ b/DMDisassembler/Program.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Text; using System.Text.Json; -using DMCompiler.Bytecode; -using DMCompiler.Json; using JetBrains.Annotations; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.Json; namespace DMDisassembler; diff --git a/OpenDream.sln b/OpenDream.sln index aaeca98e9f..1ae1b55afd 100644 --- a/OpenDream.sln +++ b/OpenDream.sln @@ -102,6 +102,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackageTool", "Ope EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Xaml", "RobustToolbox\Robust.Xaml\Robust.Xaml.csproj", "{62F71077-77A6-4F0F-9A47-AA341668E194}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamNoClient", "OpenDreamNoClient\OpenDreamNoClient.csproj", "{CCBE231F-192D-4CDB-8931-555B04B56534}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamShared.Common", "OpenDreamShared.Common\OpenDreamShared.Common.csproj", "{F1781BFF-D0C9-4666-BE0D-447C06CDB821}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -441,6 +445,26 @@ Global {62F71077-77A6-4F0F-9A47-AA341668E194}.Release|x64.Build.0 = Release|Any CPU {62F71077-77A6-4F0F-9A47-AA341668E194}.Tools|Any CPU.ActiveCfg = Debug|Any CPU {62F71077-77A6-4F0F-9A47-AA341668E194}.Tools|Any CPU.Build.0 = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Debug|x64.ActiveCfg = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Debug|x64.Build.0 = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Release|Any CPU.Build.0 = Release|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Release|x64.ActiveCfg = Release|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Release|x64.Build.0 = Release|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Tools|Any CPU.ActiveCfg = Debug|Any CPU + {CCBE231F-192D-4CDB-8931-555B04B56534}.Tools|Any CPU.Build.0 = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Debug|x64.ActiveCfg = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Debug|x64.Build.0 = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Release|Any CPU.Build.0 = Release|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Release|x64.ActiveCfg = Release|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Release|x64.Build.0 = Release|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Tools|Any CPU.ActiveCfg = Debug|Any CPU + {F1781BFF-D0C9-4666-BE0D-447C06CDB821}.Tools|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OpenDreamClient/ClientVerbSystem.cs b/OpenDreamClient/ClientVerbSystem.cs index 7927fdaf41..a13b84a61c 100644 --- a/OpenDreamClient/ClientVerbSystem.cs +++ b/OpenDreamClient/ClientVerbSystem.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using OpenDreamClient.Interface; using OpenDreamClient.Rendering; +using OpenDreamShared.Common.DM; using OpenDreamShared.Dream; using OpenDreamShared.Rendering; using Robust.Client.GameObjects; @@ -138,7 +139,7 @@ public IEnumerable GetAllVerbs() { /// The ID, src, and information of every executable verb public IEnumerable<(int Id, ClientObjectReference Src, VerbInfo VerbInfo)> GetExecutableVerbs(ClientObjectReference target) { foreach (var verb in GetExecutableVerbs()) { - DreamValueType? targetType = verb.VerbInfo.GetTargetType(); + DMValueType? targetType = verb.VerbInfo.GetTargetType(); if (targetType == null) { // Verbs without a target but an "in view()/range()" accessibility will still show if (verb.Src.Equals(target) && @@ -150,7 +151,7 @@ is VerbAccessibility.InRange or VerbAccessibility.InORange continue; } - if (targetType == DreamValueType.Anything) { + if (targetType == DMValueType.Anything) { yield return verb; } else { switch (target.Type) { @@ -158,14 +159,14 @@ is VerbAccessibility.InRange or VerbAccessibility.InORange var entity = _entityManager.GetEntity(target.Entity); var isMob = _entityManager.HasComponent(entity); - if ((targetType & DreamValueType.Mob) != 0x0 && isMob) + if ((targetType & DMValueType.Mob) != 0x0 && isMob) yield return verb; - if ((targetType & DreamValueType.Obj) != 0x0 && !isMob) + if ((targetType & DMValueType.Obj) != 0x0 && !isMob) yield return verb; break; case ClientObjectReference.RefType.Turf: - if ((targetType & DreamValueType.Turf) != 0x0) + if ((targetType & DMValueType.Turf) != 0x0) yield return verb; break; diff --git a/OpenDreamClient/Interface/DreamInterfaceManager.cs b/OpenDreamClient/Interface/DreamInterfaceManager.cs index 708b51ced5..a23820b775 100644 --- a/OpenDreamClient/Interface/DreamInterfaceManager.cs +++ b/OpenDreamClient/Interface/DreamInterfaceManager.cs @@ -21,6 +21,7 @@ using Robust.Shared.Utility; using SixLabors.ImageSharp; using System.Linq; +using OpenDreamShared.Common.DM; using Robust.Shared.Map; namespace OpenDreamClient.Interface; @@ -149,7 +150,7 @@ private void RxAlert(MsgAlert message) { (responseType, response) => OnPromptFinished(message.PromptId, responseType, response)); } - public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose) { + public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose) { var alert = new AlertWindow( title, message, @@ -161,7 +162,7 @@ public void OpenAlert(string title, string message, string button1, string? butt } private void RxPrompt(MsgPrompt pPrompt) { - void OnPromptClose(DreamValueType responseType, object? response) { + void OnPromptClose(DMValueType responseType, object? response) { OnPromptFinished(pPrompt.PromptId, responseType, response); } @@ -242,7 +243,7 @@ private void RxWinExists(MsgWinExists message) { InterfaceElement? element = FindElementWithId(message.ControlId); MsgPromptResponse response = new() { PromptId = message.PromptId, - Type = DreamValueType.Text, + Type = DMValueType.Text, Value = element?.Type.Value ?? string.Empty }; @@ -254,7 +255,7 @@ private void RxWinGet(MsgWinGet message) { _timerManager.AddTimer(new Timer(100, false, () => { MsgPromptResponse response = new() { PromptId = message.PromptId, - Type = DreamValueType.Text, + Type = DMValueType.Text, Value = WinGet(message.ControlId, message.QueryValue, forceSnowflake:true) }; @@ -418,17 +419,17 @@ public void SaveScreenshot(bool openDialog) { }); } - public void Prompt(DreamValueType types, string title, string message, string defaultValue, Action? onClose) { + public void Prompt(DMValueType types, string title, string message, string defaultValue, Action? onClose) { PromptWindow? prompt = null; - bool canCancel = (types & DreamValueType.Null) == DreamValueType.Null; + bool canCancel = (types & DMValueType.Null) == DMValueType.Null; - if ((types & DreamValueType.Text) == DreamValueType.Text) { + if ((types & DMValueType.Text) == DMValueType.Text) { prompt = new TextPrompt(title, message, defaultValue, canCancel, onClose); - } else if ((types & DreamValueType.Num) == DreamValueType.Num) { + } else if ((types & DMValueType.Num) == DMValueType.Num) { prompt = new NumberPrompt(title, message, defaultValue, canCancel, onClose); - } else if ((types & DreamValueType.Message) == DreamValueType.Message) { + } else if ((types & DMValueType.Message) == DMValueType.Message) { prompt = new MessagePrompt(title, message, defaultValue, canCancel, onClose); - } else if ((types & DreamValueType.Color) == DreamValueType.Color) { + } else if ((types & DMValueType.Color) == DMValueType.Color) { prompt = new ColorPrompt(title, message, defaultValue, canCancel, onClose); } @@ -520,11 +521,11 @@ public void RunCommand(string fullCommand) { var arguments = new object?[verbInfo.Arguments.Length]; for (int i = 0; i < verbInfo.Arguments.Length; i++) { - DreamValueType argumentType = verbInfo.Arguments[i].Types; + DMValueType argumentType = verbInfo.Arguments[i].Types; - if (argumentType is DreamValueType.Text or DreamValueType.Message or DreamValueType.CommandText) { + if (argumentType is DMValueType.Text or DMValueType.Message or DMValueType.CommandText) { arguments[i] = args[i]; - } else if (argumentType == DreamValueType.Num) { + } else if (argumentType == DMValueType.Num) { if (!float.TryParse(args[i], out var numArg)) { _sawmill.Error( $"Invalid number argument \"{args[i]}\"; ignoring command ({fullCommand})"); @@ -965,7 +966,7 @@ private void LoadDescriptor(ElementDescriptor descriptor) { } } - private void OnPromptFinished(int promptId, DreamValueType responseType, object? response) { + private void OnPromptFinished(int promptId, DMValueType responseType, object? response) { var msg = new MsgPromptResponse { PromptId = promptId, Type = responseType, @@ -993,8 +994,8 @@ public interface IDreamInterfaceManager { void SaveScreenshot(bool openDialog); void LoadInterfaceFromSource(string source); - public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose); - public void Prompt(DreamValueType types, string title, string message, string defaultValue, Action? onClose); + public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose); + public void Prompt(DMValueType types, string title, string message, string defaultValue, Action? onClose); public void RunCommand(string fullCommand); public void StartRepeatingCommand(string command); public void StopRepeatingCommand(string command); diff --git a/OpenDreamClient/Interface/DummyDreamInterfaceManager.cs b/OpenDreamClient/Interface/DummyDreamInterfaceManager.cs index ebba9c9ccd..4cb2a89401 100644 --- a/OpenDreamClient/Interface/DummyDreamInterfaceManager.cs +++ b/OpenDreamClient/Interface/DummyDreamInterfaceManager.cs @@ -1,4 +1,5 @@ using OpenDreamClient.Interface.Controls; +using OpenDreamShared.Common.DM; using OpenDreamShared.Dream; using OpenDreamShared.Network.Messages; using Robust.Shared.Network; @@ -46,10 +47,10 @@ public string WinGet(string controlId, string queryValue, bool forceJson = false return string.Empty; } - public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose) { + public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action? onClose) { } - public void Prompt(DreamValueType types, string title, string message, string defaultValue, Action? onClose) { + public void Prompt(DMValueType types, string title, string message, string defaultValue, Action? onClose) { } public void RunCommand(string fullCommand) { diff --git a/OpenDreamClient/Interface/Prompts/AlertWindow.cs b/OpenDreamClient/Interface/Prompts/AlertWindow.cs index 0d3f95f538..4e029832a9 100644 --- a/OpenDreamClient/Interface/Prompts/AlertWindow.cs +++ b/OpenDreamClient/Interface/Prompts/AlertWindow.cs @@ -1,11 +1,12 @@ using JetBrains.Annotations; +using OpenDreamShared.Common.DM; using OpenDreamShared.Dream; using Robust.Shared.Console; namespace OpenDreamClient.Interface.Prompts; internal sealed class AlertWindow : PromptWindow { - public AlertWindow(string title, string message, string button1, string? button2, string? button3, Action? onClose) : + public AlertWindow(string title, string message, string button1, string? button2, string? button3, Action? onClose) : base(title, message, onClose) { CreateButton(button1, true); if (!string.IsNullOrEmpty(button2)) CreateButton(button2, false); @@ -13,7 +14,7 @@ public AlertWindow(string title, string message, string button1, string? button2 } protected override void ButtonClicked(string button) { - FinishPrompt(DreamValueType.Text, button); + FinishPrompt(DMValueType.Text, button); base.ButtonClicked(button); } diff --git a/OpenDreamClient/Interface/Prompts/ColorPrompt.cs b/OpenDreamClient/Interface/Prompts/ColorPrompt.cs index 072f0ddee6..3067854932 100644 --- a/OpenDreamClient/Interface/Prompts/ColorPrompt.cs +++ b/OpenDreamClient/Interface/Prompts/ColorPrompt.cs @@ -1,5 +1,5 @@ using System.Linq; -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; @@ -16,7 +16,7 @@ internal sealed class ColorPrompt : InputWindow { private readonly Color _originalColor; public ColorPrompt(string title, string message, string defaultValue, bool canCancel, - Action? onClose, bool alpha = false) : base(title, message, canCancel, onClose) { + Action? onClose, bool alpha = false) : base(title, message, canCancel, onClose) { _originalColor = Color.FromHex(defaultValue, Color.White); _colorSelector = new() { Color = _originalColor, @@ -76,7 +76,7 @@ private void LineEdit_OnFinishInput(LineEdit.LineEditEventArgs args) { } protected override void OkButtonClicked() { - FinishPrompt(DreamValueType.Color, _colorSelector.Color); + FinishPrompt(DMValueType.Color, _colorSelector.Color); } } diff --git a/OpenDreamClient/Interface/Prompts/InputWindow.cs b/OpenDreamClient/Interface/Prompts/InputWindow.cs index c0b853f978..e54ab09005 100644 --- a/OpenDreamClient/Interface/Prompts/InputWindow.cs +++ b/OpenDreamClient/Interface/Prompts/InputWindow.cs @@ -1,4 +1,4 @@ -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.UserInterface; namespace OpenDreamClient.Interface.Prompts; @@ -6,7 +6,7 @@ namespace OpenDreamClient.Interface.Prompts; [Virtual] internal class InputWindow : PromptWindow { protected InputWindow(string title, string message, bool canCancel, - Action? onClose) : base(title, message, onClose) { + Action? onClose) : base(title, message, onClose) { CreateButton("Ok", true); if (canCancel) CreateButton("Cancel", false); } @@ -19,7 +19,7 @@ protected void SetPromptControl(Control promptControl, bool grabKeyboard = true) protected override void ButtonClicked(string button) { if (button == "Ok") OkButtonClicked(); - else FinishPrompt(DreamValueType.Null, null); + else FinishPrompt(DMValueType.Null, null); base.ButtonClicked(button); } diff --git a/OpenDreamClient/Interface/Prompts/ListPrompt.cs b/OpenDreamClient/Interface/Prompts/ListPrompt.cs index e9c2b04943..be3367dc85 100644 --- a/OpenDreamClient/Interface/Prompts/ListPrompt.cs +++ b/OpenDreamClient/Interface/Prompts/ListPrompt.cs @@ -1,4 +1,4 @@ -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input; @@ -9,7 +9,7 @@ internal sealed class ListPrompt : InputWindow { private readonly ItemList _itemList; public ListPrompt(string title, string message, string defaultValue, bool canCancel, string[] values, - Action? onClose) : base(title, message, canCancel, onClose) { + Action? onClose) : base(title, message, canCancel, onClose) { _itemList = new ItemList(); // don't make it as long as the width // really this should check for fontHeight not hacky const 24 @@ -38,7 +38,7 @@ public ListPrompt(string title, string message, string defaultValue, bool canCan if (!item.Selected) continue; - FinishPrompt(DreamValueType.Num, (float)_itemList.IndexOf(item)); + FinishPrompt(DMValueType.Num, (float)_itemList.IndexOf(item)); return; } @@ -48,7 +48,8 @@ public ListPrompt(string title, string message, string defaultValue, bool canCan private void ItemList_KeyBindDown(GUIBoundKeyEventArgs e) { if (e.Function == EngineKeyFunctions.TextSubmit) { e.Handle(); - ButtonClicked(DefaultButton); + if (DefaultButton != null) + ButtonClicked(DefaultButton); } } } diff --git a/OpenDreamClient/Interface/Prompts/MessagePrompt.cs b/OpenDreamClient/Interface/Prompts/MessagePrompt.cs index 8876d00fff..5001a90fd9 100644 --- a/OpenDreamClient/Interface/Prompts/MessagePrompt.cs +++ b/OpenDreamClient/Interface/Prompts/MessagePrompt.cs @@ -1,4 +1,4 @@ -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.UserInterface.Controls; using Robust.Shared.Utility; @@ -8,7 +8,7 @@ internal sealed class MessagePrompt : InputWindow { private readonly TextEdit _textEdit; public MessagePrompt(string title, string message, string defaultValue, bool canCancel, - Action? onClose) : base(title, message, canCancel, onClose) { + Action? onClose) : base(title, message, canCancel, onClose) { _textEdit = new TextEdit { TextRope = new Rope.Leaf(defaultValue), @@ -21,6 +21,6 @@ public MessagePrompt(string title, string message, string defaultValue, bool can } protected override void OkButtonClicked() { - FinishPrompt(DreamValueType.Message, Rope.Collapse(_textEdit.TextRope)); + FinishPrompt(DMValueType.Message, Rope.Collapse(_textEdit.TextRope)); } } diff --git a/OpenDreamClient/Interface/Prompts/NumberPrompt.cs b/OpenDreamClient/Interface/Prompts/NumberPrompt.cs index a7da6c444e..8e09bac204 100644 --- a/OpenDreamClient/Interface/Prompts/NumberPrompt.cs +++ b/OpenDreamClient/Interface/Prompts/NumberPrompt.cs @@ -1,4 +1,4 @@ -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.UserInterface.Controls; namespace OpenDreamClient.Interface.Prompts; @@ -7,7 +7,7 @@ internal sealed class NumberPrompt : InputWindow { private readonly LineEdit _numberInput; public NumberPrompt(string title, string message, string defaultValue, bool canCancel, - Action? onClose) : base(title, message, canCancel, onClose) { + Action? onClose) : base(title, message, canCancel, onClose) { _numberInput = new() { Text = defaultValue, VerticalAlignment = VAlignment.Top, @@ -23,7 +23,7 @@ protected override void OkButtonClicked() { Logger.GetSawmill("opendream.prompt").Error($"Error while trying to convert {_numberInput.Text} to a number."); } - FinishPrompt(DreamValueType.Num, num); + FinishPrompt(DMValueType.Num, num); } private void NumberInput_TextEntered(LineEdit.LineEditEventArgs obj) { diff --git a/OpenDreamClient/Interface/Prompts/PromptWindow.cs b/OpenDreamClient/Interface/Prompts/PromptWindow.cs index d9a6026bc0..2b6203ab0b 100644 --- a/OpenDreamClient/Interface/Prompts/PromptWindow.cs +++ b/OpenDreamClient/Interface/Prompts/PromptWindow.cs @@ -1,5 +1,5 @@ using System.ComponentModel; -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -8,14 +8,14 @@ namespace OpenDreamClient.Interface.Prompts; public abstract class PromptWindow : OSWindow { protected readonly Control InputControl; - protected string DefaultButton; + protected string? DefaultButton; private readonly BoxContainer _buttonPanel; private bool _promptFinished; - private readonly Action? _closeAction; + private readonly Action? _closeAction; - protected PromptWindow(string? title, string? message, Action? onClose) { + protected PromptWindow(string? title, string? message, Action? onClose) { _closeAction = onClose; Title = !string.IsNullOrEmpty(title) ? title : "OpenDream"; @@ -57,7 +57,7 @@ protected void CreateButton(string text, bool isDefault) { Children = { new Label { Text = text, Margin = new Thickness(5, 2, 5, 2) } } }; - if (isDefault) + if (isDefault || DefaultButton == null) DefaultButton = text; button.OnPressed += _ => ButtonClicked(text); @@ -68,7 +68,7 @@ protected virtual void ButtonClicked(string button) { Close(); } - protected void FinishPrompt(DreamValueType responseType, object? value) { + protected void FinishPrompt(DMValueType responseType, object? value) { if (_promptFinished) return; _promptFinished = true; diff --git a/OpenDreamClient/Interface/Prompts/TextPrompt.cs b/OpenDreamClient/Interface/Prompts/TextPrompt.cs index 8f189ee3b3..ccc30ee5d7 100644 --- a/OpenDreamClient/Interface/Prompts/TextPrompt.cs +++ b/OpenDreamClient/Interface/Prompts/TextPrompt.cs @@ -1,4 +1,4 @@ -using OpenDreamShared.Dream; +using OpenDreamShared.Common.DM; using Robust.Client.UserInterface.Controls; namespace OpenDreamClient.Interface.Prompts; @@ -7,7 +7,7 @@ internal sealed class TextPrompt : InputWindow { private readonly LineEdit _textEdit; public TextPrompt(string title, string message, string defaultValue, bool canCancel, - Action? onClose) : base(title, message, canCancel, onClose) { + Action? onClose) : base(title, message, canCancel, onClose) { MinHeight = 100; _textEdit = new LineEdit { @@ -20,7 +20,7 @@ public TextPrompt(string title, string message, string defaultValue, bool canCan } protected override void OkButtonClicked() { - FinishPrompt(DreamValueType.Text, _textEdit.Text); + FinishPrompt(DMValueType.Text, _textEdit.Text); } private void TextEdit_TextEntered(LineEdit.LineEditEventArgs e) { diff --git a/OpenDreamClient/OpenDreamClient.csproj b/OpenDreamClient/OpenDreamClient.csproj index 0421e82885..11b190d4f2 100644 --- a/OpenDreamClient/OpenDreamClient.csproj +++ b/OpenDreamClient/OpenDreamClient.csproj @@ -11,6 +11,7 @@ NU1507 + diff --git a/DMCompiler/Bytecode/OpcodeVerifier.cs b/OpenDreamNoClient/Bytecode/OpcodeVerifier.cs similarity index 82% rename from DMCompiler/Bytecode/OpcodeVerifier.cs rename to OpenDreamNoClient/Bytecode/OpcodeVerifier.cs index fe9b22d953..af9fd03f48 100644 --- a/DMCompiler/Bytecode/OpcodeVerifier.cs +++ b/OpenDreamNoClient/Bytecode/OpcodeVerifier.cs @@ -1,15 +1,16 @@ +using OpenDreamShared.Common.Bytecode; using System.Security.Cryptography; using System.Text; -namespace DMCompiler.Bytecode; +namespace OpenDreamNoClient.Bytecode; // Dummy class-as-namespace because C# just kinda be like this -public static class OpcodeVerifier { +public class OpcodeVerifier: IOpcodeVerifier { /// /// Calculates a hash of all the DreamProcOpcodes for warning on incompatibilities. /// /// A MD5 hash string - public static string GetOpcodesHash() { + public string GetOpcodesHash() { Array allOpcodes = Enum.GetValues(typeof(DreamProcOpcode)); List opcodesBytes = new List(); diff --git a/OpenDreamNoClient/OpenDreamNoClient.csproj b/OpenDreamNoClient/OpenDreamNoClient.csproj new file mode 100644 index 0000000000..9f048b3046 --- /dev/null +++ b/OpenDreamNoClient/OpenDreamNoClient.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/OpenDreamPackaging/DreamPackaging.cs b/OpenDreamPackaging/DreamPackaging.cs index e171bb0208..4a6ad6cc1a 100644 --- a/OpenDreamPackaging/DreamPackaging.cs +++ b/OpenDreamPackaging/DreamPackaging.cs @@ -24,7 +24,7 @@ await RobustSharedPackaging.WriteContentAssemblies( inputPass, contentDir, "Content.Client", - new[] { "OpenDreamClient", "OpenDreamShared" }, + new[] { "OpenDreamClient", "OpenDreamShared", "OpenDreamShared.Common" }, cancel: cancel); await RobustClientPackaging.WriteClientResources(contentDir, inputPass, cancel); diff --git a/OpenDreamPackaging/OpenDreamPackaging.csproj b/OpenDreamPackaging/OpenDreamPackaging.csproj index 17e2a8b044..55516a9200 100644 --- a/OpenDreamPackaging/OpenDreamPackaging.csproj +++ b/OpenDreamPackaging/OpenDreamPackaging.csproj @@ -9,6 +9,7 @@ + diff --git a/OpenDreamRuntime/DreamConnection.cs b/OpenDreamRuntime/DreamConnection.cs index 9183aa44b0..3ff940d3d5 100644 --- a/OpenDreamRuntime/DreamConnection.cs +++ b/OpenDreamRuntime/DreamConnection.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using System.Web; +using OpenDreamShared.Common.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs.Native; @@ -289,7 +290,7 @@ public void HandleCommand(string fullCommand) { } } - public Task Prompt(DreamValueType types, string title, string message, string defaultValue) { + public Task Prompt(DMValueType types, string title, string message, string defaultValue) { var task = MakePromptTask(out var promptId); var msg = new MsgPrompt { PromptId = promptId, @@ -303,18 +304,18 @@ public Task Prompt(DreamValueType types, string title, string messag return task; } - public async Task PromptList(DreamValueType types, DreamList list, string title, string message, DreamValue defaultValue) { + public async Task PromptList(DMValueType types, DreamList list, string title, string message, DreamValue defaultValue) { List listValues = list.GetValues(); List promptValues = new(listValues.Count); foreach (var value in listValues) { - if (types.HasFlag(DreamValueType.Obj) && !value.TryGetValueAsDreamObject(out _)) + if (types.HasFlag(DMValueType.Obj) && !value.TryGetValueAsDreamObject(out _)) continue; - if (types.HasFlag(DreamValueType.Mob) && !value.TryGetValueAsDreamObject(out _)) + if (types.HasFlag(DMValueType.Mob) && !value.TryGetValueAsDreamObject(out _)) continue; - if (types.HasFlag(DreamValueType.Turf) && !value.TryGetValueAsDreamObject(out _)) + if (types.HasFlag(DMValueType.Turf) && !value.TryGetValueAsDreamObject(out _)) continue; - if (types.HasFlag(DreamValueType.Area) && !value.TryGetValueAsDreamObject(out _)) + if (types.HasFlag(DMValueType.Area) && !value.TryGetValueAsDreamObject(out _)) continue; promptValues.Add(value.Stringify()); @@ -328,7 +329,7 @@ public async Task PromptList(DreamValueType types, DreamList list, s PromptId = promptId, Title = title, Message = message, - CanCancel = (types & DreamValueType.Null) == DreamValueType.Null, + CanCancel = (types & DMValueType.Null) == DMValueType.Null, DefaultValue = defaultValue.Stringify(), Values = promptValues.ToArray() }; @@ -499,27 +500,27 @@ public void SendFile(DreamResource file, string suggestedName) { Session?.Channel.SendMessage(msg); } - public bool TryConvertPromptResponse(DreamValueType type, object? value, out DreamValue converted) { - bool CanBe(DreamValueType canBeType) => (type == DreamValueType.Anything) || ((type & canBeType) != 0x0); + public bool TryConvertPromptResponse(DMValueType type, object? value, out DreamValue converted) { + bool CanBe(DMValueType canBeType) => (type == DMValueType.Anything) || ((type & canBeType) != 0x0); - if (CanBe(DreamValueType.Null) && value == null) { + if (CanBe(DMValueType.Null) && value == null) { converted = DreamValue.Null; return true; - } else if (CanBe(DreamValueType.Text | DreamValueType.Message | DreamValueType.CommandText) && value is string strVal) { + } else if (CanBe(DMValueType.Text | DMValueType.Message | DMValueType.CommandText) && value is string strVal) { converted = new(strVal); return true; - } else if (CanBe(DreamValueType.Num) && value is float numVal) { + } else if (CanBe(DMValueType.Num) && value is float numVal) { converted = new DreamValue(numVal); return true; - } else if (CanBe(DreamValueType.Color) && value is Color colorVal) { + } else if (CanBe(DMValueType.Color) && value is Color colorVal) { converted = new DreamValue(colorVal.ToHexNoAlpha()); return true; - } else if (CanBe(type & DreamValueType.AllAtomTypes) && value is ClientObjectReference clientRef) { + } else if (CanBe(type & DMValueType.AllAtomTypes) && value is ClientObjectReference clientRef) { var atom = _dreamManager.GetFromClientReference(this, clientRef); if (atom != null) { - if ((atom.IsSubtypeOf(_objectTree.Obj) && !CanBe(DreamValueType.Obj)) || - (atom.IsSubtypeOf(_objectTree.Mob) && !CanBe(DreamValueType.Mob))) { + if ((atom.IsSubtypeOf(_objectTree.Obj) && !CanBe(DMValueType.Obj)) || + (atom.IsSubtypeOf(_objectTree.Mob) && !CanBe(DMValueType.Mob))) { converted = default; return false; } diff --git a/OpenDreamRuntime/DreamManager.cs b/OpenDreamRuntime/DreamManager.cs index 48176de307..4fe239df8c 100644 --- a/OpenDreamRuntime/DreamManager.cs +++ b/OpenDreamRuntime/DreamManager.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Text.Json; using System.Threading; -using DMCompiler.Bytecode; -using DMCompiler.Json; +using OpenDreamShared.Common.Json; +using OpenDreamNoClient.Bytecode; using OpenDreamRuntime.Map; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; @@ -127,7 +127,7 @@ public bool LoadJson(string? jsonPath) { if (json == null) return false; - if (!json.Metadata.Version.Equals(OpcodeVerifier.GetOpcodesHash())) { + if (!json.Metadata.Version.Equals(new OpcodeVerifier().GetOpcodesHash())) { _sawmill.Error("Compiler opcode version does not match the runtime version!"); } diff --git a/OpenDreamRuntime/DreamReference.cs b/OpenDreamRuntime/DreamReference.cs index 698527e27d..26709d9b97 100644 --- a/OpenDreamRuntime/DreamReference.cs +++ b/OpenDreamRuntime/DreamReference.cs @@ -1,4 +1,4 @@ -using DMRefType = DMCompiler.Bytecode.DMReference.Type; +using DMRefType = OpenDreamShared.Common.Bytecode.DMReference.Type; namespace OpenDreamRuntime; diff --git a/OpenDreamRuntime/DreamThread.cs b/OpenDreamRuntime/DreamThread.cs index c9c9212084..6dae3a6715 100644 --- a/OpenDreamRuntime/DreamThread.cs +++ b/OpenDreamRuntime/DreamThread.cs @@ -2,11 +2,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using DMCompiler.DM; +using OpenDreamShared.Common.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Procs; using OpenDreamRuntime.Procs.DebugAdapter; -using OpenDreamShared.Dream; namespace OpenDreamRuntime { public enum ProcStatus { @@ -30,7 +29,7 @@ public abstract class DreamProc { public readonly List? ArgumentNames; - public readonly List? ArgumentTypes; + public readonly List? ArgumentTypes; public int? VerbId = null; // Null until registered as a verb in ServerVerbSystem public string VerbName => _verbName ?? Name; @@ -41,7 +40,7 @@ public abstract class DreamProc { private readonly string? _verbName; private readonly string? _verbDesc; - protected DreamProc(int id, TreeEntry owningType, string name, DreamProc? superProc, ProcAttributes attributes, List? argumentNames, List? argumentTypes, VerbSrc? verbSrc, string? verbName, string? verbCategory, string? verbDesc, sbyte invisibility, bool isVerb = false) { + protected DreamProc(int id, TreeEntry owningType, string name, DreamProc? superProc, ProcAttributes attributes, List? argumentNames, List? argumentTypes, VerbSrc? verbSrc, string? verbName, string? verbCategory, string? verbDesc, sbyte invisibility, bool isVerb = false) { Id = id; OwningType = owningType; Name = name; diff --git a/OpenDreamRuntime/Map/DreamMapManager.cs b/OpenDreamRuntime/Map/DreamMapManager.cs index 408b0e0da6..9dadb06ad2 100644 --- a/OpenDreamRuntime/Map/DreamMapManager.cs +++ b/OpenDreamRuntime/Map/DreamMapManager.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; -using DMCompiler.Json; +using OpenDreamShared.Common.Json; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs; diff --git a/OpenDreamRuntime/Objects/DreamObject.cs b/OpenDreamRuntime/Objects/DreamObject.cs index e3e4389248..378f8db9ac 100644 --- a/OpenDreamRuntime/Objects/DreamObject.cs +++ b/OpenDreamRuntime/Objects/DreamObject.cs @@ -2,7 +2,6 @@ using OpenDreamRuntime.Procs; using System.Globalization; using System.Runtime.CompilerServices; -using DMCompiler.Bytecode; using OpenDreamRuntime.Map; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Rendering; @@ -14,6 +13,7 @@ using Robust.Shared.Map; using Robust.Shared.Serialization.Manager; using Robust.Shared.Utility; +using OpenDreamShared.Common.Bytecode; namespace OpenDreamRuntime.Objects { [Virtual] diff --git a/OpenDreamRuntime/Objects/DreamObjectTree.cs b/OpenDreamRuntime/Objects/DreamObjectTree.cs index 2fdd1a785a..2b9f3055a5 100644 --- a/OpenDreamRuntime/Objects/DreamObjectTree.cs +++ b/OpenDreamRuntime/Objects/DreamObjectTree.cs @@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Threading.Tasks; -using DMCompiler.Json; +using OpenDreamShared.Common.Json; using OpenDreamRuntime.Map; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs; diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs index 102fe44855..3194ff5328 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; -using DMCompiler; +using OpenDreamShared.Common; using OpenDreamRuntime.Procs; using OpenDreamRuntime.Resources; diff --git a/OpenDreamRuntime/OpenDreamRuntime.csproj b/OpenDreamRuntime/OpenDreamRuntime.csproj index bd5a6e2c75..b5d7bea973 100644 --- a/OpenDreamRuntime/OpenDreamRuntime.csproj +++ b/OpenDreamRuntime/OpenDreamRuntime.csproj @@ -1,4 +1,4 @@ - + net9.0 enable @@ -7,8 +7,9 @@ AnyCPU - + + diff --git a/OpenDreamRuntime/Procs/AsyncNativeProc.cs b/OpenDreamRuntime/Procs/AsyncNativeProc.cs index 772921408f..876df9570e 100644 --- a/OpenDreamRuntime/Procs/AsyncNativeProc.cs +++ b/OpenDreamRuntime/Procs/AsyncNativeProc.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; -using DMCompiler.DM; +using OpenDreamShared.Common.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Resources; using Dependency = Robust.Shared.IoC.DependencyAttribute; diff --git a/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs b/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs index 9e9ef6afaa..27abf9624d 100644 --- a/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs +++ b/OpenDreamRuntime/Procs/DMOpcodeHandlers.cs @@ -5,8 +5,9 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -using DMCompiler; -using DMCompiler.Bytecode; +using OpenDreamShared.Common; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs.Native; @@ -2488,7 +2489,7 @@ public static ProcStatus OutputControl(DMProcState state) { } public static ProcStatus Prompt(DMProcState state) { - DreamValueType types = (DreamValueType)state.ReadInt(); + DMValueType types = (DMValueType)state.ReadInt(); DreamValue list = state.Pop(); DreamValue message, title, defaultValue; diff --git a/OpenDreamRuntime/Procs/DMProc.cs b/OpenDreamRuntime/Procs/DMProc.cs index 89e64a1b16..541488c700 100644 --- a/OpenDreamRuntime/Procs/DMProc.cs +++ b/OpenDreamRuntime/Procs/DMProc.cs @@ -2,14 +2,14 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; -using DMCompiler.Bytecode; -using DMCompiler.DM; -using DMCompiler.Json; using OpenDreamRuntime.Map; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs.DebugAdapter; using OpenDreamRuntime.Resources; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; +using OpenDreamShared.Common.Json; using OpenDreamShared.Dream; using Robust.Shared.Utility; @@ -137,12 +137,12 @@ private static List GetArgumentNames(ProcDefinitionJson json) { } } - private static List? GetArgumentTypes(ProcDefinitionJson json) { + private static List? GetArgumentTypes(ProcDefinitionJson json) { if (json.Arguments == null) { return null; } else { - var argumentTypes = new List(json.Arguments.Count); - argumentTypes.AddRange(json.Arguments.Select(a => (DreamValueType)a.Type)); + var argumentTypes = new List(json.Arguments.Count); + argumentTypes.AddRange(json.Arguments.Select(a => a.Type)); return argumentTypes; } } diff --git a/OpenDreamRuntime/Procs/DebugAdapter/DreamDebugManager.cs b/OpenDreamRuntime/Procs/DebugAdapter/DreamDebugManager.cs index 8f747f90bf..6db5e587bb 100644 --- a/OpenDreamRuntime/Procs/DebugAdapter/DreamDebugManager.cs +++ b/OpenDreamRuntime/Procs/DebugAdapter/DreamDebugManager.cs @@ -1,6 +1,6 @@ using System.IO; using System.Linq; -using DMCompiler.Bytecode; +using OpenDreamShared.Common.Bytecode; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamRuntime.Procs.DebugAdapter.Protocol; diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 5aa3761ff9..2a9eff4aab 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -16,13 +16,13 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; -using DMCompiler.DM; using OpenDreamRuntime.Objects.Types; using DreamValueType = OpenDreamRuntime.DreamValue.DreamValueType; using DreamValueTypeFlag = OpenDreamRuntime.DreamValue.DreamValueTypeFlag; using Robust.Server; using Robust.Shared.Asynchronous; using Vector4 = Robust.Shared.Maths.Vector4; +using OpenDreamShared.Common.DM; namespace OpenDreamRuntime.Procs.Native; /// diff --git a/OpenDreamRuntime/Procs/NativeProc.cs b/OpenDreamRuntime/Procs/NativeProc.cs index e6a46858b0..15fca1ddfb 100644 --- a/OpenDreamRuntime/Procs/NativeProc.cs +++ b/OpenDreamRuntime/Procs/NativeProc.cs @@ -1,10 +1,10 @@ using System.Reflection; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using DMCompiler.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Resources; using OpenDreamRuntime.Map; +using OpenDreamShared.Common.DM; namespace OpenDreamRuntime.Procs; diff --git a/OpenDreamRuntime/Procs/ProcDecoder.cs b/OpenDreamRuntime/Procs/ProcDecoder.cs index 2fd2d2f41f..c633c69470 100644 --- a/OpenDreamRuntime/Procs/ProcDecoder.cs +++ b/OpenDreamRuntime/Procs/ProcDecoder.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; using System.Text; -using DMCompiler.Bytecode; -using OpenDreamShared.Dream; +using OpenDreamShared.Common.Bytecode; +using OpenDreamShared.Common.DM; namespace OpenDreamRuntime.Procs; @@ -26,8 +26,8 @@ public int ReadInt() { return value; } - public DreamValueType ReadValueType() { - return (DreamValueType) ReadInt(); + public DMValueType ReadValueType() { + return (DMValueType) ReadInt(); } public float ReadFloat() { diff --git a/OpenDreamRuntime/ServerVerbSystem.cs b/OpenDreamRuntime/ServerVerbSystem.cs index 6da5de48e6..668c19de1a 100644 --- a/OpenDreamRuntime/ServerVerbSystem.cs +++ b/OpenDreamRuntime/ServerVerbSystem.cs @@ -1,6 +1,6 @@ using System.Diagnostics; using System.Linq; -using DMCompiler.DM; +using OpenDreamShared.Common.DM; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Objects.Types; using OpenDreamShared.Dream; diff --git a/DMCompiler/Bytecode/DMReference.cs b/OpenDreamShared.Common/Bytecode/DMReference.cs similarity index 98% rename from DMCompiler/Bytecode/DMReference.cs rename to OpenDreamShared.Common/Bytecode/DMReference.cs index ae63c782f7..545f1102cf 100644 --- a/DMCompiler/Bytecode/DMReference.cs +++ b/OpenDreamShared.Common/Bytecode/DMReference.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace DMCompiler.Bytecode; +namespace OpenDreamShared.Common.Bytecode; public struct DMReference { public static readonly DMReference Src = new() { RefType = Type.Src }; diff --git a/DMCompiler/Bytecode/DreamProcOpcode.cs b/OpenDreamShared.Common/Bytecode/DreamProcOpcode.cs similarity index 99% rename from DMCompiler/Bytecode/DreamProcOpcode.cs rename to OpenDreamShared.Common/Bytecode/DreamProcOpcode.cs index 00852ad0bb..a4244a5396 100644 --- a/DMCompiler/Bytecode/DreamProcOpcode.cs +++ b/OpenDreamShared.Common/Bytecode/DreamProcOpcode.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.Bytecode; +namespace OpenDreamShared.Common.Bytecode; // ReSharper disable MissingBlankLines public enum DreamProcOpcode : byte { diff --git a/OpenDreamShared.Common/Bytecode/IOpcodeVerifier.cs b/OpenDreamShared.Common/Bytecode/IOpcodeVerifier.cs new file mode 100644 index 0000000000..d6f3247a5b --- /dev/null +++ b/OpenDreamShared.Common/Bytecode/IOpcodeVerifier.cs @@ -0,0 +1,5 @@ +namespace OpenDreamShared.Common.Bytecode; + +public interface IOpcodeVerifier { + public string GetOpcodesHash(); +} diff --git a/DMCompiler/Bytecode/OpcodeMetadata.cs b/OpenDreamShared.Common/Bytecode/OpcodeMetadata.cs similarity index 60% rename from DMCompiler/Bytecode/OpcodeMetadata.cs rename to OpenDreamShared.Common/Bytecode/OpcodeMetadata.cs index 9dfb98f864..db1a17c035 100644 --- a/DMCompiler/Bytecode/OpcodeMetadata.cs +++ b/OpenDreamShared.Common/Bytecode/OpcodeMetadata.cs @@ -1,10 +1,10 @@ -namespace DMCompiler.Bytecode; +namespace OpenDreamShared.Common.Bytecode; /// /// Custom attribute for declaring metadata for individual opcodes /// [AttributeUsage(AttributeTargets.Field)] -internal sealed class OpcodeMetadataAttribute : Attribute { +public sealed class OpcodeMetadataAttribute : Attribute { public OpcodeMetadata Metadata; public OpcodeMetadataAttribute(int stackDelta = 0, params OpcodeArgType[] requiredArgs) { @@ -26,25 +26,6 @@ public struct OpcodeMetadata(int stackDelta = 0, bool variableArgs = false, para public readonly bool VariableArgs = variableArgs; // Whether this opcode takes a variable number of arguments } -/// -/// Automatically builds a cache of the attribute for each opcode -/// -public static class OpcodeMetadataCache { - private static readonly OpcodeMetadata[] MetadataCache = new OpcodeMetadata[256]; - - static OpcodeMetadataCache() { - foreach (DreamProcOpcode opcode in Enum.GetValues(typeof(DreamProcOpcode))) { - var field = typeof(DreamProcOpcode).GetField(opcode.ToString()); - var attribute = Attribute.GetCustomAttribute(field!, typeof(OpcodeMetadataAttribute)); - var metadataAttribute = (OpcodeMetadataAttribute?)attribute; - MetadataCache[(byte)opcode] = metadataAttribute?.Metadata ?? new OpcodeMetadata(); - } - } - - public static OpcodeMetadata GetMetadata(DreamProcOpcode opcode) { - return MetadataCache[(byte)opcode]; - } -} public enum OpcodeArgType { ArgType, diff --git a/DMCompiler/Bytecode/StringFormatEncoder.cs b/OpenDreamShared.Common/Bytecode/StringFormatEncoder.cs similarity index 99% rename from DMCompiler/Bytecode/StringFormatEncoder.cs rename to OpenDreamShared.Common/Bytecode/StringFormatEncoder.cs index 5ee7d421f0..3937a670b9 100644 --- a/DMCompiler/Bytecode/StringFormatEncoder.cs +++ b/OpenDreamShared.Common/Bytecode/StringFormatEncoder.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text; -namespace DMCompiler.Bytecode; +namespace OpenDreamShared.Common.Bytecode; /// /// Handles how we write format data into our strings. diff --git a/OpenDreamShared/Dream/DreamValueType.cs b/OpenDreamShared.Common/DM/DMValueType.cs similarity index 67% rename from OpenDreamShared/Dream/DreamValueType.cs rename to OpenDreamShared.Common/DM/DMValueType.cs index e79130bcb2..18f053763b 100644 --- a/OpenDreamShared/Dream/DreamValueType.cs +++ b/OpenDreamShared.Common/DM/DMValueType.cs @@ -1,16 +1,11 @@ -using System; - -namespace OpenDreamShared.Dream; - -// If you are modifying this, you must also modify DMCompiler.DM.DMValueType !! -// Unfortunately the client needs this and it can't reference DMCompiler due to the sandbox +namespace OpenDreamShared.Common.DM; /// ///Stores any explicit casting done via the "as" keyword. Also stores compiler hints for DMStandard.
///is a [Flags] enum because it's possible for something to have multiple values (especially with the quirky DMStandard ones) ///
[Flags] -public enum DreamValueType { +public enum DMValueType { AllAtomTypes = Obj | Mob | Turf | Area, Anything = 0x0, @@ -27,8 +22,10 @@ public enum DreamValueType { CommandText = 0x400, Sound = 0x800, Icon = 0x1000, + Path = 0x2000, // For proc return types //Byond here be dragons - Unimplemented = 0x2000, // Marks that a method or property is not implemented. Throws a compiler warning if accessed. - CompiletimeReadonly = 0x4000, // Marks that a property can only ever be read from, never written to. This is a const-ier version of const, for certain standard values like list.type + Unimplemented = 0x4000, // Marks that a method or property is not implemented. Throws a compiler warning if accessed. + CompiletimeReadonly = 0x8000, // Marks that a property can only ever be read from, never written to. This is a const-ier version of const, for certain standard values like list.type + NoConstFold = 0x10000 // Marks that a const var cannot be const-folded during compile } diff --git a/DMCompiler/DM/MatrixOpcodes.cs b/OpenDreamShared.Common/DM/MatrixOpcodes.cs similarity index 90% rename from DMCompiler/DM/MatrixOpcodes.cs rename to OpenDreamShared.Common/DM/MatrixOpcodes.cs index f9a95fde2d..7b84962cd3 100644 --- a/DMCompiler/DM/MatrixOpcodes.cs +++ b/OpenDreamShared.Common/DM/MatrixOpcodes.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.DM; +namespace OpenDreamShared.Common.DM; /// /// These are the values associated with the wacky, undocumented /matrix() signatures.
diff --git a/DMCompiler/DM/ProcAttributes.cs b/OpenDreamShared.Common/DM/ProcAttributes.cs similarity index 87% rename from DMCompiler/DM/ProcAttributes.cs rename to OpenDreamShared.Common/DM/ProcAttributes.cs index e6142b718a..39426bba1e 100644 --- a/DMCompiler/DM/ProcAttributes.cs +++ b/OpenDreamShared.Common/DM/ProcAttributes.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.DM; +namespace OpenDreamShared.Common.DM; [Flags] public enum ProcAttributes { diff --git a/DMCompiler/DM/VerbSrc.cs b/OpenDreamShared.Common/DM/VerbSrc.cs similarity index 86% rename from DMCompiler/DM/VerbSrc.cs rename to OpenDreamShared.Common/DM/VerbSrc.cs index 1730d9e134..e254826b07 100644 --- a/DMCompiler/DM/VerbSrc.cs +++ b/OpenDreamShared.Common/DM/VerbSrc.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.DM; +namespace OpenDreamShared.Common.DM; /// /// The value of "set src = ..." in a verb diff --git a/DMCompiler/DreamPath.cs b/OpenDreamShared.Common/DreamPath.cs similarity index 93% rename from DMCompiler/DreamPath.cs rename to OpenDreamShared.Common/DreamPath.cs index 1812e745a3..b942830363 100644 --- a/DMCompiler/DreamPath.cs +++ b/OpenDreamShared.Common/DreamPath.cs @@ -1,9 +1,7 @@ using System.Diagnostics.Contracts; -using System.Linq; using System.Text.Json.Serialization; -using DMCompiler.DM; -namespace DMCompiler; +namespace OpenDreamShared.Common; // TODO: This is fairly ugly structure and should probably be removed/redone with something much nicer. // It's heavily embedded into a lot of corners of the compiler though. @@ -94,22 +92,6 @@ public DreamPath(PathType type, string[] elements) { Normalize(true); } - internal DMValueType GetAtomType(DMCompiler compiler) { - if (!compiler.DMObjectTree.TryGetDMObject(this, out var dmType)) - return DMValueType.Anything; - - if (dmType.IsSubtypeOf(Obj)) - return DMValueType.Obj; - if (dmType.IsSubtypeOf(Mob)) - return DMValueType.Mob; - if (dmType.IsSubtypeOf(Turf)) - return DMValueType.Turf; - if (dmType.IsSubtypeOf(Area)) - return DMValueType.Area; - - return DMValueType.Anything; - } - public void SetFromString(string rawPath) { char pathTypeChar = rawPath[0]; string[] tempElements = rawPath.Split('/', StringSplitOptions.RemoveEmptyEntries); diff --git a/DMCompiler/Json/DreamCompiledJson.cs b/OpenDreamShared.Common/JSON/DreamCompiledJson.cs similarity index 94% rename from DMCompiler/Json/DreamCompiledJson.cs rename to OpenDreamShared.Common/JSON/DreamCompiledJson.cs index 722198b87e..05a8f1c41c 100644 --- a/DMCompiler/Json/DreamCompiledJson.cs +++ b/OpenDreamShared.Common/JSON/DreamCompiledJson.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.Json; +namespace OpenDreamShared.Common.Json; public sealed class DreamCompiledJson { public required DreamCompiledJsonMetadata Metadata { get; set; } diff --git a/DMCompiler/Json/DreamMapJson.cs b/OpenDreamShared.Common/JSON/DreamMapJson.cs similarity index 97% rename from DMCompiler/Json/DreamMapJson.cs rename to OpenDreamShared.Common/JSON/DreamMapJson.cs index af5f52e65e..051e067909 100644 --- a/DMCompiler/Json/DreamMapJson.cs +++ b/OpenDreamShared.Common/JSON/DreamMapJson.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.Json; +namespace OpenDreamShared.Common.Json; public sealed class DreamMapJson { public int MaxX { get; set; } diff --git a/DMCompiler/Json/DreamObjectJson.cs b/OpenDreamShared.Common/JSON/DreamObjectJson.cs similarity index 95% rename from DMCompiler/Json/DreamObjectJson.cs rename to OpenDreamShared.Common/JSON/DreamObjectJson.cs index d9cadb0a46..2e7b4bb394 100644 --- a/DMCompiler/Json/DreamObjectJson.cs +++ b/OpenDreamShared.Common/JSON/DreamObjectJson.cs @@ -1,4 +1,4 @@ -namespace DMCompiler.Json; +namespace OpenDreamShared.Common.Json; public enum JsonVariableType { Resource = 0, diff --git a/DMCompiler/Json/DreamProcJson.cs b/OpenDreamShared.Common/JSON/DreamProcJson.cs similarity index 95% rename from DMCompiler/Json/DreamProcJson.cs rename to OpenDreamShared.Common/JSON/DreamProcJson.cs index 070adb86c9..414cb2baf1 100644 --- a/DMCompiler/Json/DreamProcJson.cs +++ b/OpenDreamShared.Common/JSON/DreamProcJson.cs @@ -1,6 +1,6 @@ -using DMCompiler.DM; +using OpenDreamShared.Common.DM; -namespace DMCompiler.Json; +namespace OpenDreamShared.Common.Json; public sealed class ProcDefinitionJson { public int OwningTypeId { get; init; } diff --git a/OpenDreamShared.Common/OpenDreamShared.Common.csproj b/OpenDreamShared.Common/OpenDreamShared.Common.csproj new file mode 100644 index 0000000000..125f4c93bc --- /dev/null +++ b/OpenDreamShared.Common/OpenDreamShared.Common.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/DMCompiler/SharedOperations.cs b/OpenDreamShared.Common/SharedOperations.cs similarity index 98% rename from DMCompiler/SharedOperations.cs rename to OpenDreamShared.Common/SharedOperations.cs index 3e5f012020..78a3813d8b 100644 --- a/DMCompiler/SharedOperations.cs +++ b/OpenDreamShared.Common/SharedOperations.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace DMCompiler; +namespace OpenDreamShared.Common; /// /// A class containing operations used by both the compiler and the server. diff --git a/OpenDreamShared/Dream/VerbSystem.cs b/OpenDreamShared/Dream/VerbSystem.cs index ca17524890..1b7de745e0 100644 --- a/OpenDreamShared/Dream/VerbSystem.cs +++ b/OpenDreamShared/Dream/VerbSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using JetBrains.Annotations; +using OpenDreamShared.Common.DM; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -69,7 +70,7 @@ public bool IsHidden(bool ignoreHiddenAttr, sbyte seeInvisibility) => // If the verb's first argument is an atom type, it takes that type as a target [Pure] - public DreamValueType? GetTargetType() => + public DMValueType? GetTargetType() => (Arguments.Length != 0) ? Arguments[0].Types : null; public override string ToString() => GetCommandName(); @@ -85,7 +86,7 @@ public struct VerbArg { /// /// Types the argument is allowed to be /// - public DreamValueType Types; + public DMValueType Types; } [Serializable, NetSerializable] diff --git a/OpenDreamShared/Network/Messages/MsgPrompt.cs b/OpenDreamShared/Network/Messages/MsgPrompt.cs index 2332b8e196..3cc9ef4f49 100644 --- a/OpenDreamShared/Network/Messages/MsgPrompt.cs +++ b/OpenDreamShared/Network/Messages/MsgPrompt.cs @@ -1,4 +1,5 @@ using Lidgren.Network; +using OpenDreamShared.Common.DM; using OpenDreamShared.Dream; using Robust.Shared.Network; using Robust.Shared.Serialization; @@ -9,14 +10,14 @@ public sealed class MsgPrompt : NetMessage { public override MsgGroups MsgGroup => MsgGroups.EntityEvent; public int PromptId; - public DreamValueType Types; + public DMValueType Types; public string Title = string.Empty; public string Message = string.Empty; public string DefaultValue = string.Empty; public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) { PromptId = buffer.ReadVariableInt32(); - Types = (DreamValueType) buffer.ReadUInt16(); + Types = (DMValueType) buffer.ReadUInt16(); Title = buffer.ReadString(); Message = buffer.ReadString(); DefaultValue = buffer.ReadString(); diff --git a/OpenDreamShared/Network/Messages/MsgPromptResponse.cs b/OpenDreamShared/Network/Messages/MsgPromptResponse.cs index 1f7b336631..9951cd8ec7 100644 --- a/OpenDreamShared/Network/Messages/MsgPromptResponse.cs +++ b/OpenDreamShared/Network/Messages/MsgPromptResponse.cs @@ -1,5 +1,6 @@ using System; using Lidgren.Network; +using OpenDreamShared.Common.DM; using OpenDreamShared.Dream; using Robust.Shared.Maths; using Robust.Shared.Network; @@ -11,18 +12,18 @@ public sealed class MsgPromptResponse : NetMessage { public override MsgGroups MsgGroup => MsgGroups.EntityEvent; public int PromptId; - public DreamValueType Type; + public DMValueType Type; public object? Value; public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) { PromptId = buffer.ReadVariableInt32(); - Type = (DreamValueType)buffer.ReadUInt16(); + Type = (DMValueType)buffer.ReadUInt16(); Value = Type switch { - DreamValueType.Null => null, - DreamValueType.Text or DreamValueType.Message => buffer.ReadString(), - DreamValueType.Num => buffer.ReadSingle(), - DreamValueType.Color => new Color(buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte()), + DMValueType.Null => null, + DMValueType.Text or DMValueType.Message => buffer.ReadString(), + DMValueType.Num => buffer.ReadSingle(), + DMValueType.Color => new Color(buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte(), buffer.ReadByte()), _ => throw new ArgumentOutOfRangeException() }; } @@ -32,14 +33,14 @@ public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer buffer.Write((ushort)Type); switch (Type) { - case DreamValueType.Null: break; - case DreamValueType.Text or DreamValueType.Message: + case DMValueType.Null: break; + case DMValueType.Text or DMValueType.Message: buffer.Write((string)Value!); break; - case DreamValueType.Num: + case DMValueType.Num: buffer.Write((float)Value!); break; - case DreamValueType.Color: + case DMValueType.Color: var color = (Color)Value!; buffer.Write(color.RByte); buffer.Write(color.GByte); diff --git a/OpenDreamShared/OpenDreamShared.csproj b/OpenDreamShared/OpenDreamShared.csproj index c69bb75e29..239f4f9b3f 100644 --- a/OpenDreamShared/OpenDreamShared.csproj +++ b/OpenDreamShared/OpenDreamShared.csproj @@ -1,4 +1,4 @@ - + $(TargetFramework) @@ -15,6 +15,7 @@ +