1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-11 10:33:48 +08:00
This commit is contained in:
2023-09-07 20:55:34 +08:00
parent c974d70564
commit 668e7a01be
9 changed files with 419 additions and 169 deletions

View File

@@ -6,38 +6,39 @@ namespace UniverseGenTweaks;
public class I18N
{
private static bool _initialized;
public static void Init()
{
Harmony.CreateAndPatchAll(typeof(I18N));
}
private static int _nextID = 0;
private static int _nextID = 1;
private static readonly List<StringProto> StringsToAdd = new();
public static void Add(string key, string enus, string zhcn = null, string frfr = null)
{
var strings = LDB._strings;
while (_nextID <= 12000)
{
if (!strings.dataIndices.ContainsKey(_nextID))
{
break;
}
_nextID++;
}
var strProto = new StringProto
{
Name = key,
ID = _nextID,
SID = "",
ENUS = enus,
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
};
StringsToAdd.Add(strProto);
_nextID++;
if (_initialized)
{
var index = strings.dataArray.Length;
strProto.ID = GetNextID();
strings.dataArray = strings.dataArray.Append(strProto).ToArray();
strings.dataIndices[strProto.ID] = index;
strings.nameIndices[strProto.Name] = index;
}
else
{
StringsToAdd.Add(strProto);
}
}
private static bool _initialized = false;
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
{
@@ -54,8 +55,28 @@ public class I18N
var newIndex = strings.dataArray.Length;
for (; index < newIndex; index++)
{
strings.dataIndices[strings.dataArray[index].ID] = index;
var strProto = strings.dataArray[index];
strProto.ID = GetNextID();
strings.dataIndices[strProto.ID] = index;
strings.nameIndices[strings.dataArray[index].Name] = index;
}
}
private static int GetNextID()
{
var strings = LDB._strings;
while (_nextID <= 12000)
{
if (!strings.dataIndices.ContainsKey(_nextID))
{
break;
}
_nextID++;
}
var result = _nextID;
_nextID++;
return result;
}
}