Il2CppSetOptionAttribute.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. namespace Unity.IL2CPP.CompilerServices
  3. {
  4. /// <summary>
  5. /// The code generation options available for IL to C++ conversion.
  6. /// Enable or disabled these with caution.
  7. /// </summary>
  8. public enum Option
  9. {
  10. /// <summary>
  11. /// Enable or disable code generation for null checks.
  12. ///
  13. /// Global null check support is enabled by default when il2cpp.exe
  14. /// is launched from the Unity editor.
  15. ///
  16. /// Disabling this will prevent NullReferenceException exceptions from
  17. /// being thrown in generated code. In *most* cases, code that dereferences
  18. /// a null pointer will crash then. Sometimes the point where the crash
  19. /// happens is later than the location where the null reference check would
  20. /// have been emitted though.
  21. /// </summary>
  22. NullChecks = 1,
  23. /// <summary>
  24. /// Enable or disable code generation for array bounds checks.
  25. ///
  26. /// Global array bounds check support is enabled by default when il2cpp.exe
  27. /// is launched from the Unity editor.
  28. ///
  29. /// Disabling this will prevent IndexOutOfRangeException exceptions from
  30. /// being thrown in generated code. This will allow reading and writing to
  31. /// memory outside of the bounds of an array without any runtime checks.
  32. /// Disable this check with extreme caution.
  33. /// </summary>
  34. ArrayBoundsChecks = 2,
  35. /// <summary>
  36. /// Enable or disable code generation for divide by zero checks.
  37. ///
  38. /// Global divide by zero check support is disabled by default when il2cpp.exe
  39. /// is launched from the Unity editor.
  40. ///
  41. /// Enabling this will cause DivideByZeroException exceptions to be
  42. /// thrown in generated code. Most code doesn't need to handle this
  43. /// exception, so it is probably safe to leave it disabled.
  44. /// </summary>
  45. DivideByZeroChecks = 3,
  46. }
  47. /// <summary>
  48. /// Use this attribute on an assembly, struct, class, method, or property to inform the IL2CPP code conversion utility to override the
  49. /// global setting for one of a few different runtime checks.
  50. ///
  51. /// Example:
  52. ///
  53. /// [Il2CppSetOption(Option.NullChecks, false)]
  54. /// public static string MethodWithNullChecksDisabled()
  55. /// {
  56. /// var tmp = new Object();
  57. /// return tmp.ToString();
  58. /// }
  59. /// </summary>
  60. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate, Inherited = false, AllowMultiple = true)]
  61. public class Il2CppSetOptionAttribute : Attribute
  62. {
  63. public Option Option { get; private set; }
  64. public object Value { get; private set; }
  65. public Il2CppSetOptionAttribute(Option option, object value)
  66. {
  67. Option = option;
  68. Value = value;
  69. }
  70. }
  71. }