-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
111 lines (96 loc) · 3.46 KB
/
Plugin.cs
File metadata and controls
111 lines (96 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using ModifiedMovement;
using ModifiedMovement.Patches;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace ModifiedMovement
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony(PluginInfo.PLUGIN_GUID);
public static Config Config { get; private set; }
public static Plugin Instance { get; internal set; }
public static new ManualLogSource Logger { get; private set; }
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
Logger = base.Logger;
Config = new(base.Config);
//harmony.PatchAll(typeof(Plugin));
//harmony.PatchAll(typeof(PlayerControllerBPatch));
//harmony.PatchAll(typeof(GameNetworkManager));
//harmony.PatchAll(typeof(Config));
harmony.PatchAll(Assembly.GetExecutingAssembly());
// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_NAME} is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ModifiedMovement";
public const string PLUGIN_NAME = "ModifiedMovement";
public const string PLUGIN_VERSION = "1.5.3";
}
}
namespace ModifiedMovement.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPostfix]
[HarmonyPatch("Update")]
static void ModifiedMovementPatch(ref float ___sprintMeter, ref bool ___isSprinting, ref bool ___isWalking, ref float ___sprintTime, ref float ___carryWeight, ref float ___sprintMultiplier)
{
if (___isSprinting)
{
___sprintMeter = Mathf.Clamp(___sprintMeter - ((Time.deltaTime / ___sprintTime * ___carryWeight) * Config.Instance.StaminaUsageMultiplier.Value), 0f, Config.Instance.MaxStaminaMultiplier.Value);
___sprintMultiplier = Mathf.Lerp(___sprintMultiplier, Config.Instance.SprintSpeed.Value, Time.deltaTime);
}
else
{
___sprintMultiplier = Mathf.Lerp(___sprintMultiplier, 1f, Time.deltaTime);
if (___isWalking)
{
___sprintMeter = Mathf.Clamp(___sprintMeter + ((Time.deltaTime / (___sprintTime + 9f)) * Config.Instance.StaminaRegenMultiplierWalking.Value), 0f, Config.Instance.MaxStaminaMultiplier.Value);
}
else
{
___sprintMeter = Mathf.Clamp(___sprintMeter + ((Time.deltaTime / (___sprintTime + 4f)) * Config.Instance.StaminaRegenMultiplierStationary.Value), 0f, Config.Instance.MaxStaminaMultiplier.Value);
}
}
}
[HarmonyPrefix]
[HarmonyPatch("Update")]
static void WalkClimbSpeedPatch(ref float ___movementSpeed, ref float ___climbSpeed, ref float ___limpMultiplier)
{
___movementSpeed = Config.Instance.MoveSpeed.Value;
___climbSpeed = Config.Instance.ClimbSpeed.Value;
___limpMultiplier = Config.Instance.LimpMultiplier.Value;
}
[HarmonyPrefix]
[HarmonyPatch("PlayerJump")]
static void ModifiedJumpPatch(ref float ___jumpForce)
{
___jumpForce = Config.Instance.JumpMultiplier.Value * 13f;
}
[HarmonyPostfix]
[HarmonyPatch("Jump_performed")]
static void ModifiedJumpStaminaPatch(ref float ___sprintMeter)
{
___sprintMeter = Mathf.Clamp(___sprintMeter - (0.08f * Config.Instance.JumpStaminaUsageMultiplier), 0f, Config.Instance.MaxStaminaMultiplier);
}
}
}