Skip to content

Commit

Permalink
Merge pull request #1 from Kylemc1413/v0-12-compatability
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
megalon authored Jan 5, 2019
2 parents 1e3cff5 + 87efb4f commit ef1ff1c
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 128 deletions.
69 changes: 68 additions & 1 deletion BeatSaberTweaks/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using IllusionPlugin;

using UnityEngine;
namespace BeatSaberTweaks
{
public class Plugin : IPlugin
Expand All @@ -15,9 +15,16 @@ public class Plugin : IPlugin
#endif

private bool _init = false;
private BeatmapCharacteristicSelectionViewController _characteristicViewController;
private static SoloFreePlayFlowCoordinator _soloFlowCoordinator;
private static PartyFreePlayFlowCoordinator _partyFlowCoordinator;

private static PracticeViewController _practiceViewController;
private static StandardLevelDetailViewController _soloDetailView;
private static bool debug = true;
public static bool party { get; private set; } = false;

public static string _gameplayMode { get; private set; }
public enum LogLevel
{
DebugOnly = 0,
Expand All @@ -33,6 +40,66 @@ public void OnApplicationStart()
Settings.Load();
//SettingsUI.OnLoad();
TweakManager.OnLoad();
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
}

private void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1)
{
if(arg1.name == "Menu")
{
if (_characteristicViewController == null)
{
_characteristicViewController = Resources.FindObjectsOfTypeAll<BeatmapCharacteristicSelectionViewController>().FirstOrDefault();
if (_characteristicViewController == null) return;

_characteristicViewController.didSelectBeatmapCharacteristicEvent += _characteristicViewController_didSelectBeatmapCharacteristicEvent;
}

if (_soloFlowCoordinator == null)
{
_soloFlowCoordinator = Resources.FindObjectsOfTypeAll<SoloFreePlayFlowCoordinator>().FirstOrDefault();
if (_soloFlowCoordinator == null) return;
_soloDetailView = _soloFlowCoordinator.GetPrivateField<StandardLevelDetailViewController>("_levelDetailViewController");
_practiceViewController = _soloFlowCoordinator.GetPrivateField<PracticeViewController>("_practiceViewController");
if (_soloDetailView != null)
_soloDetailView.didPressPlayButtonEvent += _soloDetailView_didPressPlayButtonEvent;
else
Log("Detail View Null", Plugin.LogLevel.Info);
if (_practiceViewController != null)
_practiceViewController.didPressPlayButtonEvent += _practiceViewController_didPressPlayButtonEvent;
else
Log("Practice View Null", Plugin.LogLevel.Info);

}

if (_partyFlowCoordinator == null)
{
_partyFlowCoordinator = Resources.FindObjectsOfTypeAll<PartyFreePlayFlowCoordinator>().FirstOrDefault();
}


}
}

private void _practiceViewController_didPressPlayButtonEvent()
{
Log("Play Button Press ", Plugin.LogLevel.Info);
party = _partyFlowCoordinator.isActivated;
Log(party.ToString(), Plugin.LogLevel.Info);
}

private void _soloDetailView_didPressPlayButtonEvent(StandardLevelDetailViewController obj)
{
Log("Play Button Press " , Plugin.LogLevel.Info);
party = _partyFlowCoordinator.isActivated;
Log(party.ToString(), Plugin.LogLevel.Info);
}



private void _characteristicViewController_didSelectBeatmapCharacteristicEvent(BeatmapCharacteristicSelectionViewController arg1, BeatmapCharacteristicSO arg2)
{
_gameplayMode = arg2.characteristicName;
}

public void OnApplicationQuit()
Expand Down
25 changes: 7 additions & 18 deletions BeatSaberTweaks/TweakManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void Awake()

private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{
//Console.WriteLine("Loaded: " + arg0.name);
if(arg0.name == "Menu")
CreateUI();
}

public void Update()
Expand Down Expand Up @@ -105,23 +106,13 @@ private void CarEvent(SimpleDialogPromptViewController viewController, bool ok)

