Example #1
0
        public void SmallPayload()
        {
            var unpacker = new DataUnpacker(new IdentityTransformer());
            var input    = new byte[]
            {
                1, 2, 3, 2,
                1, 0, 0, 0,
                2, 0, 0, 0,
                4, 0, 0, 0,

                1, 2, 3, 4,
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0,
            };
            var output = new byte[16];

            var unpacked = unpacker.UnpackData(
                new ArraySegment <byte>(output),
                out var bytesWritten, out var bytesRead,
                out var pairId, out var serialId, out var payloadSize, new ArraySegment <byte>(input));

            Assert.True(unpacked);

            Assert.Equal(payloadSize, bytesWritten);
            Assert.Equal(input.Length, bytesRead);

            Assert.Equal(1, pairId);
            Assert.Equal(2, serialId);
            Assert.Equal(4, payloadSize);
        }
Example #2
0
        private static string GetEffectCode(Propeller.MemoryManager memory, bool useShortOpcodes)
        {
            Spin.ParsedAssignment ParsedAssignment = new Spin.ParsedAssignment(memory.ReadByte());

            string effect = ParsedAssignment.Push ? "" : "POP ";

            if (useShortOpcodes)
            {
                effect += "(" + ParsedAssignment.GetBasicInstruction().NameBrief + ")";
            }
            else
            {
                effect += ParsedAssignment.GetBasicInstruction().Name;
            }

            if (!ParsedAssignment.Math)
            {
                Propeller.Spin.SubAssignment SubAssignment = ParsedAssignment.GetSubAssignment();
                switch (SubAssignment.ArgumentMode)
                {
                case Propeller.Spin.ArgumentMode.None:
                    break;

                case Propeller.Spin.ArgumentMode.SignedPackedOffset:
                    effect += " " + DataUnpacker.GetSignedPackedOffset(memory);
                    break;

                default:
                    throw new Exception("Unexpected Spin Argument Mode: " + SubAssignment.ArgumentMode.ToString());
                }
            }

            return(effect);
        }
Example #3
0
	public void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.VariableID);
		byte oper;
		unpacker.Unpack(out oper);
		this.Operator = (VariableOperation)oper;
		if (this.VariableID != HamTimeline.InvalidID)
		{
			this.Operand = new VariableValue();
			this.Operand.Unpack(unpacker);
		}
	}
Example #4
0
	public void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.VariableID);
		byte comparisonByte;
		unpacker.Unpack(out comparisonByte);
		this.Comparison = (VariableComparison)comparisonByte;
		if (this.VariableID == HamTimeline.InvalidID)
		{
			this.CompareValue = null;
		}
		else
		{
			this.CompareValue = new VariableValue();
			this.CompareValue.Unpack(unpacker);
		}
		unpacker.Unpack(out this.NextNodeID);
	}
Example #5
0
        public void SmallPayloadSliced()
        {
            var unpacker = new DataUnpacker(new IdentityTransformer());
            var input    = new byte[]
            {
                1, 2, 3, 2,
                1, 0, 0, 0,
                2, 0, 0, 0,
                4, 0, 0, 0,

                1, 2, 3, 4,
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0,
            };
            var output = new byte[16];

            var unpacked = false;
            int bytesWritten, bytesRead, pairId, serialId, payloadSize;

            for (int i = 0; i < 4; i++)
            {
                unpacked = unpacker.UnpackData(
                    new ArraySegment <byte>(output),
                    out bytesWritten, out bytesRead,
                    out pairId, out serialId, out payloadSize, new ArraySegment <byte>(input, i * 4, 4));

                Assert.False(unpacked);
            }

            unpacked = unpacker.UnpackData(
                new ArraySegment <byte>(output),
                out bytesWritten, out bytesRead,
                out pairId, out serialId, out payloadSize, new ArraySegment <byte>(input, 4 * 4, 16));

            Assert.True(unpacked);

            Assert.Equal(payloadSize, bytesWritten);
            Assert.Equal(16, bytesRead);

            Assert.Equal(1, pairId);
            Assert.Equal(2, serialId);
            Assert.Equal(4, payloadSize);
        }
