2022-11-05 22:22:39 +08:00
|
|
|
|
using HybridCLR.Editor.ABI;
|
|
|
|
|
using HybridCLR.Editor.Template;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.Il2CppDef
|
|
|
|
|
{
|
|
|
|
|
public class Il2CppDefGenerator
|
|
|
|
|
{
|
|
|
|
|
public class Options
|
|
|
|
|
{
|
|
|
|
|
public string OutputFile { get; set; }
|
|
|
|
|
|
|
|
|
|
public string UnityVersion { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly Options _options;
|
|
|
|
|
public Il2CppDefGenerator(Options options)
|
|
|
|
|
{
|
|
|
|
|
_options = options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Regex s_unityVersionPat = new Regex(@"(\d+)\.(\d+)\.(\d+)");
|
|
|
|
|
|
|
|
|
|
public void Generate()
|
|
|
|
|
{
|
|
|
|
|
var frr = new FileRegionReplace(File.ReadAllText(_options.OutputFile));
|
|
|
|
|
|
|
|
|
|
List<string> lines = new List<string>();
|
|
|
|
|
|
|
|
|
|
var match = s_unityVersionPat.Matches(_options.UnityVersion)[0];
|
|
|
|
|
int majorVer = int.Parse(match.Groups[1].Value);
|
|
|
|
|
int minorVer1 = int.Parse(match.Groups[2].Value);
|
|
|
|
|
int minorVer2 = int.Parse(match.Groups[3].Value);
|
|
|
|
|
|
|
|
|
|
lines.Add($"#define HYBRIDCLR_UNITY_VERSION {majorVer}{minorVer1.ToString("D2")}{minorVer2.ToString("D2")}");
|
|
|
|
|
lines.Add($"#define HYBRIDCLR_UNITY_{majorVer} 1");
|
|
|
|
|
for (int ver = 2019; ver <= 2024; ver++)
|
|
|
|
|
{
|
|
|
|
|
if (majorVer >= ver)
|
|
|
|
|
{
|
|
|
|
|
lines.Add($"#define HYBRIDCLR_UNITY_{ver}_OR_NEW 1");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 12:09:04 +08:00
|
|
|
|
frr.Replace("UNITY_VERSION", string.Join("\n", lines));
|
2022-11-05 22:22:39 +08:00
|
|
|
|
|
|
|
|
|
frr.Commit(_options.OutputFile);
|
|
|
|
|
Debug.Log($"[HybridCLR.Editor.Il2CppDef.Generator] output:{_options.OutputFile}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|