Skip to content

Commit 577fe83

Browse files
committed
half working, continuing on my desktop
1 parent 2f639b1 commit 577fe83

File tree

11 files changed

+94
-39
lines changed

11 files changed

+94
-39
lines changed

CustomMenuText/CustomMenuText.csproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
101101
<Private>False</Private>
102102
</Reference>
103+
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
104+
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
105+
</Reference>
103106
<Reference Include="UnityEngine.UI">
104107
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
105108
<Private>False</Private>
@@ -144,14 +147,11 @@
144147
<None Include="Directory.Build.props" Condition="Exists('Directory.Build.props')" />
145148
<None Include="Directory.Build.targets" Condition="Exists('Directory.Build.targets')" />
146149
<None Include="CustomMenuText.csproj.user" Condition="Exists('CustomMenuText.csproj.user')" />
147-
<EmbeddedResource Include="Fonts\NeonTubes" />
148150
<EmbeddedResource Include="Properties\Resources.resx">
149151
<Generator>PublicResXFileCodeGenerator</Generator>
150152
<LastGenOutput>Resources1.Designer.cs</LastGenOutput>
151153
</EmbeddedResource>
152154
<EmbeddedResource Include="Views\TextSelector\TextSelector.bsml" />
153-
<EmbeddedResource Include="Fonts\Beon" />
154-
<EmbeddedResource Include="Fonts\Teko" />
155155
</ItemGroup>
156156
<ItemGroup>
157157
<PackageReference Include="BeatSaberModdingTools.Tasks">
@@ -163,5 +163,17 @@
163163
<ItemGroup>
164164
<EmbeddedResource Include="DefaultTextFile.txt" />
165165
</ItemGroup>
166+
<ItemGroup>
167+
<EmbeddedResource Include="Fonts\Teko.ttf" />
168+
</ItemGroup>
169+
<ItemGroup>
170+
<EmbeddedResource Include="Fonts\beon.ttf" />
171+
</ItemGroup>
172+
<ItemGroup>
173+
<EmbeddedResource Include="Fonts\NeonTubes2.otf" />
174+
</ItemGroup>
175+
<ItemGroup>
176+
<EmbeddedResource Include="Fonts\NeonTubes" />
177+
</ItemGroup>
166178
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
167179
</Project>

CustomMenuText/FontManager.cs

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,95 @@
77
using UnityEngine;
88
using System.IO;
99
using System.Reflection;
10+
using IPA.Utilities;
11+
using TMPro;
1012

1113
namespace CustomMenuText
1214
{
1315
class FontManager
1416
{
15-
public static Font[] FontList;
17+
public static GameObject Prefab;
18+
public static TMP_FontAsset Font;
19+
public static List<TMP_FontAsset> Fonts;
20+
public static OldFont[] FontList;
1621

17-
public static Font loadBuiltInFont(string fontName, string displayName)
22+
public static GameObject loadPrefab(string fontName)
1823
{
1924
Stream ntf = Assembly.GetExecutingAssembly().GetManifestResourceStream("CustomMenuText.Fonts." + fontName);
2025
AssetBundle neonBundle = AssetBundle.LoadFromStream(ntf);
2126
GameObject NeonTubesPrefab = neonBundle.LoadAsset<GameObject>("Text");
22-
Font NeonTubes = new Font(NeonTubesPrefab, displayName, true);
2327
ntf.Close();
2428
neonBundle.Unload(false);
25-
return NeonTubes;
29+
return NeonTubesPrefab;
2630
}
2731

32+
public static Font embeddedFont(string fileName)
33+
{
34+
string FontPath = Path.Combine(Application.temporaryCachePath, "CMT", fileName);
35+
Plugin.Log.Info($"Cache path is: {FontPath}");
36+
using (Stream ntf = Assembly.GetExecutingAssembly()
37+
.GetManifestResourceStream("CustomMenuText.Fonts." + fileName))
38+
{
39+
if (File.Exists(FontPath))
40+
{
41+
File.Delete(FontPath);
42+
}
43+
using (FileStream fileStream = new FileStream(FontPath, FileMode.CreateNew))
44+
{
45+
for (int i = 0; i < ntf.Length; i++)
46+
fileStream.WriteByte((byte)ntf.ReadByte());
47+
fileStream.Close();
48+
}
49+
ntf.Close();
50+
}
51+
return new Font(FontPath);
52+
}
2853

54+
internal static void LoadTTFFiles(string dir)
55+
{
56+
57+
}
58+
59+
public static TMP_FontAsset LoadFromTTF(string path)
60+
{
61+
var fnt = new Font(path);
62+
Font = TMP_FontAsset.CreateFontAsset(fnt);
63+
return Font;
64+
}
65+
66+
2967
public static void FirstTimeFontLoad()
3068
{
31-
List<Font> tempFontList = new List<Font>();
32-
69+
List<TMP_FontAsset> fonts = new List<TMP_FontAsset>();
70+
Prefab = loadPrefab("NeonTubes");
3371
#region inbuilt fonts
34-
35-
tempFontList.Add(loadBuiltInFont("NeonTubes", "Neon Tubes 2"));
36-
tempFontList.Add(loadBuiltInFont("Beon", "Beon"));
37-
tempFontList.Add(loadBuiltInFont("Teko", "Teko"));
72+
fonts.Add(TMP_FontAsset.CreateFontAsset(embeddedFont("NeonTubes2.otf")));
73+
fonts.Add(TMP_FontAsset.CreateFontAsset(embeddedFont("beon.ttf")));
74+
fonts.Add(TMP_FontAsset.CreateFontAsset(embeddedFont("Teko.ttf")));
3875
#endregion
3976

40-
41-
Plugin.Log.Notice("FontManager) Searching " + Plugin.FONT_PATH + " For Font Files");
42-
var fonts = Directory.GetFiles(Plugin.FONT_PATH);
43-
Plugin.Log.Notice("FontManager) " + fonts.Length + " External Fonts");
44-
if (fonts.Length > 0)
77+
string[] files = Directory.GetFiles(Path.Combine(UnityGame.UserDataPath,"CustomMenuText","Fonts"));
78+
List<string> TTFs = new List<string>();
79+
List<TMP_FontAsset> TTFFiles = new List<TMP_FontAsset>();
80+
foreach (var file in files)
4581
{
46-
for (int i = 0; i < fonts.Length; i++)
82+
if (file.EndsWith(".ttf") || file.EndsWith(".otf"))
4783
{
48-
49-
AssetBundle fontBundle = AssetBundle.LoadFromFile(fonts[i]);
50-
GameObject prefab = fontBundle.LoadAsset<GameObject>("Text");
51-
prefab.name = fonts[i].Substring(Plugin.FONT_PATH.Length);
52-
Font tempFont = new Font(prefab, fonts[i].Substring(Plugin.FONT_PATH.Length));
53-
tempFontList.Add(tempFont);
54-
Plugin.Log.Notice("Adding Font " + tempFont.name);
55-
AssetBundle.Destroy(fontBundle);
56-
fontBundle.Unload(false);
57-
84+
TTFs.Add(file);
5885
}
86+
}
5987

88+
foreach (var ttf in TTFs)
89+
{
90+
fonts.Add(LoadFromTTF(ttf));
6091
}
61-
FontList = tempFontList.ToArray();
92+
93+
Fonts = fonts;
94+
95+
96+
97+
6298
Plugin.Log.Info("FontManager) Font loading complete, ");
63-
Plugin.Log.Info("FontManager) Found " + FontList.Length + " Total Fonts.");
6499
}
65100
}
66101
}

