Skip to content

Commit

Permalink
Language detect Pryaxis/TShock#2957
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Jun 13, 2023
1 parent 20b48dc commit 4d21ce1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/AltCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private bool HandleCommandCatched(Func<TShockAPI.TSPlayer, string, bool> orig, T
return orig(player, text);
}

private static MethodInfo _uncatchedHandleCommand = Utils.Method(() =>
private static readonly MethodInfo _uncatchedHandleCommand = Utils.Method(() =>
new Plugin(null!).HandleCommandUncatched(null!, null!, null!))!;
private static MethodInfo _catchedHandleCommand = Utils.Method(() =>
private static readonly MethodInfo _catchedHandleCommand = Utils.Method(() =>
new Plugin(null!).HandleCommandCatched(null!, null!, null!))!;

private bool Detour_Command_Run(Func<Command, string, bool, TSPlayer, List<string>, bool> orig, Command instance, string msg, bool silent, TSPlayer ply, List<string> parms)
Expand Down
2 changes: 1 addition & 1 deletion src/Backport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Run()
}
#endregion

private void Detour_Backport_2934(Action orig)
private void Detour_Backport_2934(Action orig)
{
orig();
if (!Terraria.Netplay.HasClients)
Expand Down
8 changes: 7 additions & 1 deletion src/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public class EnhancementsSettings
/// </summary>
public Optional<bool> SyncVersion = Optional.Default(false);

/// <summary>
/// Fix the broken default language detect.
/// <see href="https://github.com/Pryaxis/TShock/issues/2957" />
/// </summary>
public Optional<bool> DefaultLanguageDetect = Optional.Default(true);

/// <summary>
/// Action for TShock's update
/// </summary>
Expand Down Expand Up @@ -672,4 +678,4 @@ public Optional(T value)
}

public static implicit operator T(Optional<T> self) => self.Value;
}
}
5 changes: 5 additions & 0 deletions src/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public Plugin(Main game) : base(game)
typeof(Rests.Rest)
.GetMethod("OnRequest", _bfany)!,
this.ILHook_Mitigation_KeepRestAlive);

if (this.config.Enhancements.Value.DefaultLanguageDetect)
{
typeof(System.Globalization.CultureInfo).GetField("s_currentThreadUICulture", _bfany)?.SetValue(null, null);
}
}

private void LoadConfig(TSPlayer? initiator)
Expand Down

0 comments on commit 4d21ce1

Please sign in to comment.