Example #1
0
        private void ProcessPsarcFile(string psarcFile)
        {
            //Return if file is already cached
            if (cache.Contains(psarcFile))
            {
                return;
            }

            //Read psarc data
            Dictionary <string, SongDetails> allSongDetails;

            try
            {
                allSongDetails = PSARCUtil.ReadPSARCHeaderData(psarcFile);
            }
            catch
            {
                Logger.LogError("Unable to read {0}", psarcFile);
                return;
            }

            //If loading was successful
            if (allSongDetails != null)
            {
                //Add this CDLC file to the cache
                cache.Add(psarcFile, allSongDetails);
            }
        }
Example #2
0
        private void ProcessPsarcFile(string psarcFile)
        {
            var fileInfo = new FileInfo(psarcFile);

            // Try to hash the psarc file
            string hash;

            try
            {
                hash = PSARCUtil.GetFileHash(fileInfo);
            }
            catch (Exception e)
            {
                Logger.LogError("Unable to calculate hash for {0}", psarcFile);
                Logger.LogException(e);
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //Return if file is already cached
            if (_cache.Contains(psarcFile, hash))
            {
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //Read psarc data
            Dictionary <string, SongDetails> allSongDetails;

            try
            {
                allSongDetails = PSARCUtil.ReadPSARCHeaderData(fileInfo);
            }
            catch (Exception e)
            {
                Logger.LogError("Unable to read {0}", psarcFile);
                Logger.LogException(e);
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //If loading was successful
            if (allSongDetails != null)
            {
                //In case file hash was different
                //or if this is a newer psarc with the same song ids
                //Remove all existing entries
                _cache.Remove(psarcFile, allSongDetails.Keys.ToList());

                //Add this CDLC file to the cache
                _cache.Add(psarcFile, allSongDetails);
            }

            PsarcFileProcessingDone(psarcFile, true);
        }
Example #3
0
        public void Run()
        {
            //Clear output / create output files
            ClearOutput();

            Logger.Log("Waiting for rocksmith");

            if (config.customsForgeSettings.Enabled)
            {
                customsForgeHandler = new CustomsForgeHandler(cache as SQLiteCache);
            }

            //Loop infinitely trying to find rocksmith process
            while (true)
            {
                var processes = Process.GetProcessesByName("Rocksmith2014");

                //Sleep for 1 second if no processes found
                if (processes.Length == 0)
                {
                    Thread.Sleep(1000);
                    continue;
                }

                //Select the first rocksmith process and open a handle
                rsProcess = processes[0];

                if (rsProcess.HasExited || !rsProcess.Responding)
                {
                    Thread.Sleep(1000);
                    continue;
                }

                break;
            }

            Logger.Log("Rocksmith found! Sniffing...");

            //Check rocksmith executable hash to make sure its the correct version
            string hash = PSARCUtil.GetFileHash(new FileInfo(rsProcess.MainModule.FileName));

            Logger.Log($"Rocksmith executable hash: {hash}");

            if (!hash.Equals("GxT+/TXLpUFys+Cysek8zg=="))
            {
                Logger.LogError("Executable hash does not match expected hash, make sure you have the correct version");
                Logger.Log("Press any key to exit");
                Console.ReadKey();
                Environment.Exit(0);
            }

            //Initialize file handle reader and memory reader
            Sniffer sniffer = new Sniffer(rsProcess, cache, config.snifferSettings);

            //Listen for events
            sniffer.OnSongChanged   += Sniffer_OnCurrentSongChanged;
            sniffer.OnMemoryReadout += Sniffer_OnMemoryReadout;

            //Add RPC event listeners
            if (config.rpcSettings.enabled)
            {
                rpcHandler = new DiscordRPCHandler(sniffer);
            }

            if (config.lastFMSettings.Enabled)
            {
                lastFMHandler = new LastFMHandler(sniffer);
            }

            //Inform AddonService
            if (config.addonSettings.enableAddons && addonService != null)
            {
                addonService.SetSniffer(sniffer);
            }

            while (true)
            {
                if (rsProcess == null || rsProcess.HasExited)
                {
                    break;
                }

                OutputDetails();

                //GOTTA GO FAST
                Thread.Sleep(1000);

                if (random.Next(100) == 0)
                {
                    Console.WriteLine("*sniff sniff*");
                }
            }

            sniffer.Stop();

            //Clean up as best as we can
            rsProcess.Dispose();
            rsProcess = null;

            rpcHandler?.Dispose();
            rpcHandler = null;

            lastFMHandler?.Dispose();
            lastFMHandler = null;

            customsForgeHandler = null;

            Logger.Log("This is rather unfortunate, the Rocksmith2014 process has vanished :/");
        }
Example #4
0
        private async Task <bool> UpdateCurrentDetails(string filepath)
        {
            //If the song has not changed, and the details object is valid, no need to update
            //Compare song id's in lowercase because the preview audio name is not guaranteed to match
            if (currentCDLCDetails.IsValid() && currentMemoryReadout.songID.ToLowerInvariant() == currentCDLCDetails.songID.ToLowerInvariant())
            {
                return(true);
            }

            //If songID is empty, we aren't gonna be able to do anything here
            if (currentMemoryReadout.songID == "")
            {
                return(true);
            }

            if (Logger.logSongDetails)
            {
                Logger.Log("Looking for '{0}' in psarc file: {1}", currentMemoryReadout.songID, filepath);
            }

            //Check if this psarc file is cached
            if (cache.Contains(filepath))
            {
                //Load from cache if it is
                currentCDLCDetails = cache.Load(filepath, currentMemoryReadout.songID);

                //If cache failed to load
                if (currentCDLCDetails == null)
                {
                    //Set invalid song details
                    currentCDLCDetails = new SongDetails();

                    //Return false, this is probably not the correct file
                    return(false);
                }

                //Print current details (if debug is enabled) and print warnings about this dlc
                currentCDLCDetails.Print();

                //Invoke event
                OnSongChanged?.Invoke(this, new OnSongChangedArgs()
                {
                    songDetails = currentCDLCDetails
                });

                //Exit function as data was handled from cache
                return(true);
            }

            //Read psarc data into the details object
            var allSongDetails = await Task.Run(() => PSARCUtil.ReadPSARCHeaderData(filepath));

            //If loading failed
            if (allSongDetails == null)
            {
                //Exit function
                return(true);
            }

            //If this is the songs.psarc file, we should merge RS1 DLC into it
            if (filepath.EndsWith("songs.psarc"))
            {
                //Really ugly way to find the rs1 dlc psarc
                string rs1dlcpath = filepath.Replace("songs.psarc", "dlc" + System.IO.Path.DirectorySeparatorChar + "rs1compatibilitydlc_p.psarc");

                //Read the rs1 dlc psarc
                var rs1SongDetails = await Task.Run(() => PSARCUtil.ReadPSARCHeaderData(rs1dlcpath));

                //If we got rs1 dlc arrangements
                if (rs1SongDetails != null)
                {
                    //Combine the two dictionaries
                    allSongDetails = allSongDetails.Concat(rs1SongDetails).ToDictionary(k => k.Key, v => v.Value);
                }
            }

            //If the song detail dictionary contains the song ID we are looking for
            if (allSongDetails.ContainsKey(currentMemoryReadout.songID))
            {
                //Assign current CDLC details
                currentCDLCDetails = allSongDetails[currentMemoryReadout.songID];
            }

            //Add this CDLC file to the cache
            cache.Add(filepath, allSongDetails);

            //Print current details (if debug is enabled) and print warnings about this dlc
            currentCDLCDetails.Print();

            //Invoke event
            OnSongChanged?.Invoke(this, new OnSongChangedArgs()
            {
                songDetails = currentCDLCDetails
            });

            return(true);
        }