Skip to content

Commit

Permalink
Update for game version 1.7.0; remove unneeded code; add new public m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
artemiswkearney committed Feb 9, 2020
1 parent 0599632 commit cab0646
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 52 deletions.
Binary file removed Custom Menu Text/Beon
Binary file not shown.
25 changes: 17 additions & 8 deletions Custom Menu Text/CustomMenuText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomMenuText</RootNamespace>
<AssemblyName>CustomMenuText</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -31,14 +31,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="HMLib">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Reference Include="IPA.Loader, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="IllusionPlugin">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll</HintPath>
<Reference Include="MainAssembly">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\MainAssembly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -50,19 +53,24 @@
<Reference Include="System.Xml" />
<Reference Include="Unity.TextMeshPro">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -81,8 +89,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Beon" />
<None Include="NeonTubes" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetFileName)" "C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins"</PostBuildEvent>
Expand Down
137 changes: 99 additions & 38 deletions Custom Menu Text/CustomMenuTextPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using IllusionPlugin;
using IPA.Old;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -20,13 +20,13 @@ public class CustomMenuTextPlugin : IPlugin
public static GameObject textPrefab;
// used if we can't load any custom entries
public static readonly string[] DEFAULT_TEXT = { "BEAT", "SABER" };
public static readonly Color defaultMainColor = new Color(0, 0.5019608f, 1);
public static readonly Color defaultBottomColor = Color.red;
public static readonly Color defaultMainColor = Color.red;
public static readonly Color defaultBottomColor = new Color(0, 0.5019608f, 1);

public const string DEFAULT_CONFIG =
@"# Custom Menu Text v3.0.1
@"# Custom Menu Text v3.1.0
# by Arti
# Special Thanks: Kyle1413
# Special Thanks: Kyle1413, Alphie
#
# Use # for comments!
# Separate entries with empty lines; a random one will be picked each time the menu loads.
Expand All @@ -36,7 +36,7 @@ public class CustomMenuTextPlugin : IPlugin
# Entries with a number of lines other than 2 won't be colored by default.
# Color them yourself with formatting!
<#0080FF>B<#FF0000>S
<#FF0000>B<#0080FF>S
# Finally allowed again!
MEAT
Expand All @@ -45,7 +45,7 @@ public class CustomMenuTextPlugin : IPlugin
# You can override the colors even when the text is 2 lines, plus do a lot of other stuff!
# (contributed by @Rolo)
<size=+5><#ffffff>SBU<#ffff00>BBY
<size=-5><#1E5142>eef freef.
<size=5><#1E5142>eef freef.
# Some more random messages:
BEAT
Expand All @@ -69,7 +69,7 @@ public class CustomMenuTextPlugin : IPlugin
BEAR
BEATS
<#0080FF>BEAR <#FF0000>BEATS
<#FF0000>BEAR <#0080FF>BEATS
<#DDDDDD>BATTLESTAR GALACTICA
BEE
Expand Down Expand Up @@ -141,33 +141,41 @@ HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK HECK
OFF
Having problems?
Ask in <#7289DA>#support
Ask in <#7289DA>#pc-help
READ
BOOKS
# wrong colors
<#FF0000>BEAT
<#0080FF>SABER
<#0080FF>HARDER
<#FF0000>BETTER
<#0080FF>FASTER
<#0080FF>BEAT
<#FF0000>SABER
<#FF0000>HARDER
<#0080FF>BETTER
<#FF0000>FASTER
<#0080FF>SABER
DON'T
PANIC";
PANIC
<line-height=75%><#cf7100>ARTI
<#FF0000><size=+4><</size>3
<#0080FF>JADE
<i>slontey";

// caches entries loaded from the file so we don't need to do IO every time the menu loads
public static List<string[]> allEntries = null;

public string Name => "Custom Menu Text";
public string Version => "3.0.1";
public string Version => "3.1.0";

// Store the text objects so when we leave the menu and come back, we aren't creating a bunch of them
public static TextMeshPro mainText;
public static TextMeshPro bottomText; // BOTTOM TEXT

public System.Random random;

