Esempio n. 1
0
        /// <summary>
        /// Reads all of the new lines in a log file
        /// </summary>
        private void readNewLines(object source, FileSystemEventArgs e) // When fortnite writes to the file, run this - vastly more efficient than getting screenshots :)
        {
            string        CurrentLine = "";
            List <string> NewLines    = new List <string>();       // holds the new lines that were just written to the file

            if (isLogFileEmpty())                                  // this is true when fortnite has started up and has cleared the existing log file
            {
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin); // reset log position
            }

            while ((CurrentLine = streamReader.ReadLine()) != null)
            {
                if (CurrentLine != "")         // if the line is new, add it to the list.
                {
                    NewLines.Add(CurrentLine); // list because it can usually be 2 or more per update.
                }
            }

            foreach (string i in NewLines)                             // go through the new lines.
            {
                if (i.Contains("to [UI.State.Startup.SubgameSelect]")) // Title menu
                {
                    Debug.WriteLine("State: Subgame");
                    FortniteState = FortniteState.Title;
                    RefreshPlayingMusic();
                }

                if (i.Contains("to [UI.State.Athena.Frontend]") || i.Contains("to FrontEnd")) // Main Menu // "to FrontEnd" is for STW support.
                {
                    Debug.WriteLine("State: FrontEnd");
                    FortniteState = FortniteState.Menu;
                    RefreshPlayingMusic();
                }

                if (i.Contains("NewState: Finished")) // Matchmaking finished
                {
                    Debug.WriteLine("State: MatchmakingFinished");
                    FortniteState = FortniteState.InGame;
                    RefreshPlayingMusic();
                }

                if (i.Contains("current=WaitingPostMatch")) // game end
                {
                    FortniteState = FortniteState.GameEnd;
                    RefreshPlayingMusic();
                }

                if (i.Contains("Preparing to exit")) // Fortnite closed
                {
                    Debug.WriteLine("State: Exit");
                    FortniteState = FortniteState.None;
                    RefreshPlayingMusic();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads all of the new lines in a log file
        /// </summary>
        private void readNewLines(object source, FileSystemEventArgs e) // When fortnite writes to the file, run this - vastly more efficient than getting screenshots :)
        {
            // Create the stream reader and file system if the file exists.
            if (fileStream == null && streamReader == null && File.Exists(fortniteLogDirectory + @"\FortniteGame.log"))
            {
                fileStream   = File.Open(fortniteLogDirectory + @"\FortniteGame.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                streamReader = new StreamReader(fileStream);
            }

            if (fileStream == null && streamReader == null)
            {
                return;                                            // If still null just return, it wasn't created
            }
            if (isLogFileEmpty())                                  // this is true when fortnite has started up and has cleared the existing log file
            {
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin); // reset log position
            }
            // Get all of the new lines in the log file since the last update
            List <string> newLines = new List <string>();
            string        currentLine;

            while ((currentLine = streamReader.ReadLine()) != null) // This crashes some times and idk why (some encoding problem) only happens once in a while so probably isn't a problem. Just relaunch the program!
            {
                if (currentLine != "")
                {
                    newLines.Add(currentLine);
                }
            }

            foreach (string i in newLines)                             // go through the new lines.
            {
                if (i.Contains("to [UI.State.Startup.SubgameSelect]")) // Title menu
                {
                    Debug.WriteLine("State: Subgame");
                    FortniteState = FortniteState.Title;
                    RefreshPlayingMusic();
                }
                else if (i.Contains("to [UI.State.Athena.Frontend]") || i.Contains("to FrontEnd")) // Main Menu // "to FrontEnd" is for STW support.
                {
                    Debug.WriteLine("State: FrontEnd");
                    FortniteState = FortniteState.Menu;
                    RefreshPlayingMusic();
                }
                else if (i.Contains("NewState: Finished")) // Matchmaking finished
                {
                    Debug.WriteLine("State: MatchmakingFinished");
                    FortniteState = FortniteState.InGame;
                    RefreshPlayingMusic();
                }
                else if (i.Contains("current=WaitingPostMatch")) // game end
                {
                    FortniteState = FortniteState.GameEnd;
                    RefreshPlayingMusic();
                }
                else if (i.Contains("Preparing to exit")) // Fortnite closed
                {
                    Debug.WriteLine("State: Exit");
                    FortniteState = FortniteState.None;
                    RefreshPlayingMusic();
                }
            }
        }
 private static void OnGameStateUpdated(FortniteState state)
 {
     RefreshPlayingMusic();
 }
        /// <summary>
        /// Reads all of the new lines in a log file
        /// </summary>
        private static void readNewLines(object source, FileSystemEventArgs e) // When fortnite writes to the file, run this - vastly more efficient than getting screenshots :)
        {
            // Create the stream reader and file system if the file exists.
            if (streamReader == null && File.Exists(fortniteLogDirectory + @"\FortniteGame.log"))
            {
                FileStream fileStream = File.Open(fortniteLogDirectory + @"\FortniteGame.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                streamReader = new StreamReader(fileStream);
            }

            if (streamReader == null)
            {
                return;                                            // If still null just return, it wasn't created
            }
            if (isLogFileEmpty())                                  // this is true when fortnite has started up and has cleared the existing log file
            {
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin); // reset log position
            }
            FortniteState?newFortniteState = null;
            // Get all of the new lines in the log file since the last update
            string currentLine;

            while ((currentLine = streamReader.ReadLine()) != null) // go through the new lines.
            {
                // Menu
                if (currentLine.Contains("to [UI.State.Athena.Frontend]") ||
                    currentLine.Contains("to FrontEnd")) // Main Menu // "to FrontEnd" is for STW support.
                {
                    newFortniteState = FortniteState.Menu;
                }

                // In Game
                else if (currentLine.Contains("NewState: Finished") || // Matchmaking finished
                         currentLine.Contains(
                             "BeginTearingDown for /Game/Maps/Frontend")) // Save the world matchmaking finish
                {
                    newFortniteState = FortniteState.InGame;
                }

                // Post match
                else if (currentLine.Contains("current=WaitingPostMatch") || // game end for fortnitebr
                         currentLine.Contains("End of Match (FortGameStatePvE"))    // game end for stw
                {
                    newFortniteState = FortniteState.GameEnd;
                }

                // Game closed
                else if (currentLine.Contains("Preparing to exit")) // Fortnite closed
                {
                    newFortniteState = FortniteState.None;
                }
            }

            // Call back that the fortnite log file has changed
            if (newFortniteState != null)
            {
                FortniteState = (FortniteState)newFortniteState;
                foreach (GameStatusCallback callback in callbacks)
                {
                    callback(FortniteState);
                }
            }

            streamReader.DiscardBufferedData();
        }