Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly faster private field access #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Source/DualWield/Harmony/PawnRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}
}
*/
static bool Prefix(PawnRenderer __instance, Thing eq, ref Vector3 drawLoc, ref float aimAngle)
static bool Prefix(PawnRenderer __instance, Pawn ___pawn, Thing eq, ref Vector3 drawLoc, ref float aimAngle)
{
ThingWithComps offHandEquip = null;
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
if (pawn.equipment == null)
if (___pawn.equipment == null)
{
return true;
}
if (pawn.equipment.TryGetOffHandEquipment(out ThingWithComps result))
if (___pawn.equipment.TryGetOffHandEquipment(out ThingWithComps result))
{
offHandEquip = result;
}
Expand All @@ -62,11 +61,11 @@ static bool Prefix(PawnRenderer __instance, Thing eq, ref Vector3 drawLoc, ref f
}
float mainHandAngle = aimAngle;
float offHandAngle = aimAngle;
Stance_Busy mainStance = pawn.stances.curStance as Stance_Busy;
Stance_Busy mainStance = ___pawn.stances.curStance as Stance_Busy;
Stance_Busy offHandStance = null;
if (pawn.GetStancesOffHand() != null)
if (___pawn.GetStancesOffHand() != null)
{
offHandStance = pawn.GetStancesOffHand().curStance as Stance_Busy;
offHandStance = ___pawn.GetStancesOffHand().curStance as Stance_Busy;
}
LocalTargetInfo focusTarg = null;
if (mainStance != null && !mainStance.neverAimWeapon)
Expand All @@ -86,9 +85,9 @@ static bool Prefix(PawnRenderer __instance, Thing eq, ref Vector3 drawLoc, ref f
//bool currentlyAiming = (mainStance != null && !mainStance.neverAimWeapon && mainStance.focusTarg.IsValid) || stancesOffHand.curStance is Stance_Busy ohs && !ohs.neverAimWeapon && ohs.focusTarg.IsValid;
//When wielding offhand weapon, facing south, and not aiming, draw differently

SetAnglesAndOffsets(eq, offHandEquip, aimAngle, pawn, ref offsetMainHand, ref offsetOffHand, ref mainHandAngle, ref offHandAngle, mainHandAiming, offHandAiming);
SetAnglesAndOffsets(eq, offHandEquip, aimAngle, ___pawn, ref offsetMainHand, ref offsetOffHand, ref mainHandAngle, ref offHandAngle, mainHandAiming, offHandAiming);

if (offHandEquip != pawn.equipment.Primary)
if (offHandEquip != ___pawn.equipment.Primary)
{
//drawLoc += offsetMainHand;
//aimAngle = mainHandAngle;
Expand Down