吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6518|回复: 24
收起左侧

[.NET逆向] 修改某Unity游戏实现飞行等功能(续)

  [复制链接]
growuphappily 发表于 2020-2-14 20:38
本帖最后由 growuphappily 于 2020-2-14 20:40 编辑

0x01 前言



你们别看我是个新人,我之前的账号被清理了,这次注册先发一个贴子,肯定不清了
继之前的帖子:https://www.52pojie.cn/thread-1103839-1-1.html
感谢你们对我的支持和鼓励,所以我准备再写一篇
(虽然不是一个账号,但是是我自己一个人写的,之前那个是别人的账号,这次自己注册了一个)
0x02 工具


DnSpy X 1
0x03 修改


继上一篇,我们继续修改
0x0301 跳跃修改
又该回到LegMuscles类的ApplyJumpImpulses()方法了
[C#] 纯文本查看 复制代码
private void ApplyJumpImpulses()
        {
                float d = 1f;
                for (int i = 0; i < this.human.groundManager.groundObjects.Count; i++)
                {
                        if (this.human.grabManager.IsGrabbed(this.human.groundManager.groundObjects[i]))
                        {
                                d = 0.75f;
                        }
                }
                Vector3 a = Vector3.up * this.upImpulse * d;
                Vector3 a2 = this.human.controls.walkDirection.normalized * this.forwardImpulse * d;
                this.ragdoll.partHead.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partChest.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partWaist.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partHips.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partBall.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partLeftThigh.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightThigh.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftLeg.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightLeg.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftFoot.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightFoot.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftArm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightArm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftForearm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightForearm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.human.groundManager.DistributeForce(-a / Time.fixedDeltaTime, this.ragdoll.partBall.rigidbody.position);
        }

我们知道,d这个变量就是跳跃高度
添加jump字段:
[C#] 纯文本查看 复制代码
public static float jump = 1f;

修改一下ApplyJumpImpulses()方法:
[C#] 纯文本查看 复制代码
private void ApplyJumpImpulses()
        {
                float d = jump;        //更改d的值为jump
                for (int i = 0; i < this.human.groundManager.groundObjects.Count; i++)
                {
                        if (this.human.grabManager.IsGrabbed(this.human.groundManager.groundObjects[i]))
                        {
                                d = 0.75f * jump;        //暂时这样吧,保持比例1:0.75
                }
                Vector3 a = Vector3.up * this.upImpulse * d;
                Vector3 a2 = this.human.controls.walkDirection.normalized * this.forwardImpulse * d;
                this.ragdoll.partHead.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partChest.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partWaist.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partHips.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partBall.rigidbody.SafeAddForce(a * 0.1f + a2 * 0.1f, ForceMode.Impulse);
                this.ragdoll.partLeftThigh.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightThigh.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftLeg.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightLeg.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftFoot.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightFoot.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftArm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightArm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partLeftForearm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.ragdoll.partRightForearm.rigidbody.SafeAddForce(a * 0.05f + a2 * 0.05f, ForceMode.Impulse);
                this.human.groundManager.DistributeForce(-a / Time.fixedDeltaTime, this.ragdoll.partBall.rigidbody.position);
        }

具体jump的值如何在游戏中修改请看0x0303

0x0302 缓降修改
我们先去Human类里面看看有没有思路
发现了一个可疑的方法:ProcessFall  (机翻:执行掉落)贴上它的代码
[C#] 纯文本查看 复制代码
        private void ProcessFall()
    {
        this.PushGroundAngle();
        bool flag = false;
        if (this.groundAnglesSum / (float)this.groundAngles.Length > 45f)
        {
            flag = true;
            this.slideTimer = 0f;
            this.onGround = false;
            this.state = HumanState.Slide;
        }
        else if (this.state == HumanState.Slide && this.groundAnglesSum / (float)this.groundAngles.Length < 37f && this.ragdoll.partBall.rigidbody.velocity.y > -1f)
        {
            this.slideTimer += Time.fixedDeltaTime;
            if (this.slideTimer < 0.003f)
            {
                this.onGround = false;
            }
        }
        if (!this.onGround && !flag)
        {
            if (this.fallTimer < 5f)
            {
                this.fallTimer += Time.deltaTime;
            }
            if (this.state == HumanState.Climb)
            {
                this.fallTimer = 0f;
            }
            if (this.fallTimer > 3f)
            {
                this.state = HumanState.FreeFall;
            }
            else if (this.fallTimer > 1f)
            {
                this.state = HumanState.Fall;
            }
        }
        else
        {
            this.fallTimer = 0f;
        }
    }[color=#dcdcdc]
[/color]


我注意到:在建几个if和else if块中,Human.onGround都被修改成false
只有最后一个没有修改
所以我们先添加nofall字段
[C#] 纯文本查看 复制代码
public static bool nofall ;

修改代码:
[Asm] 纯文本查看 复制代码
        private void ProcessFall()
        {
                if(nofall){
                        this.fallTimer = 0f;
                        return;
                        }
                this.PushGroundAngle();
                bool flag = false;
                if (this.groundAnglesSum / (float)this.groundAngles.Length > 45f)
                {
                        flag = true;
                        this.slideTimer = 0f;
                        this.onGround = false;
                        this.state = HumanState.Slide;
                }
                else if (this.state == HumanState.Slide && this.groundAnglesSum / (float)this.groundAngles.Length < 37f && this.ragdoll.partBall.rigidbody.velocity.y > -1f)
                {
                        this.slideTimer += Time.fixedDeltaTime;
                        if (this.slideTimer < 0.003f)
                        {
                                this.onGround = false;
                        }
                }
                if (!this.onGround && !flag)
                {
                        if (this.fallTimer < 5f)
                        {
                                this.fallTimer += Time.deltaTime;
                        }
                        if (this.state == HumanState.Climb)
                        {
                                this.fallTimer = 0f;
                        }
                        if (this.fallTimer > 3f)
                        {
                                this.state = HumanState.FreeFall;
                        }
                        else if (this.fallTimer > 1f)
                        {
                                this.state = HumanState.Fall;
                        }
                }
                else
                {
                        this.fallTimer = 0f;
                }
        }

(我没有测试,行不行不确定,大家可以自己尝试下)
0x0303 修改CheatCodes类
回到CheatCodes类,在Start方法中加入2句代码:
[C#] 纯文本查看 复制代码
Shell.RegisterCommand("nofall",new Action(this.nofall),null);
Shell.RegisterCommand("jump",new Action<string>(this.jump),null);

添加2个方法:
[Asm] 纯文本查看 复制代码
private void jump(string a)
{
    try(
    LegMuscles.jump = float.tryParse(a);
    }
    catch(
    Shell.Print("ERROR")
    }
}
private void nofall()
{
    Human.nofall = ! Human.nofall;
    Shell.Print("no fall mode " + (Human.nofall ? "on" : "off"));
}

(我没有测试,大家有兴趣可以测试一下)

0x04 最后
能不能动一下你们的手指,给我评个分呗



免费评分

参与人数 19吾爱币 +21 热心值 +16 收起 理由
Chinese666 + 1 厉害了
smaller99 + 1 + 1 谢谢@Thanks!
Hmily + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
扫地的萝卜 + 1 + 1 热心回复!
破解者灬禄 + 1 + 1 我希望您可以教导我学习,让我们变得更好。
睡觉额很多看到 + 1 我很赞同!
远方i + 1 + 1 我很赞同!
jackie_yaolu + 1 + 1 我很赞同!
Kaze + 1 + 1 我很赞同!
BG沉默 + 1 谢谢@Thanks!
sur_vant + 1 + 1 我很赞同!
老卷子 + 1 我很赞同!
nowOverQuartz + 1 + 1 我很赞同!
wisdom3176 + 1 + 1 用心讨论,共获提升!
FFF全部成为F + 1 非常感谢,之前在哔哩哔哩里面看到有人发视频不发教程
sunyoung0103 + 1 我很赞同!
橙影 + 1 + 1 用心讨论,共获提升!
世不待 + 1 谢谢@Thanks!
NB2665597272 + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| growuphappily 发表于 2020-2-15 08:47
cheewei 发表于 2020-2-15 08:44
我是小白,想问有什么Unity游戏可以修改这代码??

只要是Assembly-CSharp.dll没被加壳就行
加了壳可以尝试用de4dot脱壳

你可以先去看看之前的帖子
 楼主| growuphappily 发表于 2020-2-15 14:27
nowOverQuartz 发表于 2020-2-15 14:21
主要是没时间,今年中考

时间就像海绵,只要你去挤,他总会有的
                                                                                             ---忘了是谁说的
111234jgf 发表于 2020-2-15 00:06
XSHqiangzhuang 发表于 2020-2-15 00:21
谢谢分享 3Q
cheewei 发表于 2020-2-15 08:44
我是小白,想问有什么Unity游戏可以修改这代码??
nowOverQuartz 发表于 2020-2-15 10:11
问个问题,搜索只能在选择的那一部分代码里进行,但是它有很多部分,怎么知道哪一个才是要找的部分
 楼主| growuphappily 发表于 2020-2-15 10:23
nowOverQuartz 发表于 2020-2-15 10:11
问个问题,搜索只能在选择的那一部分代码里进行,但是它有很多部分,怎么知道哪一个才是要找的部分

看方法名或者是类名
简单分析下代码
头像被屏蔽
我是一颗小虎牙 发表于 2020-2-15 11:41
提示: 作者被禁止或删除 内容自动屏蔽
ht8086 发表于 2020-2-15 11:41
谢谢分享 3Q
csxiewei 发表于 2020-2-15 11:50
这游戏学会爬墙都严重影响游戏体验了,飞行就更不用说了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 04:57

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表