/// <summary></summary> public ScriptOperand(BinaryReader reader, ScriptArgument expected) { ScriptOperandType value = (ScriptOperandType)reader.ReadByte(); // Expectations can transform the result due to overlapping in coding, so deal with them here. switch (expected) { case ScriptArgument.Literal: // Single code byte, any value Type = ScriptOperandType.Value; CoreIntegerValue = (byte)value; return; case ScriptArgument.Opcode: // Single byte, any value if (value == ScriptOperandType.Value || value == ScriptOperandType.Variable || value == ScriptOperandType.UnknownVariable) { Type = ScriptOperandType.Opcode; CoreIntegerValue = (byte)value; return; } break; case ScriptArgument.Address: // 0x01 if (value == ScriptOperandType.Variable) { Type = ScriptOperandType.Address; CoreIntegerValue = reader.ReadUInt16(); return; } break; case ScriptArgument.Comparison: // Single code byte Type = ScriptOperandType.Comparison; CoreIntegerValue = (byte)value; return; default: break; } // Now we can freely handle the data. switch (value) { case ScriptOperandType.Value: // 0x00 Type = ScriptOperandType.Value; CoreIntegerValue = reader.ReadByte(); break; case ScriptOperandType.Variable: // 0x01 Type = ScriptOperandType.Variable; CoreIntegerValue = reader.ReadUInt16(); break; case ScriptOperandType.UnknownVariable: // 0x03 Type = ScriptOperandType.UnknownVariable; CoreIntegerValue = reader.ReadUInt16(); break; case ScriptOperandType.String: // 0x80 Type = ScriptOperandType.String; byte stringLength = reader.ReadByte(); long end = reader.BaseStream.Position + stringLength; CoreStringValue = Engine.ReadCodedString(reader, stringLength + 1); reader.BaseStream.Position = end; break; case ScriptOperandType.StringVariable: // 0x81 Type = ScriptOperandType.StringVariable; CoreIntegerValue = reader.ReadUInt16(); break; default: // Anything else Type = ScriptOperandType.Opcode; CoreIntegerValue = (byte)value; break; } }
/// <summary></summary> public ScriptOperand(byte value) { Type = ScriptOperandType.Value; CoreIntegerValue = value; }
/// <summary></summary> public ScriptOperand(BinaryReader reader, ScriptArgument expected) { ScriptOperandType value = (ScriptOperandType)reader.ReadByte(); // Expectations can transform the result due to overlapping in coding, so deal with them here. switch (expected) { case ScriptArgument.Literal: // Single code byte, any value Type = ScriptOperandType.Value; CoreIntegerValue = (byte)value; return; case ScriptArgument.Opcode: // Single byte, any value if (value == ScriptOperandType.Value || value == ScriptOperandType.Variable || value == ScriptOperandType.UnknownVariable) { Type = ScriptOperandType.Opcode; CoreIntegerValue = (byte)value; return; } break; case ScriptArgument.Address: // 0x01 if (value == ScriptOperandType.Variable) { Type = ScriptOperandType.Address; CoreIntegerValue = reader.ReadUInt16(); return; } break; case ScriptArgument.Comparison: // Single code byte Type = ScriptOperandType.Comparison; CoreIntegerValue = (byte)value; return; default: break; } // Now we can freely handle the data. switch (value) { case ScriptOperandType.Value: // 0x00 Type = ScriptOperandType.Value; CoreIntegerValue = reader.ReadByte(); break; case ScriptOperandType.Variable: // 0x01 Type = ScriptOperandType.Variable; CoreIntegerValue = reader.ReadUInt16(); break; case ScriptOperandType.UnknownVariable: // 0x03 Type = ScriptOperandType.UnknownVariable; CoreIntegerValue = reader.ReadUInt16(); break; case ScriptOperandType.String: // 0x80 Type = ScriptOperandType.String; byte stringLength = reader.ReadByte(); long end = reader.BaseStream.Position + stringLength; CoreStringValue = Engine.ReadCodedString(reader, stringLength + 1); reader.BaseStream.Position = end; break; case ScriptOperandType.StringVariable: // 0x81 Type = ScriptOperandType.StringVariable; CoreIntegerValue = reader.ReadUInt16(); break; default: // Anything else Type = ScriptOperandType.Opcode; CoreIntegerValue = (byte)value; break; } }
void RequireType(ScriptOperandType type) { if (Type != type) throw new InvalidOperationException("This is not a " + type + " " + typeof(ScriptOperand).Name + "; it is a " + Type + "."); }
/// <summary></summary> public ScriptOperand(byte value) { Type = ScriptOperandType.Value; CoreIntegerValue = value; }