-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 1.3. I messed up the 1.2 update. I iz not smrt.
- Loading branch information
1 parent
ca85697
commit 14925dd
Showing
22 changed files
with
743 additions
and
1,443 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
"ExpandedNodes": [ | ||
"" | ||
], | ||
"SelectedNode": "\\MonoBehaviors.cs", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
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,10 @@ | ||
{ | ||
"version": "0.2.1", | ||
"tasks": [ | ||
{ | ||
"taskLabel": "task-BeatSaberAutoCamera", | ||
"appliesTo": "BeatSaberAutoCamera.cs", | ||
"type": "launch" | ||
} | ||
] | ||
} |
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,169 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEngine; | ||
using MorichalionStuff; | ||
using UnityEngine.Assertions.Must; | ||
|
||
public class MoriBeatSaberCameraSettings : IPluginSettings | ||
{ | ||
|
||
} | ||
public partial class MoriBeatSaberCamera : IPluginCameraBehaviour | ||
{ | ||
MoriBeatSaberCameraSettings _settings = new MoriBeatSaberCameraSettings(); | ||
|
||
public string ID => "MoriBeatSaberKam"; | ||
public string name => "Mori's Beat Saber Cam"; | ||
public string author => "Morichalion"; | ||
public string version => "0.1.3"; | ||
|
||
public IPluginSettings settings => _settings; | ||
|
||
public event EventHandler ApplySettings; | ||
private BeatSaberStatus BS; | ||
PluginCameraHelper _helper; | ||
|
||
|
||
//overlay stuff | ||
private bool overlayactive = true; | ||
private GameObject overlay; | ||
public float overlayScale = .5f; | ||
public float overlayOffsetX = -.5f; | ||
public float overlayOffsetY = -.3f; | ||
OverlayController overlayCon; | ||
|
||
public float FOV = 60.0f; | ||
// | ||
RigCam rig; | ||
menuCam men; | ||
|
||
|
||
public void OnActivate(PluginCameraHelper helper) { | ||
_helper = helper;//got my cam stuff. | ||
BS = new BeatSaberStatus(); | ||
|
||
rig = new RigCam(); | ||
|
||
//rig.worlCam = helper.manager.camera.worldCamera.transform; | ||
rig.worlCam = helper.behaviour.manager.camera.transform; | ||
|
||
men = new menuCam(); | ||
|
||
//men.WorldCam = helper.manager.camera.worldCamera.transform; | ||
men.WorldCam = helper.behaviour.manager.camera.transform; | ||
|
||
CheckSettings(); | ||
if (overlayactive==true) | ||
{ | ||
try | ||
{ | ||
//getting my overlay | ||
string assetPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
string dp = System.IO.Path.Combine(assetPath, @"LIV\Plugins\CameraBehaviours\MoriBScam\overlay.yap"); | ||
AssetBundle myasset = AssetBundle.LoadFromFile(dp); | ||
|
||
var prefab = myasset.LoadAsset<GameObject>("Overlay"); | ||
myasset.Unload(false); | ||
//Transform c = _helper.manager.camera.worldCamera.transform; | ||
Transform c = _helper.behaviour.manager.camera.transform; | ||
overlay = UnityEngine.Object.Instantiate(prefab); | ||
overlay.transform.parent = c; | ||
overlay.transform.localPosition = new Vector3((overlayOffsetX+0.0f),(overlayOffsetY +.05f),(1.0f)); | ||
float sc = overlayScale * 0.1f; | ||
overlay.transform.localScale = new Vector3(sc, sc, sc); | ||
overlay.transform.rotation = c.rotation; | ||
overlay.transform.Rotate(-90.0f, 0f, 0f); | ||
overlayCon = overlay.AddComponent<MorichalionStuff.OverlayController>(); | ||
overlayCon._helper = helper; | ||
overlayCon.position = overlay.transform.localPosition; | ||
overlayCon.scale = overlay.transform.localScale; | ||
overlayCon.BS = BS; | ||
//overlay.SetActive(false); | ||
|
||
} | ||
catch | ||
{ | ||
debug("couldn't instantiate overlay"); | ||
overlayactive = false; | ||
} | ||
} | ||
} | ||
|
||
public void OnDeactivate() | ||
{ | ||
if (overlayactive == true) | ||
{ | ||
GameObject.Destroy(overlay); | ||
rig.KillThis(); | ||
BS.shutDown(); | ||
|
||
} | ||
} | ||
|
||
public void OnDestroy() | ||
{ | ||
|
||
} | ||
|
||
public void OnFixedUpdate() | ||
{ | ||
|
||
} | ||
|
||
public void OnLateUpdate() | ||
{ | ||
|
||
} | ||
|
||
public void OnSettingsDeserialized() | ||
{ | ||
|
||
} | ||
|
||
public void OnUpdate() | ||
{ | ||
|
||
//dump the log from the bs socket. | ||
if (BS.debug.Count > 0) | ||
{ | ||
debug(BS.debug[0]); | ||
BS.debug.RemoveAt(0); | ||
} | ||
if(BS.menu == false) | ||
{ | ||
camLook = rig.PositionUpdate(_helper); | ||
//Transform a = rig.UpdateCameraWithThis.transform; | ||
//_helper.UpdateCameraPose(a.position, a.rotation); | ||
//camLook = rig.CameraLook.transform.position; | ||
//camPos = rig.UpdateCameraWithThis.transform.position; | ||
} | ||
if(BS.menu == true) | ||
{ | ||
men.camLookPos = camLook; | ||
camLook = men.menuCamUpdate(_helper); | ||
|
||
} | ||
} | ||
public Vector3 camLook = new Vector3(); | ||
//public Vector3 camPos = new Vector3(0.0f, 0.0f, 0.0f); | ||
//public Vector3 camLook = new Vector3(0.0f, 0.0f, 0.0f); | ||
|
||
|
||
public string debugLogging = "false"; | ||
public void debug(string str) | ||
{ | ||
if (debugLogging == "true") | ||
{ | ||
|
||
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
string settingLoc = System.IO.Path.Combine(docPath, @"LIV\Plugins\CameraBehaviours\MoriBScam\"); | ||
string target = System.IO.Path.Combine(settingLoc, "debug.txt"); | ||
|
||
using (var sw = new System.IO.StreamWriter(target, true)) | ||
{ | ||
sw.WriteLine(str); | ||
} | ||
} | ||
} | ||
} |
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,141 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using WebSocketSharp; | ||
using Newtonsoft.Json.Linq; | ||
using System.Timers; | ||
|
||
public class BeatSaberStatus | ||
{ | ||
public int score = 0;//CurrentScore | ||
public int currentMaxScore = 0;//currentMaxScore possible | ||
public string rank = "SSS";//Rank | ||
public int combo = 0;//Combo | ||
public bool menu = true;//In-menu? | ||
public string type = "";//game type | ||
public string songName = ""; | ||
|
||
public string cover = "empty"; | ||
|
||
//public List<string> received = new List<string>(); | ||
public List<string> debug = new List<string>(); //debug messages. | ||
private WebSocket ws; | ||
|
||
private static Timer reconnectTimer; | ||
|
||
|
||
public void ScoreUpdate(JToken perf) | ||
{ | ||
score = (int)perf["score"]; | ||
currentMaxScore = (int)perf["currentMaxScore"]; | ||
rank = perf["rank"].ToString(); | ||
combo = (int)perf["combo"]; | ||
//debug.Add("Score: " + score + " CurrentMaxScore: " + currentMaxScore + " "); | ||
} | ||
|
||
public BeatSaberStatus() | ||
{ | ||
|
||
//the constructor, I think. | ||
ws = new WebSocket("ws://localhost:6557/socket"); | ||
ws.OnOpen += (sender, e) => | ||
{ | ||
//socket open. | ||
debug.Add("Should have connected to BS"); | ||
}; | ||
ws.OnMessage += (sender, e) => | ||
{ | ||
//debug.Add(e.Data); | ||
|
||
JObject received = JObject.Parse(e.Data); | ||
|
||
|
||
|
||
if (received["event"].ToString() == "songStart") | ||
{ | ||
debug.Add("SongStart"); | ||
cover = received["status"]["beatmap"]["songCover"].ToString(); | ||
songName = received["status"]["beatmap"]["songName"].ToString(); | ||
menu = false; | ||
debug.Add("Songname is " +songName); | ||
} | ||
|
||
if ( | ||
received["event"].ToString() == "noteMissed" | ||
|| | ||
received["event"].ToString() == "scoreChanged" | ||
) | ||
{ | ||
menu = false; | ||
ScoreUpdate(received["status"]["performance"]); | ||
} | ||
if (received["event"].ToString() == "menu") | ||
{ | ||
menu = true; | ||
} | ||
|
||
//received.Add(e.Data); | ||
//message. Just add this to the bottom of the responses list. | ||
}; | ||
ws.OnClose += (sender, e) => | ||
{ | ||
debug.Add("Closed"); | ||
//closed | ||
reconnectTimer.Start(); | ||
}; | ||
ws.OnError += (sender, e) => | ||
{ | ||
//Some error. | ||
debug.Add(e.Message); | ||
if (e.Message.Contains("OnMessage event")) | ||
{ | ||
debug.Add("Beatsaber websocket error: OnMessage event"); | ||
debug.Add("Sender is: " +sender.ToString()); | ||
debug.Add("Verbose error is: " + e.Message.ToString()); | ||
} | ||
else | ||
{ | ||
|
||
|
||
if (e.Message.Contains("occurred in closing the connection")) | ||
{ | ||
debug.Add("Webwsocket error in closing"); | ||
} | ||
else | ||
{ | ||
if (ws.IsAlive) | ||
{ | ||
debug.Add("Error wasn't about something closing. So I'm attempting to close it so it can restart"); | ||
ws.CloseAsync(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
reconnectTimer = new Timer(2000); | ||
reconnectTimer.AutoReset = true; | ||
reconnectTimer.Elapsed += wsConnect; | ||
reconnectTimer.Enabled = true; | ||
|
||
} | ||
|
||
private void wsConnect(Object source, ElapsedEventArgs t) | ||
{ | ||
debug.Add("Timer Fired. " + t.SignalTime); | ||
if (ws.IsAlive) | ||
{ | ||
debug.Add("IsAlive = true. Should be connected."); | ||
} | ||
else | ||
{ | ||
debug.Add("IsAlive = false. Try to connect."); | ||
ws.ConnectAsync(); | ||
reconnectTimer.Stop(); | ||
} | ||
} | ||
public void shutDown() | ||
{ | ||
reconnectTimer.Dispose(); | ||
ws.CloseAsync(); | ||
|
||
} | ||
} |
Oops, something went wrong.