当前位置:网站首页>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
边栏推荐
- ROS 服务通信理论模型
- MySQL 版本升级心得
- 使用Keras构建GAN,以Mnist为例
- Unity底层是如何处理C#的
- 皮质-皮质网络的多尺度交流
- Multiscale communication in cortical-cortical networks
- 每日sql -用户两天留存率
- Monte Carlo
- Redis测试
- sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
猜你喜欢
HCIP MPLS/BGP Comprehensive Experiment
每日sql-员工奖金过滤和回答率排序第一
Amazon API interface Daquan
Implement general-purpose, high-performance sorting and quicksort optimizations
Daily sql-seek the sum of successful investments in 2016
SQL滑动窗口
Pinduoduo api interface application example
Douyin API interface
Daily sql: request for friend application pass rate
A used in the study of EEG ultra scanning analysis process
随机推荐
2022-08-10 第四小组 修身课 学习笔记(every day)
Attitude solution - gyroscope + Euler method
maxwell 概念
矩阵分析——微分、积分、极限
EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法
Discourse's Close Topic and Reopen Topic
每日sql -用户两天留存率
空间金字塔池化 -Spatial Pyramid Pooling(含源码)
每日sql-找到每个学校gpa最低的同学(开窗)
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
HCIP MPLS/BGP Comprehensive Experiment
OA project meeting notice (query & whether attending & feedback for details)
HCIA knowledge review
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
Implement general-purpose, high-performance sorting and quicksort optimizations
Amazon API interface Daquan
每日sql:求好友申请通过率
Unity程序员如何提升自己的能力
详解BLEU的原理和计算