Skip to content

Commit

Permalink
Port to BONELAB and add configurable profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanaellio committed Oct 17, 2022
1 parent 0ce9000 commit 71a4fab
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 103 deletions.
169 changes: 93 additions & 76 deletions HyperJump/HyperJump.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using MelonLoader;
using StressLevelZero.Rig;
using System.Collections.Generic;
using MelonLoader;
using SLZ.Rig;
using UnityEngine;
using HarmonyLib;
using Il2CppSystem;
using StressLevelZero.VRMK;
using Object = UnityEngine.Object;
using SLZ.VRMK;
using UnityObject = UnityEngine.Object;
using Enum = System.Enum;

namespace Evanaellio.HyperJump
{
Expand All @@ -13,119 +15,134 @@ public static class BuildInfo
public const string Name = "Hyper Jump";
public const string Author = "Evanaellio";
public const string Company = null;
public const string Version = "1.1.0";
public const string DownloadLink = "https://boneworks.thunderstore.io/package/Evanaellio/HyperJump/";
public const string Version = "2.0.0";
public const string DownloadLink = "https://bonelab.thunderstore.io/package/Evanaellio/HyperJump/";
}

public class HyperJump : MelonMod
{
private const string HyperJumpCategory = nameof(HyperJump);
private const string CustomProfileCategory = "HyperJumpCustomProfile";

public static float UpwardJumpMultiplier
public static ProfilesEnum ActiveProfile
{
get => MelonPreferences.GetEntryValue<float>(HyperJumpCategory, nameof(UpwardJumpMultiplier));
set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(UpwardJumpMultiplier), value);
get
{
string activeProfile = MelonPreferences.GetEntryValue<string>(HyperJumpCategory, nameof(ActiveProfile));
if (Enum.TryParse(activeProfile, true, out ProfilesEnum profile))
{
return profile;
}

MelonLogger.Warning($"Invalid profile '{activeProfile}', using the default profile instead");
return ProfilesEnum.Default;
}

set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(ActiveProfile), value.ToString().ToLowerInvariant());
}

public static float ForwardLeapMultiplier
public class Profile
{
get => MelonPreferences.GetEntryValue<float>(HyperJumpCategory, nameof(ForwardLeapMultiplier));
set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(ForwardLeapMultiplier), value);
public float UpwardJumpMultiplier { get; set; }
public float ForwardLeapMultiplier { get; set; }
public float JumpChargingTime { get; set; }
}

public static bool HyperJumpEnabled
private static readonly Profile DefaultProfile = new Profile()
{
get => MelonPreferences.GetEntryValue<bool>(HyperJumpCategory, nameof(HyperJumpEnabled));
set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(HyperJumpEnabled), value);
}
UpwardJumpMultiplier = 90f, ForwardLeapMultiplier = 18f, JumpChargingTime = 1.5f,
};

public static bool JumpChargingEnabled
private static readonly Profile InstantProfile = new Profile()
{
get => MelonPreferences.GetEntryValue<bool>(HyperJumpCategory, nameof(JumpChargingEnabled));
set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(JumpChargingEnabled), value);
}
UpwardJumpMultiplier = DefaultProfile.UpwardJumpMultiplier, ForwardLeapMultiplier = DefaultProfile.ForwardLeapMultiplier, JumpChargingTime = 0f,
};

public static readonly Dictionary<ProfilesEnum, Profile> Profiles = new Dictionary<ProfilesEnum, Profile>()
{
{ProfilesEnum.Default, DefaultProfile},
{ProfilesEnum.Instant, InstantProfile},
};

public static float JumpChargingTime

public enum ProfilesEnum
{
get => MelonPreferences.GetEntryValue<float>(HyperJumpCategory, nameof(JumpChargingTime));
set => MelonPreferences.SetEntryValue(HyperJumpCategory, nameof(JumpChargingTime), value);
Default,
Instant,
Disabled,
Custom
}

public override void OnApplicationStart()
public override void OnInitializeMelon()
{
// Create MelonPreferences default values (if they don't exist already)
MelonPreferences.CreateCategory(HyperJumpCategory);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(UpwardJumpMultiplier), 16f);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(ForwardLeapMultiplier), 3f);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(JumpChargingEnabled), true);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(JumpChargingTime), 1.5f);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(HyperJumpEnabled), true);

