zoukankan      html  css  js  c++  java
  • CocosCreator 防内存修改

    版本:2.4.3

    参考:

    如何防止工具(八门神器)进行内存修改

    修改内存工具,类似以前玩仙剑奇侠传的修改器金手指之类,查找金币1000,然后金币改变到1200,再查找1200。

    根据多次查找锁定金币的内存位置,然后修改为99999.

    可以将保存的关键数据进行异或后保存,取出来时才经过异或获取。或者和参考中一样使用md5等方式将数据改变后再保存,避开内存修改器直接查找数值来进行修改。

    @ccclass
    export default class test_setShader extends cc.Component {
    
        public num:number = 999;
        public key:number = 0;
    
        onLoad() {
            this.key = this.num*Math.random();
            this.num = this.num^this.key;
            console.log(this.num);           //随机值
            console.log(this.num^this.key);  //999
        }
    }
    

      

    做成一个工具类EncodeNumber,将需要防内存修改的属性传入。

    const { ccclass, property } = cc._decorator;
    
    @ccclass
    export default class Test extends cc.Component {
    
        public gold:number = 999;    //金币
    
        onLoad() {
            //防内存修改属性
            EncodeNumber.encode(this, "gold");
    
            this.node.on(cc.Node.EventType.TOUCH_END,()=>{
                let rand = Math.random()*1000;
                this.gold = rand;
                console.log("随机数:",rand, "拥有金币:", this.gold);
            },this);
        }
    }
    
    class EncodeNumber{
        private static num = {};        //存放原始值
        private static key = {};        //存放异或的key
        private static key_num = {};    //存放异或后的值
        
        public static encode(thisObj:any, propertyKey:string){
            Object.defineProperty(thisObj, propertyKey, {
                get:()=>{
                    if(this.key_num[propertyKey] != null && this.key[propertyKey] != null){
                        console.log("get",this.key[propertyKey], this.key_num[propertyKey]);
                        if((this.num[propertyKey]^this.key[propertyKey]) != this.key_num[propertyKey]){
                            console.log("值被修改");
                            return 0;
                        }else{
                            console.log("值正常");
                            return this.key_num[propertyKey] ^this.key[propertyKey];
                        }
                    }else{
                        console.log("没有初始值");
                        return 0;
                    }
                },
                set:(value)=>{
                    this.num[propertyKey] = value;
                    this.key[propertyKey] = Math.random()*1000;
                    this.key_num[propertyKey] = this.key[propertyKey]^value;
                    console.log("set",this.key[propertyKey], this.key_num[propertyKey]);
                }
            });
        }
    }
    

      

  • 相关阅读:
    软件工程第九周总结
    作为使用者对qq拼音输入法和搜狗输入法的评价
    关于编写Windows程序中启动兼容性问题
    软件工程第八周总结
    Java实验--关于课上找“水王”问题分析
    大道至简阅读笔记03
    家庭记账本-----一
    《人月神话》读后感----一到三章
    Java实现数据库与eclipse的连接
    流和文件
  • 原文地址:https://www.cnblogs.com/gamedaybyday/p/13880554.html
Copyright © 2011-2022 走看看