Il2CppDefGenerator.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using HybridCLR.Editor.ABI;
  2. using HybridCLR.Editor.Template;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using UnityEngine;
  11. namespace HybridCLR.Editor.Il2CppDef
  12. {
  13. public class Il2CppDefGenerator
  14. {
  15. public class Options
  16. {
  17. public string OutputFile { get; set; }
  18. public string UnityVersion { get; set; }
  19. }
  20. private readonly Options _options;
  21. public Il2CppDefGenerator(Options options)
  22. {
  23. _options = options;
  24. }
  25. private static readonly Regex s_unityVersionPat = new Regex(@"(\d+)\.(\d+)\.(\d+)");
  26. public void Generate()
  27. {
  28. var frr = new FileRegionReplace(File.ReadAllText(_options.OutputFile));
  29. List<string> lines = new List<string>();
  30. var match = s_unityVersionPat.Matches(_options.UnityVersion)[0];
  31. int majorVer = int.Parse(match.Groups[1].Value);
  32. int minorVer1 = int.Parse(match.Groups[2].Value);
  33. int minorVer2 = int.Parse(match.Groups[3].Value);
  34. lines.Add($"#define HYBRIDCLR_UNITY_VERSION {majorVer}{minorVer1.ToString("D2")}{minorVer2.ToString("D2")}");
  35. lines.Add($"#define HYBRIDCLR_UNITY_{majorVer} 1");
  36. for (int ver = 2019; ver <= 2024; ver++)
  37. {
  38. if (majorVer >= ver)
  39. {
  40. lines.Add($"#define HYBRIDCLR_UNITY_{ver}_OR_NEW 1");
  41. }
  42. }
  43. frr.Replace("UNITY_VERSION", string.Join("\n", lines));
  44. frr.Commit(_options.OutputFile);
  45. Debug.Log($"[HybridCLR.Editor.Il2CppDef.Generator] output:{_options.OutputFile}");
  46. }
  47. }
  48. }