Skip to content

Commit 11c0abb

Browse files
committed
Update for patch 1.15.0
1 parent a56f562 commit 11c0abb

9 files changed

Lines changed: 285 additions & 12 deletions

File tree

ExtendedColorSchemes/ExtendedColorSchemes.csproj

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
<Private>False</Private>
5151
<SpecificVersion>False</SpecificVersion>
5252
</Reference>
53+
<Reference Include="Polyglot">
54+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Polyglot.dll</HintPath>
55+
<Private>False</Private>
56+
<SpecificVersion>False</SpecificVersion>
57+
</Reference>
58+
<Reference Include="SiraUtil">
59+
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
60+
<Private>False</Private>
61+
<SpecificVersion>False</SpecificVersion>
62+
</Reference>
5363
<Reference Include="System" />
5464
<Reference Include="System.Core" />
5565
<Reference Include="System.Xml.Linq" />
@@ -100,10 +110,22 @@
100110
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
101111
<Private>False</Private>
102112
</Reference>
113+
<Reference Include="Zenject">
114+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
115+
<Private>False</Private>
116+
<SpecificVersion>False</SpecificVersion>
117+
</Reference>
118+
<Reference Include="Zenject-usage">
119+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
120+
<Private>False</Private>
121+
<SpecificVersion>False</SpecificVersion>
122+
</Reference>
103123
</ItemGroup>
104124
<ItemGroup>
125+
<Compile Include="HarmonyPatches\ColorSchemesSettings.cs" />
105126
<Compile Include="Config.cs" />
106-
<Compile Include="HarmonyPatches.cs" />
127+
<Compile Include="Installers\LocalizerInstaller.cs" />
128+
<Compile Include="Localizer.cs" />
107129
<Compile Include="Plugin.cs" />
108130
<Compile Include="Properties\AssemblyInfo.cs" />
109131
<Compile Include="Utils.cs" />
@@ -115,6 +137,7 @@
115137
<None Include="Directory.Build.props" Condition="Exists('Directory.Build.props')" />
116138
<None Include="Directory.Build.targets" Condition="Exists('Directory.Build.targets')" />
117139
<None Include="ExtendedColorSchemes.csproj.user" Condition="Exists('ExtendedColorSchemes.csproj.user')" />
140+
<EmbeddedResource Include="Resources\locales.csv" />
118141
</ItemGroup>
119142
<ItemGroup>
120143
<PackageReference Include="BeatSaberModdingTools.Tasks">
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
using HarmonyLib;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace ExtendedColorSchemes.HarmonyPatches
6+
{
7+
internal class HarmonyPatches
8+
{
9+
[HarmonyPatch(typeof(ColorSchemesSettings), MethodType.Constructor, new[] { typeof(ColorScheme[]) })]
10+
private class PColorSchemesSettings
11+
{
12+
internal static void Postfix(List<ColorScheme> ____colorSchemesList, string ____selectedColorSchemeId)
13+
{
14+
if (Plugin.Config.SelectedColorSchemeId == null)
15+
{
16+
Plugin.Config.SelectedColorSchemeId = ____selectedColorSchemeId;
17+
18+
if (Plugin.Config.ColorSchemesList.Count == 0)
19+
{
20+
for (int i = 0; i < 16; i++)
21+
{
22+
Plugin.Config.ColorSchemesList.Add(new Utils.ExtendedColorScheme
23+
{
24+
_colorSchemeId = $"User{i + 4}",
25+
_colorSchemeNameLocalizationKey = $"CUSTOM_{i + 4}_COLOR_SCHEME",
26+
_isEditable = ____colorSchemesList[0].isEditable,
27+
_saberAColor = ____colorSchemesList[0].saberAColor,
28+
_saberBColor = ____colorSchemesList[0].saberBColor,
29+
_environmentColor0 = ____colorSchemesList[0].environmentColor0,
30+
_environmentColor1 = ____colorSchemesList[0].environmentColor1,
31+
_supportsEnvironmentColorBoost = ____colorSchemesList[0].supportsEnvironmentColorBoost,
32+
_environmentColor0Boost = ____colorSchemesList[0].environmentColor0Boost,
33+
_environmentColor1Boost = ____colorSchemesList[0].environmentColor1Boost,
34+
_obstaclesColor = ____colorSchemesList[0].obstaclesColor,
35+
});
36+
}
37+
38+
Plugin.Config.Changed();
39+
}
40+
}
41+
}
42+
}
43+
44+
[HarmonyPatch(typeof(ColorSchemesSettings), "GetNumberOfColorSchemes")]
45+
private class PGetNumberOfColorSchemes
46+
{
47+
internal static void Postfix(ref int __result)
48+
{
49+
// Prevents the game from saving our color schemes
50+
if (Utils.IsCallByMethod("Save"))
51+
return;
52+
53+
__result += Plugin.Config.ColorSchemesList.Count;
54+
}
55+
}
56+
57+
[HarmonyPatch(typeof(ColorSchemesSettings), "GetColorSchemeForIdx")]
58+
private class PGetColorSchemeForIdx
59+
{
60+
internal static bool Prefix(ref ColorScheme __result, ref int idx)
61+
{
62+
// Prevents the game from saving our color schemes,
63+
// we should only save the base color schemes
64+
if (Utils.IsCallByMethod("Save"))
65+
return true;
66+
67+
// Makes sure our color schemes are inserted at the fourth position
68+
// so it follows the base custom ones
69+
if (idx < 4)
70+
return true;
71+
else if (idx >= Plugin.Config.ColorSchemesList.Count + 4)
72+
{
73+
idx -= Plugin.Config.ColorSchemesList.Count;
74+
return true;
75+
}
76+
77+
__result = Plugin.Config.ColorSchemesList[idx - 4].ToColorScheme();
78+
79+
return false;
80+
}
81+
}
82+
83+
[HarmonyPatch(typeof(ColorSchemesSettings), "GetColorSchemeForId")]
84+
private class PGetColorSchemeForId
85+
{
86+
internal static void Postfix(ref ColorScheme __result, string id)
87+
{
88+
var extendedColorScheme = Plugin.Config.ColorSchemesList.FirstOrDefault(x => x._colorSchemeId == id);
89+
90+
if (extendedColorScheme != null)
91+
{
92+
__result = extendedColorScheme.ToColorScheme();
93+
}
94+
}
95+
}
96+
97+
[HarmonyPatch(typeof(ColorSchemesSettings), "GetSelectedColorScheme")]
98+
private class PGetSelectedColorScheme
99+
{
100+
internal static bool Prefix(ref ColorScheme __result)
101+
{
102+
var extendedColorScheme = Plugin.Config.ColorSchemesList.FirstOrDefault(x => x._colorSchemeId == Plugin.Config.SelectedColorSchemeId);
103+
104+
if (extendedColorScheme != null)
105+
{
106+
__result = extendedColorScheme.ToColorScheme();
107+
return false;
108+
}
109+
110+
return true;
111+
}
112+
}
113+
114+
[HarmonyPatch(typeof(ColorSchemesSettings), "GetSelectedColorSchemeIdx")]
115+
private class PGetSelectedColorSchemeIdx
116+
{
117+
internal static void Postfix(ref int __result)
118+
{
119+
for (int i = 0; i < Plugin.Config.ColorSchemesList.Count; i++)
120+
{
121+
if (Plugin.Config.ColorSchemesList[i]._colorSchemeId == Plugin.Config.SelectedColorSchemeId)
122+
{
123+
__result = i + 4;
124+
return;
125+
}
126+
}
127+
128+
// Returns the base color schemes
129+
if (__result >= 4)
130+
__result += Plugin.Config.ColorSchemesList.Count;
131+
}
132+
}
133+
134+
[HarmonyPatch(typeof(ColorSchemesSettings), "SetColorSchemeForId")]
135+
private class PSetColorSchemeForId
136+
{
137+
internal static void Prefix(ColorScheme colorScheme)
138+
{
139+
if (Plugin.Config.ColorSchemesList.Any(x => x._colorSchemeId == colorScheme.colorSchemeId))
140+
{
141+
for (int i = 0; i < Plugin.Config.ColorSchemesList.Count; i++)
142+
{
143+
if (Plugin.Config.ColorSchemesList[i]._colorSchemeId == colorScheme.colorSchemeId)
144+
{
145+
Plugin.Config.ColorSchemesList[i] = Utils.ToExtendedColorScheme(colorScheme);
146+
return;
147+
}
148+
}
149+
}
150+
}
151+
}
152+
153+
[HarmonyPatch(typeof(ColorSchemesSettings), "selectedColorSchemeId", MethodType.Getter)]
154+
private class PSelectedColorSchemeIdGet
155+
{
156+
internal static void Postfix(ref string __result)
157+
{
158+
// Prevents the game from saving our color schemes selection
159+
if (Utils.IsCallByMethod("Save"))
160+
return;
161+
162+
__result = Plugin.Config.SelectedColorSchemeId;
163+
}
164+
}
165+
166+
[HarmonyPatch(typeof(ColorSchemesSettings), "selectedColorSchemeId", MethodType.Setter)]
167+
private class PSelectedColorSchemeIdSet
168+
{
169+
internal static bool Prefix(string value, Dictionary<string, ColorScheme> ____colorSchemesDict)
170+
{
171+
bool existsInCollection = Plugin.Config.ColorSchemesList.Any(x => x._colorSchemeId == value);
172+
173+
// Makes sure the color scheme exist, probably a bit overkill,
174+
// but at least not messing up the game's save file
175+
if (!existsInCollection && !____colorSchemesDict.ContainsKey(value))
176+
return false;
177+
178+
// Prevents the game from overriding our selected color scheme at launch time
179+
if (Utils.IsCallByMethod("LoadFromCurrentVersion"))
180+
return true;
181+
182+
Plugin.Config.SelectedColorSchemeId = value;
183+
184+
if (existsInCollection)
185+
return false;
186+
187+
return true;
188+
}
189+
}
190+
}
191+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Zenject;
2+
3+
namespace ExtendedColorSchemes.Installers
4+
{
5+
internal class LocalizerInstaller : Installer
6+
{
7+
public override void InstallBindings()
8+
{
9+
Container.BindInterfacesAndSelfTo<Localizer>().AsSingle();
10+
}
11+
}
12+
}

ExtendedColorSchemes/Localizer.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Polyglot;
2+
using System.Reflection;
3+
using UnityEngine;
4+
using Zenject;
5+
6+
namespace ExtendedColorSchemes
7+
{
8+
internal class Localizer : IInitializable
9+
{
10+
public void Initialize()
11+
{
12+
SiraUtil.Utilities.AssemblyFromPath("ExtendedColorSchemes.Resources.locales.csv", out Assembly assembly, out string path);
13+
string content = SiraUtil.Utilities.GetResourceContent(assembly, path);
14+
15+
var asset = new LocalizationAsset
16+
{
17+
Format = GoogleDriveDownloadFormat.CSV,
18+
TextAsset = new TextAsset(content)
19+
};
20+
21+
Localization.Instance.InputFiles.Add(asset);
22+
LocalizationImporter.Refresh();
23+
}
24+
}
25+
}

ExtendedColorSchemes/Plugin.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using HarmonyLib;
1+
using ExtendedColorSchemes.Installers;
2+
using HarmonyLib;
23
using IPA;
34
using IPA.Config.Stores;
5+
using SiraUtil.Zenject;
46
using System.Reflection;
57
using Conf = IPA.Config.Config;
68
using IPALogger = IPA.Logging.Logger;
@@ -17,11 +19,13 @@ public class Plugin
1719
private const string HarmonyID = "com.meivyn.extendedcolorschemes";
1820

1921
[Init]
20-
public Plugin(IPALogger logger, Conf conf)
22+
public Plugin(IPALogger logger, Conf conf, Zenjector zenjector)
2123
{
2224
Log = logger;
2325
Config = conf.Generated<Config>();
2426
_harmony = new Harmony(HarmonyID);
27+
28+
zenjector.OnApp<LocalizerInstaller>();
2529
}
2630

2731
[OnStart]

ExtendedColorSchemes/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -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("1.0.2")]
36-
[assembly: AssemblyFileVersion("1.0.2")]
35+
[assembly: AssemblyVersion("1.0.3")]
36+
[assembly: AssemblyFileVersion("1.0.3")]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Polyglot,100,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2+
CUSTOM_4_COLOR_SCHEME,,Custom 4,Personnalisé 4,Personalizado 4,Spezial 4,,,,,,,,,,,,,カスタム4,,,사용자 지정 4,,,,,,,,
3+
CUSTOM_5_COLOR_SCHEME,,Custom 5,Personnalisé 5,Personalizado 5,Spezial 5,,,,,,,,,,,,,カスタム5,,,사용자 지정 5,,,,,,,,
4+
CUSTOM_6_COLOR_SCHEME,,Custom 6,Personnalisé 6,Personalizado 6,Spezial 6,,,,,,,,,,,,,カスタム6,,,사용자 지정 6,,,,,,,,
5+
CUSTOM_7_COLOR_SCHEME,,Custom 7,Personnalisé 7,Personalizado 7,Spezial 7,,,,,,,,,,,,,カスタム7,,,사용자 지정 7,,,,,,,,
6+
CUSTOM_8_COLOR_SCHEME,,Custom 8,Personnalisé 8,Personalizado 8,Spezial 8,,,,,,,,,,,,,カスタム8,,,사용자 지정 8,,,,,,,,
7+
CUSTOM_9_COLOR_SCHEME,,Custom 9,Personnalisé 9,Personalizado 9,Spezial 9,,,,,,,,,,,,,カスタム9,,,사용자 지정 9,,,,,,,,
8+
CUSTOM_10_COLOR_SCHEME,,Custom 10,Personnalisé 10,Personalizado 10,Spezial 10,,,,,,,,,,,,,カスタム10,,,사용자 지정 10,,,,,,,,
9+
CUSTOM_11_COLOR_SCHEME,,Custom 11,Personnalisé 11,Personalizado 11,Spezial 11,,,,,,,,,,,,,カスタム11,,,사용자 지정 11,,,,,,,,
10+
CUSTOM_12_COLOR_SCHEME,,Custom 12,Personnalisé 12,Personalizado 12,Spezial 12,,,,,,,,,,,,,カスタム12,,,사용자 지정 12,,,,,,,,
11+
CUSTOM_13_COLOR_SCHEME,,Custom 13,Personnalisé 13,Personalizado 13,Spezial 13,,,,,,,,,,,,,カスタム13,,,사용자 지정 13,,,,,,,,
12+
CUSTOM_14_COLOR_SCHEME,,Custom 14,Personnalisé 14,Personalizado 14,Spezial 14,,,,,,,,,,,,,カスタム14,,,사용자 지정 14,,,,,,,,
13+
CUSTOM_15_COLOR_SCHEME,,Custom 15,Personnalisé 15,Personalizado 15,Spezial 15,,,,,,,,,,,,,カスタム15,,,사용자 지정 15,,,,,,,,
14+
CUSTOM_16_COLOR_SCHEME,,Custom 16,Personnalisé 16,Personalizado 16,Spezial 16,,,,,,,,,,,,,カスタム16,,,사용자 지정 16,,,,,,,,
15+
CUSTOM_17_COLOR_SCHEME,,Custom 17,Personnalisé 17,Personalizado 17,Spezial 17,,,,,,,,,,,,,カスタム17,,,사용자 지정 17,,,,,,,,
16+
CUSTOM_18_COLOR_SCHEME,,Custom 18,Personnalisé 18,Personalizado 18,Spezial 18,,,,,,,,,,,,,カスタム18,,,사용자 지정 18,,,,,,,,
17+
CUSTOM_19_COLOR_SCHEME,,Custom 19,Personnalisé 19,Personalizado 19,Spezial 19,,,,,,,,,,,,,カスタム19,,,사용자 지정 19,,,,,,,,

