3

我正在使用System.Text.Encoding1252 编码来扩展 ASCII 支持以充分利用字节的第 8 位,到目前为止,当使用 Mono 作为 时Scripting Backend,我将能够防止通过Assets/link.xml文件剥离代码,如下所示:

<assembly fullname="I18N">
    <type fullname="I18N.Common" preserve="all"/>
    <type fullname="I18N.Common.ByteEncoding" preserve="all"/>
    <type fullname="I18N.Common.Handlers" preserve="all"/>
    <type fullname="I18N.Common.Manager" preserve="all"/>
    <type fullname="I18N.Common.MonoEncoder" preserve="all"/>
    <type fullname="I18N.Common.MonoEncoding" preserve="all"/>
    <type fullname="I18N.Common.Strings" preserve="all"/>
</assembly>

<assembly fullname="I18N.West">
    <type fullname="I18N.West" preserve="all"/>
    <type fullname="I18N.West.ENCwindows_1252" preserve="all"/>
    <type fullname="I18N.West.CP1252" preserve="all"/>
</assembly>

但是,当我切换到 IL2CPP 时,我遇到了崩溃,因为在构建过程中某些功能已被剥离。即使我Stripping Level在 Unity 的播放器设置中禁用了..

这是我的运行时崩溃日志:

IL2CPP 崩溃:

NotSupportedException: CodePage 1252 not supported
  at System.Security.Cryptography.TripleDESCryptoServiceProvider.CreateEncryptor (System.Byte[] rgbKey, System.Byte[] rgbIV) [0x00000] in <filename unknown>:0 
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 

当我删除preservelink.xml 中的语句时,这与 Mono 中的相同:

NotSupportedException: CodePage 1252 not supported
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 

这是我如何使用有问题的代码:

byte[] bytes = System.Text.Encoding.GetEncoding(1252).GetBytes(str); // exactly 8-bit

string str = System.Text.Encoding.GetEncoding(1252).GetString(bytes);

非常感谢您!

4

1 回答 1

2

实际上,您可能在 IL2CPP 运行时中看到了一个与代码剥离完全无关的错误。使用 Unity 的 4.6.4p3 版本,我可以看到同样的问题,并且我已经跟踪了它。我们应该能够在下一个补丁版本中修复这个问题。

事实证明,libil2cpp 运行时中的 icall 与 mscorlib 中的托管代码交互不正确,因此 mscorlib 中的代码被发送到 IL2CPP 脚本后端的不同路径。

于 2015-04-17T14:40:50.857 回答