// ModThatIsNotMod Menu
ModThatIsNotMod.BoneMenu.MenuCategory category =
ModThatIsNotMod.BoneMenu.MenuManager.CreateCategory("Hyper Jump", Color.green);
category.CreateFloatElement("Upward Jump Multiplier", Color.white, UpwardJumpMultiplier,
newValue => UpwardJumpMultiplier = newValue, 4f, 0f, 40f, true);
category.CreateFloatElement("Forward Leap Multiplier", Color.white, ForwardLeapMultiplier,
newValue => ForwardLeapMultiplier = newValue, 0.5f, 0f, 5f, true);
category.CreateBoolElement("Enable Jump Charging", Color.white, JumpChargingEnabled,
newValue => JumpChargingEnabled = newValue);
category.CreateFloatElement("Jump Charging Time (seconds)", Color.white, JumpChargingTime,
newValue => JumpChargingTime = newValue, 0.5f, 0f, 4f, true);
category.CreateBoolElement("Enable Hyper Jump", Color.red, HyperJumpEnabled,
newValue => HyperJumpEnabled = newValue);
MelonPreferences.CreateCategory(CustomProfileCategory);
MelonPreferences.CreateEntry(HyperJumpCategory, nameof(ActiveProfile), "default");
MelonPreferences.CreateEntry(CustomProfileCategory, nameof(Profile.UpwardJumpMultiplier), DefaultProfile.UpwardJumpMultiplier);
MelonPreferences.CreateEntry(CustomProfileCategory, nameof(Profile.ForwardLeapMultiplier), DefaultProfile.ForwardLeapMultiplier);
MelonPreferences.CreateEntry(CustomProfileCategory, nameof(Profile.JumpChargingTime), DefaultProfile.JumpChargingTime);

Profiles.Add(ProfilesEnum.Custom, new Profile
{
UpwardJumpMultiplier = MelonPreferences.GetEntryValue<float>(CustomProfileCategory, nameof(Profile.UpwardJumpMultiplier)),
ForwardLeapMultiplier = MelonPreferences.GetEntryValue<float>(CustomProfileCategory, nameof(Profile.ForwardLeapMultiplier)),
JumpChargingTime = MelonPreferences.GetEntryValue<float>(CustomProfileCategory, nameof(Profile.JumpChargingTime)),
});
}
}

[HarmonyPatch(typeof(ControllerRig), "Jump")]
class ControllerRigJumpPatch
[HarmonyPatch(typeof(ControllerRig), "JumpCharge")]
class ControllerRigJumpChargePatch
{
public static void Postfix(ControllerRig __instance)
public static DateTime? JumpChargeStartedDate = null;

public static void Postfix(ControllerRig __instance, bool chargeInput)
{
if (!HyperJump.HyperJumpEnabled) return;
// Skip HyperJump behaviour for the disabled profile
if (HyperJump.ActiveProfile.Equals(HyperJump.ProfilesEnum.Disabled)) return;
HyperJump.Profile currentProfile = HyperJump.Profiles[HyperJump.ActiveProfile];

var physGrounder = Object.FindObjectOfType<PhysGrounder>();
// chargeInput is true when the jump button is being pressed
if (chargeInput && !JumpChargeStartedDate.HasValue)
{
JumpChargeStartedDate = DateTime.Now;
}
else if (!chargeInput && JumpChargeStartedDate.HasValue)
{
// When jump button is released, trigger hyper jump then reset jump charging
TriggerHyperJump(__instance, currentProfile);
JumpChargeStartedDate = null;
}
}

private static void TriggerHyperJump(ControllerRig controllerRig, HyperJump.Profile profile)
{
var physGrounder = UnityObject.FindObjectOfType<PhysGrounder>();
// Only jump when on the ground
if (physGrounder.isGrounded)
{
PhysicsRig rig = Object.FindObjectOfType<PhysicsRig>();
PhysicsRig rig = UnityObject.FindObjectOfType<PhysicsRig>();

float jumpChargeRatio = 1f;
// Compute jump charging ratio (between 0 and 1) if charging is enabled
if (HyperJump.JumpChargingEnabled)

// Compute jump charging ratio (between 0 and 1) if charging is enabled (charging time greater than 0)
if (profile.JumpChargingTime > 0)
{
TimeSpan jumpChargeDuration =
(DateTime.Now - ControllerRigJumpChargePatch.jumpChargeStartedDate) ?? TimeSpan.Zero;
jumpChargeRatio = Mathf.InverseLerp(0.0f, HyperJump.JumpChargingTime * 1000, (float) jumpChargeDuration.TotalMilliseconds);
(DateTime.Now - JumpChargeStartedDate) ?? TimeSpan.Zero;
jumpChargeRatio = Mathf.InverseLerp(0.0f, profile.JumpChargingTime * 1000,
(float) jumpChargeDuration.TotalMilliseconds);
}

// Compute velocity vectors for jumping (up) and leaping (forward)
float walkSpeed = new Vector3(rig.pelvisVelocity.x, 0, rig.pelvisVelocity.z).magnitude;
Vector3 forwardJump = __instance.m_head.forward * walkSpeed * HyperJump.ForwardLeapMultiplier;
Vector3 verticalJump = Vector3.up * HyperJump.UpwardJumpMultiplier;

// Apply jump velocity to the player
rig.physBody.rbPelvis.AddForce((verticalJump + forwardJump) * jumpChargeRatio, ForceMode.VelocityChange);
}
}
}
Vector3 forwardJump = controllerRig.m_head.forward * walkSpeed * profile.ForwardLeapMultiplier;
Vector3 verticalJump = Vector3.up * profile.UpwardJumpMultiplier;

