Skip to content

Commit

Permalink
Ped Randomizer: Fish can now fly :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parik27 committed Jun 8, 2021
1 parent a281e81 commit 125b49a
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
401
407
49 changes: 49 additions & 0 deletions lib/CPed.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "CVehicle.hh"
#include "Patterns/Patterns.hh"
#include <Utils.hh>
#include <CPed.hh>

void *(*CPedInventory__GiveWeapon) (CPedInventory *, uint32_t, uint32_t);
CInventoryItem *(*CInventoryItemRepository__FindWeapon) (
CInventoryItemRepository *, uint32_t);
CPed *(*fwScriptGuidPool__GetPed) (uint32_t handle);
CMotionTaskDataSet *(*CMotionTaskDataManager__FindByName) (uint32_t name);
aiTask *(*CPed__CreateMotionTask) (CPed *, sMotionTaskData *, bool);

/*******************************************************/
CInventoryItem *__cdecl CInventoryItemRepository::FindWeapon (uint32_t hash)
Expand Down Expand Up @@ -60,6 +64,41 @@ CPedInventory::AddWeapon (uint32_t hash, uint32_t ammo)
return CPedInventory__GiveWeapon (this, hash, ammo);
}

/*******************************************************/
CMotionTaskDataSet *
CMotionTaskDataManager::FindByName (uint32_t name)
{
return CMotionTaskDataManager__FindByName (name);
}

/*******************************************************/
aiTask *
CPed::CreateMotionTask (sMotionTaskData *set, bool lowLod)
{
return CPed__CreateMotionTask (this, set, lowLod);
}

/*******************************************************/
CVehicle *
CPed::GetVehicle ()
{
static uint32_t nVehicleIndex = *hook::get_pattern<uint32_t> (
"8b ? ? ? ? ? c1 e8 1e 41 84 c5 74 ? ? 83 ? ? ? ? ? 00 74 ? ba 0c 00 "
"00 00 e9",
17);

return *GetAtOffset<CVehicle *> (this, nVehicleIndex);
}

/*******************************************************/
uint32_t
CPed::GetMotionState ()
{
static uint32_t nMotionStateIndex = *hook::get_pattern<uint32_t> (
"44 8b f2 ? 8b e9 e8 ? ? ? ? 33 ff 44 89 ? ? ? ? ?", 16);
return *GetAtOffset<uint32_t> (this, nMotionStateIndex);
}

/*******************************************************/
void
CPedInventory::InitialisePatterns ()
Expand All @@ -78,6 +117,16 @@ CPedInventory::InitialisePatterns ()
"? 83 ec 20 ? 8b f8 8b ea e8 ? ? ? ? 33 db ? 85 c0", 9),
fwScriptGuidPool__GetPed);

ReadCall (
hook::get_pattern ("? 89 ? ? ? ? ? 8b ? ? ? ? ? e8 ? ? ? ? ? 89 ? ? ? "
"? ? 8b ? ? ? ? ? e8 ? ? ? ? 33 d2 ? 8d ? ? ? ? ?",
13),
CMotionTaskDataManager__FindByName);

ReadCall (hook::get_pattern (
"? 8b 52 08 45 8a c1 e8 ? ? ? ? ? 8b c0 ? 8b c0 ", 7),
CPed__CreateMotionTask);

//?? 8b 05 ?? ?? ?? ?? ?? 8b d9 ?? 8b ?? ?? ?? 8b 42 20 ?? 85 c0
CPedFactory::sm_Instance = GetRelativeReference<CPedFactory *> (
"? 8b 05 ? ? ? ? ? 8b d9 ? 8b ? ? ? 8b 42 20 ? 85 c0", 3, 7);
Expand Down
22 changes: 22 additions & 0 deletions lib/CPed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
#include <cstdint>
#include <rage.hh>
#include "CEntity.hh"
#include "ParserUtils.hh"

class CInventoryItem;
class CPed;
class CVehicle;
struct aiTask;

