/// <summary> /// lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath("font.u3d"); WWW luaLoader = new WWW(luaP); yield return(luaLoader); if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV); AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (var ass in all) { keyName = ass.name; luacache[keyName] = ass; } item.Unload(false); luaLoader.Dispose(); } DoUnity3dLua(); if (domain) { DoMain(); } if (onLoadedFn != null) { onLoadedFn.Call(); } }
private IEnumerator loadLuaBundle() { string keyName = ""; string luaPath = PathUtil.GetAssetFullPath("lua.u3d"); WWW luaLoader = new WWW(luaPath); yield return(luaLoader); if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, KeyVData.Instance.KEY, KeyVData.Instance.IV); AssetBundle item = AssetBundle.LoadFromMemory(byts); TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (TextAsset ass in all) { keyName = ass.name; luacache[keyName] = ass.bytes; } item.Unload(true); luaLoader.Dispose(); } DoMain(); }
public static string LoadLocalData(string fileName) { string fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName); if (System.IO.File.Exists(fullPath)) { FileStream fs = new FileStream(fullPath, FileMode.Open); if (fs != null && fs.Length > 0) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); string loadData = string.Empty; try { loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv)); } catch (System.Exception ex) { Debug.LogError(ex); } return(loadData); } } return(""); }
public static string LoadLocalData(string fileName) { string fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName); FileInfo fileInfo = new FileInfo(fullPath); string loadData = string.Empty; if (fileInfo.Exists) { using (FileStream fs = fileInfo.OpenRead()) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); try { loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv)); } catch (System.Exception ex) { Debug.LogError(ex); } return(loadData); } } return(loadData); }
/// <summary> /// 加载lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath("font.u3d"); //Debug.Log("load lua bundle" + luaP); WWW luaLoader = new WWW(luaP); yield return(luaLoader); if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV); AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); // item = luaLoader.assetBundle; #if UNITY_5 TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (var ass in all) { keyName = Regex.Replace(ass.name, @"\.", ""); //Debug.Log("cache : " + keyName); luacache[keyName] = ass; } #else UnityEngine.Object[] all = item.LoadAll(typeof(TextAsset)); foreach (var ass in all) { keyName = Regex.Replace(ass.name, @"\.", ""); Debug.Log(keyName + " complete"); luacache[keyName] = ass as TextAsset; } #endif //Debug.Log("loaded lua bundle complete" + luaP); // luaLoader.assetBundle.Unload(false); item.Unload(false); luaLoader.Dispose(); } DoUnity3dLua(); if (domain) { DoMain(); } if (onLoadedFn != null) { onLoadedFn.call(); } }
//[MenuItem("Custom/lua/解析lua", false, 1)] public static void LoadLua() { string saveFolderPath = EditorUtility.SaveFolderPanel("导出", null, "Assets"); if (string.IsNullOrEmpty(saveFolderPath)) { return; } Debug.Log(saveFolderPath); string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform); string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua_core.u3d")); byte[] bytes = File.ReadAllBytes(luaExportPath); byte[] byts = CryptographHelper.Decrypt(bytes, key, iv); #if UNITY_5_3 AssetBundle item = AssetBundle.LoadFromMemory(byts); #else AssetBundle item = AssetBundle.LoadFromMemory(byts); #endif string keyName = ""; TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (TextAsset ass in all) { keyName = ass.name; string absFilePath = keyName.Replace("%", "/"); int last = absFilePath.LastIndexOf("/"); string cut0 = absFilePath.Substring(0, last); string cut1 = absFilePath.Substring(last, absFilePath.Length - last).Replace("/", "."); string newFilePath = cut0 + cut1; string fullPath = Path.Combine(saveFolderPath, newFilePath); FileInfo fi = new FileInfo(fullPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } using (StreamWriter kWriter = new StreamWriter(fullPath, false, new System.Text.UTF8Encoding(false))) { kWriter.Write(ass.text); kWriter.Close(); } } item.Unload(true); }
static public int Decrypt_s(IntPtr l) { try { System.Byte[] a1; checkType(l, 1, out a1); System.Byte[] a2; checkType(l, 2, out a2); System.Byte[] a3; checkType(l, 3, out a3); var ret = CryptographHelper.Decrypt(a1, a2, a3); pushValue(l, ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
/// <summary> /// lua bundle /// </summary> /// <returns></returns> private IEnumerator DecryptLuaBundle(string luaPath, bool isStreaming, LuaFunction onLoadedFn) { luaPath = CUtils.CheckWWWUrl(luaPath); Debug.Log("loadluabundle:" + luaPath); WWW luaLoader = new WWW(luaPath); yield return(luaLoader); if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV); AssetBundleCreateRequest abcreq = null; #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 abcreq = AssetBundle.CreateFromMemory(byts); #else abcreq = AssetBundle.LoadFromMemoryAsync(byts); #endif yield return(abcreq); var item = abcreq.assetBundle; TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (var ass in all) { SetRequire(ass.name, ass); } item.Unload(false); luaLoader.Dispose(); } else { Debug.LogWarning(luaLoader.error); } if (onLoadedFn != null) { onLoadedFn.call(); } else { DoMain(); } }