Skip to content

Commit

Permalink
New translation and fixes
Browse files Browse the repository at this point in the history
- Added German translation
- Some refactoring to load languages properly
- Internal mod structure
  • Loading branch information
DingoDjango committed Mar 16, 2019
1 parent 797e7bf commit 8fc4ea0
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 28 deletions.
2 changes: 1 addition & 1 deletion QMods/StorageInfo/Languages/English.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ContainerEmpty": "empty",
"ContainerOneItem": "1 item (not full)",
"ContainerFull": "completely full",
"ContainerFull": "full",
"ContainerNonempty": "{0} items (not full)"
}
6 changes: 6 additions & 0 deletions QMods/StorageInfo/Languages/German.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ContainerEmpty": "Leer",
"ContainerOneItem": "1 Gegenstand",
"ContainerFull": "Voll",
"ContainerNonempty": "{0} Gegenstände"
}
Binary file modified QMods/StorageInfo/StorageInfo.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion QMods/StorageInfo/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "StorageInfo",
"DisplayName": "Storage Info",
"Author": "Dingo",
"Version": "1.0.1",
"Version": "1.0.2",
"Enable": true,
"Game": "Subnautica",
"AssemblyName": "StorageInfo.dll",
Expand Down
22 changes: 1 addition & 21 deletions Source/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
using System;
using System.Reflection;
using Harmony;
using UnityEngine;

namespace StorageInfo
{
public class Entry
{
private static void InitializeHarmony()
{
HarmonyInstance harmony = HarmonyInstance.Create("dingo.storageinfo");

#if DEBUG
HarmonyInstance.DEBUG = true;
#endif

MethodInfo containerOnHandHover = AccessTools.Method(typeof(StorageContainer), nameof(StorageContainer.OnHandHover));

// Removes original SetInteractText and injects SetCustomInteractText
harmony.Patch(
original: containerOnHandHover,
prefix: null,
postfix: null,
transpiler: new HarmonyMethod(typeof(HarmonyPatches), nameof(HarmonyPatches.Patch_StorageContainer_OnHandHover_Transpiler)));
}

public static void Initialize()
{
try
{
InitializeHarmony();
HarmonyPatches.InitializeHarmony();
}

catch (Exception ex)
Expand Down
33 changes: 32 additions & 1 deletion Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class HarmonyPatches
* IL_004E: ldsfld string [mscorlib]System.String::Empty
* IL_0053: callvirt instance void HandReticle::SetInteractText(string, string)
* Last IL index we snip, folding the IL nicely on itself ---> IL_0058: ldsfld class HandReticle HandReticle::main */
internal static IEnumerable<CodeInstruction> Patch_StorageContainer_OnHandHover_Transpiler(IEnumerable<CodeInstruction> instructions)
private static IEnumerable<CodeInstruction> Patch_StorageContainer_OnHandHover_Transpiler(IEnumerable<CodeInstruction> instructions)
{
FieldInfo handleReticleMain = AccessTools.Field(typeof(HandReticle), nameof(HandReticle.main));
MethodInfo setInteractText = AccessTools.Method(typeof(HandReticle), nameof(HandReticle.SetInteractText), new Type[] { typeof(string), typeof(string) });
Expand Down Expand Up @@ -94,6 +94,37 @@ internal static IEnumerable<CodeInstruction> Patch_StorageContainer_OnHandHover_
return instructions;
}

private static void Patch_SetCurrentLanguage_Postfix()
{
Translation.ClearCache();
}

internal static void InitializeHarmony()
{
HarmonyInstance harmony = HarmonyInstance.Create("dingo.storageinfo");

#if DEBUG
HarmonyInstance.DEBUG = true;
#endif

MethodInfo containerOnHandHover = AccessTools.Method(typeof(StorageContainer), nameof(StorageContainer.OnHandHover));
MethodInfo setLanguage = AccessTools.Method(typeof(Language), nameof(Language.SetCurrentLanguage));

// Remove original SetInteractText and inject SetCustomInteractText
harmony.Patch(
original: containerOnHandHover,
prefix: null,
postfix: null,
transpiler: new HarmonyMethod(typeof(HarmonyPatches), nameof(HarmonyPatches.Patch_StorageContainer_OnHandHover_Transpiler)));

// Reset language cache upon language change
harmony.Patch(
original: setLanguage,
prefix: null,
postfix: new HarmonyMethod(typeof(HarmonyPatches), nameof(HarmonyPatches.Patch_SetCurrentLanguage_Postfix)),
transpiler: null);
}

public static void SetCustomInteractText(StorageContainer _storage)
{
if (_storage != null)
Expand Down
2 changes: 1 addition & 1 deletion Source/Languages/English.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ContainerEmpty": "empty",
"ContainerOneItem": "1 item (not full)",
"ContainerFull": "completely full",
"ContainerFull": "full",
"ContainerNonempty": "{0} items (not full)"
}
6 changes: 6 additions & 0 deletions Source/Languages/German.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ContainerEmpty": "Leer",
"ContainerOneItem": "1 Gegenstand",
"ContainerFull": "Voll",
"ContainerNonempty": "{0} Gegenstände"
}
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
3 changes: 3 additions & 0 deletions Source/StorageInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<None Include="Languages\English.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Languages\German.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="mod.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
5 changes: 5 additions & 0 deletions Source/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,10 @@ internal static string FormatSingle(this string source, string arg0)

return basic;
}

internal static void ClearCache()
{
languageStrings.Clear();
}
}
}
2 changes: 1 addition & 1 deletion Source/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "StorageInfo",
"DisplayName": "Storage Info",
"Author": "Dingo",
"Version": "1.0.1",
"Version": "1.0.2",
"Enable": true,
"Game": "Subnautica",
"AssemblyName": "StorageInfo.dll",
Expand Down

0 comments on commit 8fc4ea0

Please sign in to comment.