2021-08-12 23:28:19 -04:00
|
|
|
#include "extensions/Paths.h"
|
2022-06-15 06:45:43 -04:00
|
|
|
#include "pch.h"
|
2021-08-12 23:28:19 -04:00
|
|
|
|
2021-10-25 10:03:27 -04:00
|
|
|
ResourceStore::ResourceStore(const char* text, eResourceType type, ImVec2 imageSize)
|
2022-01-07 03:18:00 -05:00
|
|
|
: m_ImageSize(imageSize)
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2022-06-12 14:01:43 -04:00
|
|
|
if (type == eResourceType::TYPE_TEXT || type == eResourceType::TYPE_BOTH)
|
2021-08-13 16:09:43 -04:00
|
|
|
{
|
2022-06-15 06:45:43 -04:00
|
|
|
m_pData = std::make_unique<DataStore>(text);
|
2021-08-13 16:09:43 -04:00
|
|
|
|
|
|
|
if (type == eResourceType::TYPE_TEXT)
|
|
|
|
{
|
|
|
|
// Generate categories
|
2022-06-15 06:45:43 -04:00
|
|
|
for (auto [k, v] : m_pData->Items())
|
2021-08-13 16:09:43 -04:00
|
|
|
{
|
2022-06-15 06:45:43 -04:00
|
|
|
m_Categories.push_back(std::string(k.str()));
|
2021-08-13 16:09:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 03:18:00 -05:00
|
|
|
|
2022-06-12 14:01:43 -04:00
|
|
|
if (type == eResourceType::TYPE_IMAGE || type == eResourceType::TYPE_BOTH)
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2022-01-07 03:18:00 -05:00
|
|
|
/*
|
2021-08-13 13:45:56 -04:00
|
|
|
Textures need to be loaded from main thread
|
|
|
|
Loading it directly here doesn't work
|
2022-06-12 14:01:43 -04:00
|
|
|
TODO:
|
|
|
|
Maybe enabling a dx9 flag fixes this?
|
|
|
|
Switch to initScriptsEvent
|
2021-08-13 13:45:56 -04:00
|
|
|
*/
|
2021-10-25 10:03:27 -04:00
|
|
|
Events::processScriptsEvent += [text, this]()
|
|
|
|
{
|
2021-08-12 23:28:19 -04:00
|
|
|
if (!m_bTexturesLoaded)
|
|
|
|
{
|
|
|
|
LoadTextureResource(text);
|
|
|
|
m_bTexturesLoaded = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 14:01:43 -04:00
|
|
|
// Get dx9 texture object from RwTexture*
|
|
|
|
static IDirect3DTexture9** GetTextureFromRaster(RwTexture* pTexture)
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2022-01-07 03:18:00 -05:00
|
|
|
RwRasterEx* raster = (RwRasterEx*)(&pTexture->raster->parent);
|
2021-08-12 23:28:19 -04:00
|
|
|
|
2022-01-07 03:18:00 -05:00
|
|
|
return (&raster->m_pRenderResource->texture);
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
|
|
|
|
2022-06-15 06:45:43 -04:00
|
|
|
RwTexDictionary* LoadTexDictionary(char const* filename) {
|
|
|
|
return plugin::CallAndReturnDynGlobal<RwTexDictionary*, char const*>(0x5B3860, filename);
|
|
|
|
}
|
|
|
|
|
2021-10-25 10:03:27 -04:00
|
|
|
void ResourceStore::LoadTextureResource(std::string&& name)
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2022-06-16 14:44:33 -04:00
|
|
|
std::string fullPath = PLUGIN_PATH((char*)FILE_NAME "\\") + name + ".txd";
|
2022-06-15 06:45:43 -04:00
|
|
|
|
|
|
|
if (!std::filesystem::exists(fullPath))
|
|
|
|
{
|
|
|
|
//Log::PrintWarn("Failed to load {}", fullPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RwTexDictionary* pRwTexDictionary = LoadTexDictionary(fullPath.c_str());
|
2021-08-12 23:28:19 -04:00
|
|
|
|
2022-01-07 03:18:00 -05:00
|
|
|
if (pRwTexDictionary)
|
|
|
|
{
|
2021-10-25 10:03:27 -04:00
|
|
|
RwLinkList *pRLL = (RwLinkList*)pRwTexDictionary->texturesInDict.link.next;
|
2021-08-12 23:28:19 -04:00
|
|
|
RwTexDictionary *pEndDic;
|
|
|
|
do
|
|
|
|
{
|
2021-10-25 10:03:27 -04:00
|
|
|
pEndDic = (RwTexDictionary*)pRLL->link.next;
|
|
|
|
RwTexture *pTex = (RwTexture*)&pRLL[-1];
|
2021-08-12 23:28:19 -04:00
|
|
|
|
2021-08-27 23:12:20 -04:00
|
|
|
m_ImagesList.push_back(std::make_unique<TextureResource>());
|
2021-08-12 23:28:19 -04:00
|
|
|
m_ImagesList.back().get()->m_pRwTexture = pTex;
|
2022-01-07 03:18:00 -05:00
|
|
|
|
2021-08-12 23:28:19 -04:00
|
|
|
// Fetch IDirec9Texture9* from RwTexture*
|
2021-08-25 06:06:21 -04:00
|
|
|
m_ImagesList.back().get()->m_pTexture = GetTextureFromRaster(pTex);
|
2021-08-12 23:28:19 -04:00
|
|
|
|
|
|
|
// Naming format in Txd `Category$TextureName`
|
|
|
|
std::stringstream ss(pTex->name);
|
|
|
|
std::string str;
|
2021-08-13 16:09:43 -04:00
|
|
|
|
2021-08-12 23:28:19 -04:00
|
|
|
getline(ss, str, '$');
|
|
|
|
m_ImagesList.back().get()->m_CategoryName = str;
|
|
|
|
|
|
|
|
if (name == "clothes")
|
|
|
|
{
|
|
|
|
// pass full name
|
|
|
|
m_ImagesList.back().get()->m_FileName = pTex->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getline(ss, str, '$');
|
|
|
|
m_ImagesList.back().get()->m_FileName = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Genereate categories
|
2021-08-13 16:09:43 -04:00
|
|
|
if (!std::count(m_Categories.begin(), m_Categories.end(), m_ImagesList.back().get()->m_CategoryName))
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2021-08-13 16:09:43 -04:00
|
|
|
m_Categories.push_back(m_ImagesList.back().get()->m_CategoryName);
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
2021-10-25 10:03:27 -04:00
|
|
|
pRLL = (RwLinkList*)pEndDic;
|
|
|
|
}
|
|
|
|
while ( pEndDic != (RwTexDictionary*)&pRwTexDictionary->texturesInDict );
|
2022-01-07 03:18:00 -05:00
|
|
|
}
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|