Skip to content

Commit

Permalink
feat: half drawn bow sync
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Nov 30, 2021
1 parent da1a7e2 commit 120ea21
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
37 changes: 29 additions & 8 deletions Code/client/Games/Skyrim/Projectiles/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@
#include <Events/ProjectileLaunchedEvent.h>
#include <Games/Skyrim/Forms/TESObjectCELL.h>

TP_THIS_FUNCTION(TLaunch, void*, void, Projectile::LaunchData& arData);

TP_THIS_FUNCTION(TLaunch, uint32_t*, void, Projectile::LaunchData& arData);
static TLaunch* RealLaunch = nullptr;

void* Projectile::Launch(void* apResult, LaunchData& apLaunchData) noexcept
uint32_t* Projectile::Launch(void* apResult, LaunchData& apLaunchData) noexcept
{
return ThisCall(RealLaunch, apResult, apLaunchData);
auto result = ThisCall(RealLaunch, apResult, apLaunchData);

TP_ASSERT(result, "No projectile handle returned.");

auto* pObject = TESObjectREFR::GetByHandle(*result);
auto* pProjectile = RTTI_CAST(pObject, TESObjectREFR, Projectile);

TP_ASSERT(pProjectile, "No projectile found.");

pProjectile->fPower = apLaunchData.fPower;

return result;
}

// Projectile::Launch() is still somehow dependent on its shooter.
// Therefore, this can only be used to sync arrows, really.
// TODO: sync projectiles other than arrows, and make arrows work with half drawn bows.
void* TP_MAKE_THISCALL(HookLaunch, void, Projectile::LaunchData& arData)
uint32_t* TP_MAKE_THISCALL(HookLaunch, void, Projectile::LaunchData& arData)
{
if (!arData.pSpell)
return ThisCall(RealLaunch, apThis, arData);
//if (!arData.pSpell)
//return ThisCall(RealLaunch, apThis, arData);

if (arData.pShooter)
{
Expand Down Expand Up @@ -68,9 +78,20 @@ void* TP_MAKE_THISCALL(HookLaunch, void, Projectile::LaunchData& arData)
Event.Tracer = arData.bTracer;
Event.ForceConeOfFire = arData.bForceConeOfFire;

auto result = ThisCall(RealLaunch, apThis, arData);

TP_ASSERT(result, "No projectile handle returned.");

auto* pObject = TESObjectREFR::GetByHandle(*result);
auto* pProjectile = RTTI_CAST(pObject, TESObjectREFR, Projectile);

TP_ASSERT(pProjectile, "No projectile found.");

Event.Power = pProjectile->fPower;

World::Get().GetRunner().Trigger(Event);

return ThisCall(RealLaunch, apThis, arData);
return result;
}

static TiltedPhoques::Initializer s_projectileHooks([]() {
Expand Down
12 changes: 11 additions & 1 deletion Code/client/Games/Skyrim/Projectiles/Projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ struct Projectile : TESObjectREFR
bool bForceConeOfFire; // unsure // init to false
};

static void* Launch(void* apResult, LaunchData& arData) noexcept;
uint8_t unk98[0xF0];
// TODO: get fPower after Projectile::Launch() function has finished
float fPower;
float fSpeedMult;
float fRange;
float fAge;
float fDamage;

static uint32_t* Launch(void* apResult, LaunchData& arData) noexcept;
};

constexpr size_t t = offsetof(Projectile, fPower);

static_assert(sizeof(Projectile::LaunchData) == 0xA8);

0 comments on commit 120ea21

Please sign in to comment.