Example #6
0
	public static void Unpack(out HamTimelineNode node, DataUnpacker unpacker)
	{
		byte typeByte;
		unpacker.Unpack(out typeByte);
		TimelineNodeType type = (TimelineNodeType)typeByte;

		int id;
		unpacker.Unpack(out id);

		int numPrevIDs;
		unpacker.Unpack(out numPrevIDs);
		List<int> previousNodeIDs = new List<int>();
		for (int i = 0; i < numPrevIDs; ++i)
		{
			int prevID;
			unpacker.Unpack(out prevID);
			previousNodeIDs.Add(prevID);
		}

		switch (type)
		{
		case TimelineNodeType.Dialog:
			node = new HamDialogNode();
			break;
		case TimelineNodeType.Branch:
			node = new HamBranchNode();
			break;
		case TimelineNodeType.Decision:
			node = new HamDecisionNode();
			break;
		case TimelineNodeType.Consequence:
			node = new HamConsequenceNode();
			break;
		default:
			node = null;
			return;
		}
		node.ID = id;
		node.Type = type;
		node.PreviousNodeIDs = previousNodeIDs;

		node.Unpack(unpacker);
	}
Example #7
0
        private void VerifyOutput(byte[] input, byte[] output, int bytesWritten)
        {
            Assert.True(bytesWritten > input.Length);
            Assert.True(bytesWritten <= output.Length);
            Assert.True(bytesWritten % (new IdentityTransformer().OutputBlockSize) == 0);

            var pos = ParseHeader(output, bytesWritten);

            Assert.True(pos > 0 && pos < bytesWritten - 1);

            var pairId = DataUnpacker.ReadInt(output, ref pos);

            Assert.Equal(1, pairId);

            var serialId = DataUnpacker.ReadInt(output, ref pos);

            Assert.Equal(2, serialId);

            var payloadSize = DataUnpacker.ReadInt(output, ref pos);

            Assert.Equal(input.Length, payloadSize);

            Assert.True(Enumerable.SequenceEqual(output.Skip(pos).Take(input.Length), input));
        }
Example #8
0
	public void Unpack(DataUnpacker unpacker)
	{
		this.timeline = new HamTimeline();
		this.timeline.Unpack(unpacker);

		int varSize;
		unpacker.Unpack(out varSize);
		for (int i = 0; i < varSize; ++i)
		{
			int key;
			unpacker.Unpack(out key);
			VariableValue val = new VariableValue();
			val.Unpack(unpacker);
			this.variables[key] = val;
		}
		unpacker.Unpack(out this.currentNodeID);
		unpacker.Unpack(out this.currentSceneID);

		int charSize;
		unpacker.Unpack(out charSize);
		for (int i = 0; i < charSize; ++i)
		{
			int next;
			unpacker.Unpack(out next);
			this.currentCharactersInScene.Add(next);
		}

		int historySize;
		unpacker.Unpack(out historySize);
		for (int i = 0; i < historySize; ++i)
		{
			int history;
			unpacker.Unpack(out history);
			this.nodeHistory.Add(history);
		}
	}
Example #9
0
	public override void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.SceneID);

		int size;
		unpacker.Unpack(out size);
		this.CharacterIDs = new List<int>();
		for (int i = 0; i < size; ++i)
		{
			int id;
			unpacker.Unpack(out id);
			this.CharacterIDs.Add(id);
		}

		unpacker.Unpack(out this.SpeakerID);
		unpacker.Unpack(out this.Dialog);
		unpacker.Unpack(out this.NextNodeID);
	}
Example #10
0
	public override void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.DefaultNextID);
		int size;
		this.Predicates = new List<HamPredicate>();
		unpacker.Unpack(out size);
		for (int i = 0; i < size; ++i)
		{
			HamPredicate predicate = new HamPredicate();
			predicate.Unpack(unpacker);
			this.Predicates.Add(predicate);
		}
	}
Example #11
0
	public void Unpack(DataUnpacker unpacker)
	{
		int versionInt;
		unpacker.Unpack(out versionInt);
		// TODO - In the future, we'll want to have separate unpacker functions based on version diffs
		//        For now there aren't any, but we'll stick this version int here for when that day arrives

		unpacker.Unpack(out this.Name);
		unpacker.Unpack(out this.IDCount);
		unpacker.Unpack(out this.OriginNodeID);
		unpacker.Unpack(out this.NarratorID);
		unpacker.Unpack(out this.DefaultSceneID);

		int numVars;
		unpacker.Unpack(out numVars);
		for (int i = 0; i < numVars; ++i)
		{
			HamTimelineVariable variable = new HamTimelineVariable();
			variable.Unpack(unpacker);
			this.Variables[variable.ID] = variable;
		}

		int numScenes;
		unpacker.Unpack(out numScenes);
		for (int i = 0; i < numScenes; ++i)
		{
			HamScene scene = new HamScene();
			scene.Unpack(unpacker);
			this.Scenes[scene.ID] = scene;
		}

		int numCharacters;
		unpacker.Unpack(out numCharacters);
		for (int i = 0; i < numCharacters; ++i)
		{
			HamCharacter character = new HamCharacter();
			character.Unpack(unpacker);
			this.Characters[character.ID] = character;
		}

		int numNodes;
		unpacker.Unpack(out numNodes);
		for (int i = 0; i < numNodes; ++i)
		{
			HamTimelineNode node;
			HamTimelineNode.Unpack(out node, unpacker);
			this.Nodes[node.ID] = node;
		}
	}
