Skip to content

Commit

Permalink
Allow ignore journey mode, set encoding to default for legacy Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Nov 27, 2023
1 parent eecd567 commit e97c79e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
9 changes: 7 additions & 2 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public record class VanillaMode
TShockAPI.Permissions.sendemoji,
DefinedConsts.Permission.Ping
});
public Optional<bool> AllowJourney = Optional.Default(false);
public Optional<bool> AllowJourneyPowers = Optional.Default(false);
public Optional<bool> IgnoreAntiCheat = Optional.Default(false);
public Optional<VanillaAntiCheat> AntiCheat = Optional.Default(new VanillaAntiCheat(), true);

Expand Down Expand Up @@ -630,7 +630,12 @@ public record class MitigationSettings
/// Default: -1, use Encoding.Default when Win32NT && Version <= 10
/// </para>
/// </summary>
public Optional<int> UseDefaultEncoding = Optional.Default(Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major < 10 ? -1 : 65001);
public Optional<int> UseDefaultEncoding = Optional.Default(Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major < 10 ? -1 : 0);

/// <summary>
/// Allow journey and non-journey players to join the server.
/// </summary>
public Optional<bool> AllowCrossJourney = Optional.Default(false);

public enum DisabledDamageAction
{
Expand Down
9 changes: 9 additions & 0 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ private void OTHook_Mitigation_GetData(object? sender, OTAPI.Hooks.MessageBuffer

switch (args.PacketId)
{
case (int) PacketTypes.PlayerInfo when mitigation.AllowCrossJourney:
{
// FIXME: Version specific, might be changed in the future
if (Terraria.Main.GameModeInfo.IsJourneyMode == ((args.Instance.readBuffer[args.Length - 1] & 0b1000) == 0))
{
args.Instance.readBuffer[args.Length - 1] ^= 0b1000;
}
break;
}
case (int) PacketTypes.PlayerSlot:
{
var index = args.Instance.whoAmI;
Expand Down
18 changes: 10 additions & 8 deletions Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public Plugin(Main game) : base(game)
AppDomain.CurrentDomain.FirstChanceException += this.FirstChanceExceptionHandler;
this.Order = int.MinValue;
this.LoadConfig(Utils.ConsolePlayer.Instance);

if (this.config.Enhancements.Value.DefaultLanguageDetect)
{
this.ResetGameLocale();
}

{
var mitigation = this.config.Mitigation.Value;
if (!mitigation.DisableAllMitigation)
Expand All @@ -38,17 +44,18 @@ public Plugin(Main game) : base(game)
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
if (encoding == -1)
{
Console.OutputEncoding = System.Text.Encoding.Default;
Console.WriteLine($"Console encoding set to default ({Console.OutputEncoding})");
Console.OutputEncoding = System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ANSICodePage);
Console.WriteLine($"Console encoding set to default ({Console.OutputEncoding.EncodingName})");
}
else
{
Console.OutputEncoding = System.Text.Encoding.GetEncoding(encoding);
Console.WriteLine($"Console encoding set to {Console.OutputEncoding}");
Console.WriteLine($"Console encoding set to {Console.OutputEncoding.EncodingName}");
}
}
}
}

this.Detour(
nameof(this.Detour_UpdateCheckAsync),
typeof(UpdateManager)
Expand Down Expand Up @@ -103,11 +110,6 @@ public Plugin(Main game) : base(game)
.GetMethod("AttemptConfigUpgrade", _bfany),
this.Detour_Mitigation_ConfigUpdate
);

if (this.config.Enhancements.Value.DefaultLanguageDetect)
{
this.ResetGameLocale();
}
}

public event Action<Plugin>? OnConfigLoad;
Expand Down
2 changes: 1 addition & 1 deletion Core/Vanilla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private void VanillaSetup()
}

var addperm = TShockAPI.TShock.Groups.AddPermissions(Misc.VanillaGroup, vanillaMode.Permissions);
if (vanillaMode.AllowJourney)
if (vanillaMode.AllowJourneyPowers)
{
addperm += TShockAPI.TShock.Groups.AddPermissions(Misc.VanillaGroup, new List<string> { "tshock.journey.*" });
}
Expand Down

0 comments on commit e97c79e

Please sign in to comment.