Skip to content

Commit

Permalink
Lots of changes, see release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mystogan98 committed Mar 26, 2020
1 parent 4d37e37 commit 2549b84
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 75 deletions.
9 changes: 7 additions & 2 deletions BeatSaviorData/BeatSaviorData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BSML">
<HintPath>..\..\..\..\..\..\Games\steamapps\common\Beat Saber\Plugins\BSML.dll</HintPath>
</Reference>
<Reference Include="BS_Utils">
<HintPath>D:\Logiciels\Steam\steamapps\common\Beat Saber\Plugins\BS_Utils.dll</HintPath>
<HintPath>..\..\..\..\..\..\Games\steamapps\common\Beat Saber\Plugins\BS_Utils.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json.12.0.0.0">
<HintPath>D:\Logiciels\Steam\steamapps\common\Beat Saber\IPA\Libs\Newtonsoft.Json.12.0.0.0.dll</HintPath>
<HintPath>..\..\..\..\..\..\Games\steamapps\common\Beat Saber\Libs\Newtonsoft.Json.12.0.0.0.dll</HintPath>
</Reference>
<Reference Include="Oculus.VR">
<HintPath>..\..\..\..\..\..\Games\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Oculus.VR.dll</HintPath>
Expand Down Expand Up @@ -106,6 +109,7 @@
<Compile Include="Logger.cs" />
<Compile Include="PrivateKeys.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SettingsMenu.cs" />
<Compile Include="SongData.cs" />
<Compile Include="Trackers\AccuracyTracker.cs" />
<Compile Include="Trackers\HitTracker.cs" />
Expand All @@ -119,6 +123,7 @@
</ItemGroup>
<ItemGroup>
<None Include="BuildTargets.targets" />
<EmbeddedResource Include="UI\Views\SettingsView.bsml" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
17 changes: 7 additions & 10 deletions BeatSaviorData/HTTPManager.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace BeatSaviorData
{
class HTTPManager
{
public static readonly HttpClient client = new HttpClient();

public static bool uploadJson(string json)
public async static void uploadJson(string json)
{
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage success = await client.PostAsync(PrivateKeys.BeatSaviorUploadUrl, content);

if (client.PostAsync(PrivateKeys.BeatSaviorUploadUrl, content).Result.IsSuccessStatusCode)
return true;
return false;
if (success.IsSuccessStatusCode)
Logger.log.Info("BSD : Upload succeeded !");
else
Logger.log.Info("BSD : Upload failed.");
}
}
}
32 changes: 16 additions & 16 deletions BeatSaviorData/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using IPA;
using IPA.Config;
using IPA.Utilities;
using IPA;
using UnityEngine.SceneManagement;
using UnityEngine;
using IPALogger = IPA.Logging.Logger;
using BS_Utils.Gameplay;
using BS_Utils.Utilities;
using Newtonsoft.Json;
using BeatSaberMarkupLanguage.Settings;

