Skip to content

Commit

Permalink
1.1.0.0 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Zgoly authored Nov 23, 2024
1 parent 5f308c6 commit 6c3bc2c
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 255 deletions.
12 changes: 12 additions & 0 deletions MultiBloxy/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public class Config
private static readonly string ConfigFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.xml");
private static XDocument configDocument;

// Static constructor to initialize the config document
static Config()
{
Load();
}

// Loads the configuration from the config file
public static void Load()
{
if (File.Exists(ConfigFilePath))
Expand All @@ -26,6 +28,7 @@ public static void Load()
}
}

// Saves the configuration to the config file
public static void Save()
{
if (!configDocument.Root.HasElements)
Expand All @@ -41,6 +44,7 @@ public static void Save()
}
}

// Sets a configuration value for a given key
public static void Set(string key, object value)
{
var element = configDocument.Root.Element(key);
Expand All @@ -55,6 +59,7 @@ public static void Set(string key, object value)
Save();
}

// Gets a configuration value for a given key, with default value
public static T Get<T>(string key, T defaultValue = default)
{
var element = configDocument.Root.Element(key);
Expand All @@ -65,6 +70,13 @@ public static T Get<T>(string key, T defaultValue = default)
return defaultValue;
}

// Checks if a configuration key exists
public static bool Has(string key)
{
return configDocument.Root.Element(key) != null;
}