public static bool IsPartyMode()
{
return false;

/*
* TODO
* Fix partymode
if (_mainGameSceneSetupData == null)
{
_mainGameSceneSetupData = Resources.FindObjectsOfTypeAll<MainGameSceneSetupData>().FirstOrDefault();
}
if (_mainGameSceneSetupData == null)
{
Plugin.Log(Plugin.party.ToString(), Plugin.LogLevel.Info);
if (Plugin.party)
return true;
else
return false;
}

return _mainGameSceneSetupData.gameplayMode == GameplayMode.PartyStandard;
*/

}

public void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
Expand All @@ -135,8 +126,6 @@ public void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
_mainMenuViewController = Resources.FindObjectsOfTypeAll<MainMenuViewController>().First();
//var _menuMasterViewController = Resources.FindObjectsOfTypeAll<StandardLevelSelectionFlowCoordinator>().First();
//prompt = ReflectionUtil.GetPrivateField<SimpleDialogPromptViewController>(_menuMasterViewController, "_simpleDialogPromptViewController");

CreateUI();
}
else
{
Expand Down
43 changes: 17 additions & 26 deletions BeatSaberTweaks/Tweaks/OneColour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OneColour : MonoBehaviour

public static void OnLoad(Transform parent)
{
Plugin.Log("One Color Load", Plugin.LogLevel.Info);
if (Instance != null) return;
new GameObject("One Colour").AddComponent<OneColour>().transform.parent = parent;
}
Expand All @@ -38,15 +39,15 @@ public void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
{
try
{
//if (SettingsUI.isMenuScene(scene))
// {
// if (model == null)
// {
// model = Resources.FindObjectsOfTypeAll<MainSettingsModel>().FirstOrDefault();
// rumble = model.controllersRumbleEnabled;
// }
// model.controllersRumbleEnabled = rumble;
// }
if (scene.name == "Menu")
{
if (model == null)
{
model = Resources.FindObjectsOfTypeAll<MainSettingsModel>().FirstOrDefault();
rumble = model.controllersRumbleEnabled;
}
model.controllersRumbleEnabled = rumble;
}
if (SceneUtils.isGameScene(scene) && Settings.OneColour && TweakManager.IsPartyMode())
{
StartCoroutine(WaitForLoad());
Expand Down Expand Up @@ -76,32 +77,22 @@ private IEnumerator WaitForLoad()
loaded = true;
}
}
yield return new WaitForSeconds(0.1f);
LoadingDidFinishEvent();
}

private void LoadingDidFinishEvent()
{
try
{
PlayerController _playerController = FindObjectOfType<PlayerController>();
Saber left = _playerController.leftSaber;
Saber right = _playerController.rightSaber;
Plugin.Log("One Color Activation Attempt", Plugin.LogLevel.Info);
PlayerController _playerController = Resources.FindObjectsOfTypeAll<PlayerController>().FirstOrDefault();
var leftSaberType = _playerController.leftSaber.GetPrivateField<SaberTypeObject>("_saberType");
leftSaberType.SetPrivateField("_saberType", Saber.SaberType.SaberB);
rumble = model.controllersRumbleEnabled;
model.controllersRumbleEnabled = false;

//rumble = model.controllersRumbleEnabled;
//model.controllersRumbleEnabled = false;

if (left != null && right != null)
{
GameObject gameObject = Instantiate(right.gameObject);
Saber component = gameObject.GetComponent<Saber>();
gameObject.transform.parent = left.transform.parent;
gameObject.transform.localPosition = Vector3.zero;
gameObject.transform.localRotation = Quaternion.identity;
left.gameObject.SetActive(false);
ReflectionUtil.SetPrivateField(_playerController, "_leftSaber", component);
//var type = ReflectionUtil.GetPrivateField<SaberTypeObject>(right, "_saberType");
//ReflectionUtil.SetPrivateField(component, "_saberType", type);
}
}
catch (Exception e)
{
Expand Down
Loading

0 comments on commit ef1ff1c

Please sign in to comment.