-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6f23b26
Showing
14 changed files
with
2,594 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Build | ||
BeatSaberHTTPStatus/head | ||
|
||
# Libs | ||
libs/beatsaber/* | ||
|
||
# C# | ||
bin | ||
obj | ||
|
||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "libs/websocket-sharp"] | ||
path = libs/websocket-sharp | ||
url = https://github.com/sta/websocket-sharp.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1C0571AC-F8D6-4F9E-93b2-2F23892AE61E}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>BeatSaberHTTPStatus</RootNamespace> | ||
<AssemblyName>BeatSaberHTTPStatus</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<Version>$(Version)-dev</Version> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\Assembly-CSharp.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\IllusionPlugin.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\UnityEngine.CoreModule.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.AudioModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\UnityEngine.AudioModule.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.ImageConversionModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\libs\beatsaber\UnityEngine.ImageConversionModule.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<ProjectReference Include="..\libs\websocket-sharp\websocket-sharp\websocket-sharp.csproj"> | ||
<Project>{B357BAC7-529E-4D81-A0D2-71041B19C8DE}</Project> | ||
<Name>websocket-sharp</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="**\*.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<ItemGroup> | ||
<ZipFiles Include="$(OutDir)\BeatSaberHTTPStatus.dll" /> | ||
<ZipFiles Include="$(OutDir)\websocket-sharp.dll" /> | ||
</ItemGroup> | ||
<Exec Command="git rev-parse HEAD > head" /> | ||
<ReadLinesFromFile File="head"> | ||
<Output TaskParameter="Lines" PropertyName="FullCommitHash" /> | ||
</ReadLinesFromFile> | ||
<Delete Files="head" /> | ||
<PropertyGroup> | ||
<CommitHash>$(FullCommitHash.Substring(0, 8))</CommitHash> | ||
</PropertyGroup> | ||
<Copy SourceFiles="@(ZipFiles)" DestinationFolder="$(OutDir)\zip\Plugins" /> | ||
<ZipDir ZipFileName="$(OutDir)\BeatSaberHTTPStatus-$(Version)-$(CommitHash).zip" DirectoryName="$(OutDir)\zip" /> | ||
</Target> | ||
<!-- Source: https://stackoverflow.com/a/38127938 --> | ||
<UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> | ||
<ParameterGroup> | ||
<ZipFileName ParameterType="System.String" Required="true" /> | ||
<DirectoryName ParameterType="System.String" Required="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Reference Include="System.IO.Compression.FileSystem" /> | ||
<Using Namespace="System.IO.Compression" /> | ||
<Code Type="Fragment" Language="cs"><![CDATA[ | ||
try | ||
{ | ||
Log.LogMessage(string.Format("Zipping Directory {0} to {1}", DirectoryName, ZipFileName)); | ||
ZipFile.CreateFromDirectory( DirectoryName, ZipFileName ); | ||
return true; | ||
} | ||
catch(Exception ex) | ||
{ | ||
Log.LogErrorFromException(ex); | ||
return false; | ||
} | ||
]]></Code> | ||
</Task> | ||
</UsingTask> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
|
||
namespace BeatSaberHTTPStatus { | ||
[Serializable] | ||
public class GameStatus { | ||
public string updateCause; | ||
|
||
public string scene = null; | ||
public string mode = null; | ||
|
||
// Beatmap | ||
public string songName = null; | ||
public string songSubName = null; | ||
public string songAuthorName = null; | ||
public string songCover = null; | ||
public float songBPM; | ||
public long songTimeOffset = 0; | ||
public long length = 0; | ||
public long start = 0; | ||
public long paused = 0; | ||
public string difficulty = null; | ||
public int notesCount = 0; | ||
public int obstaclesCount = 0; | ||
public int maxScore = 0; | ||
|
||
// Performance | ||
public int score = 0; | ||
public int currentMaxScore = 0; | ||
public string rank = "E"; | ||
public int passedNotes = 0; | ||
public int hitNotes = 0; | ||
public int missedNotes = 0; | ||
public int lastNoteScore = 0; | ||
public int passedBombs = 0; | ||
public int hitBombs = 0; | ||
public int combo = 0; | ||
public int maxCombo = 0; | ||
public int multiplier = 0; | ||
public float multiplierProgress = 0; | ||
|
||
// Note cut | ||
public int noteID = -1; | ||
public string noteType = null; | ||
public string noteCutDirection = null; | ||
public bool speedOK = false; | ||
public bool directionOK = false; | ||
public bool saberTypeOK = false; | ||
public bool wasCutTooSoon = false; | ||
public int initialScore = -1; | ||
public int finalScore = -1; | ||
public int cutMultiplier = 0; | ||
public float saberSpeed = 0; | ||
public float saberDirX = 0; | ||
public float saberDirY = 0; | ||
public float saberDirZ = 0; | ||
public string saberType = null; | ||
public float swingRating = 0; | ||
public float timeDeviation = 0; | ||
public float cutDirectionDeviation = 0; | ||
public float cutPointX = 0; | ||
public float cutPointY = 0; | ||
public float cutPointZ = 0; | ||
public float cutNormalX = 0; | ||
public float cutNormalY = 0; | ||
public float cutNormalZ = 0; | ||
public float cutDistanceToCenter = 0; | ||
|
||
// Mods | ||
public string modObstacles = "None"; | ||
public bool modNoEnergy = false; | ||
public bool modMirror = false; | ||
|
||
public void ResetMapInfo() { | ||
this.songName = null; | ||
this.songSubName = null; | ||
this.songAuthorName = null; | ||
this.songCover = null; | ||
this.songBPM = 0f; | ||
this.songTimeOffset = 0; | ||
this.length = 0; | ||
this.start = 0; | ||
this.paused = 0; | ||
this.difficulty = null; | ||
this.notesCount = 0; | ||
this.obstaclesCount = 0; | ||
this.maxScore = 0; | ||
} | ||
|
||
public void ResetPerformance() { | ||
this.score = 0; | ||
this.currentMaxScore = 0; | ||
this.rank = "E"; | ||
this.passedNotes = 0; | ||
this.hitNotes = 0; | ||
this.missedNotes = 0; | ||
this.lastNoteScore = 0; | ||
this.passedBombs = 0; | ||
this.hitBombs = 0; | ||
this.combo = 0; | ||
this.maxCombo = 0; | ||
this.multiplier = 0; | ||
this.multiplierProgress = 0; | ||
} | ||
|
||
public void ResetNoteCut() { | ||
this.noteID = -1; | ||
this.noteType = null; | ||
this.noteCutDirection = null; | ||
this.speedOK = false; | ||
this.directionOK = false; | ||
this.saberTypeOK = false; | ||
this.wasCutTooSoon = false; | ||
this.initialScore = -1; | ||
this.finalScore = -1; | ||
this.cutMultiplier = 0; | ||
this.saberSpeed = 0; | ||
this.saberDirX = 0; | ||
this.saberDirY = 0; | ||
this.saberDirZ = 0; | ||
this.saberType = null; | ||
this.swingRating = 0; | ||
this.timeDeviation = 0; | ||
this.cutDirectionDeviation = 0; | ||
this.cutPointX = 0; | ||
this.cutPointY = 0; | ||
this.cutPointZ = 0; | ||
this.cutNormalX = 0; | ||
this.cutNormalY = 0; | ||
this.cutNormalZ = 0; | ||
this.cutDistanceToCenter = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
using System.Text; | ||
using SimpleJSON; | ||
using WebSocketSharp; | ||
using WebSocketSharp.Net; | ||
using WebSocketSharp.Server; | ||
|
||
namespace BeatSaberHTTPStatus { | ||
public class HTTPServer { | ||
private int ServerPort = 6557; | ||
|
||
private HttpServer server; | ||
|
||
private StatusManager statusManager; | ||
|
||
public HTTPServer(StatusManager statusManager) { | ||
this.statusManager = statusManager; | ||
} | ||
|
||
public void InitServer() { | ||
server = new HttpServer(ServerPort); | ||
|
||
server.OnGet += (sender, e) => { | ||
OnHTTPGet(e); | ||
}; | ||
|
||
server.AddWebSocketService<StatusBroadcastBehavior>("/socket", behavior => behavior.SetStatusManager(statusManager)); | ||
|
||
Console.WriteLine("[HTTP Status] Starting HTTP server on port " + ServerPort); | ||
server.Start(); | ||
} | ||
|
||
public void StopServer() { | ||
Console.WriteLine("[HTTP Status] Stopping HTTP server"); | ||
server.Stop(); | ||
} | ||
|
||
public void OnHTTPGet(HttpRequestEventArgs e) { | ||
var req = e.Request; | ||
var res = e.Response; | ||
|
||
if (req.RawUrl == "/status.json") { | ||
res.StatusCode = 200; | ||
res.ContentType = "application/json"; | ||
res.ContentEncoding = Encoding.UTF8; | ||
|
||
res.WriteContent(Encoding.UTF8.GetBytes(statusManager.statusJSON.ToString())); | ||
|
||
return; | ||
} | ||
|
||
res.StatusCode = 404; | ||
res.WriteContent(new byte[] {}); | ||
} | ||
} | ||
|
||
public class StatusBroadcastBehavior : WebSocketBehavior { | ||
private StatusManager statusManager; | ||
|
||
public void SetStatusManager(StatusManager statusManager) { | ||
this.statusManager = statusManager; | ||
|
||
statusManager.statusChange += OnStatusChange; | ||
} | ||
|
||
protected override void OnOpen() { | ||
JSONObject eventJSON = new JSONObject(); | ||
|
||
eventJSON["event"] = "hello"; | ||
eventJSON["time"] = new JSONNumber(Plugin.GetCurrentTime()); | ||
eventJSON["status"] = statusManager.statusJSON; | ||
|
||
Send(eventJSON.ToString()); | ||
} | ||
|
||
protected override void OnClose(CloseEventArgs e) { | ||
statusManager.statusChange -= OnStatusChange; | ||
} | ||
|
||
public void OnStatusChange(StatusManager statusManager, ChangedProperties changedProps, string cause) { | ||
JSONObject eventJSON = new JSONObject(); | ||
eventJSON["event"] = cause; | ||
eventJSON["time"] = new JSONNumber(Plugin.GetCurrentTime()); | ||
|
||
if (changedProps.game && changedProps.beatmap && changedProps.performance && changedProps.mod) { | ||
eventJSON["status"] = statusManager.statusJSON; | ||
} else { | ||
JSONObject status = new JSONObject(); | ||
eventJSON["status"] = status; | ||
|
||
if (changedProps.game) status["game"] = statusManager.statusJSON["game"]; | ||
if (changedProps.beatmap) status["beatmap"] = statusManager.statusJSON["beatmap"]; | ||
if (changedProps.performance) status["performance"] = statusManager.statusJSON["performance"]; | ||
if (changedProps.mod) status["mod"] = statusManager.statusJSON["mod"]; | ||
} | ||
|
||
if (changedProps.noteCut) { | ||
eventJSON["noteCut"] = statusManager.noteCutJSON; | ||
} | ||
|
||
Send(eventJSON.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.