public void OnApplicationStart()
{
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
Expand All @@ -176,7 +184,7 @@ public void OnApplicationStart()

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
{
if (arg1.name == "MenuCore") // Only run in menu scene
if (arg0.name == "EmptyTransition" && arg1.name.Contains("Menu")) // Only run in menu scene
{
if (allEntries == null)
{
Expand All @@ -188,48 +196,51 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
}
else
{
// Choose an entry randomly

// Unity's random seems to give biased results
// int entryPicked = UnityEngine.Random.Range(0, entriesInFile.Count);
// using System.Random instead
System.Random r = new System.Random();
int entryPicked = r.Next(allEntries.Count);

// Set the text
setText(allEntries[entryPicked]);
pickRandomEntry();
}
}
}

/// <summary>
/// Chooses a random entry from the current config and sets the menu text to that entry.
/// Warning: Only call this function from the main menu scene!
/// </summary>
public void pickRandomEntry()
{
// Choose an entry randomly

// Unity's random seems to give biased results
// int entryPicked = UnityEngine.Random.Range(0, entriesInFile.Count);
// using System.Random instead
if (random == null) random = new System.Random();
int entryPicked = random.Next(allEntries.Count);

// Set the text
setText(allEntries[entryPicked]);
}

private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{

}

public static GameObject loadTextPrefab(string path)
{
var oldFonts = GameObject.FindObjectsOfType<TMP_FontAsset>();
var glowFonts = oldFonts.Where(f => !f.name.Contains("No Glow"));
var mat = glowFonts.FirstOrDefault()?.material;

GameObject prefab;
string fontPath = Path.Combine(Environment.CurrentDirectory, path);
if (!File.Exists(fontPath))
{
File.WriteAllBytes(fontPath, Properties.Resources.Beon);
File.WriteAllBytes(fontPath, Properties.Resources.NeonTubes);
}
AssetBundle fontBundle = AssetBundle.LoadFromFile(fontPath);
prefab = fontBundle.LoadAsset<GameObject>("Text");
if (prefab == null)
{
Console.WriteLine("[CustomMenuText] No text prefab found in the provided AssetBundle! Using Beon.");
AssetBundle beonBundle = AssetBundle.LoadFromMemory(Properties.Resources.Beon);
Console.WriteLine("[CustomMenuText] No text prefab found in the provided AssetBundle! Using NeonTubes.");
AssetBundle beonBundle = AssetBundle.LoadFromMemory(Properties.Resources.NeonTubes);
prefab = beonBundle.LoadAsset<GameObject>("Text");
}

if (mat != null) prefab.GetComponent<TextMeshPro>().font.material = mat;

return prefab;
}

Expand Down Expand Up @@ -365,7 +376,7 @@ public static void replaceLogo()
/// the text of your choice. TextMeshPro formatting can be used here.
/// Additionally:
/// - If the text is exactly 2 lines long, the first line will be
/// displayed in blue, and the second will be displayed in red.
/// displayed in red, and the second will be displayed in blue.
/// Warning: Only call this function from the main menu scene!
/// </summary>
/// <param name="lines">
Expand Down Expand Up @@ -404,6 +415,56 @@ public void reloadFile()
allEntries = readFromFile(FILE_PATH);
}

/// <summary>
/// Saves the current value of <see cref="allEntries"/> to the default config location.
/// Warning: effectively strips comments from the file!
/// </summary>
public void writeFile()
{
// join entries by two newlines and lines by one
string contents = String.Join("\n\n", allEntries.Select(e => String.Join("\n", e)));
string gameDirectory = Environment.CurrentDirectory;
gameDirectory = gameDirectory.Replace('\\', '/');
var path = gameDirectory + FILE_PATH;
try
{
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
{
Byte[] info = new UTF8Encoding(true).GetBytes(contents
// normalize newlines to CRLF
.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"));
fs.Write(info, 0, info.Length);
}
}
catch (Exception ex)
{
Console.WriteLine("[CustomMenuText] Failed to save config!");
Console.WriteLine("[CustomMenuText] Error:");
Console.WriteLine(ex);
}
}

/// <summary>
/// Overwrites the current config with the default and loads it.
/// </summary>
public void restoreDefaultConfig()
{
string gameDirectory = Environment.CurrentDirectory;
gameDirectory = gameDirectory.Replace('\\', '/');
var path = gameDirectory + FILE_PATH;
try
{
if (File.Exists(path)) File.Delete(path);
reloadFile();
}
catch (Exception ex)
{
Console.WriteLine("[CustomMenuText] Failed to save config!");
Console.WriteLine("[CustomMenuText] Error:");
Console.WriteLine(ex);
}
}

public void OnApplicationQuit()
{
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
Expand Down
Binary file added Custom Menu Text/NeonTubes
Binary file not shown.
4 changes: 2 additions & 2 deletions Custom Menu Text/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.1.0")]
[assembly: AssemblyFileVersion("3.0.1.0")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
4 changes: 2 additions & 2 deletions Custom Menu Text/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Custom Menu Text/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Beon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Beon;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="NeonTubes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\NeonTubes;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

0 comments on commit cab0646

Please sign in to comment.