class CPedWeaponManager
{
Expand Down Expand Up @@ -127,6 +130,22 @@ public:
rage::bitset<BF_TOTAL_FLAGS> &GetCombatBehaviourFlags ();
};

class sMotionTaskData : public ParserWrapper<sMotionTaskData>
{
};

class CMotionTaskDataSet : public ParserWrapper<CMotionTaskDataSet>
{
};

class CMotionTaskDataManager
{
public:
atArray<CMotionTaskDataSet *> aMotionTaskData;

static CMotionTaskDataSet *FindByName (uint32_t name);
};

struct CPedInventory
{
public:
Expand Down Expand Up @@ -160,6 +179,9 @@ public:

CPedInventory * GetInventory ();
CPedIntelligence *GetIntelligence ();
aiTask * CreateMotionTask (sMotionTaskData *set, bool lowLod);
CVehicle * GetVehicle ();
uint32_t GetMotionState ();
};

class CPedFactory
Expand Down
17 changes: 17 additions & 0 deletions lib/CTask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ aiTask::InitialisePatterns ()
CTaskGun::vftable = GetRelativeReference (
"? 8d 05 ? ? ? ? f3 0f 10 74 ? ? 0f 57 ff 0f 2f 35 ? ? ? ? ? 89 ? ", 3,
7);

CTaskHumanLocomotion::vftable
= GetRelativeReference ("? 8d 05 ? ? ? ? 0f 57 c0 ? 89 ? ? 8d 8e 30 01 "
"00 00 0f 29 86 20 01 00 00 ",
3, 7);

CTaskBirdLocomotion::vftable = GetRelativeReference (
"? 8d 05 ? ? ? ? ? 8d 8e 20 01 00 00 ? 89 ? e8 ? ? ? ? ? 8b 44 ? ? 33 "
"d2 ? 89 96 40 01 00 00 ",
3, 7);

CTaskMotionInVehicle::vftable = GetRelativeReference (
"? 8d 05 ? ? ? ? ? 8d 8b 58 01 00 00 ? 89 ? ? 89 bb 20 01 00 00 ", 3,
7);

CTaskMotionAiming::vftable = GetRelativeReference (
"? 8d 05 ? ? ? ? 0f 57 c0 ? 89 ? ? 8d 8e 38 01 00 00 ", 3, 7);
}
34 changes: 34 additions & 0 deletions lib/CTask.hh
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,40 @@ public:
inline static void *vftable;
};

class CTaskHumanLocomotion : public aiTask
{
public:
inline static void *vftable;
};

class CTaskBirdLocomotion : public aiTask
{
public:
inline static void *vftable;
};

class CTaskMotionInVehicle : public aiTask
{
public:
inline static void *vftable;

static auto *Create [[nodiscard]] ()
{
return TaskHelper::CreateTask<CTaskMotionInVehicle> ();
}
};

class CTaskMotionAiming : public aiTask
{
public:
inline static void *vftable;

static auto *Create [[nodiscard]] ()
{
return TaskHelper::CreateTask<CTaskMotionAiming> ();
}
};

class CTaskWeapon : public aiTask
{
public:
Expand Down
4 changes: 4 additions & 0 deletions src/peds/peds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ class PedRandomizer
const ModelSwapper swap (newModel, model);
swap.OverrideClipset (Config ().ForcedClipset);

PedRandomizerCompatibility::SetRandomizingPed (
CStreaming::GetModelByIndex<CPedModelInfo> (model));

CPed *ped = CPedFactory__CreatePed (fac, p2, newModel, p4, p5);

PedRandomizerCompatibility::SetRandomizingPed (nullptr);
PedRandomizerCompatibility::AddRandomizedPed (ped, model, newModel);
PedRandomizer_PlayerFixes::UpdatePlayerHash ();
PedRandomizer_PlayerFixes::RandomizeSpecialAbility (ped);
Expand Down
Loading

0 comments on commit 125b49a

Please sign in to comment.