public override void CounterInit() { if (PluginConfig.Instance.HideDuringReplay && Utils.Utils.IsInReplay()) { _logger.Info("We are in a replay, Counter hides."); return; } if (!Refresh()) { _logger.Info("Can't Refresh"); _logger.Info("Please check your settings about data source and the link or id."); return; } CreateCounter(); Utils.GamePause.GameStart(); try { _bpmDownloader.Start(); _logger.Info("Start updating heart rate"); } catch (Exception e) { _logger.Critical("Could not start bpm downloader."); _logger.Error(e.Message); _logger.Debug(e); _bpmDownloader.Stop(); return; } Start(); _logger.Info("Start updating counter text"); }
public void Init(IPA.Logging.Logger log) { if (_init) { return; } _init = true; logger = log; harmonyInstance = HarmonyInstance.Create("slaynash.discordpresence"); gameObject = Resources.FindObjectsOfTypeAll <MonoBehaviour>().First(c => c.GetType().Name == "PluginComponent"); try { logger.Info("Initializing"); logger.Info("Starting Discord RichPresence"); var handlers = new DiscordRpc.EventHandlers(); DiscordRpc.Initialize(DiscordAppID, ref handlers, false, string.Empty); logger.Info("Fetching nonpublic fields"); _gameplayCoreSceneSetupDataField = typeof(GameplayCoreSceneSetup).GetField("_sceneSetupData", BindingFlags.NonPublic | BindingFlags.Instance); _oneColorBeatmapCharacteristic = typeof(GameplayCoreSceneSetup).GetField("_oneColorBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); _90DegreeBeatmapCharacteristic = typeof(GameplayCoreSceneSetup).GetField("_90DegreeBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); _360DegreeBeatmapCharacteristic = typeof(GameplayCoreSceneSetup).GetField("_360DegreeBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); #if DEBUG logger.Debug("Discord Presence - Field SceneSetup<GameplayCoreSceneSetupData>._sceneSetupData: " + _gameplayCoreSceneSetupDataField); #endif if (_gameplayCoreSceneSetupDataField == null) { logger.Error("Unable to fetch SceneSetup<GameplayCoreSceneSetupData>._sceneSetupData"); return; } logger.Info("Init done !"); } catch (Exception e) { logger.Error("Unable to initialize plugin:\n" + e); } }
public void Initialize() { _bottomScreen = _hierarchyManager.transform.Find("BottomScreen"); if (!_bottomScreen) { _logger.Error("BottomScreen transform not found!"); return; } _settings.PropertyChanged += OnSettingsPropertyChanged; UpdateScale(); }
public void OnApplicationStart() { config = Conf.CreateConfig(ConfigType.YAML, BeatSaber.UserDataPath, "Particular"); try { HarmonyInstance harmony = HarmonyInstance.Create("com.jackbaron.beatsaber.particular"); harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch (Exception e) { log.Error( "This plugin requires Harmony. Make sure you installed the plugin properly, " + "as the Harmony DLL should have been installed with it." ); log.Critical(e); } }
private bool CreateCounter() { _logger.Info("Creating counter"); _counter = CanvasUtility.CreateTextFromSettings(Settings); _counter.fontSize = 3; _counter.text = ""; var canvas = CanvasUtility.GetCanvasFromID(Settings.CanvasID); if (canvas == null) { Logger.logger.Warn("Cannot find counters+ canvas"); return(false); } var counter = AssetBundleManager.SetupCustomCounter(); _customCounter = counter.Icon; _customCounterText = counter.Numbers; if (_customCounter == null || _customCounterText == null) { _logger.Error("Cannot create custom counter"); return(false); } // position the counter as the counters+ one _customCounter.transform.localScale = Vector3.one / 30; _customCounter.transform.SetParent(canvas.transform, false); _customCounter.GetComponent <RectTransform>().anchoredPosition = _counter.rectTransform.anchoredPosition; _customCounter.transform.localPosition -= new Vector3(2, 0, 0); // recenter OnHRUpdate(null, new HRUpdateEventArgs(BPM.Instance.Bpm)); // give it an initial value if (counter.CurrentCanvas != null) { // destroy the unused game obj Object.Destroy(counter.CurrentCanvas); } HRController.OnHRUpdate += OnHRUpdate; return(true); }
public Plugin(IPALogger _logger) { instance = this; log = _logger; log?.Debug("Logger initialized."); if (_init) { return; } _init = true; logger = log; harmonyInstance = new Harmony(HarmonyId); gameObject = Resources.FindObjectsOfTypeAll <MonoBehaviour>() .First(c => c.GetType().Name == "PluginComponent"); try { logger?.Info("Initializing"); logger?.Info("Starting Discord RichPresence"); var handlers = new DiscordRpc.EventHandlers(); DiscordRpc.Initialize(DiscordAppID, ref handlers, false, string.Empty); logger?.Info("Fetching nonpublic fields"); _gameplayCoreSceneSetupDataField = typeof(GameplayCoreSceneSetupData).GetField("_sceneSetupData", BindingFlags.NonPublic | BindingFlags.Instance); _oneColorBeatmapCharacteristic = typeof(GameplayCoreSceneSetupData).GetField("_oneColorBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); _90DegreeBeatmapCharacteristic = typeof(GameplayCoreSceneSetupData).GetField("_90DegreeBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); _360DegreeBeatmapCharacteristic = typeof(GameplayCoreSceneSetupData).GetField("_360DegreeBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance); logger?.Info("Init done !"); } catch (Exception e) { logger?.Error("Unable to initialize plugin:\n" + e); } }
public void Initialize() { _logger.Debug("HRController Init"); if (_bpmDownloader == null) { _logger.Warn("BPM Downloader is null!"); return; } _bpmDownloader.OnHRUpdate += OnHRUpdateInternalHandler; try { _bpmDownloader.Start(); _logger.Info("Start updating heart rate"); } catch (Exception e) { _logger.Error($"Could not start bpm downloader. {e.Message}"); _logger.Debug(e); _bpmDownloader.OnHRUpdate -= OnHRUpdateInternalHandler; _bpmDownloader.Stop(); } }
public void OnStart() { _logger.Info("Starting " + typeof(Plugin).Namespace); try { OpenVRUtilities.Init(); } catch (Exception ex) { _logger.Error("Failed to initialize OpenVR API; DynamicOpenVR will not run"); _logger.Error(ex); return; } _logger.Info("Successfully initialized OpenVR API"); // adding the manifest to config is more of a quality of life thing try { AddManifestToSteamConfig(); } catch (Exception ex) { _logger.Error("Failed to update SteamVR manifest."); _logger.Error(ex); } RegisterActionSet(); ApplyHarmonyPatches(); OpenVRActionManager.instance.Initialize(kActionManifestPath); SceneManager.sceneLoaded += OnSceneLoaded; OpenVREventHandler.instance.eventTriggered += OnOpenVREventTriggered; }
private IEnumerator UpdatePresenceAfterFrame() { // Wait for next frame yield return(true); // Fetch all required objects _mainFlowCoordinator = Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().FirstOrDefault(); _gameplaySetup = Resources.FindObjectsOfTypeAll <GameplayCoreSceneSetup>().FirstOrDefault(); if (_z == null) { _z = Resources.FindObjectsOfTypeAll <Component>().FirstOrDefault(c => c != null && c.GetType().Name == "Z"); if (_z == null) { logger.Warn("No element of type \"Z\" found. Maybe the game isn't running a version of ScoreSaber supporting replay ?"); } } if (_gameplaySetup != null) { _mainSetupData = _gameplayCoreSceneSetupDataField.GetValue(_gameplaySetup) as GameplayCoreSceneSetupData; } #if DEBUG logger.Debug("_gameplaySetup: " + _gameplaySetup); logger.Debug("_gameplayCoreSceneSetupDataField: " + _gameplayCoreSceneSetupDataField); logger.Debug("_mainSetupData: " + _mainSetupData); GetFlowTypeHumanReadable(); // Used to debug print values #endif // Check if every required object is found if (_mainSetupData == null || _gameplaySetup == null || _mainFlowCoordinator == null) { logger.Error("Error finding the scriptable objects required to update presence. (_mainSetupData: " + (_mainSetupData == null ? "N/A" : "OK") + ", _gameplaySetup: " + (_gameplaySetup == null ? "N/A" : "OK") + ", _mainFlowCoordinator: " + (_mainFlowCoordinator == null ? "N/A" : "OK")); Presence.details = "Playing"; DiscordRpc.UpdatePresence(Presence); yield break; } // Set presence main values IDifficultyBeatmap diff = _mainSetupData.difficultyBeatmap; Presence.details = $"{diff.level.songName} | {diff.difficulty.Name()}"; Presence.state = ""; if (_z != null) { //Console.WriteLine("--------------------------"); FieldInfo[] fields = _z.GetType().GetFields((BindingFlags)(-1)); foreach (FieldInfo fi in fields) { if (fi.FieldType.Name == "Mode" && fi.GetValue(_z).ToString() == "Playback") { Presence.state += "[Replay] "; } //logger.Debug("Discord Presence - [" + fi.Name + ": " + fi.FieldType.Name + "] => " + fi.GetValue(_z)); } } if (diff.level.levelID.Contains('∎')) { Presence.state += "Custom | "; } if (_mainSetupData.practiceSettings != null) { Presence.state += "Practice | "; } Presence.state += GetFlowTypeHumanReadable() + " "; #if DEBUG logger.Debug("Discord Presence - diff.parentDifficultyBeatmapSet.beatmapCharacteristic: " + diff.parentDifficultyBeatmapSet.beatmapCharacteristic); logger.Debug("Discord Presence - _gameplaySetup._oneColorBeatmapCharacteristic: " + typeof(GameplayCoreSceneSetup).GetField("_oneColorBeatmapCharacteristic", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_gameplaySetup)); #endif // Update gamemode (Standard / One Saber / No Arrow) if (_mainSetupData.gameplayModifiers.noArrows || diff.parentDifficultyBeatmapSet.beatmapCharacteristic.ToString().ToLower().Contains("noarrow")) { _gamemode = GameMode.NoArrows; } else if (diff.parentDifficultyBeatmapSet.beatmapCharacteristic == (BeatmapCharacteristicSO)_oneColorBeatmapCharacteristic.GetValue(_gameplaySetup)) { _gamemode = GameMode.OneSaber; } else if (diff.parentDifficultyBeatmapSet.beatmapCharacteristic.ToString().ToLower().Contains("90degree")) { _gamemode = GameMode.NinetyDegree; } else if (diff.parentDifficultyBeatmapSet.beatmapCharacteristic.ToString().ToLower().Contains("360degree")) { _gamemode = GameMode.ThreeSixtyDegree; } else { _gamemode = GameMode.Standard; } string gameplayModeText = _gamemode == GameMode.OneSaber ? "One Saber" : _gamemode == GameMode.NoArrows ? "No Arrow" : _gamemode == GameMode.NinetyDegree ? "90º" : _gamemode == GameMode.ThreeSixtyDegree ? "360º" : "Standard"; Presence.state += gameplayModeText; // Set music speak if (_mainSetupData.practiceSettings != null) { if (_mainSetupData.practiceSettings.songSpeedMul != 1.0f) { Presence.state += " | Speed x" + _mainSetupData.practiceSettings.songSpeedMul; } } else { if (_mainSetupData.gameplayModifiers.songSpeedMul != 1.0f) { Presence.state += " | Speed x" + _mainSetupData.gameplayModifiers.songSpeedMul; } } // Set common gameplay modifiers if (_mainSetupData.gameplayModifiers.noFail) { Presence.state += " | No Fail"; } if (_mainSetupData.gameplayModifiers.instaFail) { Presence.state += " | Instant Fail"; } if (_mainSetupData.gameplayModifiers.disappearingArrows) { Presence.state += " | Disappearing Arrows"; } if (_mainSetupData.gameplayModifiers.ghostNotes) { Presence.state += " | Ghost Notes"; } Presence.largeImageKey = "default"; Presence.largeImageText = "Beat Saber"; Presence.smallImageKey = GetFlowTypeHumanReadable() == "Party" ? "party" : _gamemode == GameMode.OneSaber ? "one_saber" : _gamemode == GameMode.NoArrows ? "no_arrows" : _gamemode == GameMode.NinetyDegree ? "90" : _gamemode == GameMode.ThreeSixtyDegree ? "360" : "solo"; Presence.smallImageText = gameplayModeText; Presence.startTimestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; // Set startTimestamp offset if we are in training mode if (_mainSetupData.practiceSettings != null) { #if DEBUG logger.Debug("Discord Presence - _mainSetupData.practiceSettings.startSongTime: " + _mainSetupData.practiceSettings.startSongTime); #endif if (_mainSetupData.practiceSettings.startInAdvanceAndClearNotes) { Presence.startTimestamp -= (long)Mathf.Max(0f, _mainSetupData.practiceSettings.startSongTime - 3f); } else { Presence.startTimestamp -= (long)_mainSetupData.practiceSettings.startSongTime; } } DiscordRpc.UpdatePresence(Presence); }
public static void Log(Exception e) { logger.Error(e); }
public void Error(string message) { logSource.Error(message); }
public void Error(object message) { _logger.Error(message?.ToString()); }