Skip to content

Commit

Permalink
Version 0.1.0 Rewrite.
Browse files Browse the repository at this point in the history
First version of a complete rewrite.

Hopefully it reflects a less amateurish way of approchaing the task.

On the to-do list:
-make settings accessible again.
  • Loading branch information
Morichalion committed Jun 1, 2020
1 parent b11872f commit 532ae60
Show file tree
Hide file tree
Showing 19 changed files with 773 additions and 211 deletions.
Binary file modified .vs/MoriBScam/v16/.suo
Binary file not shown.
Binary file modified .vs/MoriBScam/v16/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/MoriBScam/v16/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/MoriBScam/v16/Server/sqlite3/storage.ide-wal
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\MonoBehaviors.cs",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
10 changes: 10 additions & 0 deletions .vs/tasks.vs.json
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"
}
]
}
159 changes: 159 additions & 0 deletions BeatSaberAutoCamera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using MorichalionStuff;

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 v0.1.0";
public string author => "Morichalion";
public string version => "0.1.0";

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;

//
RigCam rig;
menuCam men;


public void OnActivate(PluginCameraHelper helper) {
_helper = helper;//got my cam stuff.
BS = new BeatSaberStatus();
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;
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;
}
}
rig = new RigCam();
rig.worlCam = helper.manager.camera.worldCamera.transform;
men = new menuCam();

men.WorldCam = helper.manager.camera.worldCamera.transform;
}

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);
}
}
}
}
141 changes: 141 additions & 0 deletions BeatSaberStatus.cs
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();

}
}
Loading

0 comments on commit 532ae60

Please sign in to comment.