Skip to content

Commit

Permalink
v0.1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcook committed Jun 16, 2021
1 parent 2399e69 commit 3b6b2b1
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 9 deletions.
Binary file modified PCE.dll
Binary file not shown.
90 changes: 81 additions & 9 deletions PCE/PCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void Start()
CustomCard.BuildCard<GhostGunCard>();
CustomCard.BuildCard<TractorBeamCard>();
CustomCard.BuildCard<MoonShoesCard>();
//CustomCard.BuildCard<JetpackCard>(); // cannot set number of jumps greater than 1 but less than infinity
CustomCard.BuildCard<OldJetpackCard>();
CustomCard.BuildCard<FlipCard>();
CustomCard.BuildCard<GroundedCard>();
//CustomCard.BuildCard<AntCard>(); // small players have physics issues
Expand Down Expand Up @@ -423,6 +423,81 @@ private static void Prefix(Block __instance)

}
}
// fix the erroneous logic in PlayerJump.Jump by completely replacing. this is a terrible way of doing this.
[HarmonyPatch(typeof(PlayerJump), "Jump")]
class PlayerJumpPatchJump
{
private static bool Prefix(PlayerJump __instance, bool forceJump = false, float multiplier = 1f)
{
// read private/internal variables
CharacterData data = (CharacterData)Traverse.Create(__instance).Field("data").GetValue();
CharacterStatModifiers stats = (CharacterStatModifiers)Traverse.Create(__instance).Field("stats").GetValue();

if (!forceJump)
{
if (data.sinceJump < 0.1f)
{
return false;
}
if (data.currentJumps <= 0 && data.sinceWallGrab > 0.1f)
{
return false;
}
}
Vector3 a = Vector3.up;
Vector3 vector = data.groundPos;
if (__instance.JumpAction != null)
{
__instance.JumpAction();
}
bool flag = false;
if (data.sinceWallGrab < 0.1f && !data.isGrounded)
{
a = Vector2.up * 0.8f + data.wallNormal * 0.4f;
vector = data.wallPos;
data.currentJumps = data.jumps;
flag = true;
}
else
{
if (data.sinceGrounded > 0.05f)
{
vector = __instance.transform.position;
}
// this is the error in the original method
//data.currentJumps = data.jumps;
}
// read more private/internal fields
Vector2 velocity = (Vector2)Traverse.Create(data.playerVel).Field("velocity").GetValue();
if (velocity.y < 0f)
{
// assign new velocity which is an internal field
Traverse.Create(data.playerVel).Field("velocity").SetValue(new Vector2(velocity.x, 0f));
}
data.sinceGrounded = 0f;
data.sinceJump = 0f;
data.isGrounded = false;
data.isWallGrab = false;
data.currentJumps--;
// read another private/internal field
float mass = (float)Traverse.Create(data.playerVel).Field("mass").GetValue();
// call private/internal method
typeof(PlayerVelocity).InvokeMember("AddForce", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, data.playerVel, new object[] { a * multiplier * 0.01f * data.stats.jump * mass * (1f - stats.GetSlow()) * __instance.upForce, ForceMode2D.Impulse });
if (!flag)
{
typeof(PlayerVelocity).InvokeMember("AddForce", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, data.playerVel, new object[] { Vector2.right * multiplier * __instance.sideForce * 0.01f * data.stats.jump * mass * (1f - stats.GetSlow()) * velocity.x, ForceMode2D.Impulse });
}
for (int i = 0; i < __instance.jumpPart.Length; i++)
{
__instance.jumpPart[i].transform.position = new Vector3(vector.x, vector.y, 5f) - a * 0f;
__instance.jumpPart[i].transform.rotation = Quaternion.LookRotation(velocity);
__instance.jumpPart[i].Play();
}
return false; // do not run the base function or any postfixes.
}


}

}

Expand Down Expand Up @@ -707,33 +782,30 @@ protected override CardThemeColor.CardThemeColorType GetTheme()
return CardThemeColor.CardThemeColorType.TechWhite;
}
}
public class JetpackCard : CustomCard
public class OldJetpackCard : CustomCard
{
public override void SetupCard(CardInfo cardInfo, Gun gun, ApplyCardStats cardStats, CharacterStatModifiers statModifiers)
{

}
public override void OnAddCard(Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers characterStats)
{
// TODO: this doesn't work as intended... this gives infinite jumps instead of 10

data.jumps += 10;
characterStats.jump = 0.5f;
characterStats.movementSpeed *= 0.75f;
data.maxHealth *= 0.75f;

}
public override void OnRemoveCard()
{
}

protected override string GetTitle()
{
return "Jetpack";
return "Old Jetpack";
}
protected override string GetDescription()
{
return "Fly around for a bit";
return "Sputter around for a bit by continually firing this old jetpack";
}

protected override GameObject GetCardArt()
Expand All @@ -753,8 +825,8 @@ protected override CardInfoStat[] GetStats()
new CardInfoStat
{
positive = true,
stat = "Jetpack",
amount = "A",
stat = "Old Jetpack",
amount = "An",
simepleAmount = CardInfoStat.SimpleAmount.notAssigned
},
new CardInfoStat
Expand Down
9 changes: 9 additions & 0 deletions PCE/PCE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>Libs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ParticleSystemModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ROUNDS\Rounds_Data\Managed\UnityEngine.ParticleSystemModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Physics2DModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ROUNDS\Rounds_Data\Managed\UnityEngine.Physics2DModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ROUNDS\Rounds_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ A massive thanks to the people who helped me learn how to mod, especially Ascyst
- Balanced gravity effects
- Gravity effects no longer launch you at the ground once finished

- v0.1.7.0: new card, Old Jetpack
- New card
- Patched PlayerJump logic so that arbitrary numbers of jumps are possible

### Suggestions, Bug Reports, and Troubleshooting
-------------------------------------------------

Expand Down

0 comments on commit 3b6b2b1

Please sign in to comment.