ExtendedColorSchemes/Utils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class Utils
99
internal class ExtendedColorScheme
1010
{
1111
public string _colorSchemeId = "Default";
12-
internal string _colorSchemeName = "Default";
12+
internal string _colorSchemeNameLocalizationKey = "Default";
1313
internal bool _isEditable = true;
1414
internal Color _saberAColor = Color.white;
1515
internal Color _saberBColor = Color.white;
@@ -24,7 +24,7 @@ public ColorScheme ToColorScheme()
2424
{
2525
return new ColorScheme(
2626
_colorSchemeId,
27-
_colorSchemeName,
27+
_colorSchemeNameLocalizationKey,
2828
_isEditable,
2929
_saberAColor,
3030
_saberBColor,
@@ -43,7 +43,7 @@ public static ExtendedColorScheme ToExtendedColorScheme(ColorScheme colorScheme)
4343
var extendedColorScheme = new ExtendedColorScheme
4444
{
4545
_colorSchemeId = colorScheme.colorSchemeId,
46-
_colorSchemeName = colorScheme.colorSchemeName,
46+
_colorSchemeNameLocalizationKey = colorScheme.colorSchemeNameLocalizationKey,
4747
_isEditable = colorScheme.isEditable,
4848
_saberAColor = colorScheme.saberAColor,
4949
_saberBColor = colorScheme.saberBColor,

ExtendedColorSchemes/manifest.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"id": "ExtendedColorSchemes",
44
"name": "ExtendedColorSchemes",
55
"author": "Meivyn",
6-
"version": "1.0.2",
6+
"version": "1.0.3",
77
"description": "Adds additional custom slots to color schemes.",
8-
"gameVersion": "1.13.4",
8+
"gameVersion": "1.15.0",
99
"dependsOn": {
10-
"BSIPA": "^4.1.4"
10+
"BSIPA": "^4.1.4",
11+
"SiraUtil": "^2.5.3"
1112
}
1213
}

0 commit comments

Comments
 (0)