diff --git a/Editor/Misc/EventScriptingDefineSymbols.cs b/Editor/Misc/EventScriptingDefineSymbols.cs new file mode 100644 index 0000000..9de3265 --- /dev/null +++ b/Editor/Misc/EventScriptingDefineSymbols.cs @@ -0,0 +1,46 @@ +using AlicizaX.Editor; +using UnityEditor; +using UnityEngine; + +namespace AlicizaX.Editor +{ + internal static class EventScriptingDefineSymbols + { + private const string MenuPath = "Tools/AlicizaX/Enable Strict Check"; + private const string DefineSymbol = "Event_StrictCheck"; + + [MenuItem(MenuPath)] + private static void ToggleStrictCheck() + { + bool enabled = IsEnabled(); + SetEnabled(!enabled); + } + + [MenuItem(MenuPath, true)] + private static bool ToggleStrictCheckValidate() + { + Menu.SetChecked(MenuPath, IsEnabled()); + return true; + } + + private static bool IsEnabled() + { + return ScriptingDefineSymbols.HasScriptingDefineSymbol(EditorUserBuildSettings.selectedBuildTargetGroup, DefineSymbol); + } + + private static void SetEnabled(bool enabled) + { + var targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; + if (enabled) + { + ScriptingDefineSymbols.AddScriptingDefineSymbol(targetGroup, DefineSymbol); + } + else + { + ScriptingDefineSymbols.RemoveScriptingDefineSymbol(targetGroup, DefineSymbol); + } + + Debug.Log($"[EventKit] Strict Check {(enabled ? "Enabled" : "Disabled")}"); + } + } +} diff --git a/Editor/Misc/EventScriptingDefineSymbols.cs.meta b/Editor/Misc/EventScriptingDefineSymbols.cs.meta new file mode 100644 index 0000000..1ed3286 --- /dev/null +++ b/Editor/Misc/EventScriptingDefineSymbols.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a0f666b24d9c41c4a355f9a9a643928b +timeCreated: 1756782190 \ No newline at end of file diff --git a/Plugins/EventSourceGenerator.dll b/Plugins/EventSourceGenerator.dll new file mode 100644 index 0000000..b800e52 Binary files /dev/null and b/Plugins/EventSourceGenerator.dll differ diff --git a/Plugins/EventSourceGenerator.dll.meta b/Plugins/EventSourceGenerator.dll.meta new file mode 100644 index 0000000..d0ee933 --- /dev/null +++ b/Plugins/EventSourceGenerator.dll.meta @@ -0,0 +1,52 @@ +fileFormatVersion: 2 +guid: e0f9fe588fe13b14ca28cddf735a2f0b +labels: +- RoslynAnalyzer +PluginImporter: + externalObjects: {} + serializedVersion: 3 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + Any: + enabled: 1 + settings: + Exclude Editor: 1 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 0 + Editor: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + Linux64: + enabled: 1 + settings: + CPU: AnyCPU + OSXUniversal: + enabled: 1 + settings: + CPU: AnyCPU + Win: + enabled: 1 + settings: + CPU: AnyCPU + Win64: + enabled: 1 + settings: + CPU: AnyCPU + WindowsStoreApps: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Event.meta b/Runtime/Event.meta new file mode 100644 index 0000000..e74cce7 --- /dev/null +++ b/Runtime/Event.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 421689177e8f4c58ae0ce91e5ea9f9c3 +timeCreated: 1736415505 \ No newline at end of file diff --git a/Runtime/Event/EventRuntimeHandle.cs b/Runtime/Event/EventRuntimeHandle.cs new file mode 100644 index 0000000..6438bfe --- /dev/null +++ b/Runtime/Event/EventRuntimeHandle.cs @@ -0,0 +1,36 @@ +using System; +using System.Runtime.CompilerServices; +using Unity.IL2CPP.CompilerServices; + +namespace AlicizaX +{ + public interface IEventArgs { } + + [AttributeUsage(AttributeTargets.Struct)] + public sealed class PrewarmAttribute : Attribute + { + public int Capacity { get; } + public PrewarmAttribute(int capacity) => Capacity = capacity; + } + + [Il2CppSetOption(Option.NullChecks, false)] + [Il2CppSetOption(Option.DivideByZeroChecks, false)] + [Il2CppSetOption(Option.ArrayBoundsChecks, false)] + public readonly struct EventRuntimeHandle + { + private readonly Action _unsubscribe; + private readonly int _index; + private readonly int _version; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public EventRuntimeHandle(Action unsubscribe, int index, int version) + { + _unsubscribe = unsubscribe; + _index = index; + _version = version; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() => _unsubscribe?.Invoke(_index, _version); + } +} diff --git a/Runtime/Event/EventRuntimeHandle.cs.meta b/Runtime/Event/EventRuntimeHandle.cs.meta new file mode 100644 index 0000000..6539b7d --- /dev/null +++ b/Runtime/Event/EventRuntimeHandle.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d85feee75c2d4b54bd6b593fe55145d7 +timeCreated: 1740488369 \ No newline at end of file diff --git a/Runtime/Event/Il2CppSetOptionAttribute.cs b/Runtime/Event/Il2CppSetOptionAttribute.cs new file mode 100644 index 0000000..e7453df --- /dev/null +++ b/Runtime/Event/Il2CppSetOptionAttribute.cs @@ -0,0 +1,74 @@ +using System; + +namespace Unity.IL2CPP.CompilerServices +{ + /// + /// The code generation options available for IL to C++ conversion. + /// Enable or disabled these with caution. + /// + public enum Option + { + /// + /// Enable or disable code generation for null checks. + /// + /// Global null check support is enabled by default when il2cpp.exe + /// is launched from the Unity editor. + /// + /// Disabling this will prevent NullReferenceException exceptions from + /// being thrown in generated code. In *most* cases, code that dereferences + /// a null pointer will crash then. Sometimes the point where the crash + /// happens is later than the location where the null reference check would + /// have been emitted though. + /// + NullChecks = 1, + /// + /// Enable or disable code generation for array bounds checks. + /// + /// Global array bounds check support is enabled by default when il2cpp.exe + /// is launched from the Unity editor. + /// + /// Disabling this will prevent IndexOutOfRangeException exceptions from + /// being thrown in generated code. This will allow reading and writing to + /// memory outside of the bounds of an array without any runtime checks. + /// Disable this check with extreme caution. + /// + ArrayBoundsChecks = 2, + /// + /// Enable or disable code generation for divide by zero checks. + /// + /// Global divide by zero check support is disabled by default when il2cpp.exe + /// is launched from the Unity editor. + /// + /// Enabling this will cause DivideByZeroException exceptions to be + /// thrown in generated code. Most code doesn't need to handle this + /// exception, so it is probably safe to leave it disabled. + /// + DivideByZeroChecks = 3, + } + + /// + /// Use this attribute on an assembly, struct, class, method, or property to inform the IL2CPP code conversion utility to override the + /// global setting for one of a few different runtime checks. + /// + /// Example: + /// + /// [Il2CppSetOption(Option.NullChecks, false)] + /// public static string MethodWithNullChecksDisabled() + /// { + /// var tmp = new Object(); + /// return tmp.ToString(); + /// } + /// + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate, Inherited = false, AllowMultiple = true)] + public class Il2CppSetOptionAttribute : Attribute + { + public Option Option { get; private set; } + public object Value { get; private set; } + + public Il2CppSetOptionAttribute(Option option, object value) + { + Option = option; + Value = value; + } + } +} diff --git a/Runtime/Event/Il2CppSetOptionAttribute.cs.meta b/Runtime/Event/Il2CppSetOptionAttribute.cs.meta new file mode 100644 index 0000000..691658c --- /dev/null +++ b/Runtime/Event/Il2CppSetOptionAttribute.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 997668ad76a5387428e679240d659155 \ No newline at end of file