Add config to control whether json values are escaped

This commit is contained in:
esterTion 2024-09-24 11:13:54 +08:00
parent 4741d46ba9
commit 1d31daac3f
No known key found for this signature in database
GPG key ID: 3542D2F7A092D72B
4 changed files with 9 additions and 3 deletions

View file

@ -17,5 +17,6 @@
public double ForceVersion { get; set; } = 24.3;
public bool ForceDump { get; set; } = false;
public bool NoRedirectedPointer { get; set; } = false;
public bool EscapeJsonValues { get; set; } = false;
}
}

View file

@ -39,7 +39,7 @@ namespace Il2CppDumper
il2Cpp = il2CppExecutor.il2Cpp;
}
public void WriteScript(string outputDir)
public void WriteScript(string outputDir, bool escapeJsonValues)
{
var json = new ScriptJson();
// 生成唯一名称
@ -373,6 +373,10 @@ namespace Il2CppDumper
address = $"0x{x.Address:X}"
}).ToArray();
var jsonOptions = new JsonSerializerOptions() { WriteIndented = true, IncludeFields = true };
if (!escapeJsonValues)
{
jsonOptions.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
}
File.WriteAllText(outputDir + "stringliteral.json", JsonSerializer.Serialize(stringLiterals, jsonOptions), new UTF8Encoding(false));
//写入文件
File.WriteAllText(outputDir + "script.json", JsonSerializer.Serialize(json, jsonOptions));

View file

@ -262,7 +262,7 @@ namespace Il2CppDumper
{
Console.WriteLine("Generate struct...");
var scriptGenerator = new StructGenerator(executor);
scriptGenerator.WriteScript(outputDir);
scriptGenerator.WriteScript(outputDir, config.EscapeJsonValues);
Console.WriteLine("Done!");
}
if (config.GenerateDummyDll)

View file

@ -13,5 +13,6 @@
"ForceIl2CppVersion": false,
"ForceVersion": 16,
"ForceDump": false,
"NoRedirectedPointer": false
"NoRedirectedPointer": false,
"EscapeJsonValues": true
}