資源簡介
高性能的內存加密類庫,主要可用于各種游戲的內存加密,防止用戶修改游戲數據從而影響游戲的平衡性。 可用于Unity游戲項目,集成簡單,使用方便。集成后基本無需修改原來的代碼邏輯,僅需要將變量聲明中的int改為EncryptInt,float改為EncryptFloat……,支持int,float,...
代碼片段和文件信息
/****************************************************************************
Copyright?(c)?home
home_498@163.com
Permission?is?hereby?granted?free?of?charge?to?any?person?obtaining?a?copy
of?this?software?and?associated?documentation?files?(the?“Software“)?to?deal
in?the?Software?without?restriction?including?without?limitation?the?rights
to?use?copy?modify?merge?publish?distribute?sublicense?and/or?sell
copies?of?the?Software?and?to?permit?persons?to?whom?the?Software?is
furnished?to?do?so?subject?to?the?following?conditions:
The?above?copyright?notice?and?this?permission?notice?shall?be?included?in
all?copies?or?substantial?portions?of?the?Software.
THE?SOFTWARE?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF?ANY?KIND?EXPRESS?OR
IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO?THE?WARRANTIES?OF?MERCHANTABILITY
FITNESS?FOR?A?PARTICULAR?PURPOSE?AND?NONINFRINGEMENT.?IN?NO?EVENT?SHALL?THE
AUTHORS?OR?COPYRIGHT?HOLDERS?BE?LIABLE?FOR?ANY?CLAIM?DAMAGES?OR?OTHER
LIABILITY?WHETHER?IN?AN?ACTION?OF?CONTRACT?TORT?OR?OTHERWISE?ARISING?FROM
OUT?OF?OR?IN?CONNECTION?WITH?THE?SOFTWARE?OR?THE?USE?OR?OTHER?DEALINGS?IN
THE?SOFTWARE.
****************************************************************************/
using?System;
namespace?home.MemoryEncrypt
{
????public?class?MemoryCheatException?:?Exception
????{
????????
????}
????class?MemoryEncrypt
????{
????????private?static?int?key;
????????private?static?long?longKey;
????????private?static?int?checkKey;
????????private?static?long?checkLongKey;
????????static?MemoryEncrypt()
????????{
????????????var?r?=?new?Random();
????????????key?=?r.Next(0x10000000?int.MaxValue);
????????????longKey?=?((long)key?<32)?+?key;
????????????checkKey?=?r.Next(0x10000000?int.MaxValue);
????????????checkLongKey?=?((long)checkKey?<32)?+?checkKey;
????????}
????????public?static?void?Do(int?value?out?int?val?out?int?check)
????????{
????????????val??=?value?^?key;
????????????check?=?value?^?checkKey;
????????}
????????public?static?int?UnDo(int?val?int?check)
????????{
????????????val??^=?key;
????????????check?^=?checkKey;
????????????if?(val?==?check)
????????????{
????????????????return?val;
????????????}
????????????throw?new?MemoryCheatException();
????????}
????????public?static?void?Do(long?value?out?long?val?out?long?check)
????????{
????????????val??=?value?^?longKey;
????????????check?=?value?^?checkLongKey;
????????}
????????public?static?long?UnDo(long?val?long?check)
????????{
????????????val??^=?longKey;
????????????check?^=?checkLongKey;
????????????if?(val?==?check)
????????????{
????????????????return?val;
????????????}
????????????throw?new?MemoryCheatException();
????????}
????????public?static?void?Do(float?value?out?int?val?out?int?check)
????????{
????????????val?=?BitConverter.ToInt32(BitConverter.GetBytes(value)?0)?^?key;
????????????check?=?BitConverter.ToInt32(BitConverter.GetBytes(valu
- 上一篇:C# rdlc報表嵌套子報表+源碼
- 下一篇:基于C#的串口自動收發例程
評論
共有 條評論