Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/ACE.Common/ACE.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14</LangVersion>
<IsAotCompatible>true</IsAotCompatible>
<Platforms>AnyCPU</Platforms>
<Authors>ACEmulator Contributors</Authors>
<RepositoryType>git</RepositoryType>
Expand Down
12 changes: 12 additions & 0 deletions Source/ACE.Common/ConfigJsonContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace ACE.Common
{
/// <summary>
/// Source-generated JSON metadata for Config.js, so that ConfigManager can read it in a trimmed or native AOT app.
/// </summary>
[JsonSerializable(typeof(MasterConfiguration))]
internal partial class ConfigJsonContext : JsonSerializerContext
{
}
}
14 changes: 7 additions & 7 deletions Source/ACE.Common/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ public static void Initialize(string path = @"Config.js")
if (!File.Exists(pathToUse))
{
// File not found in Environment.CurrentDirectory
// Lets try the ExecutingAssembly Location
var executingAssemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
// Lets try the application's directory. (Assembly.Location is empty in a single-file or native AOT app.)
directoryName = AppContext.BaseDirectory;

directoryName = Path.GetDirectoryName(executingAssemblyLocation);

if (directoryName != null)
pathToUse = Path.Combine(directoryName, fileName);
pathToUse = Path.Combine(directoryName, fileName);
}
}
else
Expand All @@ -61,7 +58,10 @@ public static void Initialize(string path = @"Config.js")

var fileText = File.ReadAllText(pathToUse);

Config = JsonSerializer.Deserialize<MasterConfiguration>(fileText, SerializerOptions);
// The source-generated metadata reads the file without reflection, with the settings of SerializerOptions
var context = new ConfigJsonContext(new JsonSerializerOptions(SerializerOptions));

Config = JsonSerializer.Deserialize(fileText, context.MasterConfiguration);
}
catch (Exception exception)
{
Expand Down
5 changes: 4 additions & 1 deletion Source/ACE.Common/Extensions/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public static class EnumHelper
/// </summary>
public static List<Enum> GetFlags(this Enum e)
{
return Enum.GetValues(e.GetType()).Cast<Enum>().Where(e.HasFlag).ToList();
var type = e.GetType();

// Enum.GetValues(Type) has to create an array of the enum type at runtime, which native AOT cannot always do
return Enum.GetValuesAsUnderlyingType(type).Cast<object>().Select(v => (Enum)Enum.ToObject(type, v)).Where(e.HasFlag).ToList();
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Source/ACE.DatLoader/ACE.DatLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14</LangVersion>
<IsAotCompatible>true</IsAotCompatible>
<Platforms>AnyCPU</Platforms>
<Authors>ACEmulator Contributors</Authors>
<RepositoryType>git</RepositoryType>
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.DatLoader/DatDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ACE.DatLoader
{
public class DatDatabase
{
private static readonly ILogger log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILogger log = LogManager.GetLogger(typeof(DatDatabase));

private const uint DAT_HEADER_OFFSET = 0x140;

Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.DatLoader/DatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ACE.DatLoader
{
public static class DatManager
{
private static readonly ILogger log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILogger log = LogManager.GetLogger(typeof(DatManager));

private static string datFile;

Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.DatLoader/Entity/AnimationHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ACE.DatLoader.Entity
{
public class AnimationHook : IUnpackable
{
private static readonly ILogger log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILogger log = LogManager.GetLogger(typeof(AnimationHook));

public AnimationHookType HookType { get; private set; }
public AnimationHookDir Direction { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions Source/ACE.Entity/ACE.Entity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14</LangVersion>
<IsAotCompatible>true</IsAotCompatible>
<Platforms>AnyCPU</Platforms>
<Authors>ACEmulator Contributors</Authors>
<RepositoryType>git</RepositoryType>
Expand Down
3 changes: 3 additions & 0 deletions Source/ACE.Entity/Enum/AttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Diagnostics.CodeAnalysis;

namespace ACE.Entity.Enum
{
public static class AttributeExtensions
{
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Trimming never removes the literal fields of an enum.")]
public static T GetAttributeOfType<T>(this System.Enum enumVal) where T : System.Attribute
{
var type = enumVal.GetType();
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.Entity/Enum/CharacterOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static class CharacterOptionExtensions

static CharacterOptionExtensions()
{
var vals = System.Enum.GetValues(typeof(CharacterOption)).Cast<CharacterOption>();
var vals = System.Enum.GetValues<CharacterOption>();
CharacterOptions1Attributes = vals.ToDictionary(o => o, o => o.GetAttributeOfType<CharacterOptions1Attribute>());
CharacterOptions2Attributes = vals.ToDictionary(o => o, o => o.GetAttributeOfType<CharacterOptions2Attribute>());
}
Expand Down
3 changes: 2 additions & 1 deletion Source/ACE.Entity/Enum/Properties/AssessmentProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace ACE.Entity.Enum.Properties
Expand All @@ -14,7 +15,7 @@ public static class AssessmentProperties
/// </summary>
/// <typeparam name="T">Enum to list by [AssessmentProperty]</typeparam>
/// <typeparam name="TResult">Type of the results</typeparam>
private static HashSet<TResult> GetValues<T, TResult>()
private static HashSet<TResult> GetValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T, TResult>()
{
var list = typeof(T).GetFields().Select(x => new
{
Expand Down
3 changes: 2 additions & 1 deletion Source/ACE.Entity/Enum/Properties/EphemeralProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace ACE.Entity.Enum.Properties
Expand All @@ -14,7 +15,7 @@ public static class EphemeralProperties
/// </summary>
/// <typeparam name="T">Enum to list by [Ephemeral]</typeparam>
/// <typeparam name="TResult">Type of the results</typeparam>
private static HashSet<T> GetValues<T>()
private static HashSet<T> GetValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>()
{
var list = typeof(T).GetFields().Select(x => new
{
Expand Down
3 changes: 2 additions & 1 deletion Source/ACE.Entity/Enum/Properties/SendOnLoginProperties.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace ACE.Entity.Enum.Properties
Expand All @@ -14,7 +15,7 @@ public static class SendOnLoginProperties
/// </summary>
/// <typeparam name="T">Enum to list by [SendOnLogin]</typeparam>
/// <typeparam name="TResult">Type of the results</typeparam>
private static HashSet<TResult> GetValues<T, TResult>()
private static HashSet<TResult> GetValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T, TResult>()
{
var list = typeof(T).GetFields().Select(x => new
{
Expand Down