// Removes a configuration key
public static void Remove(string key)
{
var element = configDocument.Root.Element(key);
Expand Down
9 changes: 4 additions & 5 deletions MultiBloxy/HandleCloser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void CloseAllHandles()
while (true)
{
// Query system information for handles
uint status = NtQuerySystemInformation(SystemHandleInformation, buffer, size, out uint returnLength);
uint status = NtQuerySystemInformation(SystemHandleInformation, buffer, size, out uint _);

// If the buffer is too small, double its size and retry
if (status == 0xC0000004)
Expand Down Expand Up @@ -113,9 +113,8 @@ public static void CloseAllHandles()
continue;
}

IntPtr dupHandle = IntPtr.Zero;
// Duplicate the handle to the current process
bool success = DuplicateHandle(processHandle, new IntPtr(handleInfo.Handle), GetCurrentProcess(), out dupHandle, 0, false, DUPLICATE_SAME_ACCESS);
bool success = DuplicateHandle(processHandle, new IntPtr(handleInfo.Handle), GetCurrentProcess(), out IntPtr dupHandle, 0, false, DUPLICATE_SAME_ACCESS);
if (!success)
{
// Close the process handle and move to the next handle if duplication fails
Expand All @@ -128,7 +127,7 @@ public static void CloseAllHandles()
IntPtr nameBuffer = Marshal.AllocHGlobal((int)bufferSize);

// Query the object name information for the duplicated handle
uint status = NtQueryObject(dupHandle, ObjectNameInformation, nameBuffer, bufferSize, out uint returnLength);
uint status = NtQueryObject(dupHandle, ObjectNameInformation, nameBuffer, bufferSize, out uint _);

if (status != 0)
{
Expand All @@ -149,7 +148,7 @@ public static void CloseAllHandles()
if (name.Contains("ROBLOX_singletonEvent"))
{
// Close the handle if it matches the target name
bool success2 = DuplicateHandle(processHandle, new IntPtr(handleInfo.Handle), IntPtr.Zero, out _, 0, false, DUPLICATE_CLOSE_SOURCE);
DuplicateHandle(processHandle, new IntPtr(handleInfo.Handle), IntPtr.Zero, out _, 0, false, DUPLICATE_CLOSE_SOURCE);
}
}

Expand Down
56 changes: 32 additions & 24 deletions MultiBloxy/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ namespace MultiBloxy
{
public class Localization
{
private readonly Dictionary<string, Dictionary<string, string>> _translations;
private string _currentLocale;
public readonly Dictionary<string, Dictionary<string, string>> Locales;
public string CurrentLocale;

// Constructor to initialize the Localization class
public Localization()
{
_translations = new Dictionary<string, Dictionary<string, string>>();
_currentLocale = CultureInfo.CurrentCulture.Name;
LoadTranslations();
Locales = new Dictionary<string, Dictionary<string, string>>();
AutoCurrentLocale();
LoadLocales();
}

private void LoadTranslations()
// Automatically sets the current locale based on the system's culture settings
public void AutoCurrentLocale()
{
_translations["en"] = new Dictionary<string, string>
CurrentLocale = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
}

// Loads predefined locales into the Locales dictionary
private void LoadLocales()
{
Locales["en"] = new Dictionary<string, string>
{
{ "ContextMenu.StatusMenuItem.Running", "Status: Running" },
{ "ContextMenu.StatusMenuItem.Paused", "Status: Paused" },
Expand All @@ -31,6 +39,8 @@ private void LoadTranslations()
{ "ContextMenu.SettingsMenuItem.Settings", "Settings" },
{ "ContextMenu.SettingsMenuItem.PauseOnLaunchMenuItem.PauseOnLaunch", "Pause on Launch" },
{ "ContextMenu.SettingsMenuItem.ResetRememberedMenuItem.ResetRemembered", "Reset Remembered Options" },
{ "ContextMenu.SettingsMenuItem.LanguageMenuItem.Language", "Language" },
{ "ContextMenu.SettingsMenuItem.LanguageMenuItem.AutoDetectMenuItem.AutoDetect", "Auto Detect" },
{ "ContextMenu.ExitMenuItem.Exit", "Exit" },
{ "Error.Mutex.Caption", "Failed to Create Mutex" },
{ "Error.Mutex.Message", "An error occurred while creating the Mutex. This likely happened because when {0} was launched, Roblox was already running and had registered its handle. You can do the following:" },
Expand All @@ -44,7 +54,7 @@ private void LoadTranslations()
{ "Error.Singleton.Message", "{0} is already running. Try looking in the system tray." }
};

_translations["ru"] = new Dictionary<string, string>
Locales["ru"] = new Dictionary<string, string>
{
{ "ContextMenu.StatusMenuItem.Running", "Статус: Работает" },
{ "ContextMenu.StatusMenuItem.Paused", "Статус: Приостановлено" },
Expand All @@ -58,6 +68,8 @@ private void LoadTranslations()
{ "ContextMenu.SettingsMenuItem.Settings", "Настройки" },
{ "ContextMenu.SettingsMenuItem.PauseOnLaunchMenuItem.PauseOnLaunch", "Приостановить при запуске" },
{ "ContextMenu.SettingsMenuItem.ResetRememberedMenuItem.ResetRemembered", "Сбросить запомненные параметры" },
{ "ContextMenu.SettingsMenuItem.LanguageMenuItem.Language", "Язык" },
{ "ContextMenu.SettingsMenuItem.LanguageMenuItem.AutoDetectMenuItem.AutoDetect", "Определять автоматически" },
{ "ContextMenu.ExitMenuItem.Exit", "Выход" },
{ "Error.Mutex.Caption", "Не удалось создать Mutex" },
{ "Error.Mutex.Message", "Произошла ошибка при создании Mutex. Скорее всего, это связано с тем, что при запуске {0} Roblox уже был запущен и успел зарегистрировать свой дескриптор. Вы можете сделать следующее:" },
Expand All @@ -72,33 +84,29 @@ private void LoadTranslations()
};
}

public string GetTranslation(string key)
// Retrieves the localized string for the given key
public string GetLocaleString(string key)
{
string locale = GetLocaleWithoutRegion(_currentLocale);

if (_translations.ContainsKey(locale) && _translations[locale].ContainsKey(key))
if (Locales.ContainsKey(CurrentLocale) && Locales[CurrentLocale].ContainsKey(key))
{
return _translations[locale][key];
return Locales[CurrentLocale][key];
}

// Fallback to English if the translation is not found
if (_translations.ContainsKey("en") && _translations["en"].ContainsKey(key))
// Fallback to English if the locale string is not found
if (Locales.ContainsKey("en") && Locales["en"].ContainsKey(key))
{
return _translations["en"][key];
return Locales["en"][key];
}

// Fallback to the key if the translation is not found
// Fallback to the key if the locale string is not found
return key;
}

private string GetLocaleWithoutRegion(string locale)
// Returns a stylized name for the given locale
public string GetStylizedLocaleName(string locale)
{
int index = locale.IndexOf('-');
if (index != -1)
{
return locale.Substring(0, index);
}
return locale;
CultureInfo cultureInfo = new CultureInfo(locale);
return $"{cultureInfo.DisplayName} ({cultureInfo.NativeName})";
}
}
}
7 changes: 6 additions & 1 deletion MultiBloxy/MultiBloxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\MultiBloxy.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
Expand All @@ -43,10 +46,12 @@
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="HandleCloser.cs" />
<Compile Include="HandleCloser.cs" />
<Compile Include="Localization.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\**\*.*" Exclude="Resources\MultiBloxy.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 6c3bc2c

Please sign in to comment.