当前位置:网站首页>What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
2022-08-11 07:29:00 【Clank's Game Stack】
Unity's games are easy to be hackedDecompile out, and then repackage and publish it, and make yourself work hardA game that was developed hard, and the transcription was naked.Many projects require resource encryption. How to do resource encryption in Unity?This article will share with you the idea of encryption algorithm + resource packaging integration:
(1) How to choose the encryption algorithm for game resource encryption;
(2) Encryption and decryption of Assetsbundle resource package;
Yes!Here is a The unity learning exchange group has gathered a group of zero-based beginners who love to learn unity, and there are also some technical leaders who are engaged in unity development. You are welcome to exchange and learn.
How to choose an encryption algorithm for game resource packs
The first thing to do when encrypting the game resource package is to choose an encryption/decryption algorithm, which is not easy to be cracked by others.How do we choose?I am sorry to tell you that no safe encryption and decryption algorithm is safe.The gangster will come to refute the first time, how is this possible, how can he crack it after I encrypted it?Game resource encryption is destined that the encryption algorithm cannot be too time-consuming.Next, let's take a look at how different encryption algorithms are cracked.
(1) Use the encryption and decryption algorithm implemented by the standard library, such as using the encrypt encryption/decryption algorithm.There is a problem here, we will have a key to decrypt, and the key is usually written into the code in the game.This kind of cracking is too simple, the key is written in the code, basically string, etc., static analysisThe code finds the string corresponding to the key. With the key, you are using the standard library, and the encrypted resources will be cracked at once, and your resources will be cracked in minutes.
(2) Use the encryption and decryption algorithm implemented by yourself, for example, use binary or for encryption and decryption, for example, set a binary mask mask for encryption, let each byte XOR this mask, and get a newdata, so that the resource cannot be directly identified. When the resource is used, the encrypted data is XORed and the mask is decrypted and returned to the project for use.This kind of cracking is a bit annoying to write, you need to decompile your decryption code yourself, and at the same time find your decryption key key.But the essence is also easier to crack.
The encryption/decryption algorithm is shown as follows:
Source data 1110 0001, key is 00101000;
Encrypted data: 1110 0001 ^ 00101000 = 1100 1001
Decrypted data: 1100 1001 ^ 00101000 = 1110 0001
From the above analysis, it is almost difficult not to be cracked, depending on the cost of cracking.Is your game worth it.Generally, our goal is not to let people use the Unity decompilation tool to directly decompile our game into the Unity project project, and then recompile, package and publish.The decryption algorithm should be fast, and it is destined to not be too complicated. The key is only put on the client or the network, and it is destined to be obtained.
Assetsbundle encryption and decryption
After analyzing the encryption and decryption algorithm, let's take a look at how to encrypt our resources. Let's first introduce the first solution. When printing a resource package, encrypt a single resource and enter the encrypted data into theresource pack.When decrypting, read the resource from the ab package, and then decrypt the content in the resource package.The specific steps are as follows:
(1) Create a new class, inherit from FileStream, and override the Read/Write function.The code is as follows:
using System.IO;public class MyStream : FileStream {const byte KEY = 40; // key mask: 0010 1000public MyStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) :base(path, mode, access, share, bufferSize, useAsync) {}public MyStream(string path, FileMode mode) : base(path, mode) {}// Overload the read interface, read and decrypt once;public override int Read(byte[] array, int offset, int count) {var index = base.Read(array, offset, count);for (int i = 0 ; i < array.Length; i++) {array[i] ^= KEY;}return index;}public override void Write(byte[] array, int offset, int count) {// Override the write interface, encrypt first and then write;for (int i = 0; i < array.Length; i++) {array[i] ^= KEY;}base.Write(array, offset, count);}}
(2) Modify the script of the ab package packaging tool, and then encrypt the generated ab package resources once. The package encryption script is as follows:
[MenuItem("Tools/BuildAB")]static void BuildAB(){…// The for loop traverses each packaged resource Ab package inside, and then calls for encryption.foreach (var name in manifest.GetAllAssetBundles()){var uniqueSalt = Encoding.UTF8.GetBytes(name);var data = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, name));using (var myStream = new MyStream(Path.Combine(Application.streamingAssetsPath, "encypt_" + name),FileMode.Create)){myStream.Write(data, 0, data.Length); // Trigger the call of our rewritten write function in MyStream to complete data encryption}}AssetDatabase.Refresh();}
(3) When decrypting, read the ab package and use the function AssetsBundle.LoadFromStream to load it, and this will trigger the Stream to call the Read data interface, and you can enter our overloaded Read interface for decryption.The code is as follows:
var fileStream = new MyStream(Application.streamingAssetsPath + "/encypt_myab.unity3d", FileMode.Open, FileAccess.Read, FileShare.None, 1024 * 4, false)){var myLoadedAssetBundle = AssetBundle.LoadFromStream(fileStream); // Trigger the Read call in MyStream to decrypt the data.}
Today's sharing is here, you can enter the study group to communicate game development together
边栏推荐
猜你喜欢
抖音API接口
淘宝sku API 接口(PHP示例)
每日sql-统计各个专业人数(包括专业人数为0的)
Redis源码:Redis源码怎么查看、Redis源码查看顺序、Redis外部数据结构到Redis内部数据结构查看源码顺序
When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
淘宝商品详情API接口
1688商品详情接口
SQL滑动窗口
什么是Inductive learning和Transductive learning
exness:黄金1800关口遇阻,静待美国CPI出炉
随机推荐
Coordinate system in navigation and positioning
Shell:三剑客之awk
每日sql -用户两天留存率
Pinduoduo API interface
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
docker安装mysql5.7(仅供测试使用)
opencv实现数据增强(图片+标签)平移,翻转,缩放,旋转
Taobao API common interface and acquisition method
淘宝商品详情API接口
SQL sliding window
图文带你理解什么是Few-shot Learning
概念名词解释
torch.cat()使用方法
Taobao sku API interface (PHP example)
拼多多api接口应用示例
损失函数——负对数似然
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
强烈推荐一款好用的API接口
【推荐系统】:协同过滤和基于内容过滤概述
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现