Skip to content

Commit

Permalink
Updated for Beat Saber 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingabopp committed Jan 4, 2020
1 parent 2f3c120 commit c79987a
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 513 deletions.
70 changes: 31 additions & 39 deletions BailOutMode/BailOutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace BailOutMode
class BailOutController : MonoBehaviour
{
#region "Fields with get/setters"
private static BailOutController _instance;
public static BailOutController instance { get; private set; }
private LevelFailedTextEffect _levelFailedEffect;
private StandardLevelGameplayManager _gameManager;
private GameEnergyCounter _energyCounter;
Expand All @@ -20,13 +20,13 @@ class BailOutController : MonoBehaviour
#endregion
#region "Fields"
public bool isHiding = false;
public static int numFails = 0;
public int numFails = 0;

public bool IsEnabled
{
get
{
return Plugin.IsEnabled && (!isCampaign);
return Config.instance.IsEnabled && (!isCampaign);
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ private static PlayerSpecificSettings PlayerSettings
{
_playerSettings = BS_Utils.Plugin.LevelData?.GameplayCoreSceneSetupData?.playerSpecificSettings;
if (_playerSettings == null)
Logger.Warning($"Unable to find PlayerSettings");
Logger.log.Warn($"Unable to find PlayerSettings");
}
return _playerSettings;
}
Expand All @@ -95,34 +95,23 @@ private static float PlayerHeight
}
else
{
Logger.Warning("Unable to find PlayerSettings, using 1.8 for player height");
Logger.log.Warn("Unable to find PlayerSettings, using 1.8 for player height");
return 1.8f;
}
}
}
public static BailOutController Instance
{
get
{
if (_instance == null)
{
Logger.Debug("BailOutController instance is null, creating new one");
_instance = new GameObject("BailOutController").AddComponent<BailOutController>();
}
return _instance;
}
}

public static bool InstanceExists
{
get { return _instance != null; }
get { return instance != null; }
}

#endregion

public void Awake()
{
//Logger.Trace("BailOutController Awake()");
_instance = this;
instance = this;
isHiding = false;
}

Expand All @@ -142,7 +131,7 @@ private IEnumerator Initialize()
//Logger.Trace("Checking for Campaign mode");
if (GameObject.FindObjectsOfType<MissionGameplaySceneSetup>().Count() > 0)
{
Logger.Info("Campaign mode detected, BailOutMode unavailable.");
Logger.log.Info("Campaign mode detected, BailOutMode unavailable.");
isCampaign = true;
}
else
Expand All @@ -151,63 +140,65 @@ private IEnumerator Initialize()
}
if ((GameManager != null) && (EnergyCounter != null) && IsEnabled)
{
Logger.Info("BailOutMode enabled");
Logger.log.Info("BailOutMode enabled");
//Logger.Trace("Removing HandleGameEnergyDidReach0");
EnergyCounter.gameEnergyDidReach0Event -= GameManager.HandleGameEnergyDidReach0;
}
}

private void OnDestroy()
{
Logger.Debug("Destroying BailOutController");
Logger.log.Debug("Destroying BailOutController");
instance = null;
}

public void ShowLevelFailed()
{
//Logger.Trace("BailOutController ShowLevelFailed()");
//BS_Utils.Gameplay.ScoreSubmission.DisableSubmission(Plugin.PluginName); Don't need this here
UpdateFailText($"Bailed Out {numFails} time{(numFails != 1 ? "s" : "")}");
if (!isHiding && Plugin.ShowFailEffect)
if (!isHiding && Config.instance.ShowFailEffect)
{
try
{
if (!Plugin.RepeatFailEffect && numFails > 1)
if (!Config.instance.RepeatFailEffect && numFails > 1)
return; // Don't want to repeatedly show fail effect, stop here.

//Logger.Debug("Showing fail effect");
LevelFailedEffect.ShowEffect();
if (Plugin.FailEffectDuration > 0)
if (Config.instance.FailEffectDuration > 0)
StartCoroutine(hideLevelFailed());
else
isHiding = true; // Fail text never hides, so don't try to keep showing it
}
catch (Exception ex)
{
Logger.Exception("Exception trying to show the fail Effect", ex);
Logger.log.Error($"Exception trying to show the fail Effect: {ex.Message}");
Logger.log.Debug(ex);
}
}
}

