Skip to content

Commit

Permalink
Counters+ has been BSIPA-ified while I wait for CustomUI to fix the g…
Browse files Browse the repository at this point in the history
…od damn bugs.
  • Loading branch information
Caeden117 committed Apr 7, 2019
1 parent 3f78d4d commit c53d599
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 46 deletions.
14 changes: 11 additions & 3 deletions Counters+/Counters+.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CountersPlus</RootNamespace>
<AssemblyName>Counters+</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -39,9 +39,14 @@
<HintPath>D:\Oculus\Software\Software\hyperbolic-magnetism-beat-saber\Plugins\BeatSaberCustomUI.dll</HintPath>
</Reference>
<Reference Include="BS_Utils" />
<Reference Include="IllusionInjector, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
<Reference Include="IllusionPlugin" />
<Reference Include="INIFileParser" />
<Reference Include="IPA.Loader, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\Oculus\Software\Software\hyperbolic-magnetism-beat-saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
</Reference>
<Reference Include="SemVer.1.2.0.0">
<HintPath>D:\Oculus\Software\Software\hyperbolic-magnetism-beat-saber\Libs\SemVer.1.2.0.0.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -135,6 +140,9 @@
<ItemGroup>
<EmbeddedResource Include="UI\Images\WotAreYeDoin.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="manifest.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetPath)" "D:\Oculus\Software\Software\hyperbolic-magnetism-beat-saber\Plugins\CountersPlus.dll"</PostBuildEvent>
Expand Down
4 changes: 2 additions & 2 deletions Counters+/Counters/ScoreCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public string GetRank(int score, float prec)
return "E";
}

private void _OnNoteWasMissed(NoteData noteData, int score)
private void _OnNoteWasMissed(NoteData data, int score)
{
notes++;
if (data.noteType != NoteType.Bomb) notes++;
UpdateScore(_currentScore);
}

Expand Down
11 changes: 6 additions & 5 deletions Counters+/CountersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using CountersPlus.Counters;
using CountersPlus.Custom;
using UnityEngine.SceneManagement;
using IllusionInjector;
using IllusionPlugin;
using IPA.Loader;
using IniParser;
using IniParser.Model;
using TMPro;
using System.Collections;
using IPA.Old;

