feat(util): Added model hash table helper (#423)

This commit is contained in:
Yimura 2022-08-25 02:02:04 +02:00 committed by GitHub
parent da617afaeb
commit 91754f3e0e
2 changed files with 64 additions and 30 deletions

View File

@ -322,36 +322,6 @@ namespace big
m_model_table = ptr.add(3).rip().as<HashTable<CBaseModelInfo*>*>();
LOG(G3LOG_DEBUG) << "HashTable => [" << HEX_TO_UPPER(m_model_table) << "]";
// sample code to iterator models
/*for (int i = 0; i < m_model_table->m_size; ++i)
{
for (auto node = m_model_table->m_lookup_table[i]; node; node = node->m_next)
{
if (const auto table_idx = node->m_idx; table_idx < m_model_table->m_size)
{
if (const auto model = m_model_table->m_data[table_idx]; model && model->m_model_type == eModelType::Vehicle)
{
}
}
}
}*/
// sample code to get a specific model
/*auto adder_hash = RAGE_JOAAT("adder");
for (auto i = m_model_table->m_lookup_table[adder_hash % m_model_table->m_lookup_key]; i; i = i->m_next)
{
if (i->m_hash == adder_hash)
{
if (const auto model = m_model_table->m_data[i->m_idx]; model)
{
LOG(G3LOG_DEBUG) << "Found Model: " << HEX_TO_UPPER(model->m_model_hash) << " => type: " << (int)model->m_model_type;
break;
}
}
}*/
});
// Get Label Text

View File

@ -0,0 +1,64 @@
#pragma once
#include "gta/joaat.hpp"
#include "pointers.hpp"
namespace big
{
// iterate all models
/*
for (int i = 0; i < m_model_table->m_size; ++i)
{
for (auto node = m_model_table->m_lookup_table[i]; node; node = node->m_next)
{
if (const auto table_idx = node->m_idx; table_idx < m_model_table->m_size)
{
if (const auto model = m_model_table->m_data[table_idx]; model && model->m_model_type == eModelType::Vehicle)
{
}
}
}
}*/
class model_info
{
public:
static bool does_model_exist(const rage::joaat_t hash)
{
if (const auto model = model_info::get_model(hash); model)
return true;
return false;
}
template<typename T = CBaseModelInfo*>
static T get_model(const rage::joaat_t hash)
{
const auto model_table = g_pointers->m_model_table;
for (auto i = model_table->m_lookup_table[hash % model_table->m_lookup_key]; i; i = i->m_next)
{
if (i->m_hash == hash)
{
if (const auto model = model_table->m_data[i->m_idx]; model)
{
return reinterpret_cast<T>(model);
}
}
}
return nullptr;
}
static CVehicleModelInfo* get_vehicle_model(const rage::joaat_t hash)
{
if (const auto model = model_info::get_model<CVehicleModelInfo*>(hash); model && model->m_model_type == eModelType::Vehicle)
return model;
return nullptr;
}
static bool is_model_of_type(const rage::joaat_t hash, const eModelType type)
{
if (const auto model = model_info::get_model(hash); model && model->m_model_type == type)
return true;
return false;
}
};
}