示例#1
0
        public void SetOnlineGame(string viewerId, BGA.TableData table, JSONObject bgaData)
        {
            Logger.Instance.Log("LOG", "NWInterface: SetOnlineGame()");
            try
            {
                Clear();

                BGA.BoardData board = new BGA.BoardData(viewerId, table);

                string bgaDataDebugString = JSONTools.FormatJsonDisplay(bgaData);
                foreach (string chunk in splitInLineChunks(bgaDataDebugString, 500))
                {
                    Logger.Instance.Log("DETAIL", chunk);
                }

                GameStateReader gameStateReader = new GameStateReader(bgaData, board);
                if (!gameStateReader.IsValid)
                {
                    Logger.Instance.Log("ERROR", "invalid gamestate received from server");
                }
                gamestate = gameStateReader.convertToGameState();

                gameData.SetOnlineGame(board, gameStateReader.initMoveId, gameStateReader.initPacketId);
            }
            catch (System.Exception e)
            {
                Logger.Instance.Log("ERROR", e.ToString());
                BGA.BoardData board = new BGA.BoardData(viewerId, table);
                gamestate = null;
                gameData.SetOnlineGame(board, 0, 0);
            }
        }
示例#2
0
 static void MainSimple(string[] args)
 {
     using (var streamProvider = new PipBoyStreamProvider())
         using (var stream = streamProvider.ReadFile("data.dump"))
         {
             var gameStateReader = new GameStateReader(stream);
             while (gameStateReader.NextState())
             {
                 Console.WriteLine("Player X position: " + (float)gameStateReader.GameState.Map.World.Player.X);
             }
         }
 }
示例#3
0
        private static void ReadStream(Stream stream)
        {
            //var gameStateReader = new GameStateReader(stream, new GameStateReaderDebugSettings { Writer = Console.Out, DumpInitialPacketParsing = true, DumpPacketParsing = true });
            var gameStateReader = new GameStateReader(stream);

            gameStateReader.NextState();        // read first state
            var playerPosition = (GameObject)gameStateReader.GameState.Map.World.Player;

            playerPosition.Changed += PlayerPosition_Changed;

            while (!Console.KeyAvailable && gameStateReader.NextState())
            {
                // process events
            }
        }
示例#4
0
        public void Dump(Stream stream)
        {
            if (_objectFile != null)
            {
                using (var writer = new StreamWriter(new FileStream(_objectFile, FileMode.Create)))
                {
                    try
                    {
                        //var gameStateReader = new GameStateReader(stream, new GameStateReaderDebugSettings { Writer = writer, DumpInitialPacketParsing = true, DumpPacketParsing = true });
                        var gameStateReader = new GameStateReader(stream);
                        gameStateReader.NextState(); // read first state
                        var state = (GameObject)gameStateReader.GameState;
                        writer.WriteLine(state.ToString(true));
                        state.Changed += (s, e) =>
                        {
                            foreach (var changedChild in e.ChangedChildren)
                            {
                                writer.WriteLine(changedChild.ToString(true));
                            }
                            writer.WriteLine("===============================================================================");
                        };

                        while (!_cancelTokenSource.Token.IsCancellationRequested && gameStateReader.NextState())
                        {
                            // do nothing
                        }

                        return;
                    }
                    catch (Exception e)
                    {
                        writer.WriteLine("Exception reading game objects: " + e.Message);
                        writer.WriteLine(e.StackTrace);
                    }
                }
            }

            // if no objectFile or an exception occured
            ReadToEnd(stream);
        }