private WaitForSeconds failDurationWait = new WaitForSeconds(Config.instance.FailEffectDuration);
public IEnumerator<WaitForSeconds> hideLevelFailed()
{
Logger.Trace("BailOutController hideLevelFailed() CoRoutine");
Logger.log.Trace("BailOutController hideLevelFailed() CoRoutine");
if (!isHiding)
{
Logger.Trace($"BailOutController, will hide LevelFailedEffect after {Plugin.FailEffectDuration}s");
Logger.log.Trace($"BailOutController, will hide LevelFailedEffect after {Config.instance.FailEffectDuration}s");
isHiding = true;
yield return new WaitForSeconds(Plugin.FailEffectDuration);
Logger.Trace($"BailOutController, hiding LevelFailedEffect");
yield return failDurationWait;
Logger.log.Trace($"BailOutController, hiding LevelFailedEffect");
LevelFailedEffect.gameObject.SetActive(false);
isHiding = false;
}
else
Logger.Trace("BailOutController, skipping hideLevel because isHiding is true");
Logger.log.Trace("BailOutController, skipping hideLevel because isHiding is true");
yield break;
}

public static void FacePosition(Transform obj, Vector3 targetPos)
{
var rotAngle = Quaternion.LookRotation(StringToVector3(Plugin.CounterTextPosition) - targetPos);
var rotAngle = Quaternion.LookRotation(StringToVector3(Config.instance.CounterTextPosition) - targetPos);
obj.rotation = rotAngle;
}