[HarmonyPatch(typeof(ControllerRig), "JumpCharge")]
class ControllerRigJumpChargePatch
{
public static DateTime? jumpChargeStartedDate = null;

public static void Postfix(ControllerRig __instance, bool chargeInput)
{
// chargeInput is true when the jump button is being pressed
if (chargeInput && !jumpChargeStartedDate.HasValue)
{
jumpChargeStartedDate = DateTime.Now;
} else if (!chargeInput && jumpChargeStartedDate.HasValue)
{
jumpChargeStartedDate = null;
// Apply jump velocity to the player
rig.torso.rbPelvis.AddForce((verticalJump + forwardJump) * jumpChargeRatio,
ForceMode.VelocityChange);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions HyperJump/HyperJump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<BoneworksFolder>C:\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS</BoneworksFolder>
<BonelabFolder>C:\Program Files (x86)\Steam\steamapps\common\BONELAB</BonelabFolder>
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -36,17 +36,17 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.9.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(BonelabFolder)\MelonLoader\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Il2Cppmscorlib">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>$(BoneworksFolder)\MelonLoader\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="ModThatIsNotMod">
<HintPath>$(BoneworksFolder)\Mods\ModThatIsNotMod.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -56,16 +56,16 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnhollowerBaseLib">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\UnityEngine.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>$(BoneworksFolder)\MelonLoader\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>$(BonelabFolder)\MelonLoader\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -75,7 +75,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
COPY "$(TargetPath)" "$(BoneworksFolder)\Mods"
COPY "$(TargetPath)" "$(BonelabFolder)\Mods"
COPY "$(TargetPath)" "$(MSBuildProjectDirectory)\..\ThunderstorePackage\Mods"
</PostBuildEvent>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion HyperJump/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
// Create and Setup a MelonModGame to mark a Mod as Universal or Compatible with specific Games.
// If no MelonModGameAttribute is found or any of the Values for any MelonModGame on the Mod is null or empty it will be assumed the Mod is Universal.
// Values for MelonModGame can be found in the Game's app.info file or printed at the top of every log directly beneath the Unity version.
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
42 changes: 30 additions & 12 deletions ThunderstorePackage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,45 @@

Jump higher and leap further.

To install the mod, copy the Mods folder inside the zip into your Boneworks directory.
To install the mod, copy the Mods folder inside the zip into your BONELAB directory.

Hyper jumps and leaps are best used in exterior environments (unless you like fracturing your skull on the ceiling or
smashing your face against a wall).
Hyper jumps and leaps are best used in exterior environments (unless you like fracturing your skull on the ceiling or smashing your face against a wall).

Hyper leaps only apply when walking/running, and will propel you towards where you are looking.

Hyper jumps/leaps can be charged so that the jump power scales with how long the jump button was pressed for. If disabled, all jumps will be performed at max power.
Hyper jumps/leaps can be charged so that the jump power scales with how long the jump button was pressed for.

Use Bonemenu to configure the following :
You can edit your MelonPreferences.cfg file in order to customize your HyperJump experience. By default, it's configured like this :

| Property | Description | Default Value |
|------------------------------|-------------------------------------------------------------------------|---------------|
| Upward Jump Multiplier | How high the hyper jumps will go | 16 |
| Forward Leap Multiplier | How far the hyper leaps will go | 3 |
| Enable Jump Charging | Enables scaling jump power with charge time | true |
| Jump Charging Time (seconds) | How many seconds to hold the jump button until you reach max jump power | 1.5 |
| Enable Hyper Jump | Enables or disables the hyper jumps/leaps entirely | true |
```ini
[HyperJump]
ActiveProfile = "default"

[HyperJumpCustomProfile]
UpwardJumpMultiplier = 90.0
ForwardLeapMultiplier = 18.0
JumpChargingTime = 1.5
```

ActiveProfile can take the following values :
`default` the default HyperJump profile
`instant` same as the default but all jumps will be performed at max power
`disabled` disables HyperJump
`custom` uses the parameters from the `[HyperJumpCustomProfile]` section, which is initially the same as the default profile

| Custom property | Description |
|-----------------------|-----------------------------------------------------------------------------------------------------------|
| UpwardJumpMultiplier | How high the hyper jumps will go |
| ForwardLeapMultiplier | How far the hyper leaps will go |
| JumpChargingTime | How many seconds to hold the jump button until you reach max jump power, set to 0 for instant hyper jumps |

## Changelogs

#### v2.0.0

- Port from BONEWORKS to BONELAB
- Add configurable profiles

#### v1.1.0:

- Add jump charging
Expand Down
Binary file modified ThunderstorePackage/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ThunderstorePackage/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "HyperJump",
"version_number": "1.1.0",
"version_number": "2.0.0",
"description": "Jump higher and leap further",
"website_url": "https://github.com/Evanaellio/HyperJump",
"dependencies": ["gnonme-ModThatIsNotMod-0.2.4"]
"dependencies": []
}

0 comments on commit 71a4fab

Please sign in to comment.