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);
        }
Exemple #2
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 :/");
        }