Il2CppSetOptionAttribute.cs 3.0 KB

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