修改某Unity游戏实现飞行等功能(续)
本帖最后由 growuphappily 于 2020-2-14 20:40 编辑0x01 前言
------------------------
你们别看我是个新人,我之前的账号被清理了,这次注册先发一个贴子,肯定不清了{:301_1008:}
继之前的帖子:https://www.52pojie.cn/thread-1103839-1-1.html
感谢你们对我的支持和鼓励,所以我准备再写一篇
(虽然不是一个账号,但是是我自己一个人写的,之前那个是别人的账号,这次自己注册了一个)
0x02 工具
------------------------
DnSpy X 1
0x03 修改
------------------------
继上一篇,我们继续修改
0x0301 跳跃修改
又该回到LegMuscles类的ApplyJumpImpulses()方法了
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))
{
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字段:
public static float jump = 1f;
修改一下ApplyJumpImpulses()方法:
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))
{
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(机翻:执行掉落)贴上它的代码
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;
}
}
我注意到:在建几个if和else if块中,Human.onGround都被修改成false
只有最后一个没有修改
所以我们先添加nofall字段
public static bool nofall ;
修改代码:
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句代码:
Shell.RegisterCommand("nofall",new Action(this.nofall),null);
Shell.RegisterCommand("jump",new Action<string>(this.jump),null);
添加2个方法:
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 最后
能不能动一下你们的手指,给我评个分呗{:301_997:}{:301_978:}
cheewei 发表于 2020-2-15 08:44
我是小白,想问有什么Unity游戏可以修改这代码??
只要是Assembly-CSharp.dll没被加壳就行
加了壳可以尝试用de4dot脱壳
你可以先去看看之前的帖子 nowOverQuartz 发表于 2020-2-15 14:21
主要是没时间,今年中考
时间就像海绵,只要你去挤,他总会有的
---忘了是谁说的 感谢分享 谢谢分享 3Q 我是小白,想问有什么Unity游戏可以修改这代码?? 问个问题,搜索只能在选择的那一部分代码里进行,但是它有很多部分,怎么知道哪一个才是要找的部分 nowOverQuartz 发表于 2020-2-15 10:11
问个问题,搜索只能在选择的那一部分代码里进行,但是它有很多部分,怎么知道哪一个才是要找的部分
看方法名或者是类名
简单分析下代码 谢谢分享 3Q 这游戏学会爬墙都严重影响游戏体验了,飞行就更不用说了