using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
using Elements.Assets;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("ResoniteModding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+5d109566b003849489ee266e1af6bfeb0e95f7e9")]
[assembly: AssemblyProduct("Bepis Locale Loader")]
[assembly: AssemblyTitle("BepisLocaleLoader")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ResoniteModding/BepisLocaleLoader")]
[assembly: AssemblyVersion("1.2.0.0")]
[module: RefSafetyRules(11)]
namespace BepisLocaleLoader;
public struct ConfigLocale
{
public LocaleString Name;
public LocaleString Description;
public ConfigLocale(string name, string description)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
Name = LocaleHelper.AsLocaleKey(name, (string)null, true, (Dictionary<string, object>)null);
Description = LocaleHelper.AsLocaleKey(description, (string)null, true, (Dictionary<string, object>)null);
}
public ConfigLocale(LocaleString name, LocaleString description)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
Name = name;
Description = description;
}
}
public static class ConfigLocaleHelper
{
public static ConfigEntry<T> BindLocalized<T>(this ConfigFile config, string guid, string section, string key, T defaultValue, string englishDescription)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
//IL_001d: Expected O, but got Unknown
return config.BindLocalized(guid, new ConfigDefinition(section, key), defaultValue, new ConfigDescription(englishDescription, (AcceptableValueBase)null, global::System.Array.Empty<object>()));
}
public static ConfigEntry<T> BindLocalized<T>(this ConfigFile config, string guid, string section, string key, T defaultValue, ConfigDescription configDescription = null)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
return config.BindLocalized(guid, new ConfigDefinition(section, key), defaultValue, configDescription);
}
public static ConfigEntry<T> BindLocalized<T>(this ConfigFile config, string guid, ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
{
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
string text = $"Settings.{guid}.{configDefinition.Section}.{configDefinition.Key}";
string description = text + ".Description";
ConfigLocale configLocale = new ConfigLocale(text, description);
if (configDescription == null)
{
configDescription = new ConfigDescription(string.Empty, (AcceptableValueBase)null, new object[1] { configLocale });
}
else
{
string description2 = configDescription.Description;
AcceptableValueBase acceptableValues = configDescription.AcceptableValues;
object[] tags = configDescription.Tags;
int num = 0;
object[] array = new object[1 + tags.Length];
global::System.ReadOnlySpan<object> readOnlySpan = new global::System.ReadOnlySpan<object>(tags);
readOnlySpan.CopyTo(new global::System.Span<object>(array).Slice(num, readOnlySpan.Length));
num += readOnlySpan.Length;
array[num] = configLocale;
configDescription = new ConfigDescription(description2, acceptableValues, array);
}
return config.Bind<T>(configDefinition, defaultValue, configDescription);
}
}
public static class LocaleLoader
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Action <>9__11_0;
internal void <UpdateLocale>b__11_0()
{
((SyncField<string>)(object)_localeProvider.OverrideLocale).Value = _lastOverrideLocale;
}
}
private static StaticLocaleProvider _localeProvider;
private static string _lastOverrideLocale;
private const string OverrideLocaleString = "somethingRandomJustToMakeItChange";
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
ReadCommentHandling = (JsonCommentHandling)1,
AllowTrailingCommas = true
};
public static readonly HashSet<PluginInfo> PluginsWithLocales = new HashSet<PluginInfo>();
public static void AddLocaleString(string rawString, string localeString, bool force = false, string authors = null)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
List<string> authors2;
if (!string.IsNullOrWhiteSpace(authors))
{
authors2 = Enumerable.ToList<string>((global::System.Collections.Generic.IEnumerable<string>)authors.Split(", ", (StringSplitOptions)1));
}
else if (!string.IsNullOrWhiteSpace("ResoniteModding"))
{
authors2 = Enumerable.ToList<string>((global::System.Collections.Generic.IEnumerable<string>)"ResoniteModding".Split(", ", (StringSplitOptions)1));
}
else
{
List<string> obj = new List<string>();
obj.Add("BepInEx");
authors2 = obj;
}
LocaleData val = new LocaleData
{
LocaleCode = "en-US",
Authors = authors2
};
Dictionary<string, string> obj2 = new Dictionary<string, string>();
obj2.Add(rawString, localeString);
val.Messages = obj2;
Update(val, force);
}
public static void AddLocaleFromPlugin(PluginInfo plugin)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
string text = Path.Combine(Path.GetDirectoryName(plugin.Location), "Locale");
if (Path.Exists(text))
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Adding locale for ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(plugin.Metadata.GUID);
}
log.LogDebug(val);
ProcessPath(text, AddLocaleFromFile);
PluginsWithLocales.Add(plugin);
}
}
public static void AddLocaleFromFile(string path)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
if (File.Exists(path))
{
string text = File.ReadAllText(path);
LocaleData val;
try
{
val = JsonSerializer.Deserialize<LocaleData>(text, JsonOptions);
}
catch (global::System.Exception ex)
{
Plugin.Log.LogError((object)ex);
return;
}
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(31, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("- LocaleCode: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.LocaleCode);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", Message Count: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.Messages.Count);
}
log.LogDebug(val2);
Update(val, force: true);
}
}
private static void Update(LocaleData localeData, bool force)
{
UpdateDelayed(localeData, force);
Settings.RegisterValueChanges<LocaleSettings>((SettingUpdateHandler<LocaleSettings>)delegate
{
UpdateDelayed(localeData, force);
});
}
private static void UpdateDelayed(LocaleData localeData, bool force)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
World userspaceWorld = Userspace.UserspaceWorld;
if (userspaceWorld != null)
{
userspaceWorld.RunInUpdates(15, (Action)delegate
{
UpdateIntern(localeData, force);
});
}
}
private static void UpdateIntern(LocaleData localeData, bool force)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
World userspaceWorld = Userspace.UserspaceWorld;
_localeProvider = ((userspaceWorld != null) ? LocaleHelper.GetCoreLocale((IWorldElement)(object)userspaceWorld) : null);
StaticLocaleProvider localeProvider = _localeProvider;
object obj;
if (localeProvider == null)
{
obj = null;
}
else
{
LocaleResource asset = ((AssetProvider<LocaleResource>)(object)localeProvider).Asset;
obj = ((asset != null) ? asset.Data : null);
}
if (obj == null)
{
World userspaceWorld2 = Userspace.UserspaceWorld;
if (userspaceWorld2 != null)
{
userspaceWorld2.RunSynchronously((Action)delegate
{
UpdateIntern(localeData, force);
}, false, (IUpdatable)null, false);
}
}
else
{
UpdateLocale(localeData, force);
}
}
private static void UpdateLocale(LocaleData localeData, bool force)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Expected O, but got Unknown
StaticLocaleProvider localeProvider = _localeProvider;
object obj;
if (localeProvider == null)
{
obj = null;
}
else
{
LocaleResource asset = ((AssetProvider<LocaleResource>)(object)localeProvider).Asset;
obj = ((asset != null) ? asset.Data : null);
}
if (obj != null)
{
if (!force)
{
string firstKey = Enumerable.FirstOrDefault<string>((global::System.Collections.Generic.IEnumerable<string>)localeData.Messages.Keys);
if (Enumerable.Any<KeyValuePair<string, Message>>((global::System.Collections.Generic.IEnumerable<KeyValuePair<string, Message>>)(object)((AssetProvider<LocaleResource>)(object)_localeProvider).Asset.Data.Messages, (Func<KeyValuePair<string, Message>, bool>)((KeyValuePair<string, Message> ld) => ld.Key == firstKey)))
{
return;
}
}
((AssetProvider<LocaleResource>)(object)_localeProvider).Asset.Data.LoadDataAdditively(localeData);
if (((SyncField<string>)(object)_localeProvider.OverrideLocale).Value != null && ((SyncField<string>)(object)_localeProvider.OverrideLocale).Value != "somethingRandomJustToMakeItChange")
{
_lastOverrideLocale = ((SyncField<string>)(object)_localeProvider.OverrideLocale).Value;
}
((SyncField<string>)(object)_localeProvider.OverrideLocale).Value = "somethingRandomJustToMakeItChange";
World userspaceWorld = Userspace.UserspaceWorld;
object obj2 = <>c.<>9__11_0;
if (obj2 == null)
{
Action val = delegate
{
((SyncField<string>)(object)_localeProvider.OverrideLocale).Value = _lastOverrideLocale;
};
<>c.<>9__11_0 = val;
obj2 = (object)val;
}
userspaceWorld.RunInUpdates(1, (Action)obj2);
}
else
{
StaticLocaleProvider localeProvider2 = _localeProvider;
object obj3;
if (localeProvider2 == null)
{
obj3 = null;
}
else
{
LocaleResource asset2 = ((AssetProvider<LocaleResource>)(object)localeProvider2).Asset;
obj3 = ((asset2 != null) ? asset2.Data : null);
}
if (obj3 == null)
{
Plugin.Log.LogError((object)"Locale data is null when it shouldn't be!");
}
}
}
private static void ProcessPath(string path, Action<string> fileAction)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if (!Path.Exists(path))
{
throw new DirectoryNotFoundException("Directory not found: " + path);
}
ProcessDirectory(path, fileAction);
}
private static void ProcessDirectory(string directory, Action<string> fileAction)
{
string[] files = Directory.GetFiles(directory);
foreach (string text in files)
{
fileAction.Invoke(text);
}
files = Directory.GetDirectories(directory);
for (int i = 0; i < files.Length; i++)
{
ProcessDirectory(files[i], fileAction);
}
}
private static string GetFormattedLocaleString(this string key, string format, Dictionary<string, object> dict, ValueTuple<string, object>[] arguments)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
Dictionary<string, object> val = ((dict != null) ? new Dictionary<string, object>((IDictionary<string, object>)(object)dict) : new Dictionary<string, object>());
if (arguments != null)
{
for (int i = 0; i < arguments.Length; i++)
{
ValueTuple<string, object> val2 = arguments[i];
string item = val2.Item1;
object item2 = val2.Item2;
val[item] = item2;
}
}
StaticLocaleProvider localeProvider = _localeProvider;
object obj;
if (localeProvider == null)
{
obj = null;
}
else
{
LocaleResource asset = ((AssetProvider<LocaleResource>)(object)localeProvider).Asset;
obj = ((asset != null) ? asset.Format(key, val, false) : null);
}
string text = (string)obj;
if (!string.IsNullOrWhiteSpace(format))
{
text = string.Format(format, (object)text);
}
return text;
}
public static string GetFormattedLocaleString(this string key)
{
return key.GetFormattedLocaleString((string)null, (Dictionary<string, object>)null, (ValueTuple<string, object>[])null);
}
public static string GetFormattedLocaleString(this string key, string format)
{
return key.GetFormattedLocaleString(format, (Dictionary<string, object>)null, (ValueTuple<string, object>[])null);
}
public static string GetFormattedLocaleString(this string key, string argName, object argField)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return key.GetFormattedLocaleString(null, null, new ValueTuple<string, object>[1]
{
new ValueTuple<string, object>(argName, argField)
});
}
public static string GetFormattedLocaleString(this string key, string format, string argName, object argField)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return key.GetFormattedLocaleString(format, null, new ValueTuple<string, object>[1]
{
new ValueTuple<string, object>(argName, argField)
});
}
public static string GetFormattedLocaleString(this string key, params ValueTuple<string, object>[] arguments)
{
return key.GetFormattedLocaleString(null, null, arguments);
}
public static string GetFormattedLocaleString(this string key, string format, params ValueTuple<string, object>[] arguments)
{
return key.GetFormattedLocaleString(format, null, arguments);
}
public static LocaleString T(this string str, string argName, object argField)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
return LocaleHelper.AsLocaleKey(str, (string)null, new ValueTuple<string, object>[1]
{
new ValueTuple<string, object>(argName, argField)
});
}
public static LocaleString T(this string str, string format, string argName, object argField)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
return LocaleHelper.AsLocaleKey(str, format, new ValueTuple<string, object>[1]
{
new ValueTuple<string, object>(argName, argField)
});
}
public static LocaleString T(this string str, params ValueTuple<string, object>[] arguments)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return LocaleHelper.AsLocaleKey(str, (string)null, arguments);
}
public static LocaleString T(this string str, string format, params ValueTuple<string, object>[] arguments)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return LocaleHelper.AsLocaleKey(str, format, arguments);
}
public static LocaleString T(this string str, bool continuous, Dictionary<string, object> arguments = null)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return new LocaleString(str, (string)null, true, continuous, arguments);
}
public static LocaleString T(this string str, string format = null, bool continuous = true, Dictionary<string, object> arguments = null)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return new LocaleString(str, format, true, continuous, arguments);
}
}
[ResonitePlugin("ResoniteModding.BepisLocaleLoader", "Bepis Locale Loader", "1.2.0", "ResoniteModding", "https://github.com/ResoniteModding/BepisLocaleLoader")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
[StructLayout(3)]
private struct <<Load>b__1_0>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncVoidMethodBuilder <>t__builder;
private TaskAwaiter <>u__1;
private void MoveNext()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
try
{
TaskAwaiter awaiter;
if (num != 0)
{
awaiter = global::System.Threading.Tasks.Task.Delay(5000).GetAwaiter();
if (!((TaskAwaiter)(ref awaiter)).IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
((AsyncVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter, <<Load>b__1_0>d>(ref awaiter, ref this);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter);
num = (<>1__state = -1);
}
((TaskAwaiter)(ref awaiter)).GetResult();
if (((BaseChainloader<BasePlugin>)(object)NetChainloader.Instance).Plugins.Count > 0)
{
CollectionExtensions.Do<PluginInfo>((global::System.Collections.Generic.IEnumerable<PluginInfo>)((BaseChainloader<BasePlugin>)(object)NetChainloader.Instance).Plugins.Values, (Action<PluginInfo>)LocaleLoader.AddLocaleFromPlugin);
}
}
catch (global::System.Exception exception)
{
<>1__state = -2;
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetException(exception);
return;
}
<>1__state = -2;
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetResult();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
}
}
public static readonly <>c <>9 = new <>c();
public static Action <>9__1_0;
[AsyncStateMachine(typeof(<<Load>b__1_0>d))]
internal void <Load>b__1_0()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
<<Load>b__1_0>d <<Load>b__1_0>d = default(<<Load>b__1_0>d);
<<Load>b__1_0>d.<>t__builder = AsyncVoidMethodBuilder.Create();
<<Load>b__1_0>d.<>1__state = -1;
((AsyncVoidMethodBuilder)(ref <<Load>b__1_0>d.<>t__builder)).Start<<<Load>b__1_0>d>(ref <<Load>b__1_0>d);
}
}
internal static ManualLogSource Log;
public override void Load()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
object obj = <>c.<>9__1_0;
if (obj == null)
{
Action val = [AsyncStateMachine(typeof(<>c.<<Load>b__1_0>d))] () =>
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
<>c.<<Load>b__1_0>d <<Load>b__1_0>d = default(<>c.<<Load>b__1_0>d);
<<Load>b__1_0>d.<>t__builder = AsyncVoidMethodBuilder.Create();
<<Load>b__1_0>d.<>1__state = -1;
((AsyncVoidMethodBuilder)(ref <<Load>b__1_0>d.<>t__builder)).Start<<>c.<<Load>b__1_0>d>(ref <<Load>b__1_0>d);
};
<>c.<>9__1_0 = val;
obj = (object)val;
}
ResoniteHooks.OnEngineReady += (Action)obj;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("ResoniteModding.BepisLocaleLoader");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is loaded!");
}
log.LogInfo(val2);
}
}
public static class PluginMetadata
{
public const string GUID = "ResoniteModding.BepisLocaleLoader";
public const string NAME = "Bepis Locale Loader";
public const string VERSION = "1.2.0";
public const string AUTHORS = "ResoniteModding";
public const string REPOSITORY_URL = "https://github.com/ResoniteModding/BepisLocaleLoader";
}