cocos luacompile
Overview
Usage
Available Arguments
arg | available value | sample | description | necessary |
---|---|---|---|---|
-h,--help | - | - | Show the help message and exit | no |
-s,--src | source directory | ./projects/MyLuaGame/src |
Specify source directory of lua files needed to be compiled. | yes |
-d,--dst | destination directory | ./projects/MyLuaGame/src |
Specify destination directory bytecode files to be stored. | yes |
-e,--encrypt | - | - | Enable the encrypting of lua files. | no |
-k,--encryptkey | any string | MyLuaKey |
Specify the encrypt key for the encrypting of lua scripts. It's only take effect when-e,--encrypt is enabled. Default value is2dxLua . |
no |
-b,--encryptsign | any string | MyLuaSign |
Specify the encrypt sign for the encrypting of lua scripts. It's only take effect when--encrypt is enabled. Default value isXXTEA . |
no |
Samples
cocos luacompile -h
. Show the help message.cocos luacompile -s ./projects/MyLuaGame/src -d ./projects/MyLuaGame/src -e -k MyLuaKey -b MyLuaSign
Compile the*.lua
in directory./projects/MyLuaGame/src
to*.luac
. Then encrypt the luac files with key isMyLuaKey
and sign isMyLuaSign
.
下面给出全过程与测试工程
1.0 cocos luacompile 用法
@H_301_186@我用的普通的cocos2d lua,没用quick,quick好像可以对整个资源包括图像和音频都加密,打包成zip。但我没用quick.看了下luacompile 的 help,比较简单啊。
@H_301_186@先在项目根目录下建立了一个out的文件夹,然后就用这个命令试了下:
@H_301_186@比预想的顺利,在out目录下看到了很多luac文件。正如命令里说的,支持子目录。网上说luac还是会被反编译。就加上了key。
@H_301_186@他用的是XXTEA加密算法,可以看这篇文章《XXTEA 可逆加密解密算法 C++ C#兼容版本》
@H_301_186@还需要在AppDelegate.cpp文件的applicationDidFinishLaunching方法中加入setXXTEAKeyAndSign。这点它那个luacompile 的help就没提了,这是第一个坑。
2.不支持64bit
@H_301_186@第二个坑马上来了:刚开始在IPhone4S模拟器运行好好的,IPhone5s就漆黑一片了。原来这样把lua编译后,虽然速度变快了,但还未支持64位系统,据说cocos2d 年底会给出luajit 64位解决方案,因为苹果要求的啊。
@H_301_186@然后因为这个问题我卡了一会儿。网上搜了了也没什么结果,都推荐使用Quick。游戏都写完了,转Quick有点麻烦。
@H_301_186@突然注意到luacompile help中最后一个选项:–disable-compile ,然后把命令改成下面这种:
@H_301_186@项目测试:
/// decode:
const char * key = "testKey123456";
int keylen = (int)strlen(key);
const char * sign = "testSign123456";
int signlen = (int)strlen(sign);
Data srcInfo = FileUtils::getInstance()->getDataFromFile("BugAnt.luac");
//decode:
xxtea_long len = 0;
unsigned char * result = xxtea_decrypt(srcInfo.getBytes() + signlen,
(xxtea_long)srcInfo.getSize() - signlen,
(unsigned char* )key,
(xxtea_long)keylen,
&len);
printf("\n result: %s \n len; %ld",result,len);
读取正常;