public MemoryStream LoadResource_LuaScript(string filePath) { if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { try { #if _Develop FileStream file = new FileStream(UniGameResources.ConnectPath(UniGameResources.DataPath, UniGameResourcesDefine.DefineAssetBundleName_LuaScript, "/", filePath), FileMode.Open, FileAccess.Read, FileShare.Read); file.Seek(0, SeekOrigin.Begin); byte[] buffer = new byte[file.Length]; file.Read(buffer, 0, buffer.Length); file.Close(); return(new MemoryStream(buffer)); #else return(luaScriptReaderSecurity.Load(filePath)); #endif//_Develop } catch (System.Exception ex) { Debug.LogError(ex.ToString()); return(null); } } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { if (luaScriptPackage == null) { throw new Exception("cant find lua script package!"); } luaScriptPackage.LockPackage(); #if UNITY_4_3 || UNITY_4_6 TextAsset textAsset = luaScriptPackage.currentAssetBundle.Load(filePath, typeof(TextAsset)) as TextAsset; #else TextAsset textAsset = luaScriptPackage.currentAssetBundle.LoadAsset(filePath, typeof(TextAsset)) as TextAsset; #endif MemoryStream ret = null; try { byte[] luadata = textAsset.bytes; luadata = Convert.FromBase64String(Encoding.ASCII.GetString(luadata)); //解密数据 #if _SupportDeviceVerify luadata = luaScriptFileEncipher.FileDecrypt(luadata, true); #else luadata = luaScriptFileEncipher.FileDecrypt(luadata); #endif //_SupportDeviceVerify ret = new MemoryStream(luadata); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); ret = null; } UniGameResources.ReleaseOneAssets(textAsset); luaScriptPackage.UnLockPackage(); return(ret); } return(null); }
//加载Xml文件 private XmlDocument LoadResource_XmlDocument(ref GameResourcesNode data, Encoding code) { if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity) { try { #if _Develop XmlDocument doc = new XmlDocument(); doc.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path)); return(doc); #else return(xmlReaderSecurity.LoadXml(data.path)); #endif//_Develop } catch (System.Exception ex) { Debug.LogError(ex.ToString()); return(null); } } else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile) { UniGameResourcesPackage package = (UniGameResourcesPackage)data.package; package.LockPackage(); #if UNITY_4_3 || UNITY_4_6 TextAsset textAsset = package.currentAssetBundle.Load(data.path, typeof(TextAsset)) as TextAsset; #else TextAsset textAsset = package.currentAssetBundle.LoadAsset(data.path, typeof(TextAsset)) as TextAsset; #endif XmlDocument doc = null; try { byte[] xmldata = textAsset.bytes; xmldata = Convert.FromBase64String(Encoding.ASCII.GetString(xmldata)); //解密数据 #if _SupportDeviceVerify xmldata = xmlFileEncipher.FileDecrypt(xmldata, true); #else xmldata = xmlFileEncipher.FileDecrypt(xmldata); #endif //_SupportDeviceVerify //MemoryStream s = new MemoryStream(xmldata); doc = new XmlDocument(); doc.LoadXml(code.GetString(xmldata)); //s.Close(); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); doc = null; } UniGameResources.ReleaseOneAssets(textAsset); package.UnLockPackage(); return(doc); } return(null); }
public static byte[] Decrypt(byte[] data) { FTEncipher ftEncipher = getDecryptHandler(); return(ftEncipher.FileDecrypt(data)); }
//加载包清单文件 public IEnumerator LoadingGameAssetBundleInventoryPackageFile() { WWW www; if (UniGameResources.IsLocalDownloadUrlPath) { www = WWW.LoadFromCacheOrDownload(FTLibrary.Text.IStringPath.ConnectPath(UniGameResources.downloadUrlPath, UniGameResourcesDefine.GameAssetBundleInventoryPackageFilePath), UniGameResources.version_GameAssetBundleInventoryPackageFile); } else { www = new WWW(FTLibrary.Text.IStringPath.ConnectPath(UniGameResources.downloadUrlPath, UniGameResourcesDefine.GameAssetBundleInventoryPackageFilePath)); } yield return(www); if (www.error != null) { GameRoot.Error(string.Format("资源引导文件下载错误:{0}", www.error)); yield break; } byte[] data = null; try { #if UNITY_4_3 || UNITY_4_6 TextAsset textAsset = www.assetBundle.Load(UniGameResourcesDefine.GameAssetBundleInventoryXmlFilePath, typeof(TextAsset)) as TextAsset; #else TextAsset textAsset = www.assetBundle.LoadAsset(UniGameResourcesDefine.GameAssetBundleInventoryXmlFilePath, typeof(TextAsset)) as TextAsset; #endif data = textAsset.bytes; UniGameResources.ReleaseOneAssets(textAsset); www.assetBundle.Unload(false); //当获取一次资源对象的时候实际是克隆一个对象 //UnityEngine.Object.DestroyObject(www.assetBundle); www.Dispose(); } catch (System.Exception ex) { GameRoot.Error(string.Format("资源引导文件读取错误:{0}", ex.ToString())); yield break; } FTEncipher encipher = null; try { //首先从BASE64转换回来 data = Convert.FromBase64String(Encoding.ASCII.GetString(data)); //构建解密组件 encipher = UniGameResources.AllocXmlFileEncipher(); #if _SupportDeviceVerify data = encipher.FileDecrypt(data, true); #else data = encipher.FileDecrypt(data); #endif //_SupportDeviceVerify encipher.Dispose(); encipher = null; MemoryStream s = new MemoryStream(data); XmlDocument doc = new XmlDocument(); doc.Load(s); s.Close(); UniGameResources.BuildSystemResourcesPackageTable(doc); } catch (System.Exception ex) { GameRoot.Error(string.Format("资源引导文件解析错误:{0}", ex.ToString())); if (encipher != null) { encipher.Dispose(); encipher = null; } yield break; } }