Expand All @@ -233,11 +224,11 @@ public TextMeshProUGUI CreateText(Canvas parent, string text, Vector2 anchoredPo
var font = Instantiate(Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF No Glow"));
if (font == null)
{
Logger.Error("Could not locate font asset, unable to display text");
Logger.log.Error("Could not locate font asset, unable to display text");
return null;
}
textMesh.font = font;
textMesh.fontSize = Plugin.CounterTextSize;
textMesh.fontSize = Config.instance.CounterTextSize;
textMesh.rectTransform.SetParent(parent.transform as RectTransform, false);
textMesh.text = text;
textMesh.color = Color.white;
Expand All @@ -254,7 +245,7 @@ public TextMeshProUGUI CreateText(Canvas parent, string text, Vector2 anchoredPo
public static void CenterTextMesh(TextMeshProUGUI text)
{
text.ForceMeshUpdate();
var pos = StringToVector3(Plugin.CounterTextPosition);
var pos = StringToVector3(Config.instance.CounterTextPosition);
pos.x = pos.x - (text.renderedWidth * text.gameObject.transform.localScale.x) / 2;
pos.y = pos.y + (text.renderedHeight * text.gameObject.transform.localScale.y);
FacePosition(text.gameObject.transform, new Vector3(0, PlayerHeight, 0));
Expand All @@ -265,8 +256,8 @@ public static void CenterTextMesh(TextMeshProUGUI text)
public void UpdateFailText(string text)
{
FailText.text = text;
if (Plugin.DynamicSettings)
FailText.fontSize = Plugin.CounterTextSize;
if (Config.instance.DynamicSettings)
FailText.fontSize = Config.instance.CounterTextSize;
CenterTextMesh(FailText);
}

Expand All @@ -284,7 +275,8 @@ public static Vector3 StringToVector3(string vStr)
}
catch (Exception ex)
{
Logger.Exception($"Cannot convert value of {vStr} to a Vector. Needs to be in the format #,#,#", ex);
Logger.log.Error($"Cannot convert value of {vStr} to a Vector. Needs to be in the format #,#,#: {ex.Message}");
Logger.log.Debug(ex);
return new Vector3(DefaultSettings.CounterTextPosition.x, DefaultSettings.CounterTextPosition.y, DefaultSettings.CounterTextPosition.z);
}
}
Expand Down
98 changes: 90 additions & 8 deletions BailOutMode/BailOutMode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BailOutMode</RootNamespace>
<AssemblyName>BailOutMode</AssemblyName>
<AssemblyVersion>1.4.0</AssemblyVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
Expand All @@ -33,24 +34,34 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>.\References\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>.\References\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="0Harmony.1.2.0.1, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Libs\0Harmony.1.2.0.1.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BeatSaberCustomUI">
<HintPath>References\Plugins\BeatSaberCustomUI.dll</HintPath>
</Reference>
<Reference Include="BSML, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
</Reference>
<Reference Include="BS_Utils">
<HintPath>References\Plugins\BS_Utils.dll</HintPath>
</Reference>
<Reference Include="HMLib, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
</Reference>
<Reference Include="HMUI, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll</HintPath>
</Reference>
<Reference Include="IllusionInjector">
<HintPath>References\Managed\IllusionInjector.dll</HintPath>
</Reference>
<Reference Include="IllusionPlugin">
<HintPath>References\Managed\IllusionPlugin.dll</HintPath>
<HintPath>IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="INIFileParser">
<HintPath>References\Managed\INIFileParser.dll</HintPath>
Expand All @@ -61,6 +72,10 @@
<Reference Include="IPA.Loader">
<HintPath>References\Managed\IPA.Loader.dll</HintPath>
</Reference>
<Reference Include="MainAssembly, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\MainAssembly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -94,24 +109,91 @@
<HintPath>.\References\Managed\UnityEngine.VRModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Zenject, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Harmony_Patches\GameEnergyCounterAddEnergy.cs" />
<Compile Include="BailOutController.cs" />
<Compile Include="Harmony_Patches\HandleSongDidFinish.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionUtil.cs" />
<Compile Include="UI\BailOutModeUI.cs" />
</ItemGroup>
<ItemGroup>
<None Include="CreateJunctions.bat" />
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="UI\Settings.bsml" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="CopyToPlugins" AfterTargets="Build" Condition="'$(NCrunch)' != '1'">
<Message Text="Copying $(OutputPath)$(AssemblyName).dll to Plugins folder" Importance="high" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFiles="$(ProjectDir)\References\Plugins\$(AssemblyName).dll" />
</Target>
<!-- Source: Mostly from https://github.com/opl-/beatsaber-http-status -->
<Target Name="ZipRelease" AfterTargets="Build" Condition="'$(NCrunch' != '1' AND '$(Configuration)' == 'Release'">
<Message Text="Zipping plugin for release. $(AssemblyVersion)" Importance="high" />
<Exec Command="git rev-parse HEAD &gt; $(IntermediateOutputPath)head" />
<ReadLinesFromFile File="$(IntermediateOutputPath)head">
<Output TaskParameter="Lines" PropertyName="FullCommitHash" />
</ReadLinesFromFile>
<Delete Files="$(IntermediateOutputPath)head" />
<PropertyGroup>
<CommitHash>$(FullCommitHash.Substring(0, 8))</CommitHash>
</PropertyGroup>
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFiles="$(IntermediateOutputPath)\zip\Plugins\$(AssemblyName).dll" />
<ZipDir ZipFileName="$(OutDir)\zip\$(AssemblyName)-$(AssemblyVersion)-$(CommitHash).zip" DirectoryName="$(IntermediateOutputPath)\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" />
<Reference Include="System.IO" />
<Using Namespace="System.IO.Compression" />
<Using Namespace="System.IO" />
<Using Namespace="System.Threading" />
<Code Type="Fragment" Language="cs"><![CDATA[
try
{
var zipDir = new DirectoryInfo(Path.GetDirectoryName(Path.GetFullPath(ZipFileName)));
if (zipDir.Exists)
zipDir.Delete(true);
zipDir.Create();
zipDir.Refresh();
int tries = 0;
while(!zipDir.Exists || tries < 10) // Prevents breaking when Explorer is in the folder.
{
tries++;
Thread.Sleep(50);
zipDir.Create();
zipDir.Refresh();
}
if(File.Exists(ZipFileName))
File.Delete(ZipFileName);
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>
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetFileName)" "$(ProjectDir)\References\Plugins"</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
Loading

0 comments on commit c79987a

Please sign in to comment.