Cocos2d-x 2.2.6 iOS 版,直接跳过了XXTEA 解密,导致XXTEA加密的代码无法运行,以下是改后的正确代码
'''
static const std::string BYTECODE_FILE_EXT = ".luac";
static const std::string NOT_BYTECODE_FILE_EXT = ".lua";
int CCLuaStack::executeScriptFile(const char* filename)
{
if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
std::string code("require \"");
code.append(filename);
code.append("\"");
return executeString(code.c_str());
elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
std::string buf(filename);
//
// remove .lua or .luac
//
size_t pos = buf.rfind(BYTECODE_FILE_EXT);
if (pos != std::string::npos)
{
buf = buf.substr(0, pos);
}
else
{
pos = buf.rfind(NOT_BYTECODE_FILE_EXT);
if (pos == buf.length() - NOT_BYTECODE_FILE_EXT.length())
{
buf = buf.substr(0, pos);
}
}
CCFileUtils *utils = CCFileUtils::sharedFileUtils();
//
// 1. check .lua suffix
// 2. check .luac suffix
//
std::string tmpfilename = buf + NOT_BYTECODE_FILE_EXT;
if (utils->isFileExist(tmpfilename))
{
buf = tmpfilename;
}
else
{
tmpfilename = buf + BYTECODE_FILE_EXT;
if (utils->isFileExist(tmpfilename))
{
buf = tmpfilename;
}
}
unsigned char* chunk = NULL;
unsigned long chunkSize = 0;
std::string chunkName = "";
chunkName = CCFileUtils::sharedFileUtils()->fullPathForFilename(buf.c_str());
chunk = utils->getFileData(chunkName.c_str(), "rb", &chunkSize);
int rn = 0;
if (NULL != chunk)
{
if (luaLoadBuffer(m_state, (const char*)chunk, (int)chunkSize, chunkName.c_str()) == 0)
{
rn = executeFunction(0);
}
}
return rn;
else
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(filename);
++m_callFromLua;
int nRet = luaL_dofile(m_state, fullPath.c_str());
--m_callFromLua;
CC_ASSERT(m_callFromLua >= 0);
// lua_gc(m_state, LUA_GCCOLLECT, 0);
if (nRet != 0)
{
CCLOG("[LUA ERROR] %s", lua_tostring(m_state, -1));
lua_pop(m_state, 1);
return nRet;
}
return 0;
endif
}
'''