Skip to content

Commit

Permalink
Merge pull request #12 from buoutuanzi/LuaAsset
Browse files Browse the repository at this point in the history
修复在 .net5 .net6 版本的中文编码问题
  • Loading branch information
zhangjiequan authored Dec 29, 2023
2 parents e2eec07 + 76f1da6 commit 356119c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions AssetStudio/LuaDecompile/OutputProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public OutputProcess()
{
StartInfo.RedirectStandardOutput = true;
StartInfo.RedirectStandardError = true;

OutputDataReceived += OnProcessOutput;
ErrorDataReceived += OnProcessError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ private bool TryDecompile(byte[] luaBytes, out byte[] luaCode)
if (decompileProcess.ExitCode == 0)
{
luaCode = Encoding.UTF8.GetBytes(decompileProcess.Output);
luaCode = Encoding.Convert(Encoding.UTF8, Encoding.Default, luaCode);
}
else
{
Expand All @@ -67,6 +66,7 @@ private OutputProcess BuildProcess(string pythonExePath, string args)
decompileProcess.StartInfo.FileName = pythonExePath;
decompileProcess.StartInfo.Arguments = args;
decompileProcess.StartInfo.UseShellExecute = false;
decompileProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
return decompileProcess;
}
}
Expand Down
14 changes: 9 additions & 5 deletions AssetStudio/LuaDecompile/handlers/LuacDecompileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LuacDecompileHandler : ILuaDecompileHandler

private const string EXE_DIR = "Dependencies/luadec";
private const string TEMP_FILE = "tempCompiledLua.lua";
private static readonly string DecompileArg = "-se UTF8 " + TEMP_FILE;
private static readonly string DecompileArg = $"-se UTF8 {TEMP_FILE}";

public byte[] Decompile(LuaByteInfo luaByteInfo)
{
Expand All @@ -36,20 +36,24 @@ public byte[] Decompile(LuaByteInfo luaByteInfo)

private byte[] TryDecompile(LuaByteInfo luaByteInfo, string exePath)
{
File.WriteAllBytes(TEMP_FILE, luaByteInfo.RawByte);
File.WriteAllBytes(TEMP_FILE, luaByteInfo.RawByte);
var decompileProcess = new OutputProcess();
decompileProcess.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, EXE_DIR, exePath);
decompileProcess.StartInfo.Arguments = DecompileArg;
decompileProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8;
decompileProcess.StartInfo.UseShellExecute = false;
try
{
decompileProcess.Start();
decompileProcess.WaitForExit();
if (decompileProcess.ExitCode == 0)
{
// 编译完成结果缓存起来
var gbkEncode = Encoding.GetEncoding("gbk");
luaByteInfo.SetDecompiledContent(gbkEncode.GetBytes(decompileProcess.Output));
// 编译完成结果缓存起来;
luaByteInfo.SetDecompiledContent(Encoding.UTF8.GetBytes(decompileProcess.Output));
}
else
{
Console.WriteLine(decompileProcess.Error);
}
}
catch (Exception e)
Expand Down

0 comments on commit 356119c

Please sign in to comment.