mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 20:53:28 +08:00
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<AssemblyName>CompressSave</AssemblyName>
|
||||
<BepInExPluginGuid>org.soardev.compresssave</BepInExPluginGuid>
|
||||
<Description>DSP MOD - CompressSave</Description>
|
||||
<Version>1.3.4</Version>
|
||||
<Version>1.3.5</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CompressSave;
|
||||
|
||||
public static class I18N
|
||||
{
|
||||
private static bool _initialized;
|
||||
|
||||
public static Action OnInitialized;
|
||||
private static bool _dirty;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
@@ -17,88 +13,116 @@ public static class I18N
|
||||
}
|
||||
|
||||
public static bool Initialized() => _initialized;
|
||||
private struct Translation
|
||||
{
|
||||
public string Key;
|
||||
public string English;
|
||||
public string Chinese;
|
||||
}
|
||||
private static readonly List<Translation> StringsToAdd = [];
|
||||
private static readonly List<Tuple<string, string, int>> Keys = [];
|
||||
private static readonly Dictionary<int, List<string>> Strings = [];
|
||||
|
||||
public static void Add(string key, string enus, string zhcn = null)
|
||||
{
|
||||
if (zhcn == null && key == enus) return;
|
||||
var strProto = new Translation
|
||||
Keys.Add(Tuple.Create(key, enus, -1));
|
||||
if (Strings.TryGetValue(2052, out var zhcnList))
|
||||
{
|
||||
Key = key,
|
||||
English = enus,
|
||||
Chinese = string.IsNullOrEmpty(zhcn) ? enus : zhcn
|
||||
};
|
||||
StringsToAdd.Add(strProto);
|
||||
zhcnList.Add(string.IsNullOrEmpty(zhcn) ? enus : zhcn);
|
||||
}
|
||||
else
|
||||
{
|
||||
Strings.Add(2052, [string.IsNullOrEmpty(zhcn) ? enus : zhcn]);
|
||||
}
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
private static void ApplyIndexers()
|
||||
{
|
||||
var indexer = Localization.namesIndexer;
|
||||
var index = indexer.Count;
|
||||
var len = Keys.Count;
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var (key, def, value) = Keys[i];
|
||||
if (value >= 0) continue;
|
||||
if (indexer.TryGetValue(key, out var idx))
|
||||
{
|
||||
Keys[i] = Tuple.Create(key, def, idx);
|
||||
continue;
|
||||
}
|
||||
indexer[key] = index;
|
||||
Keys[i] = Tuple.Create(key, def, index);
|
||||
index++;
|
||||
}
|
||||
_dirty = false;
|
||||
var strings = Localization.strings;
|
||||
if (strings == null) return;
|
||||
var len2 = strings.Length;
|
||||
for (var i = 0; i < len2; i++)
|
||||
{
|
||||
ApplyLanguage(i);
|
||||
if (i != Localization.currentLanguageIndex) continue;
|
||||
Localization.currentStrings = Localization.strings[i];
|
||||
Localization.currentFloats = Localization.floats[i];
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyLanguage(int index)
|
||||
{
|
||||
var indexerLength = Localization.namesIndexer.Count;
|
||||
var strs = Localization.strings[index];
|
||||
if (strs == null) return;
|
||||
if (strs.Length < indexerLength)
|
||||
{
|
||||
var newStrs = new string[indexerLength];
|
||||
Array.Copy(strs, newStrs, strs.Length);
|
||||
strs = newStrs;
|
||||
Localization.strings[index] = strs;
|
||||
}
|
||||
var floats = Localization.floats[index];
|
||||
if (floats != null)
|
||||
{
|
||||
if (floats.Length < indexerLength)
|
||||
{
|
||||
var newFloats = new float[indexerLength];
|
||||
Array.Copy(floats, newFloats, floats.Length);
|
||||
floats = newFloats;
|
||||
Localization.floats[index] = floats;
|
||||
}
|
||||
}
|
||||
|
||||
var keyLength = Keys.Count;
|
||||
if (Strings.TryGetValue(Localization.Languages[index].lcId, out var list))
|
||||
{
|
||||
for (var j = 0; j < keyLength; j++)
|
||||
{
|
||||
strs[Keys[j].Item3] = list[j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var j = 0; j < keyLength; j++)
|
||||
{
|
||||
strs[Keys[j].Item3] = Keys[j].Item2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Apply()
|
||||
{
|
||||
if (!_initialized) return;
|
||||
var indexer = Localization.namesIndexer;
|
||||
var enIdx = -1;
|
||||
var zhIdx = -1;
|
||||
var llen = 0;
|
||||
for (var i = 0; i < Localization.strings.Length; i++)
|
||||
{
|
||||
switch (Localization.Languages[i].lcId)
|
||||
{
|
||||
case Localization.LCID_ENUS:
|
||||
if (!Localization.LanguageLoaded(i) && Localization.Loaded)
|
||||
{
|
||||
Localization.LoadLanguage(i);
|
||||
}
|
||||
enIdx = i;
|
||||
break;
|
||||
case Localization.LCID_ZHCN:
|
||||
if (!Localization.LanguageLoaded(i) && Localization.Loaded)
|
||||
{
|
||||
Localization.LoadLanguage(i);
|
||||
}
|
||||
zhIdx = i;
|
||||
llen = Localization.strings[i].Length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var enus = new string[StringsToAdd.Count];
|
||||
var zhcn = new string[StringsToAdd.Count];
|
||||
for (var i = 0; i < StringsToAdd.Count; i++)
|
||||
{
|
||||
var str = StringsToAdd[i];
|
||||
enus[i] = str.English;
|
||||
zhcn[i] = str.Chinese;
|
||||
indexer[str.Key] = llen + i;
|
||||
}
|
||||
|
||||
Localization.strings[enIdx] = Localization.strings[enIdx].Concat(enus).ToArray();
|
||||
if (enIdx == Localization.currentLanguageIndex)
|
||||
{
|
||||
Localization.currentStrings = Localization.strings[enIdx];
|
||||
}
|
||||
Localization.strings[zhIdx] = Localization.strings[zhIdx].Concat(zhcn).ToArray();
|
||||
if (zhIdx == Localization.currentLanguageIndex)
|
||||
{
|
||||
Localization.currentStrings = Localization.strings[zhIdx];
|
||||
}
|
||||
StringsToAdd.Clear();
|
||||
if (Keys.Count == 0) return;
|
||||
if (!_dirty) return;
|
||||
ApplyIndexers();
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(Localization), nameof(Localization.LoadSettings))]
|
||||
private static void Localization_LoadSettings_Postfix()
|
||||
{
|
||||
if (_initialized) return;
|
||||
_initialized = true;
|
||||
if (StringsToAdd.Count == 0)
|
||||
{
|
||||
OnInitialized?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
Apply();
|
||||
OnInitialized?.Invoke();
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(Localization), nameof(Localization.LoadLanguage))]
|
||||
private static void Localization_LoadLanguage_Postfix(int index)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
ApplyLanguage(index);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.3.5
|
||||
* Fix a crash issue on choosing language other than English and Chinese.
|
||||
|
||||
### 1.3.4
|
||||
* Support for game version 0.10.28.20759.
|
||||
|
||||
@@ -140,6 +143,9 @@
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 1.3.5
|
||||
* 修复了选择英文和中文以外的语言时的崩溃问题。
|
||||
|
||||
### 1.3.4
|
||||
* 支持游戏版本 0.10.28.20759。
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "CompressSave",
|
||||
"version_number": "1.3.4",
|
||||
"version_number": "1.3.5",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/CompressSave",
|
||||
"description": "Compress game saves to reduce space use and boost save speed / 压缩游戏存档以降低空间使用并提升保存速度",
|
||||
"dependencies": ["xiaoye97-BepInEx-5.4.17"]
|
||||
|
||||
Reference in New Issue
Block a user