Skip to content

Commit

Permalink
WIP: Enable partial trimming of the Arise.Client project.
Browse files Browse the repository at this point in the history
Closes #52.
  • Loading branch information
alexrp committed Jan 21, 2024
1 parent 6cae922 commit fad0bf0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/client/Launcher/Templates/WindowLocatorDataTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public bool Match(object? data)
return data is LauncherController;
}

[UnconditionalSuppressMessage("", "IL2026")]
public Control Build(object? param)
{
return Unsafe.As<Control>(
Expand Down
1 change: 1 addition & 0 deletions src/client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Arise.Client;

internal static class Program
{
[UnconditionalSuppressMessage("", "IL2026")]
private static Task Main(string[] args)
{
var context = InjectedProgramContext.Instance;
Expand Down
5 changes: 5 additions & 0 deletions src/client/client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
<AssemblyName>arise</AssemblyName>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<CopyDebugSymbolFilesFromPackages Condition="'$(DebugSymbols)' == 'true'">true</CopyDebugSymbolFilesFromPackages>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EventSourceSupport>false</EventSourceSupport>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<IsPublishable>true</IsPublishable>
<NullabilityInfoContextSupport>false</NullabilityInfoContextSupport>
<OutputType>WinExe</OutputType>
<PublishTrimmed>true</PublishTrimmed>
<RootNamespace>Arise.Client</RootNamespace>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<RuntimeIdentifiers />
<SelfContained>true</SelfContained>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<TrimmerRemoveSymbols Condition="'$(DebugSymbols)' != 'true'">true</TrimmerRemoveSymbols>
<TrimMode>partial</TrimMode>
<!-- This is unfortunately needed due to the patcher reference. -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/shared/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('$(MSBuildThisFile)', '$(MSBuildThisFileDirectory)..'))" />

<PropertyGroup>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions src/shared/game/Bridge/BridgeModuleActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Arise.Bridge;

public static class BridgeModuleActivator
{
[UnconditionalSuppressMessage("", "IL2026")]
[UnconditionalSuppressMessage("", "IL2072")]
public static BridgeModule Create(ReadOnlyMemory<byte> module)
{
using var stream = SlimMemoryStream.CreateReadOnly(module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ private AriseGamePacketSerializer()

protected override void GenerateDeserializer(Expression packet, Expression accessor)
{
[UnconditionalSuppressMessage("", "IL2072")]
void GenerateForObject(Expression @object)
{
[UnconditionalSuppressMessage("", "IL2060")]
void GenerateForValue(Type type, Action<Expression> handler)
{
Expression result;
Expand Down Expand Up @@ -119,8 +121,10 @@ void GenerateForValue(Type type, Action<Expression> handler)

protected override void GenerateSerializer(Expression packet, Expression accessor)
{
[UnconditionalSuppressMessage("", "IL2072")]
void GenerateForObject(Expression @object)
{
[UnconditionalSuppressMessage("", "IL2060")]
void GenerateForValue(Expression value)
{
var type = value.Type;
Expand Down
8 changes: 6 additions & 2 deletions src/shared/game/Net/Serialization/GamePacketSerializer`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ internal abstract class GamePacketSerializer<TCode, TPacket>

private int _variableCounter;

[UnconditionalSuppressMessage("", "IL2026")]
[UnconditionalSuppressMessage("", "IL2072")]
private protected GamePacketSerializer()
{
var creators = new Dictionary<TCode, Func<TPacket>>();
var deserializers = new Dictionary<TCode, Action<TPacket, GameStreamAccessor>>();
var serializers = new Dictionary<TCode, Action<TPacket, GameStreamAccessor>>();

[SuppressMessage("", "SA1134")]
Action<TPacket, GameStreamAccessor> CompileFunction(Type type, Action<Expression, Expression> generator)
{
return Lambda<Action<TPacket, GameStreamAccessor>>(ctx =>
return Lambda<Action<TPacket, GameStreamAccessor>>([UnconditionalSuppressMessage("", "IL2060")] (ctx) =>
{
var (packet, accessor) = ctx;
Expand Down Expand Up @@ -62,7 +65,8 @@ private protected GamePacketSerializer()
_serializers = serializers.ToFrozenDictionary();
}

protected static IEnumerable<PropertyInfo> EnumerateProperties(Type type)
protected static IEnumerable<PropertyInfo> EnumerateProperties(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
{
var isPacket = type.IsSubclassOf(typeof(GamePacket));

Expand Down
4 changes: 4 additions & 0 deletions src/shared/game/Net/Serialization/TeraGamePacketSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ private TeraGamePacketSerializer()

protected override void GenerateDeserializer(Expression packet, Expression accessor)
{
[UnconditionalSuppressMessage("", "IL2072")]
void GenerateForObject(Expression @object)
{
[UnconditionalSuppressMessage("", "IL2060")]
void GenerateForValue(Type type, Action<Expression> handler)
{
Expression result;
Expand Down Expand Up @@ -142,8 +144,10 @@ void GenerateForValue(Type type, Action<Expression> handler)

protected override void GenerateSerializer(Expression packet, Expression accessor)
{
[UnconditionalSuppressMessage("", "IL2072")]
void GenerateForObject(Expression @object)
{
[UnconditionalSuppressMessage("", "IL2060")]
void GenerateFirstPassForValue(Expression value, Action<ParameterExpression> handler)
{
var type = value.Type;
Expand Down
3 changes: 2 additions & 1 deletion src/shared/game/Net/Sessions/GameSessionDispatcher`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

namespace Arise.Net.Sessions;

public abstract class GameSessionDispatcher<TSession, THandler>
public abstract class GameSessionDispatcher<TSession, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] THandler>
where TSession : GameSession
where THandler : class
{
private static readonly MethodInfo _as = typeof(Unsafe).GetMethod("As", 1, [typeof(object)])!;

private readonly FrozenDictionary<Type, Action<TSession, GamePacket>> _handlers;

[UnconditionalSuppressMessage("", "IL2060")]
protected GameSessionDispatcher()
{
_handlers = typeof(THandler)
Expand Down

0 comments on commit fad0bf0

Please sign in to comment.