Il2CppClass.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {NativeStruct} from "./NativeStruct";
  2. import {il2cppApi} from "../il2cppApi";
  3. import {log} from "../../logger";
  4. export class Il2CppClass extends NativeStruct{
  5. name(){
  6. return il2cppApi.il2cpp_class_get_name(this).readCString();
  7. }
  8. namespaze(){
  9. return il2cppApi.il2cpp_class_get_namespace(this).readCString();
  10. }
  11. flags(){
  12. return il2cppApi.il2cpp_class_get_flags(this);
  13. }
  14. valueType(){
  15. return il2cppApi.il2cpp_class_is_valuetype(this);
  16. }
  17. enumType(){
  18. return il2cppApi.il2cpp_class_is_enum(this);
  19. }
  20. isGeneric(){
  21. return il2cppApi.il2cpp_class_is_generic(this);
  22. }
  23. /**
  24. * class_type
  25. */
  26. getType(){
  27. return il2cppApi.il2cpp_class_get_type(this);
  28. }
  29. getElementClass(){
  30. return il2cppApi.il2cpp_class_get_element_class(this);
  31. }
  32. getDeclaringType(){
  33. return il2cppApi.il2cpp_class_get_declaring_type(this);
  34. }
  35. filedCount(){
  36. return il2cppApi.il2cpp_class_num_fields(this);
  37. }
  38. /**
  39. *
  40. * @returns {Il2CppType}
  41. */
  42. getEnumBaseType(){
  43. return il2cppApi.il2cpp_class_enum_basetype(this);
  44. }
  45. getFieldsInfo(iter){
  46. return il2cppApi.il2cpp_class_get_fields(this,iter);
  47. }
  48. getProperties(iter){
  49. return il2cppApi.il2cpp_class_get_properties(this,iter);
  50. }
  51. getMethods(iter){
  52. return il2cppApi.il2cpp_class_get_methods(this,iter);
  53. }
  54. /**
  55. * 获取泛型参数名
  56. * @returns {string}
  57. */
  58. getGenericName(){
  59. let type = this.getType();
  60. let name = this.name();
  61. if (name.indexOf("`") !== -1) {
  62. // log("获取Type:Il2cpp:"+this.name() +" nameSpaze:"+this.namespaze());
  63. let il2cppTypeGetName = type.getName();
  64. if (il2cppTypeGetName==null){
  65. return name;
  66. }
  67. let split = name.split("`");
  68. name = split[0];
  69. let indexOf = il2cppTypeGetName.indexOf(name);
  70. let s = il2cppTypeGetName.substr(indexOf + name.length, il2cppTypeGetName.length - name.length);
  71. let genericT ="\<System.Object\>";
  72. // log(" genericT:"+genericT);
  73. if (s===genericT){
  74. return "\<T\>";
  75. }
  76. return s ;
  77. }
  78. return name;
  79. }
  80. parent(){
  81. return new Il2CppClass(il2cppApi.il2cpp_class_get_parent(this));
  82. }
  83. getInterfaces(iter) {
  84. return il2cppApi.il2cpp_class_get_interfaces(this,iter);
  85. }
  86. }