├── .gitignore
├── LICENSE
├── README.md
├── Screenshot.png
├── SongPlayHistory.UnitTest
├── SPHModelTest.cs
├── SongPlayHistory.UnitTest.csproj
└── TestLogger.cs
├── SongPlayHistory.sln
└── SongPlayHistory
├── .gitignore
├── Assets
├── ThumbsDown.png
└── ThumbsUp.png
├── BeatSaberUI.cs
├── CreateJunctions.bat
├── HarmonyPatches.cs
├── Plugin.cs
├── PluginConfig.cs
├── SPHController.cs
├── SPHModel.cs
├── SPHUI.cs
├── Settings.bsml
├── SettingsController.cs
├── SongPlayHistory.csproj
└── manifest.json
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Swift Kim
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SongPlayHistory
2 |
3 | [](https://github.com/swift-kim/SongPlayHistory/releases)
4 |
5 | Track all your scores.
6 |
7 | ## Screenshot
8 |
9 | 
10 |
11 | ## Features
12 |
13 | - Keep detailed track of your plays
14 | - Show how many times you've played a single beatmap
15 | - Visualize your song preferences (👍/👎)
16 |
17 | ## Installation
18 |
19 | - Copy [SongPlayHistory.dll](https://github.com/swift-kim/SongPlayHistory/releases) to Beat Saber's _Plugins_ directory (Requires _BS Utils_, _BeatSaberMarkupLanguage_)
20 | - Also available on [BeatMods](https://beatmods.com/#/mods) (Use [ModAssistant](https://github.com/Assistant/ModAssistant))
21 |
22 | ## Notes
23 |
24 | - Recording play data begins when you first install this plugin. (This doesn't apply to play counts.)
25 | - The data file (_SongPlayData.json_) is created in Beat Saber's _UserData_ directory. You can delete individual records from there if you want.
26 | - The data are not uploaded anywhere so you have to **backup** the file when re-installing the game.
27 | - If you run into any problem, please contact me either via Discord _(peperoro#1013)_ or by filing an issue.
28 |
--------------------------------------------------------------------------------
/Screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/swift-kim/SongPlayHistory/e19bf7a3d2e8bcf8e940ac59e3db3fe0c8084391/Screenshot.png
--------------------------------------------------------------------------------
/SongPlayHistory.UnitTest/SPHModelTest.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using Xunit;
6 | using Xunit.Abstractions;
7 |
8 | namespace SongPlayHistory.UnitTest
9 | {
10 | ///
11 | /// Unit tests for static file I/O methods in .
12 | /// Only general non-Unity-related methods can be tested.
13 | /// It is not allowed to access any Unity class from a standalone test runner.
14 | ///
15 | public class SPHModelTest
16 | {
17 | public SPHModelTest(ITestOutputHelper output)
18 | {
19 | Plugin.Log = new TestLogger() { Output = output };
20 |
21 | var userDataDir = Path.Combine(Environment.CurrentDirectory, "UserData");
22 | if (Directory.Exists(userDataDir))
23 | {
24 | Directory.Delete(userDataDir, true);
25 | }
26 | Directory.CreateDirectory(userDataDir);
27 |
28 | SPHModel.Records.Clear();
29 | SPHModel.Votes.Clear();
30 | }
31 |
32 | [Fact]
33 | public void InitializeRecords_DataFileNotExist()
34 | {
35 | SPHModel.InitializeRecords();
36 |
37 | Assert.False(File.Exists(SPHModel.DataFile));
38 | Assert.True(SPHModel.Records.Count == 0);
39 | }
40 |
41 | [Fact]
42 | public void InitializeRecords_ReadData()
43 | {
44 | var records = new Dictionary>();
45 | records.Add("Level1", new List { new Record() });
46 | records.Add("Level2", new List { new Record(), new Record() });
47 |
48 | var serialized = JsonConvert.SerializeObject(records);
49 | File.WriteAllText(SPHModel.DataFile, serialized);
50 |
51 | SPHModel.InitializeRecords();
52 |
53 | Assert.True(File.Exists(SPHModel.DataFile));
54 | Assert.True(SPHModel.Records.Count == 2);
55 | Assert.True(SPHModel.Records["Level1"].Count == 1);
56 | Assert.True(SPHModel.Records["Level2"].Count == 2);
57 | }
58 |
59 | [Fact]
60 | public void InitializeRecords_EmptyDataNoBackup()
61 | {
62 | File.WriteAllText(SPHModel.DataFile, string.Empty);
63 |
64 | SPHModel.InitializeRecords();
65 |
66 | Assert.True(SPHModel.Records.Count == 0);
67 | }
68 |
69 | [Fact]
70 | public void InitializeRecords_InvalidDataNoBackup()
71 | {
72 | File.WriteAllText(SPHModel.DataFile, "NOT_A_VALID_JSON");
73 |
74 | SPHModel.InitializeRecords();
75 |
76 | Assert.True(SPHModel.Records.Count == 0);
77 | }
78 |
79 | [Fact]
80 | public void InitializeRecords_RestoreFromBackup()
81 | {
82 | File.WriteAllText(SPHModel.DataFile, "NOT_A_VALID_JSON");
83 |
84 | var records = new Dictionary>();
85 | records.Add("Level1", new List { new Record() });
86 | records.Add("Level2", new List { new Record(), new Record() });
87 |
88 | var serialized = JsonConvert.SerializeObject(records);
89 | var backupFile = Path.ChangeExtension(SPHModel.DataFile, ".bak");
90 | File.WriteAllText(backupFile, serialized);
91 |
92 | SPHModel.InitializeRecords();
93 |
94 | Assert.True(File.Exists(backupFile));
95 | Assert.True(SPHModel.Records.Count == 2);
96 | }
97 |
98 | [Fact]
99 | public void InitializeRecords_FailToRestoreFromBackup()
100 | {
101 | File.WriteAllText(SPHModel.DataFile, string.Empty);
102 |
103 | var backupFile = Path.ChangeExtension(SPHModel.DataFile, ".bak");
104 | File.WriteAllText(backupFile, string.Empty);
105 |
106 | SPHModel.InitializeRecords();
107 |
108 | Assert.True(SPHModel.Records.Count == 0);
109 | }
110 |
111 | [Fact]
112 | public void SaveRecordsToFile_WriteData()
113 | {
114 | var records = SPHModel.Records = new Dictionary>();
115 |
116 | SPHModel.SaveRecordsToFile();
117 |
118 | Assert.False(File.Exists(SPHModel.DataFile));
119 |
120 | records.Add("Level1", new List { new Record() });
121 | records.Add("Level2", new List { new Record(), new Record() });
122 |
123 | SPHModel.SaveRecordsToFile();
124 |
125 | Assert.True(File.Exists(SPHModel.DataFile));
126 |
127 | var text = File.ReadAllText(SPHModel.DataFile);
128 | Assert.Contains("Level1", text);
129 | Assert.Contains("Level2", text);
130 | }
131 |
132 | [Fact]
133 | public void BackupRecords_OverwriteBackup()
134 | {
135 | var backupFile = Path.ChangeExtension(SPHModel.DataFile, ".bak");
136 | File.WriteAllText(backupFile, string.Empty);
137 |
138 | var records = new Dictionary>();
139 | records.Add("Level1", new List { new Record() });
140 |
141 | var serialized = JsonConvert.SerializeObject(records);
142 | File.WriteAllText(SPHModel.DataFile, serialized);
143 |
144 | Assert.True(new FileInfo(SPHModel.DataFile).Length > new FileInfo(backupFile).Length);
145 |
146 | SPHModel.BackupRecords();
147 |
148 | Assert.True(new FileInfo(SPHModel.DataFile).Length == new FileInfo(backupFile).Length);
149 | }
150 |
151 | [Fact]
152 | public void BackupRecords_DoNotOverwriteBackup()
153 | {
154 | File.WriteAllText(SPHModel.DataFile, string.Empty);
155 |
156 | var records = new Dictionary>();
157 | records.Add("Level1", new List { new Record() });
158 |
159 | var serialized = JsonConvert.SerializeObject(records);
160 | var backupFile = Path.ChangeExtension(SPHModel.DataFile, ".bak");
161 | File.WriteAllText(backupFile, serialized);
162 |
163 | SPHModel.BackupRecords();
164 |
165 | Assert.True(new FileInfo(SPHModel.DataFile).Length < new FileInfo(backupFile).Length);
166 | }
167 |
168 | [Fact]
169 | public void ScanVoteData_FileNotExist()
170 | {
171 | Assert.False(SPHModel.ScanVoteData());
172 | Assert.True(SPHModel.Votes.Count == 0);
173 | }
174 |
175 | [Fact]
176 | public void ScanVoteData_EmptyData()
177 | {
178 | File.WriteAllText(SPHModel.VoteFile, string.Empty);
179 |
180 | Assert.True(SPHModel.ScanVoteData());
181 | Assert.True(SPHModel.Votes.Count == 0);
182 | }
183 |
184 | [Fact]
185 | public void ScanVoteData_InvalidData()
186 | {
187 | File.WriteAllText(SPHModel.VoteFile, "NOT_A_VALID_JSON");
188 |
189 | Assert.False(SPHModel.ScanVoteData());
190 | Assert.True(SPHModel.Votes.Count == 0);
191 | }
192 |
193 | [Fact]
194 | public void ScanVoteData_FileUpdated()
195 | {
196 | var votes = new Dictionary();
197 | votes.Add("Level1", new UserVote() { key = "1111", voteType = "Upvote" });
198 | votes.Add("Level2", new UserVote() { key = "2222", voteType = "Downvote" });
199 |
200 | var serialized = JsonConvert.SerializeObject(votes);
201 | File.WriteAllText(SPHModel.VoteFile, serialized);
202 |
203 | Assert.True(SPHModel.ScanVoteData());
204 | Assert.True(SPHModel.Votes.Count == 2);
205 |
206 | votes.Add("Level3", new UserVote() { key = "3333", voteType = "Upvote" });
207 |
208 | serialized = JsonConvert.SerializeObject(votes);
209 | File.WriteAllText(SPHModel.VoteFile, serialized);
210 |
211 | Assert.True(SPHModel.ScanVoteData());
212 | Assert.True(SPHModel.Votes.Count == 3);
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/SongPlayHistory.UnitTest/SongPlayHistory.UnitTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 | false
6 | $(ProjectDir)..\SongPlayHistory\References
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | $(BeatSaberDir)\IPA\Data\Managed\IPA.Loader.dll
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SongPlayHistory.UnitTest/TestLogger.cs:
--------------------------------------------------------------------------------
1 | using IPA.Logging;
2 | using Xunit.Abstractions;
3 |
4 | namespace SongPlayHistory.UnitTest
5 | {
6 | internal class TestLogger : Logger
7 | {
8 | public ITestOutputHelper Output { get; set; }
9 |
10 | public override void Log(Level level, string message)
11 | {
12 | Output?.WriteLine(message);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/SongPlayHistory.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29613.14
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SongPlayHistory", "SongPlayHistory\SongPlayHistory.csproj", "{A27CE832-9835-494F-BCD9-1D8A4A0F90ED}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SongPlayHistory.UnitTest", "SongPlayHistory.UnitTest\SongPlayHistory.UnitTest.csproj", "{9C2AE911-BA20-49F2-B61C-9581DEAD962A}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {A27CE832-9835-494F-BCD9-1D8A4A0F90ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {A27CE832-9835-494F-BCD9-1D8A4A0F90ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {A27CE832-9835-494F-BCD9-1D8A4A0F90ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {A27CE832-9835-494F-BCD9-1D8A4A0F90ED}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {9C2AE911-BA20-49F2-B61C-9581DEAD962A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {9C2AE911-BA20-49F2-B61C-9581DEAD962A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {9C2AE911-BA20-49F2-B61C-9581DEAD962A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {9C2AE911-BA20-49F2-B61C-9581DEAD962A}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {08B43F33-0381-4223-B7F6-A22F3B8CD226}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/SongPlayHistory/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore References folder
2 | References/
3 |
--------------------------------------------------------------------------------
/SongPlayHistory/Assets/ThumbsDown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/swift-kim/SongPlayHistory/e19bf7a3d2e8bcf8e940ac59e3db3fe0c8084391/SongPlayHistory/Assets/ThumbsDown.png
--------------------------------------------------------------------------------
/SongPlayHistory/Assets/ThumbsUp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/swift-kim/SongPlayHistory/e19bf7a3d2e8bcf8e940ac59e3db3fe0c8084391/SongPlayHistory/Assets/ThumbsUp.png
--------------------------------------------------------------------------------
/SongPlayHistory/BeatSaberUI.cs:
--------------------------------------------------------------------------------
1 | using BS_Utils.Utilities;
2 | using HMUI;
3 | using System.Linq;
4 | using UnityEngine;
5 |
6 | namespace SongPlayHistory
7 | {
8 | internal static class BeatSaberUI
9 | {
10 | public static ResultsViewController ResultsViewController { get; private set; }
11 |
12 | public static LevelStatsView LeaderboardLevelStatsView { get; private set; }
13 |
14 | public static StandardLevelDetailViewController LevelDetailViewController { get; private set; }
15 |
16 | public static LevelParamsPanel LevelParamsPanel { get; private set; }
17 |
18 | public static LevelCollectionTableView LevelCollectionTableView { get; private set; }
19 |
20 | private static LevelSelectionFlowCoordinator _flowCoordinator;
21 |
22 | public static bool IsValid => _flowCoordinator != null;
23 |
24 | public static bool IsSolo
25 | {
26 | get
27 | {
28 | return _flowCoordinator == null || _flowCoordinator is SoloFreePlayFlowCoordinator;
29 | }
30 | set
31 | {
32 | if (value)
33 | {
34 | _flowCoordinator = Resources.FindObjectsOfTypeAll().LastOrDefault();
35 |
36 | ResultsViewController = _flowCoordinator?.GetPrivateField("_resultsViewController");
37 | var leaderboardViewController = _flowCoordinator?.GetPrivateField("_platformLeaderboardViewController");
38 | LeaderboardLevelStatsView = leaderboardViewController?.GetPrivateField("_levelStatsView");
39 | }
40 | else
41 | {
42 | var parent = Resources.FindObjectsOfTypeAll().LastOrDefault();
43 | _flowCoordinator = parent?.GetPrivateField("multiplayerLevelSelectionFlowCoordinator");
44 | }
45 |
46 | var levelSelectionNavController = _flowCoordinator?.GetPrivateField("levelSelectionNavigationController");
47 | var levelCollectionNavController = levelSelectionNavController?.GetPrivateField("_levelCollectionNavigationController");
48 | LevelDetailViewController = levelCollectionNavController?.GetPrivateField("_levelDetailViewController");
49 | var levelDetailView = LevelDetailViewController?.GetPrivateField("_standardLevelDetailView");
50 | LevelParamsPanel = levelDetailView?.GetPrivateField("_levelParamsPanel");
51 | var levelCollectionViewController = levelCollectionNavController?.GetPrivateField("_levelCollectionViewController");
52 | LevelCollectionTableView = levelCollectionViewController?.GetPrivateField("_levelCollectionTableView");
53 | }
54 | }
55 |
56 | public static void ReloadSongList()
57 | {
58 | if (IsValid)
59 | {
60 | LevelCollectionTableView?.GetPrivateField("_tableView")?.RefreshCellsContent();
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/SongPlayHistory/CreateJunctions.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | set SourcePath=%~1
3 | set DestPath=%~dp0
4 |
5 | if "%SourcePath%" == "" (
6 | echo Enter the full path (without quotes^) to your Beat Saber game folder. Alternatively, you can drag and drop your Beat Saber folder onto this batch file to automatically make the junctions.
7 | set /p SourcePath="Path:"
8 | )
9 |
10 | echo Source target: %SourcePath%
11 | echo Link target: %DestPath%
12 | set PluginPath=%SourcePath%\Plugins
13 | set ManagedPath=%SourcePath%\Beat Saber_Data\Managed
14 | set LibsPath=%SourcePath%\Libs
15 | set IPAPath=%SourcePath%\IPA
16 |
17 | if exist "%PluginPath%" (
18 | echo Plugin folder exists, creating link
19 | if not exist "%DestPath%References" mkdir "%DestPath%References"
20 | mklink /J "%DestPath%References\Plugins" "%PluginPath%"
21 | ) else (
22 | echo Plugin folder missing
23 | )
24 | if exist "%ManagedPath%" (
25 | echo Managed folder exists, creating link
26 | if not exist "%DestPath%References" mkdir "%DestPath%References"
27 | if not exist "%DestPath%References\Beat Saber_Data" mkdir "%DestPath%References\Beat Saber_Data"
28 | mklink /J "%DestPath%References\Beat Saber_Data\Managed" "%ManagedPath%"
29 | ) else (
30 | echo Managed folder missing
31 | )
32 | if exist "%LibsPath%" (
33 | echo Libs folder exists, creating link
34 | if not exist "%DestPath%References" mkdir "%DestPath%References"
35 | mklink /J "%DestPath%References\Libs" "%LibsPath%"
36 | ) else (
37 | echo Libs folder missing
38 | )
39 | if exist "%IPAPath%" (
40 | echo Libs folder exists, creating link
41 | if not exist "%DestPath%References" mkdir "%DestPath%References"
42 | mklink /J "%DestPath%References\IPA" "%IPAPath%"
43 | ) else (
44 | echo Libs folder missing
45 | )
46 | :End
47 | pause
--------------------------------------------------------------------------------
/SongPlayHistory/HarmonyPatches.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using HarmonyLib;
4 | using TMPro;
5 | using UnityEngine;
6 | using UnityEngine.UI;
7 | using static UnityEngine.Object;
8 |
9 | namespace SongPlayHistory
10 | {
11 | [HarmonyPatch(typeof(LevelListTableCell))]
12 | [HarmonyPatch("SetDataFromLevelAsync", new Type[] { typeof(IPreviewBeatmapLevel), typeof(bool) })]
13 | internal class SetDataFromLevelAsync
14 | {
15 | private static Sprite _thumbsUp;
16 | private static Sprite _thumbsDown;
17 |
18 | public static bool Prepare()
19 | {
20 | _thumbsUp ??= LoadSpriteFromResource($"SongPlayHistory.Assets.ThumbsUp.png");
21 | _thumbsDown ??= LoadSpriteFromResource($"SongPlayHistory.Assets.ThumbsDown.png");
22 |
23 | return SPHModel.ScanVoteData();
24 | }
25 |
26 | [HarmonyAfter(new string[] { "com.kyle1413.BeatSaber.SongCore" })]
27 | public static void Postfix(LevelListTableCell __instance, IPreviewBeatmapLevel level, bool isFavorite,
28 | Image ____favoritesBadgeImage,
29 | TextMeshProUGUI ____songBpmText)
30 | {
31 | if (float.TryParse(____songBpmText?.text, out float bpm))
32 | {
33 | ____songBpmText.text = bpm.ToString("0");
34 | }
35 |
36 | Image voteIcon = null;
37 | foreach (var image in __instance.GetComponentsInChildren())
38 | {
39 | // For performance reason, avoid using Linq.
40 | if (image.name == "Vote")
41 | {
42 | voteIcon = image;
43 | break;
44 | }
45 | }
46 | if (voteIcon == null)
47 | {
48 | voteIcon = Instantiate(____favoritesBadgeImage, __instance.transform);
49 | voteIcon.name = "Vote";
50 | voteIcon.rectTransform.sizeDelta = new Vector2(2.5f, 2.5f);
51 | voteIcon.color = new Color(1f, 1f, 1f, 0.3f);
52 | }
53 | voteIcon.enabled = false;
54 |
55 | if (!isFavorite && SPHModel.Votes.TryGetValue(level.levelID.Replace("custom_level_", "").ToLower(), out var vote))
56 | {
57 | voteIcon.sprite = vote.voteType == "Upvote" ? _thumbsUp : _thumbsDown;
58 | voteIcon.enabled = true;
59 | }
60 | }
61 |
62 | public static void OnUnpatch()
63 | {
64 | foreach (var image in Resources.FindObjectsOfTypeAll())
65 | {
66 | if (image.name == "Vote")
67 | {
68 | Destroy(image.gameObject);
69 | }
70 | }
71 | }
72 |
73 | private static Sprite LoadSpriteFromResource(string resourcePath)
74 | {
75 | try
76 | {
77 | using var stream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourcePath);
78 | var resource = new byte[stream.Length];
79 | stream.Read(resource, 0, (int)stream.Length);
80 |
81 | var texture = new Texture2D(2, 2);
82 | texture.LoadImage(resource);
83 |
84 | var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
85 | return sprite;
86 | }
87 | catch (Exception ex)
88 | {
89 | Plugin.Log?.Error("Error while loading a resource.\n" + ex.ToString());
90 | return null;
91 | }
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/SongPlayHistory/Plugin.cs:
--------------------------------------------------------------------------------
1 | using BeatSaberMarkupLanguage.Settings;
2 | using BS_Utils.Gameplay;
3 | using HarmonyLib;
4 | using IPA;
5 | using IPA.Config;
6 | using IPA.Config.Stores;
7 | using IPA.Logging;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Reflection;
11 |
12 | namespace SongPlayHistory
13 | {
14 | [Plugin(RuntimeOptions.SingleStartInit)]
15 | public class Plugin
16 | {
17 | public const string HarmonyId = "com.github.swift-kim.SongPlayHistory";
18 |
19 | public static Plugin Instance { get; private set; }
20 | public static Logger Log { get; internal set; }
21 |
22 | private readonly Harmony _harmony;
23 | private bool _isPractice;
24 |
25 | [Init]
26 | public Plugin(Logger logger, Config config)
27 | {
28 | Instance = this;
29 | Log = logger;
30 | _harmony = new Harmony(HarmonyId);
31 |
32 | PluginConfig.Instance = config.Generated();
33 | BSMLSettings.instance.AddSettingsMenu("Song Play History", $"SongPlayHistory.Settings.bsml", SettingsController.instance);
34 |
35 | SPHModel.InitializeRecords();
36 | }
37 |
38 | [OnStart]
39 | public void OnStart()
40 | {
41 | BS_Utils.Utilities.BSEvents.gameSceneLoaded += OnGameSceneLoaded;
42 | BS_Utils.Plugin.LevelDidFinishEvent += OnLevelFinished;
43 | BS_Utils.Plugin.MultiLevelDidFinishEvent += OnMultilevelFinished;
44 |
45 | // Init after the menu scene is loaded.
46 | BS_Utils.Utilities.BSEvents.lateMenuSceneLoadedFresh += (o) =>
47 | {
48 | Log.Info("The menu scene was loaded.");
49 | _ = new UnityEngine.GameObject(nameof(SPHController)).AddComponent();
50 | };
51 |
52 | ApplyHarmonyPatches(PluginConfig.Instance.ShowVotes);
53 | }
54 |
55 | [OnExit]
56 | public void OnExit()
57 | {
58 | BS_Utils.Utilities.BSEvents.gameSceneLoaded -= OnGameSceneLoaded;
59 | BS_Utils.Plugin.LevelDidFinishEvent -= OnLevelFinished;
60 | BS_Utils.Plugin.MultiLevelDidFinishEvent -= OnMultilevelFinished;
61 |
62 | SPHModel.BackupRecords();
63 | }
64 |
65 | private void OnGameSceneLoaded()
66 | {
67 | var practiceSettings = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData?.practiceSettings;
68 | _isPractice = practiceSettings != null;
69 | }
70 |
71 | private void OnLevelFinished(StandardLevelScenesTransitionSetupDataSO scene, LevelCompletionResults result)
72 | {
73 | if (_isPractice || Gamemode.IsPartyActive)
74 | {
75 | return;
76 | }
77 | SaveRecord(scene?.difficultyBeatmap, result, false);
78 | }
79 |
80 | private void OnMultilevelFinished(MultiplayerLevelScenesTransitionSetupDataSO scene, LevelCompletionResults result, IReadOnlyList _)
81 | {
82 | SaveRecord(scene?.difficultyBeatmap, result, true);
83 | }
84 |
85 | private void SaveRecord(IDifficultyBeatmap beatmap, LevelCompletionResults result, bool isMultiplayer)
86 | {
87 | if (result?.rawScore > 0)
88 | {
89 | // Actually there's no way to know if any custom modifier was applied if the user failed a map.
90 | var submissionDisabled = ScoreSubmission.WasDisabled || ScoreSubmission.Disabled || ScoreSubmission.ProlongedDisabled;
91 | SPHModel.SaveRecord(beatmap, result, submissionDisabled, isMultiplayer);
92 | }
93 | }
94 |
95 | public void ApplyHarmonyPatches(bool enabled)
96 | {
97 | try
98 | {
99 | if (enabled && !Harmony.HasAnyPatches(HarmonyId))
100 | {
101 | Log.Info("Applying Harmony patches...");
102 | _harmony.PatchAll(Assembly.GetExecutingAssembly());
103 | }
104 | else if (!enabled && Harmony.HasAnyPatches(HarmonyId))
105 | {
106 | Log.Info("Removing Harmony patches...");
107 | _harmony.UnpatchAll(HarmonyId);
108 |
109 | SetDataFromLevelAsync.OnUnpatch();
110 | }
111 | }
112 | catch (Exception ex)
113 | {
114 | Log.Error("Error while applying Harmony patches.\n" + ex.ToString());
115 | }
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/SongPlayHistory/PluginConfig.cs:
--------------------------------------------------------------------------------
1 | namespace SongPlayHistory
2 | {
3 | public class PluginConfig
4 | {
5 | public static PluginConfig Instance { get; set; }
6 |
7 | public bool ShowFailed { get; set; } = true;
8 | public bool AverageAccuracy { get; set; } = true;
9 | public bool SortByDate { get; set; } = false;
10 | public bool ShowVotes { get; set; } = true;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/SongPlayHistory/SPHController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using UnityEngine;
4 | using UnityEngine.UI;
5 |
6 | namespace SongPlayHistory
7 | {
8 | internal class SPHController : MonoBehaviour
9 | {
10 | public static SPHController Instance { get; set; }
11 |
12 | private readonly SPHUI _pluginUI = new SPHUI();
13 |
14 | #region MonoBehaviour Messages
15 | ///
16 | /// Only ever called once, mainly used to initialize variables.
17 | ///
18 | private void Awake()
19 | {
20 | if (Instance != null)
21 | {
22 | Destroy(Instance.gameObject);
23 | }
24 | DontDestroyOnLoad(this);
25 | Instance = this;
26 | }
27 |
28 | ///
29 | /// Only ever called once on the first frame the script is Enabled. Start is called after any other script's Awake() and before Update().
30 | ///
31 | private void Start()
32 | {
33 | var soloButton = Resources.FindObjectsOfTypeAll