-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
404c3e7
commit 5517c28
Showing
9 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "pch.h" | ||
#include <vector> | ||
#include <map> | ||
|
||
template <class T, class Y> | ||
class Extender { | ||
private: | ||
inline static std::vector<std::pair<T, Y>> data{}; | ||
|
||
public: | ||
Extender(const Extender&) = delete; | ||
Extender() {} | ||
|
||
Y& Get(T ptr) { | ||
for (auto it = data.begin(); it < data.end(); ++it) { | ||
if (it->first == ptr) { | ||
return it->second; | ||
} | ||
} | ||
|
||
data.push_back({ ptr, Y(ptr) }); | ||
return data.back().second; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "pch.h" | ||
#include "randomremap.h" | ||
#include <TxdDef.h> | ||
#include <CTxdStore.h> | ||
#include <CKeyGen.h> | ||
#define MAX_REMAPS 32 | ||
#define NODE_ID "x_ranmap" | ||
|
||
RandomRemapFeature RandomRemap; | ||
|
||
struct RemapData { | ||
bool m_bInit; | ||
unsigned int rand; | ||
std::vector<RwTexture*> m_pTextures; | ||
}; | ||
|
||
void RandomRemapFeature::Process(RwFrame* frame, void* ptr, eNodeEntityType type) { | ||
FrameData &data = xFrame.Get(frame); | ||
|
||
if (data.m_bInit) { | ||
return; | ||
} | ||
|
||
std::string name = GetFrameNodeName(frame); | ||
if (name.find(NODE_ID) != std::string::npos) { | ||
std::string str = Util::GetRegexVal(name, NODE_ID"_(.*)", ""); | ||
|
||
RpClump *pClump; | ||
RemapData remapData; | ||
|
||
CBaseModelInfo *pModelInfo = nullptr; | ||
if (type == eNodeEntityType::Weapon) { | ||
CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(reinterpret_cast<CWeapon*>(ptr)->m_eWeaponType, | ||
FindPlayerPed()->GetWeaponSkill(reinterpret_cast<CWeapon*>(ptr)->m_eWeaponType)); | ||
if (pWeaponInfo){ | ||
pModelInfo = CModelInfo::GetModelInfo(pWeaponInfo->m_nModelId1); | ||
} | ||
} else { | ||
pModelInfo = CModelInfo::GetModelInfo(reinterpret_cast<CEntity*>(ptr)->m_nModelIndex); | ||
} | ||
|
||
|
||
if (pModelInfo) { | ||
pClump = pModelInfo->m_pRwClump; | ||
|
||
TxdDef pedTxd = CTxdStore::ms_pTxdPool->m_pObjects[pModelInfo->m_nTxdIndex]; | ||
RwTexDictionary *pedTxdDic = pedTxd.m_pRwDictionary; | ||
if (pedTxdDic) { | ||
RwTexture *ptr = RwTexDictionaryFindHashNamedTexture(pedTxdDic, CKeyGen::GetUppercaseKey(str.c_str())); | ||
remapData.m_pTextures.push_back(ptr); | ||
for (int i = 1; i != MAX_REMAPS; i++) { | ||
RwTexture *ptr = RwTexDictionaryFindHashNamedTexture(pedTxdDic, | ||
CKeyGen::GetUppercaseKey((str + "_" + std::to_string(i)).c_str())); | ||
|
||
if (ptr) { | ||
remapData.m_pTextures.push_back(ptr); | ||
} | ||
} | ||
} | ||
} | ||
|
||
remapData.rand = Random(0u, remapData.m_pTextures.size()-1); | ||
RpClumpForAllAtomics(pClump, [](RpAtomic *atomic, void *data) { | ||
if (atomic->geometry) { | ||
RpGeometryForAllMaterials(atomic->geometry, [](RpMaterial *material, void *data) { | ||
RemapData *pData = reinterpret_cast<RemapData*>(data); | ||
if (material->texture == pData->m_pTextures[0]) { | ||
material->texture = pData->m_pTextures[pData->rand]; | ||
} | ||
return material; | ||
}, data); | ||
} | ||
return atomic; | ||
}, &remapData); | ||
|
||
data.m_bInit = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "plugin.h" | ||
#include "../../interface/ifeature.hpp" | ||
#include "../../extender.h" | ||
|
||
class RandomRemapFeature : public IFeature { | ||
private: | ||
struct FrameData { | ||
bool m_bInit = false; | ||
FrameData(RwFrame*) {} | ||
~FrameData() {} | ||
}; | ||
Extender<RwFrame*, FrameData> xFrame; | ||
|
||
public: | ||
RandomRemapFeature () {}; | ||
|
||
void Process(RwFrame* frame, void* ptr, eNodeEntityType type); | ||
}; | ||
|
||
extern RandomRemapFeature RandomRemap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters