Example #1
0
        /// <summary>
        /// Assume we're running a command and have save game data.
        /// </summary>
        /// <param name="gameFile"></param>
        /// <param name="saveFile"></param>
        /// <param name="command"></param>
        public EngineWrapper(byte[] gameFile, byte[] saveFile, string command)
        {
            if (gameFile == null)
                throw new Exception("Missing game data.");

            if (saveFile == null)
                throw new Exception("Missing required save file.");

            if (command == "")
                throw new Exception("Missing command.");

            MemoryStream gameData = new MemoryStream(gameFile);
            saveFileData = new MemoryStream(saveFile);

            vm = new Engine(gameData, saveFileData);

            wrapperState = VMWrapperState.LoadGame;
            if (command == "restore.current.game")
            {
                requestType = VMRequestType.NoCommand;
            }
            else
            {
                requestType = VMRequestType.ExecuteCommand;
            }

            // save the user's command for later
            saveCommand = command;

            Run();
        }
Example #2
0
        public void SendCommand(string command)
        {
            wrapperState = VMWrapperState.RunCommand;
            requestType  = VMRequestType.ExecuteCommand;

            saveCommand = command;

            vm.Continue();
        }
Example #3
0
        public void Restore(byte[] restoreData)
        {
            restoreStream = new MemoryStream(restoreData);

            wrapperState = VMWrapperState.RequestRestore;
            requestType  = VMRequestType.ExecuteCommand;

            needLine = true;

            vm.Continue();
        }
Example #4
0
        /// <summary>
        /// Load the game and return data.
        /// </summary>
        /// <param name="gameFile"></param>
        public EngineWrapper(byte[] gameFile)
        {
            if (gameFile == null)
            {
                throw new Exception("Missing game file.");
            }

            MemoryStream gameData = new MemoryStream(gameFile);

            vm = new Engine(gameData);

            requestType  = VMRequestType.StartGame;
            wrapperState = VMWrapperState.LoadGame;

            Run();
        }
Example #5
0
        private void vm_OutputReady(object sender, OutputReadyEventArgs e)
        {
            // ----------- DECIDE TO STORE OUTPUT --------------

            if (!needLine || wrapperState == VMWrapperState.LoadGame)
            {
                if ((wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.StartGame) || wrapperState == VMWrapperState.RunCommand)
                {
                    HandleOutput((Dictionary <string, string>)e.Package);
                }

                // ----------- DETERMINE STATE -------------

                if (wrapperState == VMWrapperState.RequestSave)
                {
                    outSaveFile  = saveStream.ToArray();
                    wrapperState = VMWrapperState.Completed;
                    vm.Stop();
                }

                if (wrapperState == VMWrapperState.RunCommand || (wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.StartGame))
                {
                    wrapperState = VMWrapperState.RequestSave;
                }

                if (wrapperState == VMWrapperState.RequestRestore && requestType == VMRequestType.ExecuteCommand)
                {
                    wrapperState = VMWrapperState.RunCommand;
                }

                if (wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.ExecuteCommand)
                {
                    wrapperState = VMWrapperState.RequestRestore;
                }

                needLine = true;
            }
        }
Example #6
0
        /// <summary>
        /// Load the game and return data.
        /// </summary>
        /// <param name="gameFile"></param>
        public EngineWrapper(byte[] gameFile)
        {
            if (gameFile == null)
                throw new Exception("Missing game file.");

            MemoryStream gameData = new MemoryStream(gameFile);

            vm = new Engine(gameData);

            requestType = VMRequestType.StartGame;
            wrapperState = VMWrapperState.LoadGame;

            Run();
        }
Example #7
0
        //private void SetChannelData(string channel, Dictionary<string, string> package, XmlWriter writer)
        //{
        //    string text = "";
        //    string channelName = channel;
        //    if (package.TryGetValue(channel, out text))
        //    {
        //        WriteElementCDATA(writer, channelName, text.Trim());
        //    }
        //    else
        //    {
        //        WriteElementCDATA(writer, channelName, "");
        //    }
        //}
        //private void SetChannelDataJSON(string channel, Dictionary<string, string> package, JsonTextWriter writer)
        //{
        //    string text = "";
        //    string channelName = channel;
        //    if (package.TryGetValue(channel, out text))
        //    {
        //        writer.WritePropertyName(channel);
        //        writer.WriteValue(text);
        //    }
        //    else
        //    {
        //        writer.WritePropertyName(channel);
        //        writer.WriteValue("");
        //    }
        //}
        //private void WriteElementCDATA(XmlWriter xWriter, string elementName, string text)
        //{
        //    xWriter.WriteStartElement(elementName);
        //    xWriter.WriteCData(text);
        //    xWriter.WriteEndElement();
        //}
        private void vm_OutputReady(object sender, OutputReadyEventArgs e)
        {
            // ----------- DECIDE TO STORE OUTPUT --------------

            if ((wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.StartGame) || wrapperState == VMWrapperState.RunCommand)
            {
                HandleOutput((Dictionary<string, string>)e.Package);
            }

            // ----------- DETERMINE STATE -------------

            if (wrapperState == VMWrapperState.RequestSave)
            {
                outSaveFile = saveStream.ToArray();
                vm.Stop();
            }

            if (wrapperState == VMWrapperState.RunCommand || (wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.StartGame))
                wrapperState = VMWrapperState.RequestSave;

            if (wrapperState == VMWrapperState.RequestRestore && requestType == VMRequestType.ExecuteCommand)
                wrapperState = VMWrapperState.RunCommand;

            if (wrapperState == VMWrapperState.LoadGame && requestType == VMRequestType.ExecuteCommand)
                wrapperState = VMWrapperState.RequestRestore;
        }
Example #8
0
        public void SendCommand(string command)
        {
            wrapperState = VMWrapperState.LoadGame;
            requestType = VMRequestType.ExecuteCommand;

            saveCommand = command;

            vm.Continue();
        }