Skip to content

Commit

Permalink
Fix bugs introduced in fa3a0b2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Aug 27, 2023
1 parent fe9de75 commit 9efea46
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/server/world/Bridge/BridgeModuleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ReadOnlyMemory<byte> CreateModule(BridgeModuleKind kind, int seed)
{
_modules.Clear();

var serverKind = _hostEnvironment.IsDevelopment()
var clientKind = _hostEnvironment.IsDevelopment()
? BridgeModuleKind.Normal
: BridgeModuleKind.Hardened;

Expand All @@ -100,7 +100,7 @@ ReadOnlyMemory<byte> CreateModule(BridgeModuleKind kind, int seed)

_modules.Add(
(BridgeModuleActivator.Create(CreateModule(BridgeModuleKind.Normal, seed)),
CreateModule(serverKind, seed)));
CreateModule(clientKind, seed)));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/server/world/Bridge/BridgeModulePatchingPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ void PatchPacketCodeSequences<T>()
insns.Add(Instruction.Create(OpCodes.Ret));
}

switch ((method.DeclaringType.Name.String, method.Name.String))
switch (((string)method.DeclaringType.Name, (string)method.Name))
{
case ("GameProtection", "Initialize") or
("PatchableBridgeProtectionComponent", "Start") or
("PatchableBridgeProtectionComponent", "Stop") when kind == BridgeModuleKind.Normal:
case ("GameProtection", "Initialize") when kind == BridgeModuleKind.Normal:
{
insns.Clear();
insns.Add(Instruction.Create(OpCodes.Ret));
Expand Down
13 changes: 0 additions & 13 deletions src/shared/module/ModuleInitializer.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/shared/module/PatchableBridgeModule.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Arise.Bridge.Protection;

namespace Arise.Bridge;

public sealed class PatchableBridgeModule : BridgeModule
Expand All @@ -9,4 +11,9 @@ public sealed class PatchableBridgeModule : BridgeModule
public override PatchableBridgeProtocolComponent Protocol { get; } = new();

public override PatchableBridgeWatchdogComponent Watchdog { get; } = new();

public PatchableBridgeModule()
{
GameProtection.Initialize();
}
}
15 changes: 3 additions & 12 deletions src/shared/module/PatchableBridgeProtectionComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@ namespace Arise.Bridge;

public sealed class PatchableBridgeProtectionComponent : BridgeProtectionComponent
{
private readonly IEnumerable<GameProtectionTask> _tasks = new GameProtectionTask[]
{
new CodeChecksumTask(),
new DebuggerDetectionTask(),
};
private readonly Queue<GameProtectionTask> _tasks = new();

[Obfuscation]
public override void Start()
{
// This method body is erased by the server's BridgeModuleGenerator for module instances that run on the server
// and for module instances running on the client in development scenarios.
_tasks.Enqueue(new CodeChecksumTask());
_tasks.Enqueue(new DebuggerDetectionTask());

foreach (var task in _tasks)
task.Start();
}

[Obfuscation]
public override void Stop()
{
// This method body is erased by the server's BridgeModuleGenerator for module instances that run on the server
// and for module instances running on the client in development scenarios.

foreach (var task in _tasks.Reverse())
task.Stop();
}
Expand Down
5 changes: 5 additions & 0 deletions src/shared/module/Protection/GameProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ namespace Arise.Bridge.Protection;

internal static class GameProtection
{
private static int _initialized;

[Obfuscation]
public static void Initialize()
{
// This method body is erased by the server's BridgeModuleGenerator for module instances that run on the server
// and for module instances running on the client in development scenarios.

if (Interlocked.Exchange(ref _initialized, 1) == 1)
return;

var culture = CultureInfo.InvariantCulture;

if (DateTime.UtcNow - DateTime.Parse(GetIssueTime(), culture) > TimeSpan.Parse(GetValidDuration(), culture))
Expand Down
2 changes: 2 additions & 0 deletions src/shared/module/Protection/GameProtectionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private static int GetCheckInterval()

private async Task PerformCheckAsync(CancellationToken cancellationToken)
{
await _ready.Task.ConfigureAwait(false);

Initialize();

while (!cancellationToken.IsCancellationRequested)
Expand Down

0 comments on commit 9efea46

Please sign in to comment.