Example #12
0
		public void Unpack(DataUnpacker unpacker)
		{
			unpacker.Unpack(out this.DecisionText);
			unpacker.Unpack(out this.IsDialog);

			int size;
			unpacker.Unpack(out size);
			this.Predicates = new List<HamPredicate>();
			for (int i = 0; i < size; ++i)
			{
				HamPredicate p = new HamPredicate();
				p.Unpack(unpacker);
				this.Predicates.Add(p);
			}

			unpacker.Unpack(out this.NextNodeID);
		}
Example #13
0
	public override void Unpack(DataUnpacker unpacker)
	{
		int numDecisions;
		unpacker.Unpack(out numDecisions);
		this.Decisions = new List<Decision>();
		for (int i = 0; i < numDecisions; ++i)
		{
			Decision d = new Decision();
			d.Unpack(unpacker);
			this.Decisions.Add(d);
		}
	}
Example #14
0
	public void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.ID);
		unpacker.Unpack(out this.Name);
	}
Example #15
0
        public static string InterpreterText(Propeller.MemoryManager memory, bool displayAsHexadecimal, bool useShortOpcodes)
        {
            string format;

            if (displayAsHexadecimal)
            {
                format = "{0} ${1:X}";
            }
            else
            {
                format = "{0} {1}";
            }

            Propeller.Spin.Instruction Instr = Propeller.Spin.Instructions[memory.ReadByte()];

            string Name;

            if (useShortOpcodes)
            {
                Name = Instr.NameBrief;
            }
            else
            {
                Name = Instr.Name;
            }

            switch (Instr.ArgumentMode)
            {
            case Propeller.Spin.ArgumentMode.None:
                return(Name);

            case Propeller.Spin.ArgumentMode.UnsignedOffset:
                return(String.Format(format, Name, DataUnpacker.GetPackedOffset(memory)));

            case Propeller.Spin.ArgumentMode.UnsignedEffectedOffset:
                return(String.Format("{0} {1} {2}", Name, DataUnpacker.GetPackedOffset(memory), GetEffectCode(memory, useShortOpcodes)));

            case Propeller.Spin.ArgumentMode.Effect:
                return(String.Format(format, Name, GetEffectCode(memory, useShortOpcodes)));

            case Propeller.Spin.ArgumentMode.SignedOffset:
                return(String.Format(format, Name, DataUnpacker.GetSignedOffset(memory)));

            case Propeller.Spin.ArgumentMode.PackedLiteral:
                return(String.Format(format, Name, DataUnpacker.GetPackedLiteral(memory)));

            case Propeller.Spin.ArgumentMode.ByteLiteral:
                return(String.Format(format, Name, memory.ReadByte()));

            case Propeller.Spin.ArgumentMode.WordLiteral:
                return(String.Format(format, Name, DataUnpacker.GetWordLiteral(memory)));

            case Propeller.Spin.ArgumentMode.NearLongLiteral:
                return(String.Format(format, Name, DataUnpacker.GetNearLongLiteral(memory)));

            case Propeller.Spin.ArgumentMode.LongLiteral:
                return(String.Format(format, Name, DataUnpacker.GetLongLiteral(memory)));

            case Propeller.Spin.ArgumentMode.ObjCallPair:
            {
                byte obj   = memory.ReadByte();
                byte funct = memory.ReadByte();
                return(String.Format("{0} {1}.{2}", Name, obj, funct));
            }

            case Propeller.Spin.ArgumentMode.MemoryOpCode:
                return(String.Format("{0} {1}", Name, GetMemoryOp(memory, useShortOpcodes)));

            default:
                throw new Exception("Unknown Spin Argument Mode: " + Instr.ArgumentMode.ToString());
            }
        }
Example #16
0
	public abstract void Unpack(DataUnpacker unpacker);
Example #17
0
	public override void Unpack(DataUnpacker unpacker)
	{
		unpacker.Unpack(out this.NextNodeID);
		int size;
		unpacker.Unpack(out size);
		this.Operations = new List<HamOperation>();
		for (int i = 0; i < size; ++i)
		{
			HamOperation operation = new HamOperation();
			operation.Unpack(unpacker);
			this.Operations.Add(operation);
		}
	}