CustomMenuText/Fonts/Beon

-313 KB
Binary file not shown.
20.2 KB
Binary file not shown.

CustomMenuText/Fonts/Teko

-1.22 MB
Binary file not shown.

CustomMenuText/Fonts/Teko.ttf

283 KB
Binary file not shown.

CustomMenuText/Fonts/beon.ttf

52.1 KB
Binary file not shown.

CustomMenuText/Plugin.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ public class Plugin
4343
/// </summary>
4444
public void Init(IPALogger logger)
4545
{
46+
47+
if(!Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
48+
Directory.CreateDirectory(Path.Combine(Application.temporaryCachePath, "CMT"));
4649
Instance = this;
4750
Log = logger;
4851
harmony = new Harmony("com.headassbtw.custommenutext");
4952
Log.Info("CustomMenuText initialized.");
53+
5054
}
5155

5256
public static Color defaultMainColor = Color.red;
@@ -94,7 +98,7 @@ public void InitWithConfig(Config conf)
9498
public static List<string[]> allEntries = null;
9599

96100
public string Name => "Custom Menu Text";
97-
public string Version => "3.3.0";
101+
public string Version => "3.4.0";
98102

99103
// Store the text objects so when we leave the menu and come back, we aren't creating a bunch of them
100104
public static TextMeshPro mainText;
@@ -277,7 +281,8 @@ public static void replaceLogo()
277281
GameObject.Destroy(bottomText);
278282
bottomText = null;
279283
}
280-
textPrefab = FontManager.FontList[Configuration.PluginConfig.Instance.Font].prefab;
284+
285+
textPrefab = FontManager.loadPrefab("NeonTubes");
281286
//if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
282287
//if (mainText == null)
283288
{
@@ -301,6 +306,7 @@ public static void replaceLogo()
301306
mainText.color = MainColor;
302307

303308
mainText.text = "BEAT";
309+
mainText.font = FontManager.Font;
304310

305311
//if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
306312
//if (bottomText == null)
@@ -324,8 +330,8 @@ public static void replaceLogo()
324330
bottomText.rectTransform.position = DefBotPos;
325331
bottomText.color = BottomColor;
326332
bottomText.text = "SABER";
333+
bottomText.font = FontManager.Font;
327334

328-
329335

330336
// Destroy Default Logo
331337

@@ -394,6 +400,8 @@ public void OnApplicationQuit()
394400
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
395401
}
396402
catch (Exception) { }
403+
if(Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
404+
Directory.Delete(Path.Combine(Application.temporaryCachePath, "CMT"));
397405
}
398406

399407

CustomMenuText/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.3.1")]
36-
[assembly: AssemblyFileVersion("3.3.1")]
35+
[assembly: AssemblyVersion("3.4.0")]
36+
[assembly: AssemblyFileVersion("3.4.0")]

CustomMenuText/Tools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ public enum logo
214214
saber
215215
}
216216

217-
public struct Font
217+
public struct OldFont
218218
{
219219
public GameObject prefab;
220220
public string name;
221221
public bool builtin;
222222

223-
public Font(GameObject prefab, string name, bool builtIn = false)
223+
public OldFont(GameObject prefab, string name, bool builtIn = false)
224224
{
225225
this.prefab = prefab;
226226
this.name = name;

0 commit comments

Comments
 (0)