namespace CountersPlus
{
Expand Down Expand Up @@ -81,7 +80,9 @@ public static void LoadCounters()
{
if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
{
if (!PluginManager.Plugins.Any((IPlugin x) => x.Name == section.Keys["ModCreator"])) return;
if (PluginManager.GetPlugin(section.Keys["ModCreator"]) == null &&
#pragma warning disable CS0618 //Fuck off DaNike
PluginManager.Plugins.Where((IPlugin x) => x.Name == section.Keys["ModCreator"]) == null) return;
CustomConfigModel potential = new CustomConfigModel(section.SectionName);
LoadCounter<CustomConfigModel, CustomCounterHook>(section.Keys["SectionName"], potential);
}
Expand All @@ -91,7 +92,7 @@ public static void LoadCounters()
for (int i = 0; i < GameObject.Find("ComboPanel").transform.childCount; i++)
{
GameObject child = GameObject.Find("ComboPanel").transform.GetChild(i).gameObject;
if (child.name != "BG") Destroy(child);
if (child.name != "BG") child.SetActive(false);
}
}
if (settings.HideMultiplier)
Expand Down
20 changes: 17 additions & 3 deletions Counters+/Custom/CustomCounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
using System.Text;
using System.Threading.Tasks;
using CountersPlus.Config;
using IllusionPlugin;
using IPA.Loader;
using UnityEngine;
using UnityEngine.SceneManagement;
using CustomUI.Settings;
using System.Threading;
using System.IO;
using IniParser.Model;
using IniParser;
using IPA;
using IPA.Old;

namespace CountersPlus.Custom
{
Expand All @@ -30,12 +32,19 @@ public static void CreateCustomCounter<T>(T model, params ICounterPositions[] re
foreach (SectionData section in data.Sections)
{
if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
{
if (section.SectionName == model.Name) return;
}
}
if (scene.name == "" || scene.name == "Init" || scene.name == "EmptyTransition" || scene.name == "HealthWarning")
{
string modCreator = "";
if (model.Mod != null)
modCreator = model.Mod.Name;
if (model.BSIPAMod != null)
{ //Fucking hell DaNike can't you expose the IBeatSaberPlugins so it would be easier for stuff like this!?!?
PluginLoader.PluginInfo info = PluginManager.AllPlugins.Where((PluginLoader.PluginInfo x) => model.BSIPAMod == x.GetPrivateField<IBeatSaberPlugin>("Plugin")).FirstOrDefault();
if (info != null)
modCreator = info.Metadata.Name;
}
CustomConfigModel counter = new CustomConfigModel(model.Name)
{
DisplayName = model.Name,
Expand Down Expand Up @@ -77,8 +86,13 @@ public class CustomCounter
/// <summary>
/// The plugin that created this custom counter. Will be displayed in the Settings UI.
/// </summary>
#pragma warning disable CS0618 //Fuck off DaNike
public IPlugin Mod { get; set; }
/// <summary>
/// The plugin that created this custom counter. Will be displayed in the Settings UI.
/// </summary>
public IBeatSaberPlugin BSIPAMod { get; set; }
/// <summary>
/// The name of the counter that will be added when it gets created.
/// </summary>
public string Counter { get; set; }
Expand Down
60 changes: 36 additions & 24 deletions Counters+/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
using IllusionPlugin;
using System;
using System;
using System.IO;
using UnityEngine.SceneManagement;
using UnityEngine;
using System.Linq;
using CountersPlus.UI;
using IPA;
using IPA.Logging;

namespace CountersPlus
{
public class Plugin : IPlugin
public class Plugin : IBeatSaberPlugin
{
public string Name => "Counters+";
public string Version => "1.5.3";
internal static Plugin Instance;
public enum LogInfo { Info, Warning, Error, Fatal };
internal static IPA.Logging.Logger Logger;
public enum LogInfo { Info, Warning, Notice, Error, Fatal };
internal static BS_Utils.Utilities.Config config = new BS_Utils.Utilities.Config("CountersPlus"); //Conflicts with CountersPlus.Config POG
internal static bool upToDate = true;
internal static string webVersion;

public void OnApplicationStart()
public void Init(object thisIsNull, IPA.Logging.Logger log)
{
VersionChecker.GetOnlineVersion();
Logger = log;
VersionChecker.GetOnlineVersion();
Instance = this;
if (!File.Exists(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini"))
File.Create(Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/CountersPlus.ini");
SceneManager.activeSceneChanged += SceneManager_sceneLoaded;
SceneManager.sceneLoaded += AddUI;
CountersController.OnLoad();
}

private void SceneManager_sceneLoaded(Scene arg0, Scene arg1)
public void OnApplicationStart()
{

}

public void OnActiveSceneChanged(Scene arg0, Scene arg1)
{
//if (CountersController.settings.Enabled) CountersController.OnLoad();
if (arg1.name == "GameCore" &&
Expand All @@ -43,25 +47,19 @@ private void SceneManager_sceneLoaded(Scene arg0, Scene arg1)
}
}

private void AddUI(Scene arg, LoadSceneMode hiBrian)
public void OnSceneLoaded(Scene arg, LoadSceneMode hiBrian)
{
try
{
if (arg.name == "MenuCore") MenuUI.CreateUI();
}catch(Exception e)
{
Log(e.ToString(), LogInfo.Fatal);
Log(e.ToString(), LogInfo.Fatal, "Install your dependencies!");
}
}

public void OnApplicationQuit()
{
SceneManager.activeSceneChanged -= SceneManager_sceneLoaded;
SceneManager.sceneLoaded -= AddUI;
}

public void OnLevelWasLoaded(int level) { }
public void OnLevelWasInitialized(int level) { }
public void OnApplicationQuit() { }
public void OnSceneUnloaded(Scene scene) { }
public void OnUpdate() { }
public void OnFixedUpdate() { }

Expand All @@ -72,9 +70,23 @@ public static void Log(string m)

public static void Log(string m, LogInfo l)
{
Console.WriteLine("Counters+ [" + l.ToString() + "] | " + m);
if (l == LogInfo.Fatal)
Console.WriteLine("Counters+ [IMPORTANT] | Contact Caeden117#0117 on Discord with this issue!");
Log(m, l, null);
}

public static void Log(string m, LogInfo l, string suggestedAction)
{
IPA.Logging.Logger.Level level = IPA.Logging.Logger.Level.Debug;
switch (l)
{
case LogInfo.Info: level = IPA.Logging.Logger.Level.Debug; break;
case LogInfo.Notice: level = IPA.Logging.Logger.Level.Notice; break;
case LogInfo.Warning: level = IPA.Logging.Logger.Level.Warning; break;
case LogInfo.Error: level = IPA.Logging.Logger.Level.Error; break;
case LogInfo.Fatal: level = IPA.Logging.Logger.Level.Critical; break;
}
Logger.Log(level, m);
if (suggestedAction != null)
Logger.Log(level, $"Suggested Action: {suggestedAction}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading;
using BS_Utils.Gameplay;
using System.Collections;
using IPA.Loader;

namespace CountersPlus.UI
{
Expand Down Expand Up @@ -70,7 +71,7 @@ internal static void CreateCredits()
setPositioning(name.rectTransform, 0, 0.7f, 1, 0.166f, 0.5f);

version = BeatSaberUI.CreateText(rect,
$"Version <color={(Plugin.upToDate ? "#00FF00" : "#FF0000")}>{Plugin.Instance.Version}</color>", Vector2.zero);
$"Version <color={(Plugin.upToDate ? "#00FF00" : "#FF0000")}>{PluginManager.GetPlugin("Counters+").Metadata.Version.ToString()}</color>", Vector2.zero);
version.fontSize = 3;
version.alignment = TextAlignmentOptions.Center;
setPositioning(version.rectTransform, 0, 0.5f, 1, 0.166f, 0.5f);
Expand Down Expand Up @@ -205,7 +206,7 @@ public static void UpdateSettings<T>(T settings, SettingsInfo info) where T : IC
loadedElements.Add(settingsTitle.gameObject);
foreach (ListViewController list in loadedSettings) list.Init();
}
catch(Exception e) { Plugin.Log(e.ToString(), Plugin.LogInfo.Fatal); }
catch(Exception e) { Plugin.Log(e.ToString(), Plugin.LogInfo.Fatal, "Go to the Counters+ GitHub and open an Issue."); }
}

private static SubMenu CreateBase<T>(T settings, params ICounterPositions[] restricted) where T : IConfigModel
Expand All @@ -226,6 +227,7 @@ private static SubMenu CreateBase<T>(T settings, params ICounterPositions[] rest

var position = AddList(ref sub, settings, "Position", "The relative position of common UI elements", (restrictedList.Count() == 0) ? positions.Count() : restrictedList.Count());
position.GetTextForValue = (v) => {
Plugin.Log(v.ToString());
if (restrictedList.Count() == 0)
return positions[Mathf.RoundToInt(v)].Item2;
else
Expand All @@ -235,7 +237,6 @@ private static SubMenu CreateBase<T>(T settings, params ICounterPositions[] rest
return positions.ToList().IndexOf(positions.Where((Tuple<ICounterPositions, string> x) => (x.Item1 == settings.Position)).First());
};
position.SetValue += (v) => {
Plugin.Log(v.ToString());
if (restrictedList.Count() == 0)
settings.Position = positions[Mathf.RoundToInt(v)].Item1;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
using IniParser.Model;
using IniParser;
using CountersPlus.Custom;
using IllusionInjector;
using IllusionPlugin;
using System.Collections;
using CountersPlus.UI.Images;
using TMPro;
using CustomUI.Settings;
using IPA.Loader;

namespace CountersPlus.UI
{
Expand Down Expand Up @@ -46,7 +45,7 @@ protected override void DidActivate(bool firstActivation, ActivationType type)
if (section.Keys.Any((KeyData x) => x.KeyName == "SectionName"))
{
CustomConfigModel potential = new CustomConfigModel(section.SectionName);
if (!PluginManager.Plugins.Any((IPlugin x) => x.Name == section.Keys["ModCreator"])) continue;
if (PluginManager.GetPlugin(section.Keys["ModCreator"]) == null) continue;
counterInfos.Add(new SettingsInfo()
{
Name = potential.DisplayName,
Expand Down Expand Up @@ -151,7 +150,7 @@ private void onCellSelect(TableView view, int row)
SettingsListInit = true;
}
SettingsInfo info = null;
if (row > 0 && row < NumberOfCells() - 2) info = counterInfos[row - 2];
if (row > 0 && row < NumberOfCells() - 2) info = counterInfos[row - 1];
if (row == 0) CountersPlusEditViewController.ShowMainSettings();
else if (row == NumberOfCells() - 2) CountersPlusEditViewController.CreateCredits();
else if (row == NumberOfCells() - 1) CountersPlusEditViewController.ShowContributors();
Expand Down
6 changes: 4 additions & 2 deletions Counters+/Utils/VersionChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UnityEngine;
using UnityEngine.Networking;
using SimpleJSON;
using IPA.Loader;

namespace CountersPlus
{
Expand Down Expand Up @@ -57,9 +58,10 @@ private static IEnumerator GetOnlineVersionRoutine()

private static bool isLatestVersion(string downloadedVersion)
{
string Version = PluginManager.GetPlugin("Counters+").Metadata.Version.ToString();
List<int> pluginVersion = new List<int>();
List<int> webVersion = new List<int>();
foreach(string num in Plugin.Instance.Version.Split('.'))
foreach(string num in Version.Split('.'))
pluginVersion.Add(int.Parse(num));
foreach (string num in downloadedVersion.Split('.'))
webVersion.Add(int.Parse(num));
Expand All @@ -70,7 +72,7 @@ private static bool isLatestVersion(string downloadedVersion)
else if (pluginVersion[i] < webVersion[i]) return false;
else if (pluginVersion[i] > webVersion[i]) return true;
}
if (Plugin.Instance.Version == downloadedVersion) return true;
if (Version == downloadedVersion) return true;
return false;
}
}
Expand Down
11 changes: 11 additions & 0 deletions Counters+/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://github.com/nike4613/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "Caeden117",
"description": "A collection of widely used counters, all configurable in one mod!",
"gameVersion": "0.13.2",
"id": "countersplus",
"name": "Counters+",
"version": "1.5.4",
"features": [
]
}

0 comments on commit c53d599

Please sign in to comment.