namespace BeatSaviorData
{
Expand All @@ -25,6 +17,9 @@ public class Plugin : IBeatSaberPlugin

public void OnApplicationStart()
{
bool a = SettingsMenu.instance.DisableFails;
a = SettingsMenu.instance.DisablePass;

if (!init)
{
BSEvents.levelCleared += UploadData;
Expand All @@ -33,6 +28,8 @@ public void OnApplicationStart()
BSEvents.levelRestarted += OnLevelRestarted;*/
init = true;
}

BSMLSettings.instance.AddSettingsMenu("BeatSaviorData", "BeatSaviorData.UI.Views.SettingsView.bsml", SettingsMenu.instance);
}

private void UploadData(StandardLevelScenesTransitionSetupDataSO data, LevelCompletionResults results)
Expand All @@ -42,11 +39,13 @@ private void UploadData(StandardLevelScenesTransitionSetupDataSO data, LevelComp
if (!songData.IsAReplay() && !songData.IsPraticeMode()) {
string json = songData.FinalizeData(results);
ShowData(json);
// upload
if (HTTPManager.uploadJson(json))
Logger.log.Info("BSD : Upload succeeded !");

if (results.levelEndStateType == LevelCompletionResults.LevelEndStateType.Cleared && SettingsMenu.instance.DisablePass)
Logger.log.Info("Pass upload is disabled.");
else if (results.levelEndStateType == LevelCompletionResults.LevelEndStateType.Failed && SettingsMenu.instance.DisableFails)
Logger.log.Info("Fail upload is disabled.");
else
Logger.log.Info("BSD : Upload failed.");
HTTPManager.uploadJson(json);
}
else if (songData.IsAReplay()) {
Logger.log.Info("BSD : That was a replay you cheater (╯°□°)╯︵ ┻━┻");
Expand All @@ -61,8 +60,9 @@ private void UploadData(StandardLevelScenesTransitionSetupDataSO data, LevelComp

public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
{
if (nextScene.name == "GameCore")
songData = new SongData();
if(!SettingsMenu.instance.DisableFails || !SettingsMenu.instance.DisablePass)
if (nextScene.name == "GameCore")
songData = new SongData();
}

#region InterfaceImplementation
Expand Down
24 changes: 24 additions & 0 deletions BeatSaviorData/SettingsMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BeatSaberMarkupLanguage.Attributes;
using BS_Utils.Utilities;

namespace BeatSaviorData
{
class SettingsMenu : PersistentSingleton<SettingsMenu>
{
private static readonly Config config = new Config("BeatSaviorData");

[UIValue("DisablePass")]
public bool DisablePass
{
get => config.GetBool("BeatSaviorData", "DisablePass", false, true);
set => config.SetBool("BeatSaviorData", "DisablePass", value);
}

[UIValue("DisableFail")]
public bool DisableFails
{
get => config.GetBool("BeatSaviorData", "DisableFails", false, true);
set => config.SetBool("BeatSaviorData", "DisableFails", value);
}
}
}
3 changes: 0 additions & 3 deletions BeatSaviorData/SongData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using BS_Utils.Gameplay;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using BeatSaviorData.Trackers;
using Newtonsoft.Json;
Expand Down
26 changes: 18 additions & 8 deletions BeatSaviorData/Trackers/AccuracyTracker.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BeatSaviorData.Trackers
{
class AccuracyTracker : ITracker
{
public float accRight, accLeft, averageAcc;
public float[] gridAcc = new float[12];
public float[] gridAcc = new float[12], leftAverageCut = new float[3], rightAverageCut = new float[3], averageCut = new float[3];

private int cutRight, cutLeft;
private int[] gridCut = new int[12];
Expand All @@ -21,10 +17,18 @@ public void EndOfSong(LevelCompletionResults results)
{
accRight = Utils.SafeDivide(accRight, cutRight);
accLeft = Utils.SafeDivide(accLeft, cutLeft);

for (int i = 0; i < 12; i++)
gridAcc[i] = Utils.SafeDivide(gridAcc[i], gridCut[i]);
// This doesn't take into account the number of note hit by each hand, gotta change that
averageAcc = (accRight + accLeft) / 2;

for (int i = 0; i < 3; i++) {
leftAverageCut[i] = Utils.SafeDivide(leftAverageCut[i], cutLeft);
rightAverageCut[i] = Utils.SafeDivide(rightAverageCut[i], cutRight);
averageCut[i] = (rightAverageCut[i] * cutRight + leftAverageCut[i] * cutLeft) / (cutRight + cutLeft);
averageCut[i] = Utils.SafeAverage(rightAverageCut[i], cutRight, leftAverageCut[i], cutLeft);
}

averageAcc = Utils.SafeAverage(accRight, cutRight, accLeft, cutLeft);
}

public void OnNoteCut(BeatmapObjectSpawnController bosc, INoteController data, NoteCutInfo info)
Expand Down Expand Up @@ -53,11 +57,17 @@ private void WaitForSwing(SaberSwingRatingCounter s)
{
cutLeft++;
accLeft += before + acc + after;
leftAverageCut[0] += before;
leftAverageCut[1] += acc;
leftAverageCut[2] += after;
}
else if (type == Saber.SaberType.SaberB)
{
cutRight++;
accRight += before + acc + after;
rightAverageCut[0] += before;
rightAverageCut[1] += acc;
rightAverageCut[2] += after;
}

gridCut[thisIsBullshit[s].Value]++;
Expand Down
30 changes: 13 additions & 17 deletions BeatSaviorData/Trackers/HitTracker.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeatSaviorData.Trackers
namespace BeatSaviorData.Trackers
{
class HitTracker : ITracker
{
Expand All @@ -30,26 +24,27 @@ public void OnNoteCut(BeatmapObjectSpawnController bosc, INoteController data, N
case NoteType.NoteB:
rightNoteHit++;
break;
case NoteType.Bomb:
bombHit++;
break;
}
} else
{
miss++;
if (combo > maxCombo)
maxCombo = combo;
combo = 0;
if (data.noteData.noteType == NoteType.Bomb)
bombHit++;
else
miss++;
}
}

private void BreakComboWall()
{
if (combo > maxCombo)
maxCombo = combo;
combo = 0;
}

public void OnNoteMissed(BeatmapObjectSpawnController bosc, INoteController data)
{
if (data.noteData.noteType != NoteType.Bomb)
{
if (combo > maxCombo)
maxCombo = combo;
combo = 0;
miss++;
}
}
Expand All @@ -58,6 +53,7 @@ public void RegisterTracker(SongData data)
{
data.GetBOSC().noteWasCutEvent += OnNoteCut;
data.GetBOSC().noteWasMissedEvent += OnNoteMissed;
data.GetScoreController().comboBreakingEventHappenedEvent += BreakComboWall;
}
}
}
8 changes: 1 addition & 7 deletions BeatSaviorData/Trackers/WinTracker.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeatSaviorData.Trackers
namespace BeatSaviorData.Trackers
{
class WinTracker : ITracker
{
Expand Down
7 changes: 7 additions & 0 deletions BeatSaviorData/UI/Views/SettingsView.bsml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<settings-container>
<horizontal pad="2" preferred-height="8">
<text text="Disabling passes upload will prevent you from participating in events." font-size="3.5"/>
</horizontal>
<checkbox text="Disable Pass Upload" value="DisablePass" />
<checkbox text="Disable Fail Upload" value="DisableFail" />
</settings-container>
18 changes: 11 additions & 7 deletions BeatSaviorData/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeatSaviorData
namespace BeatSaviorData
{
class Utils
{
Expand All @@ -19,5 +13,15 @@ public static float SafeDivide(float a, float b)
return 0;
}
}

public static float SafeAverage(float a, float nbA, float b, float nbB)
{
if (!float.IsNaN(a) && !float.IsNaN(b))
return (a * nbA + b * nbB) / (nbA + nbB);
else if (float.IsNaN(b))
return a;
else
return b;
}
}
}
14 changes: 9 additions & 5 deletions BeatSaviorData/manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"$schema": "https://raw.githubusercontent.com/nike4613/ModSaber-MetadataFileSchema/master/Schema.json",
"id": null,
"id": "BeatSaviorData",
"name": "BeatSaviorData",
"author": "Mystogan",
"version": "0.0.1",
"description": "Streams data such as map completion to Beat Savior",
"version": "1.0.0",
"description": "Uploads data on map completion, such as per saber accuracy, to Beat Savior",
"gameVersion": "1.7.0",
"dependsOn": {
"BS Utils": "^1.3.5",
"BeatSaberMarkupLanguage": "^1.1.5"
},
"loadAfter": [ "BS Utils" ],
"loadAfter": [ "BS Utils", "BeatSaberMarkupLanguage" ],
"features": [],
"misc": {
"plugin-hint": "BeatSaviorData.Plugin"
}
},
"links": {
"project-home": "https://github.com/Mystogan98/BeatSaviorData"
}
}

0 comments on commit 2549b84

Please sign in to comment.