94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Text;
|
||
using System.Collections;
|
||
using UnityEngine;
|
||
using YooAsset;
|
||
|
||
/// <summary>
|
||
/// 文件偏移加密方式
|
||
/// </summary>
|
||
public class TestFileOffsetEncryption : IEncryptionServices
|
||
{
|
||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||
{
|
||
// 说明:对TestRes3资源目录进行加密
|
||
if (fileInfo.BundleName.Contains("_testres3_"))
|
||
{
|
||
int offset = 32;
|
||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||
var encryptedData = new byte[fileData.Length + offset];
|
||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||
|
||
EncryptResult result = new EncryptResult();
|
||
result.Encrypted = true;
|
||
result.EncryptedData = encryptedData;
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
EncryptResult result = new EncryptResult();
|
||
result.Encrypted = false;
|
||
return result;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 资源文件偏移解密类
|
||
/// </summary>
|
||
public class TestFileOffsetDecryption : IDecryptionServices
|
||
{
|
||
/// <summary>
|
||
/// 同步方式获取解密的资源包对象
|
||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||
/// </summary>
|
||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||
{
|
||
DecryptResult decryptResult = new DecryptResult();
|
||
decryptResult.ManagedStream = null;
|
||
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||
return decryptResult;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 异步方式获取解密的资源包对象
|
||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||
/// </summary>
|
||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||
{
|
||
DecryptResult decryptResult = new DecryptResult();
|
||
decryptResult.ManagedStream = null;
|
||
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||
return decryptResult;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 后备方式获取解密的资源包对象
|
||
/// </summary>
|
||
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
||
{
|
||
return new DecryptResult();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取解密的字节数据
|
||
/// </summary>
|
||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取解密的文本数据
|
||
/// </summary>
|
||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
|
||
private static ulong GetFileOffset()
|
||
{
|
||
return 32;
|
||
}
|
||
} |