Skip to content

Commit

Permalink
up...
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Feb 8, 2024
1 parent b99d942 commit ce89892
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 56 deletions.
22 changes: 11 additions & 11 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ static void InitFeatures() {
Randomizer.Initialize();
}

static void ProcessNodesRecursive(RwFrame * frame, void* pEntity, eNodeEntityType type) {
static void ProcessNodesRecursive(RwFrame * frame, void* pEntity, eModelEntityType type) {
if(frame) {
const std::string name = GetFrameNodeName(frame);

if (type == eNodeEntityType::Vehicle) {
if (type == eModelEntityType::Vehicle) {
CVehicle *pVeh = static_cast<CVehicle*>(pEntity);
HandleBar.Process(frame, pVeh);
}

if ((name[0] == 'x' && name[1] == '_')|| (name[0] == 'f' && name[1] == 'c' && name[2] == '_')) {
if (type == eNodeEntityType::Vehicle) {
if (type == eModelEntityType::Vehicle) {
CVehicle *pVeh = static_cast<CVehicle*>(pEntity);
Chain.Process(frame, pVeh);
FrontBrake.Process(frame, pVeh);
Expand All @@ -41,21 +41,21 @@ static void ProcessNodesRecursive(RwFrame * frame, void* pEntity, eNodeEntityTyp
GearLever.Process(frame, pVeh);
GearSound.Process(frame, pVeh);
Randomizer.Process(frame, static_cast<void*>(pVeh), type);
} else if (type == eNodeEntityType::Weapon) {
} else if (type == eModelEntityType::Weapon) {
CWeapon *pWep = static_cast<CWeapon*>(pEntity);
BodyState.Process(frame, pWep);
BodyState.ProcessZen(frame, pWep);
BloodRemap.Process(frame, pWep);
Randomizer.Process(frame, static_cast<void*>(pWep), type);
} else if (type == eNodeEntityType::Object) {
} else if (type == eModelEntityType::Object) {

/*
processing weapon & jetpack pickups here
*/
CWeapon *pWep = static_cast<CWeapon*>(pEntity);
BodyState.Process(frame, pWep);
BodyState.ProcessZen(frame, pWep);
} else if (type == eNodeEntityType::Ped) {
} else if (type == eModelEntityType::Ped) {
Randomizer.Process(frame, pEntity, type);
}
}
Expand Down Expand Up @@ -83,21 +83,21 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) {
};

Events::vehicleRenderEvent += [](CVehicle* pVeh) {
ProcessNodesRecursive((RwFrame *)pVeh->m_pRwClump->object.parent, pVeh, eNodeEntityType::Vehicle);
ProcessNodesRecursive((RwFrame *)pVeh->m_pRwClump->object.parent, pVeh, eModelEntityType::Vehicle);
};

objectRenderEvent += [](CObject *pObj) {
ProcessNodesRecursive((RwFrame *)pObj->m_pRwClump->object.parent, pObj, eNodeEntityType::Object);
ProcessNodesRecursive((RwFrame *)pObj->m_pRwClump->object.parent, pObj, eModelEntityType::Object);
};

Events::pedRenderEvent += [](CPed* pPed) {
// peds
ProcessNodesRecursive((RwFrame *)pPed->m_pRwClump->object.parent, pPed, eNodeEntityType::Ped);
ProcessNodesRecursive((RwFrame *)pPed->m_pRwClump->object.parent, pPed, eModelEntityType::Ped);

// jetpack
CTaskSimpleJetPack *pTask = pPed->m_pIntelligence->GetTaskJetPack();
if (pTask && pTask->m_pJetPackClump) {
ProcessNodesRecursive((RwFrame *)pTask->m_pJetPackClump->object.parent, pPed, eNodeEntityType::Weapon);
ProcessNodesRecursive((RwFrame *)pTask->m_pJetPackClump->object.parent, pPed, eModelEntityType::Weapon);
}

// weapons
Expand All @@ -108,7 +108,7 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) {
if (pWeaponInfo) {
CWeaponModelInfo* pWeaponModelInfo = static_cast<CWeaponModelInfo*>(CModelInfo::GetModelInfo(pWeaponInfo->m_nModelId1));
if (pWeaponModelInfo && pWeaponModelInfo->m_pRwClump) {
ProcessNodesRecursive((RwFrame *)pWeaponModelInfo->m_pRwClump->object.parent, pWeapon, eNodeEntityType::Weapon);
ProcessNodesRecursive((RwFrame *)pWeaponModelInfo->m_pRwClump->object.parent, pWeapon, eModelEntityType::Weapon);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/common/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void RandomizerFeature::Initialize() {
};
}

void RandomizerFeature::Process(RwFrame* frame, void* ptr, eNodeEntityType type) {
void RandomizerFeature::Process(RwFrame* frame, void* ptr, eModelEntityType type) {
std::string name = GetFrameNodeName(frame);

if (NODE_FOUND(name, NODE_ID)) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/common/randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RandomizerFeature : public IFeature {

public:
void Initialize();
void Process(RwFrame* frame, void* ptr, eNodeEntityType type);
void Process(RwFrame* frame, void* ptr, eModelEntityType type);
};

extern RandomizerFeature Randomizer;
20 changes: 10 additions & 10 deletions src/features/common/remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

RemapFeature Remap;

void RemapFeature::LoadRemaps(CBaseModelInfo *pModelInfo, int model, eNodeEntityType type)
void RemapFeature::LoadRemaps(CBaseModelInfo *pModelInfo, int model, eModelEntityType type)
{
if (pModelInfo)
{
Expand Down Expand Up @@ -61,32 +61,32 @@ static std::map<void*, bool> m_pBloodState;

void RemapFeature::Initialize() {
Events::vehicleRenderEvent.before += [this](CVehicle* ptr) {
BeforeRender(reinterpret_cast<void*>(ptr), eNodeEntityType::Vehicle);
BeforeRender(reinterpret_cast<void*>(ptr), eModelEntityType::Vehicle);
};

Events::pedRenderEvent.before += [this](CPed* pPed) {
BeforeRender(reinterpret_cast<void*>(pPed), eNodeEntityType::Ped);
BeforeRender(reinterpret_cast<void*>(pPed), eModelEntityType::Ped);
};

weaponRenderEvent.before += [this](CPed* pPed) {
CWeapon *pWeapon = &pPed->m_aWeapons[pPed->m_nActiveWeaponSlot];
if (pWeapon) {
BeforeRender(reinterpret_cast<void*>(pWeapon), eNodeEntityType::Weapon);
BeforeRender(reinterpret_cast<void*>(pWeapon), eModelEntityType::Weapon);
}
};

Events::vehicleRenderEvent.after += [this](CVehicle* ptr) {
AfterRender(reinterpret_cast<void*>(ptr), eNodeEntityType::Vehicle);
AfterRender(reinterpret_cast<void*>(ptr), eModelEntityType::Vehicle);
};

Events::pedRenderEvent.after += [this](CPed* pPed) {
AfterRender(reinterpret_cast<void*>(pPed), eNodeEntityType::Ped);
AfterRender(reinterpret_cast<void*>(pPed), eModelEntityType::Ped);
};

weaponRenderEvent.after += [this](CPed* pPed) {
CWeapon *pWeapon = &pPed->m_aWeapons[pPed->m_nActiveWeaponSlot];
if (pWeapon) {
AfterRender(reinterpret_cast<void*>(pWeapon), eNodeEntityType::Weapon);
AfterRender(reinterpret_cast<void*>(pWeapon), eModelEntityType::Weapon);
}
};

Expand All @@ -104,7 +104,7 @@ void RemapFeature::Initialize() {
};
}

void RemapFeature::AfterRender(void* ptr, eNodeEntityType type) {
void RemapFeature::AfterRender(void* ptr, eModelEntityType type) {
for (auto &e : m_pOriginalTextures) {
*e.first = e.second;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ bool RemapFeature::GetKilledState(CWeapon *pWeapon) {
return state;
}

void RemapFeature::BeforeRender(void* ptr, eNodeEntityType type) {
void RemapFeature::BeforeRender(void* ptr, eModelEntityType type) {
int model = Util::GetEntityModel(ptr, type);
CBaseModelInfo *pModelInfo = CModelInfo::GetModelInfo(model);

Expand All @@ -148,7 +148,7 @@ void RemapFeature::BeforeRender(void* ptr, eNodeEntityType type) {
return;
}

if (type == eNodeEntityType::Weapon) {
if (type == eModelEntityType::Weapon) {
data.useBlood = GetKilledState(static_cast<CWeapon*>(ptr));
}

Expand Down
6 changes: 3 additions & 3 deletions src/features/common/remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class RemapFeature : public IFeature {
private:
bool GetKilledState(CWeapon *pWeapon);

void LoadRemaps(CBaseModelInfo *pModelInfo, int model, eNodeEntityType type);
void LoadRemaps(CBaseModelInfo *pModelInfo, int model, eModelEntityType type);

void BeforeRender(void* ptr, eNodeEntityType type);
void AfterRender(void* ptr, eNodeEntityType type);
void BeforeRender(void* ptr, eModelEntityType type);
void AfterRender(void* ptr, eModelEntityType type);

public:
RemapFeature () {};
Expand Down
42 changes: 21 additions & 21 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,46 @@
class Logger {
private:
enum class LogLevel {
Debug,
Info,
Warn,
Error,
None,
Debug,
Info,
Warn,
Error,
None,
};

std::mutex logMutex; // Add a mutex for thread safety

public:
explicit Logger(const std::string& logName = "Logger.log") : logName(logName) {
pLog.open(logName, std::ios::out); // Open in out mode
pLog.open(logName, std::ios::out); // Open in out mode
}

Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;

template <typename... Args>
void Warn(const std::string& fmt, Args&&... args) noexcept {
LogMessage(LogLevel::Warn, fmt, std::forward<Args>(args)...);
LogMessage(LogLevel::Warn, fmt, std::forward<Args>(args)...);
}

template <typename... Args>
void Info(const std::string& fmt, Args&&... args) noexcept {
LogMessage(LogLevel::Info, fmt, std::forward<Args>(args)...);
LogMessage(LogLevel::Info, fmt, std::forward<Args>(args)...);
}

template <typename... Args>
void Debug(const std::string& fmt, Args&&... args) noexcept {
LogMessage(LogLevel::Debug, fmt, std::forward<Args>(args)...);
LogMessage(LogLevel::Debug, fmt, std::forward<Args>(args)...);
}

template <typename... Args>
void Error(const std::string& fmt, Args&&... args) noexcept {
LogMessage(LogLevel::Error, fmt, std::forward<Args>(args)...);
LogMessage(LogLevel::Error, fmt, std::forward<Args>(args)...);
}

template <typename... Args>
void Print(const std::string& fmt, Args&&... args) noexcept {
LogMessage(LogLevel::None, fmt, std::forward<Args>(args)...);
LogMessage(LogLevel::None, fmt, std::forward<Args>(args)...);
}

private:
Expand All @@ -59,18 +59,18 @@ class Logger {

template <typename... Args>
void LogMessage(LogLevel logLevel, const std::string& fmt, Args&&... args) noexcept {
std::scoped_lock lock(logMutex); // Lock for thread safety
std::scoped_lock lock(logMutex); // Lock for thread safety

if (!pLog.is_open()) {
pLog.open(logName, std::ios::out); // Open in out mode
}
if (!pLog.is_open()) {
pLog.open(logName, std::ios::out); // Open in out mode
}

std::string logMessage = fmt;
if (logLevel != LogLevel::None) {
const char* levelNames[] = {"D", "I", "W", "E", ""};
logMessage = "[" + std::string(levelNames[static_cast<int>(logLevel)]) + "] " + logMessage;
}
std::string logMessage = fmt;
if (logLevel != LogLevel::None) {
const char* levelNames[] = {"D", "I", "W", "E", ""};
logMessage = "[" + std::string(levelNames[static_cast<int>(logLevel)]) + "] " + logMessage;
}

pLog << std::vformat(logMessage, std::make_format_args(std::forward<Args>(args)...)) << std::endl;
pLog << std::vformat(logMessage, std::make_format_args(std::forward<Args>(args)...)) << std::endl;
}
};
1 change: 1 addition & 0 deletions src/pch.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include "pch.h"

std::shared_ptr<Logger> gLogger = std::make_shared<Logger>(MOD_NAME".log");
10 changes: 5 additions & 5 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

using namespace plugin;

enum class eNodeEntityType {
Ped,
Object,
Vehicle,
Weapon,
enum class eModelEntityType {
Ped,
Object,
Vehicle,
Weapon,
};

#define MOD_DATA_PATH(x) PLUGIN_PATH((char*)("ModelExtras/"x))
Expand Down
4 changes: 2 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ float Util::GetVehicleSpeedRealistic(CVehicle * vehicle) {
return wheelSpeed;
}

unsigned int Util::GetEntityModel(void *ptr, eNodeEntityType type) {
unsigned int Util::GetEntityModel(void *ptr, eModelEntityType type) {
int model = 0;
if (type == eNodeEntityType::Weapon) {
if (type == eModelEntityType::Weapon) {
CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(reinterpret_cast<CWeapon*>(ptr)->m_eWeaponType,
FindPlayerPed()->GetWeaponSkill(reinterpret_cast<CWeapon*>(ptr)->m_eWeaponType));
if (pWeaponInfo){
Expand Down
4 changes: 2 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

typedef enum class eNodeEntityType eNodeEntityType;
typedef enum class eModelEntityType eModelEntityType;

class Util {
public:
Expand All @@ -12,7 +12,7 @@ class Util {

// Returns the speed of the vehicle handler
static float GetVehicleSpeedRealistic(CVehicle * vehicle);
static unsigned int GetEntityModel(void *ptr, eNodeEntityType type);
static unsigned int GetEntityModel(void *ptr, eModelEntityType type);

// Rotate model frame
static void SetFrameRotationX(RwFrame* frame, float angle);
Expand Down

0 comments on commit ce89892

Please sign in to comment.