Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Mar 6, 2022
0 parents commit f8bec83
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

bin/*
obj/*
*.user
*.xcf
HarmonyPatches/RemoveSplashscreen.cs
HarmonyPatchHelper.cs
Screenshots/SocialPreview.jpg
35 changes: 35 additions & 0 deletions Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]
namespace HitscoreCounter {
internal class Config {
public static Config Instance { get; set; }


public virtual bool verticalLayout { get; set; } = true;

[NonNullable, UseConverter]
public virtual List<int> splits { get; set; } = new List<int>() { 115, 114, 110, 100, 0 };

public static IEnumerable<int> FilterSplitsList(IEnumerable<int> splits) {
var x = splits.Where(x => x <= ScoreModel.kMaxCutRawScore && x >= 0).Distinct().OrderByDescending(x => x);

if(!x.Any())
return new[] { 115 };

return x;
}

public virtual void Changed() {
var x = FilterSplitsList(splits);

if(!x.SequenceEqual(splits))
splits = x.ToList();
}
}
}
101 changes: 101 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file contains the build tasks and targets for verifying the manifest, zipping Release builds,
and copying the plugin to to your Beat Saber folder. Only edit this if you know what you are doing. -->
<Project>
<PropertyGroup>
<BuildTargetsVersion>2.0</BuildTargetsVersion>
<!--Set this to true if you edit this file to prevent automatic updates-->
<BuildTargetsModified>false</BuildTargetsModified>
<!--Output assembly path without extension-->
<OutputAssemblyName>$(OutputPath)$(AssemblyName)</OutputAssemblyName>
<!--Path to folder to be zipped. Needs to be relative to the project directory to work without changes to the 'BuildForCI' target.-->
<ArtifactDestination>$(OutputPath)Final</ArtifactDestination>
<ErrorOnMismatchedVersions Condition="'$(Configuration)' == 'Release'">True</ErrorOnMismatchedVersions>
</PropertyGroup>
<!--Build Targets-->
<!--Displays a warning if BeatSaberModdingTools.Tasks is not installed.-->
<Target Name="CheckBSMTInstalled" AfterTargets="BeforeBuild" Condition="'$(BSMTTaskAssembly)' == ''">
<Warning Text="The BeatSaberModdingTools.Tasks nuget package doesn't seem to be installed, advanced build targets will not work." />
</Target>
<!--Runs a build task to get info about the project used by later targets.-->
<Target Name="GetProjectInfo" AfterTargets="CheckBSMTInstalled" DependsOnTargets="CheckBSMTInstalled" Condition="'$(BSMTTaskAssembly)' != ''">
<Message Text="Using AssemblyVersion defined in project instead of 'Properties\AssemblyInfo.cs'" Importance="high" Condition="'$(AssemblyVersion)' != ''" />
<GetManifestInfo FailOnError="$(ErrorOnMismatchedVersions)">
<Output TaskParameter="PluginVersion" PropertyName="PluginVersion" />
<Output TaskParameter="BasePluginVersion" PropertyName="BasePluginVersion" />
<Output TaskParameter="GameVersion" PropertyName="GameVersion" />
</GetManifestInfo>
<PropertyGroup>
<AssemblyVersion>$(BasePluginVersion)</AssemblyVersion>
<FileVersion>$(BasePluginVersion)</FileVersion>
<InformationalVersion>$(BasePluginVersion)</InformationalVersion>
</PropertyGroup>
<GetCommitInfo ProjectDir="$(ProjectDir)">
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
<Output TaskParameter="Branch" PropertyName="Branch" />
<Output TaskParameter="Modified" PropertyName="GitModified" />
</GetCommitInfo>
<PropertyGroup>
<!--Build name for artifact/zip file-->
<ArtifactName>$(AssemblyName)</ArtifactName>
<ArtifactName Condition="'$(PluginVersion)' != ''">$(ArtifactName)-$(PluginVersion)</ArtifactName>
<ArtifactName Condition="'$(GameVersion)' != ''">$(ArtifactName)-bs$(GameVersion)</ArtifactName>
<ArtifactName Condition="'$(CommitHash)' != '' AND '$(CommitHash)' != 'local'">$(ArtifactName)-$(CommitHash)</ArtifactName>
</PropertyGroup>
</Target>
<!--Build target for Continuous Integration builds. Set up for GitHub Actions.-->
<Target Name="BuildForCI" AfterTargets="Build" DependsOnTargets="GetProjectInfo" Condition="'$(ContinuousIntegrationBuild)' == 'True' AND '$(BSMTTaskAssembly)' != ''">
<PropertyGroup>
<!--Set 'ArtifactName' if it failed before.-->
<ArtifactName Condition="'$(ArtifactName)' == ''">$(AssemblyName)</ArtifactName>
</PropertyGroup>
<Message Text="Building for CI" Importance="high" />
<Message Text="PluginVersion: $(PluginVersion), AssemblyVersion: $(AssemblyVersion), GameVersion: $(GameVersion)" Importance="high" />
<Message Text="::set-output name=filename::$(ArtifactName)" Importance="high" />
<Message Text="::set-output name=assemblyname::$(AssemblyName)" Importance="high" />
<Message Text="::set-output name=artifactpath::$(ProjectDir)$(ArtifactDestination)" Importance="high" />
<Message Text="Copying '$(OutputAssemblyName).dll' to '$(ProjectDir)$(ArtifactDestination)\Plugins\$(AssemblyName).dll'" Importance="high" />
<Copy SourceFiles="$(OutputAssemblyName).dll" DestinationFiles="$(ProjectDir)$(ArtifactDestination)\Plugins\$(AssemblyName).dll" />
</Target>
<!--Creates a BeatMods compliant zip file with the release.-->
<Target Name="ZipRelease" AfterTargets="Build" Condition="'$(DisableZipRelease)' != 'True' AND '$(Configuration)' == 'Release' AND '$(BSMTTaskAssembly)' != ''">
<PropertyGroup>
<!--Set 'ArtifactName' if it failed before.-->
<ArtifactName Condition="'$(ArtifactName)' == ''">$(AssemblyName)</ArtifactName>
<DestinationDirectory>$(OutDir)zip\</DestinationDirectory>
</PropertyGroup>
<ItemGroup>
<OldZips Include="$(DestinationDirectory)$(AssemblyName)*.zip"/>
</ItemGroup>
<Copy SourceFiles="$(OutputAssemblyName).dll" DestinationFiles="$(ArtifactDestination)\Plugins\$(AssemblyName).dll" />
<Message Text="PluginVersion: $(PluginVersion), AssemblyVersion: $(AssemblyVersion), GameVersion: $(GameVersion)" Importance="high" />
<Delete Files="@(OldZips)" TreatErrorsAsWarnings="true" ContinueOnError="true" />
<ZipDir SourceDirectory="$(ArtifactDestination)" DestinationFile="$(DestinationDirectory)$(ArtifactName).zip" />
</Target>
<!--Copies the assembly and pdb to the Beat Saber folder.-->
<Target Name="CopyToPlugins" AfterTargets="Build" Condition="'$(DisableCopyToPlugins)' != 'True' AND '$(ContinuousIntegrationBuild)' != 'True'">
<PropertyGroup>
<PluginDir>$(BeatSaberDir)\Plugins</PluginDir>
<CanCopyToPlugins>True</CanCopyToPlugins>
<CopyToPluginsError Condition="!Exists('$(PluginDir)')">Unable to copy assembly to game folder, did you set 'BeatSaberDir' correctly in your 'csproj.user' file? Plugins folder doesn't exist: '$(PluginDir)'.</CopyToPluginsError>
<!--Error if 'BeatSaberDir' does not have 'Beat Saber.exe'-->
<CopyToPluginsError Condition="!Exists('$(BeatSaberDir)\Beat Saber.exe')">Unable to copy to Plugins folder, '$(BeatSaberDir)' does not appear to be a Beat Saber game install.</CopyToPluginsError>
<!--Error if 'BeatSaberDir' is the same as 'LocalRefsDir'-->
<CopyToPluginsError Condition="'$(BeatSaberDir)' == '$(LocalRefsDir)' OR '$(BeatSaberDir)' == ''">Unable to copy to Plugins folder, 'BeatSaberDir' has not been set in your 'csproj.user' file.</CopyToPluginsError>
<CanCopyToPlugins Condition="'$(CopyToPluginsError)' != ''">False</CanCopyToPlugins>
</PropertyGroup>
<!--Check if Beat Saber is running-->
<IsProcessRunning ProcessName="Beat Saber" Condition="'$(BSMTTaskAssembly)' != ''">
<Output TaskParameter="IsRunning" PropertyName="IsRunning" />
</IsProcessRunning>
<PropertyGroup>
<!--If Beat Saber is running, output to the Pending folder-->
<PluginDir Condition="'$(IsRunning)' == 'True'">$(BeatSaberDir)\IPA\Pending\Plugins</PluginDir>
</PropertyGroup>
<Warning Text="$(CopyToPluginsError)" Condition="'$(CopyToPluginsError)' != ''" />
<Message Text="Copying '$(OutputAssemblyName).dll' to '$(PluginDir)'." Importance="high" Condition="$(CanCopyToPlugins)" />
<Copy SourceFiles="$(OutputAssemblyName).dll" DestinationFiles="$(PluginDir)\$(AssemblyName).dll" Condition="$(CanCopyToPlugins)" />
<Copy SourceFiles="$(OutputAssemblyName).pdb" DestinationFiles="$(PluginDir)\$(AssemblyName).pdb" Condition="'$(CanCopyToPlugins)' == 'True' AND Exists('$(OutputAssemblyName).pdb')" />
<Warning Text="Beat Saber is running, restart the game to use the latest build." Condition="'$(IsRunning)' == 'True'" />
</Target>
</Project>
123 changes: 123 additions & 0 deletions HitscoreCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using CountersPlus.Counters.Custom;
using CountersPlus.Counters.Interfaces;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using TMPro;
using UnityEngine;

namespace HitscoreCounter {
public class HitscoreCounter : BasicCustomCounter, INoteEventHandler, ISaberSwingRatingCounterDidFinishReceiver {
TMP_Text[] hintLabels;
TMP_Text[] valueLabels;
int[] targets;
int[] values;

public override void CounterInit() {
var label = CanvasUtility.CreateTextFromSettings(Settings);
label.text = "Hitscores";
label.fontSize = 3;

TMP_Text CreateLabel(TextAlignmentOptions align, Vector3 offset, float fontSize = 2.69f) {
var x = CanvasUtility.CreateTextFromSettings(Settings, offset);
x.text = "0";
x.alignment = align;
x.fontSize = fontSize;

return x;
}

var countersCount = Config.Instance.splits.Count;

hintLabels = new TMP_Text[countersCount];
valueLabels = new TMP_Text[countersCount];
values = new int[countersCount];
targets = new int[countersCount];

var totalWidth = countersCount * 0.5f;
var halfWidth = totalWidth / 2f;
var labelStep = totalWidth / (countersCount - 1);

if(Config.Instance.verticalLayout) {
for(var i = countersCount; i-- != 0;) {
hintLabels[i] = CreateLabel(TextAlignmentOptions.CaplineRight, new Vector3(-0.25f, -0.3f - (i * 0.25f)));
valueLabels[i] = CreateLabel(TextAlignmentOptions.CaplineLeft, new Vector3(0.25f, -0.3f - (i * 0.25f)), 3f);
}
} else {
if(countersCount == 1) {
labelStep = 0;
halfWidth = 0;
}

for(var i = countersCount; i-- != 0;) {
hintLabels[i] = CreateLabel(TextAlignmentOptions.Center, new Vector3((i * labelStep) - halfWidth, -0.3f));
valueLabels[i] = CreateLabel(TextAlignmentOptions.Center, new Vector3((i * labelStep) - halfWidth, -0.6f), 3f);
}
}

var prevValue = ScoreModel.kMaxCutRawScore + 1;
for(var i = 0; i < countersCount; i++) {
if(!Config.Instance.verticalLayout)
hintLabels[i].fontStyle = FontStyles.Underline;

if(i == countersCount - 1 && Config.Instance.splits[i] == 0) {
hintLabels[i].text = $"<{prevValue}";
targets[i] = -1;
break;
}

if(prevValue - Config.Instance.splits[i] > 1) {
if(i == 0) {
hintLabels[i].text = $">{Config.Instance.splits[i] - 1}";
} else {
hintLabels[i].text = $"{prevValue - 1}-{Config.Instance.splits[i]}";

if(!Config.Instance.verticalLayout)
hintLabels[i].fontSize = 2.2f;
}
} else {
hintLabels[i].text = Config.Instance.splits[i].ToString();
}
prevValue = Config.Instance.splits[i];
targets[i] = Config.Instance.splits[i] - 1;
}
}

public override void CounterDestroy() {
hintLabels = null;
valueLabels = null;
targets = null;
values = null;
}

void IncrementValueLabelForHitscore(int hitscore) {
for(var i = 0; i < targets.Length; i++) {
if(hitscore > targets[i]) {
valueLabels[i].text = (++values[i]).ToString();
return;
}
}
}

private Dictionary<ISaberSwingRatingCounter, float> noteCutAccs = new Dictionary<ISaberSwingRatingCounter, float>();
public void OnNoteCut(NoteData data, NoteCutInfo info) {
if(!info.allIsOK || data.colorType == ColorType.None)
return;

noteCutAccs.Add(info.swingRatingCounter, info.cutDistanceToCenter);
info.swingRatingCounter.RegisterDidFinishReceiver(this);
}

public void OnNoteMiss(NoteData data) { }

public void HandleSaberSwingRatingCounterDidFinish(ISaberSwingRatingCounter saberSwingRatingCounter) {
if(!noteCutAccs.TryGetValue(saberSwingRatingCounter, out var nci))
return;

noteCutAccs.Remove(saberSwingRatingCounter);

ScoreModel.RawScoreWithoutMultiplier(saberSwingRatingCounter, nci, out int beforeCut, out int afterCut, out int cutDistance);

IncrementValueLabelForHitscore(beforeCut + afterCut + cutDistance);
}
}
}
126 changes: 126 additions & 0 deletions HitscoreCounter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>8</LangVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<RootNamespace>HitscoreCounter</RootNamespace>
<LocalRefsDir Condition="Exists('..\Refs')">..\Refs</LocalRefsDir>
<BeatSaberDir>$(LocalRefsDir)</BeatSaberDir>
<AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase>
<Nullable>disable</Nullable>
<Product>HitscoreCounter</Product>
<Company />
<Authors>Kinsi55</Authors>
<Copyright>Kinsi55</Copyright>
<RepositoryType></RepositoryType>
<RepositoryUrl></RepositoryUrl>
<Description></Description>
<Platforms>x64</Platforms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<Import Project="SuppressRefereces.targets" />

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>DEBUG</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<OutputPath>bin\Debug</OutputPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>none</DebugType>
<OutputPath>bin\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="$(DefineConstants.Contains('CIBuild')) OR '$(NCrunch)' == '1'">
<DisableCopyToPlugins>True</DisableCopyToPlugins>
</PropertyGroup>
<PropertyGroup Condition="'$(NCrunch)' == '1'">
<DisableCopyToPlugins>True</DisableCopyToPlugins>
<DisableZipRelease>True</DisableZipRelease>
</PropertyGroup>
<ItemGroup>
<None Remove="Images\icon.png" />
<None Remove="settings.bsml" />
</ItemGroup>

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="BeatmapCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll</HintPath>
</Reference>
<Reference Include="Counters+">
<HintPath>$(BeatSaberDir)\Plugins\Counters+.dll</HintPath>
</Reference>
<Reference Include="GameplayCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\GameplayCore.dll</HintPath>
</Reference>
<Reference Include="System"></Reference>
<Reference Include="System.Core"></Reference>
<Reference Include="System.Xml.Linq"></Reference>
<Reference Include="System.Data.DataSetExtensions"></Reference>
<Reference Include="System.Data"></Reference>
<Reference Include="System.Xml"></Reference>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
</Reference>
<Reference Include="HMLib">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
</Reference>
<Reference Include="HMUI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll</HintPath>
</Reference>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\icon.png" />
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="settings.bsml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks">
<Version>1.4.3</Version>
<IncludeAssets>build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Update="System.Drawing"></Reference>
</ItemGroup>
<ItemGroup>
<Reference Update="System.IO.Compression.FileSystem"></Reference>
</ItemGroup>
<ItemGroup>
<Reference Update="System.Numerics"></Reference>
</ItemGroup>
<ItemGroup>
<Reference Update="System.Runtime.Serialization"></Reference>
</ItemGroup>
</Project>
Binary file added Images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/ss.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f8bec83

Please sign in to comment.