本帖最后由 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 最后
能不能动一下你们的手指,给我评个分呗
|